Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/es/user-sidebar' into autostaging
Browse files Browse the repository at this point in the history
  • Loading branch information
gherceg committed Nov 17, 2023
2 parents e20838a + b3fe04a commit 26948ef
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 61 deletions.
6 changes: 0 additions & 6 deletions corehq/apps/users/templates/users/mobile_workers.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@
<i class="fa fa-cloud-upload"></i> {% trans "Bulk Upload" %}
</a>
{% endif %}
{% if can_add_extra_users and can_access_all_locations %}
<a class="btn btn-default" href="{% url "user_fields_view" domain %}" id="btn-edit_user_fields">
<i class="fa fa-edit"></i>
{% trans "Edit User Fields" %}
</a>
{% endif %}
{% if request|toggle_enabled:"CLEAR_MOBILE_WORKER_DATA" %}
<a id="clear-data" class="btn btn-danger" href="{% url "clear_commcare_users" domain %}">
<i class="fa fa-eraser"></i>
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<couch_user_id>[ \w-]+)/$',
EditCommCareUserView.as_view(),
Expand Down
102 changes: 48 additions & 54 deletions corehq/tabs/tabclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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]),
Expand All @@ -1522,22 +1516,28 @@ 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': _(
ConfirmBillingAccountForExtraUsersView.page_title),
'urlname': ConfirmBillingAccountForExtraUsersView.urlname},
],
'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):
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
Expand All @@ -1552,21 +1552,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
Expand All @@ -1578,23 +1573,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]),
Expand All @@ -1619,22 +1603,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)
Expand Down Expand Up @@ -1716,13 +1706,17 @@ 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._user_fields(),
self._groups(),
self._web_apps_permissions(),
])
if users_menu:
items.append((_('Users'), users_menu))

locations_menu = self._get_locations_menu()
if locations_menu:
Expand Down

0 comments on commit 26948ef

Please sign in to comment.