From 2c8e8804507458716c0fda0c1cae9fce77bb2a01 Mon Sep 17 00:00:00 2001 From: Ethan Soergel Date: Mon, 13 Nov 2023 12:29:36 -0500 Subject: [PATCH 1/3] Rearrange user sidebar All user pages were filed under "Application Users" or "Project Users", but that dichotomy doesn't hold up very well today (not to mention the terminology is unorthodox). Mobile workers can also have roles, and web users will soon be able to have user data, and in the future likely groups too. This puts in a single "Users" section with both combined. --- corehq/tabs/tabclasses.py | 92 +++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 52 deletions(-) diff --git a/corehq/tabs/tabclasses.py b/corehq/tabs/tabclasses.py index fa41f7b9683e..bf54108172e3 100644 --- a/corehq/tabs/tabclasses.py +++ b/corehq/tabs/tabclasses.py @@ -1476,17 +1476,11 @@ def _is_viewable(self): or self.couch_user.can_view_web_users() ) - @property - def can_view_cloudcare(self): - return (has_privilege(self._request, privileges.CLOUDCARE) - and self.couch_user.is_domain_admin()) - @property def has_project_access(self): return has_privilege(self._request, privileges.PROJECT_ACCESS) - def _get_mobile_users_menu(self): - menu = [] + def _mobile_workers(self): if ((self.couch_user.can_edit_commcare_users() or self.couch_user.can_view_commcare_users()) and self.has_project_access): @@ -1507,7 +1501,7 @@ def _get_commcare_username(request=None, couch_user=None, MobileWorkerListView, ) - menu.append({ + return { 'title': _(MobileWorkerListView.page_title), 'url': reverse(MobileWorkerListView.urlname, args=[self.domain]), @@ -1531,13 +1525,14 @@ def _get_commcare_username(request=None, couch_user=None, 'urlname': ConfirmBillingAccountForExtraUsersView.urlname}, ], 'show_in_dropdown': True, - }) + } + def _groups(self): if ((self.couch_user.can_edit_groups() or self.couch_user.can_view_groups()) and self.has_project_access): is_view_only_subpage = (hasattr(self._request, 'is_view_only') and self._request.is_view_only) - menu.append({ + return { 'title': _('Groups'), 'url': reverse('all_groups', args=[self.domain]), 'description': _("""Create and manage @@ -1552,21 +1547,16 @@ def _get_commcare_username(request=None, couch_user=None, 'urlname': 'group_membership'} ], 'show_in_dropdown': True, - }) - - if self.can_view_cloudcare: - title = _("Web Apps Permissions") - menu.append({ - 'title': title, - 'url': reverse('cloudcare_app_settings', - args=[self.domain]) - }) - - return menu + } - def _get_project_users_menu(self): - menu = [] + def _web_apps_permissions(self): + if has_privilege(self._request, privileges.CLOUDCARE) and self.couch_user.is_domain_admin(): + return { + 'title': _("Web Apps Permissions"), + 'url': reverse('cloudcare_app_settings', args=[self.domain]), + } + def _web_users(self): if self.couch_user.can_edit_web_users() or self.couch_user.can_view_web_users(): def _get_web_username(request=None, couch_user=None, **context): if (couch_user.user_id != request.couch_user.user_id @@ -1578,23 +1568,12 @@ def _get_web_username(request=None, couch_user=None, **context): else: return None - from corehq.apps.users.views import ( - EditWebUserView, - EnterpriseUsersView, - ListWebUsersView, - ) + from corehq.apps.users.views import EditWebUserView, ListWebUsersView from corehq.apps.users.views.mobile.users import ( FilteredWebUserDownload, ) - if toggles.ENTERPRISE_USER_MANAGEMENT.enabled_for_request(self._request): - menu.append({ - 'title': _(EnterpriseUsersView.page_title), - 'url': reverse(EnterpriseUsersView.urlname, args=[self.domain]), - 'show_in_dropdown': True, - }) - - menu = menu + [{ + return { 'title': _(ListWebUsersView.page_title), 'url': reverse(ListWebUsersView.urlname, args=[self.domain]), @@ -1619,22 +1598,28 @@ def _get_web_username(request=None, couch_user=None, **context): }, ], 'show_in_dropdown': True, - }] + } + def _enterprise_users(self): + from corehq.apps.users.views import EnterpriseUsersView + if toggles.ENTERPRISE_USER_MANAGEMENT.enabled_for_request(self._request): + return { + 'title': _(EnterpriseUsersView.page_title), + 'url': reverse(EnterpriseUsersView.urlname, args=[self.domain]), + 'show_in_dropdown': True, + } + + def _roles_and_permissions(self): if ((self.couch_user.is_domain_admin() or self.couch_user.can_view_roles()) and self.has_project_access): from corehq.apps.users.views import ListRolesView - menu.append({ + return { 'title': _(ListRolesView.page_title), - 'url': reverse(ListRolesView.urlname, - args=[self.domain]), - 'description': _( - "View and manage user roles."), + 'url': reverse(ListRolesView.urlname, args=[self.domain]), + 'description': _("View and manage user roles."), 'subpages': [], 'show_in_dropdown': True, - }) - - return menu + } def _get_locations_menu(self): if (not has_privilege(self._request, privileges.LOCATIONS) @@ -1716,13 +1701,16 @@ def _get_locations_menu(self): def sidebar_items(self): items = [] - mobile_users_menu = self._get_mobile_users_menu() - if mobile_users_menu: - items.append((_('Application Users'), mobile_users_menu)) - - project_users_menu = self._get_project_users_menu() - if project_users_menu: - items.append((_('Project Users'), project_users_menu)) + users_menu = filter(None, [ + self._enterprise_users(), + self._mobile_workers(), + self._web_users(), + self._roles_and_permissions(), + self._groups(), + self._web_apps_permissions(), + ]) + if users_menu: + items.append((_('Users'), users_menu)) locations_menu = self._get_locations_menu() if locations_menu: From d45456d2a37978a5841325b3a68217316ad445ff Mon Sep 17 00:00:00 2001 From: Ethan Soergel Date: Mon, 13 Nov 2023 14:44:29 -0500 Subject: [PATCH 2/3] Move User Fields page to sidebar --- corehq/apps/users/templates/users/mobile_workers.html | 6 ------ corehq/tabs/tabclasses.py | 10 ++++++++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/corehq/apps/users/templates/users/mobile_workers.html b/corehq/apps/users/templates/users/mobile_workers.html index ae7295e11f5a..11d0530e9002 100644 --- a/corehq/apps/users/templates/users/mobile_workers.html +++ b/corehq/apps/users/templates/users/mobile_workers.html @@ -98,12 +98,6 @@ {% trans "Bulk Upload" %} {% endif %} - {% if can_add_extra_users and can_access_all_locations %} - - - {% trans "Edit User Fields" %} - - {% endif %} {% if request|toggle_enabled:"CLEAR_MOBILE_WORKER_DATA" %} diff --git a/corehq/tabs/tabclasses.py b/corehq/tabs/tabclasses.py index bf54108172e3..079f491a0d13 100644 --- a/corehq/tabs/tabclasses.py +++ b/corehq/tabs/tabclasses.py @@ -1516,8 +1516,6 @@ def _get_commcare_username(request=None, couch_user=None, 'urlname': 'delete_commcare_users'}, {'title': _('Bulk Lookup'), 'urlname': 'commcare_users_lookup'}, - {'title': _('Edit User Fields'), - 'urlname': 'user_fields_view'}, {'title': _('Filter and Download Mobile Workers'), 'urlname': 'filter_and_download_commcare_users'}, {'title': _( @@ -1527,6 +1525,13 @@ def _get_commcare_username(request=None, couch_user=None, 'show_in_dropdown': True, } + def _user_fields(self): + if self.can_access_all_locations and self.couch_user.can_edit_commcare_users(): + return { + 'title': _("Edit User Fields"), + 'url': reverse('user_fields_view', args=[self.domain]), + } + def _groups(self): if ((self.couch_user.can_edit_groups() or self.couch_user.can_view_groups()) and self.has_project_access): @@ -1706,6 +1711,7 @@ def sidebar_items(self): self._mobile_workers(), self._web_users(), self._roles_and_permissions(), + self._user_fields(), self._groups(), self._web_apps_permissions(), ]) From b3fe04a026f2d006d08893df8a5d3e0e4ee1cdf9 Mon Sep 17 00:00:00 2001 From: Ethan Soergel Date: Mon, 13 Nov 2023 17:32:33 -0500 Subject: [PATCH 3/3] Move URL out of commcare prefix Otherwise both items are highlighted on the sidebar now that this is no longer a subpage --- corehq/apps/users/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/corehq/apps/users/urls.py b/corehq/apps/users/urls.py index 4191f4e30e71..ca8c9ec49833 100644 --- a/corehq/apps/users/urls.py +++ b/corehq/apps/users/urls.py @@ -149,7 +149,7 @@ ] + [ url(r'^commcare/$', MobileWorkerListView.as_view(), name=MobileWorkerListView.urlname), url(r'^commcare/json/$', paginate_mobile_workers, name='paginate_mobile_workers'), - url(r'^commcare/fields/$', waf_allow('XSS_BODY')(UserFieldsView.as_view()), name=UserFieldsView.urlname), + url(r'^user_data/$', waf_allow('XSS_BODY')(UserFieldsView.as_view()), name=UserFieldsView.urlname), url( r'^commcare/account/(?P[ \w-]+)/$', EditCommCareUserView.as_view(),