-
Notifications
You must be signed in to change notification settings - Fork 26
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
Changes from 29 commits
3e4b85d
36f1d70
a025ba2
275aed2
9a79a5e
42b63b6
b4f9e8f
9162ee6
6e74b9c
8dfbd80
c356c42
468f9eb
87dfb9e
3aec96d
21addc2
443cb58
773582b
280f8b2
ffbd52d
32e3cd9
8be71fe
abfbefd
35f739f
fe3e77e
8ac6300
6b9d772
a9341b0
4633eed
2641a8e
7054aed
92fa165
5b26bf1
20b6d5c
ee2cff4
033ebde
e922d46
9b51eff
13aa7b6
8a4a6fd
fa6aa20
2b85c6e
798c49b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## Payload | ||
``` | ||
{id: Id;} | ||
``` | ||
|
||
## Action | ||
Deletes the gender. | ||
|
||
## Permissions | ||
The user needs to have the organization management level `can_manage_organization`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## Payload | ||
```js | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you put the js-tag to the page? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used it to see the highlighting changes as it is being done in some other md files. Since this is mostly not used in our docs I agreed with @rrenkert to delete these tags from the files I'm editing. |
||
{ | ||
// Required | ||
id: number; | ||
// 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 doesn't exist. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also add some text like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
## Permissions | ||
- Group A: The user needs the OML `can_manage_organization` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
## Payload | ||
``` | ||
```js | ||
{ | ||
// Optional | ||
// Group A | ||
|
@@ -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); | ||
|
@@ -57,7 +57,7 @@ Creates a user. | |
* 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` | ||
* The given `gender_id` must be present in `organization/gender_ids` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
* 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`. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
// Optional | ||
username: string; | ||
email: string; | ||
gender: string; | ||
gender_id: Id; | ||
pronoun: string; | ||
} | ||
``` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import create, delete, update # noqa |
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
|
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from typing import Any | ||
|
||
from datastore.shared.util import fqid_from_collection_and_id | ||
|
||
from openslides_backend.action.action import Action | ||
from openslides_backend.shared.exceptions import ActionException, PermissionException | ||
|
||
from ...mixins.check_unique_name_mixin import CheckUniqueInContextMixin | ||
|
||
|
||
class GenderUniqueMixin(CheckUniqueInContextMixin): | ||
def validate_instance(self, instance: dict[str, Any]) -> None: | ||
if instance.get("name") == "": | ||
raise ActionException("Empty gender name not allowed.") | ||
super().validate_instance(instance) | ||
self.check_unique_in_context( | ||
"name", | ||
instance.get("name", ""), | ||
"Gender '" + instance.get("name", "") + "' already exists.", | ||
instance.get("id"), | ||
) | ||
|
||
|
||
class GenderPermissionMixin(Action): | ||
def check_permissions(self, instance: dict[str, Any]) -> None: | ||
super().check_permissions(instance) | ||
# default genders shall not be mutable | ||
gender_id = instance.get("id", 0) | ||
if 0 < gender_id < 5: | ||
if gender_name := self.datastore.get( | ||
fqid_from_collection_and_id("gender", gender_id), | ||
["name"], | ||
lock_result=False, | ||
).get("name"): | ||
msg = f"Cannot delete or update gender '{gender_name}' from default selection." | ||
else: | ||
msg = f"Cannot delete or update gender '{gender_id}' from default selection." | ||
raise PermissionException(msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add some text like
The first 4 gender names are fixed and cannot be changed or delete
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done