@@ -39,102 +39,102 @@ |
||
39 | 39 | * @package OCA\DAV\CalDAV\BirthdayCalendar |
40 | 40 | */ |
41 | 41 | class EnablePlugin extends ServerPlugin { |
42 | - public const NS_Nextcloud = 'http://nextcloud.com/ns'; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var IConfig |
|
46 | - */ |
|
47 | - protected $config; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var BirthdayService |
|
51 | - */ |
|
52 | - protected $birthdayService; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var Server |
|
56 | - */ |
|
57 | - protected $server; |
|
58 | - |
|
59 | - /** |
|
60 | - * PublishPlugin constructor. |
|
61 | - * |
|
62 | - * @param IConfig $config |
|
63 | - * @param BirthdayService $birthdayService |
|
64 | - */ |
|
65 | - public function __construct(IConfig $config, BirthdayService $birthdayService) { |
|
66 | - $this->config = $config; |
|
67 | - $this->birthdayService = $birthdayService; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * This method should return a list of server-features. |
|
72 | - * |
|
73 | - * This is for example 'versioning' and is added to the DAV: header |
|
74 | - * in an OPTIONS response. |
|
75 | - * |
|
76 | - * @return string[] |
|
77 | - */ |
|
78 | - public function getFeatures() { |
|
79 | - return ['nc-enable-birthday-calendar']; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Returns a plugin name. |
|
84 | - * |
|
85 | - * Using this name other plugins will be able to access other plugins |
|
86 | - * using Sabre\DAV\Server::getPlugin |
|
87 | - * |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function getPluginName() { |
|
91 | - return 'nc-enable-birthday-calendar'; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * This initializes the plugin. |
|
96 | - * |
|
97 | - * This function is called by Sabre\DAV\Server, after |
|
98 | - * addPlugin is called. |
|
99 | - * |
|
100 | - * This method should set up the required event subscriptions. |
|
101 | - * |
|
102 | - * @param Server $server |
|
103 | - */ |
|
104 | - public function initialize(Server $server) { |
|
105 | - $this->server = $server; |
|
106 | - |
|
107 | - $this->server->on('method:POST', [$this, 'httpPost']); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * We intercept this to handle POST requests on calendar homes. |
|
112 | - * |
|
113 | - * @param RequestInterface $request |
|
114 | - * @param ResponseInterface $response |
|
115 | - * |
|
116 | - * @return bool|void |
|
117 | - */ |
|
118 | - public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
119 | - $node = $this->server->tree->getNodeForPath($this->server->getRequestUri()); |
|
120 | - if (!($node instanceof CalendarHome)) { |
|
121 | - return; |
|
122 | - } |
|
123 | - |
|
124 | - $requestBody = $request->getBodyAsString(); |
|
125 | - $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
126 | - if ($documentType !== '{'.self::NS_Nextcloud.'}enable-birthday-calendar') { |
|
127 | - return; |
|
128 | - } |
|
129 | - |
|
130 | - $principalUri = $node->getOwner(); |
|
131 | - $userId = substr($principalUri, 17); |
|
132 | - |
|
133 | - $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
134 | - $this->birthdayService->syncUser($userId); |
|
135 | - |
|
136 | - $this->server->httpResponse->setStatus(204); |
|
137 | - |
|
138 | - return false; |
|
139 | - } |
|
42 | + public const NS_Nextcloud = 'http://nextcloud.com/ns'; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var IConfig |
|
46 | + */ |
|
47 | + protected $config; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var BirthdayService |
|
51 | + */ |
|
52 | + protected $birthdayService; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var Server |
|
56 | + */ |
|
57 | + protected $server; |
|
58 | + |
|
59 | + /** |
|
60 | + * PublishPlugin constructor. |
|
61 | + * |
|
62 | + * @param IConfig $config |
|
63 | + * @param BirthdayService $birthdayService |
|
64 | + */ |
|
65 | + public function __construct(IConfig $config, BirthdayService $birthdayService) { |
|
66 | + $this->config = $config; |
|
67 | + $this->birthdayService = $birthdayService; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * This method should return a list of server-features. |
|
72 | + * |
|
73 | + * This is for example 'versioning' and is added to the DAV: header |
|
74 | + * in an OPTIONS response. |
|
75 | + * |
|
76 | + * @return string[] |
|
77 | + */ |
|
78 | + public function getFeatures() { |
|
79 | + return ['nc-enable-birthday-calendar']; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Returns a plugin name. |
|
84 | + * |
|
85 | + * Using this name other plugins will be able to access other plugins |
|
86 | + * using Sabre\DAV\Server::getPlugin |
|
87 | + * |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function getPluginName() { |
|
91 | + return 'nc-enable-birthday-calendar'; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * This initializes the plugin. |
|
96 | + * |
|
97 | + * This function is called by Sabre\DAV\Server, after |
|
98 | + * addPlugin is called. |
|
99 | + * |
|
100 | + * This method should set up the required event subscriptions. |
|
101 | + * |
|
102 | + * @param Server $server |
|
103 | + */ |
|
104 | + public function initialize(Server $server) { |
|
105 | + $this->server = $server; |
|
106 | + |
|
107 | + $this->server->on('method:POST', [$this, 'httpPost']); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * We intercept this to handle POST requests on calendar homes. |
|
112 | + * |
|
113 | + * @param RequestInterface $request |
|
114 | + * @param ResponseInterface $response |
|
115 | + * |
|
116 | + * @return bool|void |
|
117 | + */ |
|
118 | + public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
119 | + $node = $this->server->tree->getNodeForPath($this->server->getRequestUri()); |
|
120 | + if (!($node instanceof CalendarHome)) { |
|
121 | + return; |
|
122 | + } |
|
123 | + |
|
124 | + $requestBody = $request->getBodyAsString(); |
|
125 | + $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
126 | + if ($documentType !== '{'.self::NS_Nextcloud.'}enable-birthday-calendar') { |
|
127 | + return; |
|
128 | + } |
|
129 | + |
|
130 | + $principalUri = $node->getOwner(); |
|
131 | + $userId = substr($principalUri, 17); |
|
132 | + |
|
133 | + $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
134 | + $this->birthdayService->syncUser($userId); |
|
135 | + |
|
136 | + $this->server->httpResponse->setStatus(204); |
|
137 | + |
|
138 | + return false; |
|
139 | + } |
|
140 | 140 | } |
@@ -30,13 +30,13 @@ |
||
30 | 30 | */ |
31 | 31 | class Collection extends \Sabre\CalDAV\Principal\Collection { |
32 | 32 | |
33 | - /** |
|
34 | - * Returns a child object based on principal information |
|
35 | - * |
|
36 | - * @param array $principalInfo |
|
37 | - * @return User |
|
38 | - */ |
|
39 | - public function getChildForPrincipal(array $principalInfo) { |
|
40 | - return new User($this->principalBackend, $principalInfo); |
|
41 | - } |
|
33 | + /** |
|
34 | + * Returns a child object based on principal information |
|
35 | + * |
|
36 | + * @param array $principalInfo |
|
37 | + * @return User |
|
38 | + */ |
|
39 | + public function getChildForPrincipal(array $principalInfo) { |
|
40 | + return new User($this->principalBackend, $principalInfo); |
|
41 | + } |
|
42 | 42 | } |
@@ -30,25 +30,25 @@ |
||
30 | 30 | */ |
31 | 31 | class User extends \Sabre\CalDAV\Principal\User { |
32 | 32 | |
33 | - /** |
|
34 | - * Returns a list of ACE's for this node. |
|
35 | - * |
|
36 | - * Each ACE has the following properties: |
|
37 | - * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
38 | - * currently the only supported privileges |
|
39 | - * * 'principal', a url to the principal who owns the node |
|
40 | - * * 'protected' (optional), indicating that this ACE is not allowed to |
|
41 | - * be updated. |
|
42 | - * |
|
43 | - * @return array |
|
44 | - */ |
|
45 | - public function getACL() { |
|
46 | - $acl = parent::getACL(); |
|
47 | - $acl[] = [ |
|
48 | - 'privilege' => '{DAV:}read', |
|
49 | - 'principal' => '{DAV:}authenticated', |
|
50 | - 'protected' => true, |
|
51 | - ]; |
|
52 | - return $acl; |
|
53 | - } |
|
33 | + /** |
|
34 | + * Returns a list of ACE's for this node. |
|
35 | + * |
|
36 | + * Each ACE has the following properties: |
|
37 | + * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
38 | + * currently the only supported privileges |
|
39 | + * * 'principal', a url to the principal who owns the node |
|
40 | + * * 'protected' (optional), indicating that this ACE is not allowed to |
|
41 | + * be updated. |
|
42 | + * |
|
43 | + * @return array |
|
44 | + */ |
|
45 | + public function getACL() { |
|
46 | + $acl = parent::getACL(); |
|
47 | + $acl[] = [ |
|
48 | + 'privilege' => '{DAV:}read', |
|
49 | + 'principal' => '{DAV:}authenticated', |
|
50 | + 'protected' => true, |
|
51 | + ]; |
|
52 | + return $acl; |
|
53 | + } |
|
54 | 54 | } |
@@ -34,102 +34,102 @@ |
||
34 | 34 | */ |
35 | 35 | class Outbox extends \Sabre\CalDAV\Schedule\Outbox { |
36 | 36 | |
37 | - /** @var IConfig */ |
|
38 | - private $config; |
|
37 | + /** @var IConfig */ |
|
38 | + private $config; |
|
39 | 39 | |
40 | - /** @var null|bool */ |
|
41 | - private $disableFreeBusy = null; |
|
40 | + /** @var null|bool */ |
|
41 | + private $disableFreeBusy = null; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Outbox constructor. |
|
45 | - * |
|
46 | - * @param IConfig $config |
|
47 | - * @param string $principalUri |
|
48 | - */ |
|
49 | - public function __construct(IConfig $config, string $principalUri) { |
|
50 | - parent::__construct($principalUri); |
|
51 | - $this->config = $config; |
|
52 | - } |
|
43 | + /** |
|
44 | + * Outbox constructor. |
|
45 | + * |
|
46 | + * @param IConfig $config |
|
47 | + * @param string $principalUri |
|
48 | + */ |
|
49 | + public function __construct(IConfig $config, string $principalUri) { |
|
50 | + parent::__construct($principalUri); |
|
51 | + $this->config = $config; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Returns a list of ACE's for this node. |
|
56 | - * |
|
57 | - * Each ACE has the following properties: |
|
58 | - * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
59 | - * currently the only supported privileges |
|
60 | - * * 'principal', a url to the principal who owns the node |
|
61 | - * * 'protected' (optional), indicating that this ACE is not allowed to |
|
62 | - * be updated. |
|
63 | - * |
|
64 | - * @return array |
|
65 | - */ |
|
66 | - public function getACL() { |
|
67 | - // getACL is called so frequently that we cache the config result |
|
68 | - if ($this->disableFreeBusy === null) { |
|
69 | - $this->disableFreeBusy = ($this->config->getAppValue('dav', 'disableFreeBusy', 'no') === 'yes'); |
|
70 | - } |
|
54 | + /** |
|
55 | + * Returns a list of ACE's for this node. |
|
56 | + * |
|
57 | + * Each ACE has the following properties: |
|
58 | + * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
59 | + * currently the only supported privileges |
|
60 | + * * 'principal', a url to the principal who owns the node |
|
61 | + * * 'protected' (optional), indicating that this ACE is not allowed to |
|
62 | + * be updated. |
|
63 | + * |
|
64 | + * @return array |
|
65 | + */ |
|
66 | + public function getACL() { |
|
67 | + // getACL is called so frequently that we cache the config result |
|
68 | + if ($this->disableFreeBusy === null) { |
|
69 | + $this->disableFreeBusy = ($this->config->getAppValue('dav', 'disableFreeBusy', 'no') === 'yes'); |
|
70 | + } |
|
71 | 71 | |
72 | - $commonAcl = [ |
|
73 | - [ |
|
74 | - 'privilege' => '{DAV:}read', |
|
75 | - 'principal' => $this->getOwner(), |
|
76 | - 'protected' => true, |
|
77 | - ], |
|
78 | - [ |
|
79 | - 'privilege' => '{DAV:}read', |
|
80 | - 'principal' => $this->getOwner() . '/calendar-proxy-read', |
|
81 | - 'protected' => true, |
|
82 | - ], |
|
83 | - [ |
|
84 | - 'privilege' => '{DAV:}read', |
|
85 | - 'principal' => $this->getOwner() . '/calendar-proxy-write', |
|
86 | - 'protected' => true, |
|
87 | - ], |
|
88 | - ]; |
|
72 | + $commonAcl = [ |
|
73 | + [ |
|
74 | + 'privilege' => '{DAV:}read', |
|
75 | + 'principal' => $this->getOwner(), |
|
76 | + 'protected' => true, |
|
77 | + ], |
|
78 | + [ |
|
79 | + 'privilege' => '{DAV:}read', |
|
80 | + 'principal' => $this->getOwner() . '/calendar-proxy-read', |
|
81 | + 'protected' => true, |
|
82 | + ], |
|
83 | + [ |
|
84 | + 'privilege' => '{DAV:}read', |
|
85 | + 'principal' => $this->getOwner() . '/calendar-proxy-write', |
|
86 | + 'protected' => true, |
|
87 | + ], |
|
88 | + ]; |
|
89 | 89 | |
90 | - // schedule-send is an aggregate privilege for: |
|
91 | - // - schedule-send-invite |
|
92 | - // - schedule-send-reply |
|
93 | - // - schedule-send-freebusy |
|
94 | - // |
|
95 | - // If FreeBusy is disabled, we have to remove the latter privilege |
|
90 | + // schedule-send is an aggregate privilege for: |
|
91 | + // - schedule-send-invite |
|
92 | + // - schedule-send-reply |
|
93 | + // - schedule-send-freebusy |
|
94 | + // |
|
95 | + // If FreeBusy is disabled, we have to remove the latter privilege |
|
96 | 96 | |
97 | - if ($this->disableFreeBusy) { |
|
98 | - return array_merge($commonAcl, [ |
|
99 | - [ |
|
100 | - 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-invite', |
|
101 | - 'principal' => $this->getOwner(), |
|
102 | - 'protected' => true, |
|
103 | - ], |
|
104 | - [ |
|
105 | - 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-invite', |
|
106 | - 'principal' => $this->getOwner() . '/calendar-proxy-write', |
|
107 | - 'protected' => true, |
|
108 | - ], |
|
109 | - [ |
|
110 | - 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-reply', |
|
111 | - 'principal' => $this->getOwner(), |
|
112 | - 'protected' => true, |
|
113 | - ], |
|
114 | - [ |
|
115 | - 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-reply', |
|
116 | - 'principal' => $this->getOwner() . '/calendar-proxy-write', |
|
117 | - 'protected' => true, |
|
118 | - ], |
|
119 | - ]); |
|
120 | - } |
|
97 | + if ($this->disableFreeBusy) { |
|
98 | + return array_merge($commonAcl, [ |
|
99 | + [ |
|
100 | + 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-invite', |
|
101 | + 'principal' => $this->getOwner(), |
|
102 | + 'protected' => true, |
|
103 | + ], |
|
104 | + [ |
|
105 | + 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-invite', |
|
106 | + 'principal' => $this->getOwner() . '/calendar-proxy-write', |
|
107 | + 'protected' => true, |
|
108 | + ], |
|
109 | + [ |
|
110 | + 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-reply', |
|
111 | + 'principal' => $this->getOwner(), |
|
112 | + 'protected' => true, |
|
113 | + ], |
|
114 | + [ |
|
115 | + 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-reply', |
|
116 | + 'principal' => $this->getOwner() . '/calendar-proxy-write', |
|
117 | + 'protected' => true, |
|
118 | + ], |
|
119 | + ]); |
|
120 | + } |
|
121 | 121 | |
122 | - return array_merge($commonAcl, [ |
|
123 | - [ |
|
124 | - 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send', |
|
125 | - 'principal' => $this->getOwner(), |
|
126 | - 'protected' => true, |
|
127 | - ], |
|
128 | - [ |
|
129 | - 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send', |
|
130 | - 'principal' => $this->getOwner() . '/calendar-proxy-write', |
|
131 | - 'protected' => true, |
|
132 | - ], |
|
133 | - ]); |
|
134 | - } |
|
122 | + return array_merge($commonAcl, [ |
|
123 | + [ |
|
124 | + 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send', |
|
125 | + 'principal' => $this->getOwner(), |
|
126 | + 'protected' => true, |
|
127 | + ], |
|
128 | + [ |
|
129 | + 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send', |
|
130 | + 'principal' => $this->getOwner() . '/calendar-proxy-write', |
|
131 | + 'protected' => true, |
|
132 | + ], |
|
133 | + ]); |
|
134 | + } |
|
135 | 135 | } |
@@ -32,17 +32,17 @@ |
||
32 | 32 | |
33 | 33 | class OffsetFilter implements XmlDeserializable { |
34 | 34 | |
35 | - /** |
|
36 | - * @param Reader $reader |
|
37 | - * @throws BadRequest |
|
38 | - * @return int |
|
39 | - */ |
|
40 | - public static function xmlDeserialize(Reader $reader) { |
|
41 | - $value = $reader->parseInnerTree(); |
|
42 | - if (!is_int($value) && !is_string($value)) { |
|
43 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}offset has illegal value'); |
|
44 | - } |
|
35 | + /** |
|
36 | + * @param Reader $reader |
|
37 | + * @throws BadRequest |
|
38 | + * @return int |
|
39 | + */ |
|
40 | + public static function xmlDeserialize(Reader $reader) { |
|
41 | + $value = $reader->parseInnerTree(); |
|
42 | + if (!is_int($value) && !is_string($value)) { |
|
43 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}offset has illegal value'); |
|
44 | + } |
|
45 | 45 | |
46 | - return (int)$value; |
|
47 | - } |
|
46 | + return (int)$value; |
|
47 | + } |
|
48 | 48 | } |
@@ -32,17 +32,17 @@ |
||
32 | 32 | |
33 | 33 | class LimitFilter implements XmlDeserializable { |
34 | 34 | |
35 | - /** |
|
36 | - * @param Reader $reader |
|
37 | - * @throws BadRequest |
|
38 | - * @return int |
|
39 | - */ |
|
40 | - public static function xmlDeserialize(Reader $reader) { |
|
41 | - $value = $reader->parseInnerTree(); |
|
42 | - if (!is_int($value) && !is_string($value)) { |
|
43 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}limit has illegal value'); |
|
44 | - } |
|
35 | + /** |
|
36 | + * @param Reader $reader |
|
37 | + * @throws BadRequest |
|
38 | + * @return int |
|
39 | + */ |
|
40 | + public static function xmlDeserialize(Reader $reader) { |
|
41 | + $value = $reader->parseInnerTree(); |
|
42 | + if (!is_int($value) && !is_string($value)) { |
|
43 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}limit has illegal value'); |
|
44 | + } |
|
45 | 45 | |
46 | - return (int)$value; |
|
47 | - } |
|
46 | + return (int)$value; |
|
47 | + } |
|
48 | 48 | } |
@@ -27,21 +27,21 @@ |
||
27 | 27 | use Sabre\Xml\XmlSerializable; |
28 | 28 | |
29 | 29 | class Groups implements XmlSerializable { |
30 | - public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
30 | + public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
31 | 31 | |
32 | - /** @var string[] of TYPE:CHECKSUM */ |
|
33 | - private $groups; |
|
32 | + /** @var string[] of TYPE:CHECKSUM */ |
|
33 | + private $groups; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param string $groups |
|
37 | - */ |
|
38 | - public function __construct($groups) { |
|
39 | - $this->groups = $groups; |
|
40 | - } |
|
35 | + /** |
|
36 | + * @param string $groups |
|
37 | + */ |
|
38 | + public function __construct($groups) { |
|
39 | + $this->groups = $groups; |
|
40 | + } |
|
41 | 41 | |
42 | - public function xmlSerialize(Writer $writer) { |
|
43 | - foreach ($this->groups as $group) { |
|
44 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}group', $group); |
|
45 | - } |
|
46 | - } |
|
42 | + public function xmlSerialize(Writer $writer) { |
|
43 | + foreach ($this->groups as $group) { |
|
44 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}group', $group); |
|
45 | + } |
|
46 | + } |
|
47 | 47 | } |
@@ -29,45 +29,45 @@ |
||
29 | 29 | |
30 | 30 | class AddressBookRoot extends \Sabre\CardDAV\AddressBookRoot { |
31 | 31 | |
32 | - /** @var PluginManager */ |
|
33 | - private $pluginManager; |
|
32 | + /** @var PluginManager */ |
|
33 | + private $pluginManager; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend |
|
37 | - * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend |
|
38 | - * @param string $principalPrefix |
|
39 | - */ |
|
40 | - public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, |
|
41 | - \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, |
|
42 | - PluginManager $pluginManager, |
|
43 | - $principalPrefix = 'principals') { |
|
44 | - parent::__construct($principalBackend, $carddavBackend, $principalPrefix); |
|
45 | - $this->pluginManager = $pluginManager; |
|
46 | - } |
|
35 | + /** |
|
36 | + * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend |
|
37 | + * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend |
|
38 | + * @param string $principalPrefix |
|
39 | + */ |
|
40 | + public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, |
|
41 | + \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, |
|
42 | + PluginManager $pluginManager, |
|
43 | + $principalPrefix = 'principals') { |
|
44 | + parent::__construct($principalBackend, $carddavBackend, $principalPrefix); |
|
45 | + $this->pluginManager = $pluginManager; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * This method returns a node for a principal. |
|
50 | - * |
|
51 | - * The passed array contains principal information, and is guaranteed to |
|
52 | - * at least contain a uri item. Other properties may or may not be |
|
53 | - * supplied by the authentication backend. |
|
54 | - * |
|
55 | - * @param array $principal |
|
56 | - * |
|
57 | - * @return \Sabre\DAV\INode |
|
58 | - */ |
|
59 | - public function getChildForPrincipal(array $principal) { |
|
60 | - return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->pluginManager); |
|
61 | - } |
|
48 | + /** |
|
49 | + * This method returns a node for a principal. |
|
50 | + * |
|
51 | + * The passed array contains principal information, and is guaranteed to |
|
52 | + * at least contain a uri item. Other properties may or may not be |
|
53 | + * supplied by the authentication backend. |
|
54 | + * |
|
55 | + * @param array $principal |
|
56 | + * |
|
57 | + * @return \Sabre\DAV\INode |
|
58 | + */ |
|
59 | + public function getChildForPrincipal(array $principal) { |
|
60 | + return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->pluginManager); |
|
61 | + } |
|
62 | 62 | |
63 | - public function getName() { |
|
64 | - if ($this->principalPrefix === 'principals') { |
|
65 | - return parent::getName(); |
|
66 | - } |
|
67 | - // Grabbing all the components of the principal path. |
|
68 | - $parts = explode('/', $this->principalPrefix); |
|
63 | + public function getName() { |
|
64 | + if ($this->principalPrefix === 'principals') { |
|
65 | + return parent::getName(); |
|
66 | + } |
|
67 | + // Grabbing all the components of the principal path. |
|
68 | + $parts = explode('/', $this->principalPrefix); |
|
69 | 69 | |
70 | - // We are only interested in the second part. |
|
71 | - return $parts[1]; |
|
72 | - } |
|
70 | + // We are only interested in the second part. |
|
71 | + return $parts[1]; |
|
72 | + } |
|
73 | 73 | } |
@@ -41,82 +41,82 @@ |
||
41 | 41 | |
42 | 42 | class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome { |
43 | 43 | |
44 | - /** @var IL10N */ |
|
45 | - protected $l10n; |
|
46 | - |
|
47 | - /** @var IConfig */ |
|
48 | - protected $config; |
|
49 | - |
|
50 | - /** @var PluginManager */ |
|
51 | - private $pluginManager; |
|
52 | - |
|
53 | - public function __construct(Backend\BackendInterface $carddavBackend, |
|
54 | - string $principalUri, |
|
55 | - PluginManager $pluginManager) { |
|
56 | - parent::__construct($carddavBackend, $principalUri); |
|
57 | - $this->pluginManager = $pluginManager; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Returns a list of address books |
|
62 | - * |
|
63 | - * @return IAddressBook[] |
|
64 | - */ |
|
65 | - public function getChildren() { |
|
66 | - if ($this->l10n === null) { |
|
67 | - $this->l10n = \OC::$server->getL10N('dav'); |
|
68 | - } |
|
69 | - if ($this->config === null) { |
|
70 | - $this->config = \OC::$server->getConfig(); |
|
71 | - } |
|
72 | - |
|
73 | - $addressBooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri); |
|
74 | - /** @var IAddressBook[] $objects */ |
|
75 | - $objects = array_map(function (array $addressBook) { |
|
76 | - if ($addressBook['principaluri'] === 'principals/system/system') { |
|
77 | - return new SystemAddressbook($this->carddavBackend, $addressBook, $this->l10n, $this->config); |
|
78 | - } |
|
79 | - |
|
80 | - return new AddressBook($this->carddavBackend, $addressBook, $this->l10n); |
|
81 | - }, $addressBooks); |
|
82 | - /** @var IAddressBook[][] $objectsFromPlugins */ |
|
83 | - $objectsFromPlugins = array_map(function (IAddressBookProvider $plugin): array { |
|
84 | - return $plugin->fetchAllForAddressBookHome($this->principalUri); |
|
85 | - }, $this->pluginManager->getAddressBookPlugins()); |
|
86 | - |
|
87 | - return array_merge($objects, ...$objectsFromPlugins); |
|
88 | - } |
|
89 | - |
|
90 | - public function createExtendedCollection($name, MkCol $mkCol) { |
|
91 | - if (ExternalAddressBook::doesViolateReservedName($name)) { |
|
92 | - throw new MethodNotAllowed('The resource you tried to create has a reserved name'); |
|
93 | - } |
|
94 | - |
|
95 | - parent::createExtendedCollection($name, $mkCol); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Returns a list of ACE's for this node. |
|
100 | - * |
|
101 | - * Each ACE has the following properties: |
|
102 | - * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
103 | - * currently the only supported privileges |
|
104 | - * * 'principal', a url to the principal who owns the node |
|
105 | - * * 'protected' (optional), indicating that this ACE is not allowed to |
|
106 | - * be updated. |
|
107 | - * |
|
108 | - * @return array |
|
109 | - */ |
|
110 | - public function getACL() { |
|
111 | - $acl = parent::getACL(); |
|
112 | - if ($this->principalUri === 'principals/system/system') { |
|
113 | - $acl[] = [ |
|
114 | - 'privilege' => '{DAV:}read', |
|
115 | - 'principal' => '{DAV:}authenticated', |
|
116 | - 'protected' => true, |
|
117 | - ]; |
|
118 | - } |
|
119 | - |
|
120 | - return $acl; |
|
121 | - } |
|
44 | + /** @var IL10N */ |
|
45 | + protected $l10n; |
|
46 | + |
|
47 | + /** @var IConfig */ |
|
48 | + protected $config; |
|
49 | + |
|
50 | + /** @var PluginManager */ |
|
51 | + private $pluginManager; |
|
52 | + |
|
53 | + public function __construct(Backend\BackendInterface $carddavBackend, |
|
54 | + string $principalUri, |
|
55 | + PluginManager $pluginManager) { |
|
56 | + parent::__construct($carddavBackend, $principalUri); |
|
57 | + $this->pluginManager = $pluginManager; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Returns a list of address books |
|
62 | + * |
|
63 | + * @return IAddressBook[] |
|
64 | + */ |
|
65 | + public function getChildren() { |
|
66 | + if ($this->l10n === null) { |
|
67 | + $this->l10n = \OC::$server->getL10N('dav'); |
|
68 | + } |
|
69 | + if ($this->config === null) { |
|
70 | + $this->config = \OC::$server->getConfig(); |
|
71 | + } |
|
72 | + |
|
73 | + $addressBooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri); |
|
74 | + /** @var IAddressBook[] $objects */ |
|
75 | + $objects = array_map(function (array $addressBook) { |
|
76 | + if ($addressBook['principaluri'] === 'principals/system/system') { |
|
77 | + return new SystemAddressbook($this->carddavBackend, $addressBook, $this->l10n, $this->config); |
|
78 | + } |
|
79 | + |
|
80 | + return new AddressBook($this->carddavBackend, $addressBook, $this->l10n); |
|
81 | + }, $addressBooks); |
|
82 | + /** @var IAddressBook[][] $objectsFromPlugins */ |
|
83 | + $objectsFromPlugins = array_map(function (IAddressBookProvider $plugin): array { |
|
84 | + return $plugin->fetchAllForAddressBookHome($this->principalUri); |
|
85 | + }, $this->pluginManager->getAddressBookPlugins()); |
|
86 | + |
|
87 | + return array_merge($objects, ...$objectsFromPlugins); |
|
88 | + } |
|
89 | + |
|
90 | + public function createExtendedCollection($name, MkCol $mkCol) { |
|
91 | + if (ExternalAddressBook::doesViolateReservedName($name)) { |
|
92 | + throw new MethodNotAllowed('The resource you tried to create has a reserved name'); |
|
93 | + } |
|
94 | + |
|
95 | + parent::createExtendedCollection($name, $mkCol); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Returns a list of ACE's for this node. |
|
100 | + * |
|
101 | + * Each ACE has the following properties: |
|
102 | + * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
103 | + * currently the only supported privileges |
|
104 | + * * 'principal', a url to the principal who owns the node |
|
105 | + * * 'protected' (optional), indicating that this ACE is not allowed to |
|
106 | + * be updated. |
|
107 | + * |
|
108 | + * @return array |
|
109 | + */ |
|
110 | + public function getACL() { |
|
111 | + $acl = parent::getACL(); |
|
112 | + if ($this->principalUri === 'principals/system/system') { |
|
113 | + $acl[] = [ |
|
114 | + 'privilege' => '{DAV:}read', |
|
115 | + 'principal' => '{DAV:}authenticated', |
|
116 | + 'protected' => true, |
|
117 | + ]; |
|
118 | + } |
|
119 | + |
|
120 | + return $acl; |
|
121 | + } |
|
122 | 122 | } |