-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Change CALDAV to allow calendars be shared with circles. #6512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MorrisJobke
merged 10 commits into
nextcloud:master
from
coletivoEITA:add_circles_sharing_to_caldav
Mar 12, 2019
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5e37b52
Share calendar to circle
viniciuscb 34601f8
allow sharing addressbooks with circles
georgehrke 58c92e6
Get user's circles without touching session
viniciuscb dc26d94
properly catch exceptions of detailsCircle
georgehrke 12d3f24
use class_exists on correct class to please phan
georgehrke 8322cec
Suppress phan exceptions because they are catched by a class_exists
MorrisJobke 789aaa4
Fix whitespace
MorrisJobke dd2496b
Use proper dependency injection for app manager
MorrisJobke c8aad3d
Fix PHPUnit
MorrisJobke 5cc5107
Fix PHPUnit
MorrisJobke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Share calendar to circle
* Allow user to share calendar with a circle * Allow user to see calendars shared with his/her circles Signed-off-by: Vinicius Cubas Brand <[email protected]>
- Loading branch information
commit 5e37b52241381e5b0f57c58a88a5dbcf0870b3bd
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,8 @@ | |
| * @author Stefan Weil <[email protected]> | ||
| * @author Thomas Citharel <[email protected]> | ||
| * @author Thomas Müller <[email protected]> | ||
| * @author Vinicius Cubas Brand <[email protected]> | ||
| * @author Daniel Tygel <[email protected]> | ||
| * | ||
| * @license AGPL-3.0 | ||
| * | ||
|
|
@@ -301,6 +303,8 @@ function getCalendarsForUser($principalUri) { | |
|
|
||
| // query for shared calendars | ||
| $principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true); | ||
| $principals = array_merge($principals, $this->principalBackend->getCircleMembership($principalUriOriginal)); | ||
|
|
||
| $principals = array_map(function($principal) { | ||
| return urldecode($principal); | ||
| }, $principals); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,8 @@ | |
| * @author Thomas Tanghus <[email protected]> | ||
| * @author Vincent Petry <[email protected]> | ||
| * @author Georg Ehrke <[email protected]> | ||
| * @author Vinicius Cubas Brand <[email protected]> | ||
| * @author Daniel Tygel <[email protected]> | ||
| * | ||
| * @license AGPL-3.0 | ||
| * | ||
|
|
@@ -66,6 +68,9 @@ class Principal implements BackendInterface { | |
| /** @var bool */ | ||
| private $hasGroups; | ||
|
|
||
| /** @var bool */ | ||
| private $hasCircles; | ||
|
|
||
| /** | ||
| * @param IUserManager $userManager | ||
| * @param IGroupManager $groupManager | ||
|
|
@@ -86,7 +91,7 @@ public function __construct(IUserManager $userManager, | |
| $this->userSession = $userSession; | ||
| $this->config = $config; | ||
| $this->principalPrefix = trim($principalPrefix, '/'); | ||
| $this->hasGroups = ($principalPrefix === 'principals/users/'); | ||
| $this->hasGroups = $this->hasCircles = ($principalPrefix === 'principals/users/'); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -131,6 +136,8 @@ public function getPrincipalByPath($path) { | |
| if ($user !== null) { | ||
| return $this->userToPrincipal($user); | ||
| } | ||
| } else if ($prefix === 'principals/circles') { | ||
| return $this->circleToPrincipal($name); | ||
| } | ||
| return null; | ||
| } | ||
|
|
@@ -388,4 +395,66 @@ public function getPrincipalPrefix() { | |
| return $this->principalPrefix; | ||
| } | ||
|
|
||
| /** | ||
| * @param string $circleUniqueId | ||
| * @return array|null | ||
| */ | ||
| protected function circleToPrincipal($circleUniqueId) { | ||
| if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) { | ||
| return null; | ||
| } | ||
|
|
||
| $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($circleUniqueId); | ||
|
|
||
| if (!$circle) { | ||
| return null; | ||
| } | ||
|
|
||
| $principal = [ | ||
| 'uri' => 'principals/circles/' . $circleUniqueId, | ||
| '{DAV:}displayname' => $circle->getName(), | ||
| ]; | ||
|
|
||
| return $principal; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the list of circles a principal is a member of | ||
| * | ||
| * @param string $principal | ||
| * @param bool $needGroups | ||
| * @return array | ||
| * @throws Exception | ||
| */ | ||
| public function getCircleMembership($principal) { | ||
| if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) { | ||
| return []; | ||
| } | ||
|
|
||
| list($prefix, $name) = \Sabre\Uri\split($principal); | ||
|
|
||
| if ($this->hasCircles && $prefix === $this->principalPrefix) { | ||
| $user = $this->userManager->get($name); | ||
| if (!$user) { | ||
| throw new Exception('Principal not found'); | ||
| } | ||
|
|
||
| $userSession = \OC::$server->getUserSession(); | ||
| $currentUser = $userSession->getUser(); | ||
|
|
||
| $userSession->setUser($user); | ||
| $circles = \OCA\Circles\Api\v1\Circles::joinedCircles(); | ||
| $userSession->setUser($currentUser); | ||
|
|
||
| $circles = array_map(function($circle) { | ||
| /** @var \OCA\Circles\Model\Circle $group */ | ||
| return 'principals/circles/' . urlencode($circle->getUniqueId()); | ||
| }, $circles); | ||
|
|
||
| return $circles; | ||
|
|
||
| } | ||
| return []; | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ | |
| * @author Robin Appelman <[email protected]> | ||
| * @author Roeland Jago Douma <[email protected]> | ||
| * @author Vincent Petry <[email protected]> | ||
| * @author Vinicius Cubas Brand <[email protected]> | ||
| * @author Daniel Tygel <[email protected]> | ||
| * | ||
| * @license AGPL-3.0 | ||
| * | ||
|
|
@@ -125,6 +127,7 @@ private function getShareTypes(\OCP\Files\Node $node) { | |
| \OCP\Share::SHARE_TYPE_REMOTE, | ||
| \OCP\Share::SHARE_TYPE_EMAIL, | ||
| \OCP\Share::SHARE_TYPE_ROOM, | ||
| \OCP\Share::SHARE_TYPE_CIRCLE, | ||
| ]; | ||
| foreach ($requestedShareTypes as $requestedShareType) { | ||
| // one of each type is enough to find out about the types | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.