Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2170 introduce gender model #2485

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
3e4b85d
draft create update delete + tests + testupdates + migration
hjanott Jun 21, 2024
36f1d70
update meta rep
hjanott Jun 21, 2024
a025ba2
general error removal and improvement for draft
hjanott Jun 21, 2024
275aed2
remove meeting import error
hjanott Jun 24, 2024
9a79a5e
update meeting import so that checker removes gender_id
hjanott Jun 24, 2024
42b63b6
general code improvements delete gender checks for back relation in o…
hjanott Jun 25, 2024
b4f9e8f
md documentation + pleasing mypy
hjanott Jun 25, 2024
9162ee6
merge upstream main
hjanott Jun 26, 2024
6e74b9c
Merge commit 'b1d1e6fd' into 2170_introduce_gender_model
hjanott Jun 26, 2024
8dfbd80
use defaultdict
hjanott Jun 26, 2024
c356c42
use new in memory flag of datastore
hjanott Jun 27, 2024
468f9eb
fix mypy error by upping datastore version
hjanott Jun 27, 2024
87dfb9e
change the permission from can_manage_organization to can_manage_users
hjanott Jun 27, 2024
3aec96d
improve documentation
hjanott Jun 28, 2024
21addc2
lock result false + no orga check
hjanott Jun 28, 2024
443cb58
add test for gender import
r-peschke Jul 5, 2024
773582b
make name and org id required
hjanott Jul 30, 2024
280f8b2
Use gender string for saml and meeting import. Refine gender actions …
hjanott Aug 1, 2024
ffbd52d
cleanup and documentation improvement
hjanott Aug 2, 2024
32e3cd9
beautify code
hjanott Aug 2, 2024
8be71fe
merge main by adding gender stuff (and locked_out in merge_mixin)
hjanott Aug 9, 2024
abfbefd
update from upstream/main
hjanott Aug 12, 2024
35f739f
add test update gender on user merge.
hjanott Aug 12, 2024
fe3e77e
update docs test for meeting import and saml account (+ new test) cre…
hjanott Aug 16, 2024
8ac6300
Merge remote-tracking branch 'upstream/main' into 2170_introduce_gend…
hjanott Aug 16, 2024
6b9d772
updated meta
hjanott Aug 16, 2024
a9341b0
meeting import create user with gender. export gender strings. improv…
hjanott Aug 20, 2024
4633eed
Separate test for gender on meeting import. General code improvements…
hjanott Aug 21, 2024
2641a8e
merge upstream main and generate models
hjanott Aug 22, 2024
7054aed
extend test for gender import, plus fixes. docs update
hjanott Aug 27, 2024
92fa165
update meta repo
hjanott Aug 28, 2024
5b26bf1
improve user and gender updates/creation
r-peschke Sep 4, 2024
20b6d5c
Gender will not be created without being used anymore. Fix error wher…
hjanott Sep 5, 2024
ee2cff4
Improve gender action documentation
hjanott Sep 5, 2024
033ebde
fixed typo in migration gender female
hjanott Sep 6, 2024
e922d46
Merge main and update migration index.
hjanott Sep 18, 2024
9b51eff
Merge branch 'main' into 2170_introduce_gender_model
hjanott Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/Actions-Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ A more general format description see in [Action-Service](https://github.com/Ope
- [theme.delete](actions/theme.delete.md)
- [theme.update](actions/theme.update.md)

## Gender

- [gender.create](actions/theme.create.md)
- [gender.delete](actions/theme.delete.md)
- [gender.update](actions/theme.update.md)

## Topics

- [topic.create](actions/topic.create.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/actions/account.import.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Payload
```js
```
{
// required
id: Id; // action worker id
Expand Down
4 changes: 2 additions & 2 deletions docs/actions/account.json_upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Because the data fields are all converted from CSV import file, **they are all of type `string`**.
The types noted below are the internal types after conversion in the backend. See [here](preface_special_imports.md#internal-types) for the representation of the types.
```js
```
{
// required
data: {
Expand All @@ -14,7 +14,7 @@ The types noted below are the internal types after conversion in the backend. Se
member_number: string, // unique member_number, info: done (used as matching field), new (newly added) or error
title: string,
pronoun: string,
gender: string, // as defined in organization/genders, info: done or warning
gender: string, // info: done or warning
default_password: string, // info: generated, done or warning
is_active: boolean,
is_physical_person: boolean,
Expand Down
13 changes: 13 additions & 0 deletions docs/actions/gender.create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Payload
```
{
// Required
name: string;
}
```

## Action
Creates the gender if a gender with the same name doesn't exist.

## Permissions
The user needs to have the organization management level `can_manage_organization`.
13 changes: 13 additions & 0 deletions docs/actions/gender.delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Payload
```
{
//Required
id: Id;
}
```

## Action
Deletes the gender if it is not one of the four default genders.

## Permissions
The user needs to have the organization management level `can_manage_organization`.
15 changes: 15 additions & 0 deletions docs/actions/gender.update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Payload
```
{
// Required
id: Id;
// Group A
name: string;
r-peschke marked this conversation as resolved.
Show resolved Hide resolved
}
```

## Action
Updates the gender if a gender with that name does not exist and is not one of the four default genders.

## Permissions
- Group A: The user needs the OML `can_manage_organization`
3 changes: 2 additions & 1 deletion docs/actions/meeting.import.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ Import one meeting from a file. The file must only contain exactly one meeting.
- The request user is assigned to the admin group.
- meeting.is_active_in_organization_id is set.
- It has to be checked, whether the organization.limit_of_meetings is unlimited(=0) or lower than the active meetings in organization.active_meeting_ids, if the new meeting is not archived (`is_active_in_organization_id` is set)
- Search for users and if username, first-name, last-name and email are identical use this user instead creating a duplicate. Keep the data, including password, of the exiating user.
- Search for users and if username, first-name, last-name and email are identical use this existing user instead of creating a duplicate. Keep the data, including password, of the existing user. Relevant relations such as to the meeting will be updated though.
- Users, that still have to be duplicated:
- Imported usernames will be checked for uniqueness and adjusted in the case of collisions.
- All previously set user passwords will be replaced
- Genders will only be updated or imported if a new user needs to be created. Updated users will not have their genders updated.


## Permissions
Expand Down
3 changes: 0 additions & 3 deletions docs/actions/organization.update.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
users_email_replyto: string;
users_email_subject: string;
users_email_body: text;
genders: string[];
require_duplicate_from: boolean;
// Group B
Expand All @@ -38,8 +37,6 @@
Updates the organization.
It has to be checked that the theme_id has to be one of the theme_ids.

Checks for deleted genders and clean the gender of users which have deleted genders.

## Permissions
- Users with OML of `can_manage_organization` can modify group A
- Users with OML of `superadmin` can modify group B
2 changes: 1 addition & 1 deletion docs/actions/participant.import.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Payload
```js
```
{
// required
id: Id; // import_preview id
Expand Down
4 changes: 2 additions & 2 deletions docs/actions/participant.json_upload.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Payload
Because the data fields are all converted from CSV import file, **they are all of type `string`**.
The types noted below are the internal types after conversion in the backend. See [here](preface_special_imports.md#internal-types) for the representation of the types.
```js
```
{
// required
meeting_id: Id,
Expand All @@ -14,7 +14,7 @@ The types noted below are the internal types after conversion in the backend. Se
member_number: string, // unique member_number, info: done, error, new (newly added) or remove (missing field permission)
title: string, // info: done or remove (missing field permission)
pronoun: string, // info: done or remove (missing field permission)
gender: string, // as defined in organization/genders, info: done, warning (undefined gender) or remove (missing field permission)
gender: string, // info: done, warning (undefined gender) or remove (missing field permission)
default_password: string, // info: generated, done, warning or remove (missing field permission)
is_active: boolean, // info: done or remove (missing field permission)
is_physical_person: boolean, // info: done or remove (missing field permission)
Expand Down
6 changes: 3 additions & 3 deletions docs/actions/user.create.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
is_active: boolean;
is_physical_person: boolean;
can_change_own_password: boolean;
gender: string;
gender_id: Id;
pronoun: string;
email: string;
default_vote_weight: decimal(6);
Expand Down Expand Up @@ -56,8 +56,8 @@ Creates a user.
* If no `default_password` is given a random one is generated. The default password is hashed via the auth service and the hash is saved within `password`. A given `default_password`is also stored as hashed password.
* If `username` is given, it has to be unique within all users. If there already exists a user with the same username, an error must be returned. If the `username` is not given, 1. the saml_id will be used or 2. it has to be generated (see [user.create#generate-a-username](user.create.md#generate-a-username) below). Also the username may not contain spaces.
* The `organization_management_level` as restring can be taken from the enum of this user field.
* Remove starting and trailing spaces from `username`, `first_name` and `last_name`
* The given `gender` must be present in `organization/genders`
* Remove starting and trailing spaces from `username`, `first_name` and `last_name`.
* The given `gender_id` must be present in the database.
* If `saml_id` is set in payload, there may be no `password` or `default_password` set or generated and `set_change_own_password` will be set to False.
* The `member_number` must be unique within all users.
* Will throw an error if the `group_ids` contain the meetings `anonymous_group_id`.
Expand Down
2 changes: 1 addition & 1 deletion docs/actions/user.merge_together.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
is_active: boolean;
is_physical_person: boolean;
default_password: string;
gender: string;
gender_id: Id;
email: string;
default_vote_weight: decimal(6);
pronoun: string;
Expand Down
2 changes: 1 addition & 1 deletion docs/actions/user.save_saml_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

## Action
The attributes for the payload are all configured in organization-wide settings. The configuration consists of a list of source attribute - target attribute pairs, where the target attributes are the ones documented in the payload.
Creates or updates the saml-account, depending whether the given `saml_id` exists or not. The `saml_id` is guaranteed to be unique in the whole system. The other fields will be set on creation or update.
Creates or updates the saml-account, depending whether the given `saml_id` exists or not. The `saml_id` is guaranteed to be unique in the whole system. If a gender does not exist in the collection, it will be created. The other fields will be set on creation or update.
The action must be `STACK_INTERNAL`. It should be called only from the auth service.

Extras to do on creation:
Expand Down
2 changes: 1 addition & 1 deletion docs/actions/user.update.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
is_active: boolean;
is_physical_person: boolean;
can_change_own_password: boolean;
gender: string;
gender_id: Id;
pronoun: string;
email: string;
default_vote_weight: decimal(6);
Expand Down
2 changes: 1 addition & 1 deletion docs/actions/user.update_self.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Optional
username: string;
email: string;
gender: string;
gender_id: Id;
pronoun: string;
}
```
Expand Down
3 changes: 2 additions & 1 deletion docs/presenters/export_meeting.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
```
JSON with export
```
The users genders are exported as their names not ids.

# Logic
The presenter exports the meeting, the collections which belong to the meeting and users of the meeting. It uses the meeting.user_id for that. And it excludes the organization tags and the committee.
Will raise an exception if the meeting is locked voa the `locked_from_inside` setting.
Will raise an exception if the meeting is locked via the `locked_from_inside` setting.

# Permissions
The request user must have the `SUPERADMIN` organization management level.
Expand Down
36 changes: 31 additions & 5 deletions global/data/example-data.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
{
"_migration_index": 56,
"_migration_index": 57,
"gender":{
"1":{
"id": 1,
"name": "male",
"organization_id": 1,
"user_ids":[1]
},
"2":{
"id": 2,
"name": "female",
"organization_id": 1,
"user_ids":[2]
},
"3":{
"id": 3,
"name": "diverse",
"organization_id": 1,
"user_ids":[3]
},
"4":{
"id": 4,
"name": "non-binary",
"organization_id": 1,
"user_ids":[]
}
},
"organization": {
"1": {
"id": 1,
"name": "Test Organization",
"legal_notice": "<a href=\"http://www.openslides.org\">OpenSlides</a> is a free web based presentation and assembly system for visualizing and controlling agenda, motions and elections of an assembly.",
"login_text": "Good Morning!",
"default_language": "en",
"genders": ["male", "female", "diverse", "non-binary"],
"gender_ids": [1, 2 ,3 ,4],
"enable_electronic_voting": true,
"enable_chat": true,
"reset_password_verbose_errors": true,
Expand Down Expand Up @@ -60,7 +86,7 @@
"password": "316af7b2ddc20ead599c38541fbe87e9a9e4e960d4017d6e59de188b41b2758flD5BVZAZ8jLy4nYW9iomHcnkXWkfk3PgBjeiTSxjGG7+fBjMBxsaS1vIiAMxYh+K38l0gDW4wcP+i8tgoc4UBg==",
"default_password": "admin",
"can_change_own_password": true,
"gender": "male",
"gender_id": 1,
"default_vote_weight": "1.000000",
"organization_management_level": "superadmin",
"is_present_in_meeting_ids": [
Expand Down Expand Up @@ -89,7 +115,7 @@
"password": "316af7b2ddc20ead599c38541fbe87e9a9e4e960d4017d6e59de188b41b2758fDB3tv5HcCtPRREt7bPGqerTf1AbmoKXt/fVFkLY4znDRh2Yy0m3ZjXD0nHI8oa6KrGlHH/cvysfvf8i2fWIzmw==",
"default_password": "a",
"can_change_own_password": true,
"gender": "female",
"gender_id": 2,
"default_vote_weight": "1.000000",
"committee_ids": [
1
Expand All @@ -110,7 +136,7 @@
"password": "316af7b2ddc20ead599c38541fbe87e9a9e4e960d4017d6e59de188b41b2758fIxDxvpkn6dDLRxT9DxJhZ/f04AL2oK2beICRFobSw53CI93U+dfN+w+NaL7BvrcR4JWuMj9NkH4dVjnnI0YTkg==",
"default_password": "jKwSLGCk",
"can_change_own_password": true,
"gender": "diverse",
"gender_id": 3,
"default_vote_weight": "1.000000",
"option_ids": [8, 11],
"meeting_user_ids": [3],
Expand Down
30 changes: 28 additions & 2 deletions global/data/initial-data.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
{
"_migration_index": 56,
"_migration_index": 57,
"gender":{
"1":{
"id": 1,
"name": "male",
"organization_id": 1,
"user_ids":[]
},
"2":{
"id": 2,
"name": "female",
"organization_id": 1,
"user_ids":[]
},
"3":{
"id": 3,
"name": "diverse",
"organization_id": 1,
"user_ids":[]
},
"4":{
"id": 4,
"name": "non-binary",
"organization_id": 1,
"user_ids":[]
}
},
"organization": {
"1": {
"id": 1,
"name": "[Your organization]",
"legal_notice": "<a href=\"http://www.openslides.org\">OpenSlides</a> is a free web based presentation and assembly system for visualizing and controlling agenda, motions and elections of an assembly. The event organizer is resposible for the content.",
"login_text": "Welcome to OpenSlides. Please login.",
"genders": ["male", "female", "diverse", "non-binary"],
"gender_ids": [1, 2, 3, 4],
"default_language": "en",
"enable_electronic_voting": true,
"limit_of_meetings": 0,
Expand Down
2 changes: 1 addition & 1 deletion global/meta
Submodule meta updated 1 files
+27 −10 models.yml
1 change: 1 addition & 0 deletions openslides_backend/action/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def prepare_actions_map() -> None:
chat_group,
chat_message,
committee,
gender,
group,
list_of_speakers,
mediafile,
Expand Down
1 change: 1 addition & 0 deletions openslides_backend/action/actions/gender/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import create, delete, update # noqa
28 changes: 28 additions & 0 deletions openslides_backend/action/actions/gender/create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from typing import Any

from ....action.mixins.archived_meeting_check_mixin import CheckForArchivedMeetingMixin
from ....models.models import Gender
from ....permissions.management_levels import OrganizationManagementLevel
from ....shared.util import ONE_ORGANIZATION_ID
from ...generics.create import CreateAction
from ...util.default_schema import DefaultSchema
from ...util.register import register_action
from .mixins import GenderUniqueMixin


@register_action("gender.create")
class GenderCreate(CreateAction, CheckForArchivedMeetingMixin, GenderUniqueMixin):
"""
Action to create a gender.
"""

model = Gender()
schema = DefaultSchema(Gender()).get_create_schema(
required_properties=["name"],
)
permission = OrganizationManagementLevel.CAN_MANAGE_USERS

def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:
super().update_instance(instance)
instance["organization_id"] = ONE_ORGANIZATION_ID
return instance
r-peschke marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 18 additions & 0 deletions openslides_backend/action/actions/gender/delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from ....models.models import Gender
from ....permissions.management_levels import OrganizationManagementLevel
from ...generics.delete import DeleteAction
from ...util.default_schema import DefaultSchema
from ...util.register import register_action
from .mixins import GenderPermissionMixin


@register_action("gender.delete")
class GenderDeleteAction(DeleteAction, GenderPermissionMixin):
"""
Action to delete a gender.
"""

model = Gender()
schema = DefaultSchema(Gender()).get_delete_schema()
permission = OrganizationManagementLevel.CAN_MANAGE_USERS
skip_archived_meeting_check = True
Loading