Loading src/FeedAccessControlHandler.php +12 −1 Original line number Diff line number Diff line Loading @@ -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': Loading Loading @@ -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(); } } src/FeedsPermissions.php +22 −0 Original line number Diff line number Diff line Loading @@ -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.'), ], ]; } Loading tests/src/Functional/FeedListBuilderOwnTest.php 0 → 100644 +558 −0 File added.Preview size limit exceeded, changes collapsed. Show changes Loading
src/FeedAccessControlHandler.php +12 −1 Original line number Diff line number Diff line Loading @@ -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': Loading Loading @@ -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(); } }
src/FeedsPermissions.php +22 −0 Original line number Diff line number Diff line Loading @@ -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.'), ], ]; } Loading
tests/src/Functional/FeedListBuilderOwnTest.php 0 → 100644 +558 −0 File added.Preview size limit exceeded, changes collapsed. Show changes