Dynamic permissions!
This commit is contained in:
parent
570d442d41
commit
142c22f8e2
@ -1,3 +1,7 @@
|
|||||||
|
permission_callbacks:
|
||||||
|
- Drupal\opencase_entities\OpenCaseEntityPermissions::permissions
|
||||||
|
|
||||||
|
|
||||||
administer opencase entity bundles:
|
administer opencase entity bundles:
|
||||||
title: 'Administer OpenCase Actor/Case/Activity Types'
|
title: 'Administer OpenCase Actor/Case/Activity Types'
|
||||||
description: 'Create, configure and delete types of actor (such as "Client" or "Legal Advisor"), types of case (such as "Housing" or "Asylum") and types of activity (such as "Case Note" or "Interview")'
|
description: 'Create, configure and delete types of actor (such as "Client" or "Legal Advisor"), types of case (such as "Housing" or "Asylum") and types of activity (such as "Case Note" or "Interview")'
|
||||||
@ -7,57 +11,57 @@ administer actor entities:
|
|||||||
description: 'Allow to access the administration form to configure Actor entities.'
|
description: 'Allow to access the administration form to configure Actor entities.'
|
||||||
restrict access: true
|
restrict access: true
|
||||||
|
|
||||||
add client entities:
|
#add client entities:
|
||||||
title: 'Create new Client entities'
|
# title: 'Create new Client entities'
|
||||||
|
#
|
||||||
delete client entities:
|
#delete client entities:
|
||||||
title: 'Delete Client entities'
|
# title: 'Delete Client entities'
|
||||||
|
#
|
||||||
edit client entities:
|
#edit client entities:
|
||||||
title: 'Edit Client entities'
|
# title: 'Edit Client entities'
|
||||||
|
#
|
||||||
view published client entities:
|
#view published client entities:
|
||||||
title: 'View published Client entities'
|
# title: 'View published Client entities'
|
||||||
|
#
|
||||||
view unpublished client entities:
|
#view unpublished client entities:
|
||||||
title: 'View unpublished Client entities'
|
# title: 'View unpublished Client entities'
|
||||||
|
#
|
||||||
view all client revisions:
|
#view all client revisions:
|
||||||
title: 'View all Client revisions'
|
# title: 'View all Client revisions'
|
||||||
|
#
|
||||||
revert all client revisions:
|
#revert all client revisions:
|
||||||
title: 'Revert all Client revisions'
|
# title: 'Revert all Client revisions'
|
||||||
description: 'Role requires permission <em>view Client revisions</em> and <em>edit rights</em> for client entities in question or <em>administer client entities</em>.'
|
# description: 'Role requires permission <em>view Client revisions</em> and <em>edit rights</em> for client entities in question or <em>administer client entities</em>.'
|
||||||
|
#
|
||||||
delete all client revisions:
|
#delete all client revisions:
|
||||||
title: 'Delete all Client revisions'
|
# title: 'Delete all Client revisions'
|
||||||
description: 'Role requires permission to <em>view Client revisions</em> and <em>delete rights</em> for client entities in question or <em>administer client entities</em>.'
|
# description: 'Role requires permission to <em>view Client revisions</em> and <em>delete rights</em> for client entities in question or <em>administer client entities</em>.'
|
||||||
|
#
|
||||||
add volunteer entities:
|
#add volunteer entities:
|
||||||
title: 'Create new Volunteer entities'
|
# title: 'Create new Volunteer entities'
|
||||||
|
#
|
||||||
delete volunteer entities:
|
#delete volunteer entities:
|
||||||
title: 'Delete Volunteer entities'
|
# title: 'Delete Volunteer entities'
|
||||||
|
#
|
||||||
edit volunteer entities:
|
#edit volunteer entities:
|
||||||
title: 'Edit Volunteer entities'
|
# title: 'Edit Volunteer entities'
|
||||||
|
#
|
||||||
view published volunteer entities:
|
#view published volunteer entities:
|
||||||
title: 'View published Volunteer entities'
|
# title: 'View published Volunteer entities'
|
||||||
|
#
|
||||||
view unpublished volunteer entities:
|
#view unpublished volunteer entities:
|
||||||
title: 'View unpublished Volunteer entities'
|
# title: 'View unpublished Volunteer entities'
|
||||||
|
#
|
||||||
view all volunteer revisions:
|
#view all volunteer revisions:
|
||||||
title: 'View all Volunteer revisions'
|
# title: 'View all Volunteer revisions'
|
||||||
|
#
|
||||||
revert all volunteer revisions:
|
#revert all volunteer revisions:
|
||||||
title: 'Revert all Volunteer revisions'
|
# title: 'Revert all Volunteer revisions'
|
||||||
description: 'Role requires permission <em>view Volunteer revisions</em> and <em>edit rights</em> for volunteer entities in question or <em>administer volunteer entities</em>.'
|
# description: 'Role requires permission <em>view Volunteer revisions</em> and <em>edit rights</em> for volunteer entities in question or <em>administer volunteer entities</em>.'
|
||||||
|
#
|
||||||
delete all volunteer revisions:
|
#delete all volunteer revisions:
|
||||||
title: 'Delete all Volunteer revisions'
|
# title: 'Delete all Volunteer revisions'
|
||||||
description: 'Role requires permission to <em>view Volunteer revisions</em> and <em>delete rights</em> for volunteer entities in question or <em>administer volunteer entities</em>.'
|
# description: 'Role requires permission to <em>view Volunteer revisions</em> and <em>delete rights</em> for volunteer entities in question or <em>administer volunteer entities</em>.'
|
||||||
|
|
||||||
add case entities:
|
add case entities:
|
||||||
title: 'Create new Case entities'
|
title: 'Create new Case entities'
|
||||||
|
93
modules/opencase_entities/src/OpenCaseEntityPermissions.php
Normal file
93
modules/opencase_entities/src/OpenCaseEntityPermissions.php
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities;
|
||||||
|
|
||||||
|
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
||||||
|
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||||
|
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
|
class OpenCaseEntityPermissions implements ContainerInjectionInterface {
|
||||||
|
|
||||||
|
use StringTranslationTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The entity type manager.
|
||||||
|
*
|
||||||
|
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||||
|
*/
|
||||||
|
protected $entityTypeManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for MyModulePermissions.
|
||||||
|
*
|
||||||
|
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||||
|
* The entity type manager.
|
||||||
|
*/
|
||||||
|
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
|
||||||
|
$this->entityTypeManager = $entity_type_manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function create(ContainerInterface $container) {
|
||||||
|
return new static($container->get('entity_type.manager'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get permissions for MyModule.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* Permissions array.
|
||||||
|
*/
|
||||||
|
public function permissions() {
|
||||||
|
$permissions = [];
|
||||||
|
|
||||||
|
foreach ($this->entityTypeManager->getStorage('oc_actor_type')->loadMultiple() as $id => $type) {
|
||||||
|
$permissions += [
|
||||||
|
"add $id entities" => [
|
||||||
|
'title' => $this->t('Create new %type entities', array('%type' => $type->label())),
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$permissions += [
|
||||||
|
"edit $id entities" => [
|
||||||
|
'title' => $this->t('Edit %type entities', array('%type' => $type->label())),
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$permissions += [
|
||||||
|
"delete $id entities" => [
|
||||||
|
'title' => $this->t('Delete %type entities', array('%type' => $type->label())),
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$permissions += [
|
||||||
|
"view published $id entities" => [
|
||||||
|
'title' => $this->t('View published %type entities', array('%type' => $type->label())),
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$permissions += [
|
||||||
|
"view all $id revisions" => [
|
||||||
|
'title' => $this->t('View %type revisions', array('%type' => $type->label())),
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$permissions += [
|
||||||
|
"revert all $id revisions" => [
|
||||||
|
'title' => $this->t('Revert %type revisions', array('%type' => $type->label())),
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$permissions += [
|
||||||
|
"delete all $id revisions" => [
|
||||||
|
'title' => $this->t('Delete %type revisions', array('%type' => $type->label())),
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
return $permissions;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user