forked from CollaboraOnline/collabora-drupal
-
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.
Issue 52: Add access control to set preview operation for unpublished…
… entities.
- Loading branch information
1 parent
6a5d240
commit 012031f
Showing
4 changed files
with
61 additions
and
9 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
46 changes: 46 additions & 0 deletions
46
modules/collabora_online_group/src/Plugin/Group/RelationHandler/CollaboraAccessControl.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,46 @@ | ||
<?php | ||
|
||
namespace Drupal\collabora_online_group\Plugin\Group\RelationHandler; | ||
|
||
use Drupal\Core\Entity\EntityInterface; | ||
use Drupal\Core\Session\AccountInterface; | ||
use Drupal\group\Plugin\Group\RelationHandler\AccessControlInterface; | ||
use Drupal\group\Plugin\Group\RelationHandler\AccessControlTrait; | ||
use Drupal\group\Plugin\Group\RelationHandlerDefault\AccessControl; | ||
|
||
/** | ||
* Provides access control for group relations. | ||
*/ | ||
class CollaboraAccessControl extends AccessControl { | ||
|
||
use AccessControlTrait; | ||
|
||
/** | ||
* Constructs a new GroupMediaPermissionProvider. | ||
* | ||
* @param \Drupal\group\Plugin\Group\RelationHandler\AccessControlInterface $parent | ||
* The default access control. | ||
*/ | ||
public function __construct(AccessControlInterface $parent) { | ||
$this->parent = $parent; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function entityAccess(EntityInterface $entity, $operation, AccountInterface $account, $return_as_object = FALSE) { | ||
// Add support for unpublished vs published for "preview in collabora". | ||
$check_published = $operation === 'preview in collabora' && $this->implementsPublishedInterface; | ||
|
||
if (!$check_published) { | ||
return $this->parent->entityAccess($entity, $operation, $account, $return_as_object); | ||
} | ||
|
||
if (!$entity->isPublished()) { | ||
$operation .= ' unpublished'; | ||
} | ||
|
||
return $this->parent->entityAccess($entity, $operation, $account, $return_as_object); | ||
} | ||
|
||
} |
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
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