Skip to content

Commit

Permalink
Merge pull request #71 from jsirish/feature/baseElementPermissions
Browse files Browse the repository at this point in the history
ElementPermissions
  • Loading branch information
jsirish authored Feb 2, 2018
2 parents 894b37c + 44d1717 commit 0d3d4bd
Show file tree
Hide file tree
Showing 17 changed files with 305 additions and 474 deletions.
4 changes: 1 addition & 3 deletions src/Elements/ElementCustomerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
use SilverStripe\Forms\FieldList;

/**
* Class ElementCustomerService
* @package Dynamic\Elements\Elements
* Class ElementCustomerService.
*/
class ElementCustomerService extends BaseElement
{

/**
* @var string
*/
Expand Down
101 changes: 1 addition & 100 deletions src/Elements/ElementPromos.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Security\Security;
use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton;
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;

/**
* Class PromosElement.
*/
class ElementPromos extends BaseElement implements PermissionProvider
class ElementPromos extends BaseElement
{
/**
* @var string
Expand Down Expand Up @@ -116,100 +113,4 @@ public function getType()
{
return _t(__CLASS__.'.BlockType', 'Promos');
}

/**
* @return array
*/
public function providePermissions()
{
return array(
'EDIT_PROMOS_ELEMENT' => array(
'name' => _t(
'ElementPromos.EDIT_PROMOS_ELEMENT_PERMISSION',
'Manage Promos Elements'
),
'category' => _t(
'Permissions.PERMISSIONS_PROMOS_ELEMENT',
'Elements'
),
'help' => _t(
'ElementPromos.EDIT_PERMISSION_PROMOS_ELEMENT',
'Ability to edit Promos Elements.'
),
'sort' => 400,
),
);
}

/**
* Set permissions, allow all users to access by default.
* Override in descendant classes, or use PermissionProvider.
*/

/**
* @param null $member
*
* @return bool
*/
public function canCreate($member = null, $context = [])
{
if (!$member) {
$member = Security::getCurrentUser();
}

$extended = $this->extendedCan('canCreate', $member);
if ($extended !== null) {
return $extended;
}

return Permission::checkMember($member, 'EDIT_PROMOS_ELEMENT_PERMISSION', 'any');
}

/**
* @param null $member
*
* @return bool
*/
public function canView($member = null, $context = [])
{
return true;
}

/**
* @param null $member
*
* @return bool
*/
public function canEdit($member = null, $context = [])
{
if (!$member) {
$member = Security::getCurrentUser();
}

$extended = $this->extendedCan('canEdit', $member);
if ($extended !== null) {
return $extended;
}

return Permission::checkMember($member, 'EDIT_PROMOS_ELEMENT_PERMISSION', 'any');
}

/**
* @param null $member
*
* @return bool
*/
public function canDelete($member = null, $context = [])
{
if (!$member) {
$member = Security::getCurrentUser();
}

$extended = $this->extendedCan('canDelete', $member);
if ($extended !== null) {
return $extended;
}

return Permission::checkMember($member, 'EDIT_PROMOS_ELEMENT_PERMISSION', 'any');
}
}
81 changes: 81 additions & 0 deletions src/Extensions/ElementPermissions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Dynamic\Elements\ORM;

use SilverStripe\ORM\DataExtension;
use SilverStripe\Security\PermissionProvider;

/**
* Class ElementPermissions.
*/
class ElementPermissions extends DataExtension implements PermissionProvider
{
/**
* @return array
*/
public function providePermissions()
{
return [
'Create_Element' => [
'name' => _t(
'ELEMENT.CREATE_ELEMENT',
'Create Elemental Blocks'
),
'category' => _t(
'Permissions.PERMISSIONS_ELEMENT_PERMISSION',
'Elemental'
),
'help' => _t(
'Element.CREATE_PERMISSION_ELEMENT_PERMISSION',
'Ability to create new Elemental Blocks.'
),
'sort' => 400,
],
'Edit_Element' => [
'name' => _t(
'ELEMENT.EDIT_ELEMENT',
'Edit Elemental Blocks'
),
'category' => _t(
'Permissions.PERMISSIONS_ELEMENT_PERMISSION',
'Elemental'
),
'help' => _t(
'Element.EDIT_PERMISSION_ELEMENT_PERMISSION',
'Ability to update Elemental Blocks.'
),
'sort' => 400,
],
'Delete_Element' => [
'name' => _t(
'ELEMENT.PUBLISH_ELEMENT',
'Delete Elemental Blocks'
),
'category' => _t(
'Permissions.PERMISSIONS_ELEMENT_PERMISSION',
'Elemental'
),
'help' => _t(
'Element.PUBLISH_PERMISSION_ELEMENT_PERMISSION',
'Ability to delete Elemental Blocks.'
),
'sort' => 400,
],
'Publish_Element' => [
'name' => _t(
'ELEMENT.PUBLISH_ELEMENT',
'Publish Elemental Blocks'
),
'category' => _t(
'Permissions.PERMISSIONS_ELEMENT_PERMISSION',
'Elemental'
),
'help' => _t(
'Element.PUBLISH_PERMISSION_ELEMENT_PERMISSION',
'Ability to publish Elemental Blocks.'
),
'sort' => 400,
],
];
}
}
48 changes: 48 additions & 0 deletions src/Extensions/ElementalPermissions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Dynamic\Elements\ORM;

use SilverStripe\ORM\DataExtension;
use SilverStripe\Security\Permission;

/**
* Class ElementalAreaPermissions.
*/
class ElementalPermissions extends DataExtension
{
/**
* @param null $member
* @return bool|int|void
*/
public function canCreate($member = null)
{
return Permission::check('Create_Element', 'any', $member);
}

/**
* @param null $member
* @return bool|int|void
*/
public function canEdit($member = null)
{
return Permission::check('Edit_Element', 'any', $member);
}

/**
* @param null $member
* @return bool|int|void
*/
public function canDelete($member = null)
{
return Permission::check('Delete_Element', 'any', $member);
}

/**
* @param null $member
* @return bool|int
*/
public function canPublish($member = null)
{
return Permission::check('Publish_Element', 'any', $member);
}
}
40 changes: 0 additions & 40 deletions src/Model/AccordionPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,44 +64,4 @@ public function getCMSFields()

return parent::getCMSFields();
}

