From 3b6dfd7324e04df302c127d742704dfba66b9962 Mon Sep 17 00:00:00 2001 From: cpenny Date: Fri, 15 Feb 2019 15:09:13 +1300 Subject: [PATCH] Bugfix: GridField remove actions should be available even if object is not editable. Use the permission check to validate if the user has the permissions to remove. --- ...rgoExpiryGridFieldItemRequestExtension.php | 11 +++++++--- src/Form/EmbargoExpiryFormAction.php | 22 +++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/Form/EmbargoExpiryFormAction.php diff --git a/src/Extension/EmbargoExpiryGridFieldItemRequestExtension.php b/src/Extension/EmbargoExpiryGridFieldItemRequestExtension.php index 884d326..acb9444 100644 --- a/src/Extension/EmbargoExpiryGridFieldItemRequestExtension.php +++ b/src/Extension/EmbargoExpiryGridFieldItemRequestExtension.php @@ -8,12 +8,12 @@ use SilverStripe\Core\Extension; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\Form; -use SilverStripe\Forms\FormAction; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\ValidationException; use SilverStripe\Versioned\VersionedGridFieldItemRequest; use SilverStripe\View\ViewableData_Customised; use Symfony\Component\Finder\Exception\AccessDeniedException; +use Terraformers\EmbargoExpiry\Form\EmbargoExpiryFormAction; /** * Experimental: This does not yet have test coverage. I suggest you write your own for now. @@ -39,15 +39,20 @@ public function updateFormActions(FieldList $actions): FieldList return $actions; } + // Check that the user has permission to remove Embargo/Expiry for this Object. Exit early if they don't. + if (!$record->checkRemovePermission()) { + return $actions; + } + if ($record->getIsPublishScheduled()) { - $actions->push(FormAction::create( + $actions->push(EmbargoExpiryFormAction::create( 'removeEmbargoAction', _t(__CLASS__ . '.REMOVE_EMBARGO', 'Remove embargo') )); } if ($record->getIsUnPublishScheduled()) { - $actions->push(FormAction::create( + $actions->push(EmbargoExpiryFormAction::create( 'removeExpiryAction', _t(__CLASS__ . '.REMOVE_EXPIRY', 'Remove expiry') )); diff --git a/src/Form/EmbargoExpiryFormAction.php b/src/Form/EmbargoExpiryFormAction.php new file mode 100644 index 0000000..d53f095 --- /dev/null +++ b/src/Form/EmbargoExpiryFormAction.php @@ -0,0 +1,22 @@ +