Skip to content

Commit

Permalink
FEAT update CMS fields to allow user-specific permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewandante committed Jun 15, 2023
1 parent 2bbf15c commit 612b9f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
20 changes: 15 additions & 5 deletions code/Forms/AssetFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\TreeDropdownField;
use SilverStripe\Forms\TreeMultiselectField;
use SilverStripe\Security\InheritedPermissions;

abstract class AssetFormFactory implements FormFactory
{
Expand Down Expand Up @@ -349,15 +350,16 @@ protected function getFormFieldSecurityTab($record, $context = [])
{
// Get permissions
$viewersOptionsField = [
'Inherit' => _t(__CLASS__.'.INHERIT', 'Inherit from parent folder'),
'Anyone' => _t(__CLASS__.'.ANYONE', 'Anyone'),
'LoggedInUsers' => _t(__CLASS__.'.LOGGED_IN', 'Logged-in users'),
'OnlyTheseUsers' => _t(__CLASS__.'.ONLY_GROUPS', 'Only these groups (choose from list)')
InheritedPermissions::INHERIT => _t(__CLASS__.'.INHERIT', 'Inherit from parent folder'),
InheritedPermissions::ANYONE => _t(__CLASS__.'.ANYONE', 'Anyone'),
InheritedPermissions::LOGGED_IN_USERS => _t(__CLASS__.'.LOGGED_IN', 'Logged-in users'),
InheritedPermissions::ONLY_THESE_USERS => _t(__CLASS__.'.ONLY_GROUPS', 'Only these groups (choose from list)'),
InheritedPermissions::ONLY_THESE_MEMBERS => _t(__CLASS__.'.ONLY_MEMBERS', 'Only these users (choose from list)'),
];

// No "Anyone" editors option
$editorsOptionsField = $viewersOptionsField;
unset($editorsOptionsField['Anyone']);
unset($editorsOptionsField[InheritedPermissions::ANYONE]);

return Tab::create(
'Permissions',
Expand All @@ -370,6 +372,10 @@ protected function getFormFieldSecurityTab($record, $context = [])
'ViewerGroups',
_t(__CLASS__.'.VIEWERGROUPS', 'Viewer Groups')
),
TreeMultiselectField::create(
'ViewerMembers',
_t(__CLASS__.'.VIEWERMEMBERS', 'Viewer Users')
),
OptionsetField::create(
"CanEditType",
_t(__CLASS__.'.EDITHEADER', 'Who can edit this file?')
Expand All @@ -378,6 +384,10 @@ protected function getFormFieldSecurityTab($record, $context = [])
TreeMultiselectField::create(
'EditorGroups',
_t(__CLASS__.'.EDITORGROUPS', 'Editor Groups')
),
TreeMultiselectField::create(
'EditorMembers',
_t(__CLASS__.'.EDITORMEMBERS', 'Editor Users')
)
);
}
Expand Down
3 changes: 3 additions & 0 deletions lang/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,18 @@ en:
ANYONE: Anyone
EDITHEADER: 'Who can edit this file?'
EDITORGROUPS: 'Editor Groups'
EDITORMEMBERS: 'Editor Users'
FILENAME: Filename
FOLDERLOCATION: Location
INHERIT: 'Inherit from parent folder'
LOGGED_IN: 'Logged-in users'
ONLY_GROUPS: 'Only these groups (choose from list)'
ONLY_MEMBERS: 'Only these users (choose from list)'
ROOTNAME: '(Top level)'
SAVE: Save
SAVED: Saved
VIEWERGROUPS: 'Viewer Groups'
VIEWERMEMBERS: 'Viewer Users'
SilverStripe\AssetAdmin\Forms\FileFormFactory:
DOWNLOAD_FILE: 'Download file'
INSERT_LINK: 'Link to file'
Expand Down

0 comments on commit 612b9f4

Please sign in to comment.