mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-05 21:38:24 -04:00
Encapsulate view_activity logic within the form
This means that: - we don’t have to manually set it after processing the form - we can set it dynamically based on some other attribute later on
This commit is contained in:
@@ -257,6 +257,13 @@ class RegisterUserFromOrgInviteForm(StripWhitespaceForm):
|
||||
|
||||
|
||||
class PermissionsForm(StripWhitespaceForm):
|
||||
|
||||
def process(self, *args, **kwargs):
|
||||
super().process(*args, **kwargs)
|
||||
# view_activity is a default role to be added to all users.
|
||||
self.view_activity.data = True
|
||||
|
||||
view_activity = HiddenField("View activity")
|
||||
send_messages = BooleanField("Send messages from existing templates")
|
||||
manage_templates = BooleanField("Add and edit templates")
|
||||
manage_service = BooleanField("Modify this service and its team")
|
||||
|
||||
@@ -147,9 +147,4 @@ def cancel_invited_user(service_id, invited_user_id):
|
||||
|
||||
|
||||
def get_permissions_from_form(form):
|
||||
# view_activity is a default role to be added to all users.
|
||||
# All users will have at minimum view_activity to allow users to see notifications,
|
||||
# templates, team members but no update privileges
|
||||
selected_roles = {role for role in roles.keys() if form[role].data is True}
|
||||
selected_roles.add('view_activity')
|
||||
return selected_roles
|
||||
return {role for role in roles.keys() if form[role].data is True}
|
||||
|
||||
Reference in New Issue
Block a user