/**
* @param null $member
*
* @return bool
*/
public function canCreate($member = null, $context = [])
{
return true;
}

/**
* @param null $member
*
* @return bool
*/
public function canView($member = null, $context = [])
{
return true;
}

/**
* @param null $member
*
* @return bool
*/
public function canEdit($member = null, $context = [])
{
return true;
}

/**
* @param null $member
*
* @return bool
*/
public function canDelete($member = null, $context = [])
{
return true;
}
}
5 changes: 3 additions & 2 deletions src/Model/BaseElementObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
use Sheadawson\Linkable\Models\Link;
use SilverStripe\Assets\Image;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\HTMLEditor\TinyMCEConfig;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\ValidationResult;
use SilverStripe\Versioned\Versioned;
use SilverStripe\View\Requirements;

/**
* Class BaseElementObject.
*/
class BaseElementObject extends DataObject
{
/**
Expand Down
45 changes: 0 additions & 45 deletions src/Model/FeatureObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,49 +66,4 @@ public function getCMSFields()

return parent::getCMSFields();
}

/**
* Set permissions, allow all users to access by default.
* Override in descendant classes, or use PermissionProvider.
*/

/**
* @param null $member
*
* @return bool
*/
public function canCreate($member = null, $context = [])
{
return true;
}

/**
* @param null $member
*
* @return bool
*/
public function canView($member = null, $context = [])
{
return true;
}

/**
* @param null $member
*
* @return bool
*/
public function canEdit($member = null, $context = [])
{
return true;
}

/**
* @param null $member
*
* @return bool
*/
public function canDelete($member = null, $context = [])
{
return true;
}
}
Loading

0 comments on commit 0d3d4bd

Please sign in to comment.