Skip to content

Commit

Permalink
Merge pull request #2862 from andrewandante/FEAT_add_cms_interface_fo…
Browse files Browse the repository at this point in the history
…r_user_inherited_permission

FEAT update SiteTree permissions in CMS
  • Loading branch information
GuySartorelli authored Jul 6, 2023
2 parents 06d39c2 + 14eb767 commit e91b7c7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
36 changes: 35 additions & 1 deletion code/Model/SiteTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use SilverStripe\Forms\GridField\GridFieldDataColumns;
use SilverStripe\Forms\GridField\GridFieldLazyLoader;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Forms\ListboxField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\OptionsetField;
use SilverStripe\Forms\Tab;
Expand Down Expand Up @@ -1187,6 +1188,14 @@ public function canView($member = null)
return true;
}

// check for specific users
if ($this->CanViewType === InheritedPermissions::ONLY_THESE_MEMBERS
&& $member
&& $this->ViewerMembers()->filter('ID', $member->ID)->count() > 0
) {
return true;
}

return false;
}

Expand Down Expand Up @@ -2238,6 +2247,7 @@ public function getSettingsFields()
};
$viewAllGroupsMap = $mapFn(Permission::get_groups_by_permission(['SITETREE_VIEW_ALL', 'ADMIN']));
$editAllGroupsMap = $mapFn(Permission::get_groups_by_permission(['SITETREE_EDIT_ALL', 'ADMIN']));
$membersMap = Member::get()->map('ID', 'Name');

$fields = new FieldList(
$rootTab = new TabSet(
Expand Down Expand Up @@ -2269,6 +2279,11 @@ public function getSettingsFields()
_t(__CLASS__.'.VIEWERGROUPS', "Viewer Groups"),
Group::class
),
$viewerMembersField = ListboxField::create(
"ViewerMembers",
_t(__CLASS__.'.VIEWERMEMBERS', "Viewer Users"),
$membersMap,
),
$editorsOptionsField = new OptionsetField(
"CanEditType",
_t(__CLASS__.'.EDITHEADER', "Who can edit this page?")
Expand All @@ -2277,6 +2292,11 @@ public function getSettingsFields()
"EditorGroups",
_t(__CLASS__.'.EDITORGROUPS', "Editor Groups"),
Group::class
),
$editorMembersField = ListboxField::create(
"EditorMembers",
_t(__CLASS__.'.EDITORMEMBERS', "Editor Users"),
$membersMap
)
)
)
Expand Down Expand Up @@ -2317,6 +2337,10 @@ public function getSettingsFields()
__CLASS__.'.ACCESSONLYTHESE',
"Only these groups (choose from list)"
),
InheritedPermissions::ONLY_THESE_MEMBERS => _t(
__CLASS__.'.ACCESSONLYMEMBERS',
"Only these users (choose from list)"
),
];
$viewersOptionsField->setSource($viewersOptionsSource);

Expand All @@ -2343,17 +2367,27 @@ public function getSettingsFields()

if (!Permission::check('SITETREE_GRANT_ACCESS')) {
$fields->makeFieldReadonly($viewersOptionsField);
if ($this->CanEditType === InheritedPermissions::ONLY_THESE_USERS) {
if ($this->CanViewType === InheritedPermissions::ONLY_THESE_USERS) {
$fields->makeFieldReadonly($viewerGroupsField);
$fields->removeByName('ViewerMembers');
} elseif ($this->CanViewType === InheritedPermissions::ONLY_THESE_MEMBERS) {
$fields->makeFieldReadonly($viewerMembersField);
$fields->removeByName('ViewerGroups');
} else {
$fields->removeByName('ViewerGroups');
$fields->removeByName('ViewerMembers');
}

$fields->makeFieldReadonly($editorsOptionsField);
if ($this->CanEditType === InheritedPermissions::ONLY_THESE_USERS) {
$fields->makeFieldReadonly($editorGroupsField);
$fields->removeByName('EditorMembers');
} elseif ($this->CanEditType === InheritedPermissions::ONLY_THESE_MEMBERS) {
$fields->makeFieldReadonly($editorMembersField);
$fields->removeByName('EditorGroups');
} else {
$fields->removeByName('EditorGroups');
$fields->removeByName('EditorMembers');
}
}

Expand Down
3 changes: 3 additions & 0 deletions lang/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ en:
ACCESSANYONE: Anyone
ACCESSHEADER: 'Who can view this page?'
ACCESSLOGGEDIN: 'Logged-in users'
ACCESSONLYMEMBERS: 'Only these users (choose from list)'
ACCESSONLYTHESE: 'Only these groups (choose from list)'
ADDEDTODRAFTHELP: 'Page has not been published yet'
ADDEDTODRAFTSHORT: Draft
Expand Down Expand Up @@ -200,6 +201,7 @@ en:
DependtPageColumnLinkType: 'Link type'
EDITHEADER: 'Who can edit this page?'
EDITORGROUPS: 'Editor Groups'
EDITORMEMBERS: 'Editor Users'
EDITOR_GROUPS_FIELD_DESC: 'Groups with global edit permissions: {groupList}'
EDIT_ALL_DESCRIPTION: 'Edit any page'
EDIT_ALL_HELP: 'Ability to edit any page on the site, regardless of the settings on the Access tab. Requires the "Access to ''Pages'' section" permission'
Expand Down Expand Up @@ -257,6 +259,7 @@ en:
URLSegment: 'URL segment'
UntitledDependentObject: 'Untitled {instanceType}'
VIEWERGROUPS: 'Viewer Groups'
VIEWERMEMBERS: 'Viewer Users'
VIEWER_GROUPS_FIELD_DESC: 'Groups with global view permissions: {groupList}'
VIEW_ALL_DESCRIPTION: 'View any page'
VIEW_ALL_HELP: 'Ability to view any page on the site, regardless of the settings on the Access tab. Requires the "Access to ''Pages'' section" permission'
Expand Down

0 comments on commit e91b7c7

Please sign in to comment.