-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add address book plugins #19680
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
Closed
Closed
Add address book plugins #19680
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Add address book plugins
Signed-off-by: Christoph Wurst <[email protected]>
- Loading branch information
commit fd489de57c074ad8d7649fe572067c3f631dacfb
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
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
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
113 changes: 113 additions & 0 deletions
113
apps/dav/lib/CardDAV/Integration/ExternalAddressBook.php
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 |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OCA\DAV\CardDAV\Integration; | ||
|
|
||
| use Sabre\CardDAV\IAddressBook; | ||
| use Sabre\DAV; | ||
|
|
||
| /** | ||
| * @since 19.0.0 | ||
| */ | ||
| abstract class ExternalAddressBook implements IAddressBook, DAV\IProperties { | ||
|
|
||
| /** @var string */ | ||
| private const PREFIX = 'app-generated'; | ||
|
|
||
| /** | ||
| * @var string | ||
| * | ||
| * Double dash is a valid delimiter, | ||
| * because it will always split the URIs correctly: | ||
| * - our prefix contains only one dash and won't be split | ||
| * - appIds are not allowed to contain dashes as per spec: | ||
| * > must contain only lowercase ASCII characters and underscore | ||
| * - explode has a limit of three, so even if the app-generated | ||
| * URI has double dashes, it won't be split | ||
| */ | ||
| private const DELIMITER = '--'; | ||
|
|
||
| /** @var string */ | ||
| private $appId; | ||
|
|
||
| /** @var string */ | ||
| private $uri; | ||
|
|
||
| /** | ||
| * @param string $appId | ||
| * @param string $uri | ||
| */ | ||
| public function __construct(string $appId, string $uri) { | ||
| $this->appId = $appId; | ||
| $this->uri = $uri; | ||
| } | ||
|
|
||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| final public function getName() { | ||
| return implode(self::DELIMITER, [ | ||
| self::PREFIX, | ||
| $this->appId, | ||
| $this->uri, | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| final public function setName($name) { | ||
| throw new DAV\Exception\MethodNotAllowed('Renaming address books is not yet supported'); | ||
| } | ||
|
|
||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| final public function createDirectory($name) { | ||
| throw new DAV\Exception\MethodNotAllowed('Creating collections in address book objects is not allowed'); | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Checks whether the address book uri is app-generated | ||
| * | ||
| * @param string $uri | ||
| * | ||
| * @return bool | ||
| */ | ||
| public static function isAppGeneratedAddressBook(string $uri): bool { | ||
| return strpos($uri, self::PREFIX) === 0 && substr_count($uri, self::DELIMITER) >= 2; | ||
| } | ||
|
|
||
| /** | ||
| * Splits an app-generated uri into appId and uri | ||
| * | ||
| * @param string $uri | ||
| * | ||
| * @return array | ||
| */ | ||
| public static function splitAppGeneratedAddressBookUri(string $uri): array { | ||
| $array = array_slice(explode(self::DELIMITER, $uri, 3), 1); | ||
| // Check the array has expected amount of elements | ||
| // and none of them is an empty string | ||
| if (\count($array) !== 2 || \in_array('', $array, true)) { | ||
| throw new \InvalidArgumentException('Provided address book uri was not app-generated'); | ||
| } | ||
|
|
||
| return $array; | ||
| } | ||
|
|
||
| /** | ||
| * Checks whether a address book name the user wants to create violates | ||
| * the reserved name for URIs | ||
| * | ||
| * @param string $uri | ||
| * | ||
| * @return bool | ||
| */ | ||
| public static function doesViolateReservedName(string $uri): bool { | ||
| return strpos($uri, self::PREFIX) === 0; | ||
| } | ||
|
|
||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OCA\DAV\CardDAV\Integration; | ||
|
|
||
| use Sabre\CardDAV\IAddressBook; | ||
|
|
||
| /** | ||
| * @since 19.0.0 | ||
| */ | ||
| interface IAddressBookProvider { | ||
|
|
||
| /** | ||
| * Provides the appId of the plugin | ||
| * | ||
| * @since 19.0.0 | ||
| * @return string AppId | ||
| */ | ||
| public function getAppId(): string; | ||
|
|
||
| /** | ||
| * Fetches all calendars for a given principal uri | ||
| * | ||
| * @since 19.0.0 | ||
| * @param string $principalUri E.g. principals/users/user1 | ||
| * @return ExternalAddressBook[] Array of all calendars | ||
| */ | ||
| public function fetchAllForCalendarHome(string $principalUri): array; | ||
|
|
||
| /** | ||
| * Checks whether plugin has a calendar for a given principalUri and calendarUri | ||
| * | ||
| * @since 19.0.0 | ||
| * @param string $principalUri E.g. principals/users/user1 | ||
| * @param string $calendarUri E.g. personal | ||
| * @return bool True if calendar for principalUri and calendarUri exists, false otherwise | ||
| */ | ||
| public function hasCalendarInCalendarHome(string $principalUri, string $calendarUri): bool; | ||
|
|
||
| /** | ||
| * Fetches a calendar for a given principalUri and calendarUri | ||
| * Returns null if calendar does not exist | ||
| * | ||
| * @param string $principalUri E.g. principals/users/user1 | ||
| * @param string $calendarUri E.g. personal | ||
| * | ||
| * @return ExternalAddressBook|null Calendar if it exists, null otherwise | ||
| *@since 19.0.0 | ||
| */ | ||
| public function getCalendarInCalendarHome(string $principalUri, string $calendarUri): ?ExternalAddressBook; | ||
|
|
||
| } |
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.