Skip to content

Commit

Permalink
ENH update CMS fields to allow user-specific permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewandante committed Jul 6, 2023
1 parent 2bbf15c commit d48f81d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
25 changes: 20 additions & 5 deletions code/Forms/AssetFormFactory.php
Expand Up @@ -16,6 +16,7 @@
use SilverStripe\Forms\FormFactory;
use SilverStripe\Forms\HeaderField;
use SilverStripe\Forms\HiddenField;
use SilverStripe\Forms\ListboxField;
use SilverStripe\Forms\OptionsetField;
use SilverStripe\Forms\PopoverField;
use SilverStripe\Forms\ReadonlyField;
Expand All @@ -25,6 +26,8 @@
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\TreeDropdownField;
use SilverStripe\Forms\TreeMultiselectField;
use SilverStripe\Security\InheritedPermissions;
use SilverStripe\Security\Member;

abstract class AssetFormFactory implements FormFactory
{
Expand Down Expand Up @@ -349,15 +352,17 @@ 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]);
$membersMap = Member::get()->map('ID', 'Name');

return Tab::create(
'Permissions',
Expand All @@ -370,6 +375,11 @@ protected function getFormFieldSecurityTab($record, $context = [])
'ViewerGroups',
_t(__CLASS__.'.VIEWERGROUPS', 'Viewer Groups')
),
ListboxField::create(
'ViewerMembers',
_t(__CLASS__.'.VIEWERMEMBERS', 'Viewer Users'),
$membersMap
),
OptionsetField::create(
"CanEditType",
_t(__CLASS__.'.EDITHEADER', 'Who can edit this file?')
Expand All @@ -378,6 +388,11 @@ protected function getFormFieldSecurityTab($record, $context = [])
TreeMultiselectField::create(
'EditorGroups',
_t(__CLASS__.'.EDITORGROUPS', 'Editor Groups')
),
ListboxField::create(
'EditorMembers',
_t(__CLASS__.'.EDITORMEMBERS', 'Editor Users'),
$membersMap
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -5,7 +5,7 @@
"license": "BSD-3-Clause",
"require": {
"php": "^8.1",
"silverstripe/framework": "^5",
"silverstripe/framework": "^5.1",
"silverstripe/admin": "^2",
"silverstripe/graphql": "^5"
},
Expand Down
3 changes: 3 additions & 0 deletions lang/en.yml
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 d48f81d

Please sign in to comment.