Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve instructions for deprecated "Web Apps Permissions" feature #35245

Merged
merged 11 commits into from
Oct 24, 2024
Merged
4 changes: 4 additions & 0 deletions corehq/apps/cloudcare/static/cloudcare/js/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';

Check warning on line 1 in corehq/apps/cloudcare/static/cloudcare/js/config.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

'use strict' is unnecessary inside of modules
hqDefine("cloudcare/js/config", [
'jquery',
'underscore',
Expand Down Expand Up @@ -45,6 +45,7 @@
self.restrict = addJsonAccess(ko.observable());
self.app_groups = ko.observableArray();
self._lock = ko.observable(false);
self.disable_feature_flag = ko.observable(false);
};
ApplicationAccess.wrap = function (o) {
var self = new ApplicationAccess();
Expand Down Expand Up @@ -91,6 +92,9 @@
data: ko.mapping.toJSON(self.applicationAccess),
success: function (data) {
self.applicationAccess._rev = data._rev;
if (data.redirect_url) {
window.location.href = data.redirect_url;
}
},
});
},
Expand Down
52 changes: 48 additions & 4 deletions corehq/apps/cloudcare/templates/cloudcare/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,48 @@
<h2>{% trans 'Manage Web Apps Permissions' %}</h2>
<div class="alert alert-danger">
{% url "roles_and_permissions" domain as roles_url %}
{% url "mobile_workers" domain as mobile_workers_url %}
{% blocktrans %}
This feature is deprecated. Access to specific web apps can now be managed via
<a target="_blank" href="{{ roles_url }}">Roles & Permissions</a>.
<br /><br />
Please avoid using <em>both</em> this configuration and Roles & Permissions to manage access.
Please contact <a href="mailto:{{ SUPPORT_EMAIL }}">CommCare Support</a> if you need assistance
setting up access via Roles & Permissions.
<br/><br/>
<h5>Transitioning from the Deprecated Feature to Roles & Permissions</h5>

<p>
For the simplest case where each mobile worker belongs to only one group, follow the steps below.
For more complex cases, please contact <a href="mailto:{{ SUPPORT_EMAIL }}">CommCare Support</a> for assistance
setting up access via Roles & Permissions.
</p>

<ol>
<li>
<strong>Set up a role for each group</strong><br/>
Create a corresponding role in the <a target="_blank" href="{{ roles_url }}">Roles & Permissions</a> page for every existing group.
</li>
<li>
<strong>Configure permissions for each role</strong><br/>
Ensure that each role is granted the same permissions and access to apps that were previously available to the corresponding group.
</li>
<li>
<strong>Assign mobile workers to their new roles</strong><br/>
Map each <a target="_blank" href="{{ mobile_workers_url }}">mobile worker</a> to the appropriate role that matches their previous group membership.
</li>
<li>
<strong>Enable Roles & Permissions for Web Apps access</strong><br/>
On this page, select the option to "Use Roles & Permissions to manage Web Apps access" and click <strong>Save</strong>.
</li>
<li>
<strong>Test access for mobile workers</strong><br/>
Verify that all mobile workers can access the apps as expected, based on their assigned roles.
</li>
<li>
<strong>(Optional) Deactivate the deprecated feature</strong><br/>
Disable this feature to avoid accidentally re-enabling it in the future.
Simply check the box to turn it off and click <strong>Save</strong>.
</li>
</ol>
{% endblocktrans %}
</div>
<section id="cloudcare-app-settings" style="display: none">
Expand All @@ -28,13 +63,22 @@ <h2>{% trans 'Manage Web Apps Permissions' %}</h2>
<div class="form-check">
<input class="form-check-input" type="radio" value="false" data-bind="checked: restrict.JSON" id="radioFalse"/>
<label class="form-check-label" for="radioFalse">
{% blocktrans %}Allow all mobile workers to see all Web Apps applications.{% endblocktrans %}
{% blocktrans %}Use Roles & Permissions to manage Web Apps access{% endblocktrans %}
</label>
</div>
<div class="form-check ms-3" data-bind="visible: !restrict()">
<input type="checkbox" class="form-check-input" data-bind="checked: disable_feature_flag" id="disable_ff"/>
<label class="form-check-label" for="disable_ff">
{% blocktrans %}
Web Apps permissions have been transferred to "Roles & Permissions", and this deprecated feature can be turned off.
Please note that once you "save", you will no longer have access to this page.
{% endblocktrans %}
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" value="true" data-bind="checked: restrict.JSON" id="radioTrue"/>
<label class="form-check-label" for="radioTrue">
{% blocktrans %}Customize each mobile worker's access to Web Apps{% endblocktrans %}
{% blocktrans %}Manage Web Apps access for each mobile worker based on their group{% endblocktrans %}
</label>
</div>
<div data-bind="visible: restrict">
Expand Down
11 changes: 10 additions & 1 deletion corehq/apps/cloudcare/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
from corehq.apps.users.decorators import require_can_login_as
from corehq.apps.users.models import CouchUser
from corehq.apps.users.util import get_complete_username
from corehq.apps.users.views import BaseUserSettingsView
from corehq.apps.users.views import BaseUserSettingsView, ListRolesView
from corehq.util.metrics import metrics_counter, metrics_histogram


