JobAccessControlHandler.php in Translation Management Tool 8
File
src/Entity/Controller/JobAccessControlHandler.php
View source
<?php
namespace Drupal\tmgmt\Entity\Controller;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
class JobAccessControlHandler extends EntityAccessControlHandler {
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
if ($account
->hasPermission('administer tmgmt')) {
return AccessResult::allowed()
->cachePerPermissions();
}
switch ($operation) {
case 'view':
case 'update':
return AccessResult::allowedIfHasPermission($account, 'create translation jobs')
->orIf(AccessResult::allowedIfHasPermission($account, 'accept translation jobs'));
break;
case 'delete':
return AccessResult::allowedIfHasPermission($account, 'delete translation jobs')
->andIf(AccessResult::allowedIf(!$entity
->isActive()))
->addCacheableDependency($entity);
break;
case 'submit':
return AccessResult::allowedIfHasPermission($account, 'submit translation jobs');
break;
case 'accept':
return AccessResult::allowedIfHasPermission($account, 'accept translation jobs');
break;
case 'abort':
case 'resubmit':
return AccessResult::allowedIfHasPermission($account, 'submit translation jobs');
break;
}
}
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
return AccessResult::allowedIfHasPermission($account, 'create translation jobs')
->orIf(AccessResult::allowedIfHasPermission($account, 'administer tmgmt'));
}
}