@@ -35,22 +35,22 @@ discard block |
||
| 35 | 35 | use Sabre\CardDAV\Plugin; |
| 36 | 36 | |
| 37 | 37 | $authBackend = new Auth( |
| 38 | - \OC::$server->getSession(), |
|
| 39 | - \OC::$server->getUserSession(), |
|
| 40 | - \OC::$server->getRequest(), |
|
| 41 | - \OC::$server->getTwoFactorAuthManager(), |
|
| 42 | - \OC::$server->getBruteForceThrottler(), |
|
| 43 | - 'principals/' |
|
| 38 | + \OC::$server->getSession(), |
|
| 39 | + \OC::$server->getUserSession(), |
|
| 40 | + \OC::$server->getRequest(), |
|
| 41 | + \OC::$server->getTwoFactorAuthManager(), |
|
| 42 | + \OC::$server->getBruteForceThrottler(), |
|
| 43 | + 'principals/' |
|
| 44 | 44 | ); |
| 45 | 45 | $principalBackend = new Principal( |
| 46 | - \OC::$server->getUserManager(), |
|
| 47 | - \OC::$server->getGroupManager(), |
|
| 48 | - \OC::$server->getShareManager(), |
|
| 49 | - \OC::$server->getUserSession(), |
|
| 50 | - \OC::$server->getAppManager(), |
|
| 51 | - \OC::$server->query(\OCA\DAV\CalDAV\Proxy\ProxyMapper::class), |
|
| 52 | - \OC::$server->getConfig(), |
|
| 53 | - 'principals/' |
|
| 46 | + \OC::$server->getUserManager(), |
|
| 47 | + \OC::$server->getGroupManager(), |
|
| 48 | + \OC::$server->getShareManager(), |
|
| 49 | + \OC::$server->getUserSession(), |
|
| 50 | + \OC::$server->getAppManager(), |
|
| 51 | + \OC::$server->query(\OCA\DAV\CalDAV\Proxy\ProxyMapper::class), |
|
| 52 | + \OC::$server->getConfig(), |
|
| 53 | + 'principals/' |
|
| 54 | 54 | ); |
| 55 | 55 | $db = \OC::$server->getDatabaseConnection(); |
| 56 | 56 | $cardDavBackend = new CardDavBackend($db, $principalBackend, \OC::$server->getUserManager(), \OC::$server->getGroupManager(), \OC::$server->getEventDispatcher()); |
@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | $addressBookRoot->disableListing = !$debugging; // Disable listing |
| 66 | 66 | |
| 67 | 67 | $nodes = array( |
| 68 | - $principalCollection, |
|
| 69 | - $addressBookRoot, |
|
| 68 | + $principalCollection, |
|
| 69 | + $addressBookRoot, |
|
| 70 | 70 | ); |
| 71 | 71 | |
| 72 | 72 | // Fire up server |
@@ -81,14 +81,14 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | $server->addPlugin(new LegacyDAVACL()); |
| 83 | 83 | if ($debugging) { |
| 84 | - $server->addPlugin(new Sabre\DAV\Browser\Plugin()); |
|
| 84 | + $server->addPlugin(new Sabre\DAV\Browser\Plugin()); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | $server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
| 88 | 88 | $server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin()); |
| 89 | 89 | $server->addPlugin(new \OCA\DAV\CardDAV\ImageExportPlugin(new \OCA\DAV\CardDAV\PhotoCache( |
| 90 | - \OC::$server->getAppDataDir('dav-photocache'), |
|
| 91 | - \OC::$server->getLogger() |
|
| 90 | + \OC::$server->getAppDataDir('dav-photocache'), |
|
| 91 | + \OC::$server->getLogger() |
|
| 92 | 92 | ))); |
| 93 | 93 | $server->addPlugin(new ExceptionLoggerPlugin('carddav', \OC::$server->getLogger())); |
| 94 | 94 | |
@@ -34,22 +34,22 @@ discard block |
||
| 34 | 34 | use OCA\DAV\Connector\Sabre\Principal; |
| 35 | 35 | |
| 36 | 36 | $authBackend = new Auth( |
| 37 | - \OC::$server->getSession(), |
|
| 38 | - \OC::$server->getUserSession(), |
|
| 39 | - \OC::$server->getRequest(), |
|
| 40 | - \OC::$server->getTwoFactorAuthManager(), |
|
| 41 | - \OC::$server->getBruteForceThrottler(), |
|
| 42 | - 'principals/' |
|
| 37 | + \OC::$server->getSession(), |
|
| 38 | + \OC::$server->getUserSession(), |
|
| 39 | + \OC::$server->getRequest(), |
|
| 40 | + \OC::$server->getTwoFactorAuthManager(), |
|
| 41 | + \OC::$server->getBruteForceThrottler(), |
|
| 42 | + 'principals/' |
|
| 43 | 43 | ); |
| 44 | 44 | $principalBackend = new Principal( |
| 45 | - \OC::$server->getUserManager(), |
|
| 46 | - \OC::$server->getGroupManager(), |
|
| 47 | - \OC::$server->getShareManager(), |
|
| 48 | - \OC::$server->getUserSession(), |
|
| 49 | - \OC::$server->getAppManager(), |
|
| 50 | - \OC::$server->query(\OCA\DAV\CalDAV\Proxy\ProxyMapper::class), |
|
| 51 | - \OC::$server->getConfig(), |
|
| 52 | - 'principals/' |
|
| 45 | + \OC::$server->getUserManager(), |
|
| 46 | + \OC::$server->getGroupManager(), |
|
| 47 | + \OC::$server->getShareManager(), |
|
| 48 | + \OC::$server->getUserSession(), |
|
| 49 | + \OC::$server->getAppManager(), |
|
| 50 | + \OC::$server->query(\OCA\DAV\CalDAV\Proxy\ProxyMapper::class), |
|
| 51 | + \OC::$server->getConfig(), |
|
| 52 | + 'principals/' |
|
| 53 | 53 | ); |
| 54 | 54 | $db = \OC::$server->getDatabaseConnection(); |
| 55 | 55 | $userManager = \OC::$server->getUserManager(); |
@@ -69,8 +69,8 @@ discard block |
||
| 69 | 69 | $addressBookRoot->disableListing = !$debugging; // Disable listing |
| 70 | 70 | |
| 71 | 71 | $nodes = array( |
| 72 | - $principalCollection, |
|
| 73 | - $addressBookRoot, |
|
| 72 | + $principalCollection, |
|
| 73 | + $addressBookRoot, |
|
| 74 | 74 | ); |
| 75 | 75 | |
| 76 | 76 | // Fire up server |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | $server->addPlugin(new LegacyDAVACL()); |
| 88 | 88 | if ($debugging) { |
| 89 | - $server->addPlugin(new Sabre\DAV\Browser\Plugin()); |
|
| 89 | + $server->addPlugin(new Sabre\DAV\Browser\Plugin()); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | $server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | $server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
| 95 | 95 | |
| 96 | 96 | if ($sendInvitations) { |
| 97 | - $server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); |
|
| 97 | + $server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); |
|
| 98 | 98 | } |
| 99 | 99 | $server->addPlugin(new ExceptionLoggerPlugin('caldav', \OC::$server->getLogger())); |
| 100 | 100 | |
@@ -37,59 +37,59 @@ |
||
| 37 | 37 | |
| 38 | 38 | class CreateCalendar extends Command { |
| 39 | 39 | |
| 40 | - /** @var IUserManager */ |
|
| 41 | - protected $userManager; |
|
| 40 | + /** @var IUserManager */ |
|
| 41 | + protected $userManager; |
|
| 42 | 42 | |
| 43 | - /** @var IGroupManager $groupManager */ |
|
| 44 | - private $groupManager; |
|
| 43 | + /** @var IGroupManager $groupManager */ |
|
| 44 | + private $groupManager; |
|
| 45 | 45 | |
| 46 | - /** @var \OCP\IDBConnection */ |
|
| 47 | - protected $dbConnection; |
|
| 46 | + /** @var \OCP\IDBConnection */ |
|
| 47 | + protected $dbConnection; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @param IUserManager $userManager |
|
| 51 | - * @param IGroupManager $groupManager |
|
| 52 | - * @param IDBConnection $dbConnection |
|
| 53 | - */ |
|
| 54 | - function __construct(IUserManager $userManager, IGroupManager $groupManager, IDBConnection $dbConnection) { |
|
| 55 | - parent::__construct(); |
|
| 56 | - $this->userManager = $userManager; |
|
| 57 | - $this->groupManager = $groupManager; |
|
| 58 | - $this->dbConnection = $dbConnection; |
|
| 59 | - } |
|
| 49 | + /** |
|
| 50 | + * @param IUserManager $userManager |
|
| 51 | + * @param IGroupManager $groupManager |
|
| 52 | + * @param IDBConnection $dbConnection |
|
| 53 | + */ |
|
| 54 | + function __construct(IUserManager $userManager, IGroupManager $groupManager, IDBConnection $dbConnection) { |
|
| 55 | + parent::__construct(); |
|
| 56 | + $this->userManager = $userManager; |
|
| 57 | + $this->groupManager = $groupManager; |
|
| 58 | + $this->dbConnection = $dbConnection; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - protected function configure() { |
|
| 62 | - $this |
|
| 63 | - ->setName('dav:create-calendar') |
|
| 64 | - ->setDescription('Create a dav calendar') |
|
| 65 | - ->addArgument('user', |
|
| 66 | - InputArgument::REQUIRED, |
|
| 67 | - 'User for whom the calendar will be created') |
|
| 68 | - ->addArgument('name', |
|
| 69 | - InputArgument::REQUIRED, |
|
| 70 | - 'Name of the calendar'); |
|
| 71 | - } |
|
| 61 | + protected function configure() { |
|
| 62 | + $this |
|
| 63 | + ->setName('dav:create-calendar') |
|
| 64 | + ->setDescription('Create a dav calendar') |
|
| 65 | + ->addArgument('user', |
|
| 66 | + InputArgument::REQUIRED, |
|
| 67 | + 'User for whom the calendar will be created') |
|
| 68 | + ->addArgument('name', |
|
| 69 | + InputArgument::REQUIRED, |
|
| 70 | + 'Name of the calendar'); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 74 | - $user = $input->getArgument('user'); |
|
| 75 | - if (!$this->userManager->userExists($user)) { |
|
| 76 | - throw new \InvalidArgumentException("User <$user> in unknown."); |
|
| 77 | - } |
|
| 78 | - $principalBackend = new Principal( |
|
| 79 | - $this->userManager, |
|
| 80 | - $this->groupManager, |
|
| 81 | - \OC::$server->getShareManager(), |
|
| 82 | - \OC::$server->getUserSession(), |
|
| 83 | - \OC::$server->getAppManager(), |
|
| 84 | - \OC::$server->query(ProxyMapper::class), |
|
| 85 | - \OC::$server->getConfig() |
|
| 86 | - ); |
|
| 87 | - $random = \OC::$server->getSecureRandom(); |
|
| 88 | - $logger = \OC::$server->getLogger(); |
|
| 89 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 73 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 74 | + $user = $input->getArgument('user'); |
|
| 75 | + if (!$this->userManager->userExists($user)) { |
|
| 76 | + throw new \InvalidArgumentException("User <$user> in unknown."); |
|
| 77 | + } |
|
| 78 | + $principalBackend = new Principal( |
|
| 79 | + $this->userManager, |
|
| 80 | + $this->groupManager, |
|
| 81 | + \OC::$server->getShareManager(), |
|
| 82 | + \OC::$server->getUserSession(), |
|
| 83 | + \OC::$server->getAppManager(), |
|
| 84 | + \OC::$server->query(ProxyMapper::class), |
|
| 85 | + \OC::$server->getConfig() |
|
| 86 | + ); |
|
| 87 | + $random = \OC::$server->getSecureRandom(); |
|
| 88 | + $logger = \OC::$server->getLogger(); |
|
| 89 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 90 | 90 | |
| 91 | - $name = $input->getArgument('name'); |
|
| 92 | - $caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager, $this->groupManager, $random, $logger, $dispatcher); |
|
| 93 | - $caldav->createCalendar("principals/users/$user", $name, []); |
|
| 94 | - } |
|
| 91 | + $name = $input->getArgument('name'); |
|
| 92 | + $caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager, $this->groupManager, $random, $logger, $dispatcher); |
|
| 93 | + $caldav->createCalendar("principals/users/$user", $name, []); |
|
| 94 | + } |
|
| 95 | 95 | } |
@@ -53,455 +53,455 @@ |
||
| 53 | 53 | |
| 54 | 54 | class Principal implements BackendInterface { |
| 55 | 55 | |
| 56 | - /** @var IUserManager */ |
|
| 57 | - private $userManager; |
|
| 58 | - |
|
| 59 | - /** @var IGroupManager */ |
|
| 60 | - private $groupManager; |
|
| 61 | - |
|
| 62 | - /** @var IShareManager */ |
|
| 63 | - private $shareManager; |
|
| 64 | - |
|
| 65 | - /** @var IUserSession */ |
|
| 66 | - private $userSession; |
|
| 67 | - |
|
| 68 | - /** @var IAppManager */ |
|
| 69 | - private $appManager; |
|
| 70 | - |
|
| 71 | - /** @var string */ |
|
| 72 | - private $principalPrefix; |
|
| 73 | - |
|
| 74 | - /** @var bool */ |
|
| 75 | - private $hasGroups; |
|
| 76 | - |
|
| 77 | - /** @var bool */ |
|
| 78 | - private $hasCircles; |
|
| 79 | - |
|
| 80 | - /** @var ProxyMapper */ |
|
| 81 | - private $proxyMapper; |
|
| 82 | - |
|
| 83 | - /** @var IConfig */ |
|
| 84 | - private $config; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Principal constructor. |
|
| 88 | - * |
|
| 89 | - * @param IUserManager $userManager |
|
| 90 | - * @param IGroupManager $groupManager |
|
| 91 | - * @param IShareManager $shareManager |
|
| 92 | - * @param IUserSession $userSession |
|
| 93 | - * @param IAppManager $appManager |
|
| 94 | - * @param ProxyMapper $proxyMapper |
|
| 95 | - * @param IConfig $config |
|
| 96 | - * @param string $principalPrefix |
|
| 97 | - */ |
|
| 98 | - public function __construct(IUserManager $userManager, |
|
| 99 | - IGroupManager $groupManager, |
|
| 100 | - IShareManager $shareManager, |
|
| 101 | - IUserSession $userSession, |
|
| 102 | - IAppManager $appManager, |
|
| 103 | - ProxyMapper $proxyMapper, |
|
| 104 | - IConfig $config, |
|
| 105 | - string $principalPrefix = 'principals/users/') { |
|
| 106 | - $this->userManager = $userManager; |
|
| 107 | - $this->groupManager = $groupManager; |
|
| 108 | - $this->shareManager = $shareManager; |
|
| 109 | - $this->userSession = $userSession; |
|
| 110 | - $this->appManager = $appManager; |
|
| 111 | - $this->principalPrefix = trim($principalPrefix, '/'); |
|
| 112 | - $this->hasGroups = $this->hasCircles = ($principalPrefix === 'principals/users/'); |
|
| 113 | - $this->proxyMapper = $proxyMapper; |
|
| 114 | - $this->config = $config; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - use PrincipalProxyTrait { |
|
| 118 | - getGroupMembership as protected traitGetGroupMembership; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Returns a list of principals based on a prefix. |
|
| 123 | - * |
|
| 124 | - * This prefix will often contain something like 'principals'. You are only |
|
| 125 | - * expected to return principals that are in this base path. |
|
| 126 | - * |
|
| 127 | - * You are expected to return at least a 'uri' for every user, you can |
|
| 128 | - * return any additional properties if you wish so. Common properties are: |
|
| 129 | - * {DAV:}displayname |
|
| 130 | - * |
|
| 131 | - * @param string $prefixPath |
|
| 132 | - * @return string[] |
|
| 133 | - */ |
|
| 134 | - public function getPrincipalsByPrefix($prefixPath) { |
|
| 135 | - $principals = []; |
|
| 136 | - |
|
| 137 | - if ($prefixPath === $this->principalPrefix) { |
|
| 138 | - foreach($this->userManager->search('') as $user) { |
|
| 139 | - $principals[] = $this->userToPrincipal($user); |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - return $principals; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Returns a specific principal, specified by it's path. |
|
| 148 | - * The returned structure should be the exact same as from |
|
| 149 | - * getPrincipalsByPrefix. |
|
| 150 | - * |
|
| 151 | - * @param string $path |
|
| 152 | - * @return array |
|
| 153 | - */ |
|
| 154 | - public function getPrincipalByPath($path) { |
|
| 155 | - list($prefix, $name) = \Sabre\Uri\split($path); |
|
| 156 | - |
|
| 157 | - if ($name === 'calendar-proxy-write' || $name === 'calendar-proxy-read') { |
|
| 158 | - list($prefix2, $name2) = \Sabre\Uri\split($prefix); |
|
| 159 | - |
|
| 160 | - if ($prefix2 === $this->principalPrefix) { |
|
| 161 | - $user = $this->userManager->get($name2); |
|
| 162 | - |
|
| 163 | - if ($user !== null) { |
|
| 164 | - return [ |
|
| 165 | - 'uri' => 'principals/users/' . $user->getUID() . '/' . $name, |
|
| 166 | - ]; |
|
| 167 | - } |
|
| 168 | - return null; |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - if ($prefix === $this->principalPrefix) { |
|
| 173 | - $user = $this->userManager->get($name); |
|
| 174 | - |
|
| 175 | - if ($user !== null) { |
|
| 176 | - return $this->userToPrincipal($user); |
|
| 177 | - } |
|
| 178 | - } else if ($prefix === 'principals/circles') { |
|
| 179 | - try { |
|
| 180 | - return $this->circleToPrincipal($name); |
|
| 181 | - } catch (QueryException $e) { |
|
| 182 | - return null; |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - return null; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Returns the list of groups a principal is a member of |
|
| 190 | - * |
|
| 191 | - * @param string $principal |
|
| 192 | - * @param bool $needGroups |
|
| 193 | - * @return array |
|
| 194 | - * @throws Exception |
|
| 195 | - */ |
|
| 196 | - public function getGroupMembership($principal, $needGroups = false) { |
|
| 197 | - list($prefix, $name) = \Sabre\Uri\split($principal); |
|
| 198 | - |
|
| 199 | - if ($prefix !== $this->principalPrefix) { |
|
| 200 | - return []; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - $user = $this->userManager->get($name); |
|
| 204 | - if (!$user) { |
|
| 205 | - throw new Exception('Principal not found'); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - $groups = []; |
|
| 209 | - |
|
| 210 | - if ($this->hasGroups || $needGroups) { |
|
| 211 | - $userGroups = $this->groupManager->getUserGroups($user); |
|
| 212 | - foreach($userGroups as $userGroup) { |
|
| 213 | - $groups[] = 'principals/groups/' . urlencode($userGroup->getGID()); |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - $groups = array_unique(array_merge( |
|
| 218 | - $groups, |
|
| 219 | - $this->traitGetGroupMembership($principal, $needGroups) |
|
| 220 | - )); |
|
| 221 | - |
|
| 222 | - return $groups; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * @param string $path |
|
| 227 | - * @param PropPatch $propPatch |
|
| 228 | - * @return int |
|
| 229 | - */ |
|
| 230 | - function updatePrincipal($path, PropPatch $propPatch) { |
|
| 231 | - return 0; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Search user principals |
|
| 236 | - * |
|
| 237 | - * @param array $searchProperties |
|
| 238 | - * @param string $test |
|
| 239 | - * @return array |
|
| 240 | - */ |
|
| 241 | - protected function searchUserPrincipals(array $searchProperties, $test = 'allof') { |
|
| 242 | - $results = []; |
|
| 243 | - |
|
| 244 | - // If sharing is disabled, return the empty array |
|
| 245 | - $shareAPIEnabled = $this->shareManager->shareApiEnabled(); |
|
| 246 | - if (!$shareAPIEnabled) { |
|
| 247 | - return []; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - $allowEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
| 251 | - |
|
| 252 | - // If sharing is restricted to group members only, |
|
| 253 | - // return only members that have groups in common |
|
| 254 | - $restrictGroups = false; |
|
| 255 | - if ($this->shareManager->shareWithGroupMembersOnly()) { |
|
| 256 | - $user = $this->userSession->getUser(); |
|
| 257 | - if (!$user) { |
|
| 258 | - return []; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - $restrictGroups = $this->groupManager->getUserGroupIds($user); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - foreach ($searchProperties as $prop => $value) { |
|
| 265 | - switch ($prop) { |
|
| 266 | - case '{http://sabredav.org/ns}email-address': |
|
| 267 | - $users = $this->userManager->getByEmail($value); |
|
| 268 | - |
|
| 269 | - if (!$allowEnumeration) { |
|
| 270 | - $users = \array_filter($users, static function(IUser $user) use ($value) { |
|
| 271 | - return $user->getEMailAddress() === $value; |
|
| 272 | - }); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - $results[] = array_reduce($users, function(array $carry, IUser $user) use ($restrictGroups) { |
|
| 276 | - // is sharing restricted to groups only? |
|
| 277 | - if ($restrictGroups !== false) { |
|
| 278 | - $userGroups = $this->groupManager->getUserGroupIds($user); |
|
| 279 | - if (count(array_intersect($userGroups, $restrictGroups)) === 0) { |
|
| 280 | - return $carry; |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - $carry[] = $this->principalPrefix . '/' . $user->getUID(); |
|
| 285 | - return $carry; |
|
| 286 | - }, []); |
|
| 287 | - break; |
|
| 288 | - |
|
| 289 | - case '{DAV:}displayname': |
|
| 290 | - $users = $this->userManager->searchDisplayName($value); |
|
| 291 | - |
|
| 292 | - if (!$allowEnumeration) { |
|
| 293 | - $users = \array_filter($users, static function(IUser $user) use ($value) { |
|
| 294 | - return $user->getDisplayName() === $value; |
|
| 295 | - }); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - $results[] = array_reduce($users, function(array $carry, IUser $user) use ($restrictGroups) { |
|
| 299 | - // is sharing restricted to groups only? |
|
| 300 | - if ($restrictGroups !== false) { |
|
| 301 | - $userGroups = $this->groupManager->getUserGroupIds($user); |
|
| 302 | - if (count(array_intersect($userGroups, $restrictGroups)) === 0) { |
|
| 303 | - return $carry; |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - $carry[] = $this->principalPrefix . '/' . $user->getUID(); |
|
| 308 | - return $carry; |
|
| 309 | - }, []); |
|
| 310 | - break; |
|
| 311 | - |
|
| 312 | - case '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set': |
|
| 313 | - // If you add support for more search properties that qualify as a user-address, |
|
| 314 | - // please also add them to the array below |
|
| 315 | - $results[] = $this->searchUserPrincipals([ |
|
| 316 | - // In theory this should also search for principal:principals/users/... |
|
| 317 | - // but that's used internally only anyway and i don't know of any client querying that |
|
| 318 | - '{http://sabredav.org/ns}email-address' => $value, |
|
| 319 | - ], 'anyof'); |
|
| 320 | - break; |
|
| 321 | - |
|
| 322 | - default: |
|
| 323 | - $results[] = []; |
|
| 324 | - break; |
|
| 325 | - } |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - // results is an array of arrays, so this is not the first search result |
|
| 329 | - // but the results of the first searchProperty |
|
| 330 | - if (count($results) === 1) { |
|
| 331 | - return $results[0]; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - switch ($test) { |
|
| 335 | - case 'anyof': |
|
| 336 | - return array_values(array_unique(array_merge(...$results))); |
|
| 337 | - |
|
| 338 | - case 'allof': |
|
| 339 | - default: |
|
| 340 | - return array_values(array_intersect(...$results)); |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * @param string $prefixPath |
|
| 346 | - * @param array $searchProperties |
|
| 347 | - * @param string $test |
|
| 348 | - * @return array |
|
| 349 | - */ |
|
| 350 | - function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { |
|
| 351 | - if (count($searchProperties) === 0) { |
|
| 352 | - return []; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - switch ($prefixPath) { |
|
| 356 | - case 'principals/users': |
|
| 357 | - return $this->searchUserPrincipals($searchProperties, $test); |
|
| 358 | - |
|
| 359 | - default: |
|
| 360 | - return []; |
|
| 361 | - } |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * @param string $uri |
|
| 366 | - * @param string $principalPrefix |
|
| 367 | - * @return string |
|
| 368 | - */ |
|
| 369 | - function findByUri($uri, $principalPrefix) { |
|
| 370 | - // If sharing is disabled, return the empty array |
|
| 371 | - $shareAPIEnabled = $this->shareManager->shareApiEnabled(); |
|
| 372 | - if (!$shareAPIEnabled) { |
|
| 373 | - return null; |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - // If sharing is restricted to group members only, |
|
| 377 | - // return only members that have groups in common |
|
| 378 | - $restrictGroups = false; |
|
| 379 | - if ($this->shareManager->shareWithGroupMembersOnly()) { |
|
| 380 | - $user = $this->userSession->getUser(); |
|
| 381 | - if (!$user) { |
|
| 382 | - return null; |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - $restrictGroups = $this->groupManager->getUserGroupIds($user); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - if (strpos($uri, 'mailto:') === 0) { |
|
| 389 | - if ($principalPrefix === 'principals/users') { |
|
| 390 | - $users = $this->userManager->getByEmail(substr($uri, 7)); |
|
| 391 | - if (count($users) !== 1) { |
|
| 392 | - return null; |
|
| 393 | - } |
|
| 394 | - $user = $users[0]; |
|
| 395 | - |
|
| 396 | - if ($restrictGroups !== false) { |
|
| 397 | - $userGroups = $this->groupManager->getUserGroupIds($user); |
|
| 398 | - if (count(array_intersect($userGroups, $restrictGroups)) === 0) { |
|
| 399 | - return null; |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - return $this->principalPrefix . '/' . $user->getUID(); |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - if (substr($uri, 0, 10) === 'principal:') { |
|
| 407 | - $principal = substr($uri, 10); |
|
| 408 | - $principal = $this->getPrincipalByPath($principal); |
|
| 409 | - if ($principal !== null) { |
|
| 410 | - return $principal['uri']; |
|
| 411 | - } |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - return null; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * @param IUser $user |
|
| 419 | - * @return array |
|
| 420 | - */ |
|
| 421 | - protected function userToPrincipal($user) { |
|
| 422 | - $userId = $user->getUID(); |
|
| 423 | - $displayName = $user->getDisplayName(); |
|
| 424 | - $principal = [ |
|
| 425 | - 'uri' => $this->principalPrefix . '/' . $userId, |
|
| 426 | - '{DAV:}displayname' => is_null($displayName) ? $userId : $displayName, |
|
| 427 | - '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL', |
|
| 428 | - ]; |
|
| 429 | - |
|
| 430 | - $email = $user->getEMailAddress(); |
|
| 431 | - if (!empty($email)) { |
|
| 432 | - $principal['{http://sabredav.org/ns}email-address'] = $email; |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - return $principal; |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - public function getPrincipalPrefix() { |
|
| 439 | - return $this->principalPrefix; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * @param string $circleUniqueId |
|
| 444 | - * @return array|null |
|
| 445 | - * @throws \OCP\AppFramework\QueryException |
|
| 446 | - * @suppress PhanUndeclaredClassMethod |
|
| 447 | - * @suppress PhanUndeclaredClassCatch |
|
| 448 | - */ |
|
| 449 | - protected function circleToPrincipal($circleUniqueId) { |
|
| 450 | - if (!$this->appManager->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) { |
|
| 451 | - return null; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - try { |
|
| 455 | - $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($circleUniqueId, true); |
|
| 456 | - } catch(QueryException $ex) { |
|
| 457 | - return null; |
|
| 458 | - } catch(CircleDoesNotExistException $ex) { |
|
| 459 | - return null; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - if (!$circle) { |
|
| 463 | - return null; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - $principal = [ |
|
| 467 | - 'uri' => 'principals/circles/' . $circleUniqueId, |
|
| 468 | - '{DAV:}displayname' => $circle->getName(), |
|
| 469 | - ]; |
|
| 470 | - |
|
| 471 | - return $principal; |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * Returns the list of circles a principal is a member of |
|
| 476 | - * |
|
| 477 | - * @param string $principal |
|
| 478 | - * @return array |
|
| 479 | - * @throws Exception |
|
| 480 | - * @throws \OCP\AppFramework\QueryException |
|
| 481 | - * @suppress PhanUndeclaredClassMethod |
|
| 482 | - */ |
|
| 483 | - public function getCircleMembership($principal):array { |
|
| 484 | - if (!$this->appManager->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) { |
|
| 485 | - return []; |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - list($prefix, $name) = \Sabre\Uri\split($principal); |
|
| 489 | - if ($this->hasCircles && $prefix === $this->principalPrefix) { |
|
| 490 | - $user = $this->userManager->get($name); |
|
| 491 | - if (!$user) { |
|
| 492 | - throw new Exception('Principal not found'); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - $circles = \OCA\Circles\Api\v1\Circles::joinedCircles($name, true); |
|
| 496 | - |
|
| 497 | - $circles = array_map(function($circle) { |
|
| 498 | - /** @var \OCA\Circles\Model\Circle $circle */ |
|
| 499 | - return 'principals/circles/' . urlencode($circle->getUniqueId()); |
|
| 500 | - }, $circles); |
|
| 501 | - |
|
| 502 | - return $circles; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - return []; |
|
| 506 | - } |
|
| 56 | + /** @var IUserManager */ |
|
| 57 | + private $userManager; |
|
| 58 | + |
|
| 59 | + /** @var IGroupManager */ |
|
| 60 | + private $groupManager; |
|
| 61 | + |
|
| 62 | + /** @var IShareManager */ |
|
| 63 | + private $shareManager; |
|
| 64 | + |
|
| 65 | + /** @var IUserSession */ |
|
| 66 | + private $userSession; |
|
| 67 | + |
|
| 68 | + /** @var IAppManager */ |
|
| 69 | + private $appManager; |
|
| 70 | + |
|
| 71 | + /** @var string */ |
|
| 72 | + private $principalPrefix; |
|
| 73 | + |
|
| 74 | + /** @var bool */ |
|
| 75 | + private $hasGroups; |
|
| 76 | + |
|
| 77 | + /** @var bool */ |
|
| 78 | + private $hasCircles; |
|
| 79 | + |
|
| 80 | + /** @var ProxyMapper */ |
|
| 81 | + private $proxyMapper; |
|
| 82 | + |
|
| 83 | + /** @var IConfig */ |
|
| 84 | + private $config; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Principal constructor. |
|
| 88 | + * |
|
| 89 | + * @param IUserManager $userManager |
|
| 90 | + * @param IGroupManager $groupManager |
|
| 91 | + * @param IShareManager $shareManager |
|
| 92 | + * @param IUserSession $userSession |
|
| 93 | + * @param IAppManager $appManager |
|
| 94 | + * @param ProxyMapper $proxyMapper |
|
| 95 | + * @param IConfig $config |
|
| 96 | + * @param string $principalPrefix |
|
| 97 | + */ |
|
| 98 | + public function __construct(IUserManager $userManager, |
|
| 99 | + IGroupManager $groupManager, |
|
| 100 | + IShareManager $shareManager, |
|
| 101 | + IUserSession $userSession, |
|
| 102 | + IAppManager $appManager, |
|
| 103 | + ProxyMapper $proxyMapper, |
|
| 104 | + IConfig $config, |
|
| 105 | + string $principalPrefix = 'principals/users/') { |
|
| 106 | + $this->userManager = $userManager; |
|
| 107 | + $this->groupManager = $groupManager; |
|
| 108 | + $this->shareManager = $shareManager; |
|
| 109 | + $this->userSession = $userSession; |
|
| 110 | + $this->appManager = $appManager; |
|
| 111 | + $this->principalPrefix = trim($principalPrefix, '/'); |
|
| 112 | + $this->hasGroups = $this->hasCircles = ($principalPrefix === 'principals/users/'); |
|
| 113 | + $this->proxyMapper = $proxyMapper; |
|
| 114 | + $this->config = $config; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + use PrincipalProxyTrait { |
|
| 118 | + getGroupMembership as protected traitGetGroupMembership; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Returns a list of principals based on a prefix. |
|
| 123 | + * |
|
| 124 | + * This prefix will often contain something like 'principals'. You are only |
|
| 125 | + * expected to return principals that are in this base path. |
|
| 126 | + * |
|
| 127 | + * You are expected to return at least a 'uri' for every user, you can |
|
| 128 | + * return any additional properties if you wish so. Common properties are: |
|
| 129 | + * {DAV:}displayname |
|
| 130 | + * |
|
| 131 | + * @param string $prefixPath |
|
| 132 | + * @return string[] |
|
| 133 | + */ |
|
| 134 | + public function getPrincipalsByPrefix($prefixPath) { |
|
| 135 | + $principals = []; |
|
| 136 | + |
|
| 137 | + if ($prefixPath === $this->principalPrefix) { |
|
| 138 | + foreach($this->userManager->search('') as $user) { |
|
| 139 | + $principals[] = $this->userToPrincipal($user); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + return $principals; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Returns a specific principal, specified by it's path. |
|
| 148 | + * The returned structure should be the exact same as from |
|
| 149 | + * getPrincipalsByPrefix. |
|
| 150 | + * |
|
| 151 | + * @param string $path |
|
| 152 | + * @return array |
|
| 153 | + */ |
|
| 154 | + public function getPrincipalByPath($path) { |
|
| 155 | + list($prefix, $name) = \Sabre\Uri\split($path); |
|
| 156 | + |
|
| 157 | + if ($name === 'calendar-proxy-write' || $name === 'calendar-proxy-read') { |
|
| 158 | + list($prefix2, $name2) = \Sabre\Uri\split($prefix); |
|
| 159 | + |
|
| 160 | + if ($prefix2 === $this->principalPrefix) { |
|
| 161 | + $user = $this->userManager->get($name2); |
|
| 162 | + |
|
| 163 | + if ($user !== null) { |
|
| 164 | + return [ |
|
| 165 | + 'uri' => 'principals/users/' . $user->getUID() . '/' . $name, |
|
| 166 | + ]; |
|
| 167 | + } |
|
| 168 | + return null; |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + if ($prefix === $this->principalPrefix) { |
|
| 173 | + $user = $this->userManager->get($name); |
|
| 174 | + |
|
| 175 | + if ($user !== null) { |
|
| 176 | + return $this->userToPrincipal($user); |
|
| 177 | + } |
|
| 178 | + } else if ($prefix === 'principals/circles') { |
|
| 179 | + try { |
|
| 180 | + return $this->circleToPrincipal($name); |
|
| 181 | + } catch (QueryException $e) { |
|
| 182 | + return null; |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + return null; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Returns the list of groups a principal is a member of |
|
| 190 | + * |
|
| 191 | + * @param string $principal |
|
| 192 | + * @param bool $needGroups |
|
| 193 | + * @return array |
|
| 194 | + * @throws Exception |
|
| 195 | + */ |
|
| 196 | + public function getGroupMembership($principal, $needGroups = false) { |
|
| 197 | + list($prefix, $name) = \Sabre\Uri\split($principal); |
|
| 198 | + |
|
| 199 | + if ($prefix !== $this->principalPrefix) { |
|
| 200 | + return []; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + $user = $this->userManager->get($name); |
|
| 204 | + if (!$user) { |
|
| 205 | + throw new Exception('Principal not found'); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + $groups = []; |
|
| 209 | + |
|
| 210 | + if ($this->hasGroups || $needGroups) { |
|
| 211 | + $userGroups = $this->groupManager->getUserGroups($user); |
|
| 212 | + foreach($userGroups as $userGroup) { |
|
| 213 | + $groups[] = 'principals/groups/' . urlencode($userGroup->getGID()); |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + $groups = array_unique(array_merge( |
|
| 218 | + $groups, |
|
| 219 | + $this->traitGetGroupMembership($principal, $needGroups) |
|
| 220 | + )); |
|
| 221 | + |
|
| 222 | + return $groups; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * @param string $path |
|
| 227 | + * @param PropPatch $propPatch |
|
| 228 | + * @return int |
|
| 229 | + */ |
|
| 230 | + function updatePrincipal($path, PropPatch $propPatch) { |
|
| 231 | + return 0; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Search user principals |
|
| 236 | + * |
|
| 237 | + * @param array $searchProperties |
|
| 238 | + * @param string $test |
|
| 239 | + * @return array |
|
| 240 | + */ |
|
| 241 | + protected function searchUserPrincipals(array $searchProperties, $test = 'allof') { |
|
| 242 | + $results = []; |
|
| 243 | + |
|
| 244 | + // If sharing is disabled, return the empty array |
|
| 245 | + $shareAPIEnabled = $this->shareManager->shareApiEnabled(); |
|
| 246 | + if (!$shareAPIEnabled) { |
|
| 247 | + return []; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + $allowEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
| 251 | + |
|
| 252 | + // If sharing is restricted to group members only, |
|
| 253 | + // return only members that have groups in common |
|
| 254 | + $restrictGroups = false; |
|
| 255 | + if ($this->shareManager->shareWithGroupMembersOnly()) { |
|
| 256 | + $user = $this->userSession->getUser(); |
|
| 257 | + if (!$user) { |
|
| 258 | + return []; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + $restrictGroups = $this->groupManager->getUserGroupIds($user); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + foreach ($searchProperties as $prop => $value) { |
|
| 265 | + switch ($prop) { |
|
| 266 | + case '{http://sabredav.org/ns}email-address': |
|
| 267 | + $users = $this->userManager->getByEmail($value); |
|
| 268 | + |
|
| 269 | + if (!$allowEnumeration) { |
|
| 270 | + $users = \array_filter($users, static function(IUser $user) use ($value) { |
|
| 271 | + return $user->getEMailAddress() === $value; |
|
| 272 | + }); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + $results[] = array_reduce($users, function(array $carry, IUser $user) use ($restrictGroups) { |
|
| 276 | + // is sharing restricted to groups only? |
|
| 277 | + if ($restrictGroups !== false) { |
|
| 278 | + $userGroups = $this->groupManager->getUserGroupIds($user); |
|
| 279 | + if (count(array_intersect($userGroups, $restrictGroups)) === 0) { |
|
| 280 | + return $carry; |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + $carry[] = $this->principalPrefix . '/' . $user->getUID(); |
|
| 285 | + return $carry; |
|
| 286 | + }, []); |
|
| 287 | + break; |
|
| 288 | + |
|
| 289 | + case '{DAV:}displayname': |
|
| 290 | + $users = $this->userManager->searchDisplayName($value); |
|
| 291 | + |
|
| 292 | + if (!$allowEnumeration) { |
|
| 293 | + $users = \array_filter($users, static function(IUser $user) use ($value) { |
|
| 294 | + return $user->getDisplayName() === $value; |
|
| 295 | + }); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + $results[] = array_reduce($users, function(array $carry, IUser $user) use ($restrictGroups) { |
|
| 299 | + // is sharing restricted to groups only? |
|
| 300 | + if ($restrictGroups !== false) { |
|
| 301 | + $userGroups = $this->groupManager->getUserGroupIds($user); |
|
| 302 | + if (count(array_intersect($userGroups, $restrictGroups)) === 0) { |
|
| 303 | + return $carry; |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + $carry[] = $this->principalPrefix . '/' . $user->getUID(); |
|
| 308 | + return $carry; |
|
| 309 | + }, []); |
|
| 310 | + break; |
|
| 311 | + |
|
| 312 | + case '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set': |
|
| 313 | + // If you add support for more search properties that qualify as a user-address, |
|
| 314 | + // please also add them to the array below |
|
| 315 | + $results[] = $this->searchUserPrincipals([ |
|
| 316 | + // In theory this should also search for principal:principals/users/... |
|
| 317 | + // but that's used internally only anyway and i don't know of any client querying that |
|
| 318 | + '{http://sabredav.org/ns}email-address' => $value, |
|
| 319 | + ], 'anyof'); |
|
| 320 | + break; |
|
| 321 | + |
|
| 322 | + default: |
|
| 323 | + $results[] = []; |
|
| 324 | + break; |
|
| 325 | + } |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + // results is an array of arrays, so this is not the first search result |
|
| 329 | + // but the results of the first searchProperty |
|
| 330 | + if (count($results) === 1) { |
|
| 331 | + return $results[0]; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + switch ($test) { |
|
| 335 | + case 'anyof': |
|
| 336 | + return array_values(array_unique(array_merge(...$results))); |
|
| 337 | + |
|
| 338 | + case 'allof': |
|
| 339 | + default: |
|
| 340 | + return array_values(array_intersect(...$results)); |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * @param string $prefixPath |
|
| 346 | + * @param array $searchProperties |
|
| 347 | + * @param string $test |
|
| 348 | + * @return array |
|
| 349 | + */ |
|
| 350 | + function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { |
|
| 351 | + if (count($searchProperties) === 0) { |
|
| 352 | + return []; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + switch ($prefixPath) { |
|
| 356 | + case 'principals/users': |
|
| 357 | + return $this->searchUserPrincipals($searchProperties, $test); |
|
| 358 | + |
|
| 359 | + default: |
|
| 360 | + return []; |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * @param string $uri |
|
| 366 | + * @param string $principalPrefix |
|
| 367 | + * @return string |
|
| 368 | + */ |
|
| 369 | + function findByUri($uri, $principalPrefix) { |
|
| 370 | + // If sharing is disabled, return the empty array |
|
| 371 | + $shareAPIEnabled = $this->shareManager->shareApiEnabled(); |
|
| 372 | + if (!$shareAPIEnabled) { |
|
| 373 | + return null; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + // If sharing is restricted to group members only, |
|
| 377 | + // return only members that have groups in common |
|
| 378 | + $restrictGroups = false; |
|
| 379 | + if ($this->shareManager->shareWithGroupMembersOnly()) { |
|
| 380 | + $user = $this->userSession->getUser(); |
|
| 381 | + if (!$user) { |
|
| 382 | + return null; |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + $restrictGroups = $this->groupManager->getUserGroupIds($user); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + if (strpos($uri, 'mailto:') === 0) { |
|
| 389 | + if ($principalPrefix === 'principals/users') { |
|
| 390 | + $users = $this->userManager->getByEmail(substr($uri, 7)); |
|
| 391 | + if (count($users) !== 1) { |
|
| 392 | + return null; |
|
| 393 | + } |
|
| 394 | + $user = $users[0]; |
|
| 395 | + |
|
| 396 | + if ($restrictGroups !== false) { |
|
| 397 | + $userGroups = $this->groupManager->getUserGroupIds($user); |
|
| 398 | + if (count(array_intersect($userGroups, $restrictGroups)) === 0) { |
|
| 399 | + return null; |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + return $this->principalPrefix . '/' . $user->getUID(); |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + if (substr($uri, 0, 10) === 'principal:') { |
|
| 407 | + $principal = substr($uri, 10); |
|
| 408 | + $principal = $this->getPrincipalByPath($principal); |
|
| 409 | + if ($principal !== null) { |
|
| 410 | + return $principal['uri']; |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + return null; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * @param IUser $user |
|
| 419 | + * @return array |
|
| 420 | + */ |
|
| 421 | + protected function userToPrincipal($user) { |
|
| 422 | + $userId = $user->getUID(); |
|
| 423 | + $displayName = $user->getDisplayName(); |
|
| 424 | + $principal = [ |
|
| 425 | + 'uri' => $this->principalPrefix . '/' . $userId, |
|
| 426 | + '{DAV:}displayname' => is_null($displayName) ? $userId : $displayName, |
|
| 427 | + '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL', |
|
| 428 | + ]; |
|
| 429 | + |
|
| 430 | + $email = $user->getEMailAddress(); |
|
| 431 | + if (!empty($email)) { |
|
| 432 | + $principal['{http://sabredav.org/ns}email-address'] = $email; |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + return $principal; |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + public function getPrincipalPrefix() { |
|
| 439 | + return $this->principalPrefix; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * @param string $circleUniqueId |
|
| 444 | + * @return array|null |
|
| 445 | + * @throws \OCP\AppFramework\QueryException |
|
| 446 | + * @suppress PhanUndeclaredClassMethod |
|
| 447 | + * @suppress PhanUndeclaredClassCatch |
|
| 448 | + */ |
|
| 449 | + protected function circleToPrincipal($circleUniqueId) { |
|
| 450 | + if (!$this->appManager->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) { |
|
| 451 | + return null; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + try { |
|
| 455 | + $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($circleUniqueId, true); |
|
| 456 | + } catch(QueryException $ex) { |
|
| 457 | + return null; |
|
| 458 | + } catch(CircleDoesNotExistException $ex) { |
|
| 459 | + return null; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + if (!$circle) { |
|
| 463 | + return null; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + $principal = [ |
|
| 467 | + 'uri' => 'principals/circles/' . $circleUniqueId, |
|
| 468 | + '{DAV:}displayname' => $circle->getName(), |
|
| 469 | + ]; |
|
| 470 | + |
|
| 471 | + return $principal; |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * Returns the list of circles a principal is a member of |
|
| 476 | + * |
|
| 477 | + * @param string $principal |
|
| 478 | + * @return array |
|
| 479 | + * @throws Exception |
|
| 480 | + * @throws \OCP\AppFramework\QueryException |
|
| 481 | + * @suppress PhanUndeclaredClassMethod |
|
| 482 | + */ |
|
| 483 | + public function getCircleMembership($principal):array { |
|
| 484 | + if (!$this->appManager->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) { |
|
| 485 | + return []; |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + list($prefix, $name) = \Sabre\Uri\split($principal); |
|
| 489 | + if ($this->hasCircles && $prefix === $this->principalPrefix) { |
|
| 490 | + $user = $this->userManager->get($name); |
|
| 491 | + if (!$user) { |
|
| 492 | + throw new Exception('Principal not found'); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + $circles = \OCA\Circles\Api\v1\Circles::joinedCircles($name, true); |
|
| 496 | + |
|
| 497 | + $circles = array_map(function($circle) { |
|
| 498 | + /** @var \OCA\Circles\Model\Circle $circle */ |
|
| 499 | + return 'principals/circles/' . urlencode($circle->getUniqueId()); |
|
| 500 | + }, $circles); |
|
| 501 | + |
|
| 502 | + return $circles; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + return []; |
|
| 506 | + } |
|
| 507 | 507 | } |
@@ -44,131 +44,131 @@ |
||
| 44 | 44 | |
| 45 | 45 | class RootCollection extends SimpleCollection { |
| 46 | 46 | |
| 47 | - public function __construct() { |
|
| 48 | - $config = \OC::$server->getConfig(); |
|
| 49 | - $l10n = \OC::$server->getL10N('dav'); |
|
| 50 | - $random = \OC::$server->getSecureRandom(); |
|
| 51 | - $logger = \OC::$server->getLogger(); |
|
| 52 | - $userManager = \OC::$server->getUserManager(); |
|
| 53 | - $userSession = \OC::$server->getUserSession(); |
|
| 54 | - $groupManager = \OC::$server->getGroupManager(); |
|
| 55 | - $shareManager = \OC::$server->getShareManager(); |
|
| 56 | - $db = \OC::$server->getDatabaseConnection(); |
|
| 57 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 58 | - $proxyMapper = \OC::$server->query(ProxyMapper::class); |
|
| 59 | - |
|
| 60 | - $userPrincipalBackend = new Principal( |
|
| 61 | - $userManager, |
|
| 62 | - $groupManager, |
|
| 63 | - $shareManager, |
|
| 64 | - \OC::$server->getUserSession(), |
|
| 65 | - \OC::$server->getAppManager(), |
|
| 66 | - $proxyMapper, |
|
| 67 | - \OC::$server->getConfig() |
|
| 68 | - ); |
|
| 69 | - $groupPrincipalBackend = new GroupPrincipalBackend($groupManager, $userSession, $shareManager); |
|
| 70 | - $calendarResourcePrincipalBackend = new ResourcePrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper); |
|
| 71 | - $calendarRoomPrincipalBackend = new RoomPrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper); |
|
| 72 | - // as soon as debug mode is enabled we allow listing of principals |
|
| 73 | - $disableListing = !$config->getSystemValue('debug', false); |
|
| 74 | - |
|
| 75 | - // setup the first level of the dav tree |
|
| 76 | - $userPrincipals = new Collection($userPrincipalBackend, 'principals/users'); |
|
| 77 | - $userPrincipals->disableListing = $disableListing; |
|
| 78 | - $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups'); |
|
| 79 | - $groupPrincipals->disableListing = $disableListing; |
|
| 80 | - $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); |
|
| 81 | - $systemPrincipals->disableListing = $disableListing; |
|
| 82 | - $calendarResourcePrincipals = new Collection($calendarResourcePrincipalBackend, 'principals/calendar-resources'); |
|
| 83 | - $calendarResourcePrincipals->disableListing = $disableListing; |
|
| 84 | - $calendarRoomPrincipals = new Collection($calendarRoomPrincipalBackend, 'principals/calendar-rooms'); |
|
| 85 | - $calendarRoomPrincipals->disableListing = $disableListing; |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 89 | - $filesCollection->disableListing = $disableListing; |
|
| 90 | - $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); |
|
| 91 | - $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); |
|
| 92 | - $userCalendarRoot->disableListing = $disableListing; |
|
| 93 | - |
|
| 94 | - $resourceCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); |
|
| 95 | - $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources'); |
|
| 96 | - $resourceCalendarRoot->disableListing = $disableListing; |
|
| 97 | - $roomCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); |
|
| 98 | - $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $roomCalendarCaldavBackend, 'principals/calendar-rooms'); |
|
| 99 | - $roomCalendarRoot->disableListing = $disableListing; |
|
| 100 | - |
|
| 101 | - $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config); |
|
| 102 | - $publicCalendarRoot->disableListing = $disableListing; |
|
| 103 | - |
|
| 104 | - $systemTagCollection = new SystemTag\SystemTagsByIdCollection( |
|
| 105 | - \OC::$server->getSystemTagManager(), |
|
| 106 | - \OC::$server->getUserSession(), |
|
| 107 | - $groupManager |
|
| 108 | - ); |
|
| 109 | - $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection( |
|
| 110 | - \OC::$server->getSystemTagManager(), |
|
| 111 | - \OC::$server->getSystemTagObjectMapper(), |
|
| 112 | - \OC::$server->getUserSession(), |
|
| 113 | - $groupManager, |
|
| 114 | - \OC::$server->getEventDispatcher() |
|
| 115 | - ); |
|
| 116 | - $commentsCollection = new Comments\RootCollection( |
|
| 117 | - \OC::$server->getCommentsManager(), |
|
| 118 | - $userManager, |
|
| 119 | - \OC::$server->getUserSession(), |
|
| 120 | - \OC::$server->getEventDispatcher(), |
|
| 121 | - \OC::$server->getLogger() |
|
| 122 | - ); |
|
| 123 | - |
|
| 124 | - $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher); |
|
| 125 | - $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users'); |
|
| 126 | - $usersAddressBookRoot->disableListing = $disableListing; |
|
| 127 | - |
|
| 128 | - $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher); |
|
| 129 | - $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system'); |
|
| 130 | - $systemAddressBookRoot->disableListing = $disableListing; |
|
| 131 | - |
|
| 132 | - $uploadCollection = new Upload\RootCollection( |
|
| 133 | - $userPrincipalBackend, |
|
| 134 | - 'principals/users', |
|
| 135 | - \OC::$server->query(CleanupService::class)); |
|
| 136 | - $uploadCollection->disableListing = $disableListing; |
|
| 137 | - |
|
| 138 | - $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 139 | - $avatarCollection->disableListing = $disableListing; |
|
| 140 | - |
|
| 141 | - $appleProvisioning = new AppleProvisioningNode( |
|
| 142 | - \OC::$server->query(ITimeFactory::class)); |
|
| 143 | - |
|
| 144 | - $children = [ |
|
| 145 | - new SimpleCollection('principals', [ |
|
| 146 | - $userPrincipals, |
|
| 147 | - $groupPrincipals, |
|
| 148 | - $systemPrincipals, |
|
| 149 | - $calendarResourcePrincipals, |
|
| 150 | - $calendarRoomPrincipals]), |
|
| 151 | - $filesCollection, |
|
| 152 | - $userCalendarRoot, |
|
| 153 | - new SimpleCollection('system-calendars', [ |
|
| 154 | - $resourceCalendarRoot, |
|
| 155 | - $roomCalendarRoot, |
|
| 156 | - ]), |
|
| 157 | - $publicCalendarRoot, |
|
| 158 | - new SimpleCollection('addressbooks', [ |
|
| 159 | - $usersAddressBookRoot, |
|
| 160 | - $systemAddressBookRoot]), |
|
| 161 | - $systemTagCollection, |
|
| 162 | - $systemTagRelationsCollection, |
|
| 163 | - $commentsCollection, |
|
| 164 | - $uploadCollection, |
|
| 165 | - $avatarCollection, |
|
| 166 | - new SimpleCollection('provisioning', [ |
|
| 167 | - $appleProvisioning |
|
| 168 | - ]) |
|
| 169 | - ]; |
|
| 170 | - |
|
| 171 | - parent::__construct('root', $children); |
|
| 172 | - } |
|
| 47 | + public function __construct() { |
|
| 48 | + $config = \OC::$server->getConfig(); |
|
| 49 | + $l10n = \OC::$server->getL10N('dav'); |
|
| 50 | + $random = \OC::$server->getSecureRandom(); |
|
| 51 | + $logger = \OC::$server->getLogger(); |
|
| 52 | + $userManager = \OC::$server->getUserManager(); |
|
| 53 | + $userSession = \OC::$server->getUserSession(); |
|
| 54 | + $groupManager = \OC::$server->getGroupManager(); |
|
| 55 | + $shareManager = \OC::$server->getShareManager(); |
|
| 56 | + $db = \OC::$server->getDatabaseConnection(); |
|
| 57 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 58 | + $proxyMapper = \OC::$server->query(ProxyMapper::class); |
|
| 59 | + |
|
| 60 | + $userPrincipalBackend = new Principal( |
|
| 61 | + $userManager, |
|
| 62 | + $groupManager, |
|
| 63 | + $shareManager, |
|
| 64 | + \OC::$server->getUserSession(), |
|
| 65 | + \OC::$server->getAppManager(), |
|
| 66 | + $proxyMapper, |
|
| 67 | + \OC::$server->getConfig() |
|
| 68 | + ); |
|
| 69 | + $groupPrincipalBackend = new GroupPrincipalBackend($groupManager, $userSession, $shareManager); |
|
| 70 | + $calendarResourcePrincipalBackend = new ResourcePrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper); |
|
| 71 | + $calendarRoomPrincipalBackend = new RoomPrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper); |
|
| 72 | + // as soon as debug mode is enabled we allow listing of principals |
|
| 73 | + $disableListing = !$config->getSystemValue('debug', false); |
|
| 74 | + |
|
| 75 | + // setup the first level of the dav tree |
|
| 76 | + $userPrincipals = new Collection($userPrincipalBackend, 'principals/users'); |
|
| 77 | + $userPrincipals->disableListing = $disableListing; |
|
| 78 | + $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups'); |
|
| 79 | + $groupPrincipals->disableListing = $disableListing; |
|
| 80 | + $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); |
|
| 81 | + $systemPrincipals->disableListing = $disableListing; |
|
| 82 | + $calendarResourcePrincipals = new Collection($calendarResourcePrincipalBackend, 'principals/calendar-resources'); |
|
| 83 | + $calendarResourcePrincipals->disableListing = $disableListing; |
|
| 84 | + $calendarRoomPrincipals = new Collection($calendarRoomPrincipalBackend, 'principals/calendar-rooms'); |
|
| 85 | + $calendarRoomPrincipals->disableListing = $disableListing; |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 89 | + $filesCollection->disableListing = $disableListing; |
|
| 90 | + $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); |
|
| 91 | + $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); |
|
| 92 | + $userCalendarRoot->disableListing = $disableListing; |
|
| 93 | + |
|
| 94 | + $resourceCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); |
|
| 95 | + $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources'); |
|
| 96 | + $resourceCalendarRoot->disableListing = $disableListing; |
|
| 97 | + $roomCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); |
|
| 98 | + $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $roomCalendarCaldavBackend, 'principals/calendar-rooms'); |
|
| 99 | + $roomCalendarRoot->disableListing = $disableListing; |
|
| 100 | + |
|
| 101 | + $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config); |
|
| 102 | + $publicCalendarRoot->disableListing = $disableListing; |
|
| 103 | + |
|
| 104 | + $systemTagCollection = new SystemTag\SystemTagsByIdCollection( |
|
| 105 | + \OC::$server->getSystemTagManager(), |
|
| 106 | + \OC::$server->getUserSession(), |
|
| 107 | + $groupManager |
|
| 108 | + ); |
|
| 109 | + $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection( |
|
| 110 | + \OC::$server->getSystemTagManager(), |
|
| 111 | + \OC::$server->getSystemTagObjectMapper(), |
|
| 112 | + \OC::$server->getUserSession(), |
|
| 113 | + $groupManager, |
|
| 114 | + \OC::$server->getEventDispatcher() |
|
| 115 | + ); |
|
| 116 | + $commentsCollection = new Comments\RootCollection( |
|
| 117 | + \OC::$server->getCommentsManager(), |
|
| 118 | + $userManager, |
|
| 119 | + \OC::$server->getUserSession(), |
|
| 120 | + \OC::$server->getEventDispatcher(), |
|
| 121 | + \OC::$server->getLogger() |
|
| 122 | + ); |
|
| 123 | + |
|
| 124 | + $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher); |
|
| 125 | + $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users'); |
|
| 126 | + $usersAddressBookRoot->disableListing = $disableListing; |
|
| 127 | + |
|
| 128 | + $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher); |
|
| 129 | + $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system'); |
|
| 130 | + $systemAddressBookRoot->disableListing = $disableListing; |
|
| 131 | + |
|
| 132 | + $uploadCollection = new Upload\RootCollection( |
|
| 133 | + $userPrincipalBackend, |
|
| 134 | + 'principals/users', |
|
| 135 | + \OC::$server->query(CleanupService::class)); |
|
| 136 | + $uploadCollection->disableListing = $disableListing; |
|
| 137 | + |
|
| 138 | + $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 139 | + $avatarCollection->disableListing = $disableListing; |
|
| 140 | + |
|
| 141 | + $appleProvisioning = new AppleProvisioningNode( |
|
| 142 | + \OC::$server->query(ITimeFactory::class)); |
|
| 143 | + |
|
| 144 | + $children = [ |
|
| 145 | + new SimpleCollection('principals', [ |
|
| 146 | + $userPrincipals, |
|
| 147 | + $groupPrincipals, |
|
| 148 | + $systemPrincipals, |
|
| 149 | + $calendarResourcePrincipals, |
|
| 150 | + $calendarRoomPrincipals]), |
|
| 151 | + $filesCollection, |
|
| 152 | + $userCalendarRoot, |
|
| 153 | + new SimpleCollection('system-calendars', [ |
|
| 154 | + $resourceCalendarRoot, |
|
| 155 | + $roomCalendarRoot, |
|
| 156 | + ]), |
|
| 157 | + $publicCalendarRoot, |
|
| 158 | + new SimpleCollection('addressbooks', [ |
|
| 159 | + $usersAddressBookRoot, |
|
| 160 | + $systemAddressBookRoot]), |
|
| 161 | + $systemTagCollection, |
|
| 162 | + $systemTagRelationsCollection, |
|
| 163 | + $commentsCollection, |
|
| 164 | + $uploadCollection, |
|
| 165 | + $avatarCollection, |
|
| 166 | + new SimpleCollection('provisioning', [ |
|
| 167 | + $appleProvisioning |
|
| 168 | + ]) |
|
| 169 | + ]; |
|
| 170 | + |
|
| 171 | + parent::__construct('root', $children); |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | 174 | } |
@@ -34,64 +34,64 @@ |
||
| 34 | 34 | use OCP\AppFramework\Utility\ITimeFactory; |
| 35 | 35 | |
| 36 | 36 | class Application extends App { |
| 37 | - public function __construct (array $urlParams = []) { |
|
| 38 | - parent::__construct('files_trashbin', $urlParams); |
|
| 37 | + public function __construct (array $urlParams = []) { |
|
| 38 | + parent::__construct('files_trashbin', $urlParams); |
|
| 39 | 39 | |
| 40 | - $container = $this->getContainer(); |
|
| 41 | - /* |
|
| 40 | + $container = $this->getContainer(); |
|
| 41 | + /* |
|
| 42 | 42 | * Register capabilities |
| 43 | 43 | */ |
| 44 | - $container->registerCapability(Capabilities::class); |
|
| 44 | + $container->registerCapability(Capabilities::class); |
|
| 45 | 45 | |
| 46 | - /* |
|
| 46 | + /* |
|
| 47 | 47 | * Register expiration |
| 48 | 48 | */ |
| 49 | - $container->registerAlias('Expiration', Expiration::class); |
|
| 49 | + $container->registerAlias('Expiration', Expiration::class); |
|
| 50 | 50 | |
| 51 | - /* |
|
| 51 | + /* |
|
| 52 | 52 | * Register $principalBackend for the DAV collection |
| 53 | 53 | */ |
| 54 | - $container->registerService('principalBackend', function () { |
|
| 55 | - return new Principal( |
|
| 56 | - \OC::$server->getUserManager(), |
|
| 57 | - \OC::$server->getGroupManager(), |
|
| 58 | - \OC::$server->getShareManager(), |
|
| 59 | - \OC::$server->getUserSession(), |
|
| 60 | - \OC::$server->getAppManager(), |
|
| 61 | - \OC::$server->query(ProxyMapper::class), |
|
| 62 | - \OC::$server->getConfig() |
|
| 63 | - ); |
|
| 64 | - }); |
|
| 54 | + $container->registerService('principalBackend', function () { |
|
| 55 | + return new Principal( |
|
| 56 | + \OC::$server->getUserManager(), |
|
| 57 | + \OC::$server->getGroupManager(), |
|
| 58 | + \OC::$server->getShareManager(), |
|
| 59 | + \OC::$server->getUserSession(), |
|
| 60 | + \OC::$server->getAppManager(), |
|
| 61 | + \OC::$server->query(ProxyMapper::class), |
|
| 62 | + \OC::$server->getConfig() |
|
| 63 | + ); |
|
| 64 | + }); |
|
| 65 | 65 | |
| 66 | - $container->registerService(ITrashManager::class, function(IAppContainer $c) { |
|
| 67 | - return new TrashManager(); |
|
| 68 | - }); |
|
| 66 | + $container->registerService(ITrashManager::class, function(IAppContainer $c) { |
|
| 67 | + return new TrashManager(); |
|
| 68 | + }); |
|
| 69 | 69 | |
| 70 | - $this->registerTrashBackends(); |
|
| 71 | - } |
|
| 70 | + $this->registerTrashBackends(); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - public function registerTrashBackends() { |
|
| 74 | - $server = $this->getContainer()->getServer(); |
|
| 75 | - $logger = $server->getLogger(); |
|
| 76 | - $appManager = $server->getAppManager(); |
|
| 77 | - /** @var ITrashManager $trashManager */ |
|
| 78 | - $trashManager = $this->getContainer()->getServer()->query(ITrashManager::class); |
|
| 79 | - foreach($appManager->getInstalledApps() as $app) { |
|
| 80 | - $appInfo = $appManager->getAppInfo($app); |
|
| 81 | - if (isset($appInfo['trash'])) { |
|
| 82 | - $backends = $appInfo['trash']; |
|
| 83 | - foreach($backends as $backend) { |
|
| 84 | - $class = $backend['@value']; |
|
| 85 | - $for = $backend['@attributes']['for']; |
|
| 73 | + public function registerTrashBackends() { |
|
| 74 | + $server = $this->getContainer()->getServer(); |
|
| 75 | + $logger = $server->getLogger(); |
|
| 76 | + $appManager = $server->getAppManager(); |
|
| 77 | + /** @var ITrashManager $trashManager */ |
|
| 78 | + $trashManager = $this->getContainer()->getServer()->query(ITrashManager::class); |
|
| 79 | + foreach($appManager->getInstalledApps() as $app) { |
|
| 80 | + $appInfo = $appManager->getAppInfo($app); |
|
| 81 | + if (isset($appInfo['trash'])) { |
|
| 82 | + $backends = $appInfo['trash']; |
|
| 83 | + foreach($backends as $backend) { |
|
| 84 | + $class = $backend['@value']; |
|
| 85 | + $for = $backend['@attributes']['for']; |
|
| 86 | 86 | |
| 87 | - try { |
|
| 88 | - $backendObject = $server->query($class); |
|
| 89 | - $trashManager->registerBackend($for, $backendObject); |
|
| 90 | - } catch (\Exception $e) { |
|
| 91 | - $logger->logException($e); |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - } |
|
| 87 | + try { |
|
| 88 | + $backendObject = $server->query($class); |
|
| 89 | + $trashManager->registerBackend($for, $backendObject); |
|
| 90 | + } catch (\Exception $e) { |
|
| 91 | + $logger->logException($e); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | 97 | } |
@@ -39,93 +39,93 @@ |
||
| 39 | 39 | |
| 40 | 40 | class Application extends App { |
| 41 | 41 | |
| 42 | - const APP_ID = 'files_versions'; |
|
| 43 | - |
|
| 44 | - public function __construct(array $urlParams = []) { |
|
| 45 | - parent::__construct(self::APP_ID, $urlParams); |
|
| 46 | - |
|
| 47 | - $container = $this->getContainer(); |
|
| 48 | - $server = $container->getServer(); |
|
| 49 | - |
|
| 50 | - /** @var IEventDispatcher $newDispatcher */ |
|
| 51 | - $dispatcher = $server->query(IEventDispatcher::class); |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Register capabilities |
|
| 55 | - */ |
|
| 56 | - $container->registerCapability(Capabilities::class); |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Register $principalBackend for the DAV collection |
|
| 60 | - */ |
|
| 61 | - $container->registerService('principalBackend', function (IAppContainer $c) { |
|
| 62 | - $server = $c->getServer(); |
|
| 63 | - return new Principal( |
|
| 64 | - $server->getUserManager(), |
|
| 65 | - $server->getGroupManager(), |
|
| 66 | - $server->getShareManager(), |
|
| 67 | - $server->getUserSession(), |
|
| 68 | - $server->getAppManager(), |
|
| 69 | - $server->query(ProxyMapper::class), |
|
| 70 | - \OC::$server->getConfig() |
|
| 71 | - ); |
|
| 72 | - }); |
|
| 73 | - |
|
| 74 | - $container->registerService(IVersionManager::class, function(IAppContainer $c) { |
|
| 75 | - return new VersionManager(); |
|
| 76 | - }); |
|
| 77 | - |
|
| 78 | - $this->registerVersionBackends(); |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Register Events |
|
| 82 | - */ |
|
| 83 | - $this->registerEvents($dispatcher); |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Register hooks |
|
| 87 | - */ |
|
| 88 | - Hooks::connectHooks(); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - public function registerVersionBackends() { |
|
| 92 | - $server = $this->getContainer()->getServer(); |
|
| 93 | - $appManager = $server->getAppManager(); |
|
| 94 | - foreach($appManager->getInstalledApps() as $app) { |
|
| 95 | - $appInfo = $appManager->getAppInfo($app); |
|
| 96 | - if (isset($appInfo['versions'])) { |
|
| 97 | - $backends = $appInfo['versions']; |
|
| 98 | - foreach($backends as $backend) { |
|
| 99 | - if (isset($backend['@value'])) { |
|
| 100 | - $this->loadBackend($backend); |
|
| 101 | - } else { |
|
| 102 | - foreach ($backend as $singleBackend) { |
|
| 103 | - $this->loadBackend($singleBackend); |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - private function loadBackend(array $backend) { |
|
| 112 | - $server = $this->getContainer()->getServer(); |
|
| 113 | - $logger = $server->getLogger(); |
|
| 114 | - /** @var IVersionManager $versionManager */ |
|
| 115 | - $versionManager = $this->getContainer()->getServer()->query(IVersionManager::class); |
|
| 116 | - $class = $backend['@value']; |
|
| 117 | - $for = $backend['@attributes']['for']; |
|
| 118 | - try { |
|
| 119 | - $backendObject = $server->query($class); |
|
| 120 | - $versionManager->registerBackend($for, $backendObject); |
|
| 121 | - } catch (\Exception $e) { |
|
| 122 | - $logger->logException($e); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - protected function registerEvents(IEventDispatcher $dispatcher) { |
|
| 127 | - $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class); |
|
| 128 | - $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class); |
|
| 129 | - } |
|
| 42 | + const APP_ID = 'files_versions'; |
|
| 43 | + |
|
| 44 | + public function __construct(array $urlParams = []) { |
|
| 45 | + parent::__construct(self::APP_ID, $urlParams); |
|
| 46 | + |
|
| 47 | + $container = $this->getContainer(); |
|
| 48 | + $server = $container->getServer(); |
|
| 49 | + |
|
| 50 | + /** @var IEventDispatcher $newDispatcher */ |
|
| 51 | + $dispatcher = $server->query(IEventDispatcher::class); |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Register capabilities |
|
| 55 | + */ |
|
| 56 | + $container->registerCapability(Capabilities::class); |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Register $principalBackend for the DAV collection |
|
| 60 | + */ |
|
| 61 | + $container->registerService('principalBackend', function (IAppContainer $c) { |
|
| 62 | + $server = $c->getServer(); |
|
| 63 | + return new Principal( |
|
| 64 | + $server->getUserManager(), |
|
| 65 | + $server->getGroupManager(), |
|
| 66 | + $server->getShareManager(), |
|
| 67 | + $server->getUserSession(), |
|
| 68 | + $server->getAppManager(), |
|
| 69 | + $server->query(ProxyMapper::class), |
|
| 70 | + \OC::$server->getConfig() |
|
| 71 | + ); |
|
| 72 | + }); |
|
| 73 | + |
|
| 74 | + $container->registerService(IVersionManager::class, function(IAppContainer $c) { |
|
| 75 | + return new VersionManager(); |
|
| 76 | + }); |
|
| 77 | + |
|
| 78 | + $this->registerVersionBackends(); |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Register Events |
|
| 82 | + */ |
|
| 83 | + $this->registerEvents($dispatcher); |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Register hooks |
|
| 87 | + */ |
|
| 88 | + Hooks::connectHooks(); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + public function registerVersionBackends() { |
|
| 92 | + $server = $this->getContainer()->getServer(); |
|
| 93 | + $appManager = $server->getAppManager(); |
|
| 94 | + foreach($appManager->getInstalledApps() as $app) { |
|
| 95 | + $appInfo = $appManager->getAppInfo($app); |
|
| 96 | + if (isset($appInfo['versions'])) { |
|
| 97 | + $backends = $appInfo['versions']; |
|
| 98 | + foreach($backends as $backend) { |
|
| 99 | + if (isset($backend['@value'])) { |
|
| 100 | + $this->loadBackend($backend); |
|
| 101 | + } else { |
|
| 102 | + foreach ($backend as $singleBackend) { |
|
| 103 | + $this->loadBackend($singleBackend); |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + private function loadBackend(array $backend) { |
|
| 112 | + $server = $this->getContainer()->getServer(); |
|
| 113 | + $logger = $server->getLogger(); |
|
| 114 | + /** @var IVersionManager $versionManager */ |
|
| 115 | + $versionManager = $this->getContainer()->getServer()->query(IVersionManager::class); |
|
| 116 | + $class = $backend['@value']; |
|
| 117 | + $for = $backend['@attributes']['for']; |
|
| 118 | + try { |
|
| 119 | + $backendObject = $server->query($class); |
|
| 120 | + $versionManager->registerBackend($for, $backendObject); |
|
| 121 | + } catch (\Exception $e) { |
|
| 122 | + $logger->logException($e); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + protected function registerEvents(IEventDispatcher $dispatcher) { |
|
| 127 | + $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class); |
|
| 128 | + $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class); |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | 131 | } |