Commit 8be6b6b3 authored by Digant Jagtap's avatar Digant Jagtap Committed by Youri van Koppen
Browse files

Issue #3136344 by DigantDj, MegaChriz, Kristen Pol: Added permissions for edit...

Issue #3136344 by DigantDj, MegaChriz, Kristen Pol: Added permissions for edit and delete own feeds and feed items.
parent a1f5d49e
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ class FeedAccessControlHandler extends EntityAccessControlHandler {
   * {@inheritdoc}
   */
  protected function checkAccess(EntityInterface $feed, $operation, AccountInterface $account) {
    $has_perm = $account->hasPermission('administer feeds') || $account->hasPermission("$operation {$feed->bundle()} feeds");
    $has_perm = $account->hasPermission('administer feeds') || $account->hasPermission("$operation {$feed->bundle()} feeds") || ($account->hasPermission("$operation own {$feed->bundle()} feeds") && $this->isFeedOwner($feed, $account));

    switch ($operation) {
      case 'view':
@@ -50,4 +50,15 @@ class FeedAccessControlHandler extends EntityAccessControlHandler {
    return AccessResult::allowedIf($has_perm);
  }

  /**
   * Performs check if current user is feed owner.
   *
   * @return bool
   *   True if the current user is the feed owner. False otherwise.
   */
  public function isFeedOwner(EntityInterface $feed, AccountInterface $account) {
    $user = $feed->get('uid')->entity;
    return $user->id() === $account->id();
  }

}
+22 −0
Original line number Diff line number Diff line
@@ -61,28 +61,50 @@ class FeedsPermissions {
      "view $id feeds" => [
        'title' => $this->t('%name: View feeds', $args),
      ],
      "view own $id feeds" => [
        'title' => $this->t('%name: View own feeds', $args),
      ],
      "create $id feeds" => [
        'title' => $this->t('%name: Create new feeds', $args),
      ],
      "update $id feeds" => [
        'title' => $this->t('%name: Update existing feeds', $args),
      ],
      "update own $id feeds" => [
        'title' => $this->t('%name: Update own existing feeds', $args),
      ],
      "delete $id feeds" => [
        'title' => $this->t('%name: Delete feeds', $args),
      ],
      "delete own $id feeds" => [
        'title' => $this->t('%name: Delete own feeds', $args),
      ],
      "import $id feeds" => [
        'title' => $this->t('%name: Import feeds', $args),
      ],
      "import own $id feeds" => [
        'title' => $this->t('%name: Import own feeds', $args),
      ],
      "schedule_import $id feeds" => [
        'title' => $this->t('%name: Import feeds in background', $args),
      ],
      "schedule_import own $id feeds" => [
        'title' => $this->t('%name: Import own feeds in background', $args),
      ],
      "clear $id feeds" => [
        'title' => $this->t('%name: Delete feed items', $args),
      ],
      "clear own $id feeds" => [
        'title' => $this->t('%name: Delete own feed items', $args),
      ],
      "unlock $id feeds" => [
        'title' => $this->t('%name: Unlock feeds', $args),
        'description' => $this->t('If a feed importation breaks for some reason, users with this permission can unlock it.'),
      ],
      "unlock own $id feeds" => [
        'title' => $this->t('%name: Unlock own feeds', $args),
        'description' => $this->t('If a feed importation breaks for some reason, users with this permission can unlock it.'),
      ],
    ];
  }

+558 −0

File added.

Preview size limit exceeded, changes collapsed.