@@ -36,49 +36,49 @@ |
||
36 | 36 | */ |
37 | 37 | class SimpleOutput implements IOutput { |
38 | 38 | |
39 | - /** @var ILogger */ |
|
40 | - private $logger; |
|
41 | - private $appName; |
|
39 | + /** @var ILogger */ |
|
40 | + private $logger; |
|
41 | + private $appName; |
|
42 | 42 | |
43 | - public function __construct(ILogger $logger, $appName) { |
|
44 | - $this->logger = $logger; |
|
45 | - $this->appName = $appName; |
|
46 | - } |
|
43 | + public function __construct(ILogger $logger, $appName) { |
|
44 | + $this->logger = $logger; |
|
45 | + $this->appName = $appName; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param string $message |
|
50 | - * @since 9.1.0 |
|
51 | - */ |
|
52 | - public function info($message) { |
|
53 | - $this->logger->info($message, ['app' => $this->appName]); |
|
54 | - } |
|
48 | + /** |
|
49 | + * @param string $message |
|
50 | + * @since 9.1.0 |
|
51 | + */ |
|
52 | + public function info($message) { |
|
53 | + $this->logger->info($message, ['app' => $this->appName]); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @param string $message |
|
58 | - * @since 9.1.0 |
|
59 | - */ |
|
60 | - public function warning($message) { |
|
61 | - $this->logger->warning($message, ['app' => $this->appName]); |
|
62 | - } |
|
56 | + /** |
|
57 | + * @param string $message |
|
58 | + * @since 9.1.0 |
|
59 | + */ |
|
60 | + public function warning($message) { |
|
61 | + $this->logger->warning($message, ['app' => $this->appName]); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param int $max |
|
66 | - * @since 9.1.0 |
|
67 | - */ |
|
68 | - public function startProgress($max = 0) { |
|
69 | - } |
|
64 | + /** |
|
65 | + * @param int $max |
|
66 | + * @since 9.1.0 |
|
67 | + */ |
|
68 | + public function startProgress($max = 0) { |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * @param int $step |
|
73 | - * @param string $description |
|
74 | - * @since 9.1.0 |
|
75 | - */ |
|
76 | - public function advance($step = 1, $description = '') { |
|
77 | - } |
|
71 | + /** |
|
72 | + * @param int $step |
|
73 | + * @param string $description |
|
74 | + * @since 9.1.0 |
|
75 | + */ |
|
76 | + public function advance($step = 1, $description = '') { |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @since 9.1.0 |
|
81 | - */ |
|
82 | - public function finishProgress() { |
|
83 | - } |
|
79 | + /** |
|
80 | + * @since 9.1.0 |
|
81 | + */ |
|
82 | + public function finishProgress() { |
|
83 | + } |
|
84 | 84 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @throws \Doctrine\DBAL\Schema\SchemaException |
81 | 81 | */ |
82 | 82 | public function getTable($tableName) { |
83 | - return $this->schema->getTable($this->connection->getPrefix() . $tableName); |
|
83 | + return $this->schema->getTable($this->connection->getPrefix().$tableName); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @return boolean |
92 | 92 | */ |
93 | 93 | public function hasTable($tableName) { |
94 | - return $this->schema->hasTable($this->connection->getPrefix() . $tableName); |
|
94 | + return $this->schema->hasTable($this->connection->getPrefix().$tableName); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @return \Doctrine\DBAL\Schema\Table |
102 | 102 | */ |
103 | 103 | public function createTable($tableName) { |
104 | - return $this->schema->createTable($this->connection->getPrefix() . $tableName); |
|
104 | + return $this->schema->createTable($this->connection->getPrefix().$tableName); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function dropTable($tableName) { |
127 | 127 | $this->tablesToDelete[$tableName] = true; |
128 | - return $this->schema->dropTable($this->connection->getPrefix() . $tableName); |
|
128 | + return $this->schema->dropTable($this->connection->getPrefix().$tableName); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -30,107 +30,107 @@ |
||
30 | 30 | |
31 | 31 | class SchemaWrapper implements ISchemaWrapper { |
32 | 32 | |
33 | - /** @var IDBConnection|Connection */ |
|
34 | - protected $connection; |
|
35 | - |
|
36 | - /** @var Schema */ |
|
37 | - protected $schema; |
|
38 | - |
|
39 | - /** @var array */ |
|
40 | - protected $tablesToDelete = []; |
|
41 | - |
|
42 | - /** |
|
43 | - * @param IDBConnection $connection |
|
44 | - */ |
|
45 | - public function __construct(IDBConnection $connection) { |
|
46 | - $this->connection = $connection; |
|
47 | - $this->schema = $this->connection->createSchema(); |
|
48 | - } |
|
49 | - |
|
50 | - public function getWrappedSchema() { |
|
51 | - return $this->schema; |
|
52 | - } |
|
53 | - |
|
54 | - public function performDropTableCalls() { |
|
55 | - foreach ($this->tablesToDelete as $tableName => $true) { |
|
56 | - $this->connection->dropTable($tableName); |
|
57 | - unset($this->tablesToDelete[$tableName]); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Gets all table names |
|
63 | - * |
|
64 | - * @return array |
|
65 | - */ |
|
66 | - public function getTableNamesWithoutPrefix() { |
|
67 | - $tableNames = $this->schema->getTableNames(); |
|
68 | - return array_map(function($tableName) { |
|
69 | - if (strpos($tableName, $this->connection->getPrefix()) === 0) { |
|
70 | - return substr($tableName, strlen($this->connection->getPrefix())); |
|
71 | - } |
|
72 | - |
|
73 | - return $tableName; |
|
74 | - }, $tableNames); |
|
75 | - } |
|
76 | - |
|
77 | - // Overwritten methods |
|
78 | - |
|
79 | - /** |
|
80 | - * @return array |
|
81 | - */ |
|
82 | - public function getTableNames() { |
|
83 | - return $this->schema->getTableNames(); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @param string $tableName |
|
88 | - * |
|
89 | - * @return \Doctrine\DBAL\Schema\Table |
|
90 | - * @throws \Doctrine\DBAL\Schema\SchemaException |
|
91 | - */ |
|
92 | - public function getTable($tableName) { |
|
93 | - return $this->schema->getTable($this->connection->getPrefix() . $tableName); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Does this schema have a table with the given name? |
|
98 | - * |
|
99 | - * @param string $tableName |
|
100 | - * |
|
101 | - * @return boolean |
|
102 | - */ |
|
103 | - public function hasTable($tableName) { |
|
104 | - return $this->schema->hasTable($this->connection->getPrefix() . $tableName); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Creates a new table. |
|
109 | - * |
|
110 | - * @param string $tableName |
|
111 | - * @return \Doctrine\DBAL\Schema\Table |
|
112 | - */ |
|
113 | - public function createTable($tableName) { |
|
114 | - return $this->schema->createTable($this->connection->getPrefix() . $tableName); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Drops a table from the schema. |
|
119 | - * |
|
120 | - * @param string $tableName |
|
121 | - * @return \Doctrine\DBAL\Schema\Schema |
|
122 | - */ |
|
123 | - public function dropTable($tableName) { |
|
124 | - $this->tablesToDelete[$tableName] = true; |
|
125 | - return $this->schema->dropTable($this->connection->getPrefix() . $tableName); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Gets all tables of this schema. |
|
130 | - * |
|
131 | - * @return \Doctrine\DBAL\Schema\Table[] |
|
132 | - */ |
|
133 | - public function getTables() { |
|
134 | - return $this->schema->getTables(); |
|
135 | - } |
|
33 | + /** @var IDBConnection|Connection */ |
|
34 | + protected $connection; |
|
35 | + |
|
36 | + /** @var Schema */ |
|
37 | + protected $schema; |
|
38 | + |
|
39 | + /** @var array */ |
|
40 | + protected $tablesToDelete = []; |
|
41 | + |
|
42 | + /** |
|
43 | + * @param IDBConnection $connection |
|
44 | + */ |
|
45 | + public function __construct(IDBConnection $connection) { |
|
46 | + $this->connection = $connection; |
|
47 | + $this->schema = $this->connection->createSchema(); |
|
48 | + } |
|
49 | + |
|
50 | + public function getWrappedSchema() { |
|
51 | + return $this->schema; |
|
52 | + } |
|
53 | + |
|
54 | + public function performDropTableCalls() { |
|
55 | + foreach ($this->tablesToDelete as $tableName => $true) { |
|
56 | + $this->connection->dropTable($tableName); |
|
57 | + unset($this->tablesToDelete[$tableName]); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Gets all table names |
|
63 | + * |
|
64 | + * @return array |
|
65 | + */ |
|
66 | + public function getTableNamesWithoutPrefix() { |
|
67 | + $tableNames = $this->schema->getTableNames(); |
|
68 | + return array_map(function($tableName) { |
|
69 | + if (strpos($tableName, $this->connection->getPrefix()) === 0) { |
|
70 | + return substr($tableName, strlen($this->connection->getPrefix())); |
|
71 | + } |
|
72 | + |
|
73 | + return $tableName; |
|
74 | + }, $tableNames); |
|
75 | + } |
|
76 | + |
|
77 | + // Overwritten methods |
|
78 | + |
|
79 | + /** |
|
80 | + * @return array |
|
81 | + */ |
|
82 | + public function getTableNames() { |
|
83 | + return $this->schema->getTableNames(); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @param string $tableName |
|
88 | + * |
|
89 | + * @return \Doctrine\DBAL\Schema\Table |
|
90 | + * @throws \Doctrine\DBAL\Schema\SchemaException |
|
91 | + */ |
|
92 | + public function getTable($tableName) { |
|
93 | + return $this->schema->getTable($this->connection->getPrefix() . $tableName); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Does this schema have a table with the given name? |
|
98 | + * |
|
99 | + * @param string $tableName |
|
100 | + * |
|
101 | + * @return boolean |
|
102 | + */ |
|
103 | + public function hasTable($tableName) { |
|
104 | + return $this->schema->hasTable($this->connection->getPrefix() . $tableName); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Creates a new table. |
|
109 | + * |
|
110 | + * @param string $tableName |
|
111 | + * @return \Doctrine\DBAL\Schema\Table |
|
112 | + */ |
|
113 | + public function createTable($tableName) { |
|
114 | + return $this->schema->createTable($this->connection->getPrefix() . $tableName); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Drops a table from the schema. |
|
119 | + * |
|
120 | + * @param string $tableName |
|
121 | + * @return \Doctrine\DBAL\Schema\Schema |
|
122 | + */ |
|
123 | + public function dropTable($tableName) { |
|
124 | + $this->tablesToDelete[$tableName] = true; |
|
125 | + return $this->schema->dropTable($this->connection->getPrefix() . $tableName); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Gets all tables of this schema. |
|
130 | + * |
|
131 | + * @return \Doctrine\DBAL\Schema\Table[] |
|
132 | + */ |
|
133 | + public function getTables() { |
|
134 | + return $this->schema->getTables(); |
|
135 | + } |
|
136 | 136 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | } |
111 | 111 | |
112 | 112 | public function getACL() { |
113 | - $acl = [ |
|
113 | + $acl = [ |
|
114 | 114 | [ |
115 | 115 | 'privilege' => '{DAV:}read', |
116 | 116 | 'principal' => $this->getOwner(), |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | } |
132 | 132 | |
133 | 133 | if ($this->getOwner() !== parent::getOwner()) { |
134 | - $acl[] = [ |
|
134 | + $acl[] = [ |
|
135 | 135 | 'privilege' => '{DAV:}read', |
136 | 136 | 'principal' => parent::getOwner(), |
137 | 137 | 'protected' => true, |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | public function delete() { |
179 | 179 | if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) && |
180 | 180 | $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) { |
181 | - $principal = 'principal:' . parent::getOwner(); |
|
181 | + $principal = 'principal:'.parent::getOwner(); |
|
182 | 182 | $shares = $this->caldavBackend->getShares($this->getResourceId()); |
183 | 183 | $shares = array_filter($shares, function($share) use ($principal){ |
184 | 184 | return $share['href'] === $principal; |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | |
268 | 268 | $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters); |
269 | 269 | if ($this->isShared()) { |
270 | - return array_filter($uris, function ($uri) { |
|
270 | + return array_filter($uris, function($uri) { |
|
271 | 271 | return $this->childExists($uri); |
272 | 272 | }); |
273 | 273 | } |
@@ -42,301 +42,301 @@ |
||
42 | 42 | */ |
43 | 43 | class Calendar extends \Sabre\CalDAV\Calendar implements IShareable { |
44 | 44 | |
45 | - /** @var IConfig */ |
|
46 | - private $config; |
|
47 | - |
|
48 | - public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) { |
|
49 | - parent::__construct($caldavBackend, $calendarInfo); |
|
50 | - |
|
51 | - if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
52 | - $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays'); |
|
53 | - } |
|
54 | - if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI && |
|
55 | - $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) { |
|
56 | - $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal'); |
|
57 | - } |
|
58 | - |
|
59 | - $this->config = $config; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Updates the list of shares. |
|
64 | - * |
|
65 | - * The first array is a list of people that are to be added to the |
|
66 | - * resource. |
|
67 | - * |
|
68 | - * Every element in the add array has the following properties: |
|
69 | - * * href - A url. Usually a mailto: address |
|
70 | - * * commonName - Usually a first and last name, or false |
|
71 | - * * summary - A description of the share, can also be false |
|
72 | - * * readOnly - A boolean value |
|
73 | - * |
|
74 | - * Every element in the remove array is just the address string. |
|
75 | - * |
|
76 | - * @param array $add |
|
77 | - * @param array $remove |
|
78 | - * @return void |
|
79 | - * @throws Forbidden |
|
80 | - */ |
|
81 | - public function updateShares(array $add, array $remove) { |
|
82 | - if ($this->isShared()) { |
|
83 | - throw new Forbidden(); |
|
84 | - } |
|
85 | - $this->caldavBackend->updateShares($this, $add, $remove); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Returns the list of people whom this resource is shared with. |
|
90 | - * |
|
91 | - * Every element in this array should have the following properties: |
|
92 | - * * href - Often a mailto: address |
|
93 | - * * commonName - Optional, for example a first + last name |
|
94 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
95 | - * * readOnly - boolean |
|
96 | - * * summary - Optional, a description for the share |
|
97 | - * |
|
98 | - * @return array |
|
99 | - */ |
|
100 | - public function getShares() { |
|
101 | - if ($this->isShared()) { |
|
102 | - return []; |
|
103 | - } |
|
104 | - return $this->caldavBackend->getShares($this->getResourceId()); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @return int |
|
109 | - */ |
|
110 | - public function getResourceId() { |
|
111 | - return $this->calendarInfo['id']; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @return string |
|
116 | - */ |
|
117 | - public function getPrincipalURI() { |
|
118 | - return $this->calendarInfo['principaluri']; |
|
119 | - } |
|
120 | - |
|
121 | - public function getACL() { |
|
122 | - $acl = [ |
|
123 | - [ |
|
124 | - 'privilege' => '{DAV:}read', |
|
125 | - 'principal' => $this->getOwner(), |
|
126 | - 'protected' => true, |
|
127 | - ]]; |
|
128 | - if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
129 | - $acl[] = [ |
|
130 | - 'privilege' => '{DAV:}write', |
|
131 | - 'principal' => $this->getOwner(), |
|
132 | - 'protected' => true, |
|
133 | - ]; |
|
134 | - } else { |
|
135 | - $acl[] = [ |
|
136 | - 'privilege' => '{DAV:}write-properties', |
|
137 | - 'principal' => $this->getOwner(), |
|
138 | - 'protected' => true, |
|
139 | - ]; |
|
140 | - } |
|
141 | - |
|
142 | - if (!$this->isShared()) { |
|
143 | - return $acl; |
|
144 | - } |
|
145 | - |
|
146 | - if ($this->getOwner() !== parent::getOwner()) { |
|
147 | - $acl[] = [ |
|
148 | - 'privilege' => '{DAV:}read', |
|
149 | - 'principal' => parent::getOwner(), |
|
150 | - 'protected' => true, |
|
151 | - ]; |
|
152 | - if ($this->canWrite()) { |
|
153 | - $acl[] = [ |
|
154 | - 'privilege' => '{DAV:}write', |
|
155 | - 'principal' => parent::getOwner(), |
|
156 | - 'protected' => true, |
|
157 | - ]; |
|
158 | - } else { |
|
159 | - $acl[] = [ |
|
160 | - 'privilege' => '{DAV:}write-properties', |
|
161 | - 'principal' => parent::getOwner(), |
|
162 | - 'protected' => true, |
|
163 | - ]; |
|
164 | - } |
|
165 | - } |
|
166 | - if ($this->isPublic()) { |
|
167 | - $acl[] = [ |
|
168 | - 'privilege' => '{DAV:}read', |
|
169 | - 'principal' => 'principals/system/public', |
|
170 | - 'protected' => true, |
|
171 | - ]; |
|
172 | - } |
|
173 | - |
|
174 | - $acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
175 | - $allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public']; |
|
176 | - return array_filter($acl, function($rule) use ($allowedPrincipals) { |
|
177 | - return \in_array($rule['principal'], $allowedPrincipals, true); |
|
178 | - }); |
|
179 | - } |
|
180 | - |
|
181 | - public function getChildACL() { |
|
182 | - return $this->getACL(); |
|
183 | - } |
|
184 | - |
|
185 | - public function getOwner() { |
|
186 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
187 | - return $this->calendarInfo['{http://owncloud.org/ns}owner-principal']; |
|
188 | - } |
|
189 | - return parent::getOwner(); |
|
190 | - } |
|
191 | - |
|
192 | - public function delete() { |
|
193 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) && |
|
194 | - $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) { |
|
195 | - $principal = 'principal:' . parent::getOwner(); |
|
196 | - $shares = $this->caldavBackend->getShares($this->getResourceId()); |
|
197 | - $shares = array_filter($shares, function($share) use ($principal){ |
|
198 | - return $share['href'] === $principal; |
|
199 | - }); |
|
200 | - if (empty($shares)) { |
|
201 | - throw new Forbidden(); |
|
202 | - } |
|
203 | - |
|
204 | - $this->caldavBackend->updateShares($this, [], [ |
|
205 | - $principal |
|
206 | - ]); |
|
207 | - return; |
|
208 | - } |
|
209 | - |
|
210 | - // Remember when a user deleted their birthday calendar |
|
211 | - // in order to not regenerate it on the next contacts change |
|
212 | - if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
213 | - $principalURI = $this->getPrincipalURI(); |
|
214 | - $userId = substr($principalURI, 17); |
|
215 | - |
|
216 | - $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'no'); |
|
217 | - } |
|
218 | - |
|
219 | - parent::delete(); |
|
220 | - } |
|
221 | - |
|
222 | - public function propPatch(PropPatch $propPatch) { |
|
223 | - // parent::propPatch will only update calendars table |
|
224 | - // if calendar is shared, changes have to be made to the properties table |
|
225 | - if (!$this->isShared()) { |
|
226 | - parent::propPatch($propPatch); |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - public function getChild($name) { |
|
231 | - |
|
232 | - $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
233 | - |
|
234 | - if (!$obj) { |
|
235 | - throw new NotFound('Calendar object not found'); |
|
236 | - } |
|
237 | - |
|
238 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
239 | - throw new NotFound('Calendar object not found'); |
|
240 | - } |
|
241 | - |
|
242 | - $obj['acl'] = $this->getChildACL(); |
|
243 | - |
|
244 | - return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
245 | - |
|
246 | - } |
|
247 | - |
|
248 | - public function getChildren() { |
|
249 | - |
|
250 | - $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']); |
|
251 | - $children = []; |
|
252 | - foreach ($objs as $obj) { |
|
253 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
254 | - continue; |
|
255 | - } |
|
256 | - $obj['acl'] = $this->getChildACL(); |
|
257 | - $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
258 | - } |
|
259 | - return $children; |
|
260 | - |
|
261 | - } |
|
262 | - |
|
263 | - public function getMultipleChildren(array $paths) { |
|
264 | - |
|
265 | - $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths); |
|
266 | - $children = []; |
|
267 | - foreach ($objs as $obj) { |
|
268 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
269 | - continue; |
|
270 | - } |
|
271 | - $obj['acl'] = $this->getChildACL(); |
|
272 | - $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
273 | - } |
|
274 | - return $children; |
|
275 | - |
|
276 | - } |
|
277 | - |
|
278 | - public function childExists($name) { |
|
279 | - $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
280 | - if (!$obj) { |
|
281 | - return false; |
|
282 | - } |
|
283 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
284 | - return false; |
|
285 | - } |
|
286 | - |
|
287 | - return true; |
|
288 | - } |
|
289 | - |
|
290 | - public function calendarQuery(array $filters) { |
|
291 | - |
|
292 | - $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters); |
|
293 | - if ($this->isShared()) { |
|
294 | - return array_filter($uris, function ($uri) { |
|
295 | - return $this->childExists($uri); |
|
296 | - }); |
|
297 | - } |
|
298 | - |
|
299 | - return $uris; |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * @param boolean $value |
|
304 | - * @return string|null |
|
305 | - */ |
|
306 | - public function setPublishStatus($value) { |
|
307 | - $publicUri = $this->caldavBackend->setPublishStatus($value, $this); |
|
308 | - $this->calendarInfo['publicuri'] = $publicUri; |
|
309 | - return $publicUri; |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * @return mixed $value |
|
314 | - */ |
|
315 | - public function getPublishStatus() { |
|
316 | - return $this->caldavBackend->getPublishStatus($this); |
|
317 | - } |
|
318 | - |
|
319 | - private function canWrite() { |
|
320 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { |
|
321 | - return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; |
|
322 | - } |
|
323 | - return true; |
|
324 | - } |
|
325 | - |
|
326 | - private function isPublic() { |
|
327 | - return isset($this->calendarInfo['{http://owncloud.org/ns}public']); |
|
328 | - } |
|
329 | - |
|
330 | - protected function isShared() { |
|
331 | - if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
332 | - return false; |
|
333 | - } |
|
334 | - |
|
335 | - return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; |
|
336 | - } |
|
337 | - |
|
338 | - public function isSubscription() { |
|
339 | - return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']); |
|
340 | - } |
|
45 | + /** @var IConfig */ |
|
46 | + private $config; |
|
47 | + |
|
48 | + public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) { |
|
49 | + parent::__construct($caldavBackend, $calendarInfo); |
|
50 | + |
|
51 | + if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
52 | + $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays'); |
|
53 | + } |
|
54 | + if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI && |
|
55 | + $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) { |
|
56 | + $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal'); |
|
57 | + } |
|
58 | + |
|
59 | + $this->config = $config; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Updates the list of shares. |
|
64 | + * |
|
65 | + * The first array is a list of people that are to be added to the |
|
66 | + * resource. |
|
67 | + * |
|
68 | + * Every element in the add array has the following properties: |
|
69 | + * * href - A url. Usually a mailto: address |
|
70 | + * * commonName - Usually a first and last name, or false |
|
71 | + * * summary - A description of the share, can also be false |
|
72 | + * * readOnly - A boolean value |
|
73 | + * |
|
74 | + * Every element in the remove array is just the address string. |
|
75 | + * |
|
76 | + * @param array $add |
|
77 | + * @param array $remove |
|
78 | + * @return void |
|
79 | + * @throws Forbidden |
|
80 | + */ |
|
81 | + public function updateShares(array $add, array $remove) { |
|
82 | + if ($this->isShared()) { |
|
83 | + throw new Forbidden(); |
|
84 | + } |
|
85 | + $this->caldavBackend->updateShares($this, $add, $remove); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Returns the list of people whom this resource is shared with. |
|
90 | + * |
|
91 | + * Every element in this array should have the following properties: |
|
92 | + * * href - Often a mailto: address |
|
93 | + * * commonName - Optional, for example a first + last name |
|
94 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
95 | + * * readOnly - boolean |
|
96 | + * * summary - Optional, a description for the share |
|
97 | + * |
|
98 | + * @return array |
|
99 | + */ |
|
100 | + public function getShares() { |
|
101 | + if ($this->isShared()) { |
|
102 | + return []; |
|
103 | + } |
|
104 | + return $this->caldavBackend->getShares($this->getResourceId()); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @return int |
|
109 | + */ |
|
110 | + public function getResourceId() { |
|
111 | + return $this->calendarInfo['id']; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @return string |
|
116 | + */ |
|
117 | + public function getPrincipalURI() { |
|
118 | + return $this->calendarInfo['principaluri']; |
|
119 | + } |
|
120 | + |
|
121 | + public function getACL() { |
|
122 | + $acl = [ |
|
123 | + [ |
|
124 | + 'privilege' => '{DAV:}read', |
|
125 | + 'principal' => $this->getOwner(), |
|
126 | + 'protected' => true, |
|
127 | + ]]; |
|
128 | + if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
129 | + $acl[] = [ |
|
130 | + 'privilege' => '{DAV:}write', |
|
131 | + 'principal' => $this->getOwner(), |
|
132 | + 'protected' => true, |
|
133 | + ]; |
|
134 | + } else { |
|
135 | + $acl[] = [ |
|
136 | + 'privilege' => '{DAV:}write-properties', |
|
137 | + 'principal' => $this->getOwner(), |
|
138 | + 'protected' => true, |
|
139 | + ]; |
|
140 | + } |
|
141 | + |
|
142 | + if (!$this->isShared()) { |
|
143 | + return $acl; |
|
144 | + } |
|
145 | + |
|
146 | + if ($this->getOwner() !== parent::getOwner()) { |
|
147 | + $acl[] = [ |
|
148 | + 'privilege' => '{DAV:}read', |
|
149 | + 'principal' => parent::getOwner(), |
|
150 | + 'protected' => true, |
|
151 | + ]; |
|
152 | + if ($this->canWrite()) { |
|
153 | + $acl[] = [ |
|
154 | + 'privilege' => '{DAV:}write', |
|
155 | + 'principal' => parent::getOwner(), |
|
156 | + 'protected' => true, |
|
157 | + ]; |
|
158 | + } else { |
|
159 | + $acl[] = [ |
|
160 | + 'privilege' => '{DAV:}write-properties', |
|
161 | + 'principal' => parent::getOwner(), |
|
162 | + 'protected' => true, |
|
163 | + ]; |
|
164 | + } |
|
165 | + } |
|
166 | + if ($this->isPublic()) { |
|
167 | + $acl[] = [ |
|
168 | + 'privilege' => '{DAV:}read', |
|
169 | + 'principal' => 'principals/system/public', |
|
170 | + 'protected' => true, |
|
171 | + ]; |
|
172 | + } |
|
173 | + |
|
174 | + $acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
175 | + $allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public']; |
|
176 | + return array_filter($acl, function($rule) use ($allowedPrincipals) { |
|
177 | + return \in_array($rule['principal'], $allowedPrincipals, true); |
|
178 | + }); |
|
179 | + } |
|
180 | + |
|
181 | + public function getChildACL() { |
|
182 | + return $this->getACL(); |
|
183 | + } |
|
184 | + |
|
185 | + public function getOwner() { |
|
186 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
187 | + return $this->calendarInfo['{http://owncloud.org/ns}owner-principal']; |
|
188 | + } |
|
189 | + return parent::getOwner(); |
|
190 | + } |
|
191 | + |
|
192 | + public function delete() { |
|
193 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) && |
|
194 | + $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) { |
|
195 | + $principal = 'principal:' . parent::getOwner(); |
|
196 | + $shares = $this->caldavBackend->getShares($this->getResourceId()); |
|
197 | + $shares = array_filter($shares, function($share) use ($principal){ |
|
198 | + return $share['href'] === $principal; |
|
199 | + }); |
|
200 | + if (empty($shares)) { |
|
201 | + throw new Forbidden(); |
|
202 | + } |
|
203 | + |
|
204 | + $this->caldavBackend->updateShares($this, [], [ |
|
205 | + $principal |
|
206 | + ]); |
|
207 | + return; |
|
208 | + } |
|
209 | + |
|
210 | + // Remember when a user deleted their birthday calendar |
|
211 | + // in order to not regenerate it on the next contacts change |
|
212 | + if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
213 | + $principalURI = $this->getPrincipalURI(); |
|
214 | + $userId = substr($principalURI, 17); |
|
215 | + |
|
216 | + $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'no'); |
|
217 | + } |
|
218 | + |
|
219 | + parent::delete(); |
|
220 | + } |
|
221 | + |
|
222 | + public function propPatch(PropPatch $propPatch) { |
|
223 | + // parent::propPatch will only update calendars table |
|
224 | + // if calendar is shared, changes have to be made to the properties table |
|
225 | + if (!$this->isShared()) { |
|
226 | + parent::propPatch($propPatch); |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + public function getChild($name) { |
|
231 | + |
|
232 | + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
233 | + |
|
234 | + if (!$obj) { |
|
235 | + throw new NotFound('Calendar object not found'); |
|
236 | + } |
|
237 | + |
|
238 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
239 | + throw new NotFound('Calendar object not found'); |
|
240 | + } |
|
241 | + |
|
242 | + $obj['acl'] = $this->getChildACL(); |
|
243 | + |
|
244 | + return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
245 | + |
|
246 | + } |
|
247 | + |
|
248 | + public function getChildren() { |
|
249 | + |
|
250 | + $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']); |
|
251 | + $children = []; |
|
252 | + foreach ($objs as $obj) { |
|
253 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
254 | + continue; |
|
255 | + } |
|
256 | + $obj['acl'] = $this->getChildACL(); |
|
257 | + $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
258 | + } |
|
259 | + return $children; |
|
260 | + |
|
261 | + } |
|
262 | + |
|
263 | + public function getMultipleChildren(array $paths) { |
|
264 | + |
|
265 | + $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths); |
|
266 | + $children = []; |
|
267 | + foreach ($objs as $obj) { |
|
268 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
269 | + continue; |
|
270 | + } |
|
271 | + $obj['acl'] = $this->getChildACL(); |
|
272 | + $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
273 | + } |
|
274 | + return $children; |
|
275 | + |
|
276 | + } |
|
277 | + |
|
278 | + public function childExists($name) { |
|
279 | + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
280 | + if (!$obj) { |
|
281 | + return false; |
|
282 | + } |
|
283 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
284 | + return false; |
|
285 | + } |
|
286 | + |
|
287 | + return true; |
|
288 | + } |
|
289 | + |
|
290 | + public function calendarQuery(array $filters) { |
|
291 | + |
|
292 | + $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters); |
|
293 | + if ($this->isShared()) { |
|
294 | + return array_filter($uris, function ($uri) { |
|
295 | + return $this->childExists($uri); |
|
296 | + }); |
|
297 | + } |
|
298 | + |
|
299 | + return $uris; |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * @param boolean $value |
|
304 | + * @return string|null |
|
305 | + */ |
|
306 | + public function setPublishStatus($value) { |
|
307 | + $publicUri = $this->caldavBackend->setPublishStatus($value, $this); |
|
308 | + $this->calendarInfo['publicuri'] = $publicUri; |
|
309 | + return $publicUri; |
|
310 | + } |
|
311 | + |
|
312 | + /** |
|
313 | + * @return mixed $value |
|
314 | + */ |
|
315 | + public function getPublishStatus() { |
|
316 | + return $this->caldavBackend->getPublishStatus($this); |
|
317 | + } |
|
318 | + |
|
319 | + private function canWrite() { |
|
320 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { |
|
321 | + return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; |
|
322 | + } |
|
323 | + return true; |
|
324 | + } |
|
325 | + |
|
326 | + private function isPublic() { |
|
327 | + return isset($this->calendarInfo['{http://owncloud.org/ns}public']); |
|
328 | + } |
|
329 | + |
|
330 | + protected function isShared() { |
|
331 | + if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
332 | + return false; |
|
333 | + } |
|
334 | + |
|
335 | + return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; |
|
336 | + } |
|
337 | + |
|
338 | + public function isSubscription() { |
|
339 | + return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']); |
|
340 | + } |
|
341 | 341 | |
342 | 342 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | $this->config = $config; |
97 | 97 | |
98 | 98 | $this->excludedPaths[] = 'files_encryption'; |
99 | - $this->excludedPaths[] = 'appdata_' . $config->getSystemValue('instanceid', null); |
|
99 | + $this->excludedPaths[] = 'appdata_'.$config->getSystemValue('instanceid', null); |
|
100 | 100 | $this->excludedPaths[] = 'files_external'; |
101 | 101 | } |
102 | 102 | |
@@ -136,12 +136,12 @@ discard block |
||
136 | 136 | * @throws EncryptionHeaderKeyExistsException if header key is already in use |
137 | 137 | */ |
138 | 138 | public function createHeader(array $headerData, IEncryptionModule $encryptionModule) { |
139 | - $header = self::HEADER_START . ':' . self::HEADER_ENCRYPTION_MODULE_KEY . ':' . $encryptionModule->getId() . ':'; |
|
139 | + $header = self::HEADER_START.':'.self::HEADER_ENCRYPTION_MODULE_KEY.':'.$encryptionModule->getId().':'; |
|
140 | 140 | foreach ($headerData as $key => $value) { |
141 | 141 | if (in_array($key, $this->ocHeaderKeys)) { |
142 | 142 | throw new EncryptionHeaderKeyExistsException($key); |
143 | 143 | } |
144 | - $header .= $key . ':' . $value . ':'; |
|
144 | + $header .= $key.':'.$value.':'; |
|
145 | 145 | } |
146 | 146 | $header .= self::HEADER_END; |
147 | 147 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | if ($c->getType() === 'dir') { |
173 | 173 | $dirList[] = $c->getPath(); |
174 | 174 | } else { |
175 | - $result[] = $c->getPath(); |
|
175 | + $result[] = $c->getPath(); |
|
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
@@ -249,15 +249,15 @@ discard block |
||
249 | 249 | public function stripPartialFileExtension($path) { |
250 | 250 | $extension = pathinfo($path, PATHINFO_EXTENSION); |
251 | 251 | |
252 | - if ( $extension === 'part') { |
|
252 | + if ($extension === 'part') { |
|
253 | 253 | |
254 | 254 | $newLength = strlen($path) - 5; // 5 = strlen(".part") |
255 | 255 | $fPath = substr($path, 0, $newLength); |
256 | 256 | |
257 | 257 | // if path also contains a transaction id, we remove it too |
258 | 258 | $extension = pathinfo($fPath, PATHINFO_EXTENSION); |
259 | - if(substr($extension, 0, 12) === 'ocTransferId') { // 12 = strlen("ocTransferId") |
|
260 | - $newLength = strlen($fPath) - strlen($extension) -1; |
|
259 | + if (substr($extension, 0, 12) === 'ocTransferId') { // 12 = strlen("ocTransferId") |
|
260 | + $newLength = strlen($fPath) - strlen($extension) - 1; |
|
261 | 261 | $fPath = substr($fPath, 0, $newLength); |
262 | 262 | } |
263 | 263 | return $fPath; |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | if (\OCP\App::isEnabled("files_external")) { |
302 | 302 | $mounts = \OC_Mount_Config::getSystemMountPoints(); |
303 | 303 | foreach ($mounts as $mount) { |
304 | - if (strpos($path, '/files/' . $mount['mountpoint']) === 0) { |
|
304 | + if (strpos($path, '/files/'.$mount['mountpoint']) === 0) { |
|
305 | 305 | if ($this->isMountPointApplicableToUser($mount, $uid)) { |
306 | 306 | return true; |
307 | 307 | } |
@@ -39,374 +39,374 @@ |
||
39 | 39 | |
40 | 40 | class Util { |
41 | 41 | |
42 | - const HEADER_START = 'HBEGIN'; |
|
43 | - const HEADER_END = 'HEND'; |
|
44 | - const HEADER_PADDING_CHAR = '-'; |
|
45 | - |
|
46 | - const HEADER_ENCRYPTION_MODULE_KEY = 'oc_encryption_module'; |
|
47 | - |
|
48 | - /** |
|
49 | - * block size will always be 8192 for a PHP stream |
|
50 | - * @see https://bugs.php.net/bug.php?id=21641 |
|
51 | - * @var integer |
|
52 | - */ |
|
53 | - protected $headerSize = 8192; |
|
54 | - |
|
55 | - /** |
|
56 | - * block size will always be 8192 for a PHP stream |
|
57 | - * @see https://bugs.php.net/bug.php?id=21641 |
|
58 | - * @var integer |
|
59 | - */ |
|
60 | - protected $blockSize = 8192; |
|
61 | - |
|
62 | - /** @var View */ |
|
63 | - protected $rootView; |
|
64 | - |
|
65 | - /** @var array */ |
|
66 | - protected $ocHeaderKeys; |
|
67 | - |
|
68 | - /** @var \OC\User\Manager */ |
|
69 | - protected $userManager; |
|
70 | - |
|
71 | - /** @var IConfig */ |
|
72 | - protected $config; |
|
73 | - |
|
74 | - /** @var array paths excluded from encryption */ |
|
75 | - protected $excludedPaths; |
|
76 | - |
|
77 | - /** @var \OC\Group\Manager $manager */ |
|
78 | - protected $groupManager; |
|
79 | - |
|
80 | - /** |
|
81 | - * |
|
82 | - * @param View $rootView |
|
83 | - * @param \OC\User\Manager $userManager |
|
84 | - * @param \OC\Group\Manager $groupManager |
|
85 | - * @param IConfig $config |
|
86 | - */ |
|
87 | - public function __construct( |
|
88 | - View $rootView, |
|
89 | - \OC\User\Manager $userManager, |
|
90 | - \OC\Group\Manager $groupManager, |
|
91 | - IConfig $config) { |
|
92 | - |
|
93 | - $this->ocHeaderKeys = [ |
|
94 | - self::HEADER_ENCRYPTION_MODULE_KEY |
|
95 | - ]; |
|
96 | - |
|
97 | - $this->rootView = $rootView; |
|
98 | - $this->userManager = $userManager; |
|
99 | - $this->groupManager = $groupManager; |
|
100 | - $this->config = $config; |
|
101 | - |
|
102 | - $this->excludedPaths[] = 'files_encryption'; |
|
103 | - $this->excludedPaths[] = 'appdata_' . $config->getSystemValue('instanceid', null); |
|
104 | - $this->excludedPaths[] = 'files_external'; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * read encryption module ID from header |
|
109 | - * |
|
110 | - * @param array $header |
|
111 | - * @return string |
|
112 | - * @throws ModuleDoesNotExistsException |
|
113 | - */ |
|
114 | - public function getEncryptionModuleId(array $header = null) { |
|
115 | - $id = ''; |
|
116 | - $encryptionModuleKey = self::HEADER_ENCRYPTION_MODULE_KEY; |
|
117 | - |
|
118 | - if (isset($header[$encryptionModuleKey])) { |
|
119 | - $id = $header[$encryptionModuleKey]; |
|
120 | - } elseif (isset($header['cipher'])) { |
|
121 | - if (class_exists('\OCA\Encryption\Crypto\Encryption')) { |
|
122 | - // fall back to default encryption if the user migrated from |
|
123 | - // ownCloud <= 8.0 with the old encryption |
|
124 | - $id = \OCA\Encryption\Crypto\Encryption::ID; |
|
125 | - } else { |
|
126 | - throw new ModuleDoesNotExistsException('Default encryption module missing'); |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - return $id; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * create header for encrypted file |
|
135 | - * |
|
136 | - * @param array $headerData |
|
137 | - * @param IEncryptionModule $encryptionModule |
|
138 | - * @return string |
|
139 | - * @throws EncryptionHeaderToLargeException if header has to many arguments |
|
140 | - * @throws EncryptionHeaderKeyExistsException if header key is already in use |
|
141 | - */ |
|
142 | - public function createHeader(array $headerData, IEncryptionModule $encryptionModule) { |
|
143 | - $header = self::HEADER_START . ':' . self::HEADER_ENCRYPTION_MODULE_KEY . ':' . $encryptionModule->getId() . ':'; |
|
144 | - foreach ($headerData as $key => $value) { |
|
145 | - if (in_array($key, $this->ocHeaderKeys)) { |
|
146 | - throw new EncryptionHeaderKeyExistsException($key); |
|
147 | - } |
|
148 | - $header .= $key . ':' . $value . ':'; |
|
149 | - } |
|
150 | - $header .= self::HEADER_END; |
|
151 | - |
|
152 | - if (strlen($header) > $this->getHeaderSize()) { |
|
153 | - throw new EncryptionHeaderToLargeException(); |
|
154 | - } |
|
155 | - |
|
156 | - $paddedHeader = str_pad($header, $this->headerSize, self::HEADER_PADDING_CHAR, STR_PAD_RIGHT); |
|
157 | - |
|
158 | - return $paddedHeader; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * go recursively through a dir and collect all files and sub files. |
|
163 | - * |
|
164 | - * @param string $dir relative to the users files folder |
|
165 | - * @return array with list of files relative to the users files folder |
|
166 | - */ |
|
167 | - public function getAllFiles($dir) { |
|
168 | - $result = array(); |
|
169 | - $dirList = array($dir); |
|
170 | - |
|
171 | - while ($dirList) { |
|
172 | - $dir = array_pop($dirList); |
|
173 | - $content = $this->rootView->getDirectoryContent($dir); |
|
174 | - |
|
175 | - foreach ($content as $c) { |
|
176 | - if ($c->getType() === 'dir') { |
|
177 | - $dirList[] = $c->getPath(); |
|
178 | - } else { |
|
179 | - $result[] = $c->getPath(); |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - } |
|
184 | - |
|
185 | - return $result; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * check if it is a file uploaded by the user stored in data/user/files |
|
190 | - * or a metadata file |
|
191 | - * |
|
192 | - * @param string $path relative to the data/ folder |
|
193 | - * @return boolean |
|
194 | - */ |
|
195 | - public function isFile($path) { |
|
196 | - $parts = explode('/', Filesystem::normalizePath($path), 4); |
|
197 | - if (isset($parts[2]) && $parts[2] === 'files') { |
|
198 | - return true; |
|
199 | - } |
|
200 | - return false; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * return size of encryption header |
|
205 | - * |
|
206 | - * @return integer |
|
207 | - */ |
|
208 | - public function getHeaderSize() { |
|
209 | - return $this->headerSize; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * return size of block read by a PHP stream |
|
214 | - * |
|
215 | - * @return integer |
|
216 | - */ |
|
217 | - public function getBlockSize() { |
|
218 | - return $this->blockSize; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * get the owner and the path for the file relative to the owners files folder |
|
223 | - * |
|
224 | - * @param string $path |
|
225 | - * @return array |
|
226 | - * @throws \BadMethodCallException |
|
227 | - */ |
|
228 | - public function getUidAndFilename($path) { |
|
229 | - |
|
230 | - $parts = explode('/', $path); |
|
231 | - $uid = ''; |
|
232 | - if (count($parts) > 2) { |
|
233 | - $uid = $parts[1]; |
|
234 | - } |
|
235 | - if (!$this->userManager->userExists($uid)) { |
|
236 | - throw new \BadMethodCallException( |
|
237 | - 'path needs to be relative to the system wide data folder and point to a user specific file' |
|
238 | - ); |
|
239 | - } |
|
240 | - |
|
241 | - $ownerPath = implode('/', array_slice($parts, 2)); |
|
242 | - |
|
243 | - return array($uid, Filesystem::normalizePath($ownerPath)); |
|
244 | - |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * Remove .path extension from a file path |
|
249 | - * @param string $path Path that may identify a .part file |
|
250 | - * @return string File path without .part extension |
|
251 | - * @note this is needed for reusing keys |
|
252 | - */ |
|
253 | - public function stripPartialFileExtension($path) { |
|
254 | - $extension = pathinfo($path, PATHINFO_EXTENSION); |
|
255 | - |
|
256 | - if ( $extension === 'part') { |
|
257 | - |
|
258 | - $newLength = strlen($path) - 5; // 5 = strlen(".part") |
|
259 | - $fPath = substr($path, 0, $newLength); |
|
260 | - |
|
261 | - // if path also contains a transaction id, we remove it too |
|
262 | - $extension = pathinfo($fPath, PATHINFO_EXTENSION); |
|
263 | - if(substr($extension, 0, 12) === 'ocTransferId') { // 12 = strlen("ocTransferId") |
|
264 | - $newLength = strlen($fPath) - strlen($extension) -1; |
|
265 | - $fPath = substr($fPath, 0, $newLength); |
|
266 | - } |
|
267 | - return $fPath; |
|
268 | - |
|
269 | - } else { |
|
270 | - return $path; |
|
271 | - } |
|
272 | - } |
|
273 | - |
|
274 | - public function getUserWithAccessToMountPoint($users, $groups) { |
|
275 | - $result = []; |
|
276 | - if (in_array('all', $users)) { |
|
277 | - $users = $this->userManager->search('', null, null); |
|
278 | - $result = array_map(function(IUser $user) { |
|
279 | - return $user->getUID(); |
|
280 | - }, $users); |
|
281 | - } else { |
|
282 | - $result = array_merge($result, $users); |
|
283 | - |
|
284 | - $groupManager = \OC::$server->getGroupManager(); |
|
285 | - foreach ($groups as $group) { |
|
286 | - $groupObject = $groupManager->get($group); |
|
287 | - if ($groupObject) { |
|
288 | - $foundUsers = $groupObject->searchUsers('', -1, 0); |
|
289 | - $userIds = []; |
|
290 | - foreach ($foundUsers as $user) { |
|
291 | - $userIds[] = $user->getUID(); |
|
292 | - } |
|
293 | - $result = array_merge($result, $userIds); |
|
294 | - } |
|
295 | - } |
|
296 | - } |
|
297 | - |
|
298 | - return $result; |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * check if the file is stored on a system wide mount point |
|
303 | - * @param string $path relative to /data/user with leading '/' |
|
304 | - * @param string $uid |
|
305 | - * @return boolean |
|
306 | - */ |
|
307 | - public function isSystemWideMountPoint($path, $uid) { |
|
308 | - if (\OCP\App::isEnabled("files_external")) { |
|
309 | - $mounts = \OC_Mount_Config::getSystemMountPoints(); |
|
310 | - foreach ($mounts as $mount) { |
|
311 | - if (strpos($path, '/files/' . $mount['mountpoint']) === 0) { |
|
312 | - if ($this->isMountPointApplicableToUser($mount, $uid)) { |
|
313 | - return true; |
|
314 | - } |
|
315 | - } |
|
316 | - } |
|
317 | - } |
|
318 | - return false; |
|
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * check if mount point is applicable to user |
|
323 | - * |
|
324 | - * @param array $mount contains $mount['applicable']['users'], $mount['applicable']['groups'] |
|
325 | - * @param string $uid |
|
326 | - * @return boolean |
|
327 | - */ |
|
328 | - private function isMountPointApplicableToUser($mount, $uid) { |
|
329 | - $acceptedUids = array('all', $uid); |
|
330 | - // check if mount point is applicable for the user |
|
331 | - $intersection = array_intersect($acceptedUids, $mount['applicable']['users']); |
|
332 | - if (!empty($intersection)) { |
|
333 | - return true; |
|
334 | - } |
|
335 | - // check if mount point is applicable for group where the user is a member |
|
336 | - foreach ($mount['applicable']['groups'] as $gid) { |
|
337 | - if ($this->groupManager->isInGroup($uid, $gid)) { |
|
338 | - return true; |
|
339 | - } |
|
340 | - } |
|
341 | - return false; |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * check if it is a path which is excluded by ownCloud from encryption |
|
346 | - * |
|
347 | - * @param string $path |
|
348 | - * @return boolean |
|
349 | - */ |
|
350 | - public function isExcluded($path) { |
|
351 | - $normalizedPath = Filesystem::normalizePath($path); |
|
352 | - $root = explode('/', $normalizedPath, 4); |
|
353 | - if (count($root) > 1) { |
|
354 | - |
|
355 | - // detect alternative key storage root |
|
356 | - $rootDir = $this->getKeyStorageRoot(); |
|
357 | - if ($rootDir !== '' && |
|
358 | - 0 === strpos( |
|
359 | - Filesystem::normalizePath($path), |
|
360 | - Filesystem::normalizePath($rootDir) |
|
361 | - ) |
|
362 | - ) { |
|
363 | - return true; |
|
364 | - } |
|
365 | - |
|
366 | - |
|
367 | - //detect system wide folders |
|
368 | - if (in_array($root[1], $this->excludedPaths)) { |
|
369 | - return true; |
|
370 | - } |
|
371 | - |
|
372 | - // detect user specific folders |
|
373 | - if ($this->userManager->userExists($root[1]) |
|
374 | - && in_array($root[2], $this->excludedPaths)) { |
|
375 | - |
|
376 | - return true; |
|
377 | - } |
|
378 | - } |
|
379 | - return false; |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * check if recovery key is enabled for user |
|
384 | - * |
|
385 | - * @param string $uid |
|
386 | - * @return boolean |
|
387 | - */ |
|
388 | - public function recoveryEnabled($uid) { |
|
389 | - $enabled = $this->config->getUserValue($uid, 'encryption', 'recovery_enabled', '0'); |
|
390 | - |
|
391 | - return $enabled === '1'; |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * set new key storage root |
|
396 | - * |
|
397 | - * @param string $root new key store root relative to the data folder |
|
398 | - */ |
|
399 | - public function setKeyStorageRoot($root) { |
|
400 | - $this->config->setAppValue('core', 'encryption_key_storage_root', $root); |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * get key storage root |
|
405 | - * |
|
406 | - * @return string key storage root |
|
407 | - */ |
|
408 | - public function getKeyStorageRoot() { |
|
409 | - return $this->config->getAppValue('core', 'encryption_key_storage_root', ''); |
|
410 | - } |
|
42 | + const HEADER_START = 'HBEGIN'; |
|
43 | + const HEADER_END = 'HEND'; |
|
44 | + const HEADER_PADDING_CHAR = '-'; |
|
45 | + |
|
46 | + const HEADER_ENCRYPTION_MODULE_KEY = 'oc_encryption_module'; |
|
47 | + |
|
48 | + /** |
|
49 | + * block size will always be 8192 for a PHP stream |
|
50 | + * @see https://bugs.php.net/bug.php?id=21641 |
|
51 | + * @var integer |
|
52 | + */ |
|
53 | + protected $headerSize = 8192; |
|
54 | + |
|
55 | + /** |
|
56 | + * block size will always be 8192 for a PHP stream |
|
57 | + * @see https://bugs.php.net/bug.php?id=21641 |
|
58 | + * @var integer |
|
59 | + */ |
|
60 | + protected $blockSize = 8192; |
|
61 | + |
|
62 | + /** @var View */ |
|
63 | + protected $rootView; |
|
64 | + |
|
65 | + /** @var array */ |
|
66 | + protected $ocHeaderKeys; |
|
67 | + |
|
68 | + /** @var \OC\User\Manager */ |
|
69 | + protected $userManager; |
|
70 | + |
|
71 | + /** @var IConfig */ |
|
72 | + protected $config; |
|
73 | + |
|
74 | + /** @var array paths excluded from encryption */ |
|
75 | + protected $excludedPaths; |
|
76 | + |
|
77 | + /** @var \OC\Group\Manager $manager */ |
|
78 | + protected $groupManager; |
|
79 | + |
|
80 | + /** |
|
81 | + * |
|
82 | + * @param View $rootView |
|
83 | + * @param \OC\User\Manager $userManager |
|
84 | + * @param \OC\Group\Manager $groupManager |
|
85 | + * @param IConfig $config |
|
86 | + */ |
|
87 | + public function __construct( |
|
88 | + View $rootView, |
|
89 | + \OC\User\Manager $userManager, |
|
90 | + \OC\Group\Manager $groupManager, |
|
91 | + IConfig $config) { |
|
92 | + |
|
93 | + $this->ocHeaderKeys = [ |
|
94 | + self::HEADER_ENCRYPTION_MODULE_KEY |
|
95 | + ]; |
|
96 | + |
|
97 | + $this->rootView = $rootView; |
|
98 | + $this->userManager = $userManager; |
|
99 | + $this->groupManager = $groupManager; |
|
100 | + $this->config = $config; |
|
101 | + |
|
102 | + $this->excludedPaths[] = 'files_encryption'; |
|
103 | + $this->excludedPaths[] = 'appdata_' . $config->getSystemValue('instanceid', null); |
|
104 | + $this->excludedPaths[] = 'files_external'; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * read encryption module ID from header |
|
109 | + * |
|
110 | + * @param array $header |
|
111 | + * @return string |
|
112 | + * @throws ModuleDoesNotExistsException |
|
113 | + */ |
|
114 | + public function getEncryptionModuleId(array $header = null) { |
|
115 | + $id = ''; |
|
116 | + $encryptionModuleKey = self::HEADER_ENCRYPTION_MODULE_KEY; |
|
117 | + |
|
118 | + if (isset($header[$encryptionModuleKey])) { |
|
119 | + $id = $header[$encryptionModuleKey]; |
|
120 | + } elseif (isset($header['cipher'])) { |
|
121 | + if (class_exists('\OCA\Encryption\Crypto\Encryption')) { |
|
122 | + // fall back to default encryption if the user migrated from |
|
123 | + // ownCloud <= 8.0 with the old encryption |
|
124 | + $id = \OCA\Encryption\Crypto\Encryption::ID; |
|
125 | + } else { |
|
126 | + throw new ModuleDoesNotExistsException('Default encryption module missing'); |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + return $id; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * create header for encrypted file |
|
135 | + * |
|
136 | + * @param array $headerData |
|
137 | + * @param IEncryptionModule $encryptionModule |
|
138 | + * @return string |
|
139 | + * @throws EncryptionHeaderToLargeException if header has to many arguments |
|
140 | + * @throws EncryptionHeaderKeyExistsException if header key is already in use |
|
141 | + */ |
|
142 | + public function createHeader(array $headerData, IEncryptionModule $encryptionModule) { |
|
143 | + $header = self::HEADER_START . ':' . self::HEADER_ENCRYPTION_MODULE_KEY . ':' . $encryptionModule->getId() . ':'; |
|
144 | + foreach ($headerData as $key => $value) { |
|
145 | + if (in_array($key, $this->ocHeaderKeys)) { |
|
146 | + throw new EncryptionHeaderKeyExistsException($key); |
|
147 | + } |
|
148 | + $header .= $key . ':' . $value . ':'; |
|
149 | + } |
|
150 | + $header .= self::HEADER_END; |
|
151 | + |
|
152 | + if (strlen($header) > $this->getHeaderSize()) { |
|
153 | + throw new EncryptionHeaderToLargeException(); |
|
154 | + } |
|
155 | + |
|
156 | + $paddedHeader = str_pad($header, $this->headerSize, self::HEADER_PADDING_CHAR, STR_PAD_RIGHT); |
|
157 | + |
|
158 | + return $paddedHeader; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * go recursively through a dir and collect all files and sub files. |
|
163 | + * |
|
164 | + * @param string $dir relative to the users files folder |
|
165 | + * @return array with list of files relative to the users files folder |
|
166 | + */ |
|
167 | + public function getAllFiles($dir) { |
|
168 | + $result = array(); |
|
169 | + $dirList = array($dir); |
|
170 | + |
|
171 | + while ($dirList) { |
|
172 | + $dir = array_pop($dirList); |
|
173 | + $content = $this->rootView->getDirectoryContent($dir); |
|
174 | + |
|
175 | + foreach ($content as $c) { |
|
176 | + if ($c->getType() === 'dir') { |
|
177 | + $dirList[] = $c->getPath(); |
|
178 | + } else { |
|
179 | + $result[] = $c->getPath(); |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + } |
|
184 | + |
|
185 | + return $result; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * check if it is a file uploaded by the user stored in data/user/files |
|
190 | + * or a metadata file |
|
191 | + * |
|
192 | + * @param string $path relative to the data/ folder |
|
193 | + * @return boolean |
|
194 | + */ |
|
195 | + public function isFile($path) { |
|
196 | + $parts = explode('/', Filesystem::normalizePath($path), 4); |
|
197 | + if (isset($parts[2]) && $parts[2] === 'files') { |
|
198 | + return true; |
|
199 | + } |
|
200 | + return false; |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * return size of encryption header |
|
205 | + * |
|
206 | + * @return integer |
|
207 | + */ |
|
208 | + public function getHeaderSize() { |
|
209 | + return $this->headerSize; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * return size of block read by a PHP stream |
|
214 | + * |
|
215 | + * @return integer |
|
216 | + */ |
|
217 | + public function getBlockSize() { |
|
218 | + return $this->blockSize; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * get the owner and the path for the file relative to the owners files folder |
|
223 | + * |
|
224 | + * @param string $path |
|
225 | + * @return array |
|
226 | + * @throws \BadMethodCallException |
|
227 | + */ |
|
228 | + public function getUidAndFilename($path) { |
|
229 | + |
|
230 | + $parts = explode('/', $path); |
|
231 | + $uid = ''; |
|
232 | + if (count($parts) > 2) { |
|
233 | + $uid = $parts[1]; |
|
234 | + } |
|
235 | + if (!$this->userManager->userExists($uid)) { |
|
236 | + throw new \BadMethodCallException( |
|
237 | + 'path needs to be relative to the system wide data folder and point to a user specific file' |
|
238 | + ); |
|
239 | + } |
|
240 | + |
|
241 | + $ownerPath = implode('/', array_slice($parts, 2)); |
|
242 | + |
|
243 | + return array($uid, Filesystem::normalizePath($ownerPath)); |
|
244 | + |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * Remove .path extension from a file path |
|
249 | + * @param string $path Path that may identify a .part file |
|
250 | + * @return string File path without .part extension |
|
251 | + * @note this is needed for reusing keys |
|
252 | + */ |
|
253 | + public function stripPartialFileExtension($path) { |
|
254 | + $extension = pathinfo($path, PATHINFO_EXTENSION); |
|
255 | + |
|
256 | + if ( $extension === 'part') { |
|
257 | + |
|
258 | + $newLength = strlen($path) - 5; // 5 = strlen(".part") |
|
259 | + $fPath = substr($path, 0, $newLength); |
|
260 | + |
|
261 | + // if path also contains a transaction id, we remove it too |
|
262 | + $extension = pathinfo($fPath, PATHINFO_EXTENSION); |
|
263 | + if(substr($extension, 0, 12) === 'ocTransferId') { // 12 = strlen("ocTransferId") |
|
264 | + $newLength = strlen($fPath) - strlen($extension) -1; |
|
265 | + $fPath = substr($fPath, 0, $newLength); |
|
266 | + } |
|
267 | + return $fPath; |
|
268 | + |
|
269 | + } else { |
|
270 | + return $path; |
|
271 | + } |
|
272 | + } |
|
273 | + |
|
274 | + public function getUserWithAccessToMountPoint($users, $groups) { |
|
275 | + $result = []; |
|
276 | + if (in_array('all', $users)) { |
|
277 | + $users = $this->userManager->search('', null, null); |
|
278 | + $result = array_map(function(IUser $user) { |
|
279 | + return $user->getUID(); |
|
280 | + }, $users); |
|
281 | + } else { |
|
282 | + $result = array_merge($result, $users); |
|
283 | + |
|
284 | + $groupManager = \OC::$server->getGroupManager(); |
|
285 | + foreach ($groups as $group) { |
|
286 | + $groupObject = $groupManager->get($group); |
|
287 | + if ($groupObject) { |
|
288 | + $foundUsers = $groupObject->searchUsers('', -1, 0); |
|
289 | + $userIds = []; |
|
290 | + foreach ($foundUsers as $user) { |
|
291 | + $userIds[] = $user->getUID(); |
|
292 | + } |
|
293 | + $result = array_merge($result, $userIds); |
|
294 | + } |
|
295 | + } |
|
296 | + } |
|
297 | + |
|
298 | + return $result; |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * check if the file is stored on a system wide mount point |
|
303 | + * @param string $path relative to /data/user with leading '/' |
|
304 | + * @param string $uid |
|
305 | + * @return boolean |
|
306 | + */ |
|
307 | + public function isSystemWideMountPoint($path, $uid) { |
|
308 | + if (\OCP\App::isEnabled("files_external")) { |
|
309 | + $mounts = \OC_Mount_Config::getSystemMountPoints(); |
|
310 | + foreach ($mounts as $mount) { |
|
311 | + if (strpos($path, '/files/' . $mount['mountpoint']) === 0) { |
|
312 | + if ($this->isMountPointApplicableToUser($mount, $uid)) { |
|
313 | + return true; |
|
314 | + } |
|
315 | + } |
|
316 | + } |
|
317 | + } |
|
318 | + return false; |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * check if mount point is applicable to user |
|
323 | + * |
|
324 | + * @param array $mount contains $mount['applicable']['users'], $mount['applicable']['groups'] |
|
325 | + * @param string $uid |
|
326 | + * @return boolean |
|
327 | + */ |
|
328 | + private function isMountPointApplicableToUser($mount, $uid) { |
|
329 | + $acceptedUids = array('all', $uid); |
|
330 | + // check if mount point is applicable for the user |
|
331 | + $intersection = array_intersect($acceptedUids, $mount['applicable']['users']); |
|
332 | + if (!empty($intersection)) { |
|
333 | + return true; |
|
334 | + } |
|
335 | + // check if mount point is applicable for group where the user is a member |
|
336 | + foreach ($mount['applicable']['groups'] as $gid) { |
|
337 | + if ($this->groupManager->isInGroup($uid, $gid)) { |
|
338 | + return true; |
|
339 | + } |
|
340 | + } |
|
341 | + return false; |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * check if it is a path which is excluded by ownCloud from encryption |
|
346 | + * |
|
347 | + * @param string $path |
|
348 | + * @return boolean |
|
349 | + */ |
|
350 | + public function isExcluded($path) { |
|
351 | + $normalizedPath = Filesystem::normalizePath($path); |
|
352 | + $root = explode('/', $normalizedPath, 4); |
|
353 | + if (count($root) > 1) { |
|
354 | + |
|
355 | + // detect alternative key storage root |
|
356 | + $rootDir = $this->getKeyStorageRoot(); |
|
357 | + if ($rootDir !== '' && |
|
358 | + 0 === strpos( |
|
359 | + Filesystem::normalizePath($path), |
|
360 | + Filesystem::normalizePath($rootDir) |
|
361 | + ) |
|
362 | + ) { |
|
363 | + return true; |
|
364 | + } |
|
365 | + |
|
366 | + |
|
367 | + //detect system wide folders |
|
368 | + if (in_array($root[1], $this->excludedPaths)) { |
|
369 | + return true; |
|
370 | + } |
|
371 | + |
|
372 | + // detect user specific folders |
|
373 | + if ($this->userManager->userExists($root[1]) |
|
374 | + && in_array($root[2], $this->excludedPaths)) { |
|
375 | + |
|
376 | + return true; |
|
377 | + } |
|
378 | + } |
|
379 | + return false; |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * check if recovery key is enabled for user |
|
384 | + * |
|
385 | + * @param string $uid |
|
386 | + * @return boolean |
|
387 | + */ |
|
388 | + public function recoveryEnabled($uid) { |
|
389 | + $enabled = $this->config->getUserValue($uid, 'encryption', 'recovery_enabled', '0'); |
|
390 | + |
|
391 | + return $enabled === '1'; |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * set new key storage root |
|
396 | + * |
|
397 | + * @param string $root new key store root relative to the data folder |
|
398 | + */ |
|
399 | + public function setKeyStorageRoot($root) { |
|
400 | + $this->config->setAppValue('core', 'encryption_key_storage_root', $root); |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * get key storage root |
|
405 | + * |
|
406 | + * @return string key storage root |
|
407 | + */ |
|
408 | + public function getKeyStorageRoot() { |
|
409 | + return $this->config->getAppValue('core', 'encryption_key_storage_root', ''); |
|
410 | + } |
|
411 | 411 | |
412 | 412 | } |
@@ -30,33 +30,33 @@ |
||
30 | 30 | |
31 | 31 | class ManagerFactory implements ICommentsManagerFactory { |
32 | 32 | |
33 | - /** |
|
34 | - * Server container |
|
35 | - * |
|
36 | - * @var IServerContainer |
|
37 | - */ |
|
38 | - private $serverContainer; |
|
33 | + /** |
|
34 | + * Server container |
|
35 | + * |
|
36 | + * @var IServerContainer |
|
37 | + */ |
|
38 | + private $serverContainer; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Constructor for the comments manager factory |
|
42 | - * |
|
43 | - * @param IServerContainer $serverContainer server container |
|
44 | - */ |
|
45 | - public function __construct(IServerContainer $serverContainer) { |
|
46 | - $this->serverContainer = $serverContainer; |
|
47 | - } |
|
40 | + /** |
|
41 | + * Constructor for the comments manager factory |
|
42 | + * |
|
43 | + * @param IServerContainer $serverContainer server container |
|
44 | + */ |
|
45 | + public function __construct(IServerContainer $serverContainer) { |
|
46 | + $this->serverContainer = $serverContainer; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * creates and returns an instance of the ICommentsManager |
|
51 | - * |
|
52 | - * @return ICommentsManager |
|
53 | - * @since 9.0.0 |
|
54 | - */ |
|
55 | - public function getManager() { |
|
56 | - return new Manager( |
|
57 | - $this->serverContainer->getDatabaseConnection(), |
|
58 | - $this->serverContainer->getLogger(), |
|
59 | - $this->serverContainer->getConfig() |
|
60 | - ); |
|
61 | - } |
|
49 | + /** |
|
50 | + * creates and returns an instance of the ICommentsManager |
|
51 | + * |
|
52 | + * @return ICommentsManager |
|
53 | + * @since 9.0.0 |
|
54 | + */ |
|
55 | + public function getManager() { |
|
56 | + return new Manager( |
|
57 | + $this->serverContainer->getDatabaseConnection(), |
|
58 | + $this->serverContainer->getLogger(), |
|
59 | + $this->serverContainer->getConfig() |
|
60 | + ); |
|
61 | + } |
|
62 | 62 | } |
@@ -24,16 +24,16 @@ |
||
24 | 24 | use Sabre\DAV\Tree; |
25 | 25 | |
26 | 26 | class CachingTree extends Tree { |
27 | - /** |
|
28 | - * Store a node in the cache |
|
29 | - * |
|
30 | - * @param Node $node |
|
31 | - * @param null|string $path |
|
32 | - */ |
|
33 | - public function cacheNode(Node $node, $path = null) { |
|
34 | - if (is_null($path)) { |
|
35 | - $path = $node->getPath(); |
|
36 | - } |
|
37 | - $this->cache[trim($path, '/')] = $node; |
|
38 | - } |
|
27 | + /** |
|
28 | + * Store a node in the cache |
|
29 | + * |
|
30 | + * @param Node $node |
|
31 | + * @param null|string $path |
|
32 | + */ |
|
33 | + public function cacheNode(Node $node, $path = null) { |
|
34 | + if (is_null($path)) { |
|
35 | + $path = $node->getPath(); |
|
36 | + } |
|
37 | + $this->cache[trim($path, '/')] = $node; |
|
38 | + } |
|
39 | 39 | } |
@@ -33,14 +33,14 @@ |
||
33 | 33 | * @see \Sabre\DAV\Server |
34 | 34 | */ |
35 | 35 | class Server extends \Sabre\DAV\Server { |
36 | - /** @var CachingTree $tree */ |
|
36 | + /** @var CachingTree $tree */ |
|
37 | 37 | |
38 | - /** |
|
39 | - * @see \Sabre\DAV\Server |
|
40 | - */ |
|
41 | - public function __construct($treeOrNode = null) { |
|
42 | - parent::__construct($treeOrNode); |
|
43 | - self::$exposeVersion = false; |
|
44 | - $this->enablePropfindDepthInfinity = true; |
|
45 | - } |
|
38 | + /** |
|
39 | + * @see \Sabre\DAV\Server |
|
40 | + */ |
|
41 | + public function __construct($treeOrNode = null) { |
|
42 | + parent::__construct($treeOrNode); |
|
43 | + self::$exposeVersion = false; |
|
44 | + $this->enablePropfindDepthInfinity = true; |
|
45 | + } |
|
46 | 46 | } |
@@ -1,12 +1,12 @@ |
||
1 | 1 | <div class="error"> |
2 | 2 | <h2><?php p($l->t('Error')) ?></h2> |
3 | 3 | <ul> |
4 | - <?php foreach($_["errors"] as $error):?> |
|
4 | + <?php foreach ($_["errors"] as $error):?> |
|
5 | 5 | <li> |
6 | 6 | <p><?php p($error['error']) ?></p> |
7 | - <?php if(isset($error['hint']) && $error['hint']): ?> |
|
7 | + <?php if (isset($error['hint']) && $error['hint']): ?> |
|
8 | 8 | <p class='hint'><?php p($error['hint']) ?></p> |
9 | - <?php endif;?> |
|
9 | + <?php endif; ?> |
|
10 | 10 | </li> |
11 | 11 | <?php endforeach ?> |
12 | 12 | </ul> |
@@ -33,304 +33,304 @@ |
||
33 | 33 | |
34 | 34 | class Activity implements IProvider { |
35 | 35 | |
36 | - /** @var IFactory */ |
|
37 | - protected $languageFactory; |
|
38 | - |
|
39 | - /** @var IL10N */ |
|
40 | - protected $l; |
|
41 | - |
|
42 | - /** @var IURLGenerator */ |
|
43 | - protected $url; |
|
44 | - |
|
45 | - /** @var IManager */ |
|
46 | - protected $activityManager; |
|
47 | - |
|
48 | - /** @var IUserManager */ |
|
49 | - protected $userManager; |
|
50 | - /** @var IContactsManager */ |
|
51 | - protected $contactsManager; |
|
52 | - |
|
53 | - /** @var array */ |
|
54 | - protected $displayNames = []; |
|
55 | - |
|
56 | - /** @var array */ |
|
57 | - protected $contactNames = []; |
|
58 | - |
|
59 | - const SUBJECT_SHARED_EMAIL_SELF = 'shared_with_email_self'; |
|
60 | - const SUBJECT_SHARED_EMAIL_BY = 'shared_with_email_by'; |
|
61 | - const SUBJECT_SHARED_EMAIL_PASSWORD_SEND = 'shared_with_email_password_send'; |
|
62 | - const SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF = 'shared_with_email_password_send_self'; |
|
63 | - |
|
64 | - /** |
|
65 | - * @param IFactory $languageFactory |
|
66 | - * @param IURLGenerator $url |
|
67 | - * @param IManager $activityManager |
|
68 | - * @param IUserManager $userManager |
|
69 | - * @param IContactsManager $contactsManager |
|
70 | - */ |
|
71 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IContactsManager $contactsManager) { |
|
72 | - $this->languageFactory = $languageFactory; |
|
73 | - $this->url = $url; |
|
74 | - $this->activityManager = $activityManager; |
|
75 | - $this->userManager = $userManager; |
|
76 | - $this->contactsManager = $contactsManager; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @param string $language |
|
81 | - * @param IEvent $event |
|
82 | - * @param IEvent|null $previousEvent |
|
83 | - * @return IEvent |
|
84 | - * @throws \InvalidArgumentException |
|
85 | - * @since 11.0.0 |
|
86 | - */ |
|
87 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
88 | - if ($event->getApp() !== 'sharebymail') { |
|
89 | - throw new \InvalidArgumentException(); |
|
90 | - } |
|
91 | - |
|
92 | - $this->l = $this->languageFactory->get('sharebymail', $language); |
|
93 | - |
|
94 | - if ($this->activityManager->isFormattingFilteredObject()) { |
|
95 | - try { |
|
96 | - return $this->parseShortVersion($event); |
|
97 | - } catch (\InvalidArgumentException $e) { |
|
98 | - // Ignore and simply use the long version... |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - return $this->parseLongVersion($event); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @param IEvent $event |
|
107 | - * @return IEvent |
|
108 | - * @throws \InvalidArgumentException |
|
109 | - * @since 11.0.0 |
|
110 | - */ |
|
111 | - public function parseShortVersion(IEvent $event) { |
|
112 | - $parsedParameters = $this->getParsedParameters($event); |
|
113 | - |
|
114 | - if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
115 | - $event->setParsedSubject($this->l->t('Shared with %1$s', [ |
|
116 | - $parsedParameters['email']['name'], |
|
117 | - ])) |
|
118 | - ->setRichSubject($this->l->t('Shared with {email}'), [ |
|
119 | - 'email' => $parsedParameters['email'], |
|
120 | - ]); |
|
121 | - if ($this->activityManager->getRequirePNG()) { |
|
122 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
123 | - } else { |
|
124 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
125 | - } |
|
126 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
127 | - $event->setParsedSubject($this->l->t('Shared with %1$s by %2$s', [ |
|
128 | - $parsedParameters['email']['name'], |
|
129 | - $parsedParameters['actor']['name'], |
|
130 | - ])) |
|
131 | - ->setRichSubject($this->l->t('Shared with {email} by {actor}'), [ |
|
132 | - 'email' => $parsedParameters['email'], |
|
133 | - 'actor' => $parsedParameters['actor'], |
|
134 | - ]); |
|
135 | - if ($this->activityManager->getRequirePNG()) { |
|
136 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
137 | - } else { |
|
138 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
139 | - } |
|
140 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
141 | - $event->setParsedSubject($this->l->t('Password for mail share sent to %1$s', [ |
|
142 | - $parsedParameters['email']['name'] |
|
143 | - ])) |
|
144 | - ->setRichSubject($this->l->t('Password for mail share sent to {email}'), [ |
|
145 | - 'email' => $parsedParameters['email'] |
|
146 | - ]); |
|
147 | - if ($this->activityManager->getRequirePNG()) { |
|
148 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
149 | - } else { |
|
150 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
151 | - } |
|
152 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
153 | - $event->setParsedSubject($this->l->t('Password for mail share sent to you')) |
|
154 | - ->setRichSubject($this->l->t('Password for mail share sent to you')); |
|
155 | - if ($this->activityManager->getRequirePNG()) { |
|
156 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
157 | - } else { |
|
158 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
159 | - } |
|
160 | - } else { |
|
161 | - throw new \InvalidArgumentException(); |
|
162 | - } |
|
163 | - |
|
164 | - return $event; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * @param IEvent $event |
|
169 | - * @return IEvent |
|
170 | - * @throws \InvalidArgumentException |
|
171 | - * @since 11.0.0 |
|
172 | - */ |
|
173 | - public function parseLongVersion(IEvent $event) { |
|
174 | - $parsedParameters = $this->getParsedParameters($event); |
|
175 | - |
|
176 | - if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
177 | - $event->setParsedSubject($this->l->t('You shared %1$s with %2$s by mail', [ |
|
178 | - $parsedParameters['file']['path'], |
|
179 | - $parsedParameters['email']['name'], |
|
180 | - ])) |
|
181 | - ->setRichSubject($this->l->t('You shared {file} with {email} by mail'), $parsedParameters); |
|
182 | - if ($this->activityManager->getRequirePNG()) { |
|
183 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
184 | - } else { |
|
185 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
186 | - } |
|
187 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
188 | - $event->setParsedSubject($this->l->t('%3$s shared %1$s with %2$s by mail', [ |
|
189 | - $parsedParameters['file']['path'], |
|
190 | - $parsedParameters['email']['name'], |
|
191 | - $parsedParameters['actor']['name'], |
|
192 | - ])) |
|
193 | - ->setRichSubject($this->l->t('{actor} shared {file} with {email} by mail'), $parsedParameters); |
|
194 | - if ($this->activityManager->getRequirePNG()) { |
|
195 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
196 | - } else { |
|
197 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
198 | - } |
|
199 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
200 | - $event->setParsedSubject($this->l->t('Password to access %1$s was sent to %2s', [ |
|
201 | - $parsedParameters['file']['path'], |
|
202 | - $parsedParameters['email']['name'] |
|
203 | - ])) |
|
204 | - ->setRichSubject($this->l->t('Password to access {file} was sent to {email}'), $parsedParameters); |
|
205 | - if ($this->activityManager->getRequirePNG()) { |
|
206 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
207 | - } else { |
|
208 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
209 | - } |
|
210 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
211 | - $event->setParsedSubject( |
|
212 | - $this->l->t('Password to access %1$s was sent to you', |
|
213 | - [$parsedParameters['file']['path']])) |
|
214 | - ->setRichSubject($this->l->t('Password to access {file} was sent to you'), $parsedParameters); |
|
215 | - if ($this->activityManager->getRequirePNG()) { |
|
216 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
217 | - } else { |
|
218 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
219 | - } |
|
220 | - |
|
221 | - } else { |
|
222 | - throw new \InvalidArgumentException(); |
|
223 | - } |
|
224 | - |
|
225 | - return $event; |
|
226 | - } |
|
227 | - |
|
228 | - protected function getParsedParameters(IEvent $event) { |
|
229 | - $subject = $event->getSubject(); |
|
230 | - $parameters = $event->getSubjectParameters(); |
|
231 | - |
|
232 | - switch ($subject) { |
|
233 | - case self::SUBJECT_SHARED_EMAIL_SELF: |
|
234 | - return [ |
|
235 | - 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
236 | - 'email' => $this->generateEmailParameter($parameters[1]), |
|
237 | - ]; |
|
238 | - case self::SUBJECT_SHARED_EMAIL_BY: |
|
239 | - return [ |
|
240 | - 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
241 | - 'email' => $this->generateEmailParameter($parameters[1]), |
|
242 | - 'actor' => $this->generateUserParameter($parameters[2]), |
|
243 | - ]; |
|
244 | - case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND: |
|
245 | - return [ |
|
246 | - 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
247 | - 'email' => $this->generateEmailParameter($parameters[1]), |
|
248 | - ]; |
|
249 | - case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF: |
|
250 | - return [ |
|
251 | - 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
252 | - ]; |
|
253 | - } |
|
254 | - throw new \InvalidArgumentException(); |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * @param int $id |
|
259 | - * @param string $path |
|
260 | - * @return array |
|
261 | - */ |
|
262 | - protected function generateFileParameter($id, $path) { |
|
263 | - return [ |
|
264 | - 'type' => 'file', |
|
265 | - 'id' => $id, |
|
266 | - 'name' => basename($path), |
|
267 | - 'path' => trim($path, '/'), |
|
268 | - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
269 | - ]; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * @param string $email |
|
274 | - * @return array |
|
275 | - */ |
|
276 | - protected function generateEmailParameter($email) { |
|
277 | - if (!isset($this->contactNames[$email])) { |
|
278 | - $this->contactNames[$email] = $this->getContactName($email); |
|
279 | - } |
|
280 | - |
|
281 | - return [ |
|
282 | - 'type' => 'email', |
|
283 | - 'id' => $email, |
|
284 | - 'name' => $this->contactNames[$email], |
|
285 | - ]; |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * @param string $uid |
|
290 | - * @return array |
|
291 | - */ |
|
292 | - protected function generateUserParameter($uid) { |
|
293 | - if (!isset($this->displayNames[$uid])) { |
|
294 | - $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
295 | - } |
|
296 | - |
|
297 | - return [ |
|
298 | - 'type' => 'user', |
|
299 | - 'id' => $uid, |
|
300 | - 'name' => $this->displayNames[$uid], |
|
301 | - ]; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * @param string $email |
|
306 | - * @return string |
|
307 | - */ |
|
308 | - protected function getContactName($email) { |
|
309 | - $addressBookContacts = $this->contactsManager->search($email, ['EMAIL']); |
|
310 | - |
|
311 | - foreach ($addressBookContacts as $contact) { |
|
312 | - if (isset($contact['isLocalSystemBook'])) { |
|
313 | - continue; |
|
314 | - } |
|
315 | - |
|
316 | - if (in_array($email, $contact['EMAIL'])) { |
|
317 | - return $contact['FN']; |
|
318 | - } |
|
319 | - } |
|
320 | - |
|
321 | - return $email; |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * @param string $uid |
|
326 | - * @return string |
|
327 | - */ |
|
328 | - protected function getDisplayName($uid) { |
|
329 | - $user = $this->userManager->get($uid); |
|
330 | - if ($user instanceof IUser) { |
|
331 | - return $user->getDisplayName(); |
|
332 | - } else { |
|
333 | - return $uid; |
|
334 | - } |
|
335 | - } |
|
36 | + /** @var IFactory */ |
|
37 | + protected $languageFactory; |
|
38 | + |
|
39 | + /** @var IL10N */ |
|
40 | + protected $l; |
|
41 | + |
|
42 | + /** @var IURLGenerator */ |
|
43 | + protected $url; |
|
44 | + |
|
45 | + /** @var IManager */ |
|
46 | + protected $activityManager; |
|
47 | + |
|
48 | + /** @var IUserManager */ |
|
49 | + protected $userManager; |
|
50 | + /** @var IContactsManager */ |
|
51 | + protected $contactsManager; |
|
52 | + |
|
53 | + /** @var array */ |
|
54 | + protected $displayNames = []; |
|
55 | + |
|
56 | + /** @var array */ |
|
57 | + protected $contactNames = []; |
|
58 | + |
|
59 | + const SUBJECT_SHARED_EMAIL_SELF = 'shared_with_email_self'; |
|
60 | + const SUBJECT_SHARED_EMAIL_BY = 'shared_with_email_by'; |
|
61 | + const SUBJECT_SHARED_EMAIL_PASSWORD_SEND = 'shared_with_email_password_send'; |
|
62 | + const SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF = 'shared_with_email_password_send_self'; |
|
63 | + |
|
64 | + /** |
|
65 | + * @param IFactory $languageFactory |
|
66 | + * @param IURLGenerator $url |
|
67 | + * @param IManager $activityManager |
|
68 | + * @param IUserManager $userManager |
|
69 | + * @param IContactsManager $contactsManager |
|
70 | + */ |
|
71 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IContactsManager $contactsManager) { |
|
72 | + $this->languageFactory = $languageFactory; |
|
73 | + $this->url = $url; |
|
74 | + $this->activityManager = $activityManager; |
|
75 | + $this->userManager = $userManager; |
|
76 | + $this->contactsManager = $contactsManager; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @param string $language |
|
81 | + * @param IEvent $event |
|
82 | + * @param IEvent|null $previousEvent |
|
83 | + * @return IEvent |
|
84 | + * @throws \InvalidArgumentException |
|
85 | + * @since 11.0.0 |
|
86 | + */ |
|
87 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
88 | + if ($event->getApp() !== 'sharebymail') { |
|
89 | + throw new \InvalidArgumentException(); |
|
90 | + } |
|
91 | + |
|
92 | + $this->l = $this->languageFactory->get('sharebymail', $language); |
|
93 | + |
|
94 | + if ($this->activityManager->isFormattingFilteredObject()) { |
|
95 | + try { |
|
96 | + return $this->parseShortVersion($event); |
|
97 | + } catch (\InvalidArgumentException $e) { |
|
98 | + // Ignore and simply use the long version... |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + return $this->parseLongVersion($event); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @param IEvent $event |
|
107 | + * @return IEvent |
|
108 | + * @throws \InvalidArgumentException |
|
109 | + * @since 11.0.0 |
|
110 | + */ |
|
111 | + public function parseShortVersion(IEvent $event) { |
|
112 | + $parsedParameters = $this->getParsedParameters($event); |
|
113 | + |
|
114 | + if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
115 | + $event->setParsedSubject($this->l->t('Shared with %1$s', [ |
|
116 | + $parsedParameters['email']['name'], |
|
117 | + ])) |
|
118 | + ->setRichSubject($this->l->t('Shared with {email}'), [ |
|
119 | + 'email' => $parsedParameters['email'], |
|
120 | + ]); |
|
121 | + if ($this->activityManager->getRequirePNG()) { |
|
122 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
123 | + } else { |
|
124 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
125 | + } |
|
126 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
127 | + $event->setParsedSubject($this->l->t('Shared with %1$s by %2$s', [ |
|
128 | + $parsedParameters['email']['name'], |
|
129 | + $parsedParameters['actor']['name'], |
|
130 | + ])) |
|
131 | + ->setRichSubject($this->l->t('Shared with {email} by {actor}'), [ |
|
132 | + 'email' => $parsedParameters['email'], |
|
133 | + 'actor' => $parsedParameters['actor'], |
|
134 | + ]); |
|
135 | + if ($this->activityManager->getRequirePNG()) { |
|
136 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
137 | + } else { |
|
138 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
139 | + } |
|
140 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
141 | + $event->setParsedSubject($this->l->t('Password for mail share sent to %1$s', [ |
|
142 | + $parsedParameters['email']['name'] |
|
143 | + ])) |
|
144 | + ->setRichSubject($this->l->t('Password for mail share sent to {email}'), [ |
|
145 | + 'email' => $parsedParameters['email'] |
|
146 | + ]); |
|
147 | + if ($this->activityManager->getRequirePNG()) { |
|
148 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
149 | + } else { |
|
150 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
151 | + } |
|
152 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
153 | + $event->setParsedSubject($this->l->t('Password for mail share sent to you')) |
|
154 | + ->setRichSubject($this->l->t('Password for mail share sent to you')); |
|
155 | + if ($this->activityManager->getRequirePNG()) { |
|
156 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
157 | + } else { |
|
158 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
159 | + } |
|
160 | + } else { |
|
161 | + throw new \InvalidArgumentException(); |
|
162 | + } |
|
163 | + |
|
164 | + return $event; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * @param IEvent $event |
|
169 | + * @return IEvent |
|
170 | + * @throws \InvalidArgumentException |
|
171 | + * @since 11.0.0 |
|
172 | + */ |
|
173 | + public function parseLongVersion(IEvent $event) { |
|
174 | + $parsedParameters = $this->getParsedParameters($event); |
|
175 | + |
|
176 | + if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
177 | + $event->setParsedSubject($this->l->t('You shared %1$s with %2$s by mail', [ |
|
178 | + $parsedParameters['file']['path'], |
|
179 | + $parsedParameters['email']['name'], |
|
180 | + ])) |
|
181 | + ->setRichSubject($this->l->t('You shared {file} with {email} by mail'), $parsedParameters); |
|
182 | + if ($this->activityManager->getRequirePNG()) { |
|
183 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
184 | + } else { |
|
185 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
186 | + } |
|
187 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
188 | + $event->setParsedSubject($this->l->t('%3$s shared %1$s with %2$s by mail', [ |
|
189 | + $parsedParameters['file']['path'], |
|
190 | + $parsedParameters['email']['name'], |
|
191 | + $parsedParameters['actor']['name'], |
|
192 | + ])) |
|
193 | + ->setRichSubject($this->l->t('{actor} shared {file} with {email} by mail'), $parsedParameters); |
|
194 | + if ($this->activityManager->getRequirePNG()) { |
|
195 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
196 | + } else { |
|
197 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
198 | + } |
|
199 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
200 | + $event->setParsedSubject($this->l->t('Password to access %1$s was sent to %2s', [ |
|
201 | + $parsedParameters['file']['path'], |
|
202 | + $parsedParameters['email']['name'] |
|
203 | + ])) |
|
204 | + ->setRichSubject($this->l->t('Password to access {file} was sent to {email}'), $parsedParameters); |
|
205 | + if ($this->activityManager->getRequirePNG()) { |
|
206 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
207 | + } else { |
|
208 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
209 | + } |
|
210 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
211 | + $event->setParsedSubject( |
|
212 | + $this->l->t('Password to access %1$s was sent to you', |
|
213 | + [$parsedParameters['file']['path']])) |
|
214 | + ->setRichSubject($this->l->t('Password to access {file} was sent to you'), $parsedParameters); |
|
215 | + if ($this->activityManager->getRequirePNG()) { |
|
216 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
217 | + } else { |
|
218 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
219 | + } |
|
220 | + |
|
221 | + } else { |
|
222 | + throw new \InvalidArgumentException(); |
|
223 | + } |
|
224 | + |
|
225 | + return $event; |
|
226 | + } |
|
227 | + |
|
228 | + protected function getParsedParameters(IEvent $event) { |
|
229 | + $subject = $event->getSubject(); |
|
230 | + $parameters = $event->getSubjectParameters(); |
|
231 | + |
|
232 | + switch ($subject) { |
|
233 | + case self::SUBJECT_SHARED_EMAIL_SELF: |
|
234 | + return [ |
|
235 | + 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
236 | + 'email' => $this->generateEmailParameter($parameters[1]), |
|
237 | + ]; |
|
238 | + case self::SUBJECT_SHARED_EMAIL_BY: |
|
239 | + return [ |
|
240 | + 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
241 | + 'email' => $this->generateEmailParameter($parameters[1]), |
|
242 | + 'actor' => $this->generateUserParameter($parameters[2]), |
|
243 | + ]; |
|
244 | + case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND: |
|
245 | + return [ |
|
246 | + 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
247 | + 'email' => $this->generateEmailParameter($parameters[1]), |
|
248 | + ]; |
|
249 | + case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF: |
|
250 | + return [ |
|
251 | + 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
252 | + ]; |
|
253 | + } |
|
254 | + throw new \InvalidArgumentException(); |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * @param int $id |
|
259 | + * @param string $path |
|
260 | + * @return array |
|
261 | + */ |
|
262 | + protected function generateFileParameter($id, $path) { |
|
263 | + return [ |
|
264 | + 'type' => 'file', |
|
265 | + 'id' => $id, |
|
266 | + 'name' => basename($path), |
|
267 | + 'path' => trim($path, '/'), |
|
268 | + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
269 | + ]; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * @param string $email |
|
274 | + * @return array |
|
275 | + */ |
|
276 | + protected function generateEmailParameter($email) { |
|
277 | + if (!isset($this->contactNames[$email])) { |
|
278 | + $this->contactNames[$email] = $this->getContactName($email); |
|
279 | + } |
|
280 | + |
|
281 | + return [ |
|
282 | + 'type' => 'email', |
|
283 | + 'id' => $email, |
|
284 | + 'name' => $this->contactNames[$email], |
|
285 | + ]; |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * @param string $uid |
|
290 | + * @return array |
|
291 | + */ |
|
292 | + protected function generateUserParameter($uid) { |
|
293 | + if (!isset($this->displayNames[$uid])) { |
|
294 | + $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
295 | + } |
|
296 | + |
|
297 | + return [ |
|
298 | + 'type' => 'user', |
|
299 | + 'id' => $uid, |
|
300 | + 'name' => $this->displayNames[$uid], |
|
301 | + ]; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * @param string $email |
|
306 | + * @return string |
|
307 | + */ |
|
308 | + protected function getContactName($email) { |
|
309 | + $addressBookContacts = $this->contactsManager->search($email, ['EMAIL']); |
|
310 | + |
|
311 | + foreach ($addressBookContacts as $contact) { |
|
312 | + if (isset($contact['isLocalSystemBook'])) { |
|
313 | + continue; |
|
314 | + } |
|
315 | + |
|
316 | + if (in_array($email, $contact['EMAIL'])) { |
|
317 | + return $contact['FN']; |
|
318 | + } |
|
319 | + } |
|
320 | + |
|
321 | + return $email; |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * @param string $uid |
|
326 | + * @return string |
|
327 | + */ |
|
328 | + protected function getDisplayName($uid) { |
|
329 | + $user = $this->userManager->get($uid); |
|
330 | + if ($user instanceof IUser) { |
|
331 | + return $user->getDisplayName(); |
|
332 | + } else { |
|
333 | + return $uid; |
|
334 | + } |
|
335 | + } |
|
336 | 336 | } |