Skip to content

Commit

Permalink
change the request to names for AppLinks utility class
Browse files Browse the repository at this point in the history
  • Loading branch information
gromdimon committed Apr 25, 2024
1 parent 3a97c54 commit 6bae19e
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 44 deletions.
13 changes: 11 additions & 2 deletions projectroles/templatetags/projectroles_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,19 @@ def get_admin_warning():
@register.simple_tag
def get_user_links(request):
"""Return user dropdown links"""
return app_links.get_user_links(request)
return app_links.get_user_links(
request.user,
app_name=request.resolver_match.app_name,
url_name=request.resolver_match.url_name,
)


@register.simple_tag
def get_project_app_links(request, project=None):
"""Return sidebar links"""
return app_links.get_project_app_links(request, project)
return app_links.get_project_app_links(
request.user,
project,
app_name=request.resolver_match.app_name,
url_name=request.resolver_match.url_name,
)
164 changes: 164 additions & 0 deletions projectroles/tests/test_views_ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,72 @@ def test_get(self):
}
self.assertEqual(response.json(), expected)

def test_get_app_links(self):
"""Test sidebar content retrieval with specific app links"""
with self.login(self.user):
response = self.client.get(
reverse(
'projectroles:ajax_sidebar',
kwargs={'project': self.project.sodar_uuid},
)
+ '?app_name=filesfolders&url_name=list'
)
self.assertEqual(response.status_code, 200)
expected = {
'links': [
{
'name': 'project-detail',
'url': f'/project/{self.project.sodar_uuid}',
'label': 'Project Overview',
'icon': 'mdi:cube',
'active': False,
},
{
'name': 'app-plugin-bgjobs',
'url': f'/bgjobs/list/{self.project.sodar_uuid}',
'label': 'Background Jobs',
'icon': 'mdi:server',
'active': False,
},
{
'name': 'app-plugin-example_project_app',
'url': f'/examples/project/{self.project.sodar_uuid}',
'label': 'Example Project App',
'icon': 'mdi:rocket-launch',
'active': False,
},
{
'name': 'app-plugin-filesfolders',
'url': f'/files/{self.project.sodar_uuid}',
'label': 'Files',
'icon': 'mdi:file',
'active': True,
},
{
'name': 'app-plugin-timeline',
'url': f'/timeline/{self.project.sodar_uuid}',
'label': 'Timeline',
'icon': 'mdi:clock-time-eight',
'active': False,
},
{
'name': 'project-roles',
'url': f'/project/members/{self.project.sodar_uuid}',
'label': 'Members',
'icon': 'mdi:account-multiple',
'active': False,
},
{
'name': 'project-update',
'url': f'/project/project/update/{self.project.sodar_uuid}',
'label': 'Update Project',
'icon': 'mdi:lead-pencil',
'active': False,
},
],
}
self.assertEqual(response.json(), expected)

def test_get_no_access(self):
"""Test sidebar content retrieval with no access"""
new_user = self.make_user('new_user')
Expand Down Expand Up @@ -721,6 +787,104 @@ def test_superuser(self):
}
self.assertEqual(response.json(), expected)

def test_superuser_app_links(self):
"""Test UserDropdownContentAjaxView with superuser"""
with self.login(self.user):
response = self.client.get(
reverse('projectroles:ajax_user_dropdown')
+ '?app_name=example_site_app&url_name=example'
)
self.assertEqual(response.status_code, 200)
expected = {
'links': [
{
'name': 'adminalerts',
'url': '/alerts/adm/list',
'label': 'Admin Alerts',
'icon': 'mdi:alert',
'active': False,
},
{
'name': 'appalerts',
'url': '/alerts/app/list',
'label': 'App Alerts',
'icon': 'mdi:alert-octagram',
'active': False,
},
{
'name': 'bgjobs_site',
'url': '/bgjobs/list',
'label': 'Site Background Jobs',
'icon': 'mdi:server',
'active': False,
},
{
'name': 'example_site_app',
'url': '/examples/site/example',
'label': 'Example Site App',
'icon': 'mdi:rocket-launch-outline',
'active': True,
},
{
'name': 'remotesites',
'url': '/project/remote/sites',
'label': 'Remote Site Access',
'icon': 'mdi:cloud-sync',
'active': False,
},
{
'name': 'siteinfo',
'url': '/siteinfo/info',
'label': 'Site Info',
'icon': 'mdi:bar-chart',
'active': False,
},
{
'name': 'timeline_site',
'url': '/timeline/site',
'label': 'Site-Wide Events',
'icon': 'mdi:clock-time-eight-outline',
'active': False,
},
{
'name': 'timeline_site_admin',
'url': '/timeline/site/all',
'label': 'All Timeline Events',
'icon': 'mdi:web-clock',
'active': False,
},
{
'name': 'tokens',
'url': '/tokens/',
'label': 'API Tokens',
'icon': 'mdi:key-chain-variant',
'active': False,
},
{
'name': 'userprofile',
'url': '/user/profile',
'label': 'User Profile',
'icon': 'mdi:account-details',
'active': False,
},
{
'name': 'admin',
'url': '/admin/',
'label': 'Django Admin',
'icon': 'mdi:cogs',
'active': False,
},
{
'name': 'sign-out',
'url': '/logout/',
'label': 'Logout',
'icon': 'mdi:logout-variant',
'active': False,
},
]
}
self.assertEqual(response.json(), expected)


class TestCurrentUserRetrieveAjaxView(SerializedObjectMixin, TestCase):
"""Tests for CurrentUserRetrieveAjaxView"""
Expand Down
Loading

0 comments on commit 6bae19e

Please sign in to comment.