@@ -26,67 +26,67 @@ |
||
26 | 26 | |
27 | 27 | class PublicAuth implements BackendInterface { |
28 | 28 | |
29 | - /** @var string[] */ |
|
30 | - private $publicURLs; |
|
29 | + /** @var string[] */ |
|
30 | + private $publicURLs; |
|
31 | 31 | |
32 | - public function __construct() { |
|
33 | - $this->publicURLs = [ |
|
34 | - 'public-calendars', |
|
35 | - 'principals/system/public' |
|
36 | - ]; |
|
37 | - } |
|
32 | + public function __construct() { |
|
33 | + $this->publicURLs = [ |
|
34 | + 'public-calendars', |
|
35 | + 'principals/system/public' |
|
36 | + ]; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * When this method is called, the backend must check if authentication was |
|
41 | - * successful. |
|
42 | - * |
|
43 | - * The returned value must be one of the following |
|
44 | - * |
|
45 | - * [true, "principals/username"] |
|
46 | - * [false, "reason for failure"] |
|
47 | - * |
|
48 | - * If authentication was successful, it's expected that the authentication |
|
49 | - * backend returns a so-called principal url. |
|
50 | - * |
|
51 | - * Examples of a principal url: |
|
52 | - * |
|
53 | - * principals/admin |
|
54 | - * principals/user1 |
|
55 | - * principals/users/joe |
|
56 | - * principals/uid/123457 |
|
57 | - * |
|
58 | - * If you don't use WebDAV ACL (RFC3744) we recommend that you simply |
|
59 | - * return a string such as: |
|
60 | - * |
|
61 | - * principals/users/[username] |
|
62 | - * |
|
63 | - * @param RequestInterface $request |
|
64 | - * @param ResponseInterface $response |
|
65 | - * @return array |
|
66 | - */ |
|
67 | - function check(RequestInterface $request, ResponseInterface $response) { |
|
39 | + /** |
|
40 | + * When this method is called, the backend must check if authentication was |
|
41 | + * successful. |
|
42 | + * |
|
43 | + * The returned value must be one of the following |
|
44 | + * |
|
45 | + * [true, "principals/username"] |
|
46 | + * [false, "reason for failure"] |
|
47 | + * |
|
48 | + * If authentication was successful, it's expected that the authentication |
|
49 | + * backend returns a so-called principal url. |
|
50 | + * |
|
51 | + * Examples of a principal url: |
|
52 | + * |
|
53 | + * principals/admin |
|
54 | + * principals/user1 |
|
55 | + * principals/users/joe |
|
56 | + * principals/uid/123457 |
|
57 | + * |
|
58 | + * If you don't use WebDAV ACL (RFC3744) we recommend that you simply |
|
59 | + * return a string such as: |
|
60 | + * |
|
61 | + * principals/users/[username] |
|
62 | + * |
|
63 | + * @param RequestInterface $request |
|
64 | + * @param ResponseInterface $response |
|
65 | + * @return array |
|
66 | + */ |
|
67 | + function check(RequestInterface $request, ResponseInterface $response) { |
|
68 | 68 | |
69 | - if ($this->isRequestPublic($request)) { |
|
70 | - return [true, "principals/system/public"]; |
|
71 | - } |
|
72 | - return [false, "No public access to this resource."]; |
|
73 | - } |
|
69 | + if ($this->isRequestPublic($request)) { |
|
70 | + return [true, "principals/system/public"]; |
|
71 | + } |
|
72 | + return [false, "No public access to this resource."]; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @inheritdoc |
|
77 | - */ |
|
78 | - function challenge(RequestInterface $request, ResponseInterface $response) { |
|
79 | - } |
|
75 | + /** |
|
76 | + * @inheritdoc |
|
77 | + */ |
|
78 | + function challenge(RequestInterface $request, ResponseInterface $response) { |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @param RequestInterface $request |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - private function isRequestPublic(RequestInterface $request) { |
|
86 | - $url = $request->getPath(); |
|
87 | - $matchingUrls = array_filter($this->publicURLs, function ($publicUrl) use ($url) { |
|
88 | - return strpos($url, $publicUrl, 0) === 0; |
|
89 | - }); |
|
90 | - return !empty($matchingUrls); |
|
91 | - } |
|
81 | + /** |
|
82 | + * @param RequestInterface $request |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + private function isRequestPublic(RequestInterface $request) { |
|
86 | + $url = $request->getPath(); |
|
87 | + $matchingUrls = array_filter($this->publicURLs, function ($publicUrl) use ($url) { |
|
88 | + return strpos($url, $publicUrl, 0) === 0; |
|
89 | + }); |
|
90 | + return !empty($matchingUrls); |
|
91 | + } |
|
92 | 92 | } |
@@ -84,7 +84,7 @@ |
||
84 | 84 | */ |
85 | 85 | private function isRequestPublic(RequestInterface $request) { |
86 | 86 | $url = $request->getPath(); |
87 | - $matchingUrls = array_filter($this->publicURLs, function ($publicUrl) use ($url) { |
|
87 | + $matchingUrls = array_filter($this->publicURLs, function($publicUrl) use ($url) { |
|
88 | 88 | return strpos($url, $publicUrl, 0) === 0; |
89 | 89 | }); |
90 | 90 | return !empty($matchingUrls); |
@@ -41,130 +41,130 @@ |
||
41 | 41 | */ |
42 | 42 | class Invite implements XmlSerializable { |
43 | 43 | |
44 | - /** |
|
45 | - * The list of users a calendar has been shared to. |
|
46 | - * |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - protected $users; |
|
50 | - |
|
51 | - /** |
|
52 | - * The organizer contains information about the person who shared the |
|
53 | - * object. |
|
54 | - * |
|
55 | - * @var array|null |
|
56 | - */ |
|
57 | - protected $organizer; |
|
58 | - |
|
59 | - /** |
|
60 | - * Creates the property. |
|
61 | - * |
|
62 | - * Users is an array. Each element of the array has the following |
|
63 | - * properties: |
|
64 | - * |
|
65 | - * * href - Often a mailto: address |
|
66 | - * * commonName - Optional, for example a first and lastname for a user. |
|
67 | - * * status - One of the SharingPlugin::STATUS_* constants. |
|
68 | - * * readOnly - true or false |
|
69 | - * * summary - Optional, description of the share |
|
70 | - * |
|
71 | - * The organizer key is optional to specify. It's only useful when a |
|
72 | - * 'sharee' requests the sharing information. |
|
73 | - * |
|
74 | - * The organizer may have the following properties: |
|
75 | - * * href - Often a mailto: address. |
|
76 | - * * commonName - Optional human-readable name. |
|
77 | - * * firstName - Optional first name. |
|
78 | - * * lastName - Optional last name. |
|
79 | - * |
|
80 | - * If you wonder why these two structures are so different, I guess a |
|
81 | - * valid answer is that the current spec is still a draft. |
|
82 | - * |
|
83 | - * @param array $users |
|
84 | - */ |
|
85 | - function __construct(array $users, array $organizer = null) { |
|
86 | - |
|
87 | - $this->users = $users; |
|
88 | - $this->organizer = $organizer; |
|
89 | - |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Returns the list of users, as it was passed to the constructor. |
|
94 | - * |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - function getValue() { |
|
98 | - |
|
99 | - return $this->users; |
|
100 | - |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * The xmlSerialize metod is called during xml writing. |
|
105 | - * |
|
106 | - * Use the $writer argument to write its own xml serialization. |
|
107 | - * |
|
108 | - * An important note: do _not_ create a parent element. Any element |
|
109 | - * implementing XmlSerializble should only ever write what's considered |
|
110 | - * its 'inner xml'. |
|
111 | - * |
|
112 | - * The parent of the current element is responsible for writing a |
|
113 | - * containing element. |
|
114 | - * |
|
115 | - * This allows serializers to be re-used for different element names. |
|
116 | - * |
|
117 | - * If you are opening new elements, you must also close them again. |
|
118 | - * |
|
119 | - * @param Writer $writer |
|
120 | - * @return void |
|
121 | - */ |
|
122 | - function xmlSerialize(Writer $writer) { |
|
123 | - |
|
124 | - $cs = '{' . Plugin::NS_OWNCLOUD . '}'; |
|
125 | - |
|
126 | - if (!is_null($this->organizer)) { |
|
127 | - |
|
128 | - $writer->startElement($cs . 'organizer'); |
|
129 | - $writer->writeElement('{DAV:}href', $this->organizer['href']); |
|
130 | - |
|
131 | - if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
|
132 | - $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
133 | - } |
|
134 | - if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
|
135 | - $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
136 | - } |
|
137 | - if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
|
138 | - $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
139 | - } |
|
140 | - $writer->endElement(); // organizer |
|
141 | - |
|
142 | - } |
|
143 | - |
|
144 | - foreach ($this->users as $user) { |
|
145 | - |
|
146 | - $writer->startElement($cs . 'user'); |
|
147 | - $writer->writeElement('{DAV:}href', $user['href']); |
|
148 | - if (isset($user['commonName']) && $user['commonName']) { |
|
149 | - $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
150 | - } |
|
151 | - $writer->writeElement($cs . 'invite-accepted'); |
|
152 | - |
|
153 | - $writer->startElement($cs . 'access'); |
|
154 | - if ($user['readOnly']) { |
|
155 | - $writer->writeElement($cs . 'read'); |
|
156 | - } else { |
|
157 | - $writer->writeElement($cs . 'read-write'); |
|
158 | - } |
|
159 | - $writer->endElement(); // access |
|
160 | - |
|
161 | - if (isset($user['summary']) && $user['summary']) { |
|
162 | - $writer->writeElement($cs . 'summary', $user['summary']); |
|
163 | - } |
|
164 | - |
|
165 | - $writer->endElement(); //user |
|
166 | - |
|
167 | - } |
|
168 | - |
|
169 | - } |
|
44 | + /** |
|
45 | + * The list of users a calendar has been shared to. |
|
46 | + * |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + protected $users; |
|
50 | + |
|
51 | + /** |
|
52 | + * The organizer contains information about the person who shared the |
|
53 | + * object. |
|
54 | + * |
|
55 | + * @var array|null |
|
56 | + */ |
|
57 | + protected $organizer; |
|
58 | + |
|
59 | + /** |
|
60 | + * Creates the property. |
|
61 | + * |
|
62 | + * Users is an array. Each element of the array has the following |
|
63 | + * properties: |
|
64 | + * |
|
65 | + * * href - Often a mailto: address |
|
66 | + * * commonName - Optional, for example a first and lastname for a user. |
|
67 | + * * status - One of the SharingPlugin::STATUS_* constants. |
|
68 | + * * readOnly - true or false |
|
69 | + * * summary - Optional, description of the share |
|
70 | + * |
|
71 | + * The organizer key is optional to specify. It's only useful when a |
|
72 | + * 'sharee' requests the sharing information. |
|
73 | + * |
|
74 | + * The organizer may have the following properties: |
|
75 | + * * href - Often a mailto: address. |
|
76 | + * * commonName - Optional human-readable name. |
|
77 | + * * firstName - Optional first name. |
|
78 | + * * lastName - Optional last name. |
|
79 | + * |
|
80 | + * If you wonder why these two structures are so different, I guess a |
|
81 | + * valid answer is that the current spec is still a draft. |
|
82 | + * |
|
83 | + * @param array $users |
|
84 | + */ |
|
85 | + function __construct(array $users, array $organizer = null) { |
|
86 | + |
|
87 | + $this->users = $users; |
|
88 | + $this->organizer = $organizer; |
|
89 | + |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Returns the list of users, as it was passed to the constructor. |
|
94 | + * |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + function getValue() { |
|
98 | + |
|
99 | + return $this->users; |
|
100 | + |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * The xmlSerialize metod is called during xml writing. |
|
105 | + * |
|
106 | + * Use the $writer argument to write its own xml serialization. |
|
107 | + * |
|
108 | + * An important note: do _not_ create a parent element. Any element |
|
109 | + * implementing XmlSerializble should only ever write what's considered |
|
110 | + * its 'inner xml'. |
|
111 | + * |
|
112 | + * The parent of the current element is responsible for writing a |
|
113 | + * containing element. |
|
114 | + * |
|
115 | + * This allows serializers to be re-used for different element names. |
|
116 | + * |
|
117 | + * If you are opening new elements, you must also close them again. |
|
118 | + * |
|
119 | + * @param Writer $writer |
|
120 | + * @return void |
|
121 | + */ |
|
122 | + function xmlSerialize(Writer $writer) { |
|
123 | + |
|
124 | + $cs = '{' . Plugin::NS_OWNCLOUD . '}'; |
|
125 | + |
|
126 | + if (!is_null($this->organizer)) { |
|
127 | + |
|
128 | + $writer->startElement($cs . 'organizer'); |
|
129 | + $writer->writeElement('{DAV:}href', $this->organizer['href']); |
|
130 | + |
|
131 | + if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
|
132 | + $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
133 | + } |
|
134 | + if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
|
135 | + $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
136 | + } |
|
137 | + if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
|
138 | + $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
139 | + } |
|
140 | + $writer->endElement(); // organizer |
|
141 | + |
|
142 | + } |
|
143 | + |
|
144 | + foreach ($this->users as $user) { |
|
145 | + |
|
146 | + $writer->startElement($cs . 'user'); |
|
147 | + $writer->writeElement('{DAV:}href', $user['href']); |
|
148 | + if (isset($user['commonName']) && $user['commonName']) { |
|
149 | + $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
150 | + } |
|
151 | + $writer->writeElement($cs . 'invite-accepted'); |
|
152 | + |
|
153 | + $writer->startElement($cs . 'access'); |
|
154 | + if ($user['readOnly']) { |
|
155 | + $writer->writeElement($cs . 'read'); |
|
156 | + } else { |
|
157 | + $writer->writeElement($cs . 'read-write'); |
|
158 | + } |
|
159 | + $writer->endElement(); // access |
|
160 | + |
|
161 | + if (isset($user['summary']) && $user['summary']) { |
|
162 | + $writer->writeElement($cs . 'summary', $user['summary']); |
|
163 | + } |
|
164 | + |
|
165 | + $writer->endElement(); //user |
|
166 | + |
|
167 | + } |
|
168 | + |
|
169 | + } |
|
170 | 170 | } |
@@ -121,21 +121,21 @@ discard block |
||
121 | 121 | */ |
122 | 122 | function xmlSerialize(Writer $writer) { |
123 | 123 | |
124 | - $cs = '{' . Plugin::NS_OWNCLOUD . '}'; |
|
124 | + $cs = '{'.Plugin::NS_OWNCLOUD.'}'; |
|
125 | 125 | |
126 | 126 | if (!is_null($this->organizer)) { |
127 | 127 | |
128 | - $writer->startElement($cs . 'organizer'); |
|
128 | + $writer->startElement($cs.'organizer'); |
|
129 | 129 | $writer->writeElement('{DAV:}href', $this->organizer['href']); |
130 | 130 | |
131 | 131 | if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
132 | - $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
132 | + $writer->writeElement($cs.'common-name', $this->organizer['commonName']); |
|
133 | 133 | } |
134 | 134 | if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
135 | - $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
135 | + $writer->writeElement($cs.'first-name', $this->organizer['firstName']); |
|
136 | 136 | } |
137 | 137 | if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
138 | - $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
138 | + $writer->writeElement($cs.'last-name', $this->organizer['lastName']); |
|
139 | 139 | } |
140 | 140 | $writer->endElement(); // organizer |
141 | 141 | |
@@ -143,23 +143,23 @@ discard block |
||
143 | 143 | |
144 | 144 | foreach ($this->users as $user) { |
145 | 145 | |
146 | - $writer->startElement($cs . 'user'); |
|
146 | + $writer->startElement($cs.'user'); |
|
147 | 147 | $writer->writeElement('{DAV:}href', $user['href']); |
148 | 148 | if (isset($user['commonName']) && $user['commonName']) { |
149 | - $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
149 | + $writer->writeElement($cs.'common-name', $user['commonName']); |
|
150 | 150 | } |
151 | - $writer->writeElement($cs . 'invite-accepted'); |
|
151 | + $writer->writeElement($cs.'invite-accepted'); |
|
152 | 152 | |
153 | - $writer->startElement($cs . 'access'); |
|
153 | + $writer->startElement($cs.'access'); |
|
154 | 154 | if ($user['readOnly']) { |
155 | - $writer->writeElement($cs . 'read'); |
|
155 | + $writer->writeElement($cs.'read'); |
|
156 | 156 | } else { |
157 | - $writer->writeElement($cs . 'read-write'); |
|
157 | + $writer->writeElement($cs.'read-write'); |
|
158 | 158 | } |
159 | 159 | $writer->endElement(); // access |
160 | 160 | |
161 | 161 | if (isset($user['summary']) && $user['summary']) { |
162 | - $writer->writeElement($cs . 'summary', $user['summary']); |
|
162 | + $writer->writeElement($cs.'summary', $user['summary']); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | $writer->endElement(); //user |
@@ -119,8 +119,9 @@ |
||
119 | 119 | |
120 | 120 | // Only handling xml |
121 | 121 | $contentType = $request->getHeader('Content-Type'); |
122 | - if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) |
|
123 | - return; |
|
122 | + if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { |
|
123 | + return; |
|
124 | + } |
|
124 | 125 | |
125 | 126 | // Making sure the node exists |
126 | 127 | try { |
@@ -38,167 +38,167 @@ |
||
38 | 38 | |
39 | 39 | class Plugin extends ServerPlugin { |
40 | 40 | |
41 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
42 | - const NS_NEXTCLOUD = 'http://nextcloud.com/ns'; |
|
43 | - |
|
44 | - /** @var Auth */ |
|
45 | - private $auth; |
|
46 | - |
|
47 | - /** @var IRequest */ |
|
48 | - private $request; |
|
49 | - |
|
50 | - /** |
|
51 | - * Plugin constructor. |
|
52 | - * |
|
53 | - * @param Auth $authBackEnd |
|
54 | - * @param IRequest $request |
|
55 | - */ |
|
56 | - public function __construct(Auth $authBackEnd, IRequest $request) { |
|
57 | - $this->auth = $authBackEnd; |
|
58 | - $this->request = $request; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Reference to SabreDAV server object. |
|
63 | - * |
|
64 | - * @var \Sabre\DAV\Server |
|
65 | - */ |
|
66 | - protected $server; |
|
67 | - |
|
68 | - /** |
|
69 | - * This method should return a list of server-features. |
|
70 | - * |
|
71 | - * This is for example 'versioning' and is added to the DAV: header |
|
72 | - * in an OPTIONS response. |
|
73 | - * |
|
74 | - * @return string[] |
|
75 | - */ |
|
76 | - function getFeatures() { |
|
77 | - return ['oc-resource-sharing']; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Returns a plugin name. |
|
82 | - * |
|
83 | - * Using this name other plugins will be able to access other plugins |
|
84 | - * using Sabre\DAV\Server::getPlugin |
|
85 | - * |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - function getPluginName() { |
|
89 | - return 'oc-resource-sharing'; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * This initializes the plugin. |
|
94 | - * |
|
95 | - * This function is called by Sabre\DAV\Server, after |
|
96 | - * addPlugin is called. |
|
97 | - * |
|
98 | - * This method should set up the required event subscriptions. |
|
99 | - * |
|
100 | - * @param Server $server |
|
101 | - * @return void |
|
102 | - */ |
|
103 | - function initialize(Server $server) { |
|
104 | - $this->server = $server; |
|
105 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = ShareRequest::class; |
|
106 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = Invite::class; |
|
107 | - |
|
108 | - $this->server->on('method:POST', [$this, 'httpPost']); |
|
109 | - $this->server->on('propFind', [$this, 'propFind']); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * We intercept this to handle POST requests on a dav resource. |
|
114 | - * |
|
115 | - * @param RequestInterface $request |
|
116 | - * @param ResponseInterface $response |
|
117 | - * @return null|false |
|
118 | - */ |
|
119 | - function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
120 | - |
|
121 | - $path = $request->getPath(); |
|
122 | - |
|
123 | - // Only handling xml |
|
124 | - $contentType = $request->getHeader('Content-Type'); |
|
125 | - if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) |
|
126 | - return; |
|
127 | - |
|
128 | - // Making sure the node exists |
|
129 | - try { |
|
130 | - $node = $this->server->tree->getNodeForPath($path); |
|
131 | - } catch (NotFound $e) { |
|
132 | - return; |
|
133 | - } |
|
134 | - |
|
135 | - $requestBody = $request->getBodyAsString(); |
|
136 | - |
|
137 | - // If this request handler could not deal with this POST request, it |
|
138 | - // will return 'null' and other plugins get a chance to handle the |
|
139 | - // request. |
|
140 | - // |
|
141 | - // However, we already requested the full body. This is a problem, |
|
142 | - // because a body can only be read once. This is why we preemptively |
|
143 | - // re-populated the request body with the existing data. |
|
144 | - $request->setBody($requestBody); |
|
145 | - |
|
146 | - $message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
147 | - |
|
148 | - switch ($documentType) { |
|
149 | - |
|
150 | - // Dealing with the 'share' document, which modified invitees on a |
|
151 | - // calendar. |
|
152 | - case '{' . self::NS_OWNCLOUD . '}share': |
|
153 | - |
|
154 | - // We can only deal with IShareableCalendar objects |
|
155 | - if (!$node instanceof IShareable) { |
|
156 | - return; |
|
157 | - } |
|
158 | - |
|
159 | - $this->server->transactionType = 'post-oc-resource-share'; |
|
160 | - |
|
161 | - // Getting ACL info |
|
162 | - $acl = $this->server->getPlugin('acl'); |
|
163 | - |
|
164 | - // If there's no ACL support, we allow everything |
|
165 | - if ($acl) { |
|
166 | - /** @var \Sabre\DAVACL\Plugin $acl */ |
|
167 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
168 | - } |
|
169 | - |
|
170 | - $node->updateShares($message->set, $message->remove); |
|
171 | - |
|
172 | - $response->setStatus(200); |
|
173 | - // Adding this because sending a response body may cause issues, |
|
174 | - // and I wanted some type of indicator the response was handled. |
|
175 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
176 | - |
|
177 | - // Breaking the event chain |
|
178 | - return false; |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * This event is triggered when properties are requested for a certain |
|
184 | - * node. |
|
185 | - * |
|
186 | - * This allows us to inject any properties early. |
|
187 | - * |
|
188 | - * @param PropFind $propFind |
|
189 | - * @param INode $node |
|
190 | - * @return void |
|
191 | - */ |
|
192 | - function propFind(PropFind $propFind, INode $node) { |
|
193 | - if ($node instanceof IShareable) { |
|
194 | - |
|
195 | - $propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function () use ($node) { |
|
196 | - return new Invite( |
|
197 | - $node->getShares() |
|
198 | - ); |
|
199 | - }); |
|
200 | - |
|
201 | - } |
|
202 | - } |
|
41 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
42 | + const NS_NEXTCLOUD = 'http://nextcloud.com/ns'; |
|
43 | + |
|
44 | + /** @var Auth */ |
|
45 | + private $auth; |
|
46 | + |
|
47 | + /** @var IRequest */ |
|
48 | + private $request; |
|
49 | + |
|
50 | + /** |
|
51 | + * Plugin constructor. |
|
52 | + * |
|
53 | + * @param Auth $authBackEnd |
|
54 | + * @param IRequest $request |
|
55 | + */ |
|
56 | + public function __construct(Auth $authBackEnd, IRequest $request) { |
|
57 | + $this->auth = $authBackEnd; |
|
58 | + $this->request = $request; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Reference to SabreDAV server object. |
|
63 | + * |
|
64 | + * @var \Sabre\DAV\Server |
|
65 | + */ |
|
66 | + protected $server; |
|
67 | + |
|
68 | + /** |
|
69 | + * This method should return a list of server-features. |
|
70 | + * |
|
71 | + * This is for example 'versioning' and is added to the DAV: header |
|
72 | + * in an OPTIONS response. |
|
73 | + * |
|
74 | + * @return string[] |
|
75 | + */ |
|
76 | + function getFeatures() { |
|
77 | + return ['oc-resource-sharing']; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Returns a plugin name. |
|
82 | + * |
|
83 | + * Using this name other plugins will be able to access other plugins |
|
84 | + * using Sabre\DAV\Server::getPlugin |
|
85 | + * |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + function getPluginName() { |
|
89 | + return 'oc-resource-sharing'; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * This initializes the plugin. |
|
94 | + * |
|
95 | + * This function is called by Sabre\DAV\Server, after |
|
96 | + * addPlugin is called. |
|
97 | + * |
|
98 | + * This method should set up the required event subscriptions. |
|
99 | + * |
|
100 | + * @param Server $server |
|
101 | + * @return void |
|
102 | + */ |
|
103 | + function initialize(Server $server) { |
|
104 | + $this->server = $server; |
|
105 | + $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = ShareRequest::class; |
|
106 | + $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = Invite::class; |
|
107 | + |
|
108 | + $this->server->on('method:POST', [$this, 'httpPost']); |
|
109 | + $this->server->on('propFind', [$this, 'propFind']); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * We intercept this to handle POST requests on a dav resource. |
|
114 | + * |
|
115 | + * @param RequestInterface $request |
|
116 | + * @param ResponseInterface $response |
|
117 | + * @return null|false |
|
118 | + */ |
|
119 | + function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
120 | + |
|
121 | + $path = $request->getPath(); |
|
122 | + |
|
123 | + // Only handling xml |
|
124 | + $contentType = $request->getHeader('Content-Type'); |
|
125 | + if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) |
|
126 | + return; |
|
127 | + |
|
128 | + // Making sure the node exists |
|
129 | + try { |
|
130 | + $node = $this->server->tree->getNodeForPath($path); |
|
131 | + } catch (NotFound $e) { |
|
132 | + return; |
|
133 | + } |
|
134 | + |
|
135 | + $requestBody = $request->getBodyAsString(); |
|
136 | + |
|
137 | + // If this request handler could not deal with this POST request, it |
|
138 | + // will return 'null' and other plugins get a chance to handle the |
|
139 | + // request. |
|
140 | + // |
|
141 | + // However, we already requested the full body. This is a problem, |
|
142 | + // because a body can only be read once. This is why we preemptively |
|
143 | + // re-populated the request body with the existing data. |
|
144 | + $request->setBody($requestBody); |
|
145 | + |
|
146 | + $message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
147 | + |
|
148 | + switch ($documentType) { |
|
149 | + |
|
150 | + // Dealing with the 'share' document, which modified invitees on a |
|
151 | + // calendar. |
|
152 | + case '{' . self::NS_OWNCLOUD . '}share': |
|
153 | + |
|
154 | + // We can only deal with IShareableCalendar objects |
|
155 | + if (!$node instanceof IShareable) { |
|
156 | + return; |
|
157 | + } |
|
158 | + |
|
159 | + $this->server->transactionType = 'post-oc-resource-share'; |
|
160 | + |
|
161 | + // Getting ACL info |
|
162 | + $acl = $this->server->getPlugin('acl'); |
|
163 | + |
|
164 | + // If there's no ACL support, we allow everything |
|
165 | + if ($acl) { |
|
166 | + /** @var \Sabre\DAVACL\Plugin $acl */ |
|
167 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
168 | + } |
|
169 | + |
|
170 | + $node->updateShares($message->set, $message->remove); |
|
171 | + |
|
172 | + $response->setStatus(200); |
|
173 | + // Adding this because sending a response body may cause issues, |
|
174 | + // and I wanted some type of indicator the response was handled. |
|
175 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
176 | + |
|
177 | + // Breaking the event chain |
|
178 | + return false; |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * This event is triggered when properties are requested for a certain |
|
184 | + * node. |
|
185 | + * |
|
186 | + * This allows us to inject any properties early. |
|
187 | + * |
|
188 | + * @param PropFind $propFind |
|
189 | + * @param INode $node |
|
190 | + * @return void |
|
191 | + */ |
|
192 | + function propFind(PropFind $propFind, INode $node) { |
|
193 | + if ($node instanceof IShareable) { |
|
194 | + |
|
195 | + $propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function () use ($node) { |
|
196 | + return new Invite( |
|
197 | + $node->getShares() |
|
198 | + ); |
|
199 | + }); |
|
200 | + |
|
201 | + } |
|
202 | + } |
|
203 | 203 | |
204 | 204 | } |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | */ |
103 | 103 | function initialize(Server $server) { |
104 | 104 | $this->server = $server; |
105 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = ShareRequest::class; |
|
106 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = Invite::class; |
|
105 | + $this->server->xml->elementMap['{'.Plugin::NS_OWNCLOUD.'}share'] = ShareRequest::class; |
|
106 | + $this->server->xml->elementMap['{'.Plugin::NS_OWNCLOUD.'}invite'] = Invite::class; |
|
107 | 107 | |
108 | 108 | $this->server->on('method:POST', [$this, 'httpPost']); |
109 | - $this->server->on('propFind', [$this, 'propFind']); |
|
109 | + $this->server->on('propFind', [$this, 'propFind']); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | |
150 | 150 | // Dealing with the 'share' document, which modified invitees on a |
151 | 151 | // calendar. |
152 | - case '{' . self::NS_OWNCLOUD . '}share': |
|
152 | + case '{'.self::NS_OWNCLOUD.'}share': |
|
153 | 153 | |
154 | 154 | // We can only deal with IShareableCalendar objects |
155 | 155 | if (!$node instanceof IShareable) { |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | function propFind(PropFind $propFind, INode $node) { |
193 | 193 | if ($node instanceof IShareable) { |
194 | 194 | |
195 | - $propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function () use ($node) { |
|
195 | + $propFind->handle('{'.Plugin::NS_OWNCLOUD.'}invite', function() use ($node) { |
|
196 | 196 | return new Invite( |
197 | 197 | $node->getShares() |
198 | 198 | ); |
@@ -43,85 +43,85 @@ |
||
43 | 43 | */ |
44 | 44 | class EntityTypeCollection extends RootCollection { |
45 | 45 | |
46 | - /** @var ILogger */ |
|
47 | - protected $logger; |
|
46 | + /** @var ILogger */ |
|
47 | + protected $logger; |
|
48 | 48 | |
49 | - /** @var IUserManager */ |
|
50 | - protected $userManager; |
|
49 | + /** @var IUserManager */ |
|
50 | + protected $userManager; |
|
51 | 51 | |
52 | - /** @var \Closure */ |
|
53 | - protected $childExistsFunction; |
|
52 | + /** @var \Closure */ |
|
53 | + protected $childExistsFunction; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @param string $name |
|
57 | - * @param ICommentsManager $commentsManager |
|
58 | - * @param IUserManager $userManager |
|
59 | - * @param IUserSession $userSession |
|
60 | - * @param ILogger $logger |
|
61 | - * @param \Closure $childExistsFunction |
|
62 | - */ |
|
63 | - public function __construct( |
|
64 | - $name, |
|
65 | - ICommentsManager $commentsManager, |
|
66 | - IUserManager $userManager, |
|
67 | - IUserSession $userSession, |
|
68 | - ILogger $logger, |
|
69 | - \Closure $childExistsFunction |
|
70 | - ) { |
|
71 | - $name = trim($name); |
|
72 | - if(empty($name) || !is_string($name)) { |
|
73 | - throw new \InvalidArgumentException('"name" parameter must be non-empty string'); |
|
74 | - } |
|
75 | - $this->name = $name; |
|
76 | - $this->commentsManager = $commentsManager; |
|
77 | - $this->logger = $logger; |
|
78 | - $this->userManager = $userManager; |
|
79 | - $this->userSession = $userSession; |
|
80 | - $this->childExistsFunction = $childExistsFunction; |
|
81 | - } |
|
55 | + /** |
|
56 | + * @param string $name |
|
57 | + * @param ICommentsManager $commentsManager |
|
58 | + * @param IUserManager $userManager |
|
59 | + * @param IUserSession $userSession |
|
60 | + * @param ILogger $logger |
|
61 | + * @param \Closure $childExistsFunction |
|
62 | + */ |
|
63 | + public function __construct( |
|
64 | + $name, |
|
65 | + ICommentsManager $commentsManager, |
|
66 | + IUserManager $userManager, |
|
67 | + IUserSession $userSession, |
|
68 | + ILogger $logger, |
|
69 | + \Closure $childExistsFunction |
|
70 | + ) { |
|
71 | + $name = trim($name); |
|
72 | + if(empty($name) || !is_string($name)) { |
|
73 | + throw new \InvalidArgumentException('"name" parameter must be non-empty string'); |
|
74 | + } |
|
75 | + $this->name = $name; |
|
76 | + $this->commentsManager = $commentsManager; |
|
77 | + $this->logger = $logger; |
|
78 | + $this->userManager = $userManager; |
|
79 | + $this->userSession = $userSession; |
|
80 | + $this->childExistsFunction = $childExistsFunction; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Returns a specific child node, referenced by its name |
|
85 | - * |
|
86 | - * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
87 | - * exist. |
|
88 | - * |
|
89 | - * @param string $name |
|
90 | - * @return \Sabre\DAV\INode |
|
91 | - * @throws NotFound |
|
92 | - */ |
|
93 | - function getChild($name) { |
|
94 | - if(!$this->childExists($name)) { |
|
95 | - throw new NotFound('Entity does not exist or is not available'); |
|
96 | - } |
|
97 | - return new EntityCollection( |
|
98 | - $name, |
|
99 | - $this->name, |
|
100 | - $this->commentsManager, |
|
101 | - $this->userManager, |
|
102 | - $this->userSession, |
|
103 | - $this->logger |
|
104 | - ); |
|
105 | - } |
|
83 | + /** |
|
84 | + * Returns a specific child node, referenced by its name |
|
85 | + * |
|
86 | + * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
87 | + * exist. |
|
88 | + * |
|
89 | + * @param string $name |
|
90 | + * @return \Sabre\DAV\INode |
|
91 | + * @throws NotFound |
|
92 | + */ |
|
93 | + function getChild($name) { |
|
94 | + if(!$this->childExists($name)) { |
|
95 | + throw new NotFound('Entity does not exist or is not available'); |
|
96 | + } |
|
97 | + return new EntityCollection( |
|
98 | + $name, |
|
99 | + $this->name, |
|
100 | + $this->commentsManager, |
|
101 | + $this->userManager, |
|
102 | + $this->userSession, |
|
103 | + $this->logger |
|
104 | + ); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * Returns an array with all the child nodes |
|
109 | - * |
|
110 | - * @return \Sabre\DAV\INode[] |
|
111 | - * @throws MethodNotAllowed |
|
112 | - */ |
|
113 | - function getChildren() { |
|
114 | - throw new MethodNotAllowed('No permission to list folder contents'); |
|
115 | - } |
|
107 | + /** |
|
108 | + * Returns an array with all the child nodes |
|
109 | + * |
|
110 | + * @return \Sabre\DAV\INode[] |
|
111 | + * @throws MethodNotAllowed |
|
112 | + */ |
|
113 | + function getChildren() { |
|
114 | + throw new MethodNotAllowed('No permission to list folder contents'); |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Checks if a child-node with the specified name exists |
|
119 | - * |
|
120 | - * @param string $name |
|
121 | - * @return bool |
|
122 | - */ |
|
123 | - function childExists($name) { |
|
124 | - return call_user_func($this->childExistsFunction, $name); |
|
125 | - } |
|
117 | + /** |
|
118 | + * Checks if a child-node with the specified name exists |
|
119 | + * |
|
120 | + * @param string $name |
|
121 | + * @return bool |
|
122 | + */ |
|
123 | + function childExists($name) { |
|
124 | + return call_user_func($this->childExistsFunction, $name); |
|
125 | + } |
|
126 | 126 | |
127 | 127 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | \Closure $childExistsFunction |
70 | 70 | ) { |
71 | 71 | $name = trim($name); |
72 | - if(empty($name) || !is_string($name)) { |
|
72 | + if (empty($name) || !is_string($name)) { |
|
73 | 73 | throw new \InvalidArgumentException('"name" parameter must be non-empty string'); |
74 | 74 | } |
75 | 75 | $this->name = $name; |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @throws NotFound |
92 | 92 | */ |
93 | 93 | function getChild($name) { |
94 | - if(!$this->childExists($name)) { |
|
94 | + if (!$this->childExists($name)) { |
|
95 | 95 | throw new NotFound('Entity does not exist or is not available'); |
96 | 96 | } |
97 | 97 | return new EntityCollection( |
@@ -36,177 +36,177 @@ |
||
36 | 36 | |
37 | 37 | class RootCollection implements ICollection { |
38 | 38 | |
39 | - /** @var EntityTypeCollection[]|null */ |
|
40 | - private $entityTypeCollections; |
|
41 | - |
|
42 | - /** @var ICommentsManager */ |
|
43 | - protected $commentsManager; |
|
44 | - |
|
45 | - /** @var string */ |
|
46 | - protected $name = 'comments'; |
|
47 | - |
|
48 | - /** @var ILogger */ |
|
49 | - protected $logger; |
|
50 | - |
|
51 | - /** @var IUserManager */ |
|
52 | - protected $userManager; |
|
53 | - |
|
54 | - /** @var IUserSession */ |
|
55 | - protected $userSession; |
|
56 | - |
|
57 | - /** @var EventDispatcherInterface */ |
|
58 | - protected $dispatcher; |
|
59 | - |
|
60 | - /** |
|
61 | - * @param ICommentsManager $commentsManager |
|
62 | - * @param IUserManager $userManager |
|
63 | - * @param IUserSession $userSession |
|
64 | - * @param EventDispatcherInterface $dispatcher |
|
65 | - * @param ILogger $logger |
|
66 | - */ |
|
67 | - public function __construct( |
|
68 | - ICommentsManager $commentsManager, |
|
69 | - IUserManager $userManager, |
|
70 | - IUserSession $userSession, |
|
71 | - EventDispatcherInterface $dispatcher, |
|
72 | - ILogger $logger) |
|
73 | - { |
|
74 | - $this->commentsManager = $commentsManager; |
|
75 | - $this->logger = $logger; |
|
76 | - $this->userManager = $userManager; |
|
77 | - $this->userSession = $userSession; |
|
78 | - $this->dispatcher = $dispatcher; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * initializes the collection. At this point of time, we need the logged in |
|
83 | - * user. Since it is not the case when the instance is created, we cannot |
|
84 | - * have this in the constructor. |
|
85 | - * |
|
86 | - * @throws NotAuthenticated |
|
87 | - */ |
|
88 | - protected function initCollections() { |
|
89 | - if($this->entityTypeCollections !== null) { |
|
90 | - return; |
|
91 | - } |
|
92 | - $user = $this->userSession->getUser(); |
|
93 | - if(is_null($user)) { |
|
94 | - throw new NotAuthenticated(); |
|
95 | - } |
|
96 | - |
|
97 | - $event = new CommentsEntityEvent(CommentsEntityEvent::EVENT_ENTITY); |
|
98 | - $this->dispatcher->dispatch(CommentsEntityEvent::EVENT_ENTITY, $event); |
|
99 | - |
|
100 | - $this->entityTypeCollections = []; |
|
101 | - foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) { |
|
102 | - $this->entityTypeCollections[$entity] = new EntityTypeCollection( |
|
103 | - $entity, |
|
104 | - $this->commentsManager, |
|
105 | - $this->userManager, |
|
106 | - $this->userSession, |
|
107 | - $this->logger, |
|
108 | - $entityExistsFunction |
|
109 | - ); |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Creates a new file in the directory |
|
115 | - * |
|
116 | - * @param string $name Name of the file |
|
117 | - * @param resource|string $data Initial payload |
|
118 | - * @return null|string |
|
119 | - * @throws Forbidden |
|
120 | - */ |
|
121 | - function createFile($name, $data = null) { |
|
122 | - throw new Forbidden('Cannot create comments by id'); |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Creates a new subdirectory |
|
127 | - * |
|
128 | - * @param string $name |
|
129 | - * @throws Forbidden |
|
130 | - */ |
|
131 | - function createDirectory($name) { |
|
132 | - throw new Forbidden('Permission denied to create collections'); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Returns a specific child node, referenced by its name |
|
137 | - * |
|
138 | - * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
139 | - * exist. |
|
140 | - * |
|
141 | - * @param string $name |
|
142 | - * @return \Sabre\DAV\INode |
|
143 | - * @throws NotFound |
|
144 | - */ |
|
145 | - function getChild($name) { |
|
146 | - $this->initCollections(); |
|
147 | - if(isset($this->entityTypeCollections[$name])) { |
|
148 | - return $this->entityTypeCollections[$name]; |
|
149 | - } |
|
150 | - throw new NotFound('Entity type "' . $name . '" not found."'); |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Returns an array with all the child nodes |
|
155 | - * |
|
156 | - * @return \Sabre\DAV\INode[] |
|
157 | - */ |
|
158 | - function getChildren() { |
|
159 | - $this->initCollections(); |
|
160 | - return $this->entityTypeCollections; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Checks if a child-node with the specified name exists |
|
165 | - * |
|
166 | - * @param string $name |
|
167 | - * @return bool |
|
168 | - */ |
|
169 | - function childExists($name) { |
|
170 | - $this->initCollections(); |
|
171 | - return isset($this->entityTypeCollections[$name]); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Deleted the current node |
|
176 | - * |
|
177 | - * @throws Forbidden |
|
178 | - */ |
|
179 | - function delete() { |
|
180 | - throw new Forbidden('Permission denied to delete this collection'); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Returns the name of the node. |
|
185 | - * |
|
186 | - * This is used to generate the url. |
|
187 | - * |
|
188 | - * @return string |
|
189 | - */ |
|
190 | - function getName() { |
|
191 | - return $this->name; |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Renames the node |
|
196 | - * |
|
197 | - * @param string $name The new name |
|
198 | - * @throws Forbidden |
|
199 | - */ |
|
200 | - function setName($name) { |
|
201 | - throw new Forbidden('Permission denied to rename this collection'); |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Returns the last modification time, as a unix timestamp |
|
206 | - * |
|
207 | - * @return int |
|
208 | - */ |
|
209 | - function getLastModified() { |
|
210 | - return null; |
|
211 | - } |
|
39 | + /** @var EntityTypeCollection[]|null */ |
|
40 | + private $entityTypeCollections; |
|
41 | + |
|
42 | + /** @var ICommentsManager */ |
|
43 | + protected $commentsManager; |
|
44 | + |
|
45 | + /** @var string */ |
|
46 | + protected $name = 'comments'; |
|
47 | + |
|
48 | + /** @var ILogger */ |
|
49 | + protected $logger; |
|
50 | + |
|
51 | + /** @var IUserManager */ |
|
52 | + protected $userManager; |
|
53 | + |
|
54 | + /** @var IUserSession */ |
|
55 | + protected $userSession; |
|
56 | + |
|
57 | + /** @var EventDispatcherInterface */ |
|
58 | + protected $dispatcher; |
|
59 | + |
|
60 | + /** |
|
61 | + * @param ICommentsManager $commentsManager |
|
62 | + * @param IUserManager $userManager |
|
63 | + * @param IUserSession $userSession |
|
64 | + * @param EventDispatcherInterface $dispatcher |
|
65 | + * @param ILogger $logger |
|
66 | + */ |
|
67 | + public function __construct( |
|
68 | + ICommentsManager $commentsManager, |
|
69 | + IUserManager $userManager, |
|
70 | + IUserSession $userSession, |
|
71 | + EventDispatcherInterface $dispatcher, |
|
72 | + ILogger $logger) |
|
73 | + { |
|
74 | + $this->commentsManager = $commentsManager; |
|
75 | + $this->logger = $logger; |
|
76 | + $this->userManager = $userManager; |
|
77 | + $this->userSession = $userSession; |
|
78 | + $this->dispatcher = $dispatcher; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * initializes the collection. At this point of time, we need the logged in |
|
83 | + * user. Since it is not the case when the instance is created, we cannot |
|
84 | + * have this in the constructor. |
|
85 | + * |
|
86 | + * @throws NotAuthenticated |
|
87 | + */ |
|
88 | + protected function initCollections() { |
|
89 | + if($this->entityTypeCollections !== null) { |
|
90 | + return; |
|
91 | + } |
|
92 | + $user = $this->userSession->getUser(); |
|
93 | + if(is_null($user)) { |
|
94 | + throw new NotAuthenticated(); |
|
95 | + } |
|
96 | + |
|
97 | + $event = new CommentsEntityEvent(CommentsEntityEvent::EVENT_ENTITY); |
|
98 | + $this->dispatcher->dispatch(CommentsEntityEvent::EVENT_ENTITY, $event); |
|
99 | + |
|
100 | + $this->entityTypeCollections = []; |
|
101 | + foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) { |
|
102 | + $this->entityTypeCollections[$entity] = new EntityTypeCollection( |
|
103 | + $entity, |
|
104 | + $this->commentsManager, |
|
105 | + $this->userManager, |
|
106 | + $this->userSession, |
|
107 | + $this->logger, |
|
108 | + $entityExistsFunction |
|
109 | + ); |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Creates a new file in the directory |
|
115 | + * |
|
116 | + * @param string $name Name of the file |
|
117 | + * @param resource|string $data Initial payload |
|
118 | + * @return null|string |
|
119 | + * @throws Forbidden |
|
120 | + */ |
|
121 | + function createFile($name, $data = null) { |
|
122 | + throw new Forbidden('Cannot create comments by id'); |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Creates a new subdirectory |
|
127 | + * |
|
128 | + * @param string $name |
|
129 | + * @throws Forbidden |
|
130 | + */ |
|
131 | + function createDirectory($name) { |
|
132 | + throw new Forbidden('Permission denied to create collections'); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Returns a specific child node, referenced by its name |
|
137 | + * |
|
138 | + * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
139 | + * exist. |
|
140 | + * |
|
141 | + * @param string $name |
|
142 | + * @return \Sabre\DAV\INode |
|
143 | + * @throws NotFound |
|
144 | + */ |
|
145 | + function getChild($name) { |
|
146 | + $this->initCollections(); |
|
147 | + if(isset($this->entityTypeCollections[$name])) { |
|
148 | + return $this->entityTypeCollections[$name]; |
|
149 | + } |
|
150 | + throw new NotFound('Entity type "' . $name . '" not found."'); |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Returns an array with all the child nodes |
|
155 | + * |
|
156 | + * @return \Sabre\DAV\INode[] |
|
157 | + */ |
|
158 | + function getChildren() { |
|
159 | + $this->initCollections(); |
|
160 | + return $this->entityTypeCollections; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Checks if a child-node with the specified name exists |
|
165 | + * |
|
166 | + * @param string $name |
|
167 | + * @return bool |
|
168 | + */ |
|
169 | + function childExists($name) { |
|
170 | + $this->initCollections(); |
|
171 | + return isset($this->entityTypeCollections[$name]); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Deleted the current node |
|
176 | + * |
|
177 | + * @throws Forbidden |
|
178 | + */ |
|
179 | + function delete() { |
|
180 | + throw new Forbidden('Permission denied to delete this collection'); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Returns the name of the node. |
|
185 | + * |
|
186 | + * This is used to generate the url. |
|
187 | + * |
|
188 | + * @return string |
|
189 | + */ |
|
190 | + function getName() { |
|
191 | + return $this->name; |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Renames the node |
|
196 | + * |
|
197 | + * @param string $name The new name |
|
198 | + * @throws Forbidden |
|
199 | + */ |
|
200 | + function setName($name) { |
|
201 | + throw new Forbidden('Permission denied to rename this collection'); |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Returns the last modification time, as a unix timestamp |
|
206 | + * |
|
207 | + * @return int |
|
208 | + */ |
|
209 | + function getLastModified() { |
|
210 | + return null; |
|
211 | + } |
|
212 | 212 | } |
@@ -86,11 +86,11 @@ discard block |
||
86 | 86 | * @throws NotAuthenticated |
87 | 87 | */ |
88 | 88 | protected function initCollections() { |
89 | - if($this->entityTypeCollections !== null) { |
|
89 | + if ($this->entityTypeCollections !== null) { |
|
90 | 90 | return; |
91 | 91 | } |
92 | 92 | $user = $this->userSession->getUser(); |
93 | - if(is_null($user)) { |
|
93 | + if (is_null($user)) { |
|
94 | 94 | throw new NotAuthenticated(); |
95 | 95 | } |
96 | 96 | |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | */ |
145 | 145 | function getChild($name) { |
146 | 146 | $this->initCollections(); |
147 | - if(isset($this->entityTypeCollections[$name])) { |
|
147 | + if (isset($this->entityTypeCollections[$name])) { |
|
148 | 148 | return $this->entityTypeCollections[$name]; |
149 | 149 | } |
150 | - throw new NotFound('Entity type "' . $name . '" not found."'); |
|
150 | + throw new NotFound('Entity type "'.$name.'" not found."'); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -41,156 +41,156 @@ |
||
41 | 41 | * @package OCA\DAV\Comments |
42 | 42 | */ |
43 | 43 | class EntityCollection extends RootCollection implements IProperties { |
44 | - const PROPERTY_NAME_READ_MARKER = '{http://owncloud.org/ns}readMarker'; |
|
44 | + const PROPERTY_NAME_READ_MARKER = '{http://owncloud.org/ns}readMarker'; |
|
45 | 45 | |
46 | - /** @var string */ |
|
47 | - protected $id; |
|
46 | + /** @var string */ |
|
47 | + protected $id; |
|
48 | 48 | |
49 | - /** @var ILogger */ |
|
50 | - protected $logger; |
|
49 | + /** @var ILogger */ |
|
50 | + protected $logger; |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param string $id |
|
54 | - * @param string $name |
|
55 | - * @param ICommentsManager $commentsManager |
|
56 | - * @param IUserManager $userManager |
|
57 | - * @param IUserSession $userSession |
|
58 | - * @param ILogger $logger |
|
59 | - */ |
|
60 | - public function __construct( |
|
61 | - $id, |
|
62 | - $name, |
|
63 | - ICommentsManager $commentsManager, |
|
64 | - IUserManager $userManager, |
|
65 | - IUserSession $userSession, |
|
66 | - ILogger $logger |
|
67 | - ) { |
|
68 | - foreach(['id', 'name'] as $property) { |
|
69 | - $$property = trim($$property); |
|
70 | - if(empty($$property) || !is_string($$property)) { |
|
71 | - throw new \InvalidArgumentException('"' . $property . '" parameter must be non-empty string'); |
|
72 | - } |
|
73 | - } |
|
74 | - $this->id = $id; |
|
75 | - $this->name = $name; |
|
76 | - $this->commentsManager = $commentsManager; |
|
77 | - $this->logger = $logger; |
|
78 | - $this->userManager = $userManager; |
|
79 | - $this->userSession = $userSession; |
|
80 | - } |
|
52 | + /** |
|
53 | + * @param string $id |
|
54 | + * @param string $name |
|
55 | + * @param ICommentsManager $commentsManager |
|
56 | + * @param IUserManager $userManager |
|
57 | + * @param IUserSession $userSession |
|
58 | + * @param ILogger $logger |
|
59 | + */ |
|
60 | + public function __construct( |
|
61 | + $id, |
|
62 | + $name, |
|
63 | + ICommentsManager $commentsManager, |
|
64 | + IUserManager $userManager, |
|
65 | + IUserSession $userSession, |
|
66 | + ILogger $logger |
|
67 | + ) { |
|
68 | + foreach(['id', 'name'] as $property) { |
|
69 | + $$property = trim($$property); |
|
70 | + if(empty($$property) || !is_string($$property)) { |
|
71 | + throw new \InvalidArgumentException('"' . $property . '" parameter must be non-empty string'); |
|
72 | + } |
|
73 | + } |
|
74 | + $this->id = $id; |
|
75 | + $this->name = $name; |
|
76 | + $this->commentsManager = $commentsManager; |
|
77 | + $this->logger = $logger; |
|
78 | + $this->userManager = $userManager; |
|
79 | + $this->userSession = $userSession; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * returns the ID of this entity |
|
84 | - * |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - public function getId() { |
|
88 | - return $this->id; |
|
89 | - } |
|
82 | + /** |
|
83 | + * returns the ID of this entity |
|
84 | + * |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + public function getId() { |
|
88 | + return $this->id; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Returns a specific child node, referenced by its name |
|
93 | - * |
|
94 | - * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
95 | - * exist. |
|
96 | - * |
|
97 | - * @param string $name |
|
98 | - * @return \Sabre\DAV\INode |
|
99 | - * @throws NotFound |
|
100 | - */ |
|
101 | - function getChild($name) { |
|
102 | - try { |
|
103 | - $comment = $this->commentsManager->get($name); |
|
104 | - return new CommentNode( |
|
105 | - $this->commentsManager, |
|
106 | - $comment, |
|
107 | - $this->userManager, |
|
108 | - $this->userSession, |
|
109 | - $this->logger |
|
110 | - ); |
|
111 | - } catch (NotFoundException $e) { |
|
112 | - throw new NotFound(); |
|
113 | - } |
|
114 | - } |
|
91 | + /** |
|
92 | + * Returns a specific child node, referenced by its name |
|
93 | + * |
|
94 | + * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
95 | + * exist. |
|
96 | + * |
|
97 | + * @param string $name |
|
98 | + * @return \Sabre\DAV\INode |
|
99 | + * @throws NotFound |
|
100 | + */ |
|
101 | + function getChild($name) { |
|
102 | + try { |
|
103 | + $comment = $this->commentsManager->get($name); |
|
104 | + return new CommentNode( |
|
105 | + $this->commentsManager, |
|
106 | + $comment, |
|
107 | + $this->userManager, |
|
108 | + $this->userSession, |
|
109 | + $this->logger |
|
110 | + ); |
|
111 | + } catch (NotFoundException $e) { |
|
112 | + throw new NotFound(); |
|
113 | + } |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * Returns an array with all the child nodes |
|
118 | - * |
|
119 | - * @return \Sabre\DAV\INode[] |
|
120 | - */ |
|
121 | - function getChildren() { |
|
122 | - return $this->findChildren(); |
|
123 | - } |
|
116 | + /** |
|
117 | + * Returns an array with all the child nodes |
|
118 | + * |
|
119 | + * @return \Sabre\DAV\INode[] |
|
120 | + */ |
|
121 | + function getChildren() { |
|
122 | + return $this->findChildren(); |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * Returns an array of comment nodes. Result can be influenced by offset, |
|
127 | - * limit and date time parameters. |
|
128 | - * |
|
129 | - * @param int $limit |
|
130 | - * @param int $offset |
|
131 | - * @param \DateTime|null $datetime |
|
132 | - * @return CommentNode[] |
|
133 | - */ |
|
134 | - function findChildren($limit = 0, $offset = 0, \DateTime $datetime = null) { |
|
135 | - $comments = $this->commentsManager->getForObject($this->name, $this->id, $limit, $offset, $datetime); |
|
136 | - $result = []; |
|
137 | - foreach($comments as $comment) { |
|
138 | - $result[] = new CommentNode( |
|
139 | - $this->commentsManager, |
|
140 | - $comment, |
|
141 | - $this->userManager, |
|
142 | - $this->userSession, |
|
143 | - $this->logger |
|
144 | - ); |
|
145 | - } |
|
146 | - return $result; |
|
147 | - } |
|
125 | + /** |
|
126 | + * Returns an array of comment nodes. Result can be influenced by offset, |
|
127 | + * limit and date time parameters. |
|
128 | + * |
|
129 | + * @param int $limit |
|
130 | + * @param int $offset |
|
131 | + * @param \DateTime|null $datetime |
|
132 | + * @return CommentNode[] |
|
133 | + */ |
|
134 | + function findChildren($limit = 0, $offset = 0, \DateTime $datetime = null) { |
|
135 | + $comments = $this->commentsManager->getForObject($this->name, $this->id, $limit, $offset, $datetime); |
|
136 | + $result = []; |
|
137 | + foreach($comments as $comment) { |
|
138 | + $result[] = new CommentNode( |
|
139 | + $this->commentsManager, |
|
140 | + $comment, |
|
141 | + $this->userManager, |
|
142 | + $this->userSession, |
|
143 | + $this->logger |
|
144 | + ); |
|
145 | + } |
|
146 | + return $result; |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * Checks if a child-node with the specified name exists |
|
151 | - * |
|
152 | - * @param string $name |
|
153 | - * @return bool |
|
154 | - */ |
|
155 | - function childExists($name) { |
|
156 | - try { |
|
157 | - $this->commentsManager->get($name); |
|
158 | - return true; |
|
159 | - } catch (NotFoundException $e) { |
|
160 | - return false; |
|
161 | - } |
|
162 | - } |
|
149 | + /** |
|
150 | + * Checks if a child-node with the specified name exists |
|
151 | + * |
|
152 | + * @param string $name |
|
153 | + * @return bool |
|
154 | + */ |
|
155 | + function childExists($name) { |
|
156 | + try { |
|
157 | + $this->commentsManager->get($name); |
|
158 | + return true; |
|
159 | + } catch (NotFoundException $e) { |
|
160 | + return false; |
|
161 | + } |
|
162 | + } |
|
163 | 163 | |
164 | - /** |
|
165 | - * Sets the read marker to the specified date for the logged in user |
|
166 | - * |
|
167 | - * @param \DateTime $value |
|
168 | - * @return bool |
|
169 | - */ |
|
170 | - public function setReadMarker($value) { |
|
171 | - $dateTime = new \DateTime($value); |
|
172 | - $user = $this->userSession->getUser(); |
|
173 | - $this->commentsManager->setReadMark($this->name, $this->id, $dateTime, $user); |
|
174 | - return true; |
|
175 | - } |
|
164 | + /** |
|
165 | + * Sets the read marker to the specified date for the logged in user |
|
166 | + * |
|
167 | + * @param \DateTime $value |
|
168 | + * @return bool |
|
169 | + */ |
|
170 | + public function setReadMarker($value) { |
|
171 | + $dateTime = new \DateTime($value); |
|
172 | + $user = $this->userSession->getUser(); |
|
173 | + $this->commentsManager->setReadMark($this->name, $this->id, $dateTime, $user); |
|
174 | + return true; |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * @inheritdoc |
|
179 | - */ |
|
180 | - function propPatch(PropPatch $propPatch) { |
|
181 | - $propPatch->handle(self::PROPERTY_NAME_READ_MARKER, [$this, 'setReadMarker']); |
|
182 | - } |
|
177 | + /** |
|
178 | + * @inheritdoc |
|
179 | + */ |
|
180 | + function propPatch(PropPatch $propPatch) { |
|
181 | + $propPatch->handle(self::PROPERTY_NAME_READ_MARKER, [$this, 'setReadMarker']); |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * @inheritdoc |
|
186 | - */ |
|
187 | - function getProperties($properties) { |
|
188 | - $marker = null; |
|
189 | - $user = $this->userSession->getUser(); |
|
190 | - if(!is_null($user)) { |
|
191 | - $marker = $this->commentsManager->getReadMark($this->name, $this->id, $user); |
|
192 | - } |
|
193 | - return [self::PROPERTY_NAME_READ_MARKER => $marker]; |
|
194 | - } |
|
184 | + /** |
|
185 | + * @inheritdoc |
|
186 | + */ |
|
187 | + function getProperties($properties) { |
|
188 | + $marker = null; |
|
189 | + $user = $this->userSession->getUser(); |
|
190 | + if(!is_null($user)) { |
|
191 | + $marker = $this->commentsManager->getReadMark($this->name, $this->id, $user); |
|
192 | + } |
|
193 | + return [self::PROPERTY_NAME_READ_MARKER => $marker]; |
|
194 | + } |
|
195 | 195 | } |
196 | 196 |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @package OCA\DAV\Comments |
42 | 42 | */ |
43 | 43 | class EntityCollection extends RootCollection implements IProperties { |
44 | - const PROPERTY_NAME_READ_MARKER = '{http://owncloud.org/ns}readMarker'; |
|
44 | + const PROPERTY_NAME_READ_MARKER = '{http://owncloud.org/ns}readMarker'; |
|
45 | 45 | |
46 | 46 | /** @var string */ |
47 | 47 | protected $id; |
@@ -65,10 +65,10 @@ discard block |
||
65 | 65 | IUserSession $userSession, |
66 | 66 | ILogger $logger |
67 | 67 | ) { |
68 | - foreach(['id', 'name'] as $property) { |
|
68 | + foreach (['id', 'name'] as $property) { |
|
69 | 69 | $$property = trim($$property); |
70 | - if(empty($$property) || !is_string($$property)) { |
|
71 | - throw new \InvalidArgumentException('"' . $property . '" parameter must be non-empty string'); |
|
70 | + if (empty($$property) || !is_string($$property)) { |
|
71 | + throw new \InvalidArgumentException('"'.$property.'" parameter must be non-empty string'); |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | $this->id = $id; |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | function findChildren($limit = 0, $offset = 0, \DateTime $datetime = null) { |
135 | 135 | $comments = $this->commentsManager->getForObject($this->name, $this->id, $limit, $offset, $datetime); |
136 | 136 | $result = []; |
137 | - foreach($comments as $comment) { |
|
137 | + foreach ($comments as $comment) { |
|
138 | 138 | $result[] = new CommentNode( |
139 | 139 | $this->commentsManager, |
140 | 140 | $comment, |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | function getProperties($properties) { |
188 | 188 | $marker = null; |
189 | 189 | $user = $this->userSession->getUser(); |
190 | - if(!is_null($user)) { |
|
190 | + if (!is_null($user)) { |
|
191 | 191 | $marker = $this->commentsManager->getReadMark($this->name, $this->id, $user); |
192 | 192 | } |
193 | 193 | return [self::PROPERTY_NAME_READ_MARKER => $marker]; |
@@ -100,13 +100,13 @@ |
||
100 | 100 | if ($this->shareManager->checkPassword($share, $password)) { |
101 | 101 | return true; |
102 | 102 | } else if ($this->session->exists('public_link_authenticated') |
103 | - && $this->session->get('public_link_authenticated') === (string)$share->getId()) { |
|
103 | + && $this->session->get('public_link_authenticated') === (string) $share->getId()) { |
|
104 | 104 | return true; |
105 | 105 | } else { |
106 | 106 | if (in_array('XMLHttpRequest', explode(',', $this->request->getHeader('X-Requested-With')))) { |
107 | 107 | // do not re-authenticate over ajax, use dummy auth name to prevent browser popup |
108 | 108 | http_response_code(401); |
109 | - header('WWW-Authenticate','DummyBasic realm="' . $this->realm . '"'); |
|
109 | + header('WWW-Authenticate', 'DummyBasic realm="'.$this->realm.'"'); |
|
110 | 110 | throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls'); |
111 | 111 | } |
112 | 112 | return false; |
@@ -44,92 +44,92 @@ |
||
44 | 44 | */ |
45 | 45 | class PublicAuth extends AbstractBasic { |
46 | 46 | |
47 | - /** @var \OCP\Share\IShare */ |
|
48 | - private $share; |
|
47 | + /** @var \OCP\Share\IShare */ |
|
48 | + private $share; |
|
49 | 49 | |
50 | - /** @var IManager */ |
|
51 | - private $shareManager; |
|
50 | + /** @var IManager */ |
|
51 | + private $shareManager; |
|
52 | 52 | |
53 | - /** @var ISession */ |
|
54 | - private $session; |
|
53 | + /** @var ISession */ |
|
54 | + private $session; |
|
55 | 55 | |
56 | - /** @var IRequest */ |
|
57 | - private $request; |
|
56 | + /** @var IRequest */ |
|
57 | + private $request; |
|
58 | 58 | |
59 | - /** |
|
60 | - * @param IRequest $request |
|
61 | - * @param IManager $shareManager |
|
62 | - * @param ISession $session |
|
63 | - */ |
|
64 | - public function __construct(IRequest $request, |
|
65 | - IManager $shareManager, |
|
66 | - ISession $session) { |
|
67 | - $this->request = $request; |
|
68 | - $this->shareManager = $shareManager; |
|
69 | - $this->session = $session; |
|
59 | + /** |
|
60 | + * @param IRequest $request |
|
61 | + * @param IManager $shareManager |
|
62 | + * @param ISession $session |
|
63 | + */ |
|
64 | + public function __construct(IRequest $request, |
|
65 | + IManager $shareManager, |
|
66 | + ISession $session) { |
|
67 | + $this->request = $request; |
|
68 | + $this->shareManager = $shareManager; |
|
69 | + $this->session = $session; |
|
70 | 70 | |
71 | - // setup realm |
|
72 | - $defaults = new \OCP\Defaults(); |
|
73 | - $this->realm = $defaults->getName(); |
|
74 | - } |
|
71 | + // setup realm |
|
72 | + $defaults = new \OCP\Defaults(); |
|
73 | + $this->realm = $defaults->getName(); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Validates a username and password |
|
78 | - * |
|
79 | - * This method should return true or false depending on if login |
|
80 | - * succeeded. |
|
81 | - * |
|
82 | - * @param string $username |
|
83 | - * @param string $password |
|
84 | - * |
|
85 | - * @return bool |
|
86 | - * @throws \Sabre\DAV\Exception\NotAuthenticated |
|
87 | - */ |
|
88 | - protected function validateUserPass($username, $password) { |
|
89 | - try { |
|
90 | - $share = $this->shareManager->getShareByToken($username); |
|
91 | - } catch (ShareNotFound $e) { |
|
92 | - return false; |
|
93 | - } |
|
76 | + /** |
|
77 | + * Validates a username and password |
|
78 | + * |
|
79 | + * This method should return true or false depending on if login |
|
80 | + * succeeded. |
|
81 | + * |
|
82 | + * @param string $username |
|
83 | + * @param string $password |
|
84 | + * |
|
85 | + * @return bool |
|
86 | + * @throws \Sabre\DAV\Exception\NotAuthenticated |
|
87 | + */ |
|
88 | + protected function validateUserPass($username, $password) { |
|
89 | + try { |
|
90 | + $share = $this->shareManager->getShareByToken($username); |
|
91 | + } catch (ShareNotFound $e) { |
|
92 | + return false; |
|
93 | + } |
|
94 | 94 | |
95 | - $this->share = $share; |
|
95 | + $this->share = $share; |
|
96 | 96 | |
97 | - \OC_User::setIncognitoMode(true); |
|
97 | + \OC_User::setIncognitoMode(true); |
|
98 | 98 | |
99 | - // check if the share is password protected |
|
100 | - if ($share->getPassword() !== null) { |
|
99 | + // check if the share is password protected |
|
100 | + if ($share->getPassword() !== null) { |
|
101 | 101 | |
102 | - if ($share->getShareType() === IShare::TYPE_LINK |
|
103 | - || $share->getShareType() === IShare::TYPE_EMAIL |
|
104 | - || $share->getShareType() === IShare::TYPE_CIRCLE) { |
|
105 | - if ($this->shareManager->checkPassword($share, $password)) { |
|
106 | - return true; |
|
107 | - } else if ($this->session->exists('public_link_authenticated') |
|
108 | - && $this->session->get('public_link_authenticated') === (string)$share->getId()) { |
|
109 | - return true; |
|
110 | - } else { |
|
111 | - if (in_array('XMLHttpRequest', explode(',', $this->request->getHeader('X-Requested-With')))) { |
|
112 | - // do not re-authenticate over ajax, use dummy auth name to prevent browser popup |
|
113 | - http_response_code(401); |
|
114 | - header('WWW-Authenticate','DummyBasic realm="' . $this->realm . '"'); |
|
115 | - throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls'); |
|
116 | - } |
|
117 | - return false; |
|
118 | - } |
|
119 | - } else if ($share->getShareType() === IShare::TYPE_REMOTE) { |
|
120 | - return true; |
|
121 | - } else { |
|
122 | - return false; |
|
123 | - } |
|
124 | - } else { |
|
125 | - return true; |
|
126 | - } |
|
127 | - } |
|
102 | + if ($share->getShareType() === IShare::TYPE_LINK |
|
103 | + || $share->getShareType() === IShare::TYPE_EMAIL |
|
104 | + || $share->getShareType() === IShare::TYPE_CIRCLE) { |
|
105 | + if ($this->shareManager->checkPassword($share, $password)) { |
|
106 | + return true; |
|
107 | + } else if ($this->session->exists('public_link_authenticated') |
|
108 | + && $this->session->get('public_link_authenticated') === (string)$share->getId()) { |
|
109 | + return true; |
|
110 | + } else { |
|
111 | + if (in_array('XMLHttpRequest', explode(',', $this->request->getHeader('X-Requested-With')))) { |
|
112 | + // do not re-authenticate over ajax, use dummy auth name to prevent browser popup |
|
113 | + http_response_code(401); |
|
114 | + header('WWW-Authenticate','DummyBasic realm="' . $this->realm . '"'); |
|
115 | + throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls'); |
|
116 | + } |
|
117 | + return false; |
|
118 | + } |
|
119 | + } else if ($share->getShareType() === IShare::TYPE_REMOTE) { |
|
120 | + return true; |
|
121 | + } else { |
|
122 | + return false; |
|
123 | + } |
|
124 | + } else { |
|
125 | + return true; |
|
126 | + } |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * @return \OCP\Share\IShare |
|
131 | - */ |
|
132 | - public function getShare() { |
|
133 | - return $this->share; |
|
134 | - } |
|
129 | + /** |
|
130 | + * @return \OCP\Share\IShare |
|
131 | + */ |
|
132 | + public function getShare() { |
|
133 | + return $this->share; |
|
134 | + } |
|
135 | 135 | } |
@@ -33,50 +33,50 @@ |
||
33 | 33 | */ |
34 | 34 | class CopyEtagHeaderPlugin extends \Sabre\DAV\ServerPlugin { |
35 | 35 | |
36 | - /** @var \Sabre\DAV\Server */ |
|
37 | - private $server; |
|
38 | - /** |
|
39 | - * This initializes the plugin. |
|
40 | - * |
|
41 | - * @param \Sabre\DAV\Server $server Sabre server |
|
42 | - * |
|
43 | - * @return void |
|
44 | - */ |
|
45 | - public function initialize(\Sabre\DAV\Server $server) { |
|
46 | - $this->server = $server; |
|
36 | + /** @var \Sabre\DAV\Server */ |
|
37 | + private $server; |
|
38 | + /** |
|
39 | + * This initializes the plugin. |
|
40 | + * |
|
41 | + * @param \Sabre\DAV\Server $server Sabre server |
|
42 | + * |
|
43 | + * @return void |
|
44 | + */ |
|
45 | + public function initialize(\Sabre\DAV\Server $server) { |
|
46 | + $this->server = $server; |
|
47 | 47 | |
48 | - $server->on('afterMethod', [$this, 'afterMethod']); |
|
49 | - $server->on('afterMove', [$this, 'afterMove']); |
|
50 | - } |
|
48 | + $server->on('afterMethod', [$this, 'afterMethod']); |
|
49 | + $server->on('afterMove', [$this, 'afterMove']); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * After method, copy the "Etag" header to "OC-Etag" header. |
|
54 | - * |
|
55 | - * @param RequestInterface $request request |
|
56 | - * @param ResponseInterface $response response |
|
57 | - */ |
|
58 | - public function afterMethod(RequestInterface $request, ResponseInterface $response) { |
|
59 | - $eTag = $response->getHeader('Etag'); |
|
60 | - if (!empty($eTag)) { |
|
61 | - $response->setHeader('OC-ETag', $eTag); |
|
62 | - } |
|
63 | - } |
|
52 | + /** |
|
53 | + * After method, copy the "Etag" header to "OC-Etag" header. |
|
54 | + * |
|
55 | + * @param RequestInterface $request request |
|
56 | + * @param ResponseInterface $response response |
|
57 | + */ |
|
58 | + public function afterMethod(RequestInterface $request, ResponseInterface $response) { |
|
59 | + $eTag = $response->getHeader('Etag'); |
|
60 | + if (!empty($eTag)) { |
|
61 | + $response->setHeader('OC-ETag', $eTag); |
|
62 | + } |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Called after a node is moved. |
|
67 | - * |
|
68 | - * This allows the backend to move all the associated properties. |
|
69 | - * |
|
70 | - * @param string $source |
|
71 | - * @param string $destination |
|
72 | - * @return void |
|
73 | - */ |
|
74 | - function afterMove($source, $destination) { |
|
75 | - $node = $this->server->tree->getNodeForPath($destination); |
|
76 | - if ($node instanceof File) { |
|
77 | - $eTag = $node->getETag(); |
|
78 | - $this->server->httpResponse->setHeader('OC-ETag', $eTag); |
|
79 | - $this->server->httpResponse->setHeader('ETag', $eTag); |
|
80 | - } |
|
81 | - } |
|
65 | + /** |
|
66 | + * Called after a node is moved. |
|
67 | + * |
|
68 | + * This allows the backend to move all the associated properties. |
|
69 | + * |
|
70 | + * @param string $source |
|
71 | + * @param string $destination |
|
72 | + * @return void |
|
73 | + */ |
|
74 | + function afterMove($source, $destination) { |
|
75 | + $node = $this->server->tree->getNodeForPath($destination); |
|
76 | + if ($node instanceof File) { |
|
77 | + $eTag = $node->getETag(); |
|
78 | + $this->server->httpResponse->setHeader('OC-ETag', $eTag); |
|
79 | + $this->server->httpResponse->setHeader('ETag', $eTag); |
|
80 | + } |
|
81 | + } |
|
82 | 82 | } |
@@ -32,41 +32,41 @@ |
||
32 | 32 | * checksum name. |
33 | 33 | */ |
34 | 34 | class ChecksumList implements XmlSerializable { |
35 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
35 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
36 | 36 | |
37 | - /** @var string[] of TYPE:CHECKSUM */ |
|
38 | - private $checksums; |
|
37 | + /** @var string[] of TYPE:CHECKSUM */ |
|
38 | + private $checksums; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param string $checksum |
|
42 | - */ |
|
43 | - public function __construct($checksum) { |
|
44 | - $this->checksums = explode(',', $checksum); |
|
45 | - } |
|
40 | + /** |
|
41 | + * @param string $checksum |
|
42 | + */ |
|
43 | + public function __construct($checksum) { |
|
44 | + $this->checksums = explode(',', $checksum); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * The xmlSerialize metod is called during xml writing. |
|
49 | - * |
|
50 | - * Use the $writer argument to write its own xml serialization. |
|
51 | - * |
|
52 | - * An important note: do _not_ create a parent element. Any element |
|
53 | - * implementing XmlSerializble should only ever write what's considered |
|
54 | - * its 'inner xml'. |
|
55 | - * |
|
56 | - * The parent of the current element is responsible for writing a |
|
57 | - * containing element. |
|
58 | - * |
|
59 | - * This allows serializers to be re-used for different element names. |
|
60 | - * |
|
61 | - * If you are opening new elements, you must also close them again. |
|
62 | - * |
|
63 | - * @param Writer $writer |
|
64 | - * @return void |
|
65 | - */ |
|
66 | - function xmlSerialize(Writer $writer) { |
|
47 | + /** |
|
48 | + * The xmlSerialize metod is called during xml writing. |
|
49 | + * |
|
50 | + * Use the $writer argument to write its own xml serialization. |
|
51 | + * |
|
52 | + * An important note: do _not_ create a parent element. Any element |
|
53 | + * implementing XmlSerializble should only ever write what's considered |
|
54 | + * its 'inner xml'. |
|
55 | + * |
|
56 | + * The parent of the current element is responsible for writing a |
|
57 | + * containing element. |
|
58 | + * |
|
59 | + * This allows serializers to be re-used for different element names. |
|
60 | + * |
|
61 | + * If you are opening new elements, you must also close them again. |
|
62 | + * |
|
63 | + * @param Writer $writer |
|
64 | + * @return void |
|
65 | + */ |
|
66 | + function xmlSerialize(Writer $writer) { |
|
67 | 67 | |
68 | - foreach ($this->checksums as $checksum) { |
|
69 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}checksum', $checksum); |
|
70 | - } |
|
71 | - } |
|
68 | + foreach ($this->checksums as $checksum) { |
|
69 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}checksum', $checksum); |
|
70 | + } |
|
71 | + } |
|
72 | 72 | } |
@@ -66,7 +66,7 @@ |
||
66 | 66 | function xmlSerialize(Writer $writer) { |
67 | 67 | |
68 | 68 | foreach ($this->checksums as $checksum) { |
69 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}checksum', $checksum); |
|
69 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}checksum', $checksum); |
|
70 | 70 | } |
71 | 71 | } |
72 | 72 | } |