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

Merged
merged 42 commits into from
Sep 27, 2024

Conversation

hjanott
Copy link
Member

@hjanott hjanott commented Jun 21, 2024

Closes #2170

Themes to check:

  • meeting export: export only the gender string per user.
  • meeting import: import the gender only for users that need to be created.
  • save_saml_account-Action: saml_attr_mapping field continue to use gender:gender mapping. In the action we have to transform the gender-string to an existing or new gender_id and update the user. Always create not existing gender-instances. An action-payload without gender-field may change nothing, a gender-field with an empty string should be interpreted as "no gender value wanted" and the user's gender_id should be set to NULL. @rrenkert @Elblinator hope you agree
  • user.create/update: now uses gender_id in payload instead of gender as string. Must be also changed in client.
  • set null in user and organization on deletion of gender-instances

@hjanott hjanott added feature migration Introduces a new migration labels Jun 21, 2024
@hjanott hjanott added this to the 4.2 milestone Jun 21, 2024
@hjanott hjanott requested a review from r-peschke June 21, 2024 13:18
@hjanott hjanott marked this pull request as ready for review June 21, 2024 13:57
@hjanott hjanott marked this pull request as draft June 21, 2024 14:17
Copy link
Member

@r-peschke r-peschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments in migration code.
With help of the openslides-datastore-service pull request 368 it will be easier to write the migration.

Copy link
Member

@Elblinator Elblinator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the permission from can_manage_organization to can_manage_accounts to edit/delete or update a gender

@hjanott
Copy link
Member Author

hjanott commented Jun 27, 2024

can_manage_accounts

I will use can_manage_users instead. ;)

openslides_backend/action/actions/meeting/import_.py Outdated Show resolved Hide resolved
"gender/1": {"name": "male"},
"gender/2": {"name": "female"},
"gender/3": {"name": "diverse"},
"gender/4": {"name": "non-binary"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amend an existing test: explicit test for the field gender being empty after importing a new user

Copy link
Member Author

@hjanott hjanott Jul 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used test_all_migrations for this.

) -> dict[str, int] | None:
"""returns gender as a dict of "name" and "id" if it exists, otherwise raises ActionException"""
if gender_id := instance.get("gender_id"):
gender_dict = datastore.get_all("gender", ["id", "name"], lock_result=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a simple self.datastore.get("gender", gender_id,...) to read the gender instance.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use the fqid to get the gender now.

)
def check_gender_exists(
datastore: DatastoreService, instance: dict[str, Any]
) -> dict[str, int] | None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't return anything, it is never used

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -29,7 +29,7 @@ def setUp(self) -> None:
"first_name": "firstName",
"last_name": "lastName",
"email": "email",
"gender": "gender",
"gender_id": "gender_id",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert to gender:gender

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -12,7 +12,7 @@ class OrganizationUpdateActionTest(BaseActionTestCase):
"first_name": "firstName",
"last_name": "lastName",
"email": "email",
"gender": "gender",
"gender_id": "gender_id",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert to gender:gender

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@r-peschke r-peschke removed their assignment Aug 28, 2024
Copy link
Member

@r-peschke r-peschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just 2 little things in documentation.
I'll try to solve the user update problem.

```

## Action
Deletes the gender.
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

```

## Action
Updates the gender if a gender with that name doesn't exist.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add some text like The first 4 gender names are fixed and cannot be changed or delete

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@hjanott
Copy link
Member Author

hjanott commented Sep 5, 2024

I'll try to solve the user update problem.

Thank you. That was really helpful. I didn't think of adding it to the org like this.

@reiterl
Copy link
Member

reiterl commented Sep 11, 2024

Notice: Needs to be updated, to work with my pr in client.

Copy link
Member

@r-peschke r-peschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@r-peschke r-peschke removed their assignment Sep 18, 2024
@r-peschke r-peschke self-requested a review September 18, 2024 12:25
Copy link
Member

@r-peschke r-peschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No changes anymore by merging main

@rrenkert rrenkert added this pull request to the merge queue Sep 27, 2024
github-merge-queue bot pushed a commit that referenced this pull request Sep 27, 2024
* draft create update delete + tests + testupdates + migration

* update meta rep

* general error removal and improvement for draft

* remove meeting import error

* update meeting import so that checker removes gender_id

* general code improvements delete gender checks for back relation in organiziation

* md documentation + pleasing mypy

* use defaultdict

* use new in memory flag of datastore

* fix mypy error by upping datastore version

* change the permission from can_manage_organization to can_manage_users

* improve documentation

* lock result false + no orga check

* add test for gender import

* make name and org id required

* Use gender string for saml and meeting import. Refine gender actions and mixin. General code improvements.

* cleanup and documentation improvement

* beautify code

* add test update gender on user merge.

* update docs test for meeting import and saml account (+ new test) create gender for saml accounts

* updated meta

* meeting import create user with gender. export gender strings. improve tests.

* Separate test for gender on meeting import. General code improvements in saml, export, import and migration plus additional test for empty string.

* extend test for gender import, plus fixes. docs update

* improve user and gender updates/creation

* Gender will not be created without being used anymore. Fix error where import without any new genders would result in exception.

* Improve gender action documentation

* fixed typo in migration gender female

* update meta

---------

Co-authored-by: Ralf Peschke <ralf.peschke@intevation.de>
Co-authored-by: rrenkert <raimund@renkert.org>
@hjanott hjanott removed this pull request from the merge queue due to a manual request Sep 27, 2024
@rrenkert rrenkert added this pull request to the merge queue Sep 27, 2024
Merged via the queue into OpenSlides:main with commit 221e2d8 Sep 27, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature migration Introduces a new migration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve organization/genders
5 participants