Expand Down Expand Up @@ -410,12 +410,21 @@ def put(self, request, *args, **kwargs):
body = json.loads(request.body.decode('utf-8'))
access = get_application_access_for_domain(self.domain)
access.restrict = body['restrict']
disable_ff = body['disable_feature_flag']
access.sqlappgroup_set.all().delete()
access.sqlappgroup_set.set([
SQLAppGroup(app_id=app_group['app_id'], group_id=app_group.get('group_id'))
for app_group in body['app_groups']
], bulk=False)
access.save()
if disable_ff and not access.restrict:
toggles.WEB_APPS_PERMISSIONS_VIA_GROUPS.set(self.domain, False, namespace=toggles.NAMESPACE_DOMAIN)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hooray

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love to see it

# This view is not accessible after the FF is disabled
redirect_url = reverse(ListRolesView.urlname, args=[self.domain])
return JsonResponse({
'success': 1,
'redirect_url': redirect_url,
})
return json_response({'success': 1})


Expand Down
7 changes: 5 additions & 2 deletions corehq/apps/users/static/users/js/roles.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';

Check warning on line 1 in corehq/apps/users/static/users/js/roles.js

View workflow job for this annotation

GitHub Actions / Lint Javascript

'use strict' is unnecessary inside of modules

hqDefine('users/js/roles',[
'jquery',
Expand Down Expand Up @@ -206,6 +206,7 @@
self.preventRoleDelete = data.preventRoleDelete;
self.hasUnpermittedLocationRestriction = data.has_unpermitted_location_restriction || false;


self.restrictRoleChecked = ko.computed(function () {
return data.manageRoleAssignments.specific.some(role => role.value() && !role.access_all_locations);
});
Expand Down Expand Up @@ -578,15 +579,16 @@
}
),
];

