From 37e8a4f3ac5065755726b96b9e08cdcdcb326e47 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 19 Dec 2023 10:21:58 +1300 Subject: [PATCH] ENH Use SearchableMultiDropdownField --- code/SiteConfig.php | 24 ++++++++++++------- composer.json | 4 ++-- .../features/manage-page-permissions.feature | 8 +++++-- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/code/SiteConfig.php b/code/SiteConfig.php index 87ea4bddc..601f58e5c 100644 --- a/code/SiteConfig.php +++ b/code/SiteConfig.php @@ -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; /** @@ -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( @@ -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?") @@ -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?") @@ -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') diff --git a/composer.json b/composer.json index ee071b742..928bc1c1e 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/tests/behat/features/manage-page-permissions.feature b/tests/behat/features/manage-page-permissions.feature index f342740c7..003f99d16 100644 --- a/tests/behat/features/manage-page-permissions.feature +++ b/tests/behat/features/manage-page-permissions.feature @@ -48,7 +48,9 @@ Feature: Manage global page permissions Scenario: I can limit global view permissions to certain members Given I select "Only these users (choose from list)" from "Who can view pages on this site?" input group - And I select "AUTHOR" from "Viewer Users" with javascript + And I fill in "Form_EditForm_ViewerMembers__input" with "author" + And I wait for 3 seconds + And I press the "Enter" key globally And I press the "Save" button When I am not logged in And I go to the homepage @@ -92,7 +94,9 @@ Feature: Manage global page permissions Scenario: I can limit global edit permissions to certain members 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"