1<?php
2
3namespace Sabre\DAVACL;
4
5use Sabre\DAV\Exception\InvalidResourceType;
6use Sabre\DAV\IExtendedCollection;
7use Sabre\DAV\MkCol;
8
9/**
10 * Principals Collection
11 *
12 * This collection represents a list of users.
13 * The users are instances of Sabre\DAVACL\Principal
14 *
15 * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
16 * @author Evert Pot (http://evertpot.com/)
17 * @license http://sabre.io/license/ Modified BSD License
18 */
19class PrincipalCollection extends AbstractPrincipalCollection implements IExtendedCollection, IACL {
20
21    use ACLTrait;
22
23    /**
24     * This method returns a node for a principal.
25     *
26     * The passed array contains principal information, and is guaranteed to
27     * at least contain a uri item. Other properties may or may not be
28     * supplied by the authentication backend.
29     *
30     * @param array $principal
31     * @return \Sabre\DAV\INode
32     */
33    function getChildForPrincipal(array $principal) {
34
35        return new Principal($this->principalBackend, $principal);
36
37    }
38
39    /**
40     * Creates a new collection.
41     *
42     * This method will receive a MkCol object with all the information about
43     * the new collection that's being created.
44     *
45     * The MkCol object contains information about the resourceType of the new
46     * collection. If you don't support the specified resourceType, you should
47     * throw Exception\InvalidResourceType.
48     *
49     * The object also contains a list of WebDAV properties for the new
50     * collection.
51     *
52     * You should call the handle() method on this object to specify exactly
53     * which properties you are storing. This allows the system to figure out
54     * exactly which properties you didn't store, which in turn allows other
55     * plugins (such as the propertystorage plugin) to handle storing the
56     * property for you.
57     *
58     * @param string $name
59     * @param MkCol $mkCol
60     * @throws InvalidResourceType
61     * @return void
62     */
63    function createExtendedCollection($name, MkCol $mkCol) {
64
65        if (!$mkCol->hasResourceType('{DAV:}principal')) {
66            throw new InvalidResourceType('Only resources of type {DAV:}principal may be created here');
67        }
68
69        $this->principalBackend->createPrincipal(
70            $this->principalPrefix . '/' . $name,
71            $mkCol
72        );
73
74    }
75
76    /**
77     * Returns a list of ACE's for this node.
78     *
79     * Each ACE has the following properties:
80     *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
81     *     currently the only supported privileges
82     *   * 'principal', a url to the principal who owns the node
83     *   * 'protected' (optional), indicating that this ACE is not allowed to
84     *      be updated.
85     *
86     * @return array
87     */
88    function getACL() {
89        return [
90            [
91                'principal' => '{DAV:}authenticated',
92                'privilege' => '{DAV:}read',
93                'protected' => true,
94            ],
95        ];
96    }
97
98}
99