@@ -37,90 +37,90 @@ |
||
| 37 | 37 | |
| 38 | 38 | class RootCollection extends SimpleCollection { |
| 39 | 39 | |
| 40 | - public function __construct() { |
|
| 41 | - $config = \OC::$server->getConfig(); |
|
| 42 | - $random = \OC::$server->getSecureRandom(); |
|
| 43 | - $userManager = \OC::$server->getUserManager(); |
|
| 44 | - $db = \OC::$server->getDatabaseConnection(); |
|
| 45 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 46 | - $userPrincipalBackend = new Principal( |
|
| 47 | - $userManager, |
|
| 48 | - \OC::$server->getGroupManager() |
|
| 49 | - ); |
|
| 50 | - $groupPrincipalBackend = new GroupPrincipalBackend( |
|
| 51 | - \OC::$server->getGroupManager() |
|
| 52 | - ); |
|
| 53 | - // as soon as debug mode is enabled we allow listing of principals |
|
| 54 | - $disableListing = !$config->getSystemValue('debug', false); |
|
| 40 | + public function __construct() { |
|
| 41 | + $config = \OC::$server->getConfig(); |
|
| 42 | + $random = \OC::$server->getSecureRandom(); |
|
| 43 | + $userManager = \OC::$server->getUserManager(); |
|
| 44 | + $db = \OC::$server->getDatabaseConnection(); |
|
| 45 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 46 | + $userPrincipalBackend = new Principal( |
|
| 47 | + $userManager, |
|
| 48 | + \OC::$server->getGroupManager() |
|
| 49 | + ); |
|
| 50 | + $groupPrincipalBackend = new GroupPrincipalBackend( |
|
| 51 | + \OC::$server->getGroupManager() |
|
| 52 | + ); |
|
| 53 | + // as soon as debug mode is enabled we allow listing of principals |
|
| 54 | + $disableListing = !$config->getSystemValue('debug', false); |
|
| 55 | 55 | |
| 56 | - // setup the first level of the dav tree |
|
| 57 | - $userPrincipals = new Collection($userPrincipalBackend, 'principals/users'); |
|
| 58 | - $userPrincipals->disableListing = $disableListing; |
|
| 59 | - $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups'); |
|
| 60 | - $groupPrincipals->disableListing = $disableListing; |
|
| 61 | - $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); |
|
| 62 | - $systemPrincipals->disableListing = $disableListing; |
|
| 63 | - $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 64 | - $filesCollection->disableListing = $disableListing; |
|
| 65 | - $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $random, $dispatcher); |
|
| 66 | - $calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); |
|
| 67 | - $calendarRoot->disableListing = $disableListing; |
|
| 68 | - $publicCalendarRoot = new PublicCalendarRoot($caldavBackend); |
|
| 69 | - $publicCalendarRoot->disableListing = $disableListing; |
|
| 56 | + // setup the first level of the dav tree |
|
| 57 | + $userPrincipals = new Collection($userPrincipalBackend, 'principals/users'); |
|
| 58 | + $userPrincipals->disableListing = $disableListing; |
|
| 59 | + $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups'); |
|
| 60 | + $groupPrincipals->disableListing = $disableListing; |
|
| 61 | + $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); |
|
| 62 | + $systemPrincipals->disableListing = $disableListing; |
|
| 63 | + $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 64 | + $filesCollection->disableListing = $disableListing; |
|
| 65 | + $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $random, $dispatcher); |
|
| 66 | + $calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); |
|
| 67 | + $calendarRoot->disableListing = $disableListing; |
|
| 68 | + $publicCalendarRoot = new PublicCalendarRoot($caldavBackend); |
|
| 69 | + $publicCalendarRoot->disableListing = $disableListing; |
|
| 70 | 70 | |
| 71 | - $systemTagCollection = new SystemTag\SystemTagsByIdCollection( |
|
| 72 | - \OC::$server->getSystemTagManager(), |
|
| 73 | - \OC::$server->getUserSession(), |
|
| 74 | - \OC::$server->getGroupManager() |
|
| 75 | - ); |
|
| 76 | - $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection( |
|
| 77 | - \OC::$server->getSystemTagManager(), |
|
| 78 | - \OC::$server->getSystemTagObjectMapper(), |
|
| 79 | - \OC::$server->getUserSession(), |
|
| 80 | - \OC::$server->getGroupManager(), |
|
| 81 | - \OC::$server->getEventDispatcher() |
|
| 82 | - ); |
|
| 83 | - $commentsCollection = new Comments\RootCollection( |
|
| 84 | - \OC::$server->getCommentsManager(), |
|
| 85 | - \OC::$server->getUserManager(), |
|
| 86 | - \OC::$server->getUserSession(), |
|
| 87 | - \OC::$server->getEventDispatcher(), |
|
| 88 | - \OC::$server->getLogger() |
|
| 89 | - ); |
|
| 71 | + $systemTagCollection = new SystemTag\SystemTagsByIdCollection( |
|
| 72 | + \OC::$server->getSystemTagManager(), |
|
| 73 | + \OC::$server->getUserSession(), |
|
| 74 | + \OC::$server->getGroupManager() |
|
| 75 | + ); |
|
| 76 | + $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection( |
|
| 77 | + \OC::$server->getSystemTagManager(), |
|
| 78 | + \OC::$server->getSystemTagObjectMapper(), |
|
| 79 | + \OC::$server->getUserSession(), |
|
| 80 | + \OC::$server->getGroupManager(), |
|
| 81 | + \OC::$server->getEventDispatcher() |
|
| 82 | + ); |
|
| 83 | + $commentsCollection = new Comments\RootCollection( |
|
| 84 | + \OC::$server->getCommentsManager(), |
|
| 85 | + \OC::$server->getUserManager(), |
|
| 86 | + \OC::$server->getUserSession(), |
|
| 87 | + \OC::$server->getEventDispatcher(), |
|
| 88 | + \OC::$server->getLogger() |
|
| 89 | + ); |
|
| 90 | 90 | |
| 91 | - $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $dispatcher); |
|
| 92 | - $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users'); |
|
| 93 | - $usersAddressBookRoot->disableListing = $disableListing; |
|
| 91 | + $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $dispatcher); |
|
| 92 | + $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users'); |
|
| 93 | + $usersAddressBookRoot->disableListing = $disableListing; |
|
| 94 | 94 | |
| 95 | - $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $dispatcher); |
|
| 96 | - $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system'); |
|
| 97 | - $systemAddressBookRoot->disableListing = $disableListing; |
|
| 95 | + $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $dispatcher); |
|
| 96 | + $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system'); |
|
| 97 | + $systemAddressBookRoot->disableListing = $disableListing; |
|
| 98 | 98 | |
| 99 | - $uploadCollection = new Upload\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 100 | - $uploadCollection->disableListing = $disableListing; |
|
| 99 | + $uploadCollection = new Upload\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 100 | + $uploadCollection->disableListing = $disableListing; |
|
| 101 | 101 | |
| 102 | - $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 103 | - $avatarCollection->disableListing = $disableListing; |
|
| 102 | + $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 103 | + $avatarCollection->disableListing = $disableListing; |
|
| 104 | 104 | |
| 105 | - $children = [ |
|
| 106 | - new SimpleCollection('principals', [ |
|
| 107 | - $userPrincipals, |
|
| 108 | - $groupPrincipals, |
|
| 109 | - $systemPrincipals]), |
|
| 110 | - $filesCollection, |
|
| 111 | - $calendarRoot, |
|
| 112 | - $publicCalendarRoot, |
|
| 113 | - new SimpleCollection('addressbooks', [ |
|
| 114 | - $usersAddressBookRoot, |
|
| 115 | - $systemAddressBookRoot]), |
|
| 116 | - $systemTagCollection, |
|
| 117 | - $systemTagRelationsCollection, |
|
| 118 | - $commentsCollection, |
|
| 119 | - $uploadCollection, |
|
| 120 | - $avatarCollection |
|
| 121 | - ]; |
|
| 105 | + $children = [ |
|
| 106 | + new SimpleCollection('principals', [ |
|
| 107 | + $userPrincipals, |
|
| 108 | + $groupPrincipals, |
|
| 109 | + $systemPrincipals]), |
|
| 110 | + $filesCollection, |
|
| 111 | + $calendarRoot, |
|
| 112 | + $publicCalendarRoot, |
|
| 113 | + new SimpleCollection('addressbooks', [ |
|
| 114 | + $usersAddressBookRoot, |
|
| 115 | + $systemAddressBookRoot]), |
|
| 116 | + $systemTagCollection, |
|
| 117 | + $systemTagRelationsCollection, |
|
| 118 | + $commentsCollection, |
|
| 119 | + $uploadCollection, |
|
| 120 | + $avatarCollection |
|
| 121 | + ]; |
|
| 122 | 122 | |
| 123 | - parent::__construct('root', $children); |
|
| 124 | - } |
|
| 123 | + parent::__construct('root', $children); |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | 126 | } |
@@ -40,196 +40,196 @@ |
||
| 40 | 40 | |
| 41 | 41 | class Principal implements BackendInterface { |
| 42 | 42 | |
| 43 | - /** @var IUserManager */ |
|
| 44 | - private $userManager; |
|
| 45 | - |
|
| 46 | - /** @var IGroupManager */ |
|
| 47 | - private $groupManager; |
|
| 48 | - |
|
| 49 | - /** @var string */ |
|
| 50 | - private $principalPrefix; |
|
| 51 | - |
|
| 52 | - /** @var bool */ |
|
| 53 | - private $hasGroups; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param IUserManager $userManager |
|
| 57 | - * @param IGroupManager $groupManager |
|
| 58 | - * @param string $principalPrefix |
|
| 59 | - */ |
|
| 60 | - public function __construct(IUserManager $userManager, |
|
| 61 | - IGroupManager $groupManager, |
|
| 62 | - $principalPrefix = 'principals/users/') { |
|
| 63 | - $this->userManager = $userManager; |
|
| 64 | - $this->groupManager = $groupManager; |
|
| 65 | - $this->principalPrefix = trim($principalPrefix, '/'); |
|
| 66 | - $this->hasGroups = ($principalPrefix === 'principals/users/'); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Returns a list of principals based on a prefix. |
|
| 71 | - * |
|
| 72 | - * This prefix will often contain something like 'principals'. You are only |
|
| 73 | - * expected to return principals that are in this base path. |
|
| 74 | - * |
|
| 75 | - * You are expected to return at least a 'uri' for every user, you can |
|
| 76 | - * return any additional properties if you wish so. Common properties are: |
|
| 77 | - * {DAV:}displayname |
|
| 78 | - * |
|
| 79 | - * @param string $prefixPath |
|
| 80 | - * @return string[] |
|
| 81 | - */ |
|
| 82 | - public function getPrincipalsByPrefix($prefixPath) { |
|
| 83 | - $principals = []; |
|
| 84 | - |
|
| 85 | - if ($prefixPath === $this->principalPrefix) { |
|
| 86 | - foreach($this->userManager->search('') as $user) { |
|
| 87 | - $principals[] = $this->userToPrincipal($user); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - return $principals; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Returns a specific principal, specified by it's path. |
|
| 96 | - * The returned structure should be the exact same as from |
|
| 97 | - * getPrincipalsByPrefix. |
|
| 98 | - * |
|
| 99 | - * @param string $path |
|
| 100 | - * @return array |
|
| 101 | - */ |
|
| 102 | - public function getPrincipalByPath($path) { |
|
| 103 | - list($prefix, $name) = URLUtil::splitPath($path); |
|
| 104 | - |
|
| 105 | - if ($prefix === $this->principalPrefix) { |
|
| 106 | - $user = $this->userManager->get($name); |
|
| 107 | - |
|
| 108 | - if (!is_null($user)) { |
|
| 109 | - return $this->userToPrincipal($user); |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - return null; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Returns the list of members for a group-principal |
|
| 117 | - * |
|
| 118 | - * @param string $principal |
|
| 119 | - * @return string[] |
|
| 120 | - * @throws Exception |
|
| 121 | - */ |
|
| 122 | - public function getGroupMemberSet($principal) { |
|
| 123 | - // TODO: for now the group principal has only one member, the user itself |
|
| 124 | - $principal = $this->getPrincipalByPath($principal); |
|
| 125 | - if (!$principal) { |
|
| 126 | - throw new Exception('Principal not found'); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - return [$principal['uri']]; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Returns the list of groups a principal is a member of |
|
| 134 | - * |
|
| 135 | - * @param string $principal |
|
| 136 | - * @param bool $needGroups |
|
| 137 | - * @return array |
|
| 138 | - * @throws Exception |
|
| 139 | - */ |
|
| 140 | - public function getGroupMembership($principal, $needGroups = false) { |
|
| 141 | - list($prefix, $name) = URLUtil::splitPath($principal); |
|
| 142 | - |
|
| 143 | - if ($prefix === $this->principalPrefix) { |
|
| 144 | - $user = $this->userManager->get($name); |
|
| 145 | - if (!$user) { |
|
| 146 | - throw new Exception('Principal not found'); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - if ($this->hasGroups || $needGroups) { |
|
| 150 | - $groups = $this->groupManager->getUserGroups($user); |
|
| 151 | - $groups = array_map(function($group) { |
|
| 152 | - /** @var IGroup $group */ |
|
| 153 | - return 'principals/groups/' . urlencode($group->getGID()); |
|
| 154 | - }, $groups); |
|
| 155 | - |
|
| 156 | - return $groups; |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - return []; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Updates the list of group members for a group principal. |
|
| 164 | - * |
|
| 165 | - * The principals should be passed as a list of uri's. |
|
| 166 | - * |
|
| 167 | - * @param string $principal |
|
| 168 | - * @param string[] $members |
|
| 169 | - * @throws Exception |
|
| 170 | - */ |
|
| 171 | - public function setGroupMemberSet($principal, array $members) { |
|
| 172 | - throw new Exception('Setting members of the group is not supported yet'); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * @param string $path |
|
| 177 | - * @param PropPatch $propPatch |
|
| 178 | - * @return int |
|
| 179 | - */ |
|
| 180 | - function updatePrincipal($path, PropPatch $propPatch) { |
|
| 181 | - return 0; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * @param string $prefixPath |
|
| 186 | - * @param array $searchProperties |
|
| 187 | - * @param string $test |
|
| 188 | - * @return array |
|
| 189 | - */ |
|
| 190 | - function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { |
|
| 191 | - return []; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * @param string $uri |
|
| 196 | - * @param string $principalPrefix |
|
| 197 | - * @return string |
|
| 198 | - */ |
|
| 199 | - function findByUri($uri, $principalPrefix) { |
|
| 200 | - if (substr($uri, 0, 7) === 'mailto:') { |
|
| 201 | - $email = substr($uri, 7); |
|
| 202 | - $users = $this->userManager->getByEmail($email); |
|
| 203 | - if (count($users) === 1) { |
|
| 204 | - return $this->principalPrefix . '/' . $users[0]->getUID(); |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - return ''; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * @param IUser $user |
|
| 213 | - * @return array |
|
| 214 | - */ |
|
| 215 | - protected function userToPrincipal($user) { |
|
| 216 | - $userId = $user->getUID(); |
|
| 217 | - $displayName = $user->getDisplayName(); |
|
| 218 | - $principal = [ |
|
| 219 | - 'uri' => $this->principalPrefix . '/' . $userId, |
|
| 220 | - '{DAV:}displayname' => is_null($displayName) ? $userId : $displayName, |
|
| 221 | - ]; |
|
| 222 | - |
|
| 223 | - $email = $user->getEMailAddress(); |
|
| 224 | - if (!empty($email)) { |
|
| 225 | - $principal['{http://sabredav.org/ns}email-address'] = $email; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - return $principal; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - public function getPrincipalPrefix() { |
|
| 232 | - return $this->principalPrefix; |
|
| 233 | - } |
|
| 43 | + /** @var IUserManager */ |
|
| 44 | + private $userManager; |
|
| 45 | + |
|
| 46 | + /** @var IGroupManager */ |
|
| 47 | + private $groupManager; |
|
| 48 | + |
|
| 49 | + /** @var string */ |
|
| 50 | + private $principalPrefix; |
|
| 51 | + |
|
| 52 | + /** @var bool */ |
|
| 53 | + private $hasGroups; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param IUserManager $userManager |
|
| 57 | + * @param IGroupManager $groupManager |
|
| 58 | + * @param string $principalPrefix |
|
| 59 | + */ |
|
| 60 | + public function __construct(IUserManager $userManager, |
|
| 61 | + IGroupManager $groupManager, |
|
| 62 | + $principalPrefix = 'principals/users/') { |
|
| 63 | + $this->userManager = $userManager; |
|
| 64 | + $this->groupManager = $groupManager; |
|
| 65 | + $this->principalPrefix = trim($principalPrefix, '/'); |
|
| 66 | + $this->hasGroups = ($principalPrefix === 'principals/users/'); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Returns a list of principals based on a prefix. |
|
| 71 | + * |
|
| 72 | + * This prefix will often contain something like 'principals'. You are only |
|
| 73 | + * expected to return principals that are in this base path. |
|
| 74 | + * |
|
| 75 | + * You are expected to return at least a 'uri' for every user, you can |
|
| 76 | + * return any additional properties if you wish so. Common properties are: |
|
| 77 | + * {DAV:}displayname |
|
| 78 | + * |
|
| 79 | + * @param string $prefixPath |
|
| 80 | + * @return string[] |
|
| 81 | + */ |
|
| 82 | + public function getPrincipalsByPrefix($prefixPath) { |
|
| 83 | + $principals = []; |
|
| 84 | + |
|
| 85 | + if ($prefixPath === $this->principalPrefix) { |
|
| 86 | + foreach($this->userManager->search('') as $user) { |
|
| 87 | + $principals[] = $this->userToPrincipal($user); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + return $principals; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Returns a specific principal, specified by it's path. |
|
| 96 | + * The returned structure should be the exact same as from |
|
| 97 | + * getPrincipalsByPrefix. |
|
| 98 | + * |
|
| 99 | + * @param string $path |
|
| 100 | + * @return array |
|
| 101 | + */ |
|
| 102 | + public function getPrincipalByPath($path) { |
|
| 103 | + list($prefix, $name) = URLUtil::splitPath($path); |
|
| 104 | + |
|
| 105 | + if ($prefix === $this->principalPrefix) { |
|
| 106 | + $user = $this->userManager->get($name); |
|
| 107 | + |
|
| 108 | + if (!is_null($user)) { |
|
| 109 | + return $this->userToPrincipal($user); |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + return null; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Returns the list of members for a group-principal |
|
| 117 | + * |
|
| 118 | + * @param string $principal |
|
| 119 | + * @return string[] |
|
| 120 | + * @throws Exception |
|
| 121 | + */ |
|
| 122 | + public function getGroupMemberSet($principal) { |
|
| 123 | + // TODO: for now the group principal has only one member, the user itself |
|
| 124 | + $principal = $this->getPrincipalByPath($principal); |
|
| 125 | + if (!$principal) { |
|
| 126 | + throw new Exception('Principal not found'); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + return [$principal['uri']]; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Returns the list of groups a principal is a member of |
|
| 134 | + * |
|
| 135 | + * @param string $principal |
|
| 136 | + * @param bool $needGroups |
|
| 137 | + * @return array |
|
| 138 | + * @throws Exception |
|
| 139 | + */ |
|
| 140 | + public function getGroupMembership($principal, $needGroups = false) { |
|
| 141 | + list($prefix, $name) = URLUtil::splitPath($principal); |
|
| 142 | + |
|
| 143 | + if ($prefix === $this->principalPrefix) { |
|
| 144 | + $user = $this->userManager->get($name); |
|
| 145 | + if (!$user) { |
|
| 146 | + throw new Exception('Principal not found'); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + if ($this->hasGroups || $needGroups) { |
|
| 150 | + $groups = $this->groupManager->getUserGroups($user); |
|
| 151 | + $groups = array_map(function($group) { |
|
| 152 | + /** @var IGroup $group */ |
|
| 153 | + return 'principals/groups/' . urlencode($group->getGID()); |
|
| 154 | + }, $groups); |
|
| 155 | + |
|
| 156 | + return $groups; |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + return []; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Updates the list of group members for a group principal. |
|
| 164 | + * |
|
| 165 | + * The principals should be passed as a list of uri's. |
|
| 166 | + * |
|
| 167 | + * @param string $principal |
|
| 168 | + * @param string[] $members |
|
| 169 | + * @throws Exception |
|
| 170 | + */ |
|
| 171 | + public function setGroupMemberSet($principal, array $members) { |
|
| 172 | + throw new Exception('Setting members of the group is not supported yet'); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * @param string $path |
|
| 177 | + * @param PropPatch $propPatch |
|
| 178 | + * @return int |
|
| 179 | + */ |
|
| 180 | + function updatePrincipal($path, PropPatch $propPatch) { |
|
| 181 | + return 0; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * @param string $prefixPath |
|
| 186 | + * @param array $searchProperties |
|
| 187 | + * @param string $test |
|
| 188 | + * @return array |
|
| 189 | + */ |
|
| 190 | + function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { |
|
| 191 | + return []; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * @param string $uri |
|
| 196 | + * @param string $principalPrefix |
|
| 197 | + * @return string |
|
| 198 | + */ |
|
| 199 | + function findByUri($uri, $principalPrefix) { |
|
| 200 | + if (substr($uri, 0, 7) === 'mailto:') { |
|
| 201 | + $email = substr($uri, 7); |
|
| 202 | + $users = $this->userManager->getByEmail($email); |
|
| 203 | + if (count($users) === 1) { |
|
| 204 | + return $this->principalPrefix . '/' . $users[0]->getUID(); |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + return ''; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * @param IUser $user |
|
| 213 | + * @return array |
|
| 214 | + */ |
|
| 215 | + protected function userToPrincipal($user) { |
|
| 216 | + $userId = $user->getUID(); |
|
| 217 | + $displayName = $user->getDisplayName(); |
|
| 218 | + $principal = [ |
|
| 219 | + 'uri' => $this->principalPrefix . '/' . $userId, |
|
| 220 | + '{DAV:}displayname' => is_null($displayName) ? $userId : $displayName, |
|
| 221 | + ]; |
|
| 222 | + |
|
| 223 | + $email = $user->getEMailAddress(); |
|
| 224 | + if (!empty($email)) { |
|
| 225 | + $principal['{http://sabredav.org/ns}email-address'] = $email; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + return $principal; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + public function getPrincipalPrefix() { |
|
| 232 | + return $this->principalPrefix; |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | 235 | } |
@@ -98,6 +98,9 @@ |
||
| 98 | 98 | throw new Forbidden('Permission denied to delete this folder'); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | + /** |
|
| 102 | + * @return string |
|
| 103 | + */ |
|
| 101 | 104 | public function getName() { |
| 102 | 105 | list(,$name) = Uri\split($this->principalInfo['uri']); |
| 103 | 106 | return $name; |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | public function getChild($name) { |
| 60 | 60 | $elements = pathinfo($name); |
| 61 | 61 | $ext = isset($elements['extension']) ? $elements['extension'] : ''; |
| 62 | - $size = (int)(isset($elements['filename']) ? $elements['filename'] : '64'); |
|
| 62 | + $size = (int) (isset($elements['filename']) ? $elements['filename'] : '64'); |
|
| 63 | 63 | if (!in_array($ext, ['jpeg', 'png'], true)) { |
| 64 | 64 | throw new MethodNotAllowed('File format not allowed'); |
| 65 | 65 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | return [ |
| 79 | 79 | $this->getChild('96.jpeg') |
| 80 | 80 | ]; |
| 81 | - } catch(NotFound $exception) { |
|
| 81 | + } catch (NotFound $exception) { |
|
| 82 | 82 | return []; |
| 83 | 83 | } |
| 84 | 84 | } |
@@ -32,89 +32,89 @@ |
||
| 32 | 32 | |
| 33 | 33 | class AvatarHome implements ICollection { |
| 34 | 34 | |
| 35 | - /** @var array */ |
|
| 36 | - private $principalInfo; |
|
| 37 | - /** @var IAvatarManager */ |
|
| 38 | - private $avatarManager; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * AvatarHome constructor. |
|
| 42 | - * |
|
| 43 | - * @param array $principalInfo |
|
| 44 | - * @param IAvatarManager $avatarManager |
|
| 45 | - */ |
|
| 46 | - public function __construct($principalInfo, IAvatarManager $avatarManager) { |
|
| 47 | - $this->principalInfo = $principalInfo; |
|
| 48 | - $this->avatarManager = $avatarManager; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public function createFile($name, $data = null) { |
|
| 52 | - throw new Forbidden('Permission denied to create a file'); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - public function createDirectory($name) { |
|
| 56 | - throw new Forbidden('Permission denied to create a folder'); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - public function getChild($name) { |
|
| 60 | - $elements = pathinfo($name); |
|
| 61 | - $ext = isset($elements['extension']) ? $elements['extension'] : ''; |
|
| 62 | - $size = (int)(isset($elements['filename']) ? $elements['filename'] : '64'); |
|
| 63 | - if (!in_array($ext, ['jpeg', 'png'], true)) { |
|
| 64 | - throw new MethodNotAllowed('File format not allowed'); |
|
| 65 | - } |
|
| 66 | - if ($size <= 0 || $size > 1024) { |
|
| 67 | - throw new MethodNotAllowed('Invalid image size'); |
|
| 68 | - } |
|
| 69 | - $avatar = $this->avatarManager->getAvatar($this->getName()); |
|
| 70 | - if ($avatar === null || !$avatar->exists()) { |
|
| 71 | - throw new NotFound(); |
|
| 72 | - } |
|
| 73 | - return new AvatarNode($size, $ext, $avatar); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - public function getChildren() { |
|
| 77 | - try { |
|
| 78 | - return [ |
|
| 79 | - $this->getChild('96.jpeg') |
|
| 80 | - ]; |
|
| 81 | - } catch(NotFound $exception) { |
|
| 82 | - return []; |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - public function childExists($name) { |
|
| 87 | - try { |
|
| 88 | - $ret = $this->getChild($name); |
|
| 89 | - return $ret !== null; |
|
| 90 | - } catch (NotFound $ex) { |
|
| 91 | - return false; |
|
| 92 | - } catch (MethodNotAllowed $ex) { |
|
| 93 | - return false; |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - public function delete() { |
|
| 98 | - throw new Forbidden('Permission denied to delete this folder'); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - public function getName() { |
|
| 102 | - list(,$name) = Uri\split($this->principalInfo['uri']); |
|
| 103 | - return $name; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - public function setName($name) { |
|
| 107 | - throw new Forbidden('Permission denied to rename this folder'); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Returns the last modification time, as a unix timestamp |
|
| 112 | - * |
|
| 113 | - * @return int|null |
|
| 114 | - */ |
|
| 115 | - public function getLastModified() { |
|
| 116 | - return null; |
|
| 117 | - } |
|
| 35 | + /** @var array */ |
|
| 36 | + private $principalInfo; |
|
| 37 | + /** @var IAvatarManager */ |
|
| 38 | + private $avatarManager; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * AvatarHome constructor. |
|
| 42 | + * |
|
| 43 | + * @param array $principalInfo |
|
| 44 | + * @param IAvatarManager $avatarManager |
|
| 45 | + */ |
|
| 46 | + public function __construct($principalInfo, IAvatarManager $avatarManager) { |
|
| 47 | + $this->principalInfo = $principalInfo; |
|
| 48 | + $this->avatarManager = $avatarManager; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public function createFile($name, $data = null) { |
|
| 52 | + throw new Forbidden('Permission denied to create a file'); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + public function createDirectory($name) { |
|
| 56 | + throw new Forbidden('Permission denied to create a folder'); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + public function getChild($name) { |
|
| 60 | + $elements = pathinfo($name); |
|
| 61 | + $ext = isset($elements['extension']) ? $elements['extension'] : ''; |
|
| 62 | + $size = (int)(isset($elements['filename']) ? $elements['filename'] : '64'); |
|
| 63 | + if (!in_array($ext, ['jpeg', 'png'], true)) { |
|
| 64 | + throw new MethodNotAllowed('File format not allowed'); |
|
| 65 | + } |
|
| 66 | + if ($size <= 0 || $size > 1024) { |
|
| 67 | + throw new MethodNotAllowed('Invalid image size'); |
|
| 68 | + } |
|
| 69 | + $avatar = $this->avatarManager->getAvatar($this->getName()); |
|
| 70 | + if ($avatar === null || !$avatar->exists()) { |
|
| 71 | + throw new NotFound(); |
|
| 72 | + } |
|
| 73 | + return new AvatarNode($size, $ext, $avatar); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + public function getChildren() { |
|
| 77 | + try { |
|
| 78 | + return [ |
|
| 79 | + $this->getChild('96.jpeg') |
|
| 80 | + ]; |
|
| 81 | + } catch(NotFound $exception) { |
|
| 82 | + return []; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + public function childExists($name) { |
|
| 87 | + try { |
|
| 88 | + $ret = $this->getChild($name); |
|
| 89 | + return $ret !== null; |
|
| 90 | + } catch (NotFound $ex) { |
|
| 91 | + return false; |
|
| 92 | + } catch (MethodNotAllowed $ex) { |
|
| 93 | + return false; |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + public function delete() { |
|
| 98 | + throw new Forbidden('Permission denied to delete this folder'); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + public function getName() { |
|
| 102 | + list(,$name) = Uri\split($this->principalInfo['uri']); |
|
| 103 | + return $name; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + public function setName($name) { |
|
| 107 | + throw new Forbidden('Permission denied to rename this folder'); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Returns the last modification time, as a unix timestamp |
|
| 112 | + * |
|
| 113 | + * @return int|null |
|
| 114 | + */ |
|
| 115 | + public function getLastModified() { |
|
| 116 | + return null; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | 119 | |
| 120 | 120 | } |
@@ -27,71 +27,71 @@ |
||
| 27 | 27 | use Sabre\DAV\File; |
| 28 | 28 | |
| 29 | 29 | class AvatarNode extends File { |
| 30 | - private $ext; |
|
| 31 | - private $size; |
|
| 32 | - private $avatar; |
|
| 30 | + private $ext; |
|
| 31 | + private $size; |
|
| 32 | + private $avatar; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * AvatarNode constructor. |
|
| 36 | - * |
|
| 37 | - * @param integer $size |
|
| 38 | - * @param string $ext |
|
| 39 | - * @param IAvatar $avatar |
|
| 40 | - */ |
|
| 41 | - public function __construct($size, $ext, $avatar) { |
|
| 42 | - $this->size = $size; |
|
| 43 | - $this->ext = $ext; |
|
| 44 | - $this->avatar = $avatar; |
|
| 45 | - } |
|
| 34 | + /** |
|
| 35 | + * AvatarNode constructor. |
|
| 36 | + * |
|
| 37 | + * @param integer $size |
|
| 38 | + * @param string $ext |
|
| 39 | + * @param IAvatar $avatar |
|
| 40 | + */ |
|
| 41 | + public function __construct($size, $ext, $avatar) { |
|
| 42 | + $this->size = $size; |
|
| 43 | + $this->ext = $ext; |
|
| 44 | + $this->avatar = $avatar; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Returns the name of the node. |
|
| 49 | - * |
|
| 50 | - * This is used to generate the url. |
|
| 51 | - * |
|
| 52 | - * @return string |
|
| 53 | - */ |
|
| 54 | - public function getName() { |
|
| 55 | - return "$this->size.$this->ext"; |
|
| 56 | - } |
|
| 47 | + /** |
|
| 48 | + * Returns the name of the node. |
|
| 49 | + * |
|
| 50 | + * This is used to generate the url. |
|
| 51 | + * |
|
| 52 | + * @return string |
|
| 53 | + */ |
|
| 54 | + public function getName() { |
|
| 55 | + return "$this->size.$this->ext"; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - public function get() { |
|
| 59 | - $image = $this->avatar->get($this->size); |
|
| 60 | - $res = $image->resource(); |
|
| 58 | + public function get() { |
|
| 59 | + $image = $this->avatar->get($this->size); |
|
| 60 | + $res = $image->resource(); |
|
| 61 | 61 | |
| 62 | - ob_start(); |
|
| 63 | - if ($this->ext === 'png') { |
|
| 64 | - imagepng($res); |
|
| 65 | - } |
|
| 66 | - imagejpeg($res); |
|
| 62 | + ob_start(); |
|
| 63 | + if ($this->ext === 'png') { |
|
| 64 | + imagepng($res); |
|
| 65 | + } |
|
| 66 | + imagejpeg($res); |
|
| 67 | 67 | |
| 68 | - return ob_get_clean(); |
|
| 69 | - } |
|
| 68 | + return ob_get_clean(); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Returns the mime-type for a file |
|
| 73 | - * |
|
| 74 | - * If null is returned, we'll assume application/octet-stream |
|
| 75 | - * |
|
| 76 | - * @return string|null |
|
| 77 | - */ |
|
| 78 | - public function getContentType() { |
|
| 79 | - if ($this->ext === 'png') { |
|
| 80 | - return 'image/png'; |
|
| 81 | - } |
|
| 82 | - return 'image/jpeg'; |
|
| 83 | - } |
|
| 71 | + /** |
|
| 72 | + * Returns the mime-type for a file |
|
| 73 | + * |
|
| 74 | + * If null is returned, we'll assume application/octet-stream |
|
| 75 | + * |
|
| 76 | + * @return string|null |
|
| 77 | + */ |
|
| 78 | + public function getContentType() { |
|
| 79 | + if ($this->ext === 'png') { |
|
| 80 | + return 'image/png'; |
|
| 81 | + } |
|
| 82 | + return 'image/jpeg'; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - public function getETag() { |
|
| 86 | - return $this->avatar->getFile($this->size)->getEtag(); |
|
| 87 | - } |
|
| 85 | + public function getETag() { |
|
| 86 | + return $this->avatar->getFile($this->size)->getEtag(); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - public function getLastModified() { |
|
| 90 | - $timestamp = $this->avatar->getFile($this->size)->getMTime(); |
|
| 91 | - if (!empty($timestamp)) { |
|
| 92 | - return (int)$timestamp; |
|
| 93 | - } |
|
| 94 | - return $timestamp; |
|
| 89 | + public function getLastModified() { |
|
| 90 | + $timestamp = $this->avatar->getFile($this->size)->getMTime(); |
|
| 91 | + if (!empty($timestamp)) { |
|
| 92 | + return (int)$timestamp; |
|
| 93 | + } |
|
| 94 | + return $timestamp; |
|
| 95 | 95 | |
| 96 | - } |
|
| 96 | + } |
|
| 97 | 97 | } |
@@ -89,7 +89,7 @@ |
||
| 89 | 89 | public function getLastModified() { |
| 90 | 90 | $timestamp = $this->avatar->getFile($this->size)->getMTime(); |
| 91 | 91 | if (!empty($timestamp)) { |
| 92 | - return (int)$timestamp; |
|
| 92 | + return (int) $timestamp; |
|
| 93 | 93 | } |
| 94 | 94 | return $timestamp; |
| 95 | 95 | |
@@ -7,23 +7,23 @@ |
||
| 7 | 7 | |
| 8 | 8 | class RootCollection extends AbstractPrincipalCollection { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * This method returns a node for a principal. |
|
| 12 | - * |
|
| 13 | - * The passed array contains principal information, and is guaranteed to |
|
| 14 | - * at least contain a uri item. Other properties may or may not be |
|
| 15 | - * supplied by the authentication backend. |
|
| 16 | - * |
|
| 17 | - * @param array $principalInfo |
|
| 18 | - * @return AvatarHome |
|
| 19 | - */ |
|
| 20 | - public function getChildForPrincipal(array $principalInfo) { |
|
| 21 | - $avatarManager = \OC::$server->getAvatarManager(); |
|
| 22 | - return new AvatarHome($principalInfo, $avatarManager); |
|
| 23 | - } |
|
| 10 | + /** |
|
| 11 | + * This method returns a node for a principal. |
|
| 12 | + * |
|
| 13 | + * The passed array contains principal information, and is guaranteed to |
|
| 14 | + * at least contain a uri item. Other properties may or may not be |
|
| 15 | + * supplied by the authentication backend. |
|
| 16 | + * |
|
| 17 | + * @param array $principalInfo |
|
| 18 | + * @return AvatarHome |
|
| 19 | + */ |
|
| 20 | + public function getChildForPrincipal(array $principalInfo) { |
|
| 21 | + $avatarManager = \OC::$server->getAvatarManager(); |
|
| 22 | + return new AvatarHome($principalInfo, $avatarManager); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - public function getName() { |
|
| 26 | - return 'avatars'; |
|
| 27 | - } |
|
| 25 | + public function getName() { |
|
| 26 | + return 'avatars'; |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | 29 | } |