예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function access(Route $route, AccountInterface $account, RdfInterface $rdf_entity, $operation = 'view')
 {
     $graph = $route->getOption('graph_name');
     $entity_type_id = $route->getOption('entity_type_id');
     $storage = $this->entityManager->getStorage($entity_type_id);
     if (!$storage instanceof RdfEntitySparqlStorage) {
         throw new \Exception('Storage not supported.');
     }
     // The active graph is the published graph. It is handled by the default
     // operation handler.
     // @todo: getActiveGraph is not the default. We should load from settings.
     $default_graph = $storage->getBundleGraphUri($rdf_entity->bundle(), 'default');
     $requested_graph = $storage->getBundleGraphUri($rdf_entity->bundle(), $graph);
     if ($requested_graph == $default_graph) {
         return AccessResult::neutral();
     }
     $active_graph_type = $storage->getRequestGraphs($rdf_entity->id());
     // Check if there is an entity saved in the passed graph.
     $storage->setRequestGraphs($rdf_entity->id(), [$graph]);
     $entity = $storage->load($rdf_entity->id());
     // Restore active graph.
     $storage->setRequestGraphs($rdf_entity->id(), $active_graph_type);
     // @todo: When the requested graph is the only one and it is not the
     // default, it is loaded in the default view, so maybe there is no need
     // to also show a separate tab.
     return AccessResult::allowedIf($entity && $this->checkAccess($rdf_entity, $route, $account, $operation, $graph))->cachePerPermissions()->addCacheableDependency($rdf_entity);
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     // If the page is not a solution page, return an empty form so that the
     // rendering of this block can be omitted.
     if (empty($this->solution) || $this->solution->bundle() != 'solution') {
         return [];
     }
     // Get news referencing to this solution.
     // @todo EntityManager is deprecated. Use EntityTypeManager instead.
     // @see https://webgate.ec.europa.eu/CITnet/jira/browse/ISAICP-2669
     $entities = $this->entityManager->getStorage('node')->loadByProperties([OgGroupAudienceHelperInterface::DEFAULT_FIELD => $this->solution->id()]);
     $items = [];
     foreach ($entities as $entity) {
         $items[] = ['#markup' => $entity->link()];
     }
     // Also retrieve related collections.
     $ids = $this->entityManager->getStorage('rdf_entity')->getQuery()->condition('field_ar_affiliates', $this->solution->id())->execute();
     $entities = Rdf::loadMultiple($ids);
     foreach ($entities as $entity) {
         $items[] = ['#markup' => $entity->link()];
     }
     // Build the array output.
     if ($items) {
         return ['list' => ['#theme' => 'item_list', '#items' => $items, '#cache' => ['tags' => ['entity:node:news', 'entity:rdf_entity:collection']]]];
     }
     return [];
 }
 /**
  * Returns the solution that a release belongs to.
  *
  * @param \Drupal\rdf_entity\RdfInterface $asset_release
  *    The asset release rdf entity.
  *
  * @return \Drupal\rdf_entity\RdfInterface
  *    The solution rdf entity that the release is version of.
  */
 public function getReleaseSolution(RdfInterface $asset_release)
 {
     if ($asset_release->bundle() != 'asset_release') {
         return NULL;
     }
     $target_id = $asset_release->field_isr_is_version_of->first()->target_id;
     return $this->entityTypeManager->getStorage('rdf_entity')->load($target_id);
 }
예제 #4
0
 /**
  * Handles access to the event add form through RDF entity pages.
  *
  * Access is granted to moderators and group members that have the permission
  * to create event articles inside of their group, which in practice means
  * this is granted to collection and solution facilitators.
  *
  * @param \Drupal\rdf_entity\RdfInterface $rdf_entity
  *   The RDF entity for which the event entity is created.
  *
  * @return \Drupal\Core\Access\AccessResult
  *   The access result object.
  */
 public function createEventAccess(RdfInterface $rdf_entity)
 {
     if (!in_array($rdf_entity->bundle(), ['collection', 'solution'])) {
         return AccessResult::forbidden();
     }
     $user = $this->currentUser();
     // Grant access if the user is a moderator.
     if (in_array('moderator', $user->getRoles())) {
         return AccessResult::allowed()->addCacheContexts(['user.roles']);
     }
     // Grant access depending on whether the user has permission to create an
     // event node entity according to their OG role.
     return $this->ogAccess->userAccessGroupContentEntityOperation('create', $rdf_entity, $this->createEventEntity($rdf_entity), $user);
 }
예제 #5
0
 /**
  * Handles access to the news add form through RDF entity pages.
  *
  * Access is granted to moderators and group members that have the permission
  * to create news articles inside of their group, which in practice means this
  * is granted to collection and solution facilitators.
  *
  * @todo Depending on the 'eLibrary creation' setting, members should be able
  *   to create news.
  * @todo If a collection is open non-members should be able to create news.
  *
  * @see https://webgate.ec.europa.eu/CITnet/jira/browse/ISAICP-2654
  * @see https://webgate.ec.europa.eu/CITnet/jira/browse/ISAICP-2445
  *
  * @param \Drupal\rdf_entity\RdfInterface $rdf_entity
  *   The RDF entity for which the news entity is created.
  *
  * @return \Drupal\Core\Access\AccessResult
  *   The access result object.
  */
 public function createNewsAccess(RdfInterface $rdf_entity)
 {
     // @todo Add also 'solution' when a workflow for news will be in place.
     if (!in_array($rdf_entity->bundle(), ['collection'])) {
         return AccessResult::forbidden();
     }
     $user = $this->currentUser();
     // Grant access if the user is a moderator.
     if (in_array('moderator', $user->getRoles())) {
         return AccessResult::allowed()->addCacheContexts(['user.roles']);
     }
     // Grant access depending on whether the user has permission to create a
     // custom page according to their OG role.
     return $this->ogAccess->userAccessGroupContentEntityOperation('create', $rdf_entity, $this->createNewsEntity($rdf_entity), $user);
 }
 /**
  * Access callback for the solution releases overview.
  *
  * @param \Drupal\rdf_entity\RdfInterface $rdf_entity
  *   The solution rdf entity.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The route match object to be checked.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The account being checked.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  *
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  *   Thrown when the rdf entity is not a solution.
  */
 public function overviewAccess(RdfInterface $rdf_entity, RouteMatchInterface $route_match, AccountInterface $account)
 {
     if ($rdf_entity->bundle() !== 'solution') {
         throw new NotFoundHttpException();
     }
     return $rdf_entity->access('view', $account, TRUE);
 }