-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1953 from tomudding/feature/improved-custom-page-…
…authorization-checks feat: dynamically evaluate page access permissions
- Loading branch information
Showing
9 changed files
with
45 additions
and
67 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
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
35 changes: 35 additions & 0 deletions
35
module/User/src/Permissions/Assertion/IsAllowedToViewPage.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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace User\Permissions\Assertion; | ||
|
||
use Frontpage\Model\Page as PageModel; | ||
use Laminas\Permissions\Acl\Acl; | ||
use Laminas\Permissions\Acl\Assertion\AssertionInterface; | ||
use Laminas\Permissions\Acl\Resource\ResourceInterface; | ||
use Laminas\Permissions\Acl\Role\RoleInterface; | ||
|
||
/** | ||
* Assertion to check if whoever is trying to view the page is allowed to view the page. | ||
*/ | ||
class IsAllowedToViewPage implements AssertionInterface | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function assert( | ||
Acl $acl, | ||
?RoleInterface $role = null, | ||
?ResourceInterface $resource = null, | ||
$privilege = null, | ||
): bool { | ||
if (!$resource instanceof PageModel) { | ||
return false; | ||
} | ||
|
||
$requiredRole = $resource->getRequiredRole()->value; | ||
|
||
return $role->getRoleId() === $requiredRole || $acl->inheritsRole($role, $requiredRole); | ||
} | ||
} |
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
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