From f193b70176a8b0c31bcaf5229e4fba91a0c34301 Mon Sep 17 00:00:00 2001 From: Mikko Nieminen Date: Tue, 31 Oct 2023 18:28:40 +0100 Subject: [PATCH] fix user app settings remote sync crash (wip) (#1315, #1320) --- CHANGELOG.rst | 2 ++ projectroles/remote_projects.py | 16 ++++++++++++++-- projectroles/tests/test_remote_projects_api.py | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 44b0db79..d5c0c00d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,7 @@ Added - **Projectroles** - ``_project_badge.html`` template (#1300) - ``InvalidFormMixin`` helper mixin (#1310) + - Temporary ``user_name`` param in remote sync app settings (#1320) Changed ------- @@ -37,6 +38,7 @@ Fixed - Unhandled exceptions in ``validate_form_app_settings()`` calls (#1306) - ``validate_form_app_settings()`` results handling crash in ``ProjectForm`` (#1307) - ``RoleAssignment`` provided to ``validate_form_app_settings()`` in ``ProjectForm`` (#1308) + - ``USER`` and ``PROJECT_USER`` app settings remote sync failure (#1315) - **Timeline** - ``get_timestamp()`` template tag crash from missing ``ProjectEventStatus`` (#1297) - **Userprofile** diff --git a/projectroles/remote_projects.py b/projectroles/remote_projects.py index e6b46577..e82e2bbf 100644 --- a/projectroles/remote_projects.py +++ b/projectroles/remote_projects.py @@ -184,6 +184,7 @@ def _add_app_setting(cls, sync_data, app_setting, all_defs): .get(app_setting.name, {}) .get('local', APP_SETTING_LOCAL_DEFAULT) ) + # TODO: Remove user_name once #1316 and #1317 are implemented sync_data['app_settings'][str(app_setting.sodar_uuid)] = { 'name': app_setting.name, 'type': app_setting.type, @@ -198,6 +199,9 @@ def _add_app_setting(cls, sync_data, app_setting, all_defs): 'user_uuid': app_setting.user.sodar_uuid if app_setting.user else None, + 'user_name': app_setting.user.username + if app_setting.user + else None, 'local': local, } return sync_data @@ -1044,8 +1048,16 @@ def _sync_app_setting(cls, uuid, set_data): if ad['project_uuid']: project = Project.objects.get(sodar_uuid=ad['project_uuid']) - if ad['user_uuid']: - user = User.objects.get(sodar_uuid=ad['user_uuid']) + # TODO: Use UUID for LDAP users once #1316 and #1317 are implemented + if ad.get('user_name'): + user = User.objects.get(username=ad['user_name']) + # Skip for now, as UUIDs have not been correctly synced + # TODO: Remove skip after #1316 and #1317 + elif ad['user_uuid']: + logger.info( + 'Skipping setting {}: user_name not present'.format(ad['name']) + ) + return try: obj = AppSetting.objects.get( diff --git a/projectroles/tests/test_remote_projects_api.py b/projectroles/tests/test_remote_projects_api.py index 793e241d..5e22abb7 100644 --- a/projectroles/tests/test_remote_projects_api.py +++ b/projectroles/tests/test_remote_projects_api.py @@ -1969,3 +1969,5 @@ def test_update_no_changes(self): 'status' ] = 'updated' self.assertEqual(original_data, remote_data) + + # TODO: Test for USER and PROJECT_USER settings