class ReplicationAccessControlHandler in Deploy - Content Staging 8
ReplicationAccessControlHandler class.
Hierarchy
- class \Drupal\Core\Entity\EntityHandlerBase uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\Core\Entity\EntityAccessControlHandler implements EntityAccessControlHandlerInterface
- class \Drupal\deploy\ReplicationAccessControlHandler implements EntityHandlerInterface uses MessengerTrait
- class \Drupal\Core\Entity\EntityAccessControlHandler implements EntityAccessControlHandlerInterface
Expanded class hierarchy of ReplicationAccessControlHandler
File
- src/
ReplicationAccessControlHandler.php, line 24
Namespace
Drupal\deployView source
class ReplicationAccessControlHandler extends EntityAccessControlHandler implements EntityHandlerInterface {
use MessengerTrait;
/**
* The workspace manager service.
*
* @var \Drupal\multiversion\Workspace\WorkspaceManagerInterface
*/
protected $workspaceManager;
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a NodeAccessControlHandler object.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\multiversion\Workspace\WorkspaceManagerInterface $workspace_manager
* The workspace manager service.
*/
public function __construct(EntityTypeInterface $entity_type, WorkspaceManagerInterface $workspace_manager, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($entity_type);
$this->workspaceManager = $workspace_manager;
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('workspace.manager'), $container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
protected function checkFieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
$restricted_fields = [
'source',
'target',
];
if (in_array($field_definition
->getName(), $restricted_fields)) {
return AccessResult::forbidden();
}
return parent::checkFieldAccess($operation, $field_definition, $account, $items);
}
/**
* {@inheritdoc}
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
$access = parent::checkCreateAccess($account, $context, $entity_bundle);
$active_workspace = $this->workspaceManager
->getActiveWorkspace();
$upstream_workspace_pointer = $active_workspace->upstream->entity;
// When no upstream workspace pointer is set the access is forbidden.
if (!$upstream_workspace_pointer) {
return AccessResult::forbidden('No target is set for the active workspace.');
}
if (\Drupal::state()
->get('workspace.last_replication_failed', FALSE)) {
return AccessResult::forbidden('Replication is blocked.');
}
$replication_in_queue = $this->entityTypeManager
->getStorage('replication')
->getQuery()
->condition('source', WorkspacePointer::loadFromWorkspace($active_workspace)
->id())
->condition('target', $upstream_workspace_pointer
->id())
->condition('replication_status', [
Replication::QUEUED,
Replication::REPLICATING,
], 'IN')
->execute();
if (!empty($replication_in_queue)) {
$this
->messenger()
->addWarning(t('Users are only allowed to create one push and one pull deployment between the same source and target workspace. New deployments are only allowed after the currently queued deployment finish.'));
return AccessResult::forbidden('Replication queued or in progress.');
}
// The 'deploy to any workspace' permission will always allow the user to
// create replication entities and perform deployments.
if ($account
->hasPermission('deploy to any workspace')) {
return AccessResult::allowed();
}
// Load just the ID and workspace separately to allow for remote workspace
// pointers which won't have the workspace_pointer field set.
$upstream_workspace_id = $upstream_workspace_pointer->workspace_pointer->target_id;
$upstream_workspace = Workspace::load($upstream_workspace_id);
// When the upstream workspace is set, the owner matches the account, and
// the user has the correct permission then allow access.
if ($upstream_workspace && $upstream_workspace
->getOwnerId() == $account
->id() && $account
->hasPermission('deploy to own workspace')) {
return AccessResult::allowed();
}
// When the user doesn't have permissions to deploy to the upstream the
// access is forbidden.
if (!$account
->hasPermission('Deploy to ' . $upstream_workspace_pointer
->label())) {
return AccessResult::forbidden('You do not have permission to deploy to the target.');
}
return $access;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
EntityAccessControlHandler:: |
protected | property | Stores calculated access check results. | |
EntityAccessControlHandler:: |
protected | property | Information about the entity type. | |
EntityAccessControlHandler:: |
protected | property | The entity type ID of the access control handler instance. | |
EntityAccessControlHandler:: |
protected | property | Allows to grant access to just the labels. | 5 |
EntityAccessControlHandler:: |
public | function |
Checks access to an operation on a given entity or entity translation. Overrides EntityAccessControlHandlerInterface:: |
1 |
EntityAccessControlHandler:: |
protected | function | Performs access checks. | 33 |
EntityAccessControlHandler:: |
public | function |
Checks access to create an entity. Overrides EntityAccessControlHandlerInterface:: |
1 |
EntityAccessControlHandler:: |
public | function |
Checks access to an operation on a given entity field. Overrides EntityAccessControlHandlerInterface:: |
|
EntityAccessControlHandler:: |
protected | function | Tries to retrieve a previously cached access value from the static cache. | |
EntityAccessControlHandler:: |
protected | function | Loads the current account object, if it does not exist yet. | |
EntityAccessControlHandler:: |
protected | function | We grant access to the entity if both of these conditions are met: | |
EntityAccessControlHandler:: |
public | function |
Clears all cached access checks. Overrides EntityAccessControlHandlerInterface:: |
|
EntityAccessControlHandler:: |
protected | function | Statically caches whether the given user has access. | |
EntityHandlerBase:: |
protected | property | The module handler to invoke hooks on. | 2 |
EntityHandlerBase:: |
protected | function | Gets the module handler. | 2 |
EntityHandlerBase:: |
public | function | Sets the module handler for this handler. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
ReplicationAccessControlHandler:: |
protected | property | The entity type manager service. | |
ReplicationAccessControlHandler:: |
protected | property | The workspace manager service. | |
ReplicationAccessControlHandler:: |
protected | function |
Performs create access checks. Overrides EntityAccessControlHandler:: |
|
ReplicationAccessControlHandler:: |
protected | function |
Default field access as determined by this access control handler. Overrides EntityAccessControlHandler:: |
|
ReplicationAccessControlHandler:: |
public static | function |
Instantiates a new instance of this entity handler. Overrides EntityHandlerInterface:: |
|
ReplicationAccessControlHandler:: |
public | function |
Constructs a NodeAccessControlHandler object. Overrides EntityAccessControlHandler:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |