Commit 319a1aa2 authored by Yan Loetzer's avatar Yan Loetzer
Browse files

By yanniboi: Fixed team label and file access permissions issues for village hosts.

parent 28920442
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -22,6 +22,11 @@ class TeamAccessControlHandler extends EntityAccessControlHandler implements Ent

  use EventAccessTrait;

  /**
   * {@inheritdoc}
   */
  protected $viewLabelOperation = TRUE;

  /**
   * {@inheritdoc}
   */
+30 −2
Original line number Diff line number Diff line
@@ -8,12 +8,16 @@
use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\contacts_events\Entity\Event;
use Drupal\contacts_events_villages\Controller\AllocatedVillageController;
use Drupal\contacts_events_villages\Controller\VillageHostInfoController;
use Drupal\contacts_events_villages\Entity\Village;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\entity\BundleFieldDefinition;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\entity\BundleFieldDefinition;
use Drupal\user\UserInterface;

/**
@@ -240,3 +244,27 @@ function contacts_events_villages_contacts_user_dashboard_user_summary_blocks_al
    ];
  }
}

/**
 * Implements hook_ENTITY_TYPE_access() for contacts_event.
 *
 * Allow village hosts to access village host files stored on the event.
 */
function contacts_events_villages_contacts_event_access(EntityInterface $entity, $operation, AccountInterface $account) {
  if ($operation != 'view') {
    return AccessResult::neutral();
  }

  /** @var \Drupal\contacts_events\Entity\EventInterface $entity */
  /** @var \Drupal\Core\DependencyInjection\ClassResolver $resolver */
  $resolver = \Drupal::service('class_resolver');
  /** @var \Drupal\contacts_events_villages\Controller\VillageHostInfoController $controller */
  $controller = $resolver->getInstanceFromDefinition(VillageHostInfoController::class);

  $access = $controller->access($entity);
  if ($access->isAllowed()) {
    return $access;
  }

  return AccessResult::neutral();
}
+9 −6
Original line number Diff line number Diff line
@@ -21,12 +21,12 @@ class VillageHostInfoController extends ControllerBase {
   * @param \Drupal\contacts_events\Entity\EventInterface $contacts_event
   *   The event.
   * @param \Drupal\contacts_events_villages\Entity\Village|null $village
   *   The village.
   *   The village, if we want to check VA assignment.
   *
   * @return \Drupal\Core\Access\AccessResult
   *   Result of the access check.
   */
  public function access(EventInterface $contacts_event, Village $village) {
  public function access(EventInterface $contacts_event, Village $village = NULL) {
    // Ensure the event is configured for village hosts.
    if (!$contacts_event->hasField('village_host_teams') || $contacts_event->get('village_host_teams')->isEmpty()) {
      return AccessResult::forbidden()->setCacheMaxAge(0);
@@ -108,13 +108,13 @@ class VillageHostInfoController extends ControllerBase {
   *
   * @param \Drupal\contacts_events\Entity\EventInterface $contacts_event
   *   The event.
   * @param \Drupal\contacts_events_villages\Entity\Village $village
   *   Village.
   * @param \Drupal\contacts_events_villages\Entity\Village|null $village
   *   The village, if we want to check VA assignment.
   *
   * @return \Drupal\Core\Entity\Query\QueryInterface
   *   The query.
   */
  private function getApplicationsQuery(EventInterface $contacts_event, Village $village) {
  private function getApplicationsQuery(EventInterface $contacts_event, Village $village = NULL) {
    $team_ids = [];

    foreach ($contacts_event->get('village_host_teams') as $item) {
@@ -128,7 +128,10 @@ class VillageHostInfoController extends ControllerBase {
    $query->condition('ticket.entity.contact', $this->currentUser()->id());
    $query->condition('state', 'approved');
    $query->condition('event', $contacts_event->id());

    if ($village) {
      $query->condition('ticket.entity.order_item.entity.order_id.entity.village', $village->id());
    }

    return $query;
  }