-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix edit permissions for transactional emails config entity
- Loading branch information
1 parent
86b09ba
commit 94711bb
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
web/modules/mailer/src/TransactionalEmailAccessControlHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Drupal\mailer; | ||
|
||
use Drupal\Core\Access\AccessException; | ||
use Drupal\Core\Access\AccessResult; | ||
use Drupal\Core\Access\AccessResultNeutral; | ||
use Drupal\Core\Entity\EntityAccessControlHandler; | ||
use Drupal\Core\Entity\EntityInterface; | ||
use Drupal\Core\Session\AccountInterface; | ||
|
||
/** | ||
* Access handler for transactional email config entities. | ||
*/ | ||
class TransactionalEmailAccessControlHandler extends EntityAccessControlHandler { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) { | ||
|
||
if (!$entity instanceof TransactionalEmailInterface) { | ||
throw new AccessException('The TransactionalEmailAccessControlHandler was called by an entity that is not a TransactionalEmail.'); | ||
} | ||
|
||
if ($account->hasPermission($entity->getEntityType()->getAdminPermission())) { | ||
return AccessResult::allowed()->cachePerUser(); | ||
} | ||
|
||
if ($operation == 'update' || $operation == 'edit') { | ||
return AccessResult::allowedIf($account->hasPermission('edit transactional emails')); | ||
} | ||
|
||
return new AccessResultNeutral(); | ||
} | ||
|
||
} |