@@ -68,7 +68,7 @@ |
||
68 | 68 | foreach (['id', 'name'] as $property) { |
69 | 69 | $$property = trim($$property); |
70 | 70 | if (empty($$property) || !is_string($$property)) { |
71 | - throw new \InvalidArgumentException('"' . $property . '" parameter must be non-empty string'); |
|
71 | + throw new \InvalidArgumentException('"'.$property.'" parameter must be non-empty string'); |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | $this->id = $id; |
@@ -42,155 +42,155 @@ |
||
42 | 42 | * @package OCA\DAV\Comments |
43 | 43 | */ |
44 | 44 | class EntityCollection extends RootCollection implements IProperties { |
45 | - public const PROPERTY_NAME_READ_MARKER = '{http://owncloud.org/ns}readMarker'; |
|
45 | + public const PROPERTY_NAME_READ_MARKER = '{http://owncloud.org/ns}readMarker'; |
|
46 | 46 | |
47 | - /** @var string */ |
|
48 | - protected $id; |
|
47 | + /** @var string */ |
|
48 | + protected $id; |
|
49 | 49 | |
50 | - /** @var ILogger */ |
|
51 | - protected $logger; |
|
50 | + /** @var ILogger */ |
|
51 | + protected $logger; |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param string $id |
|
55 | - * @param string $name |
|
56 | - * @param ICommentsManager $commentsManager |
|
57 | - * @param IUserManager $userManager |
|
58 | - * @param IUserSession $userSession |
|
59 | - * @param ILogger $logger |
|
60 | - */ |
|
61 | - public function __construct( |
|
62 | - $id, |
|
63 | - $name, |
|
64 | - ICommentsManager $commentsManager, |
|
65 | - IUserManager $userManager, |
|
66 | - IUserSession $userSession, |
|
67 | - ILogger $logger |
|
68 | - ) { |
|
69 | - foreach (['id', 'name'] as $property) { |
|
70 | - $$property = trim($$property); |
|
71 | - if (empty($$property) || !is_string($$property)) { |
|
72 | - throw new \InvalidArgumentException('"' . $property . '" parameter must be non-empty string'); |
|
73 | - } |
|
74 | - } |
|
75 | - $this->id = $id; |
|
76 | - $this->name = $name; |
|
77 | - $this->commentsManager = $commentsManager; |
|
78 | - $this->logger = $logger; |
|
79 | - $this->userManager = $userManager; |
|
80 | - $this->userSession = $userSession; |
|
81 | - } |
|
53 | + /** |
|
54 | + * @param string $id |
|
55 | + * @param string $name |
|
56 | + * @param ICommentsManager $commentsManager |
|
57 | + * @param IUserManager $userManager |
|
58 | + * @param IUserSession $userSession |
|
59 | + * @param ILogger $logger |
|
60 | + */ |
|
61 | + public function __construct( |
|
62 | + $id, |
|
63 | + $name, |
|
64 | + ICommentsManager $commentsManager, |
|
65 | + IUserManager $userManager, |
|
66 | + IUserSession $userSession, |
|
67 | + ILogger $logger |
|
68 | + ) { |
|
69 | + foreach (['id', 'name'] as $property) { |
|
70 | + $$property = trim($$property); |
|
71 | + if (empty($$property) || !is_string($$property)) { |
|
72 | + throw new \InvalidArgumentException('"' . $property . '" parameter must be non-empty string'); |
|
73 | + } |
|
74 | + } |
|
75 | + $this->id = $id; |
|
76 | + $this->name = $name; |
|
77 | + $this->commentsManager = $commentsManager; |
|
78 | + $this->logger = $logger; |
|
79 | + $this->userManager = $userManager; |
|
80 | + $this->userSession = $userSession; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * returns the ID of this entity |
|
85 | - * |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - public function getId() { |
|
89 | - return $this->id; |
|
90 | - } |
|
83 | + /** |
|
84 | + * returns the ID of this entity |
|
85 | + * |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + public function getId() { |
|
89 | + return $this->id; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Returns a specific child node, referenced by its name |
|
94 | - * |
|
95 | - * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
96 | - * exist. |
|
97 | - * |
|
98 | - * @param string $name |
|
99 | - * @return \Sabre\DAV\INode |
|
100 | - * @throws NotFound |
|
101 | - */ |
|
102 | - public function getChild($name) { |
|
103 | - try { |
|
104 | - $comment = $this->commentsManager->get($name); |
|
105 | - return new CommentNode( |
|
106 | - $this->commentsManager, |
|
107 | - $comment, |
|
108 | - $this->userManager, |
|
109 | - $this->userSession, |
|
110 | - $this->logger |
|
111 | - ); |
|
112 | - } catch (NotFoundException $e) { |
|
113 | - throw new NotFound(); |
|
114 | - } |
|
115 | - } |
|
92 | + /** |
|
93 | + * Returns a specific child node, referenced by its name |
|
94 | + * |
|
95 | + * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
96 | + * exist. |
|
97 | + * |
|
98 | + * @param string $name |
|
99 | + * @return \Sabre\DAV\INode |
|
100 | + * @throws NotFound |
|
101 | + */ |
|
102 | + public function getChild($name) { |
|
103 | + try { |
|
104 | + $comment = $this->commentsManager->get($name); |
|
105 | + return new CommentNode( |
|
106 | + $this->commentsManager, |
|
107 | + $comment, |
|
108 | + $this->userManager, |
|
109 | + $this->userSession, |
|
110 | + $this->logger |
|
111 | + ); |
|
112 | + } catch (NotFoundException $e) { |
|
113 | + throw new NotFound(); |
|
114 | + } |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Returns an array with all the child nodes |
|
119 | - * |
|
120 | - * @return \Sabre\DAV\INode[] |
|
121 | - */ |
|
122 | - public function getChildren() { |
|
123 | - return $this->findChildren(); |
|
124 | - } |
|
117 | + /** |
|
118 | + * Returns an array with all the child nodes |
|
119 | + * |
|
120 | + * @return \Sabre\DAV\INode[] |
|
121 | + */ |
|
122 | + public function getChildren() { |
|
123 | + return $this->findChildren(); |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * Returns an array of comment nodes. Result can be influenced by offset, |
|
128 | - * limit and date time parameters. |
|
129 | - * |
|
130 | - * @param int $limit |
|
131 | - * @param int $offset |
|
132 | - * @param \DateTime|null $datetime |
|
133 | - * @return CommentNode[] |
|
134 | - */ |
|
135 | - public function findChildren($limit = 0, $offset = 0, \DateTime $datetime = null) { |
|
136 | - $comments = $this->commentsManager->getForObject($this->name, $this->id, $limit, $offset, $datetime); |
|
137 | - $result = []; |
|
138 | - foreach ($comments as $comment) { |
|
139 | - $result[] = new CommentNode( |
|
140 | - $this->commentsManager, |
|
141 | - $comment, |
|
142 | - $this->userManager, |
|
143 | - $this->userSession, |
|
144 | - $this->logger |
|
145 | - ); |
|
146 | - } |
|
147 | - return $result; |
|
148 | - } |
|
126 | + /** |
|
127 | + * Returns an array of comment nodes. Result can be influenced by offset, |
|
128 | + * limit and date time parameters. |
|
129 | + * |
|
130 | + * @param int $limit |
|
131 | + * @param int $offset |
|
132 | + * @param \DateTime|null $datetime |
|
133 | + * @return CommentNode[] |
|
134 | + */ |
|
135 | + public function findChildren($limit = 0, $offset = 0, \DateTime $datetime = null) { |
|
136 | + $comments = $this->commentsManager->getForObject($this->name, $this->id, $limit, $offset, $datetime); |
|
137 | + $result = []; |
|
138 | + foreach ($comments as $comment) { |
|
139 | + $result[] = new CommentNode( |
|
140 | + $this->commentsManager, |
|
141 | + $comment, |
|
142 | + $this->userManager, |
|
143 | + $this->userSession, |
|
144 | + $this->logger |
|
145 | + ); |
|
146 | + } |
|
147 | + return $result; |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * Checks if a child-node with the specified name exists |
|
152 | - * |
|
153 | - * @param string $name |
|
154 | - * @return bool |
|
155 | - */ |
|
156 | - public function childExists($name) { |
|
157 | - try { |
|
158 | - $this->commentsManager->get($name); |
|
159 | - return true; |
|
160 | - } catch (NotFoundException $e) { |
|
161 | - return false; |
|
162 | - } |
|
163 | - } |
|
150 | + /** |
|
151 | + * Checks if a child-node with the specified name exists |
|
152 | + * |
|
153 | + * @param string $name |
|
154 | + * @return bool |
|
155 | + */ |
|
156 | + public function childExists($name) { |
|
157 | + try { |
|
158 | + $this->commentsManager->get($name); |
|
159 | + return true; |
|
160 | + } catch (NotFoundException $e) { |
|
161 | + return false; |
|
162 | + } |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * Sets the read marker to the specified date for the logged in user |
|
167 | - * |
|
168 | - * @param \DateTime $value |
|
169 | - * @return bool |
|
170 | - */ |
|
171 | - public function setReadMarker($value) { |
|
172 | - $dateTime = new \DateTime($value); |
|
173 | - $user = $this->userSession->getUser(); |
|
174 | - $this->commentsManager->setReadMark($this->name, $this->id, $dateTime, $user); |
|
175 | - return true; |
|
176 | - } |
|
165 | + /** |
|
166 | + * Sets the read marker to the specified date for the logged in user |
|
167 | + * |
|
168 | + * @param \DateTime $value |
|
169 | + * @return bool |
|
170 | + */ |
|
171 | + public function setReadMarker($value) { |
|
172 | + $dateTime = new \DateTime($value); |
|
173 | + $user = $this->userSession->getUser(); |
|
174 | + $this->commentsManager->setReadMark($this->name, $this->id, $dateTime, $user); |
|
175 | + return true; |
|
176 | + } |
|
177 | 177 | |
178 | - /** |
|
179 | - * @inheritdoc |
|
180 | - */ |
|
181 | - public function propPatch(PropPatch $propPatch) { |
|
182 | - $propPatch->handle(self::PROPERTY_NAME_READ_MARKER, [$this, 'setReadMarker']); |
|
183 | - } |
|
178 | + /** |
|
179 | + * @inheritdoc |
|
180 | + */ |
|
181 | + public function propPatch(PropPatch $propPatch) { |
|
182 | + $propPatch->handle(self::PROPERTY_NAME_READ_MARKER, [$this, 'setReadMarker']); |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * @inheritdoc |
|
187 | - */ |
|
188 | - public function getProperties($properties) { |
|
189 | - $marker = null; |
|
190 | - $user = $this->userSession->getUser(); |
|
191 | - if (!is_null($user)) { |
|
192 | - $marker = $this->commentsManager->getReadMark($this->name, $this->id, $user); |
|
193 | - } |
|
194 | - return [self::PROPERTY_NAME_READ_MARKER => $marker]; |
|
195 | - } |
|
185 | + /** |
|
186 | + * @inheritdoc |
|
187 | + */ |
|
188 | + public function getProperties($properties) { |
|
189 | + $marker = null; |
|
190 | + $user = $this->userSession->getUser(); |
|
191 | + if (!is_null($user)) { |
|
192 | + $marker = $this->commentsManager->getReadMark($this->name, $this->id, $user); |
|
193 | + } |
|
194 | + return [self::PROPERTY_NAME_READ_MARKER => $marker]; |
|
195 | + } |
|
196 | 196 | } |
@@ -85,14 +85,14 @@ discard block |
||
85 | 85 | $this->logger = $logger; |
86 | 86 | |
87 | 87 | $methods = get_class_methods($this->comment); |
88 | - $methods = array_filter($methods, function ($name) { |
|
88 | + $methods = array_filter($methods, function($name) { |
|
89 | 89 | return strpos($name, 'get') === 0; |
90 | 90 | }); |
91 | 91 | foreach ($methods as $getter) { |
92 | 92 | if ($getter === 'getMentions') { |
93 | - continue; // special treatment |
|
93 | + continue; // special treatment |
|
94 | 94 | } |
95 | - $name = '{'.self::NS_OWNCLOUD.'}' . lcfirst(substr($getter, 3)); |
|
95 | + $name = '{'.self::NS_OWNCLOUD.'}'.lcfirst(substr($getter, 3)); |
|
96 | 96 | $this->properties[$name] = $getter; |
97 | 97 | } |
98 | 98 | $this->userManager = $userManager; |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | $this->logger->logException($e, ['app' => 'dav/comments']); |
198 | 198 | if ($e instanceof MessageTooLongException) { |
199 | 199 | $msg = 'Message exceeds allowed character limit of '; |
200 | - throw new BadRequest($msg . IComment::MAX_MESSAGE_LENGTH, 0, $e); |
|
200 | + throw new BadRequest($msg.IComment::MAX_MESSAGE_LENGTH, 0, $e); |
|
201 | 201 | } |
202 | 202 | throw $e; |
203 | 203 | } |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @return array |
284 | 284 | */ |
285 | 285 | protected function composeMentionsPropertyValue() { |
286 | - return array_map(function ($mention) { |
|
286 | + return array_map(function($mention) { |
|
287 | 287 | try { |
288 | 288 | $displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']); |
289 | 289 | } catch (\OutOfBoundsException $e) { |
@@ -36,270 +36,270 @@ |
||
36 | 36 | use Sabre\DAV\PropPatch; |
37 | 37 | |
38 | 38 | class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties { |
39 | - public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
39 | + public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
40 | 40 | |
41 | - public const PROPERTY_NAME_UNREAD = '{http://owncloud.org/ns}isUnread'; |
|
42 | - public const PROPERTY_NAME_MESSAGE = '{http://owncloud.org/ns}message'; |
|
43 | - public const PROPERTY_NAME_ACTOR_DISPLAYNAME = '{http://owncloud.org/ns}actorDisplayName'; |
|
44 | - public const PROPERTY_NAME_MENTIONS = '{http://owncloud.org/ns}mentions'; |
|
45 | - public const PROPERTY_NAME_MENTION = '{http://owncloud.org/ns}mention'; |
|
46 | - public const PROPERTY_NAME_MENTION_TYPE = '{http://owncloud.org/ns}mentionType'; |
|
47 | - public const PROPERTY_NAME_MENTION_ID = '{http://owncloud.org/ns}mentionId'; |
|
48 | - public const PROPERTY_NAME_MENTION_DISPLAYNAME = '{http://owncloud.org/ns}mentionDisplayName'; |
|
41 | + public const PROPERTY_NAME_UNREAD = '{http://owncloud.org/ns}isUnread'; |
|
42 | + public const PROPERTY_NAME_MESSAGE = '{http://owncloud.org/ns}message'; |
|
43 | + public const PROPERTY_NAME_ACTOR_DISPLAYNAME = '{http://owncloud.org/ns}actorDisplayName'; |
|
44 | + public const PROPERTY_NAME_MENTIONS = '{http://owncloud.org/ns}mentions'; |
|
45 | + public const PROPERTY_NAME_MENTION = '{http://owncloud.org/ns}mention'; |
|
46 | + public const PROPERTY_NAME_MENTION_TYPE = '{http://owncloud.org/ns}mentionType'; |
|
47 | + public const PROPERTY_NAME_MENTION_ID = '{http://owncloud.org/ns}mentionId'; |
|
48 | + public const PROPERTY_NAME_MENTION_DISPLAYNAME = '{http://owncloud.org/ns}mentionDisplayName'; |
|
49 | 49 | |
50 | - /** @var IComment */ |
|
51 | - public $comment; |
|
50 | + /** @var IComment */ |
|
51 | + public $comment; |
|
52 | 52 | |
53 | - /** @var ICommentsManager */ |
|
54 | - protected $commentsManager; |
|
53 | + /** @var ICommentsManager */ |
|
54 | + protected $commentsManager; |
|
55 | 55 | |
56 | - /** @var ILogger */ |
|
57 | - protected $logger; |
|
56 | + /** @var ILogger */ |
|
57 | + protected $logger; |
|
58 | 58 | |
59 | - /** @var array list of properties with key being their name and value their setter */ |
|
60 | - protected $properties = []; |
|
59 | + /** @var array list of properties with key being their name and value their setter */ |
|
60 | + protected $properties = []; |
|
61 | 61 | |
62 | - /** @var IUserManager */ |
|
63 | - protected $userManager; |
|
62 | + /** @var IUserManager */ |
|
63 | + protected $userManager; |
|
64 | 64 | |
65 | - /** @var IUserSession */ |
|
66 | - protected $userSession; |
|
65 | + /** @var IUserSession */ |
|
66 | + protected $userSession; |
|
67 | 67 | |
68 | - /** |
|
69 | - * CommentNode constructor. |
|
70 | - * |
|
71 | - * @param ICommentsManager $commentsManager |
|
72 | - * @param IComment $comment |
|
73 | - * @param IUserManager $userManager |
|
74 | - * @param IUserSession $userSession |
|
75 | - * @param ILogger $logger |
|
76 | - */ |
|
77 | - public function __construct( |
|
78 | - ICommentsManager $commentsManager, |
|
79 | - IComment $comment, |
|
80 | - IUserManager $userManager, |
|
81 | - IUserSession $userSession, |
|
82 | - ILogger $logger |
|
83 | - ) { |
|
84 | - $this->commentsManager = $commentsManager; |
|
85 | - $this->comment = $comment; |
|
86 | - $this->logger = $logger; |
|
68 | + /** |
|
69 | + * CommentNode constructor. |
|
70 | + * |
|
71 | + * @param ICommentsManager $commentsManager |
|
72 | + * @param IComment $comment |
|
73 | + * @param IUserManager $userManager |
|
74 | + * @param IUserSession $userSession |
|
75 | + * @param ILogger $logger |
|
76 | + */ |
|
77 | + public function __construct( |
|
78 | + ICommentsManager $commentsManager, |
|
79 | + IComment $comment, |
|
80 | + IUserManager $userManager, |
|
81 | + IUserSession $userSession, |
|
82 | + ILogger $logger |
|
83 | + ) { |
|
84 | + $this->commentsManager = $commentsManager; |
|
85 | + $this->comment = $comment; |
|
86 | + $this->logger = $logger; |
|
87 | 87 | |
88 | - $methods = get_class_methods($this->comment); |
|
89 | - $methods = array_filter($methods, function ($name) { |
|
90 | - return strpos($name, 'get') === 0; |
|
91 | - }); |
|
92 | - foreach ($methods as $getter) { |
|
93 | - if ($getter === 'getMentions') { |
|
94 | - continue; // special treatment |
|
95 | - } |
|
96 | - $name = '{'.self::NS_OWNCLOUD.'}' . lcfirst(substr($getter, 3)); |
|
97 | - $this->properties[$name] = $getter; |
|
98 | - } |
|
99 | - $this->userManager = $userManager; |
|
100 | - $this->userSession = $userSession; |
|
101 | - } |
|
88 | + $methods = get_class_methods($this->comment); |
|
89 | + $methods = array_filter($methods, function ($name) { |
|
90 | + return strpos($name, 'get') === 0; |
|
91 | + }); |
|
92 | + foreach ($methods as $getter) { |
|
93 | + if ($getter === 'getMentions') { |
|
94 | + continue; // special treatment |
|
95 | + } |
|
96 | + $name = '{'.self::NS_OWNCLOUD.'}' . lcfirst(substr($getter, 3)); |
|
97 | + $this->properties[$name] = $getter; |
|
98 | + } |
|
99 | + $this->userManager = $userManager; |
|
100 | + $this->userSession = $userSession; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * returns a list of all possible property names |
|
105 | - * |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - public static function getPropertyNames() { |
|
109 | - return [ |
|
110 | - '{http://owncloud.org/ns}id', |
|
111 | - '{http://owncloud.org/ns}parentId', |
|
112 | - '{http://owncloud.org/ns}topmostParentId', |
|
113 | - '{http://owncloud.org/ns}childrenCount', |
|
114 | - '{http://owncloud.org/ns}verb', |
|
115 | - '{http://owncloud.org/ns}actorType', |
|
116 | - '{http://owncloud.org/ns}actorId', |
|
117 | - '{http://owncloud.org/ns}creationDateTime', |
|
118 | - '{http://owncloud.org/ns}latestChildDateTime', |
|
119 | - '{http://owncloud.org/ns}objectType', |
|
120 | - '{http://owncloud.org/ns}objectId', |
|
121 | - // re-used property names are defined as constants |
|
122 | - self::PROPERTY_NAME_MESSAGE, |
|
123 | - self::PROPERTY_NAME_ACTOR_DISPLAYNAME, |
|
124 | - self::PROPERTY_NAME_UNREAD, |
|
125 | - self::PROPERTY_NAME_MENTIONS, |
|
126 | - self::PROPERTY_NAME_MENTION, |
|
127 | - self::PROPERTY_NAME_MENTION_TYPE, |
|
128 | - self::PROPERTY_NAME_MENTION_ID, |
|
129 | - self::PROPERTY_NAME_MENTION_DISPLAYNAME, |
|
130 | - ]; |
|
131 | - } |
|
103 | + /** |
|
104 | + * returns a list of all possible property names |
|
105 | + * |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + public static function getPropertyNames() { |
|
109 | + return [ |
|
110 | + '{http://owncloud.org/ns}id', |
|
111 | + '{http://owncloud.org/ns}parentId', |
|
112 | + '{http://owncloud.org/ns}topmostParentId', |
|
113 | + '{http://owncloud.org/ns}childrenCount', |
|
114 | + '{http://owncloud.org/ns}verb', |
|
115 | + '{http://owncloud.org/ns}actorType', |
|
116 | + '{http://owncloud.org/ns}actorId', |
|
117 | + '{http://owncloud.org/ns}creationDateTime', |
|
118 | + '{http://owncloud.org/ns}latestChildDateTime', |
|
119 | + '{http://owncloud.org/ns}objectType', |
|
120 | + '{http://owncloud.org/ns}objectId', |
|
121 | + // re-used property names are defined as constants |
|
122 | + self::PROPERTY_NAME_MESSAGE, |
|
123 | + self::PROPERTY_NAME_ACTOR_DISPLAYNAME, |
|
124 | + self::PROPERTY_NAME_UNREAD, |
|
125 | + self::PROPERTY_NAME_MENTIONS, |
|
126 | + self::PROPERTY_NAME_MENTION, |
|
127 | + self::PROPERTY_NAME_MENTION_TYPE, |
|
128 | + self::PROPERTY_NAME_MENTION_ID, |
|
129 | + self::PROPERTY_NAME_MENTION_DISPLAYNAME, |
|
130 | + ]; |
|
131 | + } |
|
132 | 132 | |
133 | - protected function checkWriteAccessOnComment() { |
|
134 | - $user = $this->userSession->getUser(); |
|
135 | - if ($this->comment->getActorType() !== 'users' |
|
136 | - || is_null($user) |
|
137 | - || $this->comment->getActorId() !== $user->getUID() |
|
138 | - ) { |
|
139 | - throw new Forbidden('Only authors are allowed to edit their comment.'); |
|
140 | - } |
|
141 | - } |
|
133 | + protected function checkWriteAccessOnComment() { |
|
134 | + $user = $this->userSession->getUser(); |
|
135 | + if ($this->comment->getActorType() !== 'users' |
|
136 | + || is_null($user) |
|
137 | + || $this->comment->getActorId() !== $user->getUID() |
|
138 | + ) { |
|
139 | + throw new Forbidden('Only authors are allowed to edit their comment.'); |
|
140 | + } |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * Deleted the current node |
|
145 | - * |
|
146 | - * @return void |
|
147 | - */ |
|
148 | - public function delete() { |
|
149 | - $this->checkWriteAccessOnComment(); |
|
150 | - $this->commentsManager->delete($this->comment->getId()); |
|
151 | - } |
|
143 | + /** |
|
144 | + * Deleted the current node |
|
145 | + * |
|
146 | + * @return void |
|
147 | + */ |
|
148 | + public function delete() { |
|
149 | + $this->checkWriteAccessOnComment(); |
|
150 | + $this->commentsManager->delete($this->comment->getId()); |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * Returns the name of the node. |
|
155 | - * |
|
156 | - * This is used to generate the url. |
|
157 | - * |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - public function getName() { |
|
161 | - return $this->comment->getId(); |
|
162 | - } |
|
153 | + /** |
|
154 | + * Returns the name of the node. |
|
155 | + * |
|
156 | + * This is used to generate the url. |
|
157 | + * |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + public function getName() { |
|
161 | + return $this->comment->getId(); |
|
162 | + } |
|
163 | 163 | |
164 | - /** |
|
165 | - * Renames the node |
|
166 | - * |
|
167 | - * @param string $name The new name |
|
168 | - * @throws MethodNotAllowed |
|
169 | - */ |
|
170 | - public function setName($name) { |
|
171 | - throw new MethodNotAllowed(); |
|
172 | - } |
|
164 | + /** |
|
165 | + * Renames the node |
|
166 | + * |
|
167 | + * @param string $name The new name |
|
168 | + * @throws MethodNotAllowed |
|
169 | + */ |
|
170 | + public function setName($name) { |
|
171 | + throw new MethodNotAllowed(); |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * Returns the last modification time, as a unix timestamp |
|
176 | - * |
|
177 | - * @return int |
|
178 | - */ |
|
179 | - public function getLastModified() { |
|
180 | - return null; |
|
181 | - } |
|
174 | + /** |
|
175 | + * Returns the last modification time, as a unix timestamp |
|
176 | + * |
|
177 | + * @return int |
|
178 | + */ |
|
179 | + public function getLastModified() { |
|
180 | + return null; |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * update the comment's message |
|
185 | - * |
|
186 | - * @param $propertyValue |
|
187 | - * @return bool |
|
188 | - * @throws BadRequest |
|
189 | - * @throws \Exception |
|
190 | - */ |
|
191 | - public function updateComment($propertyValue) { |
|
192 | - $this->checkWriteAccessOnComment(); |
|
193 | - try { |
|
194 | - $this->comment->setMessage($propertyValue); |
|
195 | - $this->commentsManager->save($this->comment); |
|
196 | - return true; |
|
197 | - } catch (\Exception $e) { |
|
198 | - $this->logger->logException($e, ['app' => 'dav/comments']); |
|
199 | - if ($e instanceof MessageTooLongException) { |
|
200 | - $msg = 'Message exceeds allowed character limit of '; |
|
201 | - throw new BadRequest($msg . IComment::MAX_MESSAGE_LENGTH, 0, $e); |
|
202 | - } |
|
203 | - throw $e; |
|
204 | - } |
|
205 | - } |
|
183 | + /** |
|
184 | + * update the comment's message |
|
185 | + * |
|
186 | + * @param $propertyValue |
|
187 | + * @return bool |
|
188 | + * @throws BadRequest |
|
189 | + * @throws \Exception |
|
190 | + */ |
|
191 | + public function updateComment($propertyValue) { |
|
192 | + $this->checkWriteAccessOnComment(); |
|
193 | + try { |
|
194 | + $this->comment->setMessage($propertyValue); |
|
195 | + $this->commentsManager->save($this->comment); |
|
196 | + return true; |
|
197 | + } catch (\Exception $e) { |
|
198 | + $this->logger->logException($e, ['app' => 'dav/comments']); |
|
199 | + if ($e instanceof MessageTooLongException) { |
|
200 | + $msg = 'Message exceeds allowed character limit of '; |
|
201 | + throw new BadRequest($msg . IComment::MAX_MESSAGE_LENGTH, 0, $e); |
|
202 | + } |
|
203 | + throw $e; |
|
204 | + } |
|
205 | + } |
|
206 | 206 | |
207 | - /** |
|
208 | - * Updates properties on this node. |
|
209 | - * |
|
210 | - * This method received a PropPatch object, which contains all the |
|
211 | - * information about the update. |
|
212 | - * |
|
213 | - * To update specific properties, call the 'handle' method on this object. |
|
214 | - * Read the PropPatch documentation for more information. |
|
215 | - * |
|
216 | - * @param PropPatch $propPatch |
|
217 | - * @return void |
|
218 | - */ |
|
219 | - public function propPatch(PropPatch $propPatch) { |
|
220 | - // other properties than 'message' are read only |
|
221 | - $propPatch->handle(self::PROPERTY_NAME_MESSAGE, [$this, 'updateComment']); |
|
222 | - } |
|
207 | + /** |
|
208 | + * Updates properties on this node. |
|
209 | + * |
|
210 | + * This method received a PropPatch object, which contains all the |
|
211 | + * information about the update. |
|
212 | + * |
|
213 | + * To update specific properties, call the 'handle' method on this object. |
|
214 | + * Read the PropPatch documentation for more information. |
|
215 | + * |
|
216 | + * @param PropPatch $propPatch |
|
217 | + * @return void |
|
218 | + */ |
|
219 | + public function propPatch(PropPatch $propPatch) { |
|
220 | + // other properties than 'message' are read only |
|
221 | + $propPatch->handle(self::PROPERTY_NAME_MESSAGE, [$this, 'updateComment']); |
|
222 | + } |
|
223 | 223 | |
224 | - /** |
|
225 | - * Returns a list of properties for this nodes. |
|
226 | - * |
|
227 | - * The properties list is a list of propertynames the client requested, |
|
228 | - * encoded in clark-notation {xmlnamespace}tagname |
|
229 | - * |
|
230 | - * If the array is empty, it means 'all properties' were requested. |
|
231 | - * |
|
232 | - * Note that it's fine to liberally give properties back, instead of |
|
233 | - * conforming to the list of requested properties. |
|
234 | - * The Server class will filter out the extra. |
|
235 | - * |
|
236 | - * @param array $properties |
|
237 | - * @return array |
|
238 | - */ |
|
239 | - public function getProperties($properties) { |
|
240 | - $properties = array_keys($this->properties); |
|
224 | + /** |
|
225 | + * Returns a list of properties for this nodes. |
|
226 | + * |
|
227 | + * The properties list is a list of propertynames the client requested, |
|
228 | + * encoded in clark-notation {xmlnamespace}tagname |
|
229 | + * |
|
230 | + * If the array is empty, it means 'all properties' were requested. |
|
231 | + * |
|
232 | + * Note that it's fine to liberally give properties back, instead of |
|
233 | + * conforming to the list of requested properties. |
|
234 | + * The Server class will filter out the extra. |
|
235 | + * |
|
236 | + * @param array $properties |
|
237 | + * @return array |
|
238 | + */ |
|
239 | + public function getProperties($properties) { |
|
240 | + $properties = array_keys($this->properties); |
|
241 | 241 | |
242 | - $result = []; |
|
243 | - foreach ($properties as $property) { |
|
244 | - $getter = $this->properties[$property]; |
|
245 | - if (method_exists($this->comment, $getter)) { |
|
246 | - $result[$property] = $this->comment->$getter(); |
|
247 | - } |
|
248 | - } |
|
242 | + $result = []; |
|
243 | + foreach ($properties as $property) { |
|
244 | + $getter = $this->properties[$property]; |
|
245 | + if (method_exists($this->comment, $getter)) { |
|
246 | + $result[$property] = $this->comment->$getter(); |
|
247 | + } |
|
248 | + } |
|
249 | 249 | |
250 | - if ($this->comment->getActorType() === 'users') { |
|
251 | - $user = $this->userManager->get($this->comment->getActorId()); |
|
252 | - $displayName = is_null($user) ? null : $user->getDisplayName(); |
|
253 | - $result[self::PROPERTY_NAME_ACTOR_DISPLAYNAME] = $displayName; |
|
254 | - } |
|
250 | + if ($this->comment->getActorType() === 'users') { |
|
251 | + $user = $this->userManager->get($this->comment->getActorId()); |
|
252 | + $displayName = is_null($user) ? null : $user->getDisplayName(); |
|
253 | + $result[self::PROPERTY_NAME_ACTOR_DISPLAYNAME] = $displayName; |
|
254 | + } |
|
255 | 255 | |
256 | - $result[self::PROPERTY_NAME_MENTIONS] = $this->composeMentionsPropertyValue(); |
|
256 | + $result[self::PROPERTY_NAME_MENTIONS] = $this->composeMentionsPropertyValue(); |
|
257 | 257 | |
258 | - $unread = null; |
|
259 | - $user = $this->userSession->getUser(); |
|
260 | - if (!is_null($user)) { |
|
261 | - $readUntil = $this->commentsManager->getReadMark( |
|
262 | - $this->comment->getObjectType(), |
|
263 | - $this->comment->getObjectId(), |
|
264 | - $user |
|
265 | - ); |
|
266 | - if (is_null($readUntil)) { |
|
267 | - $unread = 'true'; |
|
268 | - } else { |
|
269 | - $unread = $this->comment->getCreationDateTime() > $readUntil; |
|
270 | - // re-format for output |
|
271 | - $unread = $unread ? 'true' : 'false'; |
|
272 | - } |
|
273 | - } |
|
274 | - $result[self::PROPERTY_NAME_UNREAD] = $unread; |
|
258 | + $unread = null; |
|
259 | + $user = $this->userSession->getUser(); |
|
260 | + if (!is_null($user)) { |
|
261 | + $readUntil = $this->commentsManager->getReadMark( |
|
262 | + $this->comment->getObjectType(), |
|
263 | + $this->comment->getObjectId(), |
|
264 | + $user |
|
265 | + ); |
|
266 | + if (is_null($readUntil)) { |
|
267 | + $unread = 'true'; |
|
268 | + } else { |
|
269 | + $unread = $this->comment->getCreationDateTime() > $readUntil; |
|
270 | + // re-format for output |
|
271 | + $unread = $unread ? 'true' : 'false'; |
|
272 | + } |
|
273 | + } |
|
274 | + $result[self::PROPERTY_NAME_UNREAD] = $unread; |
|
275 | 275 | |
276 | - return $result; |
|
277 | - } |
|
276 | + return $result; |
|
277 | + } |
|
278 | 278 | |
279 | - /** |
|
280 | - * transforms a mentions array as returned from IComment->getMentions to an |
|
281 | - * array with DAV-compatible structure that can be assigned to the |
|
282 | - * PROPERTY_NAME_MENTION property. |
|
283 | - * |
|
284 | - * @return array |
|
285 | - */ |
|
286 | - protected function composeMentionsPropertyValue() { |
|
287 | - return array_map(function ($mention) { |
|
288 | - try { |
|
289 | - $displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']); |
|
290 | - } catch (\OutOfBoundsException $e) { |
|
291 | - $this->logger->logException($e); |
|
292 | - // No displayname, upon client's discretion what to display. |
|
293 | - $displayName = ''; |
|
294 | - } |
|
279 | + /** |
|
280 | + * transforms a mentions array as returned from IComment->getMentions to an |
|
281 | + * array with DAV-compatible structure that can be assigned to the |
|
282 | + * PROPERTY_NAME_MENTION property. |
|
283 | + * |
|
284 | + * @return array |
|
285 | + */ |
|
286 | + protected function composeMentionsPropertyValue() { |
|
287 | + return array_map(function ($mention) { |
|
288 | + try { |
|
289 | + $displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']); |
|
290 | + } catch (\OutOfBoundsException $e) { |
|
291 | + $this->logger->logException($e); |
|
292 | + // No displayname, upon client's discretion what to display. |
|
293 | + $displayName = ''; |
|
294 | + } |
|
295 | 295 | |
296 | - return [ |
|
297 | - self::PROPERTY_NAME_MENTION => [ |
|
298 | - self::PROPERTY_NAME_MENTION_TYPE => $mention['type'], |
|
299 | - self::PROPERTY_NAME_MENTION_ID => $mention['id'], |
|
300 | - self::PROPERTY_NAME_MENTION_DISPLAYNAME => $displayName, |
|
301 | - ] |
|
302 | - ]; |
|
303 | - }, $this->comment->getMentions()); |
|
304 | - } |
|
296 | + return [ |
|
297 | + self::PROPERTY_NAME_MENTION => [ |
|
298 | + self::PROPERTY_NAME_MENTION_TYPE => $mention['type'], |
|
299 | + self::PROPERTY_NAME_MENTION_ID => $mention['id'], |
|
300 | + self::PROPERTY_NAME_MENTION_DISPLAYNAME => $displayName, |
|
301 | + ] |
|
302 | + ]; |
|
303 | + }, $this->comment->getMentions()); |
|
304 | + } |
|
305 | 305 | } |
@@ -77,7 +77,7 @@ |
||
77 | 77 | $path = array_pop($path); |
78 | 78 | |
79 | 79 | $newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view); |
80 | - $url = $request->getBaseUrl() . $newName; |
|
80 | + $url = $request->getBaseUrl().$newName; |
|
81 | 81 | $request->setUrl($url); |
82 | 82 | } |
83 | 83 | } |
@@ -35,51 +35,51 @@ |
||
35 | 35 | */ |
36 | 36 | class FilesDropPlugin extends ServerPlugin { |
37 | 37 | |
38 | - /** @var View */ |
|
39 | - private $view; |
|
38 | + /** @var View */ |
|
39 | + private $view; |
|
40 | 40 | |
41 | - /** @var bool */ |
|
42 | - private $enabled = false; |
|
41 | + /** @var bool */ |
|
42 | + private $enabled = false; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param View $view |
|
46 | - */ |
|
47 | - public function setView($view) { |
|
48 | - $this->view = $view; |
|
49 | - } |
|
44 | + /** |
|
45 | + * @param View $view |
|
46 | + */ |
|
47 | + public function setView($view) { |
|
48 | + $this->view = $view; |
|
49 | + } |
|
50 | 50 | |
51 | - public function enable() { |
|
52 | - $this->enabled = true; |
|
53 | - } |
|
51 | + public function enable() { |
|
52 | + $this->enabled = true; |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * This initializes the plugin. |
|
58 | - * |
|
59 | - * @param \Sabre\DAV\Server $server Sabre server |
|
60 | - * |
|
61 | - * @return void |
|
62 | - * @throws MethodNotAllowed |
|
63 | - */ |
|
64 | - public function initialize(\Sabre\DAV\Server $server) { |
|
65 | - $server->on('beforeMethod:*', [$this, 'beforeMethod'], 999); |
|
66 | - $this->enabled = false; |
|
67 | - } |
|
56 | + /** |
|
57 | + * This initializes the plugin. |
|
58 | + * |
|
59 | + * @param \Sabre\DAV\Server $server Sabre server |
|
60 | + * |
|
61 | + * @return void |
|
62 | + * @throws MethodNotAllowed |
|
63 | + */ |
|
64 | + public function initialize(\Sabre\DAV\Server $server) { |
|
65 | + $server->on('beforeMethod:*', [$this, 'beforeMethod'], 999); |
|
66 | + $this->enabled = false; |
|
67 | + } |
|
68 | 68 | |
69 | - public function beforeMethod(RequestInterface $request, ResponseInterface $response) { |
|
70 | - if (!$this->enabled) { |
|
71 | - return; |
|
72 | - } |
|
69 | + public function beforeMethod(RequestInterface $request, ResponseInterface $response) { |
|
70 | + if (!$this->enabled) { |
|
71 | + return; |
|
72 | + } |
|
73 | 73 | |
74 | - if ($request->getMethod() !== 'PUT') { |
|
75 | - throw new MethodNotAllowed('Only PUT is allowed on files drop'); |
|
76 | - } |
|
74 | + if ($request->getMethod() !== 'PUT') { |
|
75 | + throw new MethodNotAllowed('Only PUT is allowed on files drop'); |
|
76 | + } |
|
77 | 77 | |
78 | - $path = explode('/', $request->getPath()); |
|
79 | - $path = array_pop($path); |
|
78 | + $path = explode('/', $request->getPath()); |
|
79 | + $path = array_pop($path); |
|
80 | 80 | |
81 | - $newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view); |
|
82 | - $url = $request->getBaseUrl() . $newName; |
|
83 | - $request->setUrl($url); |
|
84 | - } |
|
81 | + $newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view); |
|
82 | + $url = $request->getBaseUrl() . $newName; |
|
83 | + $request->setUrl($url); |
|
84 | + } |
|
85 | 85 | } |
@@ -54,7 +54,7 @@ |
||
54 | 54 | $output->writeln('Syncing users ...'); |
55 | 55 | $progress = new ProgressBar($output); |
56 | 56 | $progress->start(); |
57 | - $this->syncService->syncInstance(function () use ($progress) { |
|
57 | + $this->syncService->syncInstance(function() use ($progress) { |
|
58 | 58 | $progress->advance(); |
59 | 59 | }); |
60 | 60 |
@@ -32,37 +32,37 @@ |
||
32 | 32 | |
33 | 33 | class SyncSystemAddressBook extends Command { |
34 | 34 | |
35 | - /** @var SyncService */ |
|
36 | - private $syncService; |
|
35 | + /** @var SyncService */ |
|
36 | + private $syncService; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param SyncService $syncService |
|
40 | - */ |
|
41 | - public function __construct(SyncService $syncService) { |
|
42 | - parent::__construct(); |
|
43 | - $this->syncService = $syncService; |
|
44 | - } |
|
38 | + /** |
|
39 | + * @param SyncService $syncService |
|
40 | + */ |
|
41 | + public function __construct(SyncService $syncService) { |
|
42 | + parent::__construct(); |
|
43 | + $this->syncService = $syncService; |
|
44 | + } |
|
45 | 45 | |
46 | - protected function configure() { |
|
47 | - $this |
|
48 | - ->setName('dav:sync-system-addressbook') |
|
49 | - ->setDescription('Synchronizes users to the system addressbook'); |
|
50 | - } |
|
46 | + protected function configure() { |
|
47 | + $this |
|
48 | + ->setName('dav:sync-system-addressbook') |
|
49 | + ->setDescription('Synchronizes users to the system addressbook'); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param InputInterface $input |
|
54 | - * @param OutputInterface $output |
|
55 | - */ |
|
56 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
57 | - $output->writeln('Syncing users ...'); |
|
58 | - $progress = new ProgressBar($output); |
|
59 | - $progress->start(); |
|
60 | - $this->syncService->syncInstance(function () use ($progress) { |
|
61 | - $progress->advance(); |
|
62 | - }); |
|
52 | + /** |
|
53 | + * @param InputInterface $input |
|
54 | + * @param OutputInterface $output |
|
55 | + */ |
|
56 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
57 | + $output->writeln('Syncing users ...'); |
|
58 | + $progress = new ProgressBar($output); |
|
59 | + $progress->start(); |
|
60 | + $this->syncService->syncInstance(function () use ($progress) { |
|
61 | + $progress->advance(); |
|
62 | + }); |
|
63 | 63 | |
64 | - $progress->finish(); |
|
65 | - $output->writeln(''); |
|
66 | - return 0; |
|
67 | - } |
|
64 | + $progress->finish(); |
|
65 | + $output->writeln(''); |
|
66 | + return 0; |
|
67 | + } |
|
68 | 68 | } |
@@ -58,7 +58,7 @@ |
||
58 | 58 | public function getChild($name) { |
59 | 59 | $elements = pathinfo($name); |
60 | 60 | $ext = isset($elements['extension']) ? $elements['extension'] : ''; |
61 | - $size = (int)(isset($elements['filename']) ? $elements['filename'] : '64'); |
|
61 | + $size = (int) (isset($elements['filename']) ? $elements['filename'] : '64'); |
|
62 | 62 | if (!in_array($ext, ['jpeg', 'png'], true)) { |
63 | 63 | throw new MethodNotAllowed('File format not allowed'); |
64 | 64 | } |
@@ -34,87 +34,87 @@ |
||
34 | 34 | |
35 | 35 | class AvatarHome implements ICollection { |
36 | 36 | |
37 | - /** @var array */ |
|
38 | - private $principalInfo; |
|
39 | - /** @var IAvatarManager */ |
|
40 | - private $avatarManager; |
|
37 | + /** @var array */ |
|
38 | + private $principalInfo; |
|
39 | + /** @var IAvatarManager */ |
|
40 | + private $avatarManager; |
|
41 | 41 | |
42 | - /** |
|
43 | - * AvatarHome constructor. |
|
44 | - * |
|
45 | - * @param array $principalInfo |
|
46 | - * @param IAvatarManager $avatarManager |
|
47 | - */ |
|
48 | - public function __construct($principalInfo, IAvatarManager $avatarManager) { |
|
49 | - $this->principalInfo = $principalInfo; |
|
50 | - $this->avatarManager = $avatarManager; |
|
51 | - } |
|
42 | + /** |
|
43 | + * AvatarHome constructor. |
|
44 | + * |
|
45 | + * @param array $principalInfo |
|
46 | + * @param IAvatarManager $avatarManager |
|
47 | + */ |
|
48 | + public function __construct($principalInfo, IAvatarManager $avatarManager) { |
|
49 | + $this->principalInfo = $principalInfo; |
|
50 | + $this->avatarManager = $avatarManager; |
|
51 | + } |
|
52 | 52 | |
53 | - public function createFile($name, $data = null) { |
|
54 | - throw new Forbidden('Permission denied to create a file'); |
|
55 | - } |
|
53 | + public function createFile($name, $data = null) { |
|
54 | + throw new Forbidden('Permission denied to create a file'); |
|
55 | + } |
|
56 | 56 | |
57 | - public function createDirectory($name) { |
|
58 | - throw new Forbidden('Permission denied to create a folder'); |
|
59 | - } |
|
57 | + public function createDirectory($name) { |
|
58 | + throw new Forbidden('Permission denied to create a folder'); |
|
59 | + } |
|
60 | 60 | |
61 | - public function getChild($name) { |
|
62 | - $elements = pathinfo($name); |
|
63 | - $ext = isset($elements['extension']) ? $elements['extension'] : ''; |
|
64 | - $size = (int)(isset($elements['filename']) ? $elements['filename'] : '64'); |
|
65 | - if (!in_array($ext, ['jpeg', 'png'], true)) { |
|
66 | - throw new MethodNotAllowed('File format not allowed'); |
|
67 | - } |
|
68 | - if ($size <= 0 || $size > 1024) { |
|
69 | - throw new MethodNotAllowed('Invalid image size'); |
|
70 | - } |
|
71 | - $avatar = $this->avatarManager->getAvatar($this->getName()); |
|
72 | - if (!$avatar->exists()) { |
|
73 | - throw new NotFound(); |
|
74 | - } |
|
75 | - return new AvatarNode($size, $ext, $avatar); |
|
76 | - } |
|
61 | + public function getChild($name) { |
|
62 | + $elements = pathinfo($name); |
|
63 | + $ext = isset($elements['extension']) ? $elements['extension'] : ''; |
|
64 | + $size = (int)(isset($elements['filename']) ? $elements['filename'] : '64'); |
|
65 | + if (!in_array($ext, ['jpeg', 'png'], true)) { |
|
66 | + throw new MethodNotAllowed('File format not allowed'); |
|
67 | + } |
|
68 | + if ($size <= 0 || $size > 1024) { |
|
69 | + throw new MethodNotAllowed('Invalid image size'); |
|
70 | + } |
|
71 | + $avatar = $this->avatarManager->getAvatar($this->getName()); |
|
72 | + if (!$avatar->exists()) { |
|
73 | + throw new NotFound(); |
|
74 | + } |
|
75 | + return new AvatarNode($size, $ext, $avatar); |
|
76 | + } |
|
77 | 77 | |
78 | - public function getChildren() { |
|
79 | - try { |
|
80 | - return [ |
|
81 | - $this->getChild('96.jpeg') |
|
82 | - ]; |
|
83 | - } catch (NotFound $exception) { |
|
84 | - return []; |
|
85 | - } |
|
86 | - } |
|
78 | + public function getChildren() { |
|
79 | + try { |
|
80 | + return [ |
|
81 | + $this->getChild('96.jpeg') |
|
82 | + ]; |
|
83 | + } catch (NotFound $exception) { |
|
84 | + return []; |
|
85 | + } |
|
86 | + } |
|
87 | 87 | |
88 | - public function childExists($name) { |
|
89 | - try { |
|
90 | - $ret = $this->getChild($name); |
|
91 | - return $ret !== null; |
|
92 | - } catch (NotFound $ex) { |
|
93 | - return false; |
|
94 | - } catch (MethodNotAllowed $ex) { |
|
95 | - return false; |
|
96 | - } |
|
97 | - } |
|
88 | + public function childExists($name) { |
|
89 | + try { |
|
90 | + $ret = $this->getChild($name); |
|
91 | + return $ret !== null; |
|
92 | + } catch (NotFound $ex) { |
|
93 | + return false; |
|
94 | + } catch (MethodNotAllowed $ex) { |
|
95 | + return false; |
|
96 | + } |
|
97 | + } |
|
98 | 98 | |
99 | - public function delete() { |
|
100 | - throw new Forbidden('Permission denied to delete this folder'); |
|
101 | - } |
|
99 | + public function delete() { |
|
100 | + throw new Forbidden('Permission denied to delete this folder'); |
|
101 | + } |
|
102 | 102 | |
103 | - public function getName() { |
|
104 | - [,$name] = Uri\split($this->principalInfo['uri']); |
|
105 | - return $name; |
|
106 | - } |
|
103 | + public function getName() { |
|
104 | + [,$name] = Uri\split($this->principalInfo['uri']); |
|
105 | + return $name; |
|
106 | + } |
|
107 | 107 | |
108 | - public function setName($name) { |
|
109 | - throw new Forbidden('Permission denied to rename this folder'); |
|
110 | - } |
|
108 | + public function setName($name) { |
|
109 | + throw new Forbidden('Permission denied to rename this folder'); |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Returns the last modification time, as a unix timestamp |
|
114 | - * |
|
115 | - * @return int|null |
|
116 | - */ |
|
117 | - public function getLastModified() { |
|
118 | - return null; |
|
119 | - } |
|
112 | + /** |
|
113 | + * Returns the last modification time, as a unix timestamp |
|
114 | + * |
|
115 | + * @return int|null |
|
116 | + */ |
|
117 | + public function getLastModified() { |
|
118 | + return null; |
|
119 | + } |
|
120 | 120 | } |
@@ -26,71 +26,71 @@ |
||
26 | 26 | use Sabre\DAV\File; |
27 | 27 | |
28 | 28 | class AvatarNode extends File { |
29 | - private $ext; |
|
30 | - private $size; |
|
31 | - private $avatar; |
|
29 | + private $ext; |
|
30 | + private $size; |
|
31 | + private $avatar; |
|
32 | 32 | |
33 | - /** |
|
34 | - * AvatarNode constructor. |
|
35 | - * |
|
36 | - * @param integer $size |
|
37 | - * @param string $ext |
|
38 | - * @param IAvatar $avatar |
|
39 | - */ |
|
40 | - public function __construct($size, $ext, $avatar) { |
|
41 | - $this->size = $size; |
|
42 | - $this->ext = $ext; |
|
43 | - $this->avatar = $avatar; |
|
44 | - } |
|
33 | + /** |
|
34 | + * AvatarNode constructor. |
|
35 | + * |
|
36 | + * @param integer $size |
|
37 | + * @param string $ext |
|
38 | + * @param IAvatar $avatar |
|
39 | + */ |
|
40 | + public function __construct($size, $ext, $avatar) { |
|
41 | + $this->size = $size; |
|
42 | + $this->ext = $ext; |
|
43 | + $this->avatar = $avatar; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Returns the name of the node. |
|
48 | - * |
|
49 | - * This is used to generate the url. |
|
50 | - * |
|
51 | - * @return string |
|
52 | - */ |
|
53 | - public function getName() { |
|
54 | - return "$this->size.$this->ext"; |
|
55 | - } |
|
46 | + /** |
|
47 | + * Returns the name of the node. |
|
48 | + * |
|
49 | + * This is used to generate the url. |
|
50 | + * |
|
51 | + * @return string |
|
52 | + */ |
|
53 | + public function getName() { |
|
54 | + return "$this->size.$this->ext"; |
|
55 | + } |
|
56 | 56 | |
57 | - public function get() { |
|
58 | - $image = $this->avatar->get($this->size); |
|
59 | - $res = $image->resource(); |
|
57 | + public function get() { |
|
58 | + $image = $this->avatar->get($this->size); |
|
59 | + $res = $image->resource(); |
|
60 | 60 | |
61 | - ob_start(); |
|
62 | - if ($this->ext === 'png') { |
|
63 | - imagepng($res); |
|
64 | - } else { |
|
65 | - imagejpeg($res); |
|
66 | - } |
|
61 | + ob_start(); |
|
62 | + if ($this->ext === 'png') { |
|
63 | + imagepng($res); |
|
64 | + } else { |
|
65 | + imagejpeg($res); |
|
66 | + } |
|
67 | 67 | |
68 | - return ob_get_clean(); |
|
69 | - } |
|
68 | + return ob_get_clean(); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Returns the mime-type for a file |
|
73 | - * |
|
74 | - * If null is returned, we'll assume application/octet-stream |
|
75 | - * |
|
76 | - * @return string|null |
|
77 | - */ |
|
78 | - public function getContentType() { |
|
79 | - if ($this->ext === 'png') { |
|
80 | - return 'image/png'; |
|
81 | - } |
|
82 | - return 'image/jpeg'; |
|
83 | - } |
|
71 | + /** |
|
72 | + * Returns the mime-type for a file |
|
73 | + * |
|
74 | + * If null is returned, we'll assume application/octet-stream |
|
75 | + * |
|
76 | + * @return string|null |
|
77 | + */ |
|
78 | + public function getContentType() { |
|
79 | + if ($this->ext === 'png') { |
|
80 | + return 'image/png'; |
|
81 | + } |
|
82 | + return 'image/jpeg'; |
|
83 | + } |
|
84 | 84 | |
85 | - public function getETag() { |
|
86 | - return $this->avatar->getFile($this->size)->getEtag(); |
|
87 | - } |
|
85 | + public function getETag() { |
|
86 | + return $this->avatar->getFile($this->size)->getEtag(); |
|
87 | + } |
|
88 | 88 | |
89 | - public function getLastModified() { |
|
90 | - $timestamp = $this->avatar->getFile($this->size)->getMTime(); |
|
91 | - if (!empty($timestamp)) { |
|
92 | - return (int)$timestamp; |
|
93 | - } |
|
94 | - return $timestamp; |
|
95 | - } |
|
89 | + public function getLastModified() { |
|
90 | + $timestamp = $this->avatar->getFile($this->size)->getMTime(); |
|
91 | + if (!empty($timestamp)) { |
|
92 | + return (int)$timestamp; |
|
93 | + } |
|
94 | + return $timestamp; |
|
95 | + } |
|
96 | 96 | } |
@@ -89,7 +89,7 @@ |
||
89 | 89 | public function getLastModified() { |
90 | 90 | $timestamp = $this->avatar->getFile($this->size)->getMTime(); |
91 | 91 | if (!empty($timestamp)) { |
92 | - return (int)$timestamp; |
|
92 | + return (int) $timestamp; |
|
93 | 93 | } |
94 | 94 | return $timestamp; |
95 | 95 | } |
@@ -39,7 +39,7 @@ |
||
39 | 39 | |
40 | 40 | public function xmlSerialize(Writer $writer) { |
41 | 41 | foreach ($this->groups as $group) { |
42 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}group', $group); |
|
42 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}group', $group); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | } |
@@ -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 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
97 | 97 | // remote server revoked access to the address book, remove it |
98 | 98 | $this->backend->deleteAddressBook($addressBookId); |
99 | - $this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']); |
|
99 | + $this->logger->info('Authorization failed, remove address book: '.$url, ['app' => 'dav']); |
|
100 | 100 | throw $ex; |
101 | 101 | } |
102 | 102 | } |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | */ |
170 | 170 | protected function getClient($url, $userName, $sharedSecret) { |
171 | 171 | $settings = [ |
172 | - 'baseUri' => $url . '/', |
|
172 | + 'baseUri' => $url.'/', |
|
173 | 173 | 'userName' => $userName, |
174 | 174 | 'password' => $sharedSecret, |
175 | 175 | ]; |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | if (is_null($this->localSystemAddressBook)) { |
307 | 307 | $systemPrincipal = "principals/system/system"; |
308 | 308 | $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [ |
309 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
309 | + '{'.Plugin::NS_CARDDAV.'}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
310 | 310 | ]); |
311 | 311 | } |
312 | 312 | |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | |
316 | 316 | public function syncInstance(\Closure $progressCallback = null) { |
317 | 317 | $systemAddressBook = $this->getLocalSystemAddressBook(); |
318 | - $this->userManager->callForAllUsers(function ($user) use ($systemAddressBook, $progressCallback) { |
|
318 | + $this->userManager->callForAllUsers(function($user) use ($systemAddressBook, $progressCallback) { |
|
319 | 319 | $this->updateUser($user); |
320 | 320 | if (!is_null($progressCallback)) { |
321 | 321 | $progressCallback(); |
@@ -42,300 +42,300 @@ |
||
42 | 42 | |
43 | 43 | class SyncService { |
44 | 44 | |
45 | - /** @var CardDavBackend */ |
|
46 | - private $backend; |
|
47 | - |
|
48 | - /** @var IUserManager */ |
|
49 | - private $userManager; |
|
50 | - |
|
51 | - /** @var ILogger */ |
|
52 | - private $logger; |
|
53 | - |
|
54 | - /** @var array */ |
|
55 | - private $localSystemAddressBook; |
|
56 | - |
|
57 | - /** @var AccountManager */ |
|
58 | - private $accountManager; |
|
59 | - |
|
60 | - /** @var string */ |
|
61 | - protected $certPath; |
|
62 | - |
|
63 | - /** |
|
64 | - * SyncService constructor. |
|
65 | - * |
|
66 | - * @param CardDavBackend $backend |
|
67 | - * @param IUserManager $userManager |
|
68 | - * @param ILogger $logger |
|
69 | - * @param AccountManager $accountManager |
|
70 | - */ |
|
71 | - public function __construct(CardDavBackend $backend, IUserManager $userManager, ILogger $logger, AccountManager $accountManager) { |
|
72 | - $this->backend = $backend; |
|
73 | - $this->userManager = $userManager; |
|
74 | - $this->logger = $logger; |
|
75 | - $this->accountManager = $accountManager; |
|
76 | - $this->certPath = ''; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @param string $url |
|
81 | - * @param string $userName |
|
82 | - * @param string $addressBookUrl |
|
83 | - * @param string $sharedSecret |
|
84 | - * @param string $syncToken |
|
85 | - * @param int $targetBookId |
|
86 | - * @param string $targetPrincipal |
|
87 | - * @param array $targetProperties |
|
88 | - * @return string |
|
89 | - * @throws \Exception |
|
90 | - */ |
|
91 | - public function syncRemoteAddressBook($url, $userName, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetProperties) { |
|
92 | - // 1. create addressbook |
|
93 | - $book = $this->ensureSystemAddressBookExists($targetPrincipal, $targetBookId, $targetProperties); |
|
94 | - $addressBookId = $book['id']; |
|
95 | - |
|
96 | - // 2. query changes |
|
97 | - try { |
|
98 | - $response = $this->requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken); |
|
99 | - } catch (ClientHttpException $ex) { |
|
100 | - if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
|
101 | - // remote server revoked access to the address book, remove it |
|
102 | - $this->backend->deleteAddressBook($addressBookId); |
|
103 | - $this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']); |
|
104 | - throw $ex; |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - // 3. apply changes |
|
109 | - // TODO: use multi-get for download |
|
110 | - foreach ($response['response'] as $resource => $status) { |
|
111 | - $cardUri = basename($resource); |
|
112 | - if (isset($status[200])) { |
|
113 | - $vCard = $this->download($url, $userName, $sharedSecret, $resource); |
|
114 | - $existingCard = $this->backend->getCard($addressBookId, $cardUri); |
|
115 | - if ($existingCard === false) { |
|
116 | - $this->backend->createCard($addressBookId, $cardUri, $vCard['body']); |
|
117 | - } else { |
|
118 | - $this->backend->updateCard($addressBookId, $cardUri, $vCard['body']); |
|
119 | - } |
|
120 | - } else { |
|
121 | - $this->backend->deleteCard($addressBookId, $cardUri); |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - return $response['token']; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * @param string $principal |
|
130 | - * @param string $id |
|
131 | - * @param array $properties |
|
132 | - * @return array|null |
|
133 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
134 | - */ |
|
135 | - public function ensureSystemAddressBookExists($principal, $id, $properties) { |
|
136 | - $book = $this->backend->getAddressBooksByUri($principal, $id); |
|
137 | - if (!is_null($book)) { |
|
138 | - return $book; |
|
139 | - } |
|
140 | - $this->backend->createAddressBook($principal, $id, $properties); |
|
141 | - |
|
142 | - return $this->backend->getAddressBooksByUri($principal, $id); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Check if there is a valid certPath we should use |
|
147 | - * |
|
148 | - * @return string |
|
149 | - */ |
|
150 | - protected function getCertPath() { |
|
151 | - |
|
152 | - // we already have a valid certPath |
|
153 | - if ($this->certPath !== '') { |
|
154 | - return $this->certPath; |
|
155 | - } |
|
156 | - |
|
157 | - $certManager = \OC::$server->getCertificateManager(); |
|
158 | - $certPath = $certManager->getAbsoluteBundlePath(); |
|
159 | - if (file_exists($certPath)) { |
|
160 | - $this->certPath = $certPath; |
|
161 | - } |
|
162 | - |
|
163 | - return $this->certPath; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @param string $url |
|
168 | - * @param string $userName |
|
169 | - * @param string $addressBookUrl |
|
170 | - * @param string $sharedSecret |
|
171 | - * @return Client |
|
172 | - */ |
|
173 | - protected function getClient($url, $userName, $sharedSecret) { |
|
174 | - $settings = [ |
|
175 | - 'baseUri' => $url . '/', |
|
176 | - 'userName' => $userName, |
|
177 | - 'password' => $sharedSecret, |
|
178 | - ]; |
|
179 | - $client = new Client($settings); |
|
180 | - $certPath = $this->getCertPath(); |
|
181 | - $client->setThrowExceptions(true); |
|
182 | - |
|
183 | - if ($certPath !== '' && strpos($url, 'http://') !== 0) { |
|
184 | - $client->addCurlSetting(CURLOPT_CAINFO, $this->certPath); |
|
185 | - } |
|
186 | - |
|
187 | - return $client; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * @param string $url |
|
192 | - * @param string $userName |
|
193 | - * @param string $addressBookUrl |
|
194 | - * @param string $sharedSecret |
|
195 | - * @param string $syncToken |
|
196 | - * @return array |
|
197 | - */ |
|
198 | - protected function requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken) { |
|
199 | - $client = $this->getClient($url, $userName, $sharedSecret); |
|
200 | - |
|
201 | - $body = $this->buildSyncCollectionRequestBody($syncToken); |
|
202 | - |
|
203 | - $response = $client->request('REPORT', $addressBookUrl, $body, [ |
|
204 | - 'Content-Type' => 'application/xml' |
|
205 | - ]); |
|
206 | - |
|
207 | - return $this->parseMultiStatus($response['body']); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * @param string $url |
|
212 | - * @param string $userName |
|
213 | - * @param string $sharedSecret |
|
214 | - * @param string $resourcePath |
|
215 | - * @return array |
|
216 | - */ |
|
217 | - protected function download($url, $userName, $sharedSecret, $resourcePath) { |
|
218 | - $client = $this->getClient($url, $userName, $sharedSecret); |
|
219 | - return $client->request('GET', $resourcePath); |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * @param string|null $syncToken |
|
224 | - * @return string |
|
225 | - */ |
|
226 | - private function buildSyncCollectionRequestBody($syncToken) { |
|
227 | - $dom = new \DOMDocument('1.0', 'UTF-8'); |
|
228 | - $dom->formatOutput = true; |
|
229 | - $root = $dom->createElementNS('DAV:', 'd:sync-collection'); |
|
230 | - $sync = $dom->createElement('d:sync-token', $syncToken); |
|
231 | - $prop = $dom->createElement('d:prop'); |
|
232 | - $cont = $dom->createElement('d:getcontenttype'); |
|
233 | - $etag = $dom->createElement('d:getetag'); |
|
234 | - |
|
235 | - $prop->appendChild($cont); |
|
236 | - $prop->appendChild($etag); |
|
237 | - $root->appendChild($sync); |
|
238 | - $root->appendChild($prop); |
|
239 | - $dom->appendChild($root); |
|
240 | - return $dom->saveXML(); |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * @param string $body |
|
245 | - * @return array |
|
246 | - * @throws \Sabre\Xml\ParseException |
|
247 | - */ |
|
248 | - private function parseMultiStatus($body) { |
|
249 | - $xml = new Service(); |
|
250 | - |
|
251 | - /** @var MultiStatus $multiStatus */ |
|
252 | - $multiStatus = $xml->expect('{DAV:}multistatus', $body); |
|
253 | - |
|
254 | - $result = []; |
|
255 | - foreach ($multiStatus->getResponses() as $response) { |
|
256 | - $result[$response->getHref()] = $response->getResponseProperties(); |
|
257 | - } |
|
258 | - |
|
259 | - return ['response' => $result, 'token' => $multiStatus->getSyncToken()]; |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * @param IUser $user |
|
264 | - */ |
|
265 | - public function updateUser(IUser $user) { |
|
266 | - $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
267 | - $addressBookId = $systemAddressBook['id']; |
|
268 | - $converter = new Converter($this->accountManager); |
|
269 | - $name = $user->getBackendClassName(); |
|
270 | - $userId = $user->getUID(); |
|
271 | - |
|
272 | - $cardId = "$name:$userId.vcf"; |
|
273 | - $card = $this->backend->getCard($addressBookId, $cardId); |
|
274 | - if ($user->isEnabled()) { |
|
275 | - if ($card === false) { |
|
276 | - $vCard = $converter->createCardFromUser($user); |
|
277 | - if ($vCard !== null) { |
|
278 | - $this->backend->createCard($addressBookId, $cardId, $vCard->serialize()); |
|
279 | - } |
|
280 | - } else { |
|
281 | - $vCard = $converter->createCardFromUser($user); |
|
282 | - if (is_null($vCard)) { |
|
283 | - $this->backend->deleteCard($addressBookId, $cardId); |
|
284 | - } else { |
|
285 | - $this->backend->updateCard($addressBookId, $cardId, $vCard->serialize()); |
|
286 | - } |
|
287 | - } |
|
288 | - } else { |
|
289 | - $this->backend->deleteCard($addressBookId, $cardId); |
|
290 | - } |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * @param IUser|string $userOrCardId |
|
295 | - */ |
|
296 | - public function deleteUser($userOrCardId) { |
|
297 | - $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
298 | - if ($userOrCardId instanceof IUser) { |
|
299 | - $name = $userOrCardId->getBackendClassName(); |
|
300 | - $userId = $userOrCardId->getUID(); |
|
301 | - |
|
302 | - $userOrCardId = "$name:$userId.vcf"; |
|
303 | - } |
|
304 | - $this->backend->deleteCard($systemAddressBook['id'], $userOrCardId); |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * @return array|null |
|
309 | - */ |
|
310 | - public function getLocalSystemAddressBook() { |
|
311 | - if (is_null($this->localSystemAddressBook)) { |
|
312 | - $systemPrincipal = "principals/system/system"; |
|
313 | - $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [ |
|
314 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
315 | - ]); |
|
316 | - } |
|
317 | - |
|
318 | - return $this->localSystemAddressBook; |
|
319 | - } |
|
320 | - |
|
321 | - public function syncInstance(\Closure $progressCallback = null) { |
|
322 | - $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
323 | - $this->userManager->callForAllUsers(function ($user) use ($systemAddressBook, $progressCallback) { |
|
324 | - $this->updateUser($user); |
|
325 | - if (!is_null($progressCallback)) { |
|
326 | - $progressCallback(); |
|
327 | - } |
|
328 | - }); |
|
329 | - |
|
330 | - // remove no longer existing |
|
331 | - $allCards = $this->backend->getCards($systemAddressBook['id']); |
|
332 | - foreach ($allCards as $card) { |
|
333 | - $vCard = Reader::read($card['carddata']); |
|
334 | - $uid = $vCard->UID->getValue(); |
|
335 | - // load backend and see if user exists |
|
336 | - if (!$this->userManager->userExists($uid)) { |
|
337 | - $this->deleteUser($card['uri']); |
|
338 | - } |
|
339 | - } |
|
340 | - } |
|
45 | + /** @var CardDavBackend */ |
|
46 | + private $backend; |
|
47 | + |
|
48 | + /** @var IUserManager */ |
|
49 | + private $userManager; |
|
50 | + |
|
51 | + /** @var ILogger */ |
|
52 | + private $logger; |
|
53 | + |
|
54 | + /** @var array */ |
|
55 | + private $localSystemAddressBook; |
|
56 | + |
|
57 | + /** @var AccountManager */ |
|
58 | + private $accountManager; |
|
59 | + |
|
60 | + /** @var string */ |
|
61 | + protected $certPath; |
|
62 | + |
|
63 | + /** |
|
64 | + * SyncService constructor. |
|
65 | + * |
|
66 | + * @param CardDavBackend $backend |
|
67 | + * @param IUserManager $userManager |
|
68 | + * @param ILogger $logger |
|
69 | + * @param AccountManager $accountManager |
|
70 | + */ |
|
71 | + public function __construct(CardDavBackend $backend, IUserManager $userManager, ILogger $logger, AccountManager $accountManager) { |
|
72 | + $this->backend = $backend; |
|
73 | + $this->userManager = $userManager; |
|
74 | + $this->logger = $logger; |
|
75 | + $this->accountManager = $accountManager; |
|
76 | + $this->certPath = ''; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @param string $url |
|
81 | + * @param string $userName |
|
82 | + * @param string $addressBookUrl |
|
83 | + * @param string $sharedSecret |
|
84 | + * @param string $syncToken |
|
85 | + * @param int $targetBookId |
|
86 | + * @param string $targetPrincipal |
|
87 | + * @param array $targetProperties |
|
88 | + * @return string |
|
89 | + * @throws \Exception |
|
90 | + */ |
|
91 | + public function syncRemoteAddressBook($url, $userName, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetProperties) { |
|
92 | + // 1. create addressbook |
|
93 | + $book = $this->ensureSystemAddressBookExists($targetPrincipal, $targetBookId, $targetProperties); |
|
94 | + $addressBookId = $book['id']; |
|
95 | + |
|
96 | + // 2. query changes |
|
97 | + try { |
|
98 | + $response = $this->requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken); |
|
99 | + } catch (ClientHttpException $ex) { |
|
100 | + if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
|
101 | + // remote server revoked access to the address book, remove it |
|
102 | + $this->backend->deleteAddressBook($addressBookId); |
|
103 | + $this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']); |
|
104 | + throw $ex; |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + // 3. apply changes |
|
109 | + // TODO: use multi-get for download |
|
110 | + foreach ($response['response'] as $resource => $status) { |
|
111 | + $cardUri = basename($resource); |
|
112 | + if (isset($status[200])) { |
|
113 | + $vCard = $this->download($url, $userName, $sharedSecret, $resource); |
|
114 | + $existingCard = $this->backend->getCard($addressBookId, $cardUri); |
|
115 | + if ($existingCard === false) { |
|
116 | + $this->backend->createCard($addressBookId, $cardUri, $vCard['body']); |
|
117 | + } else { |
|
118 | + $this->backend->updateCard($addressBookId, $cardUri, $vCard['body']); |
|
119 | + } |
|
120 | + } else { |
|
121 | + $this->backend->deleteCard($addressBookId, $cardUri); |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + return $response['token']; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * @param string $principal |
|
130 | + * @param string $id |
|
131 | + * @param array $properties |
|
132 | + * @return array|null |
|
133 | + * @throws \Sabre\DAV\Exception\BadRequest |
|
134 | + */ |
|
135 | + public function ensureSystemAddressBookExists($principal, $id, $properties) { |
|
136 | + $book = $this->backend->getAddressBooksByUri($principal, $id); |
|
137 | + if (!is_null($book)) { |
|
138 | + return $book; |
|
139 | + } |
|
140 | + $this->backend->createAddressBook($principal, $id, $properties); |
|
141 | + |
|
142 | + return $this->backend->getAddressBooksByUri($principal, $id); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Check if there is a valid certPath we should use |
|
147 | + * |
|
148 | + * @return string |
|
149 | + */ |
|
150 | + protected function getCertPath() { |
|
151 | + |
|
152 | + // we already have a valid certPath |
|
153 | + if ($this->certPath !== '') { |
|
154 | + return $this->certPath; |
|
155 | + } |
|
156 | + |
|
157 | + $certManager = \OC::$server->getCertificateManager(); |
|
158 | + $certPath = $certManager->getAbsoluteBundlePath(); |
|
159 | + if (file_exists($certPath)) { |
|
160 | + $this->certPath = $certPath; |
|
161 | + } |
|
162 | + |
|
163 | + return $this->certPath; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @param string $url |
|
168 | + * @param string $userName |
|
169 | + * @param string $addressBookUrl |
|
170 | + * @param string $sharedSecret |
|
171 | + * @return Client |
|
172 | + */ |
|
173 | + protected function getClient($url, $userName, $sharedSecret) { |
|
174 | + $settings = [ |
|
175 | + 'baseUri' => $url . '/', |
|
176 | + 'userName' => $userName, |
|
177 | + 'password' => $sharedSecret, |
|
178 | + ]; |
|
179 | + $client = new Client($settings); |
|
180 | + $certPath = $this->getCertPath(); |
|
181 | + $client->setThrowExceptions(true); |
|
182 | + |
|
183 | + if ($certPath !== '' && strpos($url, 'http://') !== 0) { |
|
184 | + $client->addCurlSetting(CURLOPT_CAINFO, $this->certPath); |
|
185 | + } |
|
186 | + |
|
187 | + return $client; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * @param string $url |
|
192 | + * @param string $userName |
|
193 | + * @param string $addressBookUrl |
|
194 | + * @param string $sharedSecret |
|
195 | + * @param string $syncToken |
|
196 | + * @return array |
|
197 | + */ |
|
198 | + protected function requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken) { |
|
199 | + $client = $this->getClient($url, $userName, $sharedSecret); |
|
200 | + |
|
201 | + $body = $this->buildSyncCollectionRequestBody($syncToken); |
|
202 | + |
|
203 | + $response = $client->request('REPORT', $addressBookUrl, $body, [ |
|
204 | + 'Content-Type' => 'application/xml' |
|
205 | + ]); |
|
206 | + |
|
207 | + return $this->parseMultiStatus($response['body']); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * @param string $url |
|
212 | + * @param string $userName |
|
213 | + * @param string $sharedSecret |
|
214 | + * @param string $resourcePath |
|
215 | + * @return array |
|
216 | + */ |
|
217 | + protected function download($url, $userName, $sharedSecret, $resourcePath) { |
|
218 | + $client = $this->getClient($url, $userName, $sharedSecret); |
|
219 | + return $client->request('GET', $resourcePath); |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * @param string|null $syncToken |
|
224 | + * @return string |
|
225 | + */ |
|
226 | + private function buildSyncCollectionRequestBody($syncToken) { |
|
227 | + $dom = new \DOMDocument('1.0', 'UTF-8'); |
|
228 | + $dom->formatOutput = true; |
|
229 | + $root = $dom->createElementNS('DAV:', 'd:sync-collection'); |
|
230 | + $sync = $dom->createElement('d:sync-token', $syncToken); |
|
231 | + $prop = $dom->createElement('d:prop'); |
|
232 | + $cont = $dom->createElement('d:getcontenttype'); |
|
233 | + $etag = $dom->createElement('d:getetag'); |
|
234 | + |
|
235 | + $prop->appendChild($cont); |
|
236 | + $prop->appendChild($etag); |
|
237 | + $root->appendChild($sync); |
|
238 | + $root->appendChild($prop); |
|
239 | + $dom->appendChild($root); |
|
240 | + return $dom->saveXML(); |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * @param string $body |
|
245 | + * @return array |
|
246 | + * @throws \Sabre\Xml\ParseException |
|
247 | + */ |
|
248 | + private function parseMultiStatus($body) { |
|
249 | + $xml = new Service(); |
|
250 | + |
|
251 | + /** @var MultiStatus $multiStatus */ |
|
252 | + $multiStatus = $xml->expect('{DAV:}multistatus', $body); |
|
253 | + |
|
254 | + $result = []; |
|
255 | + foreach ($multiStatus->getResponses() as $response) { |
|
256 | + $result[$response->getHref()] = $response->getResponseProperties(); |
|
257 | + } |
|
258 | + |
|
259 | + return ['response' => $result, 'token' => $multiStatus->getSyncToken()]; |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * @param IUser $user |
|
264 | + */ |
|
265 | + public function updateUser(IUser $user) { |
|
266 | + $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
267 | + $addressBookId = $systemAddressBook['id']; |
|
268 | + $converter = new Converter($this->accountManager); |
|
269 | + $name = $user->getBackendClassName(); |
|
270 | + $userId = $user->getUID(); |
|
271 | + |
|
272 | + $cardId = "$name:$userId.vcf"; |
|
273 | + $card = $this->backend->getCard($addressBookId, $cardId); |
|
274 | + if ($user->isEnabled()) { |
|
275 | + if ($card === false) { |
|
276 | + $vCard = $converter->createCardFromUser($user); |
|
277 | + if ($vCard !== null) { |
|
278 | + $this->backend->createCard($addressBookId, $cardId, $vCard->serialize()); |
|
279 | + } |
|
280 | + } else { |
|
281 | + $vCard = $converter->createCardFromUser($user); |
|
282 | + if (is_null($vCard)) { |
|
283 | + $this->backend->deleteCard($addressBookId, $cardId); |
|
284 | + } else { |
|
285 | + $this->backend->updateCard($addressBookId, $cardId, $vCard->serialize()); |
|
286 | + } |
|
287 | + } |
|
288 | + } else { |
|
289 | + $this->backend->deleteCard($addressBookId, $cardId); |
|
290 | + } |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * @param IUser|string $userOrCardId |
|
295 | + */ |
|
296 | + public function deleteUser($userOrCardId) { |
|
297 | + $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
298 | + if ($userOrCardId instanceof IUser) { |
|
299 | + $name = $userOrCardId->getBackendClassName(); |
|
300 | + $userId = $userOrCardId->getUID(); |
|
301 | + |
|
302 | + $userOrCardId = "$name:$userId.vcf"; |
|
303 | + } |
|
304 | + $this->backend->deleteCard($systemAddressBook['id'], $userOrCardId); |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * @return array|null |
|
309 | + */ |
|
310 | + public function getLocalSystemAddressBook() { |
|
311 | + if (is_null($this->localSystemAddressBook)) { |
|
312 | + $systemPrincipal = "principals/system/system"; |
|
313 | + $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [ |
|
314 | + '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
315 | + ]); |
|
316 | + } |
|
317 | + |
|
318 | + return $this->localSystemAddressBook; |
|
319 | + } |
|
320 | + |
|
321 | + public function syncInstance(\Closure $progressCallback = null) { |
|
322 | + $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
323 | + $this->userManager->callForAllUsers(function ($user) use ($systemAddressBook, $progressCallback) { |
|
324 | + $this->updateUser($user); |
|
325 | + if (!is_null($progressCallback)) { |
|
326 | + $progressCallback(); |
|
327 | + } |
|
328 | + }); |
|
329 | + |
|
330 | + // remove no longer existing |
|
331 | + $allCards = $this->backend->getCards($systemAddressBook['id']); |
|
332 | + foreach ($allCards as $card) { |
|
333 | + $vCard = Reader::read($card['carddata']); |
|
334 | + $uid = $vCard->UID->getValue(); |
|
335 | + // load backend and see if user exists |
|
336 | + if (!$this->userManager->userExists($uid)) { |
|
337 | + $this->deleteUser($card['uri']); |
|
338 | + } |
|
339 | + } |
|
340 | + } |
|
341 | 341 | } |
@@ -29,47 +29,47 @@ |
||
29 | 29 | */ |
30 | 30 | interface IShareable extends INode { |
31 | 31 | |
32 | - /** |
|
33 | - * Updates the list of shares. |
|
34 | - * |
|
35 | - * The first array is a list of people that are to be added to the |
|
36 | - * resource. |
|
37 | - * |
|
38 | - * Every element in the add array has the following properties: |
|
39 | - * * href - A url. Usually a mailto: address |
|
40 | - * * commonName - Usually a first and last name, or false |
|
41 | - * * summary - A description of the share, can also be false |
|
42 | - * * readOnly - A boolean value |
|
43 | - * |
|
44 | - * Every element in the remove array is just the address string. |
|
45 | - * |
|
46 | - * @param array $add |
|
47 | - * @param array $remove |
|
48 | - * @return void |
|
49 | - */ |
|
50 | - public function updateShares(array $add, array $remove); |
|
32 | + /** |
|
33 | + * Updates the list of shares. |
|
34 | + * |
|
35 | + * The first array is a list of people that are to be added to the |
|
36 | + * resource. |
|
37 | + * |
|
38 | + * Every element in the add array has the following properties: |
|
39 | + * * href - A url. Usually a mailto: address |
|
40 | + * * commonName - Usually a first and last name, or false |
|
41 | + * * summary - A description of the share, can also be false |
|
42 | + * * readOnly - A boolean value |
|
43 | + * |
|
44 | + * Every element in the remove array is just the address string. |
|
45 | + * |
|
46 | + * @param array $add |
|
47 | + * @param array $remove |
|
48 | + * @return void |
|
49 | + */ |
|
50 | + public function updateShares(array $add, array $remove); |
|
51 | 51 | |
52 | - /** |
|
53 | - * Returns the list of people whom this resource is shared with. |
|
54 | - * |
|
55 | - * Every element in this array should have the following properties: |
|
56 | - * * href - Often a mailto: address |
|
57 | - * * commonName - Optional, for example a first + last name |
|
58 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
59 | - * * readOnly - boolean |
|
60 | - * * summary - Optional, a description for the share |
|
61 | - * |
|
62 | - * @return array |
|
63 | - */ |
|
64 | - public function getShares(); |
|
52 | + /** |
|
53 | + * Returns the list of people whom this resource is shared with. |
|
54 | + * |
|
55 | + * Every element in this array should have the following properties: |
|
56 | + * * href - Often a mailto: address |
|
57 | + * * commonName - Optional, for example a first + last name |
|
58 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
59 | + * * readOnly - boolean |
|
60 | + * * summary - Optional, a description for the share |
|
61 | + * |
|
62 | + * @return array |
|
63 | + */ |
|
64 | + public function getShares(); |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return int |
|
68 | - */ |
|
69 | - public function getResourceId(); |
|
66 | + /** |
|
67 | + * @return int |
|
68 | + */ |
|
69 | + public function getResourceId(); |
|
70 | 70 | |
71 | - /** |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - public function getOwner(); |
|
71 | + /** |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + public function getOwner(); |
|
75 | 75 | } |