@@ -27,7 +27,7 @@ |
||
27 | 27 | use OCP\Encryption\Exceptions\GenericEncryptionException; |
28 | 28 | |
29 | 29 | class EncryptionHeaderToLargeException extends GenericEncryptionException { |
30 | - public function __construct() { |
|
31 | - parent::__construct('max header size exceeded'); |
|
32 | - } |
|
30 | + public function __construct() { |
|
31 | + parent::__construct('max header size exceeded'); |
|
32 | + } |
|
33 | 33 | } |
@@ -33,159 +33,159 @@ |
||
33 | 33 | */ |
34 | 34 | class Update { |
35 | 35 | |
36 | - /** @var \OC\Files\View */ |
|
37 | - protected $view; |
|
38 | - |
|
39 | - /** @var \OC\Encryption\Util */ |
|
40 | - protected $util; |
|
41 | - |
|
42 | - /** @var \OC\Files\Mount\Manager */ |
|
43 | - protected $mountManager; |
|
44 | - |
|
45 | - /** @var \OC\Encryption\Manager */ |
|
46 | - protected $encryptionManager; |
|
47 | - |
|
48 | - /** @var string */ |
|
49 | - protected $uid; |
|
50 | - |
|
51 | - /** @var \OC\Encryption\File */ |
|
52 | - protected $file; |
|
53 | - |
|
54 | - /** |
|
55 | - * |
|
56 | - * @param \OC\Files\View $view |
|
57 | - * @param \OC\Encryption\Util $util |
|
58 | - * @param \OC\Files\Mount\Manager $mountManager |
|
59 | - * @param \OC\Encryption\Manager $encryptionManager |
|
60 | - * @param \OC\Encryption\File $file |
|
61 | - * @param string $uid |
|
62 | - */ |
|
63 | - public function __construct( |
|
64 | - View $view, |
|
65 | - Util $util, |
|
66 | - Mount\Manager $mountManager, |
|
67 | - Manager $encryptionManager, |
|
68 | - File $file, |
|
69 | - $uid |
|
70 | - ) { |
|
71 | - $this->view = $view; |
|
72 | - $this->util = $util; |
|
73 | - $this->mountManager = $mountManager; |
|
74 | - $this->encryptionManager = $encryptionManager; |
|
75 | - $this->file = $file; |
|
76 | - $this->uid = $uid; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * hook after file was shared |
|
81 | - * |
|
82 | - * @param array $params |
|
83 | - */ |
|
84 | - public function postShared($params) { |
|
85 | - if ($this->encryptionManager->isEnabled()) { |
|
86 | - if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { |
|
87 | - $path = Filesystem::getPath($params['fileSource']); |
|
88 | - list($owner, $ownerPath) = $this->getOwnerPath($path); |
|
89 | - $absPath = '/' . $owner . '/files/' . $ownerPath; |
|
90 | - $this->update($absPath); |
|
91 | - } |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * hook after file was unshared |
|
97 | - * |
|
98 | - * @param array $params |
|
99 | - */ |
|
100 | - public function postUnshared($params) { |
|
101 | - if ($this->encryptionManager->isEnabled()) { |
|
102 | - if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { |
|
103 | - $path = Filesystem::getPath($params['fileSource']); |
|
104 | - list($owner, $ownerPath) = $this->getOwnerPath($path); |
|
105 | - $absPath = '/' . $owner . '/files/' . $ownerPath; |
|
106 | - $this->update($absPath); |
|
107 | - } |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * inform encryption module that a file was restored from the trash bin, |
|
113 | - * e.g. to update the encryption keys |
|
114 | - * |
|
115 | - * @param array $params |
|
116 | - */ |
|
117 | - public function postRestore($params) { |
|
118 | - if ($this->encryptionManager->isEnabled()) { |
|
119 | - $path = Filesystem::normalizePath('/' . $this->uid . '/files/' . $params['filePath']); |
|
120 | - $this->update($path); |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * inform encryption module that a file was renamed, |
|
126 | - * e.g. to update the encryption keys |
|
127 | - * |
|
128 | - * @param array $params |
|
129 | - */ |
|
130 | - public function postRename($params) { |
|
131 | - $source = $params['oldpath']; |
|
132 | - $target = $params['newpath']; |
|
133 | - if ( |
|
134 | - $this->encryptionManager->isEnabled() && |
|
135 | - dirname($source) !== dirname($target) |
|
136 | - ) { |
|
137 | - list($owner, $ownerPath) = $this->getOwnerPath($target); |
|
138 | - $absPath = '/' . $owner . '/files/' . $ownerPath; |
|
139 | - $this->update($absPath); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * get owner and path relative to data/<owner>/files |
|
145 | - * |
|
146 | - * @param string $path path to file for current user |
|
147 | - * @return array ['owner' => $owner, 'path' => $path] |
|
148 | - * @throw \InvalidArgumentException |
|
149 | - */ |
|
150 | - protected function getOwnerPath($path) { |
|
151 | - $info = Filesystem::getFileInfo($path); |
|
152 | - $owner = Filesystem::getOwner($path); |
|
153 | - $view = new View('/' . $owner . '/files'); |
|
154 | - $path = $view->getPath($info->getId()); |
|
155 | - if ($path === null) { |
|
156 | - throw new \InvalidArgumentException('No file found for ' . $info->getId()); |
|
157 | - } |
|
158 | - |
|
159 | - return [$owner, $path]; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * notify encryption module about added/removed users from a file/folder |
|
164 | - * |
|
165 | - * @param string $path relative to data/ |
|
166 | - * @throws Exceptions\ModuleDoesNotExistsException |
|
167 | - */ |
|
168 | - public function update($path) { |
|
169 | - $encryptionModule = $this->encryptionManager->getEncryptionModule(); |
|
170 | - |
|
171 | - // if the encryption module doesn't encrypt the files on a per-user basis |
|
172 | - // we have nothing to do here. |
|
173 | - if ($encryptionModule->needDetailedAccessList() === false) { |
|
174 | - return; |
|
175 | - } |
|
176 | - |
|
177 | - // if a folder was shared, get a list of all (sub-)folders |
|
178 | - if ($this->view->is_dir($path)) { |
|
179 | - $allFiles = $this->util->getAllFiles($path); |
|
180 | - } else { |
|
181 | - $allFiles = [$path]; |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - |
|
186 | - foreach ($allFiles as $file) { |
|
187 | - $usersSharing = $this->file->getAccessList($file); |
|
188 | - $encryptionModule->update($file, $this->uid, $usersSharing); |
|
189 | - } |
|
190 | - } |
|
36 | + /** @var \OC\Files\View */ |
|
37 | + protected $view; |
|
38 | + |
|
39 | + /** @var \OC\Encryption\Util */ |
|
40 | + protected $util; |
|
41 | + |
|
42 | + /** @var \OC\Files\Mount\Manager */ |
|
43 | + protected $mountManager; |
|
44 | + |
|
45 | + /** @var \OC\Encryption\Manager */ |
|
46 | + protected $encryptionManager; |
|
47 | + |
|
48 | + /** @var string */ |
|
49 | + protected $uid; |
|
50 | + |
|
51 | + /** @var \OC\Encryption\File */ |
|
52 | + protected $file; |
|
53 | + |
|
54 | + /** |
|
55 | + * |
|
56 | + * @param \OC\Files\View $view |
|
57 | + * @param \OC\Encryption\Util $util |
|
58 | + * @param \OC\Files\Mount\Manager $mountManager |
|
59 | + * @param \OC\Encryption\Manager $encryptionManager |
|
60 | + * @param \OC\Encryption\File $file |
|
61 | + * @param string $uid |
|
62 | + */ |
|
63 | + public function __construct( |
|
64 | + View $view, |
|
65 | + Util $util, |
|
66 | + Mount\Manager $mountManager, |
|
67 | + Manager $encryptionManager, |
|
68 | + File $file, |
|
69 | + $uid |
|
70 | + ) { |
|
71 | + $this->view = $view; |
|
72 | + $this->util = $util; |
|
73 | + $this->mountManager = $mountManager; |
|
74 | + $this->encryptionManager = $encryptionManager; |
|
75 | + $this->file = $file; |
|
76 | + $this->uid = $uid; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * hook after file was shared |
|
81 | + * |
|
82 | + * @param array $params |
|
83 | + */ |
|
84 | + public function postShared($params) { |
|
85 | + if ($this->encryptionManager->isEnabled()) { |
|
86 | + if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { |
|
87 | + $path = Filesystem::getPath($params['fileSource']); |
|
88 | + list($owner, $ownerPath) = $this->getOwnerPath($path); |
|
89 | + $absPath = '/' . $owner . '/files/' . $ownerPath; |
|
90 | + $this->update($absPath); |
|
91 | + } |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * hook after file was unshared |
|
97 | + * |
|
98 | + * @param array $params |
|
99 | + */ |
|
100 | + public function postUnshared($params) { |
|
101 | + if ($this->encryptionManager->isEnabled()) { |
|
102 | + if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { |
|
103 | + $path = Filesystem::getPath($params['fileSource']); |
|
104 | + list($owner, $ownerPath) = $this->getOwnerPath($path); |
|
105 | + $absPath = '/' . $owner . '/files/' . $ownerPath; |
|
106 | + $this->update($absPath); |
|
107 | + } |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * inform encryption module that a file was restored from the trash bin, |
|
113 | + * e.g. to update the encryption keys |
|
114 | + * |
|
115 | + * @param array $params |
|
116 | + */ |
|
117 | + public function postRestore($params) { |
|
118 | + if ($this->encryptionManager->isEnabled()) { |
|
119 | + $path = Filesystem::normalizePath('/' . $this->uid . '/files/' . $params['filePath']); |
|
120 | + $this->update($path); |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * inform encryption module that a file was renamed, |
|
126 | + * e.g. to update the encryption keys |
|
127 | + * |
|
128 | + * @param array $params |
|
129 | + */ |
|
130 | + public function postRename($params) { |
|
131 | + $source = $params['oldpath']; |
|
132 | + $target = $params['newpath']; |
|
133 | + if ( |
|
134 | + $this->encryptionManager->isEnabled() && |
|
135 | + dirname($source) !== dirname($target) |
|
136 | + ) { |
|
137 | + list($owner, $ownerPath) = $this->getOwnerPath($target); |
|
138 | + $absPath = '/' . $owner . '/files/' . $ownerPath; |
|
139 | + $this->update($absPath); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * get owner and path relative to data/<owner>/files |
|
145 | + * |
|
146 | + * @param string $path path to file for current user |
|
147 | + * @return array ['owner' => $owner, 'path' => $path] |
|
148 | + * @throw \InvalidArgumentException |
|
149 | + */ |
|
150 | + protected function getOwnerPath($path) { |
|
151 | + $info = Filesystem::getFileInfo($path); |
|
152 | + $owner = Filesystem::getOwner($path); |
|
153 | + $view = new View('/' . $owner . '/files'); |
|
154 | + $path = $view->getPath($info->getId()); |
|
155 | + if ($path === null) { |
|
156 | + throw new \InvalidArgumentException('No file found for ' . $info->getId()); |
|
157 | + } |
|
158 | + |
|
159 | + return [$owner, $path]; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * notify encryption module about added/removed users from a file/folder |
|
164 | + * |
|
165 | + * @param string $path relative to data/ |
|
166 | + * @throws Exceptions\ModuleDoesNotExistsException |
|
167 | + */ |
|
168 | + public function update($path) { |
|
169 | + $encryptionModule = $this->encryptionManager->getEncryptionModule(); |
|
170 | + |
|
171 | + // if the encryption module doesn't encrypt the files on a per-user basis |
|
172 | + // we have nothing to do here. |
|
173 | + if ($encryptionModule->needDetailedAccessList() === false) { |
|
174 | + return; |
|
175 | + } |
|
176 | + |
|
177 | + // if a folder was shared, get a list of all (sub-)folders |
|
178 | + if ($this->view->is_dir($path)) { |
|
179 | + $allFiles = $this->util->getAllFiles($path); |
|
180 | + } else { |
|
181 | + $allFiles = [$path]; |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + |
|
186 | + foreach ($allFiles as $file) { |
|
187 | + $usersSharing = $this->file->getAccessList($file); |
|
188 | + $encryptionModule->update($file, $this->uid, $usersSharing); |
|
189 | + } |
|
190 | + } |
|
191 | 191 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | * @package OC\AppFramework\Middleware\Security\Exceptions |
33 | 33 | */ |
34 | 34 | class StrictCookieMissingException extends SecurityException { |
35 | - public function __construct() { |
|
36 | - parent::__construct('Strict Cookie has not been found in request.', Http::STATUS_PRECONDITION_FAILED); |
|
37 | - } |
|
35 | + public function __construct() { |
|
36 | + parent::__construct('Strict Cookie has not been found in request.', Http::STATUS_PRECONDITION_FAILED); |
|
37 | + } |
|
38 | 38 | } |
@@ -27,52 +27,52 @@ |
||
27 | 27 | |
28 | 28 | class V1Response extends BaseResponse { |
29 | 29 | |
30 | - /** |
|
31 | - * The V1 endpoint has very limited http status codes basically everything |
|
32 | - * is status 200 except 401 |
|
33 | - * |
|
34 | - * @return int |
|
35 | - */ |
|
36 | - public function getStatus() { |
|
37 | - $status = parent::getStatus(); |
|
38 | - if ($status === Http::STATUS_FORBIDDEN || $status === API::RESPOND_UNAUTHORISED) { |
|
39 | - return Http::STATUS_UNAUTHORIZED; |
|
40 | - } |
|
30 | + /** |
|
31 | + * The V1 endpoint has very limited http status codes basically everything |
|
32 | + * is status 200 except 401 |
|
33 | + * |
|
34 | + * @return int |
|
35 | + */ |
|
36 | + public function getStatus() { |
|
37 | + $status = parent::getStatus(); |
|
38 | + if ($status === Http::STATUS_FORBIDDEN || $status === API::RESPOND_UNAUTHORISED) { |
|
39 | + return Http::STATUS_UNAUTHORIZED; |
|
40 | + } |
|
41 | 41 | |
42 | - return Http::STATUS_OK; |
|
43 | - } |
|
42 | + return Http::STATUS_OK; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * In v1 all OK is 100 |
|
47 | - * |
|
48 | - * @return int |
|
49 | - */ |
|
50 | - public function getOCSStatus() { |
|
51 | - $status = parent::getOCSStatus(); |
|
45 | + /** |
|
46 | + * In v1 all OK is 100 |
|
47 | + * |
|
48 | + * @return int |
|
49 | + */ |
|
50 | + public function getOCSStatus() { |
|
51 | + $status = parent::getOCSStatus(); |
|
52 | 52 | |
53 | - if ($status === Http::STATUS_OK) { |
|
54 | - return 100; |
|
55 | - } |
|
53 | + if ($status === Http::STATUS_OK) { |
|
54 | + return 100; |
|
55 | + } |
|
56 | 56 | |
57 | - return $status; |
|
58 | - } |
|
57 | + return $status; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Construct the meta part of the response |
|
62 | - * And then late the base class render |
|
63 | - * |
|
64 | - * @return string |
|
65 | - */ |
|
66 | - public function render() { |
|
67 | - $meta = [ |
|
68 | - 'status' => $this->getOCSStatus() === 100 ? 'ok' : 'failure', |
|
69 | - 'statuscode' => $this->getOCSStatus(), |
|
70 | - 'message' => $this->getOCSStatus() === 100 ? 'OK' : $this->statusMessage, |
|
71 | - ]; |
|
60 | + /** |
|
61 | + * Construct the meta part of the response |
|
62 | + * And then late the base class render |
|
63 | + * |
|
64 | + * @return string |
|
65 | + */ |
|
66 | + public function render() { |
|
67 | + $meta = [ |
|
68 | + 'status' => $this->getOCSStatus() === 100 ? 'ok' : 'failure', |
|
69 | + 'statuscode' => $this->getOCSStatus(), |
|
70 | + 'message' => $this->getOCSStatus() === 100 ? 'OK' : $this->statusMessage, |
|
71 | + ]; |
|
72 | 72 | |
73 | - $meta['totalitems'] = $this->itemsCount !== null ? (string)$this->itemsCount : ''; |
|
74 | - $meta['itemsperpage'] = $this->itemsPerPage !== null ? (string)$this->itemsPerPage: ''; |
|
73 | + $meta['totalitems'] = $this->itemsCount !== null ? (string)$this->itemsCount : ''; |
|
74 | + $meta['itemsperpage'] = $this->itemsPerPage !== null ? (string)$this->itemsPerPage: ''; |
|
75 | 75 | |
76 | - return $this->renderResult($meta); |
|
77 | - } |
|
76 | + return $this->renderResult($meta); |
|
77 | + } |
|
78 | 78 | } |
@@ -27,49 +27,49 @@ |
||
27 | 27 | |
28 | 28 | class V2Response extends BaseResponse { |
29 | 29 | |
30 | - /** |
|
31 | - * The V2 endpoint just passes on status codes. |
|
32 | - * Of course we have to map the OCS specific codes to proper HTTP status codes |
|
33 | - * |
|
34 | - * @return int |
|
35 | - */ |
|
36 | - public function getStatus() { |
|
37 | - $status = parent::getStatus(); |
|
38 | - if ($status === API::RESPOND_UNAUTHORISED) { |
|
39 | - return Http::STATUS_UNAUTHORIZED; |
|
40 | - } elseif ($status === API::RESPOND_NOT_FOUND) { |
|
41 | - return Http::STATUS_NOT_FOUND; |
|
42 | - } elseif ($status === API::RESPOND_SERVER_ERROR || $status === API::RESPOND_UNKNOWN_ERROR) { |
|
43 | - return Http::STATUS_INTERNAL_SERVER_ERROR; |
|
44 | - } elseif ($status < 200 || $status > 600) { |
|
45 | - return Http::STATUS_BAD_REQUEST; |
|
46 | - } |
|
30 | + /** |
|
31 | + * The V2 endpoint just passes on status codes. |
|
32 | + * Of course we have to map the OCS specific codes to proper HTTP status codes |
|
33 | + * |
|
34 | + * @return int |
|
35 | + */ |
|
36 | + public function getStatus() { |
|
37 | + $status = parent::getStatus(); |
|
38 | + if ($status === API::RESPOND_UNAUTHORISED) { |
|
39 | + return Http::STATUS_UNAUTHORIZED; |
|
40 | + } elseif ($status === API::RESPOND_NOT_FOUND) { |
|
41 | + return Http::STATUS_NOT_FOUND; |
|
42 | + } elseif ($status === API::RESPOND_SERVER_ERROR || $status === API::RESPOND_UNKNOWN_ERROR) { |
|
43 | + return Http::STATUS_INTERNAL_SERVER_ERROR; |
|
44 | + } elseif ($status < 200 || $status > 600) { |
|
45 | + return Http::STATUS_BAD_REQUEST; |
|
46 | + } |
|
47 | 47 | |
48 | - return $status; |
|
49 | - } |
|
48 | + return $status; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Construct the meta part of the response |
|
53 | - * And then late the base class render |
|
54 | - * |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - public function render() { |
|
58 | - $status = parent::getStatus(); |
|
51 | + /** |
|
52 | + * Construct the meta part of the response |
|
53 | + * And then late the base class render |
|
54 | + * |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + public function render() { |
|
58 | + $status = parent::getStatus(); |
|
59 | 59 | |
60 | - $meta = [ |
|
61 | - 'status' => $status >= 200 && $status < 300 ? 'ok' : 'failure', |
|
62 | - 'statuscode' => $this->getOCSStatus(), |
|
63 | - 'message' => $status >= 200 && $status < 300 ? 'OK' : $this->statusMessage, |
|
64 | - ]; |
|
60 | + $meta = [ |
|
61 | + 'status' => $status >= 200 && $status < 300 ? 'ok' : 'failure', |
|
62 | + 'statuscode' => $this->getOCSStatus(), |
|
63 | + 'message' => $status >= 200 && $status < 300 ? 'OK' : $this->statusMessage, |
|
64 | + ]; |
|
65 | 65 | |
66 | - if ($this->itemsCount !== null) { |
|
67 | - $meta['totalitems'] = $this->itemsCount; |
|
68 | - } |
|
69 | - if ($this->itemsPerPage !== null) { |
|
70 | - $meta['itemsperpage'] = $this->itemsPerPage; |
|
71 | - } |
|
66 | + if ($this->itemsCount !== null) { |
|
67 | + $meta['totalitems'] = $this->itemsCount; |
|
68 | + } |
|
69 | + if ($this->itemsPerPage !== null) { |
|
70 | + $meta['itemsperpage'] = $this->itemsPerPage; |
|
71 | + } |
|
72 | 72 | |
73 | - return $this->renderResult($meta); |
|
74 | - } |
|
73 | + return $this->renderResult($meta); |
|
74 | + } |
|
75 | 75 | } |
@@ -43,84 +43,84 @@ |
||
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 | - public 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 | + public 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 | - public 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 | + public 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 | - public 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 | + public function childExists($name) { |
|
124 | + return call_user_func($this->childExistsFunction, $name); |
|
125 | + } |
|
126 | 126 | } |
@@ -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 | } |
@@ -26,66 +26,66 @@ |
||
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 | - public function check(RequestInterface $request, ResponseInterface $response) { |
|
68 | - if ($this->isRequestPublic($request)) { |
|
69 | - return [true, "principals/system/public"]; |
|
70 | - } |
|
71 | - return [false, "No public access to this resource."]; |
|
72 | - } |
|
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 | + public function check(RequestInterface $request, ResponseInterface $response) { |
|
68 | + if ($this->isRequestPublic($request)) { |
|
69 | + return [true, "principals/system/public"]; |
|
70 | + } |
|
71 | + return [false, "No public access to this resource."]; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @inheritdoc |
|
76 | - */ |
|
77 | - public function challenge(RequestInterface $request, ResponseInterface $response) { |
|
78 | - } |
|
74 | + /** |
|
75 | + * @inheritdoc |
|
76 | + */ |
|
77 | + public function challenge(RequestInterface $request, ResponseInterface $response) { |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @param RequestInterface $request |
|
82 | - * @return bool |
|
83 | - */ |
|
84 | - private function isRequestPublic(RequestInterface $request) { |
|
85 | - $url = $request->getPath(); |
|
86 | - $matchingUrls = array_filter($this->publicURLs, function ($publicUrl) use ($url) { |
|
87 | - return strpos($url, $publicUrl, 0) === 0; |
|
88 | - }); |
|
89 | - return !empty($matchingUrls); |
|
90 | - } |
|
80 | + /** |
|
81 | + * @param RequestInterface $request |
|
82 | + * @return bool |
|
83 | + */ |
|
84 | + private function isRequestPublic(RequestInterface $request) { |
|
85 | + $url = $request->getPath(); |
|
86 | + $matchingUrls = array_filter($this->publicURLs, function ($publicUrl) use ($url) { |
|
87 | + return strpos($url, $publicUrl, 0) === 0; |
|
88 | + }); |
|
89 | + return !empty($matchingUrls); |
|
90 | + } |
|
91 | 91 | } |
@@ -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 | } |