-
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.
DAMO-359 | Access check fixed for media collections.
- Loading branch information
1 parent
15b2e4c
commit 4726733
Showing
6 changed files
with
88 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
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
50 changes: 50 additions & 0 deletions
50
modules/media_collection/src/Access/MediaCollectionViewAccess.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,50 @@ | ||
<?php | ||
|
||
namespace Drupal\media_collection\Access; | ||
|
||
use Drupal\Core\Access\AccessResult; | ||
use Drupal\Core\Entity\EntityTypeManagerInterface; | ||
use Drupal\Core\Routing\Access\AccessInterface; | ||
use Drupal\Core\Session\AccountInterface; | ||
use Symfony\Component\Routing\Route; | ||
|
||
/** | ||
* Provides an access checker for media collections. | ||
*/ | ||
class MediaCollectionViewAccess implements AccessInterface { | ||
|
||
/** | ||
* The entity type manager. | ||
* | ||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface | ||
*/ | ||
protected $entityTypeManager; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager | ||
* The entity type manager. | ||
*/ | ||
public function __construct(EntityTypeManagerInterface $entity_type_manager) { | ||
$this->entityTypeManager = $entity_type_manager; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function access(AccountInterface $account, Route $route) { | ||
$parts = explode('/', \Drupal::request()->getRequestUri()); | ||
$media_collection = $parts[2]; | ||
$collection = $this->entityTypeManager->getStorage('media_collection')->load($media_collection); | ||
|
||
if ($collection) { | ||
if ($collection->getOwnerId() === $account->id()) { | ||
return AccessResult::allowed(); | ||
} | ||
$shared_with = $collection->get('shared_with')->getValue(); | ||
return AccessResult::allowedIf(in_array(['target_id' => $account->id()], $shared_with)); | ||
} | ||
return AccessResult::forbidden(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
modules/media_collection/src/Routing/MediaCollectionRouteSubscriber.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,24 @@ | ||
<?php | ||
|
||
namespace Drupal\media_collection\Routing; | ||
|
||
use Drupal\Core\Routing\RouteSubscriberBase; | ||
use Symfony\Component\Routing\RouteCollection; | ||
|
||
/** | ||
* Subscribe to media bulk upload paths. | ||
* | ||
* @package Drupal\damopen_assets\Routing | ||
*/ | ||
class MediaCollectionRouteSubscriber extends RouteSubscriberBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function alterRoutes(RouteCollection $collection) { | ||
if ($route = $collection->get('view.collection_view_page.collection_view')) { | ||
$route->setRequirement('_custom_access', 'media_collection.view_access_check::access'); | ||
} | ||
} | ||
|
||
} |
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