mirror of
https://github.com/verdigado/organization_folders.git
synced 2024-12-06 11:22:41 +01:00
Added security classes and draft version of ResourceVoter
This commit is contained in:
parent
22c06b5689
commit
88cb258c2b
11 changed files with 428 additions and 0 deletions
34
lib/Security/AffirmativeStrategy.php
Normal file
34
lib/Security/AffirmativeStrategy.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\OrganizationFolders\Security;
|
||||
|
||||
class AffirmativeStrategy implements \Stringable {
|
||||
private bool $allowIfAllAbstainDecisions;
|
||||
|
||||
public function __construct(bool $allowIfAllAbstainDecisions = false) {
|
||||
$this->allowIfAllAbstainDecisions = $allowIfAllAbstainDecisions;
|
||||
}
|
||||
|
||||
public function decide(\Traversable $results): bool {
|
||||
$deny = 0;
|
||||
foreach ($results as $result) {
|
||||
if (VoterInterface::ACCESS_GRANTED === $result) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (VoterInterface::ACCESS_DENIED === $result) {
|
||||
++$deny;
|
||||
}
|
||||
}
|
||||
|
||||
if ($deny > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->allowIfAllAbstainDecisions;
|
||||
}
|
||||
|
||||
public function __toString(): string {
|
||||
return 'affirmative';
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue