forked from linnovate/openideal
-
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.
OI-74: Restrict access of author to remove himself from a group.
- Loading branch information
1 parent
9428ae4
commit ea6a2fe
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
29 changes: 29 additions & 0 deletions
29
modules/openideal_idea/src/Plugin/OpenidealGroupContentAccessControlHandler.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,29 @@ | ||
<?php | ||
|
||
namespace Drupal\openideal_idea\Plugin; | ||
|
||
use Drupal\Core\Access\AccessResult; | ||
use Drupal\Core\Session\AccountInterface; | ||
use Drupal\group\Entity\GroupContentInterface; | ||
use Drupal\group\Plugin\GroupContentAccessControlHandler; | ||
use Drupal\group\Plugin\GroupContentAccessControlHandlerInterface; | ||
|
||
/** | ||
* Provides custom access control for GroupMembership entities. | ||
*/ | ||
class OpenidealGroupContentAccessControlHandler extends GroupContentAccessControlHandler implements GroupContentAccessControlHandlerInterface { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function relationAccess(GroupContentInterface $group_content, $operation, AccountInterface $account, $return_as_object = FALSE) { | ||
// Check if the account is the owner and an restrict delete access. | ||
$is_owner = $group_content->getOwnerId() === $account->id(); | ||
if ($is_owner && $operation == 'delete') { | ||
return AccessResult::forbidden(); | ||
} | ||
|
||
return parent::relationAccess($group_content, $operation, $account, $return_as_object); | ||
} | ||
|
||
} |