principal.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * Copyright (c) 2011 Jakob Sack mail@jakobsack.de
  4. * Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
  5. * This file is licensed under the Affero General Public License version 3 or
  6. * later.
  7. * See the COPYING-README file.
  8. */
  9. class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend {
  10. /**
  11. * Returns a list of principals based on a prefix.
  12. *
  13. * This prefix will often contain something like 'principals'. You are only
  14. * expected to return principals that are in this base path.
  15. *
  16. * You are expected to return at least a 'uri' for every user, you can
  17. * return any additional properties if you wish so. Common properties are:
  18. * {DAV:}displayname
  19. *
  20. * @param string $prefixPath
  21. * @return array
  22. */
  23. public function getPrincipalsByPrefix( $prefixPath ) {
  24. $principals = array();
  25. if ($prefixPath == 'principals') {
  26. foreach(OC_User::getUsers() as $user) {
  27. $user_uri = 'principals/'.$user;
  28. $principals[] = array(
  29. 'uri' => $user_uri,
  30. '{DAV:}displayname' => $user,
  31. );
  32. }
  33. }
  34. return $principals;
  35. }
  36. /**
  37. * Returns a specific principal, specified by it's path.
  38. * The returned structure should be the exact same as from
  39. * getPrincipalsByPrefix.
  40. *
  41. * @param string $path
  42. * @return array
  43. */
  44. public function getPrincipalByPath($path) {
  45. list($prefix,$name) = explode('/', $path);
  46. if ($prefix == 'principals' && OC_User::userExists($name)) {
  47. return array(
  48. 'uri' => 'principals/'.$name,
  49. '{DAV:}displayname' => $name,
  50. );
  51. }
  52. return null;
  53. }
  54. /**
  55. * Returns the list of members for a group-principal
  56. *
  57. * @param string $principal
  58. * @return array
  59. */
  60. public function getGroupMemberSet($principal) {
  61. // TODO: for now the group principal has only one member, the user itself
  62. list($prefix,$name) = Sabre_DAV_URLUtil::splitPath($principal);
  63. $principal = $this->getPrincipalByPath($prefix);
  64. if (!$principal) throw new Sabre_DAV_Exception('Principal not found');
  65. return array(
  66. $prefix
  67. );
  68. }
  69. /**
  70. * Returns the list of groups a principal is a member of
  71. *
  72. * @param string $principal
  73. * @return array
  74. */
  75. public function getGroupMembership($principal) {
  76. list($prefix,$name) = Sabre_DAV_URLUtil::splitPath($principal);
  77. $group_membership = array();
  78. if ($prefix == 'principals') {
  79. $principal = $this->getPrincipalByPath($principal);
  80. if (!$principal) throw new Sabre_DAV_Exception('Principal not found');
  81. // TODO: for now the user principal has only its own groups
  82. return array(
  83. 'principals/'.$name.'/calendar-proxy-read',
  84. 'principals/'.$name.'/calendar-proxy-write',
  85. // The addressbook groups are not supported in Sabre,
  86. // see http://groups.google.com/group/sabredav-discuss/browse_thread/thread/ef2fa9759d55f8c#msg_5720afc11602e753
  87. //'principals/'.$name.'/addressbook-proxy-read',
  88. //'principals/'.$name.'/addressbook-proxy-write',
  89. );
  90. }
  91. return $group_membership;
  92. }
  93. /**
  94. * Updates the list of group members for a group principal.
  95. *
  96. * The principals should be passed as a list of uri's.
  97. *
  98. * @param string $principal
  99. * @param array $members
  100. * @return void
  101. */
  102. public function setGroupMemberSet($principal, array $members) {
  103. throw new Sabre_DAV_Exception('Setting members of the group is not supported yet');
  104. }
  105. function updatePrincipal($path, $mutations){return 0;}
  106. function searchPrincipals($prefixPath, array $searchProperties){return 0;}
  107. }