Relabel existing permissions

Since we have added a new, 5th permission the existing permissions
should be relabelled so that the five make sense as a coherent set.

We especially want to make sure that:
- the labels work against the checkboxes and against the tick/crosses on
  the manage users page (a long time ago this page was layed out
  differently so didn’t have space for full labels)
- there is no confusion between usage and reports

This commit also:
- re-adds a line about what all users can see (‘sent messages’) but
  continues to omit the additional bullet points about templates and
  team members (because we think this is clear enough from reading the
  permissions)
- refactors the `Form` subclass so that the content and order of the
  permissions only have to be defined once
- brings back the ‘permissions’ legend on the `fieldset`
This commit is contained in:
Chris Hill-Scott
2018-08-08 08:45:58 +01:00
parent 5108187cab
commit 347912876c
6 changed files with 76 additions and 75 deletions

View File

@@ -40,7 +40,7 @@ from app.main.validators import (
ValidEmail,
ValidGovEmail,
)
from app.notify_client.models import roles
from app.notify_client.models import permissions, roles
from app.utils import guess_name_from_email_address
@@ -256,13 +256,12 @@ class RegisterUserFromOrgInviteForm(StripWhitespaceForm):
auth_type = HiddenField('auth_type', validators=[DataRequired()])
class PermissionsForm(StripWhitespaceForm):
PermissionsAbstract = type("PermissionsAbstract", (StripWhitespaceForm,), {
permission: BooleanField(label) for permission, label in permissions
})
view_activity = BooleanField("See dashboard and reports")
send_messages = BooleanField("Send messages")
manage_templates = BooleanField("Add and edit templates")
manage_service = BooleanField("Manage this service and its team")
manage_api_keys = BooleanField("Manage API keys")
class PermissionsForm(PermissionsAbstract):
login_authentication = RadioField(
'Sign in using',
@@ -277,6 +276,10 @@ class PermissionsForm(StripWhitespaceForm):
def permissions(self):
return {role for role in roles.keys() if self[role].data is True}
@property
def permissions_fields(self):
return (getattr(self, permission) for permission, _ in permissions)
@classmethod
def from_user(cls, user, service_id):
return cls(