Skip to content

Commit

Permalink
Issue #27: Move controller access checks to the route definition for …
Browse files Browse the repository at this point in the history
…view and edit routes.
  • Loading branch information
donquixote authored and hfiguiere committed Oct 24, 2024
1 parent 2c2f030 commit 4ef31f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
8 changes: 6 additions & 2 deletions collabora_online.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ collabora-online.view:
defaults:
_controller: '\Drupal\collabora_online\Controller\ViewerController::editor'
_title: 'Collabora Online'
# The controller method has a boolean parameter '$edit'.
edit: false
options:
parameters:
Expand All @@ -11,13 +12,15 @@ collabora-online.view:
edit:
type: boolean
requirements:
_permission: 'access content'
media: \d+
_entity_access: 'media.preview in collabora'

collabora-online.edit:
path: '/cool/edit/{media}'
defaults:
_controller: '\Drupal\collabora_online\Controller\ViewerController::editor'
_title: 'Collabora Online'
# The controller method has a boolean parameter '$edit'.
edit: true
options:
parameters:
Expand All @@ -26,7 +29,8 @@ collabora-online.edit:
edit:
type: boolean
requirements:
_permission: 'access content'
media: \d+
_entity_access: 'media.edit in collabora'

collabora-online.settings:
path: '/admin/config/cool/settings'
Expand Down
13 changes: 0 additions & 13 deletions src/Controller/ViewerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,6 @@ public function editor(Media $media, $edit = false) {
'closebutton' => 'true',
];

if (!$media->access('preview in collabora')) {
$error_msg = 'Authentication failed.';
\Drupal::logger('cool')->error($error_msg);
return new Response(
$error_msg,
Response::HTTP_FORBIDDEN,
['content-type' => 'text/plain']
);
}

/* Make sure that the user is a collaborator if edit is true */
$edit = $edit && $media->access('edit in collabora');

$render_array = CoolUtils::getViewerRender($media, $edit, $options);

if (!$render_array || array_key_exists('error', $render_array)) {
Expand Down

0 comments on commit 4ef31f8

Please sign in to comment.