mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-16 20:49:00 -04:00
Display nested folders permissions form on user permissions page
We're reusing the logic for the `move_to` nested radios field for the user folder permissions nested checkboxes. The main difference between the two forms (aside from the different input type) is that "Move" form contains the root "Templates" as an option, whereas the folder permissions doesn't. It turns out that, because of the way NestedFieldMixin.children and select_nested macro are implemented the easiest way to get the desired folder permissions behaviour is to add the root folder as a choice with a `None` value and `NONE_OPTION_VALUE = None` set on the field, which allows the `child_map` to be constructed but doesn't display the root folder checkbox itself since it gets overwritten in the final `child_map`.
This commit is contained in:
committed by
Alexey Bezhan
parent
340fd021bb
commit
7413423243
@@ -418,6 +418,15 @@ PermissionsAbstract = type("PermissionsAbstract", (StripWhitespaceForm,), {
|
||||
|
||||
|
||||
class PermissionsForm(PermissionsAbstract):
|
||||
def __init__(self, all_template_folders=None, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
if all_template_folders:
|
||||
self.folder_permissions.all_template_folders = all_template_folders
|
||||
self.folder_permissions.choices = [
|
||||
(item['id'], item['name']) for item in ([{'name': 'Templates', 'id': None}] + all_template_folders)
|
||||
]
|
||||
|
||||
folder_permissions = NestedCheckboxesField('Folder permissions')
|
||||
|
||||
login_authentication = RadioField(
|
||||
'Sign in using',
|
||||
@@ -437,8 +446,9 @@ class PermissionsForm(PermissionsAbstract):
|
||||
return (getattr(self, permission) for permission, _ in permissions)
|
||||
|
||||
@classmethod
|
||||
def from_user(cls, user, service_id):
|
||||
def from_user(cls, user, service_id, **kwargs):
|
||||
return cls(
|
||||
**kwargs,
|
||||
**{
|
||||
role: user.has_permission_for_service(service_id, role)
|
||||
for role in roles.keys()
|
||||
|
||||
Reference in New Issue
Block a user