Skip to content

Commit

Permalink
Bugfix: GridField remove actions should be available even if object i…
Browse files Browse the repository at this point in the history
…s not editable.

Use the permission check to validate if the user has the permissions to remove.
  • Loading branch information
cpenny authored and chrispenny committed Feb 15, 2019
1 parent 9102489 commit 3b6dfd7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Extension/EmbargoExpiryGridFieldItemRequestExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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')
));
Expand Down
22 changes: 22 additions & 0 deletions src/Form/EmbargoExpiryFormAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Terraformers\EmbargoExpiry\Form;

use SilverStripe\Forms\FormAction;

/**
* Class EmbargoExpiryFormAction
*
* @package Terraformers\EmbargoExpiry\Form
*/
class EmbargoExpiryFormAction extends FormAction
{
/**
* We don't ever want to perform a readonly transformation on this action. If it has been made available to the use,
* that means they're allowed to use it.
*/
public function performReadonlyTransformation()
{
return $this;
}
}

0 comments on commit 3b6dfd7

Please sign in to comment.