Skip to content

Commit

Permalink
ENH Use SearchableMultiDropdownField
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Dec 14, 2023
1 parent 805341b commit 24b7aa7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
24 changes: 15 additions & 9 deletions code/SiteConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use SilverStripe\Security\Security;
use SilverStripe\View\TemplateGlobalProvider;
use SilverStripe\CMS\Controllers\CMSMain;
use SilverStripe\Forms\SearchableMultiDropdownField;
use SilverStripe\Security\InheritedPermissions;

/**
Expand Down Expand Up @@ -104,7 +105,6 @@ public function getCMSFields()
$groupsMap = $mapFn(Group::get());
$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 = FieldList::create(
TabSet::create(
Expand Down Expand Up @@ -132,11 +132,13 @@ public function getCMSFields()
'data-placeholder',
_t('SilverStripe\\CMS\\Model\\SiteTree.GroupPlaceholder', 'Click to select group')
),
$viewerMembersField = ListboxField::create(
$viewerMembersField = SearchableMultiDropdownField::create(
"ViewerMembers",
_t(self::class . '.VIEWERMEMBERS', "Viewer Users"),
$membersMap,
),
Member::get()
)
->setIsLazyLoaded(true)
->setUseSearchContext(true),
$editorsOptionsField = OptionsetField::create(
"CanEditType",
_t(self::class . '.EDITHEADER', "Who can edit pages on this site?")
Expand All @@ -150,11 +152,13 @@ public function getCMSFields()
'data-placeholder',
_t('SilverStripe\\CMS\\Model\\SiteTree.GroupPlaceholder', 'Click to select group')
),
$editorMembersField = ListboxField::create(
$editorMembersField = SearchableMultiDropdownField::create(
"EditorMembers",
_t(self::class . '.EDITORMEMBERS', "Editor Users"),
$membersMap,
),
Member::get(),
)
->setIsLazyLoaded(true)
->setUseSearchContext(true),
$topLevelCreatorsOptionsField = OptionsetField::create(
"CanCreateTopLevelType",
_t(self::class . '.TOPLEVELCREATE', "Who can create pages in the root of the site?")
Expand All @@ -168,11 +172,13 @@ public function getCMSFields()
'data-placeholder',
_t('SilverStripe\\CMS\\Model\\SiteTree.GroupPlaceholder', 'Click to select group')
),
$topLevelCreatorsMembersField = ListboxField::create(
$topLevelCreatorsMembersField = SearchableMultiDropdownField::create(
"CreateTopLevelMembers",
_t(self::class . '.TOPLEVELCREATORUSERS', "Top level creator users"),
$membersMap,
Member::get()
)
->setIsLazyLoaded(true)
->setUseSearchContext(true)
)
),
HiddenField::create('ID')
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
],
"require": {
"php": "^8.1",
"silverstripe/framework": "^5",
"silverstripe/admin": "^2",
"silverstripe/framework": "^5.2",
"silverstripe/admin": "^2.2",
"silverstripe/vendor-plugin": "^2"
},
"require-dev": {
Expand Down
6 changes: 5 additions & 1 deletion tests/behat/features/manage-page-permissions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,13 @@ Feature: Manage global page permissions
And pages should not be editable by "SECURITY"
But pages should be editable by "ADMIN"

@sboyd
Scenario: I can limit global edit permissions to certain members
Given I take a screenshot after every step
Given I select "Only these users (choose from list)" from "Who can edit pages on this site?" input group
And I select "ADMIN" from "Editor Users" with javascript
And I fill in "Form_EditForm_EditorMembers__input" with "admin"
And I wait for 3 seconds
And I press the "Enter" key globally
And I press the "Save" button
Then pages should not be editable by "AUTHOR"
And pages should not be editable by "SECURITY"
Expand Down

0 comments on commit 24b7aa7

Please sign in to comment.