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 CollaboraOnline#27: Split access checking into a service.
- Loading branch information
1 parent
a259820
commit 27e8137
Showing
4 changed files
with
64 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
services: | ||
_defaults: | ||
autoconfigure: true | ||
autowire: true | ||
Drupal\collabora_online\Access\CollaboraAccessCheck: { } | ||
|
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,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\collabora_online\Access; | ||
|
||
use Drupal\Core\Session\AccountInterface; | ||
|
||
/** | ||
* Access handler for Collabora routes and operations. | ||
* | ||
* @see \Drupal\media\MediaAccessControlHandler | ||
*/ | ||
class CollaboraAccessCheck { | ||
|
||
/** | ||
* Determines access for a Collabora operation. | ||
* | ||
* @param string $operation | ||
* The operation to perform with a media in Collabora. | ||
* One of 'preview' or 'edit'. | ||
* @param \Drupal\Core\Session\AccountInterface $account | ||
* User account to check access for. | ||
* | ||
* @return bool | ||
* TRUE to grant access, FALSE to deny it. | ||
* | ||
* @todo Add fine-grained permissions per media type. | ||
* @todo Return an access result object. | ||
*/ | ||
public function mediaAccess( | ||
string $operation, | ||
AccountInterface $account, | ||
): bool { | ||
$permission = match ($operation) { | ||
'preview' => 'preview any media in collabora', | ||
'edit' => 'edit any media in collabora', | ||
}; | ||
return $account->hasPermission($permission); | ||
} | ||
|
||
} |
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