Skip to content

Commit

Permalink
fix remote sync user additional email update (#1476)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Sep 3, 2024
1 parent e251836 commit d10867a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Fixed

- **Projectroles**
- ``BatchUpdateRolesMixin`` removal breaking tests in other repos (#1464)
- Remote sync crash on updating user with additional email (#1476)
- **Timeline**
- Deprecated link dict ``blank`` field assumed as mandatory (#1462)

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 @@ -18,6 +18,7 @@ Release Highlights

- Update app setting rendering in remote sync UI
- Fix project sidebar and dropdown app plugin link order
- Fix remote sync crash on updating user with additional email
- General bug fixes and minor updates


Expand Down
8 changes: 7 additions & 1 deletion projectroles/remote_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
AppSetting,
)
from projectroles.plugins import get_backend_api
from projectroles.utils import build_secret


app_settings = AppSettingAPI()
Expand Down Expand Up @@ -530,8 +531,13 @@ def _sync_user(self, uuid, user_data):
)
)
for e in add_emails:
if SODARUserAdditionalEmail.objects.filter(
user=user, email=e
).exists():
continue
# TODO: Remove redundant secret once #1477 is implemented
email_obj = SODARUserAdditionalEmail.objects.create(
user=user, email=e, verified=True
user=user, email=e, verified=True, secret=build_secret(16)
)
logger.info(
'Created user {} additional email "{}"'.format(
Expand Down
4 changes: 2 additions & 2 deletions projectroles/templates/projectroles/remoteproject_sync.html
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ <h4>
{% elif a.type == 'JSON' %}
<td class="text-muted font-italic">Empty</td>
{% elif a.type == 'BOOLEAN' %}
<td class="text-monospace">{% if a.value == '1' %}True{% else %}False{% endif %}</td>
<td><code>{% if a.value == '1' %}True{% else %}False{% endif %}</code></td>
{% else %}
<td class="text-monospace">{{ a.value | truncatechars:255 }}</td>
<td><code>{{ a.value | truncatechars:255 }}</code></td>
{% endif %}
<td>{{ a.status | title }}</td>
</tr>
Expand Down
17 changes: 17 additions & 0 deletions projectroles/tests/test_remote_project_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2398,6 +2398,23 @@ def test_update_user_add_email(self):
self.assertEqual(email.email, ADD_EMAIL)
self.assertEqual(email.verified, True)

def test_update_user_add_email_exists(self):
"""Test sync with existing additional email on user"""
target_user = User.objects.get(sodar_uuid=SOURCE_USER_UUID)
SODARUserAdditionalEmail.objects.create(
user=target_user,
email=ADD_EMAIL,
verified=True,
secret=build_secret(16),
)
self.assertEqual(SODARUserAdditionalEmail.objects.count(), 1)
remote_data = self.default_data
remote_data['users'][SOURCE_USER_UUID]['additional_emails'] = [
ADD_EMAIL
]
self.remote_api.sync_remote_data(self.source_site, remote_data)
self.assertEqual(SODARUserAdditionalEmail.objects.count(), 1)

def test_update_user_add_email_delete(self):
"""Test sync with deleting existing additional email on user"""
self.make_email(self.user_target, ADD_EMAIL)
Expand Down

0 comments on commit d10867a

Please sign in to comment.