Skip to content

Commit

Permalink
add get_user_by_uuid() template tag, fix sync ui user settings (#1478)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Sep 3, 2024
1 parent d10867a commit 1e64769
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,23 @@ Unreleased
Added
-----

- **Projectroles**
- ``get_user_by_uuid()`` common template tag (#1478)

Changed
-------

- **Projectroles**
- Truncate app setting values in ``remoteproject_sync.html`` (#1474)
- JSON app setting value rendering in ``remoteproject_sync.html`` (#1472)

Fixed
-----

- **Projectroles**
- Incorrect app plugin link order in ``get_project_app_links()`` (#1468)
- Empty JSON value rendering in ``remoteproject_sync.html`` (#1472)
- Remote sync crash on updating user with additional email (#1476)
- User scope app setting display in ``remoteproject_sync.html`` (#1478)


v1.0.1 (2024-08-08)
Expand All @@ -44,7 +52,6 @@ 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
8 changes: 5 additions & 3 deletions projectroles/templates/projectroles/remoteproject_sync.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ <h4>
id="sodar-pr-remote-update-table-settings">
<thead>
<tr>
<th>{% get_display_name 'PROJECT' title=True %}</th>
<th>{% get_display_name 'PROJECT' title=True %}/User</th>
<th>Name</th>
<th>Plugin</th>
<th>Value</th>
Expand All @@ -244,8 +244,10 @@ <h4>
{% if p_obj %}
{% get_project_link p_obj full_title=True as p_link %}
{{ p_link | safe }}
{% else %}
{{ p.title }}
{% elif a.user_uuid %}
{% get_user_by_uuid a.user_uuid as u_obj %}
{% get_user_html u_obj as u_html %}
{{ u_html | safe }}
{% endif %}
</td>
<td>{{ a.name }}</td>
Expand Down
15 changes: 7 additions & 8 deletions projectroles/templatetags/projectroles_common_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,18 @@ def check_backend(name):
@register.simple_tag
def get_project_by_uuid(sodar_uuid):
"""Return Project by sodar_uuid"""
try:
return Project.objects.get(sodar_uuid=sodar_uuid)
except Project.DoesNotExist:
return None
return Project.objects.filter(sodar_uuid=sodar_uuid).first()


@register.simple_tag
def get_user_by_uuid(sodar_uuid):
"""Return SODARUser by sodar_uuid"""
return User.objects.filter(sodar_uuid=sodar_uuid).first()

@register.simple_tag
def get_user_by_username(username):
"""Return User by username"""
try:
return User.objects.get(username=username)
except User.DoesNotExist:
return None
return User.objects.filter(username=username).first()


# Django helpers ---------------------------------------------------------------
Expand Down
9 changes: 8 additions & 1 deletion projectroles/tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,20 @@ def test_check_backend(self):
self.assertEqual(c_tags.check_backend('sodar_cache'), True)
self.assertEqual(c_tags.check_backend('NON_EXISTING_PLUGIN'), False)

def test_get_projcet_by_uuid(self):
def test_get_project_by_uuid(self):
"""Test get_project_by_uuid()"""
self.assertEqual(
c_tags.get_project_by_uuid(self.project.sodar_uuid), self.project
)
self.assertEqual(c_tags.get_project_by_uuid(NON_EXISTING_UUID), None)

def test_get_user_by_uuid(self):
"""Test get_user_by_uuid()"""
self.assertEqual(
c_tags.get_user_by_uuid(self.user.sodar_uuid), self.user
)
self.assertEqual(c_tags.get_user_by_uuid(NON_EXISTING_UUID), None)

def test_get_user_by_username(self):
"""Test get_user_by_username()"""
self.assertEqual(
Expand Down

0 comments on commit 1e64769

Please sign in to comment.