self.webAppsPermissions = selectPermissionModel(
let webAppsPermissions = selectPermissionModel(
'access_web_apps',
self.accessWebAppsPermission,
{
permissionText: gettext("Use Web Apps for online data entry"),
listHeading: gettext("Select which web apps the role has access to:"),
}
);
webAppsPermissions.hasRestrictedApplicationAccess = root.hasRestrictedApplicationAccess;
self.webAppsPermissions = webAppsPermissions;

// Automatically disable "Access APIs" when "Full Organization Access" is disabled
self.permissions.access_all_locations.subscribe(() => {
Expand Down Expand Up @@ -666,6 +668,7 @@
self.attendanceTrackingPrivilege = o.attendanceTrackingPrivilege;
self.unlockLinkedRoles = ko.observable(false);
self.canEditLinkedData = o.canEditLinkedData;
self.hasRestrictedApplicationAccess = o.hasRestrictedApplicationAccess;

self.userRoles = ko.observableArray(ko.utils.arrayMap(o.userRoles, function (userRole) {
return UserRole.wrap(userRole);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ hqDefine("users/js/roles_and_permissions",[
dataRegistryChoices: initialPageData.get("data_registry_choices"),
canEditLinkedData: initialPageData.get("can_edit_linked_data"),
commcareAnalyticsRoles: initialPageData.get('commcare_analytics_roles'),
hasRestrictedApplicationAccess: initialPageData.get('has_restricted_application_access'),
});
});
});
23 changes: 15 additions & 8 deletions corehq/apps/users/templates/users/partials/edit_role_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,19 @@ <h4 class="modal-title" data-bind="text: modalTitle"></h4>
</div>

<script type="text/html" id="permission_all_selected_none">
<div class="form-group">
<label class="col-sm-4 control-label" data-bind="text: text"></label>
<div class="form-group" data-bind="css: {'has-warning': id === 'access_web_apps' && hasRestrictedApplicationAccess}">
<div class="col-sm-4 control-label">
<label data-bind="text: text"></label>
<!-- ko if: id === 'access_web_apps' && hasRestrictedApplicationAccess -->
<span class='help-block'>
{% url "cloudcare_app_settings" domain as manage_web_apps_permissions_url %}
{% blocktrans %}
This permission is already configured via <a target="_blank" href="{{ manage_web_apps_permissions_url }}">Manage Web Apps Permissions</a>.
Please remove this configuration before updating access here.
{% endblocktrans %}
</span>
<!-- /ko -->
</div>
<div class="col-sm-8 controls">
<select class="form-control" data-bind="
attr: { 'id': id },
Expand All @@ -588,12 +599,8 @@ <h4 class="modal-title" data-bind="text: modalTitle"></h4>
<option value="none" data-bind="text: accessNoneText"></option>
<option value="all" data-bind="text: accessAllText"></option>
<option value="selected" data-bind="text: accessSelectedText"></option>
</select>
</div>
</div>
<div class="form-group" data-bind="visible: showItems, css: {'has-error': hasError()}">
<div class="col-sm-8 col-sm-offset-4 controls">
<div class="panel panel-default">
</select>
<div class="panel panel-default"data-bind="visible: showItems, css: {'has-error': hasError()}" style="margin-top: 15px;">
<div class="panel-heading" data-bind="text: listHeading"></div>
<div class="panel-body">
<div data-bind="foreach: specific, slideVisible: showItems">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
{% initial_page_data "data_registry_choices" data_registry_choices %}
{% initial_page_data "can_edit_linked_data" can_edit_linked_data %}
{% initial_page_data "commcare_analytics_roles" commcare_analytics_roles %}
{% initial_page_data "has_restricted_application_access" has_restricted_application_access %}

<p class="lead">
{% if can_edit_roles %}
Expand Down
6 changes: 5 additions & 1 deletion corehq/apps/users/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from couchdbkit.exceptions import ResourceNotFound
from crispy_forms.utils import render_crispy_form

from corehq.apps.cloudcare.dbaccessors import get_cloudcare_apps
from corehq.apps.cloudcare.dbaccessors import get_cloudcare_apps, get_application_access_for_domain
from corehq.apps.custom_data_fields.edit_entity import CustomDataEditor
from corehq.apps.custom_data_fields.models import CustomDataFieldsProfile, CustomDataFieldsDefinition
from corehq.apps.registry.utils import get_data_registry_dropdown_options
Expand Down Expand Up @@ -779,6 +779,10 @@ def page_context(self):
'export_ownership_enabled': domain_has_privilege(self.domain, privileges.EXPORT_OWNERSHIP),
'data_registry_choices': get_data_registry_dropdown_options(self.domain),
'commcare_analytics_roles': _commcare_analytics_roles_options(),
'has_restricted_application_access': (
get_application_access_for_domain(self.domain).restrict
and toggles.WEB_APPS_PERMISSIONS_VIA_GROUPS.enabled(self.domain)
),
}


Expand Down
Loading