-
Notifications
You must be signed in to change notification settings - Fork 0
/
AclPlugin.php
45 lines (39 loc) · 1.17 KB
/
AclPlugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
use Sabre\DAVACL\Plugin;
/**
* An extension of the ACL Plugin provided by Sabre to allow anonymous RO access.
*/
class AclPlugin extends Plugin {
protected string $anonymous;
public function __construct(string $anonymous = 'anonymous') {
$this->anonymous = "principals/$anonymous";
}
/**
* Returns a list of privileges the current user has
* on a particular node.
*
* If the current user is anonymous, keep only read permissions.
*
* Either a uri or a DAV\INode may be passed.
*
* null will be returned if the node doesn't support ACLs.
*
* @param string|DAV\INode $node
*
* @return array
*/
public function getCurrentUserPrivilegeSet($node)
{
$privileges = parent::getCurrentUserPrivilegeSet($node);
$curr = $this->getCurrentUserPrincipal();
if ($curr == $this->anonymous) {
// error_log(var_export($privileges, true));
return array_intersect($privileges, [
'{DAV:}read',
'{DAV:}read-acl',
'{DAV:}read-current-user-privilege-set',
]);
}
return $privileges;
}
}