View source
<?php
namespace Drupal\apigee_edge_teams;
use Drupal\apigee_edge_teams\Structure\TeamPermission;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
final class DefaultTeamPermissionsProvider implements DynamicTeamPermissionProviderInterface, ContainerInjectionInterface {
use StringTranslationTrait;
public function __construct(TranslationInterface $string_translation) {
$this->stringTranslation = $string_translation;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('string_translation'));
}
public function permissions() : array {
$permissions = [];
$operations = [
'team' => [
'label' => $this
->t('Team'),
'permissions' => [
'manage_members' => [
'label' => $this
->t('Manage team members and invitations'),
'description' => $this
->t('Add/remove team members and administer team invitations.'),
],
],
],
'team_app' => [
'label' => $this
->t('Team apps'),
'permissions' => [
'view' => $this
->t('View Team Apps'),
'create' => $this
->t('Create Team Apps'),
'update' => $this
->t('Edit any Team Apps'),
'delete' => $this
->t('Delete any Team Apps'),
'analytics' => $this
->t('View analytics of any Team Apps'),
'add_api_key' => $this
->t('Add API key to Team Apps'),
'revoke_api_key' => $this
->t('Revoke API key from Team Apps'),
'delete_api_key' => $this
->t('Delete API key from Team Apps'),
'edit_api_products' => $this
->t('Edit API products for Team Apps'),
],
],
'api_product' => [
'label' => $this
->t('API products'),
'permissions' => [
'access_public' => $this
->t('View and assign public API products to team apps'),
'access_private' => $this
->t('View and assign private API products to team apps'),
'access_internal' => $this
->t('View and assign internal API products to team apps'),
],
],
];
foreach ($operations as $group => $group_def) {
foreach ($group_def['permissions'] as $operation => $operation_def) {
$description = NULL;
if (is_array($operation_def)) {
$label = $operation_def['label'];
$description = $operation_def['description'] ?? NULL;
}
else {
$label = $operation_def;
}
$name = "{$group}_{$operation}";
$permissions[$name] = new TeamPermission($name, $label, $group_def['label'], $description);
}
}
return $permissions;
}
}