Skip to content

Commit

Permalink
fix user app settings remote sync crash (wip) (#1315, #1320)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Oct 31, 2023
1 parent 7a7e76e commit f193b70
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand All @@ -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**
Expand Down
16 changes: 14 additions & 2 deletions projectroles/remote_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions projectroles/tests/test_remote_projects_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f193b70

Please sign in to comment.