Skip to content

Commit

Permalink
fix PROJECT_USER app setting remote sync (#1315, #1320)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Nov 1, 2023
1 parent 7a7e76e commit eaf280e
Show file tree
Hide file tree
Showing 4 changed files with 308 additions and 177 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)
- ``PROJECT_USER`` app settings remote sync failure (#1315)
- **Timeline**
- ``get_timestamp()`` template tag crash from missing ``ProjectEventStatus`` (#1297)
- **Userprofile**
Expand Down
1 change: 1 addition & 0 deletions docs/source/major_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ v0.13.3 (WIP)
- Add InvalidFormMixin helper mixin
- Fix hidden JSON project setting reset on non-superuser project update
- Fix custom app setting validation calls in forms
- Fix remote sync PROJECT_USER app settings updating
- General bug fixes and minor updates


Expand Down
24 changes: 22 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 @@ -235,6 +239,7 @@ def get_source_data(self, target_site):
]

# Get and add app settings for project
# NOTE: Default setting values are not synced
for a in AppSetting.objects.filter(project=project):
try:
sync_data = self._add_app_setting(sync_data, a, all_defs)
Expand Down Expand Up @@ -1044,8 +1049,22 @@ 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 may not be found if e.g. local users allowed but not created
user = User.objects.filter(username=ad['user_name']).first()
if not user:
logger.info(
'Skipping setting {}: User not found'.format(ad['name'])
)
return
# 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 Expand Up @@ -1074,6 +1093,7 @@ def _sync_app_setting(cls, uuid, set_data):
# Remove keys that are not available in the model
ad.pop('local', None)
ad.pop('project_uuid', None)
ad.pop('user_name', None) # TODO: Remove once user UUID support added
ad.pop('user_uuid', None)
# Add keys required for the model
ad['project'] = project
Expand Down
Loading

0 comments on commit eaf280e

Please sign in to comment.