PrincipalCollection.php 2.9 KB

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