You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
3 years ago
|
<?php
|
||
|
|
||
|
namespace Drupal\dgi_fixity;
|
||
|
|
||
|
use Drupal\Core\Access\AccessResult;
|
||
|
use Drupal\Core\Entity\EntityAccessControlHandler;
|
||
|
use Drupal\Core\Entity\EntityInterface;
|
||
|
use Drupal\Core\Session\AccountInterface;
|
||
|
|
||
|
/**
|
||
|
* Defines an access control handler for fixity_check entities.
|
||
|
*/
|
||
|
class FixityCheckAccessControlHandler extends EntityAccessControlHandler {
|
||
|
|
||
|
/**
|
||
|
* {@inheritdoc}
|
||
|
*/
|
||
|
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||
|
if ($account->hasPermission($this->entityType->getAdminPermission())) {
|
||
|
return AccessResult::allowed()->cachePerPermissions();
|
||
|
}
|
||
|
|
||
|
switch ($operation) {
|
||
|
case 'view':
|
||
|
return AccessResult::allowedIfHasPermission($account, 'view fixity checks')->cachePerPermissions();
|
||
|
|
||
|
default:
|
||
|
return AccessResult::forbidden()->cachePerPermissions();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* {@inheritdoc}
|
||
|
*/
|
||
|
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
|
||
|
return AccessResult::allowedIfHasPermission($account, $this->entityType->getAdminPermission());
|
||
|
}
|
||
|
|
||
|
}
|