Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c8c8f93
Move createSubscription and deleteSubscription event handlers to
tcitworld Dec 17, 2021
bfdfd3e
Remove uses of LegacyDispatcher for create/delete subscriptions
tcitworld Dec 17, 2021
dfa2cc3
Move every event to listeners and remove all uses of legacy dispatcher
tcitworld Dec 17, 2021
10af3ab
Add tests for new Listeners
tcitworld Dec 17, 2021
180e695
Remove usages of legacyDispatcher in CardDAVBackend
tcitworld Dec 19, 2021
ab07629
Update some depreciated calls
tcitworld Dec 19, 2021
08abaae
Fix doctype of param passed to deleteContact
tcitworld Dec 19, 2021
4827bc7
Improve OCA\DAV\Connector\Sabre\Principal
tcitworld Dec 19, 2021
aa7994f
Improve OCA\DAV\Tests\unit\CardDAV\AddressBookImplTest
tcitworld Dec 19, 2021
3a3a1a0
Move uses of ILogger to LoggerInterface
tcitworld Dec 19, 2021
fed15f9
Move some events to IEventDispatcher
tcitworld Dec 19, 2021
c304561
Replace calls to Sabre's depreciated getPropertiesForPath with getPro…
tcitworld Jan 16, 2022
981b99c
Remove more depreciated calls
tcitworld Jan 20, 2022
dcc9c70
Remove HookManager and replace with UserChangeListener
tcitworld Jan 20, 2022
7a5f4af
Modernize endpoints
tcitworld Jan 20, 2022
d739f92
Modernize Sabre Connector
tcitworld Jan 20, 2022
244aaa7
Add @template-implements metadata for listeners
tcitworld Jan 20, 2022
57ddf28
Remove CalendarManager registration
tcitworld Jan 20, 2022
fccc89d
Various fixes
tcitworld Jan 20, 2022
041526d
Improve tests
tcitworld Jan 26, 2022
3d42336
Improve CommentsEntityEvent
tcitworld Jan 26, 2022
9246d06
Use PHP 7.4 typed properties
tcitworld Feb 14, 2022
6d6008d
Rebasing, cs and more typing
tcitworld Mar 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve OCA\DAV\Connector\Sabre\Principal
Signed-off-by: Thomas Citharel <[email protected]>
  • Loading branch information
tcitworld committed Mar 31, 2022
commit 4827bc76eec5e88906e39ba9af3ff8384aaec01b
51 changes: 22 additions & 29 deletions apps/dav/lib/Connector/Sabre/Principal.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,10 @@ public function getGroupMembership($principal, $needGroups = false) {
}
}

$groups = array_unique(array_merge(
return array_unique(array_merge(
$groups,
$this->traitGetGroupMembership($principal, $needGroups)
));

return $groups;
}

/**
Expand Down Expand Up @@ -472,25 +470,23 @@ public function findByUri($uri, $principalPrefix) {
$restrictGroups = $this->groupManager->getUserGroupIds($user);
}

if (strpos($uri, 'mailto:') === 0) {
if ($principalPrefix === 'principals/users') {
$users = $this->userManager->getByEmail(substr($uri, 7));
if (count($users) !== 1) {
return null;
}
$user = $users[0];
if ($principalPrefix === 'principals/users' && (strpos($uri, 'mailto:') === 0)) {
$users = $this->userManager->getByEmail(substr($uri, 7));
if (count($users) !== 1) {
return null;
}
$user = $users[0];

if ($restrictGroups !== false) {
$userGroups = $this->groupManager->getUserGroupIds($user);
if (count(array_intersect($userGroups, $restrictGroups)) === 0) {
return null;
}
if ($restrictGroups !== false) {
$userGroups = $this->groupManager->getUserGroupIds($user);
if (count(array_intersect($userGroups, $restrictGroups)) === 0) {
return null;
}

return $this->principalPrefix . '/' . $user->getUID();
}

return $this->principalPrefix . '/' . $user->getUID();
}
if (substr($uri, 0, 10) === 'principal:') {
if (strpos($uri, 'principal:') === 0) {
$principal = substr($uri, 10);
$principal = $this->getPrincipalByPath($principal);
if ($principal !== null) {
Expand All @@ -505,7 +501,7 @@ public function findByUri($uri, $principalPrefix) {
* @param IUser $user
* @return array
*/
protected function userToPrincipal($user) {
protected function userToPrincipal(IUser $user): array {
$userId = $user->getUID();
$displayName = $user->getDisplayName();
$principal = [
Expand All @@ -523,21 +519,21 @@ protected function userToPrincipal($user) {
return $principal;
}

public function getPrincipalPrefix() {
public function getPrincipalPrefix(): string {
return $this->principalPrefix;
}

/**
* @param string $circleUniqueId
* @return array|null
*/
protected function circleToPrincipal($circleUniqueId) {
protected function circleToPrincipal(string $circleUniqueId): ?array {
if (!$this->appManager->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) {
return null;
}

try {
$circle = \OCA\Circles\Api\v1\Circles::detailsCircle($circleUniqueId, true);
$circle = Circles::detailsCircle($circleUniqueId, true);
} catch (QueryException $ex) {
return null;
} catch (CircleNotFoundException $ex) {
Expand All @@ -562,10 +558,9 @@ protected function circleToPrincipal($circleUniqueId) {
* @param string $principal
* @return array
* @throws Exception
* @throws \OCP\AppFramework\QueryException
* @suppress PhanUndeclaredClassMethod
*/
public function getCircleMembership($principal):array {
public function getCircleMembership(string $principal):array {
if (!$this->appManager->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) {
return [];
}
Expand All @@ -577,14 +572,12 @@ public function getCircleMembership($principal):array {
throw new Exception('Principal not found');
}

$circles = \OCA\Circles\Api\v1\Circles::joinedCircles($name, true);
$circles = Circles::joinedCircles($name, true);

$circles = array_map(function ($circle) {
/** @var \OCA\Circles\Model\Circle $circle */
return array_map(static function ($circle) {
/** @var Circle $circle */
return 'principals/circles/' . urlencode($circle->getSingleId());
}, $circles);

return $circles;
}

return [];
Expand Down
4 changes: 2 additions & 2 deletions apps/dav/lib/Traits/PrincipalProxyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function getGroupMembership($principal, $needGroups = false) {
*
* @param string $principal
* @param string[] $members
* @throws Exception
* @throws Exception|\OCP\DB\Exception
*/
public function setGroupMemberSet($principal, array $members) {
[$principalUri, $target] = \Sabre\Uri\split($principal);
Expand Down Expand Up @@ -183,7 +183,7 @@ private function isProxyPrincipal(string $principalUri):bool {
[$realPrincipalUri, $proxy] = \Sabre\Uri\split($principalUri);
[$prefix, $userId] = \Sabre\Uri\split($realPrincipalUri);

if (!isset($prefix) || !isset($userId)) {
if (!isset($prefix, $userId)) {
return false;
}
if ($prefix !== $this->principalPrefix) {
Expand Down