@@ -34,339 +34,339 @@ |
||
| 34 | 34 | |
| 35 | 35 | class Provider implements IProvider { |
| 36 | 36 | |
| 37 | - const CREATE_TAG = 'create_tag'; |
|
| 38 | - const UPDATE_TAG = 'update_tag'; |
|
| 39 | - const DELETE_TAG = 'delete_tag'; |
|
| 40 | - |
|
| 41 | - const ASSIGN_TAG = 'assign_tag'; |
|
| 42 | - const UNASSIGN_TAG = 'unassign_tag'; |
|
| 43 | - |
|
| 44 | - /** @var IFactory */ |
|
| 45 | - protected $languageFactory; |
|
| 46 | - |
|
| 47 | - /** @var IL10N */ |
|
| 48 | - protected $l; |
|
| 49 | - |
|
| 50 | - /** @var IURLGenerator */ |
|
| 51 | - protected $url; |
|
| 52 | - |
|
| 53 | - /** @var IManager */ |
|
| 54 | - protected $activityManager; |
|
| 55 | - |
|
| 56 | - /** @var IUserManager */ |
|
| 57 | - protected $userManager; |
|
| 58 | - |
|
| 59 | - /** @var string[] */ |
|
| 60 | - protected $displayNames = []; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @param IFactory $languageFactory |
|
| 64 | - * @param IURLGenerator $url |
|
| 65 | - * @param IManager $activityManager |
|
| 66 | - * @param IUserManager $userManager |
|
| 67 | - */ |
|
| 68 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager) { |
|
| 69 | - $this->languageFactory = $languageFactory; |
|
| 70 | - $this->url = $url; |
|
| 71 | - $this->activityManager = $activityManager; |
|
| 72 | - $this->userManager = $userManager; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param string $language |
|
| 77 | - * @param IEvent $event |
|
| 78 | - * @param IEvent|null $previousEvent |
|
| 79 | - * @return IEvent |
|
| 80 | - * @throws \InvalidArgumentException |
|
| 81 | - * @since 11.0.0 |
|
| 82 | - */ |
|
| 83 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 84 | - if ($event->getApp() !== 'systemtags') { |
|
| 85 | - throw new \InvalidArgumentException(); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $this->l = $this->languageFactory->get('systemtags', $language); |
|
| 89 | - |
|
| 90 | - if ($this->activityManager->isFormattingFilteredObject()) { |
|
| 91 | - try { |
|
| 92 | - return $this->parseShortVersion($event); |
|
| 93 | - } catch (\InvalidArgumentException $e) { |
|
| 94 | - // Ignore and simply use the long version... |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - return $this->parseLongVersion($event); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @param IEvent $event |
|
| 103 | - * @return IEvent |
|
| 104 | - * @throws \InvalidArgumentException |
|
| 105 | - * @since 11.0.0 |
|
| 106 | - */ |
|
| 107 | - public function parseShortVersion(IEvent $event) { |
|
| 108 | - $parsedParameters = $this->getParameters($event); |
|
| 109 | - |
|
| 110 | - if ($this->activityManager->getRequirePNG()) { |
|
| 111 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.png'))); |
|
| 112 | - } else { |
|
| 113 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.svg'))); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - if ($event->getSubject() === self::ASSIGN_TAG) { |
|
| 117 | - if ($parsedParameters['actor']['id'] === '') { |
|
| 118 | - $event->setParsedSubject($this->l->t('System tag %1$s added by the system', [ |
|
| 119 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 120 | - ])) |
|
| 121 | - ->setRichSubject($this->l->t('Added system tag {systemtag}'), [ |
|
| 122 | - 'systemtag' => $parsedParameters['systemtag'], |
|
| 123 | - ]); |
|
| 124 | - } else if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 125 | - $event->setParsedSubject($this->l->t('Added system tag %1$s', [ |
|
| 126 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 127 | - ])) |
|
| 128 | - ->setRichSubject($this->l->t('Added system tag {systemtag}'), [ |
|
| 129 | - 'systemtag' => $parsedParameters['systemtag'], |
|
| 130 | - ]); |
|
| 131 | - } else { |
|
| 132 | - $event->setParsedSubject($this->l->t('%1$s added system tag %2$s', [ |
|
| 133 | - $parsedParameters['actor']['name'], |
|
| 134 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 135 | - ])) |
|
| 136 | - ->setRichSubject($this->l->t('{actor} added system tag {systemtag}'), [ |
|
| 137 | - 'actor' => $parsedParameters['actor'], |
|
| 138 | - 'systemtag' => $parsedParameters['systemtag'], |
|
| 139 | - ]); |
|
| 140 | - } |
|
| 141 | - } else if ($event->getSubject() === self::UNASSIGN_TAG) { |
|
| 142 | - if ($parsedParameters['actor']['id'] === '') { |
|
| 143 | - $event->setParsedSubject($this->l->t('System tag %1$s removed by the system', [ |
|
| 144 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 145 | - ])) |
|
| 146 | - ->setRichSubject($this->l->t('Removed system tag {systemtag}'), [ |
|
| 147 | - 'systemtag' => $parsedParameters['systemtag'], |
|
| 148 | - ]); |
|
| 149 | - } else if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 150 | - $event->setParsedSubject($this->l->t('Removed system tag %1$s', [ |
|
| 151 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 152 | - ])) |
|
| 153 | - ->setRichSubject($this->l->t('Removed system tag {systemtag}'), [ |
|
| 154 | - 'systemtag' => $parsedParameters['systemtag'], |
|
| 155 | - ]); |
|
| 156 | - } else { |
|
| 157 | - $event->setParsedSubject($this->l->t('%1$s removed system tag %2$s', [ |
|
| 158 | - $parsedParameters['actor']['name'], |
|
| 159 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 160 | - ])) |
|
| 161 | - ->setRichSubject($this->l->t('{actor} removed system tag {systemtag}'), [ |
|
| 162 | - 'actor' => $parsedParameters['actor'], |
|
| 163 | - 'systemtag' => $parsedParameters['systemtag'], |
|
| 164 | - ]); |
|
| 165 | - } |
|
| 166 | - } else { |
|
| 167 | - throw new \InvalidArgumentException(); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - return $event; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * @param IEvent $event |
|
| 175 | - * @return IEvent |
|
| 176 | - * @throws \InvalidArgumentException |
|
| 177 | - * @since 11.0.0 |
|
| 178 | - */ |
|
| 179 | - public function parseLongVersion(IEvent $event) { |
|
| 180 | - $parsedParameters = $this->getParameters($event); |
|
| 181 | - |
|
| 182 | - if ($this->activityManager->getRequirePNG()) { |
|
| 183 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.png'))); |
|
| 184 | - } else { |
|
| 185 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.svg'))); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - if ($event->getSubject() === self::CREATE_TAG) { |
|
| 189 | - if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 190 | - $event->setParsedSubject($this->l->t('You created system tag %1$s', [ |
|
| 191 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 192 | - ])) |
|
| 193 | - ->setRichSubject($this->l->t('You created system tag {systemtag}'), $parsedParameters); |
|
| 194 | - } else { |
|
| 195 | - $event->setParsedSubject($this->l->t('%1$s created system tag %2$s', [ |
|
| 196 | - $parsedParameters['actor']['name'], |
|
| 197 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 198 | - ])) |
|
| 199 | - ->setRichSubject($this->l->t('{actor} created system tag {systemtag}'), $parsedParameters); |
|
| 200 | - } |
|
| 201 | - } else if ($event->getSubject() === self::DELETE_TAG) { |
|
| 202 | - if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 203 | - $event->setParsedSubject($this->l->t('You deleted system tag %1$s', [ |
|
| 204 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 205 | - ])) |
|
| 206 | - ->setRichSubject($this->l->t('You deleted system tag {systemtag}'), $parsedParameters); |
|
| 207 | - } else { |
|
| 208 | - $event->setParsedSubject($this->l->t('%1$s deleted system tag %2$s', [ |
|
| 209 | - $parsedParameters['actor']['name'], |
|
| 210 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 211 | - ])) |
|
| 212 | - ->setRichSubject($this->l->t('{actor} deleted system tag {systemtag}'), $parsedParameters); |
|
| 213 | - } |
|
| 214 | - } else if ($event->getSubject() === self::UPDATE_TAG) { |
|
| 215 | - if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 216 | - $event->setParsedSubject($this->l->t('You updated system tag %2$s to %1$s', [ |
|
| 217 | - $this->generatePlainSystemTag($parsedParameters['newsystemtag']), |
|
| 218 | - $this->generatePlainSystemTag($parsedParameters['oldsystemtag']), |
|
| 219 | - ])) |
|
| 220 | - ->setRichSubject($this->l->t('You updated system tag {oldsystemtag} to {newsystemtag}'), $parsedParameters); |
|
| 221 | - } else { |
|
| 222 | - $event->setParsedSubject($this->l->t('%1$s updated system tag %3$s to %2$s', [ |
|
| 223 | - $parsedParameters['actor']['name'], |
|
| 224 | - $this->generatePlainSystemTag($parsedParameters['newsystemtag']), |
|
| 225 | - $this->generatePlainSystemTag($parsedParameters['oldsystemtag']), |
|
| 226 | - ])) |
|
| 227 | - ->setRichSubject($this->l->t('{actor} updated system tag {oldsystemtag} to {newsystemtag}'), $parsedParameters); |
|
| 228 | - } |
|
| 229 | - } else if ($event->getSubject() === self::ASSIGN_TAG) { |
|
| 230 | - if ($parsedParameters['actor']['id'] === '') { |
|
| 231 | - unset($parsedParameters['actor']); |
|
| 232 | - $event->setParsedSubject($this->l->t('System tag %2$s was added to %1$s by the system', [ |
|
| 233 | - $parsedParameters['file']['path'], |
|
| 234 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 235 | - ])) |
|
| 236 | - ->setRichSubject($this->l->t('System tag {systemtag} was added to {file} by the system'), $parsedParameters); |
|
| 237 | - } else if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 238 | - $event->setParsedSubject($this->l->t('You added system tag %2$s to %1$s', [ |
|
| 239 | - $parsedParameters['file']['path'], |
|
| 240 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 241 | - ])) |
|
| 242 | - ->setRichSubject($this->l->t('You added system tag {systemtag} to {file}'), $parsedParameters); |
|
| 243 | - } else { |
|
| 244 | - $event->setParsedSubject($this->l->t('%1$s added system tag %3$s to %2$s', [ |
|
| 245 | - $parsedParameters['actor']['name'], |
|
| 246 | - $parsedParameters['file']['path'], |
|
| 247 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 248 | - ])) |
|
| 249 | - ->setRichSubject($this->l->t('{actor} added system tag {systemtag} to {file}'), $parsedParameters); |
|
| 250 | - } |
|
| 251 | - } else if ($event->getSubject() === self::UNASSIGN_TAG) { |
|
| 252 | - if ($parsedParameters['actor']['id'] === '') { |
|
| 253 | - unset($parsedParameters['actor']); |
|
| 254 | - $event->setParsedSubject($this->l->t('System tag %2$s was removed from %1$s by the system', [ |
|
| 255 | - $parsedParameters['file']['path'], |
|
| 256 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 257 | - ])) |
|
| 258 | - ->setRichSubject($this->l->t('System tag {systemtag} was removed from {file} by the system'), $parsedParameters); |
|
| 259 | - } else if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 260 | - $event->setParsedSubject($this->l->t('You removed system tag %2$s from %1$s', [ |
|
| 261 | - $parsedParameters['file']['path'], |
|
| 262 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 263 | - ])) |
|
| 264 | - ->setRichSubject($this->l->t('You removed system tag {systemtag} from {file}'), $parsedParameters); |
|
| 265 | - } else { |
|
| 266 | - $event->setParsedSubject($this->l->t('%1$s removed system tag %3$s from %2$s', [ |
|
| 267 | - $parsedParameters['actor']['name'], |
|
| 268 | - $parsedParameters['file']['path'], |
|
| 269 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 270 | - ])) |
|
| 271 | - ->setRichSubject($this->l->t('{actor} removed system tag {systemtag} from {file}'), $parsedParameters); |
|
| 272 | - } |
|
| 273 | - } else { |
|
| 274 | - throw new \InvalidArgumentException(); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - return $event; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - protected function getParameters(IEvent $event) { |
|
| 281 | - $subject = $event->getSubject(); |
|
| 282 | - $parameters = $event->getSubjectParameters(); |
|
| 283 | - |
|
| 284 | - switch ($subject) { |
|
| 285 | - case self::CREATE_TAG: |
|
| 286 | - case self::DELETE_TAG: |
|
| 287 | - return [ |
|
| 288 | - 'actor' => $this->getUserParameter((string) $parameters[0]), |
|
| 289 | - 'systemtag' => $this->getSystemTagParameter($parameters[1]), |
|
| 290 | - ]; |
|
| 291 | - case self::UPDATE_TAG: |
|
| 292 | - return [ |
|
| 293 | - 'actor' => $this->getUserParameter((string) $parameters[0]), |
|
| 294 | - 'newsystemtag' => $this->getSystemTagParameter($parameters[1]), |
|
| 295 | - 'oldsystemtag' => $this->getSystemTagParameter($parameters[2]), |
|
| 296 | - ]; |
|
| 297 | - case self::ASSIGN_TAG: |
|
| 298 | - case self::UNASSIGN_TAG: |
|
| 299 | - return [ |
|
| 300 | - 'actor' => $this->getUserParameter((string) $parameters[0]), |
|
| 301 | - 'file' => $this->getFileParameter($event->getObjectId(), $parameters[1]), |
|
| 302 | - 'systemtag' => $this->getSystemTagParameter($parameters[2]), |
|
| 303 | - ]; |
|
| 304 | - } |
|
| 305 | - return []; |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - protected function getFileParameter($id, $path) { |
|
| 309 | - return [ |
|
| 310 | - 'type' => 'file', |
|
| 311 | - 'id' => $id, |
|
| 312 | - 'name' => basename($path), |
|
| 313 | - 'path' => trim($path, '/'), |
|
| 314 | - ]; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - protected function getSystemTagParameter($parameter) { |
|
| 318 | - $tagData = json_decode($parameter, true); |
|
| 319 | - if ($tagData === null) { |
|
| 320 | - list($name, $status) = explode('|||', substr($parameter, 3, -3)); |
|
| 321 | - $tagData = [ |
|
| 322 | - 'id' => 0,// No way to recover the ID |
|
| 323 | - 'name' => $name, |
|
| 324 | - 'assignable' => $status === 'assignable', |
|
| 325 | - 'visible' => $status !== 'invisible', |
|
| 326 | - ]; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - return [ |
|
| 330 | - 'type' => 'systemtag', |
|
| 331 | - 'id' => (int) $tagData['id'], |
|
| 332 | - 'name' => $tagData['name'], |
|
| 333 | - 'assignable' => $tagData['assignable'] ? '1' : '0', |
|
| 334 | - 'visibility' => $tagData['visible'] ? '1' : '0', |
|
| 335 | - ]; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - protected function getUserParameter($uid) { |
|
| 339 | - if (!isset($this->displayNames[$uid])) { |
|
| 340 | - $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - return [ |
|
| 344 | - 'type' => 'user', |
|
| 345 | - 'id' => $uid, |
|
| 346 | - 'name' => $this->displayNames[$uid], |
|
| 347 | - ]; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - protected function generatePlainSystemTag(array $parameter) { |
|
| 351 | - if ($parameter['assignable'] === '1') { |
|
| 352 | - return $parameter['name']; |
|
| 353 | - } else if ($parameter['visibility'] === '1') { |
|
| 354 | - return $this->l->t('%s (restricted)', $parameter['name']); |
|
| 355 | - } else { |
|
| 356 | - return $this->l->t('%s (invisible)', $parameter['name']); |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * @param string $uid |
|
| 362 | - * @return string |
|
| 363 | - */ |
|
| 364 | - protected function getDisplayName($uid) { |
|
| 365 | - $user = $this->userManager->get($uid); |
|
| 366 | - if ($user instanceof IUser) { |
|
| 367 | - return $user->getDisplayName(); |
|
| 368 | - } else { |
|
| 369 | - return $uid; |
|
| 370 | - } |
|
| 371 | - } |
|
| 37 | + const CREATE_TAG = 'create_tag'; |
|
| 38 | + const UPDATE_TAG = 'update_tag'; |
|
| 39 | + const DELETE_TAG = 'delete_tag'; |
|
| 40 | + |
|
| 41 | + const ASSIGN_TAG = 'assign_tag'; |
|
| 42 | + const UNASSIGN_TAG = 'unassign_tag'; |
|
| 43 | + |
|
| 44 | + /** @var IFactory */ |
|
| 45 | + protected $languageFactory; |
|
| 46 | + |
|
| 47 | + /** @var IL10N */ |
|
| 48 | + protected $l; |
|
| 49 | + |
|
| 50 | + /** @var IURLGenerator */ |
|
| 51 | + protected $url; |
|
| 52 | + |
|
| 53 | + /** @var IManager */ |
|
| 54 | + protected $activityManager; |
|
| 55 | + |
|
| 56 | + /** @var IUserManager */ |
|
| 57 | + protected $userManager; |
|
| 58 | + |
|
| 59 | + /** @var string[] */ |
|
| 60 | + protected $displayNames = []; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @param IFactory $languageFactory |
|
| 64 | + * @param IURLGenerator $url |
|
| 65 | + * @param IManager $activityManager |
|
| 66 | + * @param IUserManager $userManager |
|
| 67 | + */ |
|
| 68 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager) { |
|
| 69 | + $this->languageFactory = $languageFactory; |
|
| 70 | + $this->url = $url; |
|
| 71 | + $this->activityManager = $activityManager; |
|
| 72 | + $this->userManager = $userManager; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param string $language |
|
| 77 | + * @param IEvent $event |
|
| 78 | + * @param IEvent|null $previousEvent |
|
| 79 | + * @return IEvent |
|
| 80 | + * @throws \InvalidArgumentException |
|
| 81 | + * @since 11.0.0 |
|
| 82 | + */ |
|
| 83 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 84 | + if ($event->getApp() !== 'systemtags') { |
|
| 85 | + throw new \InvalidArgumentException(); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $this->l = $this->languageFactory->get('systemtags', $language); |
|
| 89 | + |
|
| 90 | + if ($this->activityManager->isFormattingFilteredObject()) { |
|
| 91 | + try { |
|
| 92 | + return $this->parseShortVersion($event); |
|
| 93 | + } catch (\InvalidArgumentException $e) { |
|
| 94 | + // Ignore and simply use the long version... |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + return $this->parseLongVersion($event); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @param IEvent $event |
|
| 103 | + * @return IEvent |
|
| 104 | + * @throws \InvalidArgumentException |
|
| 105 | + * @since 11.0.0 |
|
| 106 | + */ |
|
| 107 | + public function parseShortVersion(IEvent $event) { |
|
| 108 | + $parsedParameters = $this->getParameters($event); |
|
| 109 | + |
|
| 110 | + if ($this->activityManager->getRequirePNG()) { |
|
| 111 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.png'))); |
|
| 112 | + } else { |
|
| 113 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.svg'))); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + if ($event->getSubject() === self::ASSIGN_TAG) { |
|
| 117 | + if ($parsedParameters['actor']['id'] === '') { |
|
| 118 | + $event->setParsedSubject($this->l->t('System tag %1$s added by the system', [ |
|
| 119 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 120 | + ])) |
|
| 121 | + ->setRichSubject($this->l->t('Added system tag {systemtag}'), [ |
|
| 122 | + 'systemtag' => $parsedParameters['systemtag'], |
|
| 123 | + ]); |
|
| 124 | + } else if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 125 | + $event->setParsedSubject($this->l->t('Added system tag %1$s', [ |
|
| 126 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 127 | + ])) |
|
| 128 | + ->setRichSubject($this->l->t('Added system tag {systemtag}'), [ |
|
| 129 | + 'systemtag' => $parsedParameters['systemtag'], |
|
| 130 | + ]); |
|
| 131 | + } else { |
|
| 132 | + $event->setParsedSubject($this->l->t('%1$s added system tag %2$s', [ |
|
| 133 | + $parsedParameters['actor']['name'], |
|
| 134 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 135 | + ])) |
|
| 136 | + ->setRichSubject($this->l->t('{actor} added system tag {systemtag}'), [ |
|
| 137 | + 'actor' => $parsedParameters['actor'], |
|
| 138 | + 'systemtag' => $parsedParameters['systemtag'], |
|
| 139 | + ]); |
|
| 140 | + } |
|
| 141 | + } else if ($event->getSubject() === self::UNASSIGN_TAG) { |
|
| 142 | + if ($parsedParameters['actor']['id'] === '') { |
|
| 143 | + $event->setParsedSubject($this->l->t('System tag %1$s removed by the system', [ |
|
| 144 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 145 | + ])) |
|
| 146 | + ->setRichSubject($this->l->t('Removed system tag {systemtag}'), [ |
|
| 147 | + 'systemtag' => $parsedParameters['systemtag'], |
|
| 148 | + ]); |
|
| 149 | + } else if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 150 | + $event->setParsedSubject($this->l->t('Removed system tag %1$s', [ |
|
| 151 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 152 | + ])) |
|
| 153 | + ->setRichSubject($this->l->t('Removed system tag {systemtag}'), [ |
|
| 154 | + 'systemtag' => $parsedParameters['systemtag'], |
|
| 155 | + ]); |
|
| 156 | + } else { |
|
| 157 | + $event->setParsedSubject($this->l->t('%1$s removed system tag %2$s', [ |
|
| 158 | + $parsedParameters['actor']['name'], |
|
| 159 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 160 | + ])) |
|
| 161 | + ->setRichSubject($this->l->t('{actor} removed system tag {systemtag}'), [ |
|
| 162 | + 'actor' => $parsedParameters['actor'], |
|
| 163 | + 'systemtag' => $parsedParameters['systemtag'], |
|
| 164 | + ]); |
|
| 165 | + } |
|
| 166 | + } else { |
|
| 167 | + throw new \InvalidArgumentException(); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + return $event; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * @param IEvent $event |
|
| 175 | + * @return IEvent |
|
| 176 | + * @throws \InvalidArgumentException |
|
| 177 | + * @since 11.0.0 |
|
| 178 | + */ |
|
| 179 | + public function parseLongVersion(IEvent $event) { |
|
| 180 | + $parsedParameters = $this->getParameters($event); |
|
| 181 | + |
|
| 182 | + if ($this->activityManager->getRequirePNG()) { |
|
| 183 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.png'))); |
|
| 184 | + } else { |
|
| 185 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.svg'))); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + if ($event->getSubject() === self::CREATE_TAG) { |
|
| 189 | + if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 190 | + $event->setParsedSubject($this->l->t('You created system tag %1$s', [ |
|
| 191 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 192 | + ])) |
|
| 193 | + ->setRichSubject($this->l->t('You created system tag {systemtag}'), $parsedParameters); |
|
| 194 | + } else { |
|
| 195 | + $event->setParsedSubject($this->l->t('%1$s created system tag %2$s', [ |
|
| 196 | + $parsedParameters['actor']['name'], |
|
| 197 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 198 | + ])) |
|
| 199 | + ->setRichSubject($this->l->t('{actor} created system tag {systemtag}'), $parsedParameters); |
|
| 200 | + } |
|
| 201 | + } else if ($event->getSubject() === self::DELETE_TAG) { |
|
| 202 | + if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 203 | + $event->setParsedSubject($this->l->t('You deleted system tag %1$s', [ |
|
| 204 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 205 | + ])) |
|
| 206 | + ->setRichSubject($this->l->t('You deleted system tag {systemtag}'), $parsedParameters); |
|
| 207 | + } else { |
|
| 208 | + $event->setParsedSubject($this->l->t('%1$s deleted system tag %2$s', [ |
|
| 209 | + $parsedParameters['actor']['name'], |
|
| 210 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 211 | + ])) |
|
| 212 | + ->setRichSubject($this->l->t('{actor} deleted system tag {systemtag}'), $parsedParameters); |
|
| 213 | + } |
|
| 214 | + } else if ($event->getSubject() === self::UPDATE_TAG) { |
|
| 215 | + if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 216 | + $event->setParsedSubject($this->l->t('You updated system tag %2$s to %1$s', [ |
|
| 217 | + $this->generatePlainSystemTag($parsedParameters['newsystemtag']), |
|
| 218 | + $this->generatePlainSystemTag($parsedParameters['oldsystemtag']), |
|
| 219 | + ])) |
|
| 220 | + ->setRichSubject($this->l->t('You updated system tag {oldsystemtag} to {newsystemtag}'), $parsedParameters); |
|
| 221 | + } else { |
|
| 222 | + $event->setParsedSubject($this->l->t('%1$s updated system tag %3$s to %2$s', [ |
|
| 223 | + $parsedParameters['actor']['name'], |
|
| 224 | + $this->generatePlainSystemTag($parsedParameters['newsystemtag']), |
|
| 225 | + $this->generatePlainSystemTag($parsedParameters['oldsystemtag']), |
|
| 226 | + ])) |
|
| 227 | + ->setRichSubject($this->l->t('{actor} updated system tag {oldsystemtag} to {newsystemtag}'), $parsedParameters); |
|
| 228 | + } |
|
| 229 | + } else if ($event->getSubject() === self::ASSIGN_TAG) { |
|
| 230 | + if ($parsedParameters['actor']['id'] === '') { |
|
| 231 | + unset($parsedParameters['actor']); |
|
| 232 | + $event->setParsedSubject($this->l->t('System tag %2$s was added to %1$s by the system', [ |
|
| 233 | + $parsedParameters['file']['path'], |
|
| 234 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 235 | + ])) |
|
| 236 | + ->setRichSubject($this->l->t('System tag {systemtag} was added to {file} by the system'), $parsedParameters); |
|
| 237 | + } else if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 238 | + $event->setParsedSubject($this->l->t('You added system tag %2$s to %1$s', [ |
|
| 239 | + $parsedParameters['file']['path'], |
|
| 240 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 241 | + ])) |
|
| 242 | + ->setRichSubject($this->l->t('You added system tag {systemtag} to {file}'), $parsedParameters); |
|
| 243 | + } else { |
|
| 244 | + $event->setParsedSubject($this->l->t('%1$s added system tag %3$s to %2$s', [ |
|
| 245 | + $parsedParameters['actor']['name'], |
|
| 246 | + $parsedParameters['file']['path'], |
|
| 247 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 248 | + ])) |
|
| 249 | + ->setRichSubject($this->l->t('{actor} added system tag {systemtag} to {file}'), $parsedParameters); |
|
| 250 | + } |
|
| 251 | + } else if ($event->getSubject() === self::UNASSIGN_TAG) { |
|
| 252 | + if ($parsedParameters['actor']['id'] === '') { |
|
| 253 | + unset($parsedParameters['actor']); |
|
| 254 | + $event->setParsedSubject($this->l->t('System tag %2$s was removed from %1$s by the system', [ |
|
| 255 | + $parsedParameters['file']['path'], |
|
| 256 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 257 | + ])) |
|
| 258 | + ->setRichSubject($this->l->t('System tag {systemtag} was removed from {file} by the system'), $parsedParameters); |
|
| 259 | + } else if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 260 | + $event->setParsedSubject($this->l->t('You removed system tag %2$s from %1$s', [ |
|
| 261 | + $parsedParameters['file']['path'], |
|
| 262 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 263 | + ])) |
|
| 264 | + ->setRichSubject($this->l->t('You removed system tag {systemtag} from {file}'), $parsedParameters); |
|
| 265 | + } else { |
|
| 266 | + $event->setParsedSubject($this->l->t('%1$s removed system tag %3$s from %2$s', [ |
|
| 267 | + $parsedParameters['actor']['name'], |
|
| 268 | + $parsedParameters['file']['path'], |
|
| 269 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 270 | + ])) |
|
| 271 | + ->setRichSubject($this->l->t('{actor} removed system tag {systemtag} from {file}'), $parsedParameters); |
|
| 272 | + } |
|
| 273 | + } else { |
|
| 274 | + throw new \InvalidArgumentException(); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + return $event; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + protected function getParameters(IEvent $event) { |
|
| 281 | + $subject = $event->getSubject(); |
|
| 282 | + $parameters = $event->getSubjectParameters(); |
|
| 283 | + |
|
| 284 | + switch ($subject) { |
|
| 285 | + case self::CREATE_TAG: |
|
| 286 | + case self::DELETE_TAG: |
|
| 287 | + return [ |
|
| 288 | + 'actor' => $this->getUserParameter((string) $parameters[0]), |
|
| 289 | + 'systemtag' => $this->getSystemTagParameter($parameters[1]), |
|
| 290 | + ]; |
|
| 291 | + case self::UPDATE_TAG: |
|
| 292 | + return [ |
|
| 293 | + 'actor' => $this->getUserParameter((string) $parameters[0]), |
|
| 294 | + 'newsystemtag' => $this->getSystemTagParameter($parameters[1]), |
|
| 295 | + 'oldsystemtag' => $this->getSystemTagParameter($parameters[2]), |
|
| 296 | + ]; |
|
| 297 | + case self::ASSIGN_TAG: |
|
| 298 | + case self::UNASSIGN_TAG: |
|
| 299 | + return [ |
|
| 300 | + 'actor' => $this->getUserParameter((string) $parameters[0]), |
|
| 301 | + 'file' => $this->getFileParameter($event->getObjectId(), $parameters[1]), |
|
| 302 | + 'systemtag' => $this->getSystemTagParameter($parameters[2]), |
|
| 303 | + ]; |
|
| 304 | + } |
|
| 305 | + return []; |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + protected function getFileParameter($id, $path) { |
|
| 309 | + return [ |
|
| 310 | + 'type' => 'file', |
|
| 311 | + 'id' => $id, |
|
| 312 | + 'name' => basename($path), |
|
| 313 | + 'path' => trim($path, '/'), |
|
| 314 | + ]; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + protected function getSystemTagParameter($parameter) { |
|
| 318 | + $tagData = json_decode($parameter, true); |
|
| 319 | + if ($tagData === null) { |
|
| 320 | + list($name, $status) = explode('|||', substr($parameter, 3, -3)); |
|
| 321 | + $tagData = [ |
|
| 322 | + 'id' => 0,// No way to recover the ID |
|
| 323 | + 'name' => $name, |
|
| 324 | + 'assignable' => $status === 'assignable', |
|
| 325 | + 'visible' => $status !== 'invisible', |
|
| 326 | + ]; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + return [ |
|
| 330 | + 'type' => 'systemtag', |
|
| 331 | + 'id' => (int) $tagData['id'], |
|
| 332 | + 'name' => $tagData['name'], |
|
| 333 | + 'assignable' => $tagData['assignable'] ? '1' : '0', |
|
| 334 | + 'visibility' => $tagData['visible'] ? '1' : '0', |
|
| 335 | + ]; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + protected function getUserParameter($uid) { |
|
| 339 | + if (!isset($this->displayNames[$uid])) { |
|
| 340 | + $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + return [ |
|
| 344 | + 'type' => 'user', |
|
| 345 | + 'id' => $uid, |
|
| 346 | + 'name' => $this->displayNames[$uid], |
|
| 347 | + ]; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + protected function generatePlainSystemTag(array $parameter) { |
|
| 351 | + if ($parameter['assignable'] === '1') { |
|
| 352 | + return $parameter['name']; |
|
| 353 | + } else if ($parameter['visibility'] === '1') { |
|
| 354 | + return $this->l->t('%s (restricted)', $parameter['name']); |
|
| 355 | + } else { |
|
| 356 | + return $this->l->t('%s (invisible)', $parameter['name']); |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * @param string $uid |
|
| 362 | + * @return string |
|
| 363 | + */ |
|
| 364 | + protected function getDisplayName($uid) { |
|
| 365 | + $user = $this->userManager->get($uid); |
|
| 366 | + if ($user instanceof IUser) { |
|
| 367 | + return $user->getDisplayName(); |
|
| 368 | + } else { |
|
| 369 | + return $uid; |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | 372 | } |
@@ -32,58 +32,58 @@ |
||
| 32 | 32 | use OCP\IUserSession; |
| 33 | 33 | |
| 34 | 34 | class Setup { |
| 35 | - /** |
|
| 36 | - * @var Crypt |
|
| 37 | - */ |
|
| 38 | - private $crypt; |
|
| 39 | - /** |
|
| 40 | - * @var KeyManager |
|
| 41 | - */ |
|
| 42 | - private $keyManager; |
|
| 43 | - /** |
|
| 44 | - * @var ILogger |
|
| 45 | - */ |
|
| 46 | - private $logger; |
|
| 47 | - /** |
|
| 48 | - * @var bool|string |
|
| 49 | - */ |
|
| 50 | - private $user; |
|
| 35 | + /** |
|
| 36 | + * @var Crypt |
|
| 37 | + */ |
|
| 38 | + private $crypt; |
|
| 39 | + /** |
|
| 40 | + * @var KeyManager |
|
| 41 | + */ |
|
| 42 | + private $keyManager; |
|
| 43 | + /** |
|
| 44 | + * @var ILogger |
|
| 45 | + */ |
|
| 46 | + private $logger; |
|
| 47 | + /** |
|
| 48 | + * @var bool|string |
|
| 49 | + */ |
|
| 50 | + private $user; |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @param ILogger $logger |
|
| 55 | - * @param IUserSession $userSession |
|
| 56 | - * @param Crypt $crypt |
|
| 57 | - * @param KeyManager $keyManager |
|
| 58 | - */ |
|
| 59 | - public function __construct(ILogger $logger, |
|
| 60 | - IUserSession $userSession, |
|
| 61 | - Crypt $crypt, |
|
| 62 | - KeyManager $keyManager) { |
|
| 63 | - $this->logger = $logger; |
|
| 64 | - $this->user = $userSession && $userSession->isLoggedIn() ? $userSession->getUser()->getUID() : false; |
|
| 65 | - $this->crypt = $crypt; |
|
| 66 | - $this->keyManager = $keyManager; |
|
| 67 | - } |
|
| 53 | + /** |
|
| 54 | + * @param ILogger $logger |
|
| 55 | + * @param IUserSession $userSession |
|
| 56 | + * @param Crypt $crypt |
|
| 57 | + * @param KeyManager $keyManager |
|
| 58 | + */ |
|
| 59 | + public function __construct(ILogger $logger, |
|
| 60 | + IUserSession $userSession, |
|
| 61 | + Crypt $crypt, |
|
| 62 | + KeyManager $keyManager) { |
|
| 63 | + $this->logger = $logger; |
|
| 64 | + $this->user = $userSession && $userSession->isLoggedIn() ? $userSession->getUser()->getUID() : false; |
|
| 65 | + $this->crypt = $crypt; |
|
| 66 | + $this->keyManager = $keyManager; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @param string $uid user id |
|
| 71 | - * @param string $password user password |
|
| 72 | - * @return bool |
|
| 73 | - */ |
|
| 74 | - public function setupUser($uid, $password) { |
|
| 75 | - if (!$this->keyManager->userHasKeys($uid)) { |
|
| 76 | - return $this->keyManager->storeKeyPair($uid, $password, |
|
| 77 | - $this->crypt->createKeyPair()); |
|
| 78 | - } |
|
| 79 | - return true; |
|
| 80 | - } |
|
| 69 | + /** |
|
| 70 | + * @param string $uid user id |
|
| 71 | + * @param string $password user password |
|
| 72 | + * @return bool |
|
| 73 | + */ |
|
| 74 | + public function setupUser($uid, $password) { |
|
| 75 | + if (!$this->keyManager->userHasKeys($uid)) { |
|
| 76 | + return $this->keyManager->storeKeyPair($uid, $password, |
|
| 77 | + $this->crypt->createKeyPair()); |
|
| 78 | + } |
|
| 79 | + return true; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * make sure that all system keys exists |
|
| 84 | - */ |
|
| 85 | - public function setupSystem() { |
|
| 86 | - $this->keyManager->validateShareKey(); |
|
| 87 | - $this->keyManager->validateMasterKey(); |
|
| 88 | - } |
|
| 82 | + /** |
|
| 83 | + * make sure that all system keys exists |
|
| 84 | + */ |
|
| 85 | + public function setupSystem() { |
|
| 86 | + $this->keyManager->validateShareKey(); |
|
| 87 | + $this->keyManager->validateMasterKey(); |
|
| 88 | + } |
|
| 89 | 89 | } |
@@ -37,77 +37,77 @@ |
||
| 37 | 37 | |
| 38 | 38 | class SecurityProvider implements IProvider { |
| 39 | 39 | |
| 40 | - /** @var L10nFactory */ |
|
| 41 | - private $l10n; |
|
| 40 | + /** @var L10nFactory */ |
|
| 41 | + private $l10n; |
|
| 42 | 42 | |
| 43 | - /** @var IURLGenerator */ |
|
| 44 | - private $urlGenerator; |
|
| 43 | + /** @var IURLGenerator */ |
|
| 44 | + private $urlGenerator; |
|
| 45 | 45 | |
| 46 | - /** @var IManager */ |
|
| 47 | - private $activityManager; |
|
| 46 | + /** @var IManager */ |
|
| 47 | + private $activityManager; |
|
| 48 | 48 | |
| 49 | - public function __construct(L10nFactory $l10n, IURLGenerator $urlGenerator, IManager $activityManager) { |
|
| 50 | - $this->urlGenerator = $urlGenerator; |
|
| 51 | - $this->l10n = $l10n; |
|
| 52 | - $this->activityManager = $activityManager; |
|
| 53 | - } |
|
| 49 | + public function __construct(L10nFactory $l10n, IURLGenerator $urlGenerator, IManager $activityManager) { |
|
| 50 | + $this->urlGenerator = $urlGenerator; |
|
| 51 | + $this->l10n = $l10n; |
|
| 52 | + $this->activityManager = $activityManager; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 56 | - if ($event->getType() !== 'security') { |
|
| 57 | - throw new InvalidArgumentException(); |
|
| 58 | - } |
|
| 55 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 56 | + if ($event->getType() !== 'security') { |
|
| 57 | + throw new InvalidArgumentException(); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - $l = $this->l10n->get('settings', $language); |
|
| 60 | + $l = $this->l10n->get('settings', $language); |
|
| 61 | 61 | |
| 62 | - switch ($event->getSubject()) { |
|
| 63 | - case 'twofactor_success': |
|
| 64 | - $params = $event->getSubjectParameters(); |
|
| 65 | - $event->setParsedSubject($l->t('You successfully logged in using two-factor authentication (%1$s)', [ |
|
| 66 | - $params['provider'], |
|
| 67 | - ])); |
|
| 68 | - if ($this->activityManager->getRequirePNG()) { |
|
| 69 | - $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png'))); |
|
| 70 | - } else { |
|
| 71 | - $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg'))); |
|
| 72 | - } |
|
| 73 | - break; |
|
| 74 | - case 'twofactor_failed': |
|
| 75 | - $params = $event->getSubjectParameters(); |
|
| 76 | - $event->setParsedSubject($l->t('A login attempt using two-factor authentication failed (%1$s)', [ |
|
| 77 | - $params['provider'], |
|
| 78 | - ])); |
|
| 79 | - if ($this->activityManager->getRequirePNG()) { |
|
| 80 | - $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png'))); |
|
| 81 | - } else { |
|
| 82 | - $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg'))); |
|
| 83 | - } |
|
| 84 | - break; |
|
| 85 | - case 'remote_wipe_start': |
|
| 86 | - $params = $event->getSubjectParameters(); |
|
| 87 | - $event->setParsedSubject($l->t('Remote wipe was started on %1$s', [ |
|
| 88 | - $params['name'], |
|
| 89 | - ])); |
|
| 90 | - if ($this->activityManager->getRequirePNG()) { |
|
| 91 | - $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/delete.png'))); |
|
| 92 | - } else { |
|
| 93 | - $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/delete.svg'))); |
|
| 94 | - } |
|
| 95 | - break; |
|
| 96 | - case 'remote_wipe_finish': |
|
| 97 | - $params = $event->getSubjectParameters(); |
|
| 98 | - $event->setParsedSubject($l->t('Remote wipe has finished on %1$s', [ |
|
| 99 | - $params['name'], |
|
| 100 | - ])); |
|
| 101 | - if ($this->activityManager->getRequirePNG()) { |
|
| 102 | - $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/delete.png'))); |
|
| 103 | - } else { |
|
| 104 | - $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/delete.svg'))); |
|
| 105 | - } |
|
| 106 | - break; |
|
| 107 | - default: |
|
| 108 | - throw new InvalidArgumentException(); |
|
| 109 | - } |
|
| 110 | - return $event; |
|
| 111 | - } |
|
| 62 | + switch ($event->getSubject()) { |
|
| 63 | + case 'twofactor_success': |
|
| 64 | + $params = $event->getSubjectParameters(); |
|
| 65 | + $event->setParsedSubject($l->t('You successfully logged in using two-factor authentication (%1$s)', [ |
|
| 66 | + $params['provider'], |
|
| 67 | + ])); |
|
| 68 | + if ($this->activityManager->getRequirePNG()) { |
|
| 69 | + $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png'))); |
|
| 70 | + } else { |
|
| 71 | + $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg'))); |
|
| 72 | + } |
|
| 73 | + break; |
|
| 74 | + case 'twofactor_failed': |
|
| 75 | + $params = $event->getSubjectParameters(); |
|
| 76 | + $event->setParsedSubject($l->t('A login attempt using two-factor authentication failed (%1$s)', [ |
|
| 77 | + $params['provider'], |
|
| 78 | + ])); |
|
| 79 | + if ($this->activityManager->getRequirePNG()) { |
|
| 80 | + $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png'))); |
|
| 81 | + } else { |
|
| 82 | + $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg'))); |
|
| 83 | + } |
|
| 84 | + break; |
|
| 85 | + case 'remote_wipe_start': |
|
| 86 | + $params = $event->getSubjectParameters(); |
|
| 87 | + $event->setParsedSubject($l->t('Remote wipe was started on %1$s', [ |
|
| 88 | + $params['name'], |
|
| 89 | + ])); |
|
| 90 | + if ($this->activityManager->getRequirePNG()) { |
|
| 91 | + $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/delete.png'))); |
|
| 92 | + } else { |
|
| 93 | + $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/delete.svg'))); |
|
| 94 | + } |
|
| 95 | + break; |
|
| 96 | + case 'remote_wipe_finish': |
|
| 97 | + $params = $event->getSubjectParameters(); |
|
| 98 | + $event->setParsedSubject($l->t('Remote wipe has finished on %1$s', [ |
|
| 99 | + $params['name'], |
|
| 100 | + ])); |
|
| 101 | + if ($this->activityManager->getRequirePNG()) { |
|
| 102 | + $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/delete.png'))); |
|
| 103 | + } else { |
|
| 104 | + $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/delete.svg'))); |
|
| 105 | + } |
|
| 106 | + break; |
|
| 107 | + default: |
|
| 108 | + throw new InvalidArgumentException(); |
|
| 109 | + } |
|
| 110 | + return $event; |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | 113 | } |
@@ -37,357 +37,357 @@ |
||
| 37 | 37 | |
| 38 | 38 | class Activity implements IProvider { |
| 39 | 39 | |
| 40 | - /** @var IFactory */ |
|
| 41 | - protected $languageFactory; |
|
| 42 | - |
|
| 43 | - /** @var IL10N */ |
|
| 44 | - protected $l; |
|
| 45 | - |
|
| 46 | - /** @var IURLGenerator */ |
|
| 47 | - protected $url; |
|
| 48 | - |
|
| 49 | - /** @var IManager */ |
|
| 50 | - protected $activityManager; |
|
| 51 | - |
|
| 52 | - /** @var IUserManager */ |
|
| 53 | - protected $userManager; |
|
| 54 | - /** @var IContactsManager */ |
|
| 55 | - protected $contactsManager; |
|
| 56 | - |
|
| 57 | - /** @var array */ |
|
| 58 | - protected $displayNames = []; |
|
| 59 | - |
|
| 60 | - /** @var array */ |
|
| 61 | - protected $contactNames = []; |
|
| 62 | - |
|
| 63 | - const SUBJECT_SHARED_EMAIL_SELF = 'shared_with_email_self'; |
|
| 64 | - const SUBJECT_SHARED_EMAIL_BY = 'shared_with_email_by'; |
|
| 65 | - const SUBJECT_SHARED_EMAIL_PASSWORD_SEND = 'shared_with_email_password_send'; |
|
| 66 | - const SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF = 'shared_with_email_password_send_self'; |
|
| 67 | - const SUBJECT_UNSHARED_EMAIL_SELF = 'unshared_with_email_self'; |
|
| 68 | - const SUBJECT_UNSHARED_EMAIL_BY = 'unshared_with_email_by'; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @param IFactory $languageFactory |
|
| 72 | - * @param IURLGenerator $url |
|
| 73 | - * @param IManager $activityManager |
|
| 74 | - * @param IUserManager $userManager |
|
| 75 | - * @param IContactsManager $contactsManager |
|
| 76 | - */ |
|
| 77 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IContactsManager $contactsManager) { |
|
| 78 | - $this->languageFactory = $languageFactory; |
|
| 79 | - $this->url = $url; |
|
| 80 | - $this->activityManager = $activityManager; |
|
| 81 | - $this->userManager = $userManager; |
|
| 82 | - $this->contactsManager = $contactsManager; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @param string $language |
|
| 87 | - * @param IEvent $event |
|
| 88 | - * @param IEvent|null $previousEvent |
|
| 89 | - * @return IEvent |
|
| 90 | - * @throws \InvalidArgumentException |
|
| 91 | - * @since 11.0.0 |
|
| 92 | - */ |
|
| 93 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 94 | - if ($event->getApp() !== 'sharebymail') { |
|
| 95 | - throw new \InvalidArgumentException(); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - $this->l = $this->languageFactory->get('sharebymail', $language); |
|
| 99 | - |
|
| 100 | - if ($this->activityManager->isFormattingFilteredObject()) { |
|
| 101 | - try { |
|
| 102 | - return $this->parseShortVersion($event); |
|
| 103 | - } catch (\InvalidArgumentException $e) { |
|
| 104 | - // Ignore and simply use the long version... |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - return $this->parseLongVersion($event); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @param IEvent $event |
|
| 113 | - * @return IEvent |
|
| 114 | - * @throws \InvalidArgumentException |
|
| 115 | - * @since 11.0.0 |
|
| 116 | - */ |
|
| 117 | - public function parseShortVersion(IEvent $event) { |
|
| 118 | - $parsedParameters = $this->getParsedParameters($event); |
|
| 119 | - |
|
| 120 | - if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
| 121 | - $event->setParsedSubject($this->l->t('Shared with %1$s', [ |
|
| 122 | - $parsedParameters['email']['name'], |
|
| 123 | - ])) |
|
| 124 | - ->setRichSubject($this->l->t('Shared with {email}'), [ |
|
| 125 | - 'email' => $parsedParameters['email'], |
|
| 126 | - ]); |
|
| 127 | - if ($this->activityManager->getRequirePNG()) { |
|
| 128 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 129 | - } else { |
|
| 130 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 131 | - } |
|
| 132 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
| 133 | - $event->setParsedSubject($this->l->t('Shared with %1$s by %2$s', [ |
|
| 134 | - $parsedParameters['email']['name'], |
|
| 135 | - $parsedParameters['actor']['name'], |
|
| 136 | - ])) |
|
| 137 | - ->setRichSubject($this->l->t('Shared with {email} by {actor}'), [ |
|
| 138 | - 'email' => $parsedParameters['email'], |
|
| 139 | - 'actor' => $parsedParameters['actor'], |
|
| 140 | - ]); |
|
| 141 | - if ($this->activityManager->getRequirePNG()) { |
|
| 142 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 143 | - } else { |
|
| 144 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 145 | - } |
|
| 146 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_SELF) { |
|
| 147 | - $event->setParsedSubject($this->l->t('Unshared from %1$s', [ |
|
| 148 | - $parsedParameters['email']['name'], |
|
| 149 | - ])) |
|
| 150 | - ->setRichSubject($this->l->t('Unshared from {email}'), [ |
|
| 151 | - 'email' => $parsedParameters['email'], |
|
| 152 | - ]); |
|
| 153 | - if ($this->activityManager->getRequirePNG()) { |
|
| 154 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 155 | - } else { |
|
| 156 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 157 | - } |
|
| 158 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_BY) { |
|
| 159 | - $event->setParsedSubject($this->l->t('Unshared from %1$s by %2$s', [ |
|
| 160 | - $parsedParameters['email']['name'], |
|
| 161 | - $parsedParameters['actor']['name'], |
|
| 162 | - ])) |
|
| 163 | - ->setRichSubject($this->l->t('Unshared from {email} by {actor}'), [ |
|
| 164 | - 'email' => $parsedParameters['email'], |
|
| 165 | - 'actor' => $parsedParameters['actor'], |
|
| 166 | - ]); |
|
| 167 | - if ($this->activityManager->getRequirePNG()) { |
|
| 168 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 169 | - } else { |
|
| 170 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 171 | - } |
|
| 172 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
| 173 | - $event->setParsedSubject($this->l->t('Password for mail share sent to %1$s', [ |
|
| 174 | - $parsedParameters['email']['name'] |
|
| 175 | - ])) |
|
| 176 | - ->setRichSubject($this->l->t('Password for mail share sent to {email}'), [ |
|
| 177 | - 'email' => $parsedParameters['email'] |
|
| 178 | - ]); |
|
| 179 | - if ($this->activityManager->getRequirePNG()) { |
|
| 180 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 181 | - } else { |
|
| 182 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 183 | - } |
|
| 184 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
| 185 | - $event->setParsedSubject($this->l->t('Password for mail share sent to you')) |
|
| 186 | - ->setRichSubject($this->l->t('Password for mail share sent to you')); |
|
| 187 | - if ($this->activityManager->getRequirePNG()) { |
|
| 188 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 189 | - } else { |
|
| 190 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 191 | - } |
|
| 192 | - } else { |
|
| 193 | - throw new \InvalidArgumentException(); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - return $event; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * @param IEvent $event |
|
| 201 | - * @return IEvent |
|
| 202 | - * @throws \InvalidArgumentException |
|
| 203 | - * @since 11.0.0 |
|
| 204 | - */ |
|
| 205 | - public function parseLongVersion(IEvent $event) { |
|
| 206 | - $parsedParameters = $this->getParsedParameters($event); |
|
| 207 | - |
|
| 208 | - if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
| 209 | - $event->setParsedSubject($this->l->t('You shared %1$s with %2$s by mail', [ |
|
| 210 | - $parsedParameters['file']['path'], |
|
| 211 | - $parsedParameters['email']['name'], |
|
| 212 | - ])) |
|
| 213 | - ->setRichSubject($this->l->t('You shared {file} with {email} by mail'), $parsedParameters); |
|
| 214 | - if ($this->activityManager->getRequirePNG()) { |
|
| 215 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 216 | - } else { |
|
| 217 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 218 | - } |
|
| 219 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
| 220 | - $event->setParsedSubject($this->l->t('%3$s shared %1$s with %2$s by mail', [ |
|
| 221 | - $parsedParameters['file']['path'], |
|
| 222 | - $parsedParameters['email']['name'], |
|
| 223 | - $parsedParameters['actor']['name'], |
|
| 224 | - ])) |
|
| 225 | - ->setRichSubject($this->l->t('{actor} shared {file} with {email} by mail'), $parsedParameters); |
|
| 226 | - if ($this->activityManager->getRequirePNG()) { |
|
| 227 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 228 | - } else { |
|
| 229 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 230 | - } |
|
| 231 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_SELF) { |
|
| 232 | - $event->setParsedSubject($this->l->t('You unshared %1$s from %2$s by mail', [ |
|
| 233 | - $parsedParameters['file']['path'], |
|
| 234 | - $parsedParameters['email']['name'], |
|
| 235 | - ])) |
|
| 236 | - ->setRichSubject($this->l->t('You unshared {file} from {email} by mail'), $parsedParameters); |
|
| 237 | - if ($this->activityManager->getRequirePNG()) { |
|
| 238 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 239 | - } else { |
|
| 240 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 241 | - } |
|
| 242 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_BY) { |
|
| 243 | - $event->setParsedSubject($this->l->t('%3$s unshared %1$s from %2$s by mail', [ |
|
| 244 | - $parsedParameters['file']['path'], |
|
| 245 | - $parsedParameters['email']['name'], |
|
| 246 | - $parsedParameters['actor']['name'], |
|
| 247 | - ])) |
|
| 248 | - ->setRichSubject($this->l->t('{actor} unshared {file} from {email} by mail'), $parsedParameters); |
|
| 249 | - if ($this->activityManager->getRequirePNG()) { |
|
| 250 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 251 | - } else { |
|
| 252 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 253 | - } |
|
| 254 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
| 255 | - $event->setParsedSubject($this->l->t('Password to access %1$s was sent to %2s', [ |
|
| 256 | - $parsedParameters['file']['path'], |
|
| 257 | - $parsedParameters['email']['name'] |
|
| 258 | - ])) |
|
| 259 | - ->setRichSubject($this->l->t('Password to access {file} was sent to {email}'), $parsedParameters); |
|
| 260 | - if ($this->activityManager->getRequirePNG()) { |
|
| 261 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 262 | - } else { |
|
| 263 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 264 | - } |
|
| 265 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
| 266 | - $event->setParsedSubject( |
|
| 267 | - $this->l->t('Password to access %1$s was sent to you', |
|
| 268 | - [$parsedParameters['file']['path']])) |
|
| 269 | - ->setRichSubject($this->l->t('Password to access {file} was sent to you'), $parsedParameters); |
|
| 270 | - if ($this->activityManager->getRequirePNG()) { |
|
| 271 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 272 | - } else { |
|
| 273 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - } else { |
|
| 277 | - throw new \InvalidArgumentException(); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - return $event; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - protected function getParsedParameters(IEvent $event) { |
|
| 284 | - $subject = $event->getSubject(); |
|
| 285 | - $parameters = $event->getSubjectParameters(); |
|
| 286 | - |
|
| 287 | - switch ($subject) { |
|
| 288 | - case self::SUBJECT_SHARED_EMAIL_SELF: |
|
| 289 | - case self::SUBJECT_UNSHARED_EMAIL_SELF: |
|
| 290 | - return [ |
|
| 291 | - 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
| 292 | - 'email' => $this->generateEmailParameter($parameters[1]), |
|
| 293 | - ]; |
|
| 294 | - case self::SUBJECT_SHARED_EMAIL_BY: |
|
| 295 | - case self::SUBJECT_UNSHARED_EMAIL_BY: |
|
| 296 | - return [ |
|
| 297 | - 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
| 298 | - 'email' => $this->generateEmailParameter($parameters[1]), |
|
| 299 | - 'actor' => $this->generateUserParameter($parameters[2]), |
|
| 300 | - ]; |
|
| 301 | - case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND: |
|
| 302 | - return [ |
|
| 303 | - 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
| 304 | - 'email' => $this->generateEmailParameter($parameters[1]), |
|
| 305 | - ]; |
|
| 306 | - case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF: |
|
| 307 | - return [ |
|
| 308 | - 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
| 309 | - ]; |
|
| 310 | - } |
|
| 311 | - throw new \InvalidArgumentException(); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * @param int $id |
|
| 316 | - * @param string $path |
|
| 317 | - * @return array |
|
| 318 | - */ |
|
| 319 | - protected function generateFileParameter($id, $path) { |
|
| 320 | - return [ |
|
| 321 | - 'type' => 'file', |
|
| 322 | - 'id' => $id, |
|
| 323 | - 'name' => basename($path), |
|
| 324 | - 'path' => trim($path, '/'), |
|
| 325 | - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
| 326 | - ]; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * @param string $email |
|
| 331 | - * @return array |
|
| 332 | - */ |
|
| 333 | - protected function generateEmailParameter($email) { |
|
| 334 | - if (!isset($this->contactNames[$email])) { |
|
| 335 | - $this->contactNames[$email] = $this->getContactName($email); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - return [ |
|
| 339 | - 'type' => 'email', |
|
| 340 | - 'id' => $email, |
|
| 341 | - 'name' => $this->contactNames[$email], |
|
| 342 | - ]; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * @param string $uid |
|
| 347 | - * @return array |
|
| 348 | - */ |
|
| 349 | - protected function generateUserParameter($uid) { |
|
| 350 | - if (!isset($this->displayNames[$uid])) { |
|
| 351 | - $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - return [ |
|
| 355 | - 'type' => 'user', |
|
| 356 | - 'id' => $uid, |
|
| 357 | - 'name' => $this->displayNames[$uid], |
|
| 358 | - ]; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * @param string $email |
|
| 363 | - * @return string |
|
| 364 | - */ |
|
| 365 | - protected function getContactName($email) { |
|
| 366 | - $addressBookContacts = $this->contactsManager->search($email, ['EMAIL']); |
|
| 367 | - |
|
| 368 | - foreach ($addressBookContacts as $contact) { |
|
| 369 | - if (isset($contact['isLocalSystemBook'])) { |
|
| 370 | - continue; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - if (in_array($email, $contact['EMAIL'])) { |
|
| 374 | - return $contact['FN']; |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - return $email; |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * @param string $uid |
|
| 383 | - * @return string |
|
| 384 | - */ |
|
| 385 | - protected function getDisplayName($uid) { |
|
| 386 | - $user = $this->userManager->get($uid); |
|
| 387 | - if ($user instanceof IUser) { |
|
| 388 | - return $user->getDisplayName(); |
|
| 389 | - } else { |
|
| 390 | - return $uid; |
|
| 391 | - } |
|
| 392 | - } |
|
| 40 | + /** @var IFactory */ |
|
| 41 | + protected $languageFactory; |
|
| 42 | + |
|
| 43 | + /** @var IL10N */ |
|
| 44 | + protected $l; |
|
| 45 | + |
|
| 46 | + /** @var IURLGenerator */ |
|
| 47 | + protected $url; |
|
| 48 | + |
|
| 49 | + /** @var IManager */ |
|
| 50 | + protected $activityManager; |
|
| 51 | + |
|
| 52 | + /** @var IUserManager */ |
|
| 53 | + protected $userManager; |
|
| 54 | + /** @var IContactsManager */ |
|
| 55 | + protected $contactsManager; |
|
| 56 | + |
|
| 57 | + /** @var array */ |
|
| 58 | + protected $displayNames = []; |
|
| 59 | + |
|
| 60 | + /** @var array */ |
|
| 61 | + protected $contactNames = []; |
|
| 62 | + |
|
| 63 | + const SUBJECT_SHARED_EMAIL_SELF = 'shared_with_email_self'; |
|
| 64 | + const SUBJECT_SHARED_EMAIL_BY = 'shared_with_email_by'; |
|
| 65 | + const SUBJECT_SHARED_EMAIL_PASSWORD_SEND = 'shared_with_email_password_send'; |
|
| 66 | + const SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF = 'shared_with_email_password_send_self'; |
|
| 67 | + const SUBJECT_UNSHARED_EMAIL_SELF = 'unshared_with_email_self'; |
|
| 68 | + const SUBJECT_UNSHARED_EMAIL_BY = 'unshared_with_email_by'; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @param IFactory $languageFactory |
|
| 72 | + * @param IURLGenerator $url |
|
| 73 | + * @param IManager $activityManager |
|
| 74 | + * @param IUserManager $userManager |
|
| 75 | + * @param IContactsManager $contactsManager |
|
| 76 | + */ |
|
| 77 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IContactsManager $contactsManager) { |
|
| 78 | + $this->languageFactory = $languageFactory; |
|
| 79 | + $this->url = $url; |
|
| 80 | + $this->activityManager = $activityManager; |
|
| 81 | + $this->userManager = $userManager; |
|
| 82 | + $this->contactsManager = $contactsManager; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @param string $language |
|
| 87 | + * @param IEvent $event |
|
| 88 | + * @param IEvent|null $previousEvent |
|
| 89 | + * @return IEvent |
|
| 90 | + * @throws \InvalidArgumentException |
|
| 91 | + * @since 11.0.0 |
|
| 92 | + */ |
|
| 93 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 94 | + if ($event->getApp() !== 'sharebymail') { |
|
| 95 | + throw new \InvalidArgumentException(); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + $this->l = $this->languageFactory->get('sharebymail', $language); |
|
| 99 | + |
|
| 100 | + if ($this->activityManager->isFormattingFilteredObject()) { |
|
| 101 | + try { |
|
| 102 | + return $this->parseShortVersion($event); |
|
| 103 | + } catch (\InvalidArgumentException $e) { |
|
| 104 | + // Ignore and simply use the long version... |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + return $this->parseLongVersion($event); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @param IEvent $event |
|
| 113 | + * @return IEvent |
|
| 114 | + * @throws \InvalidArgumentException |
|
| 115 | + * @since 11.0.0 |
|
| 116 | + */ |
|
| 117 | + public function parseShortVersion(IEvent $event) { |
|
| 118 | + $parsedParameters = $this->getParsedParameters($event); |
|
| 119 | + |
|
| 120 | + if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
| 121 | + $event->setParsedSubject($this->l->t('Shared with %1$s', [ |
|
| 122 | + $parsedParameters['email']['name'], |
|
| 123 | + ])) |
|
| 124 | + ->setRichSubject($this->l->t('Shared with {email}'), [ |
|
| 125 | + 'email' => $parsedParameters['email'], |
|
| 126 | + ]); |
|
| 127 | + if ($this->activityManager->getRequirePNG()) { |
|
| 128 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 129 | + } else { |
|
| 130 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 131 | + } |
|
| 132 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
| 133 | + $event->setParsedSubject($this->l->t('Shared with %1$s by %2$s', [ |
|
| 134 | + $parsedParameters['email']['name'], |
|
| 135 | + $parsedParameters['actor']['name'], |
|
| 136 | + ])) |
|
| 137 | + ->setRichSubject($this->l->t('Shared with {email} by {actor}'), [ |
|
| 138 | + 'email' => $parsedParameters['email'], |
|
| 139 | + 'actor' => $parsedParameters['actor'], |
|
| 140 | + ]); |
|
| 141 | + if ($this->activityManager->getRequirePNG()) { |
|
| 142 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 143 | + } else { |
|
| 144 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 145 | + } |
|
| 146 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_SELF) { |
|
| 147 | + $event->setParsedSubject($this->l->t('Unshared from %1$s', [ |
|
| 148 | + $parsedParameters['email']['name'], |
|
| 149 | + ])) |
|
| 150 | + ->setRichSubject($this->l->t('Unshared from {email}'), [ |
|
| 151 | + 'email' => $parsedParameters['email'], |
|
| 152 | + ]); |
|
| 153 | + if ($this->activityManager->getRequirePNG()) { |
|
| 154 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 155 | + } else { |
|
| 156 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 157 | + } |
|
| 158 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_BY) { |
|
| 159 | + $event->setParsedSubject($this->l->t('Unshared from %1$s by %2$s', [ |
|
| 160 | + $parsedParameters['email']['name'], |
|
| 161 | + $parsedParameters['actor']['name'], |
|
| 162 | + ])) |
|
| 163 | + ->setRichSubject($this->l->t('Unshared from {email} by {actor}'), [ |
|
| 164 | + 'email' => $parsedParameters['email'], |
|
| 165 | + 'actor' => $parsedParameters['actor'], |
|
| 166 | + ]); |
|
| 167 | + if ($this->activityManager->getRequirePNG()) { |
|
| 168 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 169 | + } else { |
|
| 170 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 171 | + } |
|
| 172 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
| 173 | + $event->setParsedSubject($this->l->t('Password for mail share sent to %1$s', [ |
|
| 174 | + $parsedParameters['email']['name'] |
|
| 175 | + ])) |
|
| 176 | + ->setRichSubject($this->l->t('Password for mail share sent to {email}'), [ |
|
| 177 | + 'email' => $parsedParameters['email'] |
|
| 178 | + ]); |
|
| 179 | + if ($this->activityManager->getRequirePNG()) { |
|
| 180 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 181 | + } else { |
|
| 182 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 183 | + } |
|
| 184 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
| 185 | + $event->setParsedSubject($this->l->t('Password for mail share sent to you')) |
|
| 186 | + ->setRichSubject($this->l->t('Password for mail share sent to you')); |
|
| 187 | + if ($this->activityManager->getRequirePNG()) { |
|
| 188 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 189 | + } else { |
|
| 190 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 191 | + } |
|
| 192 | + } else { |
|
| 193 | + throw new \InvalidArgumentException(); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + return $event; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * @param IEvent $event |
|
| 201 | + * @return IEvent |
|
| 202 | + * @throws \InvalidArgumentException |
|
| 203 | + * @since 11.0.0 |
|
| 204 | + */ |
|
| 205 | + public function parseLongVersion(IEvent $event) { |
|
| 206 | + $parsedParameters = $this->getParsedParameters($event); |
|
| 207 | + |
|
| 208 | + if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
| 209 | + $event->setParsedSubject($this->l->t('You shared %1$s with %2$s by mail', [ |
|
| 210 | + $parsedParameters['file']['path'], |
|
| 211 | + $parsedParameters['email']['name'], |
|
| 212 | + ])) |
|
| 213 | + ->setRichSubject($this->l->t('You shared {file} with {email} by mail'), $parsedParameters); |
|
| 214 | + if ($this->activityManager->getRequirePNG()) { |
|
| 215 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 216 | + } else { |
|
| 217 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 218 | + } |
|
| 219 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
| 220 | + $event->setParsedSubject($this->l->t('%3$s shared %1$s with %2$s by mail', [ |
|
| 221 | + $parsedParameters['file']['path'], |
|
| 222 | + $parsedParameters['email']['name'], |
|
| 223 | + $parsedParameters['actor']['name'], |
|
| 224 | + ])) |
|
| 225 | + ->setRichSubject($this->l->t('{actor} shared {file} with {email} by mail'), $parsedParameters); |
|
| 226 | + if ($this->activityManager->getRequirePNG()) { |
|
| 227 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 228 | + } else { |
|
| 229 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 230 | + } |
|
| 231 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_SELF) { |
|
| 232 | + $event->setParsedSubject($this->l->t('You unshared %1$s from %2$s by mail', [ |
|
| 233 | + $parsedParameters['file']['path'], |
|
| 234 | + $parsedParameters['email']['name'], |
|
| 235 | + ])) |
|
| 236 | + ->setRichSubject($this->l->t('You unshared {file} from {email} by mail'), $parsedParameters); |
|
| 237 | + if ($this->activityManager->getRequirePNG()) { |
|
| 238 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 239 | + } else { |
|
| 240 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 241 | + } |
|
| 242 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_BY) { |
|
| 243 | + $event->setParsedSubject($this->l->t('%3$s unshared %1$s from %2$s by mail', [ |
|
| 244 | + $parsedParameters['file']['path'], |
|
| 245 | + $parsedParameters['email']['name'], |
|
| 246 | + $parsedParameters['actor']['name'], |
|
| 247 | + ])) |
|
| 248 | + ->setRichSubject($this->l->t('{actor} unshared {file} from {email} by mail'), $parsedParameters); |
|
| 249 | + if ($this->activityManager->getRequirePNG()) { |
|
| 250 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 251 | + } else { |
|
| 252 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 253 | + } |
|
| 254 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
| 255 | + $event->setParsedSubject($this->l->t('Password to access %1$s was sent to %2s', [ |
|
| 256 | + $parsedParameters['file']['path'], |
|
| 257 | + $parsedParameters['email']['name'] |
|
| 258 | + ])) |
|
| 259 | + ->setRichSubject($this->l->t('Password to access {file} was sent to {email}'), $parsedParameters); |
|
| 260 | + if ($this->activityManager->getRequirePNG()) { |
|
| 261 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 262 | + } else { |
|
| 263 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 264 | + } |
|
| 265 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
| 266 | + $event->setParsedSubject( |
|
| 267 | + $this->l->t('Password to access %1$s was sent to you', |
|
| 268 | + [$parsedParameters['file']['path']])) |
|
| 269 | + ->setRichSubject($this->l->t('Password to access {file} was sent to you'), $parsedParameters); |
|
| 270 | + if ($this->activityManager->getRequirePNG()) { |
|
| 271 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 272 | + } else { |
|
| 273 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + } else { |
|
| 277 | + throw new \InvalidArgumentException(); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + return $event; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + protected function getParsedParameters(IEvent $event) { |
|
| 284 | + $subject = $event->getSubject(); |
|
| 285 | + $parameters = $event->getSubjectParameters(); |
|
| 286 | + |
|
| 287 | + switch ($subject) { |
|
| 288 | + case self::SUBJECT_SHARED_EMAIL_SELF: |
|
| 289 | + case self::SUBJECT_UNSHARED_EMAIL_SELF: |
|
| 290 | + return [ |
|
| 291 | + 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
| 292 | + 'email' => $this->generateEmailParameter($parameters[1]), |
|
| 293 | + ]; |
|
| 294 | + case self::SUBJECT_SHARED_EMAIL_BY: |
|
| 295 | + case self::SUBJECT_UNSHARED_EMAIL_BY: |
|
| 296 | + return [ |
|
| 297 | + 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
| 298 | + 'email' => $this->generateEmailParameter($parameters[1]), |
|
| 299 | + 'actor' => $this->generateUserParameter($parameters[2]), |
|
| 300 | + ]; |
|
| 301 | + case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND: |
|
| 302 | + return [ |
|
| 303 | + 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
| 304 | + 'email' => $this->generateEmailParameter($parameters[1]), |
|
| 305 | + ]; |
|
| 306 | + case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF: |
|
| 307 | + return [ |
|
| 308 | + 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
| 309 | + ]; |
|
| 310 | + } |
|
| 311 | + throw new \InvalidArgumentException(); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * @param int $id |
|
| 316 | + * @param string $path |
|
| 317 | + * @return array |
|
| 318 | + */ |
|
| 319 | + protected function generateFileParameter($id, $path) { |
|
| 320 | + return [ |
|
| 321 | + 'type' => 'file', |
|
| 322 | + 'id' => $id, |
|
| 323 | + 'name' => basename($path), |
|
| 324 | + 'path' => trim($path, '/'), |
|
| 325 | + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
| 326 | + ]; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * @param string $email |
|
| 331 | + * @return array |
|
| 332 | + */ |
|
| 333 | + protected function generateEmailParameter($email) { |
|
| 334 | + if (!isset($this->contactNames[$email])) { |
|
| 335 | + $this->contactNames[$email] = $this->getContactName($email); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + return [ |
|
| 339 | + 'type' => 'email', |
|
| 340 | + 'id' => $email, |
|
| 341 | + 'name' => $this->contactNames[$email], |
|
| 342 | + ]; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * @param string $uid |
|
| 347 | + * @return array |
|
| 348 | + */ |
|
| 349 | + protected function generateUserParameter($uid) { |
|
| 350 | + if (!isset($this->displayNames[$uid])) { |
|
| 351 | + $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + return [ |
|
| 355 | + 'type' => 'user', |
|
| 356 | + 'id' => $uid, |
|
| 357 | + 'name' => $this->displayNames[$uid], |
|
| 358 | + ]; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * @param string $email |
|
| 363 | + * @return string |
|
| 364 | + */ |
|
| 365 | + protected function getContactName($email) { |
|
| 366 | + $addressBookContacts = $this->contactsManager->search($email, ['EMAIL']); |
|
| 367 | + |
|
| 368 | + foreach ($addressBookContacts as $contact) { |
|
| 369 | + if (isset($contact['isLocalSystemBook'])) { |
|
| 370 | + continue; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + if (in_array($email, $contact['EMAIL'])) { |
|
| 374 | + return $contact['FN']; |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + return $email; |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * @param string $uid |
|
| 383 | + * @return string |
|
| 384 | + */ |
|
| 385 | + protected function getDisplayName($uid) { |
|
| 386 | + $user = $this->userManager->get($uid); |
|
| 387 | + if ($user instanceof IUser) { |
|
| 388 | + return $user->getDisplayName(); |
|
| 389 | + } else { |
|
| 390 | + return $uid; |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | 393 | } |
@@ -62,926 +62,926 @@ |
||
| 62 | 62 | |
| 63 | 63 | class UsersController extends AUserData { |
| 64 | 64 | |
| 65 | - /** @var IAppManager */ |
|
| 66 | - private $appManager; |
|
| 67 | - /** @var ILogger */ |
|
| 68 | - private $logger; |
|
| 69 | - /** @var IFactory */ |
|
| 70 | - private $l10nFactory; |
|
| 71 | - /** @var NewUserMailHelper */ |
|
| 72 | - private $newUserMailHelper; |
|
| 73 | - /** @var FederatedFileSharingFactory */ |
|
| 74 | - private $federatedFileSharingFactory; |
|
| 75 | - /** @var ISecureRandom */ |
|
| 76 | - private $secureRandom; |
|
| 77 | - /** @var RemoteWipe */ |
|
| 78 | - private $remoteWipe; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @param string $appName |
|
| 82 | - * @param IRequest $request |
|
| 83 | - * @param IUserManager $userManager |
|
| 84 | - * @param IConfig $config |
|
| 85 | - * @param IAppManager $appManager |
|
| 86 | - * @param IGroupManager $groupManager |
|
| 87 | - * @param IUserSession $userSession |
|
| 88 | - * @param AccountManager $accountManager |
|
| 89 | - * @param ILogger $logger |
|
| 90 | - * @param IFactory $l10nFactory |
|
| 91 | - * @param NewUserMailHelper $newUserMailHelper |
|
| 92 | - * @param FederatedFileSharingFactory $federatedFileSharingFactory |
|
| 93 | - * @param ISecureRandom $secureRandom |
|
| 94 | - */ |
|
| 95 | - public function __construct(string $appName, |
|
| 96 | - IRequest $request, |
|
| 97 | - IUserManager $userManager, |
|
| 98 | - IConfig $config, |
|
| 99 | - IAppManager $appManager, |
|
| 100 | - IGroupManager $groupManager, |
|
| 101 | - IUserSession $userSession, |
|
| 102 | - AccountManager $accountManager, |
|
| 103 | - ILogger $logger, |
|
| 104 | - IFactory $l10nFactory, |
|
| 105 | - NewUserMailHelper $newUserMailHelper, |
|
| 106 | - FederatedFileSharingFactory $federatedFileSharingFactory, |
|
| 107 | - ISecureRandom $secureRandom, |
|
| 108 | - RemoteWipe $remoteWipe) { |
|
| 109 | - parent::__construct($appName, |
|
| 110 | - $request, |
|
| 111 | - $userManager, |
|
| 112 | - $config, |
|
| 113 | - $groupManager, |
|
| 114 | - $userSession, |
|
| 115 | - $accountManager); |
|
| 116 | - |
|
| 117 | - $this->appManager = $appManager; |
|
| 118 | - $this->logger = $logger; |
|
| 119 | - $this->l10nFactory = $l10nFactory; |
|
| 120 | - $this->newUserMailHelper = $newUserMailHelper; |
|
| 121 | - $this->federatedFileSharingFactory = $federatedFileSharingFactory; |
|
| 122 | - $this->secureRandom = $secureRandom; |
|
| 123 | - $this->remoteWipe = $remoteWipe; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @NoAdminRequired |
|
| 128 | - * |
|
| 129 | - * returns a list of users |
|
| 130 | - * |
|
| 131 | - * @param string $search |
|
| 132 | - * @param int $limit |
|
| 133 | - * @param int $offset |
|
| 134 | - * @return DataResponse |
|
| 135 | - */ |
|
| 136 | - public function getUsers(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
| 137 | - $user = $this->userSession->getUser(); |
|
| 138 | - $users = []; |
|
| 139 | - |
|
| 140 | - // Admin? Or SubAdmin? |
|
| 141 | - $uid = $user->getUID(); |
|
| 142 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 143 | - if ($this->groupManager->isAdmin($uid)){ |
|
| 144 | - $users = $this->userManager->search($search, $limit, $offset); |
|
| 145 | - } else if ($subAdminManager->isSubAdmin($user)) { |
|
| 146 | - $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
|
| 147 | - foreach ($subAdminOfGroups as $key => $group) { |
|
| 148 | - $subAdminOfGroups[$key] = $group->getGID(); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - $users = []; |
|
| 152 | - foreach ($subAdminOfGroups as $group) { |
|
| 153 | - $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search, $limit, $offset)); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - $users = array_keys($users); |
|
| 158 | - |
|
| 159 | - return new DataResponse([ |
|
| 160 | - 'users' => $users |
|
| 161 | - ]); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @NoAdminRequired |
|
| 166 | - * |
|
| 167 | - * returns a list of users and their data |
|
| 168 | - */ |
|
| 169 | - public function getUsersDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
| 170 | - $currentUser = $this->userSession->getUser(); |
|
| 171 | - $users = []; |
|
| 172 | - |
|
| 173 | - // Admin? Or SubAdmin? |
|
| 174 | - $uid = $currentUser->getUID(); |
|
| 175 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 176 | - if ($this->groupManager->isAdmin($uid)){ |
|
| 177 | - $users = $this->userManager->search($search, $limit, $offset); |
|
| 178 | - $users = array_keys($users); |
|
| 179 | - } else if ($subAdminManager->isSubAdmin($currentUser)) { |
|
| 180 | - $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($currentUser); |
|
| 181 | - foreach ($subAdminOfGroups as $key => $group) { |
|
| 182 | - $subAdminOfGroups[$key] = $group->getGID(); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - $users = []; |
|
| 186 | - foreach ($subAdminOfGroups as $group) { |
|
| 187 | - $users[] = array_keys($this->groupManager->displayNamesInGroup($group, $search, $limit, $offset)); |
|
| 188 | - } |
|
| 189 | - $users = array_merge(...$users); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - $usersDetails = []; |
|
| 193 | - foreach ($users as $userId) { |
|
| 194 | - $userId = (string) $userId; |
|
| 195 | - $userData = $this->getUserData($userId); |
|
| 196 | - // Do not insert empty entry |
|
| 197 | - if (!empty($userData)) { |
|
| 198 | - $usersDetails[$userId] = $userData; |
|
| 199 | - } else { |
|
| 200 | - // Logged user does not have permissions to see this user |
|
| 201 | - // only showing its id |
|
| 202 | - $usersDetails[$userId] = ['id' => $userId]; |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - return new DataResponse([ |
|
| 207 | - 'users' => $usersDetails |
|
| 208 | - ]); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * @throws OCSException |
|
| 213 | - */ |
|
| 214 | - private function createNewUserId(): string { |
|
| 215 | - $attempts = 0; |
|
| 216 | - do { |
|
| 217 | - $uidCandidate = $this->secureRandom->generate(10, ISecureRandom::CHAR_HUMAN_READABLE); |
|
| 218 | - if (!$this->userManager->userExists($uidCandidate)) { |
|
| 219 | - return $uidCandidate; |
|
| 220 | - } |
|
| 221 | - $attempts++; |
|
| 222 | - } while ($attempts < 10); |
|
| 223 | - throw new OCSException('Could not create non-existing user id', 111); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * @PasswordConfirmationRequired |
|
| 228 | - * @NoAdminRequired |
|
| 229 | - * |
|
| 230 | - * @param string $userid |
|
| 231 | - * @param string $password |
|
| 232 | - * @param string $displayName |
|
| 233 | - * @param string $email |
|
| 234 | - * @param array $groups |
|
| 235 | - * @param array $subadmin |
|
| 236 | - * @param string $quota |
|
| 237 | - * @param string $language |
|
| 238 | - * @return DataResponse |
|
| 239 | - * @throws OCSException |
|
| 240 | - */ |
|
| 241 | - public function addUser(string $userid, |
|
| 242 | - string $password = '', |
|
| 243 | - string $displayName = '', |
|
| 244 | - string $email = '', |
|
| 245 | - array $groups = [], |
|
| 246 | - array $subadmin = [], |
|
| 247 | - string $quota = '', |
|
| 248 | - string $language = ''): DataResponse { |
|
| 249 | - $user = $this->userSession->getUser(); |
|
| 250 | - $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
|
| 251 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 252 | - |
|
| 253 | - if(empty($userid) && $this->config->getAppValue('core', 'newUser.generateUserID', 'no') === 'yes') { |
|
| 254 | - $userid = $this->createNewUserId(); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - if ($this->userManager->userExists($userid)) { |
|
| 258 | - $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']); |
|
| 259 | - throw new OCSException('User already exists', 102); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - if ($groups !== []) { |
|
| 263 | - foreach ($groups as $group) { |
|
| 264 | - if (!$this->groupManager->groupExists($group)) { |
|
| 265 | - throw new OCSException('group '.$group.' does not exist', 104); |
|
| 266 | - } |
|
| 267 | - if (!$isAdmin && !$subAdminManager->isSubAdminOfGroup($user, $this->groupManager->get($group))) { |
|
| 268 | - throw new OCSException('insufficient privileges for group '. $group, 105); |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - } else { |
|
| 272 | - if (!$isAdmin) { |
|
| 273 | - throw new OCSException('no group specified (required for subadmins)', 106); |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - $subadminGroups = []; |
|
| 278 | - if ($subadmin !== []) { |
|
| 279 | - foreach ($subadmin as $groupid) { |
|
| 280 | - $group = $this->groupManager->get($groupid); |
|
| 281 | - // Check if group exists |
|
| 282 | - if ($group === null) { |
|
| 283 | - throw new OCSException('Subadmin group does not exist', 102); |
|
| 284 | - } |
|
| 285 | - // Check if trying to make subadmin of admin group |
|
| 286 | - if ($group->getGID() === 'admin') { |
|
| 287 | - throw new OCSException('Cannot create subadmins for admin group', 103); |
|
| 288 | - } |
|
| 289 | - // Check if has permission to promote subadmins |
|
| 290 | - if (!$subAdminManager->isSubAdminOfGroup($user, $group) && !$isAdmin) { |
|
| 291 | - throw new OCSForbiddenException('No permissions to promote subadmins'); |
|
| 292 | - } |
|
| 293 | - $subadminGroups[] = $group; |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - $generatePasswordResetToken = false; |
|
| 298 | - if ($password === '') { |
|
| 299 | - if ($email === '') { |
|
| 300 | - throw new OCSException('To send a password link to the user an email address is required.', 108); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - $password = $this->secureRandom->generate(10); |
|
| 304 | - // Make sure we pass the password_policy |
|
| 305 | - $password .= $this->secureRandom->generate(2, '$!.,;:-~+*[]{}()'); |
|
| 306 | - $generatePasswordResetToken = true; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - if ($email === '' && $this->config->getAppValue('core', 'newUser.requireEmail', 'no') === 'yes') { |
|
| 310 | - throw new OCSException('Required email address was not provided', 110); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - try { |
|
| 314 | - $newUser = $this->userManager->createUser($userid, $password); |
|
| 315 | - $this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']); |
|
| 316 | - |
|
| 317 | - foreach ($groups as $group) { |
|
| 318 | - $this->groupManager->get($group)->addUser($newUser); |
|
| 319 | - $this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']); |
|
| 320 | - } |
|
| 321 | - foreach ($subadminGroups as $group) { |
|
| 322 | - $subAdminManager->createSubAdmin($newUser, $group); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - if ($displayName !== '') { |
|
| 326 | - $this->editUser($userid, 'display', $displayName); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - if ($quota !== '') { |
|
| 330 | - $this->editUser($userid, 'quota', $quota); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - if ($language !== '') { |
|
| 334 | - $this->editUser($userid, 'language', $language); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - // Send new user mail only if a mail is set |
|
| 338 | - if ($email !== '' && $this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes') { |
|
| 339 | - $newUser->setEMailAddress($email); |
|
| 340 | - try { |
|
| 341 | - $emailTemplate = $this->newUserMailHelper->generateTemplate($newUser, $generatePasswordResetToken); |
|
| 342 | - $this->newUserMailHelper->sendMail($newUser, $emailTemplate); |
|
| 343 | - } catch (\Exception $e) { |
|
| 344 | - // Mail could be failing hard or just be plain not configured |
|
| 345 | - // Logging error as it is the hardest of the two |
|
| 346 | - $this->logger->logException($e, [ |
|
| 347 | - 'message' => "Unable to send the invitation mail to $email", |
|
| 348 | - 'level' => ILogger::ERROR, |
|
| 349 | - 'app' => 'ocs_api', |
|
| 350 | - ]); |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - return new DataResponse(['id' => $userid]); |
|
| 355 | - |
|
| 356 | - } catch (HintException $e) { |
|
| 357 | - $this->logger->logException($e, [ |
|
| 358 | - 'message' => 'Failed addUser attempt with hint exception.', |
|
| 359 | - 'level' => ILogger::WARN, |
|
| 360 | - 'app' => 'ocs_api', |
|
| 361 | - ]); |
|
| 362 | - throw new OCSException($e->getHint(), 107); |
|
| 363 | - } catch (OCSException $e) { |
|
| 364 | - $this->logger->logException($e, [ |
|
| 365 | - 'message' => 'Failed addUser attempt with ocs exeption.', |
|
| 366 | - 'level' => ILogger::ERROR, |
|
| 367 | - 'app' => 'ocs_api', |
|
| 368 | - ]); |
|
| 369 | - throw $e; |
|
| 370 | - } catch (\Exception $e) { |
|
| 371 | - $this->logger->logException($e, [ |
|
| 372 | - 'message' => 'Failed addUser attempt with exception.', |
|
| 373 | - 'level' => ILogger::ERROR, |
|
| 374 | - 'app' => 'ocs_api', |
|
| 375 | - ]); |
|
| 376 | - throw new OCSException('Bad request', 101); |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * @NoAdminRequired |
|
| 382 | - * @NoSubAdminRequired |
|
| 383 | - * |
|
| 384 | - * gets user info |
|
| 385 | - * |
|
| 386 | - * @param string $userId |
|
| 387 | - * @return DataResponse |
|
| 388 | - * @throws OCSException |
|
| 389 | - */ |
|
| 390 | - public function getUser(string $userId): DataResponse { |
|
| 391 | - $data = $this->getUserData($userId); |
|
| 392 | - // getUserData returns empty array if not enough permissions |
|
| 393 | - if (empty($data)) { |
|
| 394 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 395 | - } |
|
| 396 | - return new DataResponse($data); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - /** |
|
| 400 | - * @NoAdminRequired |
|
| 401 | - * @NoSubAdminRequired |
|
| 402 | - * |
|
| 403 | - * gets user info from the currently logged in user |
|
| 404 | - * |
|
| 405 | - * @return DataResponse |
|
| 406 | - * @throws OCSException |
|
| 407 | - */ |
|
| 408 | - public function getCurrentUser(): DataResponse { |
|
| 409 | - $user = $this->userSession->getUser(); |
|
| 410 | - if ($user) { |
|
| 411 | - $data = $this->getUserData($user->getUID()); |
|
| 412 | - // rename "displayname" to "display-name" only for this call to keep |
|
| 413 | - // the API stable. |
|
| 414 | - $data['display-name'] = $data['displayname']; |
|
| 415 | - unset($data['displayname']); |
|
| 416 | - return new DataResponse($data); |
|
| 417 | - |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * @NoAdminRequired |
|
| 425 | - * @NoSubAdminRequired |
|
| 426 | - */ |
|
| 427 | - public function getEditableFields(): DataResponse { |
|
| 428 | - $permittedFields = []; |
|
| 429 | - |
|
| 430 | - // Editing self (display, email) |
|
| 431 | - if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
|
| 432 | - $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
| 433 | - $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - if ($this->appManager->isEnabledForUser('federatedfilesharing')) { |
|
| 437 | - $federatedFileSharing = $this->federatedFileSharingFactory->get(); |
|
| 438 | - $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
| 439 | - if ($shareProvider->isLookupServerUploadEnabled()) { |
|
| 440 | - $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
| 441 | - $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
| 442 | - $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
| 443 | - $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - return new DataResponse($permittedFields); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * @NoAdminRequired |
|
| 452 | - * @NoSubAdminRequired |
|
| 453 | - * @PasswordConfirmationRequired |
|
| 454 | - * |
|
| 455 | - * edit users |
|
| 456 | - * |
|
| 457 | - * @param string $userId |
|
| 458 | - * @param string $key |
|
| 459 | - * @param string $value |
|
| 460 | - * @return DataResponse |
|
| 461 | - * @throws OCSException |
|
| 462 | - */ |
|
| 463 | - public function editUser(string $userId, string $key, string $value): DataResponse { |
|
| 464 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 465 | - |
|
| 466 | - $targetUser = $this->userManager->get($userId); |
|
| 467 | - if ($targetUser === null) { |
|
| 468 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - $permittedFields = []; |
|
| 472 | - if ($targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 473 | - // Editing self (display, email) |
|
| 474 | - if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
|
| 475 | - $permittedFields[] = 'display'; |
|
| 476 | - $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
| 477 | - $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - $permittedFields[] = 'password'; |
|
| 481 | - if ($this->config->getSystemValue('force_language', false) === false || |
|
| 482 | - $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 483 | - $permittedFields[] = 'language'; |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - if ($this->config->getSystemValue('force_locale', false) === false || |
|
| 487 | - $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 488 | - $permittedFields[] = 'locale'; |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - if ($this->appManager->isEnabledForUser('federatedfilesharing')) { |
|
| 492 | - $federatedFileSharing = \OC::$server->query(\OCA\FederatedFileSharing\AppInfo\Application::class); |
|
| 493 | - $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
| 494 | - if ($shareProvider->isLookupServerUploadEnabled()) { |
|
| 495 | - $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
| 496 | - $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
| 497 | - $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
| 498 | - $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - // If admin they can edit their own quota |
|
| 503 | - if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 504 | - $permittedFields[] = 'quota'; |
|
| 505 | - } |
|
| 506 | - } else { |
|
| 507 | - // Check if admin / subadmin |
|
| 508 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 509 | - if ($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
| 510 | - || $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 511 | - // They have permissions over the user |
|
| 512 | - $permittedFields[] = 'display'; |
|
| 513 | - $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
| 514 | - $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
| 515 | - $permittedFields[] = 'password'; |
|
| 516 | - $permittedFields[] = 'language'; |
|
| 517 | - $permittedFields[] = 'locale'; |
|
| 518 | - $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
| 519 | - $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
| 520 | - $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
| 521 | - $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
| 522 | - $permittedFields[] = 'quota'; |
|
| 523 | - } else { |
|
| 524 | - // No rights |
|
| 525 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - // Check if permitted to edit this field |
|
| 529 | - if (!in_array($key, $permittedFields)) { |
|
| 530 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 531 | - } |
|
| 532 | - // Process the edit |
|
| 533 | - switch($key) { |
|
| 534 | - case 'display': |
|
| 535 | - case AccountManager::PROPERTY_DISPLAYNAME: |
|
| 536 | - $targetUser->setDisplayName($value); |
|
| 537 | - break; |
|
| 538 | - case 'quota': |
|
| 539 | - $quota = $value; |
|
| 540 | - if ($quota !== 'none' && $quota !== 'default') { |
|
| 541 | - if (is_numeric($quota)) { |
|
| 542 | - $quota = (float) $quota; |
|
| 543 | - } else { |
|
| 544 | - $quota = \OCP\Util::computerFileSize($quota); |
|
| 545 | - } |
|
| 546 | - if ($quota === false) { |
|
| 547 | - throw new OCSException('Invalid quota value '.$value, 103); |
|
| 548 | - } |
|
| 549 | - if ($quota === -1) { |
|
| 550 | - $quota = 'none'; |
|
| 551 | - } else { |
|
| 552 | - $quota = \OCP\Util::humanFileSize($quota); |
|
| 553 | - } |
|
| 554 | - } |
|
| 555 | - $targetUser->setQuota($quota); |
|
| 556 | - break; |
|
| 557 | - case 'password': |
|
| 558 | - try { |
|
| 559 | - if (!$targetUser->canChangePassword()) { |
|
| 560 | - throw new OCSException('Setting the password is not supported by the users backend', 103); |
|
| 561 | - } |
|
| 562 | - $targetUser->setPassword($value); |
|
| 563 | - } catch (HintException $e) { // password policy error |
|
| 564 | - throw new OCSException($e->getMessage(), 103); |
|
| 565 | - } |
|
| 566 | - break; |
|
| 567 | - case 'language': |
|
| 568 | - $languagesCodes = $this->l10nFactory->findAvailableLanguages(); |
|
| 569 | - if (!in_array($value, $languagesCodes, true) && $value !== 'en') { |
|
| 570 | - throw new OCSException('Invalid language', 102); |
|
| 571 | - } |
|
| 572 | - $this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value); |
|
| 573 | - break; |
|
| 574 | - case 'locale': |
|
| 575 | - if (!$this->l10nFactory->localeExists($value)) { |
|
| 576 | - throw new OCSException('Invalid locale', 102); |
|
| 577 | - } |
|
| 578 | - $this->config->setUserValue($targetUser->getUID(), 'core', 'locale', $value); |
|
| 579 | - break; |
|
| 580 | - case AccountManager::PROPERTY_EMAIL: |
|
| 581 | - if (filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') { |
|
| 582 | - $targetUser->setEMailAddress($value); |
|
| 583 | - } else { |
|
| 584 | - throw new OCSException('', 102); |
|
| 585 | - } |
|
| 586 | - break; |
|
| 587 | - case AccountManager::PROPERTY_PHONE: |
|
| 588 | - case AccountManager::PROPERTY_ADDRESS: |
|
| 589 | - case AccountManager::PROPERTY_WEBSITE: |
|
| 590 | - case AccountManager::PROPERTY_TWITTER: |
|
| 591 | - $userAccount = $this->accountManager->getUser($targetUser); |
|
| 592 | - if ($userAccount[$key]['value'] !== $value) { |
|
| 593 | - $userAccount[$key]['value'] = $value; |
|
| 594 | - $this->accountManager->updateUser($targetUser, $userAccount); |
|
| 595 | - } |
|
| 596 | - break; |
|
| 597 | - default: |
|
| 598 | - throw new OCSException('', 103); |
|
| 599 | - } |
|
| 600 | - return new DataResponse(); |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - /** |
|
| 604 | - * @PasswordConfirmationRequired |
|
| 605 | - * @NoAdminRequired |
|
| 606 | - * |
|
| 607 | - * @param string $userId |
|
| 608 | - * |
|
| 609 | - * @return DataResponse |
|
| 610 | - * |
|
| 611 | - * @throws OCSException |
|
| 612 | - */ |
|
| 613 | - public function wipeUserDevices(string $userId): DataResponse { |
|
| 614 | - /** @var IUser $currentLoggedInUser */ |
|
| 615 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 616 | - |
|
| 617 | - $targetUser = $this->userManager->get($userId); |
|
| 618 | - |
|
| 619 | - if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 620 | - throw new OCSException('', 101); |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - // If not permitted |
|
| 624 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 625 | - if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 626 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - $this->remoteWipe->markAllTokensForWipe($targetUser); |
|
| 630 | - |
|
| 631 | - return new DataResponse(); |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - /** |
|
| 635 | - * @PasswordConfirmationRequired |
|
| 636 | - * @NoAdminRequired |
|
| 637 | - * |
|
| 638 | - * @param string $userId |
|
| 639 | - * @return DataResponse |
|
| 640 | - * @throws OCSException |
|
| 641 | - */ |
|
| 642 | - public function deleteUser(string $userId): DataResponse { |
|
| 643 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 644 | - |
|
| 645 | - $targetUser = $this->userManager->get($userId); |
|
| 646 | - |
|
| 647 | - if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 648 | - throw new OCSException('', 101); |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - // If not permitted |
|
| 652 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 653 | - if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 654 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - // Go ahead with the delete |
|
| 658 | - if ($targetUser->delete()) { |
|
| 659 | - return new DataResponse(); |
|
| 660 | - } else { |
|
| 661 | - throw new OCSException('', 101); |
|
| 662 | - } |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - /** |
|
| 666 | - * @PasswordConfirmationRequired |
|
| 667 | - * @NoAdminRequired |
|
| 668 | - * |
|
| 669 | - * @param string $userId |
|
| 670 | - * @return DataResponse |
|
| 671 | - * @throws OCSException |
|
| 672 | - * @throws OCSForbiddenException |
|
| 673 | - */ |
|
| 674 | - public function disableUser(string $userId): DataResponse { |
|
| 675 | - return $this->setEnabled($userId, false); |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - /** |
|
| 679 | - * @PasswordConfirmationRequired |
|
| 680 | - * @NoAdminRequired |
|
| 681 | - * |
|
| 682 | - * @param string $userId |
|
| 683 | - * @return DataResponse |
|
| 684 | - * @throws OCSException |
|
| 685 | - * @throws OCSForbiddenException |
|
| 686 | - */ |
|
| 687 | - public function enableUser(string $userId): DataResponse { |
|
| 688 | - return $this->setEnabled($userId, true); |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * @param string $userId |
|
| 693 | - * @param bool $value |
|
| 694 | - * @return DataResponse |
|
| 695 | - * @throws OCSException |
|
| 696 | - */ |
|
| 697 | - private function setEnabled(string $userId, bool $value): DataResponse { |
|
| 698 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 699 | - |
|
| 700 | - $targetUser = $this->userManager->get($userId); |
|
| 701 | - if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 702 | - throw new OCSException('', 101); |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - // If not permitted |
|
| 706 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 707 | - if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 708 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - // enable/disable the user now |
|
| 712 | - $targetUser->setEnabled($value); |
|
| 713 | - return new DataResponse(); |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - /** |
|
| 717 | - * @NoAdminRequired |
|
| 718 | - * @NoSubAdminRequired |
|
| 719 | - * |
|
| 720 | - * @param string $userId |
|
| 721 | - * @return DataResponse |
|
| 722 | - * @throws OCSException |
|
| 723 | - */ |
|
| 724 | - public function getUsersGroups(string $userId): DataResponse { |
|
| 725 | - $loggedInUser = $this->userSession->getUser(); |
|
| 726 | - |
|
| 727 | - $targetUser = $this->userManager->get($userId); |
|
| 728 | - if ($targetUser === null) { |
|
| 729 | - throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - if ($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 733 | - // Self lookup or admin lookup |
|
| 734 | - return new DataResponse([ |
|
| 735 | - 'groups' => $this->groupManager->getUserGroupIds($targetUser) |
|
| 736 | - ]); |
|
| 737 | - } else { |
|
| 738 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 739 | - |
|
| 740 | - // Looking up someone else |
|
| 741 | - if ($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
| 742 | - // Return the group that the method caller is subadmin of for the user in question |
|
| 743 | - /** @var IGroup[] $getSubAdminsGroups */ |
|
| 744 | - $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
| 745 | - foreach ($getSubAdminsGroups as $key => $group) { |
|
| 746 | - $getSubAdminsGroups[$key] = $group->getGID(); |
|
| 747 | - } |
|
| 748 | - $groups = array_intersect( |
|
| 749 | - $getSubAdminsGroups, |
|
| 750 | - $this->groupManager->getUserGroupIds($targetUser) |
|
| 751 | - ); |
|
| 752 | - return new DataResponse(['groups' => $groups]); |
|
| 753 | - } else { |
|
| 754 | - // Not permitted |
|
| 755 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 756 | - } |
|
| 757 | - } |
|
| 758 | - |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - /** |
|
| 762 | - * @PasswordConfirmationRequired |
|
| 763 | - * @NoAdminRequired |
|
| 764 | - * |
|
| 765 | - * @param string $userId |
|
| 766 | - * @param string $groupid |
|
| 767 | - * @return DataResponse |
|
| 768 | - * @throws OCSException |
|
| 769 | - */ |
|
| 770 | - public function addToGroup(string $userId, string $groupid = ''): DataResponse { |
|
| 771 | - if ($groupid === '') { |
|
| 772 | - throw new OCSException('', 101); |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - $group = $this->groupManager->get($groupid); |
|
| 776 | - $targetUser = $this->userManager->get($userId); |
|
| 777 | - if ($group === null) { |
|
| 778 | - throw new OCSException('', 102); |
|
| 779 | - } |
|
| 780 | - if ($targetUser === null) { |
|
| 781 | - throw new OCSException('', 103); |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - // If they're not an admin, check they are a subadmin of the group in question |
|
| 785 | - $loggedInUser = $this->userSession->getUser(); |
|
| 786 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 787 | - if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
| 788 | - throw new OCSException('', 104); |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - // Add user to group |
|
| 792 | - $group->addUser($targetUser); |
|
| 793 | - return new DataResponse(); |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - /** |
|
| 797 | - * @PasswordConfirmationRequired |
|
| 798 | - * @NoAdminRequired |
|
| 799 | - * |
|
| 800 | - * @param string $userId |
|
| 801 | - * @param string $groupid |
|
| 802 | - * @return DataResponse |
|
| 803 | - * @throws OCSException |
|
| 804 | - */ |
|
| 805 | - public function removeFromGroup(string $userId, string $groupid): DataResponse { |
|
| 806 | - $loggedInUser = $this->userSession->getUser(); |
|
| 807 | - |
|
| 808 | - if ($groupid === null || trim($groupid) === '') { |
|
| 809 | - throw new OCSException('', 101); |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - $group = $this->groupManager->get($groupid); |
|
| 813 | - if ($group === null) { |
|
| 814 | - throw new OCSException('', 102); |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - $targetUser = $this->userManager->get($userId); |
|
| 818 | - if ($targetUser === null) { |
|
| 819 | - throw new OCSException('', 103); |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - // If they're not an admin, check they are a subadmin of the group in question |
|
| 823 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 824 | - if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
| 825 | - throw new OCSException('', 104); |
|
| 826 | - } |
|
| 827 | - |
|
| 828 | - // Check they aren't removing themselves from 'admin' or their 'subadmin; group |
|
| 829 | - if ($targetUser->getUID() === $loggedInUser->getUID()) { |
|
| 830 | - if ($this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 831 | - if ($group->getGID() === 'admin') { |
|
| 832 | - throw new OCSException('Cannot remove yourself from the admin group', 105); |
|
| 833 | - } |
|
| 834 | - } else { |
|
| 835 | - // Not an admin, so the user must be a subadmin of this group, but that is not allowed. |
|
| 836 | - throw new OCSException('Cannot remove yourself from this group as you are a SubAdmin', 105); |
|
| 837 | - } |
|
| 838 | - |
|
| 839 | - } else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 840 | - /** @var IGroup[] $subAdminGroups */ |
|
| 841 | - $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
| 842 | - $subAdminGroups = array_map(function (IGroup $subAdminGroup) { |
|
| 843 | - return $subAdminGroup->getGID(); |
|
| 844 | - }, $subAdminGroups); |
|
| 845 | - $userGroups = $this->groupManager->getUserGroupIds($targetUser); |
|
| 846 | - $userSubAdminGroups = array_intersect($subAdminGroups, $userGroups); |
|
| 847 | - |
|
| 848 | - if (count($userSubAdminGroups) <= 1) { |
|
| 849 | - // Subadmin must not be able to remove a user from all their subadmin groups. |
|
| 850 | - throw new OCSException('Not viable to remove user from the last group you are SubAdmin of', 105); |
|
| 851 | - } |
|
| 852 | - } |
|
| 853 | - |
|
| 854 | - // Remove user from group |
|
| 855 | - $group->removeUser($targetUser); |
|
| 856 | - return new DataResponse(); |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - /** |
|
| 860 | - * Creates a subadmin |
|
| 861 | - * |
|
| 862 | - * @PasswordConfirmationRequired |
|
| 863 | - * |
|
| 864 | - * @param string $userId |
|
| 865 | - * @param string $groupid |
|
| 866 | - * @return DataResponse |
|
| 867 | - * @throws OCSException |
|
| 868 | - */ |
|
| 869 | - public function addSubAdmin(string $userId, string $groupid): DataResponse { |
|
| 870 | - $group = $this->groupManager->get($groupid); |
|
| 871 | - $user = $this->userManager->get($userId); |
|
| 872 | - |
|
| 873 | - // Check if the user exists |
|
| 874 | - if ($user === null) { |
|
| 875 | - throw new OCSException('User does not exist', 101); |
|
| 876 | - } |
|
| 877 | - // Check if group exists |
|
| 878 | - if ($group === null) { |
|
| 879 | - throw new OCSException('Group does not exist', 102); |
|
| 880 | - } |
|
| 881 | - // Check if trying to make subadmin of admin group |
|
| 882 | - if ($group->getGID() === 'admin') { |
|
| 883 | - throw new OCSException('Cannot create subadmins for admin group', 103); |
|
| 884 | - } |
|
| 885 | - |
|
| 886 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 887 | - |
|
| 888 | - // We cannot be subadmin twice |
|
| 889 | - if ($subAdminManager->isSubAdminOfGroup($user, $group)) { |
|
| 890 | - return new DataResponse(); |
|
| 891 | - } |
|
| 892 | - // Go |
|
| 893 | - $subAdminManager->createSubAdmin($user, $group); |
|
| 894 | - return new DataResponse(); |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - /** |
|
| 898 | - * Removes a subadmin from a group |
|
| 899 | - * |
|
| 900 | - * @PasswordConfirmationRequired |
|
| 901 | - * |
|
| 902 | - * @param string $userId |
|
| 903 | - * @param string $groupid |
|
| 904 | - * @return DataResponse |
|
| 905 | - * @throws OCSException |
|
| 906 | - */ |
|
| 907 | - public function removeSubAdmin(string $userId, string $groupid): DataResponse { |
|
| 908 | - $group = $this->groupManager->get($groupid); |
|
| 909 | - $user = $this->userManager->get($userId); |
|
| 910 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 911 | - |
|
| 912 | - // Check if the user exists |
|
| 913 | - if ($user === null) { |
|
| 914 | - throw new OCSException('User does not exist', 101); |
|
| 915 | - } |
|
| 916 | - // Check if the group exists |
|
| 917 | - if ($group === null) { |
|
| 918 | - throw new OCSException('Group does not exist', 101); |
|
| 919 | - } |
|
| 920 | - // Check if they are a subadmin of this said group |
|
| 921 | - if (!$subAdminManager->isSubAdminOfGroup($user, $group)) { |
|
| 922 | - throw new OCSException('User is not a subadmin of this group', 102); |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - // Go |
|
| 926 | - $subAdminManager->deleteSubAdmin($user, $group); |
|
| 927 | - return new DataResponse(); |
|
| 928 | - } |
|
| 929 | - |
|
| 930 | - /** |
|
| 931 | - * Get the groups a user is a subadmin of |
|
| 932 | - * |
|
| 933 | - * @param string $userId |
|
| 934 | - * @return DataResponse |
|
| 935 | - * @throws OCSException |
|
| 936 | - */ |
|
| 937 | - public function getUserSubAdminGroups(string $userId): DataResponse { |
|
| 938 | - $groups = $this->getUserSubAdminGroupsData($userId); |
|
| 939 | - return new DataResponse($groups); |
|
| 940 | - } |
|
| 941 | - |
|
| 942 | - /** |
|
| 943 | - * @NoAdminRequired |
|
| 944 | - * @PasswordConfirmationRequired |
|
| 945 | - * |
|
| 946 | - * resend welcome message |
|
| 947 | - * |
|
| 948 | - * @param string $userId |
|
| 949 | - * @return DataResponse |
|
| 950 | - * @throws OCSException |
|
| 951 | - */ |
|
| 952 | - public function resendWelcomeMessage(string $userId): DataResponse { |
|
| 953 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 954 | - |
|
| 955 | - $targetUser = $this->userManager->get($userId); |
|
| 956 | - if ($targetUser === null) { |
|
| 957 | - throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
| 958 | - } |
|
| 959 | - |
|
| 960 | - // Check if admin / subadmin |
|
| 961 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 962 | - if (!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
| 963 | - && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 964 | - // No rights |
|
| 965 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - $email = $targetUser->getEMailAddress(); |
|
| 969 | - if ($email === '' || $email === null) { |
|
| 970 | - throw new OCSException('Email address not available', 101); |
|
| 971 | - } |
|
| 972 | - |
|
| 973 | - try { |
|
| 974 | - $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false); |
|
| 975 | - $this->newUserMailHelper->sendMail($targetUser, $emailTemplate); |
|
| 976 | - } catch(\Exception $e) { |
|
| 977 | - $this->logger->logException($e, [ |
|
| 978 | - 'message' => "Can't send new user mail to $email", |
|
| 979 | - 'level' => ILogger::ERROR, |
|
| 980 | - 'app' => 'settings', |
|
| 981 | - ]); |
|
| 982 | - throw new OCSException('Sending email failed', 102); |
|
| 983 | - } |
|
| 984 | - |
|
| 985 | - return new DataResponse(); |
|
| 986 | - } |
|
| 65 | + /** @var IAppManager */ |
|
| 66 | + private $appManager; |
|
| 67 | + /** @var ILogger */ |
|
| 68 | + private $logger; |
|
| 69 | + /** @var IFactory */ |
|
| 70 | + private $l10nFactory; |
|
| 71 | + /** @var NewUserMailHelper */ |
|
| 72 | + private $newUserMailHelper; |
|
| 73 | + /** @var FederatedFileSharingFactory */ |
|
| 74 | + private $federatedFileSharingFactory; |
|
| 75 | + /** @var ISecureRandom */ |
|
| 76 | + private $secureRandom; |
|
| 77 | + /** @var RemoteWipe */ |
|
| 78 | + private $remoteWipe; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @param string $appName |
|
| 82 | + * @param IRequest $request |
|
| 83 | + * @param IUserManager $userManager |
|
| 84 | + * @param IConfig $config |
|
| 85 | + * @param IAppManager $appManager |
|
| 86 | + * @param IGroupManager $groupManager |
|
| 87 | + * @param IUserSession $userSession |
|
| 88 | + * @param AccountManager $accountManager |
|
| 89 | + * @param ILogger $logger |
|
| 90 | + * @param IFactory $l10nFactory |
|
| 91 | + * @param NewUserMailHelper $newUserMailHelper |
|
| 92 | + * @param FederatedFileSharingFactory $federatedFileSharingFactory |
|
| 93 | + * @param ISecureRandom $secureRandom |
|
| 94 | + */ |
|
| 95 | + public function __construct(string $appName, |
|
| 96 | + IRequest $request, |
|
| 97 | + IUserManager $userManager, |
|
| 98 | + IConfig $config, |
|
| 99 | + IAppManager $appManager, |
|
| 100 | + IGroupManager $groupManager, |
|
| 101 | + IUserSession $userSession, |
|
| 102 | + AccountManager $accountManager, |
|
| 103 | + ILogger $logger, |
|
| 104 | + IFactory $l10nFactory, |
|
| 105 | + NewUserMailHelper $newUserMailHelper, |
|
| 106 | + FederatedFileSharingFactory $federatedFileSharingFactory, |
|
| 107 | + ISecureRandom $secureRandom, |
|
| 108 | + RemoteWipe $remoteWipe) { |
|
| 109 | + parent::__construct($appName, |
|
| 110 | + $request, |
|
| 111 | + $userManager, |
|
| 112 | + $config, |
|
| 113 | + $groupManager, |
|
| 114 | + $userSession, |
|
| 115 | + $accountManager); |
|
| 116 | + |
|
| 117 | + $this->appManager = $appManager; |
|
| 118 | + $this->logger = $logger; |
|
| 119 | + $this->l10nFactory = $l10nFactory; |
|
| 120 | + $this->newUserMailHelper = $newUserMailHelper; |
|
| 121 | + $this->federatedFileSharingFactory = $federatedFileSharingFactory; |
|
| 122 | + $this->secureRandom = $secureRandom; |
|
| 123 | + $this->remoteWipe = $remoteWipe; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @NoAdminRequired |
|
| 128 | + * |
|
| 129 | + * returns a list of users |
|
| 130 | + * |
|
| 131 | + * @param string $search |
|
| 132 | + * @param int $limit |
|
| 133 | + * @param int $offset |
|
| 134 | + * @return DataResponse |
|
| 135 | + */ |
|
| 136 | + public function getUsers(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
| 137 | + $user = $this->userSession->getUser(); |
|
| 138 | + $users = []; |
|
| 139 | + |
|
| 140 | + // Admin? Or SubAdmin? |
|
| 141 | + $uid = $user->getUID(); |
|
| 142 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 143 | + if ($this->groupManager->isAdmin($uid)){ |
|
| 144 | + $users = $this->userManager->search($search, $limit, $offset); |
|
| 145 | + } else if ($subAdminManager->isSubAdmin($user)) { |
|
| 146 | + $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
|
| 147 | + foreach ($subAdminOfGroups as $key => $group) { |
|
| 148 | + $subAdminOfGroups[$key] = $group->getGID(); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + $users = []; |
|
| 152 | + foreach ($subAdminOfGroups as $group) { |
|
| 153 | + $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search, $limit, $offset)); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + $users = array_keys($users); |
|
| 158 | + |
|
| 159 | + return new DataResponse([ |
|
| 160 | + 'users' => $users |
|
| 161 | + ]); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @NoAdminRequired |
|
| 166 | + * |
|
| 167 | + * returns a list of users and their data |
|
| 168 | + */ |
|
| 169 | + public function getUsersDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
| 170 | + $currentUser = $this->userSession->getUser(); |
|
| 171 | + $users = []; |
|
| 172 | + |
|
| 173 | + // Admin? Or SubAdmin? |
|
| 174 | + $uid = $currentUser->getUID(); |
|
| 175 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 176 | + if ($this->groupManager->isAdmin($uid)){ |
|
| 177 | + $users = $this->userManager->search($search, $limit, $offset); |
|
| 178 | + $users = array_keys($users); |
|
| 179 | + } else if ($subAdminManager->isSubAdmin($currentUser)) { |
|
| 180 | + $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($currentUser); |
|
| 181 | + foreach ($subAdminOfGroups as $key => $group) { |
|
| 182 | + $subAdminOfGroups[$key] = $group->getGID(); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + $users = []; |
|
| 186 | + foreach ($subAdminOfGroups as $group) { |
|
| 187 | + $users[] = array_keys($this->groupManager->displayNamesInGroup($group, $search, $limit, $offset)); |
|
| 188 | + } |
|
| 189 | + $users = array_merge(...$users); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + $usersDetails = []; |
|
| 193 | + foreach ($users as $userId) { |
|
| 194 | + $userId = (string) $userId; |
|
| 195 | + $userData = $this->getUserData($userId); |
|
| 196 | + // Do not insert empty entry |
|
| 197 | + if (!empty($userData)) { |
|
| 198 | + $usersDetails[$userId] = $userData; |
|
| 199 | + } else { |
|
| 200 | + // Logged user does not have permissions to see this user |
|
| 201 | + // only showing its id |
|
| 202 | + $usersDetails[$userId] = ['id' => $userId]; |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + return new DataResponse([ |
|
| 207 | + 'users' => $usersDetails |
|
| 208 | + ]); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * @throws OCSException |
|
| 213 | + */ |
|
| 214 | + private function createNewUserId(): string { |
|
| 215 | + $attempts = 0; |
|
| 216 | + do { |
|
| 217 | + $uidCandidate = $this->secureRandom->generate(10, ISecureRandom::CHAR_HUMAN_READABLE); |
|
| 218 | + if (!$this->userManager->userExists($uidCandidate)) { |
|
| 219 | + return $uidCandidate; |
|
| 220 | + } |
|
| 221 | + $attempts++; |
|
| 222 | + } while ($attempts < 10); |
|
| 223 | + throw new OCSException('Could not create non-existing user id', 111); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @PasswordConfirmationRequired |
|
| 228 | + * @NoAdminRequired |
|
| 229 | + * |
|
| 230 | + * @param string $userid |
|
| 231 | + * @param string $password |
|
| 232 | + * @param string $displayName |
|
| 233 | + * @param string $email |
|
| 234 | + * @param array $groups |
|
| 235 | + * @param array $subadmin |
|
| 236 | + * @param string $quota |
|
| 237 | + * @param string $language |
|
| 238 | + * @return DataResponse |
|
| 239 | + * @throws OCSException |
|
| 240 | + */ |
|
| 241 | + public function addUser(string $userid, |
|
| 242 | + string $password = '', |
|
| 243 | + string $displayName = '', |
|
| 244 | + string $email = '', |
|
| 245 | + array $groups = [], |
|
| 246 | + array $subadmin = [], |
|
| 247 | + string $quota = '', |
|
| 248 | + string $language = ''): DataResponse { |
|
| 249 | + $user = $this->userSession->getUser(); |
|
| 250 | + $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
|
| 251 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 252 | + |
|
| 253 | + if(empty($userid) && $this->config->getAppValue('core', 'newUser.generateUserID', 'no') === 'yes') { |
|
| 254 | + $userid = $this->createNewUserId(); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + if ($this->userManager->userExists($userid)) { |
|
| 258 | + $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']); |
|
| 259 | + throw new OCSException('User already exists', 102); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + if ($groups !== []) { |
|
| 263 | + foreach ($groups as $group) { |
|
| 264 | + if (!$this->groupManager->groupExists($group)) { |
|
| 265 | + throw new OCSException('group '.$group.' does not exist', 104); |
|
| 266 | + } |
|
| 267 | + if (!$isAdmin && !$subAdminManager->isSubAdminOfGroup($user, $this->groupManager->get($group))) { |
|
| 268 | + throw new OCSException('insufficient privileges for group '. $group, 105); |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + } else { |
|
| 272 | + if (!$isAdmin) { |
|
| 273 | + throw new OCSException('no group specified (required for subadmins)', 106); |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + $subadminGroups = []; |
|
| 278 | + if ($subadmin !== []) { |
|
| 279 | + foreach ($subadmin as $groupid) { |
|
| 280 | + $group = $this->groupManager->get($groupid); |
|
| 281 | + // Check if group exists |
|
| 282 | + if ($group === null) { |
|
| 283 | + throw new OCSException('Subadmin group does not exist', 102); |
|
| 284 | + } |
|
| 285 | + // Check if trying to make subadmin of admin group |
|
| 286 | + if ($group->getGID() === 'admin') { |
|
| 287 | + throw new OCSException('Cannot create subadmins for admin group', 103); |
|
| 288 | + } |
|
| 289 | + // Check if has permission to promote subadmins |
|
| 290 | + if (!$subAdminManager->isSubAdminOfGroup($user, $group) && !$isAdmin) { |
|
| 291 | + throw new OCSForbiddenException('No permissions to promote subadmins'); |
|
| 292 | + } |
|
| 293 | + $subadminGroups[] = $group; |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + $generatePasswordResetToken = false; |
|
| 298 | + if ($password === '') { |
|
| 299 | + if ($email === '') { |
|
| 300 | + throw new OCSException('To send a password link to the user an email address is required.', 108); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + $password = $this->secureRandom->generate(10); |
|
| 304 | + // Make sure we pass the password_policy |
|
| 305 | + $password .= $this->secureRandom->generate(2, '$!.,;:-~+*[]{}()'); |
|
| 306 | + $generatePasswordResetToken = true; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + if ($email === '' && $this->config->getAppValue('core', 'newUser.requireEmail', 'no') === 'yes') { |
|
| 310 | + throw new OCSException('Required email address was not provided', 110); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + try { |
|
| 314 | + $newUser = $this->userManager->createUser($userid, $password); |
|
| 315 | + $this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']); |
|
| 316 | + |
|
| 317 | + foreach ($groups as $group) { |
|
| 318 | + $this->groupManager->get($group)->addUser($newUser); |
|
| 319 | + $this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']); |
|
| 320 | + } |
|
| 321 | + foreach ($subadminGroups as $group) { |
|
| 322 | + $subAdminManager->createSubAdmin($newUser, $group); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + if ($displayName !== '') { |
|
| 326 | + $this->editUser($userid, 'display', $displayName); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + if ($quota !== '') { |
|
| 330 | + $this->editUser($userid, 'quota', $quota); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + if ($language !== '') { |
|
| 334 | + $this->editUser($userid, 'language', $language); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + // Send new user mail only if a mail is set |
|
| 338 | + if ($email !== '' && $this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes') { |
|
| 339 | + $newUser->setEMailAddress($email); |
|
| 340 | + try { |
|
| 341 | + $emailTemplate = $this->newUserMailHelper->generateTemplate($newUser, $generatePasswordResetToken); |
|
| 342 | + $this->newUserMailHelper->sendMail($newUser, $emailTemplate); |
|
| 343 | + } catch (\Exception $e) { |
|
| 344 | + // Mail could be failing hard or just be plain not configured |
|
| 345 | + // Logging error as it is the hardest of the two |
|
| 346 | + $this->logger->logException($e, [ |
|
| 347 | + 'message' => "Unable to send the invitation mail to $email", |
|
| 348 | + 'level' => ILogger::ERROR, |
|
| 349 | + 'app' => 'ocs_api', |
|
| 350 | + ]); |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + return new DataResponse(['id' => $userid]); |
|
| 355 | + |
|
| 356 | + } catch (HintException $e) { |
|
| 357 | + $this->logger->logException($e, [ |
|
| 358 | + 'message' => 'Failed addUser attempt with hint exception.', |
|
| 359 | + 'level' => ILogger::WARN, |
|
| 360 | + 'app' => 'ocs_api', |
|
| 361 | + ]); |
|
| 362 | + throw new OCSException($e->getHint(), 107); |
|
| 363 | + } catch (OCSException $e) { |
|
| 364 | + $this->logger->logException($e, [ |
|
| 365 | + 'message' => 'Failed addUser attempt with ocs exeption.', |
|
| 366 | + 'level' => ILogger::ERROR, |
|
| 367 | + 'app' => 'ocs_api', |
|
| 368 | + ]); |
|
| 369 | + throw $e; |
|
| 370 | + } catch (\Exception $e) { |
|
| 371 | + $this->logger->logException($e, [ |
|
| 372 | + 'message' => 'Failed addUser attempt with exception.', |
|
| 373 | + 'level' => ILogger::ERROR, |
|
| 374 | + 'app' => 'ocs_api', |
|
| 375 | + ]); |
|
| 376 | + throw new OCSException('Bad request', 101); |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * @NoAdminRequired |
|
| 382 | + * @NoSubAdminRequired |
|
| 383 | + * |
|
| 384 | + * gets user info |
|
| 385 | + * |
|
| 386 | + * @param string $userId |
|
| 387 | + * @return DataResponse |
|
| 388 | + * @throws OCSException |
|
| 389 | + */ |
|
| 390 | + public function getUser(string $userId): DataResponse { |
|
| 391 | + $data = $this->getUserData($userId); |
|
| 392 | + // getUserData returns empty array if not enough permissions |
|
| 393 | + if (empty($data)) { |
|
| 394 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 395 | + } |
|
| 396 | + return new DataResponse($data); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + /** |
|
| 400 | + * @NoAdminRequired |
|
| 401 | + * @NoSubAdminRequired |
|
| 402 | + * |
|
| 403 | + * gets user info from the currently logged in user |
|
| 404 | + * |
|
| 405 | + * @return DataResponse |
|
| 406 | + * @throws OCSException |
|
| 407 | + */ |
|
| 408 | + public function getCurrentUser(): DataResponse { |
|
| 409 | + $user = $this->userSession->getUser(); |
|
| 410 | + if ($user) { |
|
| 411 | + $data = $this->getUserData($user->getUID()); |
|
| 412 | + // rename "displayname" to "display-name" only for this call to keep |
|
| 413 | + // the API stable. |
|
| 414 | + $data['display-name'] = $data['displayname']; |
|
| 415 | + unset($data['displayname']); |
|
| 416 | + return new DataResponse($data); |
|
| 417 | + |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * @NoAdminRequired |
|
| 425 | + * @NoSubAdminRequired |
|
| 426 | + */ |
|
| 427 | + public function getEditableFields(): DataResponse { |
|
| 428 | + $permittedFields = []; |
|
| 429 | + |
|
| 430 | + // Editing self (display, email) |
|
| 431 | + if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
|
| 432 | + $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
| 433 | + $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + if ($this->appManager->isEnabledForUser('federatedfilesharing')) { |
|
| 437 | + $federatedFileSharing = $this->federatedFileSharingFactory->get(); |
|
| 438 | + $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
| 439 | + if ($shareProvider->isLookupServerUploadEnabled()) { |
|
| 440 | + $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
| 441 | + $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
| 442 | + $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
| 443 | + $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + return new DataResponse($permittedFields); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * @NoAdminRequired |
|
| 452 | + * @NoSubAdminRequired |
|
| 453 | + * @PasswordConfirmationRequired |
|
| 454 | + * |
|
| 455 | + * edit users |
|
| 456 | + * |
|
| 457 | + * @param string $userId |
|
| 458 | + * @param string $key |
|
| 459 | + * @param string $value |
|
| 460 | + * @return DataResponse |
|
| 461 | + * @throws OCSException |
|
| 462 | + */ |
|
| 463 | + public function editUser(string $userId, string $key, string $value): DataResponse { |
|
| 464 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 465 | + |
|
| 466 | + $targetUser = $this->userManager->get($userId); |
|
| 467 | + if ($targetUser === null) { |
|
| 468 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + $permittedFields = []; |
|
| 472 | + if ($targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 473 | + // Editing self (display, email) |
|
| 474 | + if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
|
| 475 | + $permittedFields[] = 'display'; |
|
| 476 | + $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
| 477 | + $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + $permittedFields[] = 'password'; |
|
| 481 | + if ($this->config->getSystemValue('force_language', false) === false || |
|
| 482 | + $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 483 | + $permittedFields[] = 'language'; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + if ($this->config->getSystemValue('force_locale', false) === false || |
|
| 487 | + $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 488 | + $permittedFields[] = 'locale'; |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + if ($this->appManager->isEnabledForUser('federatedfilesharing')) { |
|
| 492 | + $federatedFileSharing = \OC::$server->query(\OCA\FederatedFileSharing\AppInfo\Application::class); |
|
| 493 | + $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
| 494 | + if ($shareProvider->isLookupServerUploadEnabled()) { |
|
| 495 | + $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
| 496 | + $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
| 497 | + $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
| 498 | + $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + // If admin they can edit their own quota |
|
| 503 | + if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 504 | + $permittedFields[] = 'quota'; |
|
| 505 | + } |
|
| 506 | + } else { |
|
| 507 | + // Check if admin / subadmin |
|
| 508 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 509 | + if ($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
| 510 | + || $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 511 | + // They have permissions over the user |
|
| 512 | + $permittedFields[] = 'display'; |
|
| 513 | + $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
| 514 | + $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
| 515 | + $permittedFields[] = 'password'; |
|
| 516 | + $permittedFields[] = 'language'; |
|
| 517 | + $permittedFields[] = 'locale'; |
|
| 518 | + $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
| 519 | + $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
| 520 | + $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
| 521 | + $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
| 522 | + $permittedFields[] = 'quota'; |
|
| 523 | + } else { |
|
| 524 | + // No rights |
|
| 525 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + // Check if permitted to edit this field |
|
| 529 | + if (!in_array($key, $permittedFields)) { |
|
| 530 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 531 | + } |
|
| 532 | + // Process the edit |
|
| 533 | + switch($key) { |
|
| 534 | + case 'display': |
|
| 535 | + case AccountManager::PROPERTY_DISPLAYNAME: |
|
| 536 | + $targetUser->setDisplayName($value); |
|
| 537 | + break; |
|
| 538 | + case 'quota': |
|
| 539 | + $quota = $value; |
|
| 540 | + if ($quota !== 'none' && $quota !== 'default') { |
|
| 541 | + if (is_numeric($quota)) { |
|
| 542 | + $quota = (float) $quota; |
|
| 543 | + } else { |
|
| 544 | + $quota = \OCP\Util::computerFileSize($quota); |
|
| 545 | + } |
|
| 546 | + if ($quota === false) { |
|
| 547 | + throw new OCSException('Invalid quota value '.$value, 103); |
|
| 548 | + } |
|
| 549 | + if ($quota === -1) { |
|
| 550 | + $quota = 'none'; |
|
| 551 | + } else { |
|
| 552 | + $quota = \OCP\Util::humanFileSize($quota); |
|
| 553 | + } |
|
| 554 | + } |
|
| 555 | + $targetUser->setQuota($quota); |
|
| 556 | + break; |
|
| 557 | + case 'password': |
|
| 558 | + try { |
|
| 559 | + if (!$targetUser->canChangePassword()) { |
|
| 560 | + throw new OCSException('Setting the password is not supported by the users backend', 103); |
|
| 561 | + } |
|
| 562 | + $targetUser->setPassword($value); |
|
| 563 | + } catch (HintException $e) { // password policy error |
|
| 564 | + throw new OCSException($e->getMessage(), 103); |
|
| 565 | + } |
|
| 566 | + break; |
|
| 567 | + case 'language': |
|
| 568 | + $languagesCodes = $this->l10nFactory->findAvailableLanguages(); |
|
| 569 | + if (!in_array($value, $languagesCodes, true) && $value !== 'en') { |
|
| 570 | + throw new OCSException('Invalid language', 102); |
|
| 571 | + } |
|
| 572 | + $this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value); |
|
| 573 | + break; |
|
| 574 | + case 'locale': |
|
| 575 | + if (!$this->l10nFactory->localeExists($value)) { |
|
| 576 | + throw new OCSException('Invalid locale', 102); |
|
| 577 | + } |
|
| 578 | + $this->config->setUserValue($targetUser->getUID(), 'core', 'locale', $value); |
|
| 579 | + break; |
|
| 580 | + case AccountManager::PROPERTY_EMAIL: |
|
| 581 | + if (filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') { |
|
| 582 | + $targetUser->setEMailAddress($value); |
|
| 583 | + } else { |
|
| 584 | + throw new OCSException('', 102); |
|
| 585 | + } |
|
| 586 | + break; |
|
| 587 | + case AccountManager::PROPERTY_PHONE: |
|
| 588 | + case AccountManager::PROPERTY_ADDRESS: |
|
| 589 | + case AccountManager::PROPERTY_WEBSITE: |
|
| 590 | + case AccountManager::PROPERTY_TWITTER: |
|
| 591 | + $userAccount = $this->accountManager->getUser($targetUser); |
|
| 592 | + if ($userAccount[$key]['value'] !== $value) { |
|
| 593 | + $userAccount[$key]['value'] = $value; |
|
| 594 | + $this->accountManager->updateUser($targetUser, $userAccount); |
|
| 595 | + } |
|
| 596 | + break; |
|
| 597 | + default: |
|
| 598 | + throw new OCSException('', 103); |
|
| 599 | + } |
|
| 600 | + return new DataResponse(); |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + /** |
|
| 604 | + * @PasswordConfirmationRequired |
|
| 605 | + * @NoAdminRequired |
|
| 606 | + * |
|
| 607 | + * @param string $userId |
|
| 608 | + * |
|
| 609 | + * @return DataResponse |
|
| 610 | + * |
|
| 611 | + * @throws OCSException |
|
| 612 | + */ |
|
| 613 | + public function wipeUserDevices(string $userId): DataResponse { |
|
| 614 | + /** @var IUser $currentLoggedInUser */ |
|
| 615 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 616 | + |
|
| 617 | + $targetUser = $this->userManager->get($userId); |
|
| 618 | + |
|
| 619 | + if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 620 | + throw new OCSException('', 101); |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + // If not permitted |
|
| 624 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 625 | + if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 626 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + $this->remoteWipe->markAllTokensForWipe($targetUser); |
|
| 630 | + |
|
| 631 | + return new DataResponse(); |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + /** |
|
| 635 | + * @PasswordConfirmationRequired |
|
| 636 | + * @NoAdminRequired |
|
| 637 | + * |
|
| 638 | + * @param string $userId |
|
| 639 | + * @return DataResponse |
|
| 640 | + * @throws OCSException |
|
| 641 | + */ |
|
| 642 | + public function deleteUser(string $userId): DataResponse { |
|
| 643 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 644 | + |
|
| 645 | + $targetUser = $this->userManager->get($userId); |
|
| 646 | + |
|
| 647 | + if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 648 | + throw new OCSException('', 101); |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + // If not permitted |
|
| 652 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 653 | + if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 654 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + // Go ahead with the delete |
|
| 658 | + if ($targetUser->delete()) { |
|
| 659 | + return new DataResponse(); |
|
| 660 | + } else { |
|
| 661 | + throw new OCSException('', 101); |
|
| 662 | + } |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + /** |
|
| 666 | + * @PasswordConfirmationRequired |
|
| 667 | + * @NoAdminRequired |
|
| 668 | + * |
|
| 669 | + * @param string $userId |
|
| 670 | + * @return DataResponse |
|
| 671 | + * @throws OCSException |
|
| 672 | + * @throws OCSForbiddenException |
|
| 673 | + */ |
|
| 674 | + public function disableUser(string $userId): DataResponse { |
|
| 675 | + return $this->setEnabled($userId, false); |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + /** |
|
| 679 | + * @PasswordConfirmationRequired |
|
| 680 | + * @NoAdminRequired |
|
| 681 | + * |
|
| 682 | + * @param string $userId |
|
| 683 | + * @return DataResponse |
|
| 684 | + * @throws OCSException |
|
| 685 | + * @throws OCSForbiddenException |
|
| 686 | + */ |
|
| 687 | + public function enableUser(string $userId): DataResponse { |
|
| 688 | + return $this->setEnabled($userId, true); |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * @param string $userId |
|
| 693 | + * @param bool $value |
|
| 694 | + * @return DataResponse |
|
| 695 | + * @throws OCSException |
|
| 696 | + */ |
|
| 697 | + private function setEnabled(string $userId, bool $value): DataResponse { |
|
| 698 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 699 | + |
|
| 700 | + $targetUser = $this->userManager->get($userId); |
|
| 701 | + if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 702 | + throw new OCSException('', 101); |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + // If not permitted |
|
| 706 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 707 | + if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 708 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + // enable/disable the user now |
|
| 712 | + $targetUser->setEnabled($value); |
|
| 713 | + return new DataResponse(); |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + /** |
|
| 717 | + * @NoAdminRequired |
|
| 718 | + * @NoSubAdminRequired |
|
| 719 | + * |
|
| 720 | + * @param string $userId |
|
| 721 | + * @return DataResponse |
|
| 722 | + * @throws OCSException |
|
| 723 | + */ |
|
| 724 | + public function getUsersGroups(string $userId): DataResponse { |
|
| 725 | + $loggedInUser = $this->userSession->getUser(); |
|
| 726 | + |
|
| 727 | + $targetUser = $this->userManager->get($userId); |
|
| 728 | + if ($targetUser === null) { |
|
| 729 | + throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + if ($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 733 | + // Self lookup or admin lookup |
|
| 734 | + return new DataResponse([ |
|
| 735 | + 'groups' => $this->groupManager->getUserGroupIds($targetUser) |
|
| 736 | + ]); |
|
| 737 | + } else { |
|
| 738 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 739 | + |
|
| 740 | + // Looking up someone else |
|
| 741 | + if ($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
| 742 | + // Return the group that the method caller is subadmin of for the user in question |
|
| 743 | + /** @var IGroup[] $getSubAdminsGroups */ |
|
| 744 | + $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
| 745 | + foreach ($getSubAdminsGroups as $key => $group) { |
|
| 746 | + $getSubAdminsGroups[$key] = $group->getGID(); |
|
| 747 | + } |
|
| 748 | + $groups = array_intersect( |
|
| 749 | + $getSubAdminsGroups, |
|
| 750 | + $this->groupManager->getUserGroupIds($targetUser) |
|
| 751 | + ); |
|
| 752 | + return new DataResponse(['groups' => $groups]); |
|
| 753 | + } else { |
|
| 754 | + // Not permitted |
|
| 755 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 756 | + } |
|
| 757 | + } |
|
| 758 | + |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + /** |
|
| 762 | + * @PasswordConfirmationRequired |
|
| 763 | + * @NoAdminRequired |
|
| 764 | + * |
|
| 765 | + * @param string $userId |
|
| 766 | + * @param string $groupid |
|
| 767 | + * @return DataResponse |
|
| 768 | + * @throws OCSException |
|
| 769 | + */ |
|
| 770 | + public function addToGroup(string $userId, string $groupid = ''): DataResponse { |
|
| 771 | + if ($groupid === '') { |
|
| 772 | + throw new OCSException('', 101); |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + $group = $this->groupManager->get($groupid); |
|
| 776 | + $targetUser = $this->userManager->get($userId); |
|
| 777 | + if ($group === null) { |
|
| 778 | + throw new OCSException('', 102); |
|
| 779 | + } |
|
| 780 | + if ($targetUser === null) { |
|
| 781 | + throw new OCSException('', 103); |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + // If they're not an admin, check they are a subadmin of the group in question |
|
| 785 | + $loggedInUser = $this->userSession->getUser(); |
|
| 786 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 787 | + if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
| 788 | + throw new OCSException('', 104); |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + // Add user to group |
|
| 792 | + $group->addUser($targetUser); |
|
| 793 | + return new DataResponse(); |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + /** |
|
| 797 | + * @PasswordConfirmationRequired |
|
| 798 | + * @NoAdminRequired |
|
| 799 | + * |
|
| 800 | + * @param string $userId |
|
| 801 | + * @param string $groupid |
|
| 802 | + * @return DataResponse |
|
| 803 | + * @throws OCSException |
|
| 804 | + */ |
|
| 805 | + public function removeFromGroup(string $userId, string $groupid): DataResponse { |
|
| 806 | + $loggedInUser = $this->userSession->getUser(); |
|
| 807 | + |
|
| 808 | + if ($groupid === null || trim($groupid) === '') { |
|
| 809 | + throw new OCSException('', 101); |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + $group = $this->groupManager->get($groupid); |
|
| 813 | + if ($group === null) { |
|
| 814 | + throw new OCSException('', 102); |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + $targetUser = $this->userManager->get($userId); |
|
| 818 | + if ($targetUser === null) { |
|
| 819 | + throw new OCSException('', 103); |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + // If they're not an admin, check they are a subadmin of the group in question |
|
| 823 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 824 | + if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
| 825 | + throw new OCSException('', 104); |
|
| 826 | + } |
|
| 827 | + |
|
| 828 | + // Check they aren't removing themselves from 'admin' or their 'subadmin; group |
|
| 829 | + if ($targetUser->getUID() === $loggedInUser->getUID()) { |
|
| 830 | + if ($this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 831 | + if ($group->getGID() === 'admin') { |
|
| 832 | + throw new OCSException('Cannot remove yourself from the admin group', 105); |
|
| 833 | + } |
|
| 834 | + } else { |
|
| 835 | + // Not an admin, so the user must be a subadmin of this group, but that is not allowed. |
|
| 836 | + throw new OCSException('Cannot remove yourself from this group as you are a SubAdmin', 105); |
|
| 837 | + } |
|
| 838 | + |
|
| 839 | + } else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 840 | + /** @var IGroup[] $subAdminGroups */ |
|
| 841 | + $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
| 842 | + $subAdminGroups = array_map(function (IGroup $subAdminGroup) { |
|
| 843 | + return $subAdminGroup->getGID(); |
|
| 844 | + }, $subAdminGroups); |
|
| 845 | + $userGroups = $this->groupManager->getUserGroupIds($targetUser); |
|
| 846 | + $userSubAdminGroups = array_intersect($subAdminGroups, $userGroups); |
|
| 847 | + |
|
| 848 | + if (count($userSubAdminGroups) <= 1) { |
|
| 849 | + // Subadmin must not be able to remove a user from all their subadmin groups. |
|
| 850 | + throw new OCSException('Not viable to remove user from the last group you are SubAdmin of', 105); |
|
| 851 | + } |
|
| 852 | + } |
|
| 853 | + |
|
| 854 | + // Remove user from group |
|
| 855 | + $group->removeUser($targetUser); |
|
| 856 | + return new DataResponse(); |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + /** |
|
| 860 | + * Creates a subadmin |
|
| 861 | + * |
|
| 862 | + * @PasswordConfirmationRequired |
|
| 863 | + * |
|
| 864 | + * @param string $userId |
|
| 865 | + * @param string $groupid |
|
| 866 | + * @return DataResponse |
|
| 867 | + * @throws OCSException |
|
| 868 | + */ |
|
| 869 | + public function addSubAdmin(string $userId, string $groupid): DataResponse { |
|
| 870 | + $group = $this->groupManager->get($groupid); |
|
| 871 | + $user = $this->userManager->get($userId); |
|
| 872 | + |
|
| 873 | + // Check if the user exists |
|
| 874 | + if ($user === null) { |
|
| 875 | + throw new OCSException('User does not exist', 101); |
|
| 876 | + } |
|
| 877 | + // Check if group exists |
|
| 878 | + if ($group === null) { |
|
| 879 | + throw new OCSException('Group does not exist', 102); |
|
| 880 | + } |
|
| 881 | + // Check if trying to make subadmin of admin group |
|
| 882 | + if ($group->getGID() === 'admin') { |
|
| 883 | + throw new OCSException('Cannot create subadmins for admin group', 103); |
|
| 884 | + } |
|
| 885 | + |
|
| 886 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 887 | + |
|
| 888 | + // We cannot be subadmin twice |
|
| 889 | + if ($subAdminManager->isSubAdminOfGroup($user, $group)) { |
|
| 890 | + return new DataResponse(); |
|
| 891 | + } |
|
| 892 | + // Go |
|
| 893 | + $subAdminManager->createSubAdmin($user, $group); |
|
| 894 | + return new DataResponse(); |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + /** |
|
| 898 | + * Removes a subadmin from a group |
|
| 899 | + * |
|
| 900 | + * @PasswordConfirmationRequired |
|
| 901 | + * |
|
| 902 | + * @param string $userId |
|
| 903 | + * @param string $groupid |
|
| 904 | + * @return DataResponse |
|
| 905 | + * @throws OCSException |
|
| 906 | + */ |
|
| 907 | + public function removeSubAdmin(string $userId, string $groupid): DataResponse { |
|
| 908 | + $group = $this->groupManager->get($groupid); |
|
| 909 | + $user = $this->userManager->get($userId); |
|
| 910 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 911 | + |
|
| 912 | + // Check if the user exists |
|
| 913 | + if ($user === null) { |
|
| 914 | + throw new OCSException('User does not exist', 101); |
|
| 915 | + } |
|
| 916 | + // Check if the group exists |
|
| 917 | + if ($group === null) { |
|
| 918 | + throw new OCSException('Group does not exist', 101); |
|
| 919 | + } |
|
| 920 | + // Check if they are a subadmin of this said group |
|
| 921 | + if (!$subAdminManager->isSubAdminOfGroup($user, $group)) { |
|
| 922 | + throw new OCSException('User is not a subadmin of this group', 102); |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + // Go |
|
| 926 | + $subAdminManager->deleteSubAdmin($user, $group); |
|
| 927 | + return new DataResponse(); |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * Get the groups a user is a subadmin of |
|
| 932 | + * |
|
| 933 | + * @param string $userId |
|
| 934 | + * @return DataResponse |
|
| 935 | + * @throws OCSException |
|
| 936 | + */ |
|
| 937 | + public function getUserSubAdminGroups(string $userId): DataResponse { |
|
| 938 | + $groups = $this->getUserSubAdminGroupsData($userId); |
|
| 939 | + return new DataResponse($groups); |
|
| 940 | + } |
|
| 941 | + |
|
| 942 | + /** |
|
| 943 | + * @NoAdminRequired |
|
| 944 | + * @PasswordConfirmationRequired |
|
| 945 | + * |
|
| 946 | + * resend welcome message |
|
| 947 | + * |
|
| 948 | + * @param string $userId |
|
| 949 | + * @return DataResponse |
|
| 950 | + * @throws OCSException |
|
| 951 | + */ |
|
| 952 | + public function resendWelcomeMessage(string $userId): DataResponse { |
|
| 953 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 954 | + |
|
| 955 | + $targetUser = $this->userManager->get($userId); |
|
| 956 | + if ($targetUser === null) { |
|
| 957 | + throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
| 958 | + } |
|
| 959 | + |
|
| 960 | + // Check if admin / subadmin |
|
| 961 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 962 | + if (!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
| 963 | + && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 964 | + // No rights |
|
| 965 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + $email = $targetUser->getEMailAddress(); |
|
| 969 | + if ($email === '' || $email === null) { |
|
| 970 | + throw new OCSException('Email address not available', 101); |
|
| 971 | + } |
|
| 972 | + |
|
| 973 | + try { |
|
| 974 | + $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false); |
|
| 975 | + $this->newUserMailHelper->sendMail($targetUser, $emailTemplate); |
|
| 976 | + } catch(\Exception $e) { |
|
| 977 | + $this->logger->logException($e, [ |
|
| 978 | + 'message' => "Can't send new user mail to $email", |
|
| 979 | + 'level' => ILogger::ERROR, |
|
| 980 | + 'app' => 'settings', |
|
| 981 | + ]); |
|
| 982 | + throw new OCSException('Sending email failed', 102); |
|
| 983 | + } |
|
| 984 | + |
|
| 985 | + return new DataResponse(); |
|
| 986 | + } |
|
| 987 | 987 | } |
@@ -48,172 +48,172 @@ |
||
| 48 | 48 | |
| 49 | 49 | abstract class AUserData extends OCSController { |
| 50 | 50 | |
| 51 | - /** @var IUserManager */ |
|
| 52 | - protected $userManager; |
|
| 53 | - /** @var IConfig */ |
|
| 54 | - protected $config; |
|
| 55 | - /** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface |
|
| 56 | - protected $groupManager; |
|
| 57 | - /** @var IUserSession */ |
|
| 58 | - protected $userSession; |
|
| 59 | - /** @var AccountManager */ |
|
| 60 | - protected $accountManager; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @param string $appName |
|
| 64 | - * @param IRequest $request |
|
| 65 | - * @param IUserManager $userManager |
|
| 66 | - * @param IConfig $config |
|
| 67 | - * @param IGroupManager $groupManager |
|
| 68 | - * @param IUserSession $userSession |
|
| 69 | - * @param AccountManager $accountManager |
|
| 70 | - */ |
|
| 71 | - public function __construct(string $appName, |
|
| 72 | - IRequest $request, |
|
| 73 | - IUserManager $userManager, |
|
| 74 | - IConfig $config, |
|
| 75 | - IGroupManager $groupManager, |
|
| 76 | - IUserSession $userSession, |
|
| 77 | - AccountManager $accountManager) { |
|
| 78 | - parent::__construct($appName, $request); |
|
| 79 | - |
|
| 80 | - $this->userManager = $userManager; |
|
| 81 | - $this->config = $config; |
|
| 82 | - $this->groupManager = $groupManager; |
|
| 83 | - $this->userSession = $userSession; |
|
| 84 | - $this->accountManager = $accountManager; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * creates a array with all user data |
|
| 89 | - * |
|
| 90 | - * @param string $userId |
|
| 91 | - * @return array |
|
| 92 | - * @throws NotFoundException |
|
| 93 | - * @throws OCSException |
|
| 94 | - * @throws OCSNotFoundException |
|
| 95 | - */ |
|
| 96 | - protected function getUserData(string $userId): array { |
|
| 97 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 98 | - |
|
| 99 | - $data = []; |
|
| 100 | - |
|
| 101 | - // Check if the target user exists |
|
| 102 | - $targetUserObject = $this->userManager->get($userId); |
|
| 103 | - if($targetUserObject === null) { |
|
| 104 | - throw new OCSNotFoundException('User does not exist'); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - // Should be at least Admin Or SubAdmin! |
|
| 108 | - if ($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
| 109 | - || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
|
| 110 | - $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true') === 'true'; |
|
| 111 | - } else { |
|
| 112 | - // Check they are looking up themselves |
|
| 113 | - if ($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
| 114 | - return $data; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - // Get groups data |
|
| 119 | - $userAccount = $this->accountManager->getUser($targetUserObject); |
|
| 120 | - $groups = $this->groupManager->getUserGroups($targetUserObject); |
|
| 121 | - $gids = []; |
|
| 122 | - foreach ($groups as $group) { |
|
| 123 | - $gids[] = $group->getGID(); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - try { |
|
| 127 | - # might be thrown by LDAP due to handling of users disappears |
|
| 128 | - # from the external source (reasons unknown to us) |
|
| 129 | - # cf. https://github.com/nextcloud/server/issues/12991 |
|
| 130 | - $data['storageLocation'] = $targetUserObject->getHome(); |
|
| 131 | - } catch (NoUserException $e) { |
|
| 132 | - throw new OCSNotFoundException($e->getMessage(), $e); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // Find the data |
|
| 136 | - $data['id'] = $targetUserObject->getUID(); |
|
| 137 | - $data['lastLogin'] = $targetUserObject->getLastLogin() * 1000; |
|
| 138 | - $data['backend'] = $targetUserObject->getBackendClassName(); |
|
| 139 | - $data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID()); |
|
| 140 | - $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID()); |
|
| 141 | - $data[AccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress(); |
|
| 142 | - $data[AccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName(); |
|
| 143 | - $data[AccountManager::PROPERTY_PHONE] = $userAccount[AccountManager::PROPERTY_PHONE]['value']; |
|
| 144 | - $data[AccountManager::PROPERTY_ADDRESS] = $userAccount[AccountManager::PROPERTY_ADDRESS]['value']; |
|
| 145 | - $data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value']; |
|
| 146 | - $data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value']; |
|
| 147 | - $data['groups'] = $gids; |
|
| 148 | - $data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang'); |
|
| 149 | - $data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale'); |
|
| 150 | - |
|
| 151 | - $backend = $targetUserObject->getBackend(); |
|
| 152 | - $data['backendCapabilities'] = [ |
|
| 153 | - 'setDisplayName' => $backend instanceof ISetDisplayNameBackend || $backend->implementsActions(Backend::SET_DISPLAYNAME), |
|
| 154 | - 'setPassword' => $backend instanceof ISetPasswordBackend || $backend->implementsActions(Backend::SET_PASSWORD), |
|
| 155 | - ]; |
|
| 156 | - |
|
| 157 | - return $data; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Get the groups a user is a subadmin of |
|
| 162 | - * |
|
| 163 | - * @param string $userId |
|
| 164 | - * @return array |
|
| 165 | - * @throws OCSException |
|
| 166 | - */ |
|
| 167 | - protected function getUserSubAdminGroupsData(string $userId): array { |
|
| 168 | - $user = $this->userManager->get($userId); |
|
| 169 | - // Check if the user exists |
|
| 170 | - if($user === null) { |
|
| 171 | - throw new OCSNotFoundException('User does not exist'); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - // Get the subadmin groups |
|
| 175 | - $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
| 176 | - $groups = []; |
|
| 177 | - foreach ($subAdminGroups as $key => $group) { |
|
| 178 | - $groups[] = $group->getGID(); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - return $groups; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * @param string $userId |
|
| 186 | - * @return array |
|
| 187 | - * @throws \OCP\Files\NotFoundException |
|
| 188 | - */ |
|
| 189 | - protected function fillStorageInfo(string $userId): array { |
|
| 190 | - try { |
|
| 191 | - \OC_Util::tearDownFS(); |
|
| 192 | - \OC_Util::setupFS($userId); |
|
| 193 | - $storage = OC_Helper::getStorageInfo('/'); |
|
| 194 | - $data = [ |
|
| 195 | - 'free' => $storage['free'], |
|
| 196 | - 'used' => $storage['used'], |
|
| 197 | - 'total' => $storage['total'], |
|
| 198 | - 'relative' => $storage['relative'], |
|
| 199 | - 'quota' => $storage['quota'], |
|
| 200 | - ]; |
|
| 201 | - } catch (NotFoundException $ex) { |
|
| 202 | - // User fs is not setup yet |
|
| 203 | - $user = $this->userManager->get($userId); |
|
| 204 | - if ($user === null) { |
|
| 205 | - throw new OCSException('User does not exist', 101); |
|
| 206 | - } |
|
| 207 | - $quota = $user->getQuota(); |
|
| 208 | - if ($quota !== 'none') { |
|
| 209 | - $quota = OC_Helper::computerFileSize($quota); |
|
| 210 | - } |
|
| 211 | - $data = [ |
|
| 212 | - 'quota' => $quota !== false ? $quota : 'none', |
|
| 213 | - 'used' => 0 |
|
| 214 | - ]; |
|
| 215 | - } |
|
| 216 | - return $data; |
|
| 217 | - } |
|
| 51 | + /** @var IUserManager */ |
|
| 52 | + protected $userManager; |
|
| 53 | + /** @var IConfig */ |
|
| 54 | + protected $config; |
|
| 55 | + /** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface |
|
| 56 | + protected $groupManager; |
|
| 57 | + /** @var IUserSession */ |
|
| 58 | + protected $userSession; |
|
| 59 | + /** @var AccountManager */ |
|
| 60 | + protected $accountManager; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @param string $appName |
|
| 64 | + * @param IRequest $request |
|
| 65 | + * @param IUserManager $userManager |
|
| 66 | + * @param IConfig $config |
|
| 67 | + * @param IGroupManager $groupManager |
|
| 68 | + * @param IUserSession $userSession |
|
| 69 | + * @param AccountManager $accountManager |
|
| 70 | + */ |
|
| 71 | + public function __construct(string $appName, |
|
| 72 | + IRequest $request, |
|
| 73 | + IUserManager $userManager, |
|
| 74 | + IConfig $config, |
|
| 75 | + IGroupManager $groupManager, |
|
| 76 | + IUserSession $userSession, |
|
| 77 | + AccountManager $accountManager) { |
|
| 78 | + parent::__construct($appName, $request); |
|
| 79 | + |
|
| 80 | + $this->userManager = $userManager; |
|
| 81 | + $this->config = $config; |
|
| 82 | + $this->groupManager = $groupManager; |
|
| 83 | + $this->userSession = $userSession; |
|
| 84 | + $this->accountManager = $accountManager; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * creates a array with all user data |
|
| 89 | + * |
|
| 90 | + * @param string $userId |
|
| 91 | + * @return array |
|
| 92 | + * @throws NotFoundException |
|
| 93 | + * @throws OCSException |
|
| 94 | + * @throws OCSNotFoundException |
|
| 95 | + */ |
|
| 96 | + protected function getUserData(string $userId): array { |
|
| 97 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 98 | + |
|
| 99 | + $data = []; |
|
| 100 | + |
|
| 101 | + // Check if the target user exists |
|
| 102 | + $targetUserObject = $this->userManager->get($userId); |
|
| 103 | + if($targetUserObject === null) { |
|
| 104 | + throw new OCSNotFoundException('User does not exist'); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + // Should be at least Admin Or SubAdmin! |
|
| 108 | + if ($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
| 109 | + || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
|
| 110 | + $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true') === 'true'; |
|
| 111 | + } else { |
|
| 112 | + // Check they are looking up themselves |
|
| 113 | + if ($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
| 114 | + return $data; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + // Get groups data |
|
| 119 | + $userAccount = $this->accountManager->getUser($targetUserObject); |
|
| 120 | + $groups = $this->groupManager->getUserGroups($targetUserObject); |
|
| 121 | + $gids = []; |
|
| 122 | + foreach ($groups as $group) { |
|
| 123 | + $gids[] = $group->getGID(); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + try { |
|
| 127 | + # might be thrown by LDAP due to handling of users disappears |
|
| 128 | + # from the external source (reasons unknown to us) |
|
| 129 | + # cf. https://github.com/nextcloud/server/issues/12991 |
|
| 130 | + $data['storageLocation'] = $targetUserObject->getHome(); |
|
| 131 | + } catch (NoUserException $e) { |
|
| 132 | + throw new OCSNotFoundException($e->getMessage(), $e); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // Find the data |
|
| 136 | + $data['id'] = $targetUserObject->getUID(); |
|
| 137 | + $data['lastLogin'] = $targetUserObject->getLastLogin() * 1000; |
|
| 138 | + $data['backend'] = $targetUserObject->getBackendClassName(); |
|
| 139 | + $data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID()); |
|
| 140 | + $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID()); |
|
| 141 | + $data[AccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress(); |
|
| 142 | + $data[AccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName(); |
|
| 143 | + $data[AccountManager::PROPERTY_PHONE] = $userAccount[AccountManager::PROPERTY_PHONE]['value']; |
|
| 144 | + $data[AccountManager::PROPERTY_ADDRESS] = $userAccount[AccountManager::PROPERTY_ADDRESS]['value']; |
|
| 145 | + $data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value']; |
|
| 146 | + $data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value']; |
|
| 147 | + $data['groups'] = $gids; |
|
| 148 | + $data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang'); |
|
| 149 | + $data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale'); |
|
| 150 | + |
|
| 151 | + $backend = $targetUserObject->getBackend(); |
|
| 152 | + $data['backendCapabilities'] = [ |
|
| 153 | + 'setDisplayName' => $backend instanceof ISetDisplayNameBackend || $backend->implementsActions(Backend::SET_DISPLAYNAME), |
|
| 154 | + 'setPassword' => $backend instanceof ISetPasswordBackend || $backend->implementsActions(Backend::SET_PASSWORD), |
|
| 155 | + ]; |
|
| 156 | + |
|
| 157 | + return $data; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Get the groups a user is a subadmin of |
|
| 162 | + * |
|
| 163 | + * @param string $userId |
|
| 164 | + * @return array |
|
| 165 | + * @throws OCSException |
|
| 166 | + */ |
|
| 167 | + protected function getUserSubAdminGroupsData(string $userId): array { |
|
| 168 | + $user = $this->userManager->get($userId); |
|
| 169 | + // Check if the user exists |
|
| 170 | + if($user === null) { |
|
| 171 | + throw new OCSNotFoundException('User does not exist'); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + // Get the subadmin groups |
|
| 175 | + $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
| 176 | + $groups = []; |
|
| 177 | + foreach ($subAdminGroups as $key => $group) { |
|
| 178 | + $groups[] = $group->getGID(); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + return $groups; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * @param string $userId |
|
| 186 | + * @return array |
|
| 187 | + * @throws \OCP\Files\NotFoundException |
|
| 188 | + */ |
|
| 189 | + protected function fillStorageInfo(string $userId): array { |
|
| 190 | + try { |
|
| 191 | + \OC_Util::tearDownFS(); |
|
| 192 | + \OC_Util::setupFS($userId); |
|
| 193 | + $storage = OC_Helper::getStorageInfo('/'); |
|
| 194 | + $data = [ |
|
| 195 | + 'free' => $storage['free'], |
|
| 196 | + 'used' => $storage['used'], |
|
| 197 | + 'total' => $storage['total'], |
|
| 198 | + 'relative' => $storage['relative'], |
|
| 199 | + 'quota' => $storage['quota'], |
|
| 200 | + ]; |
|
| 201 | + } catch (NotFoundException $ex) { |
|
| 202 | + // User fs is not setup yet |
|
| 203 | + $user = $this->userManager->get($userId); |
|
| 204 | + if ($user === null) { |
|
| 205 | + throw new OCSException('User does not exist', 101); |
|
| 206 | + } |
|
| 207 | + $quota = $user->getQuota(); |
|
| 208 | + if ($quota !== 'none') { |
|
| 209 | + $quota = OC_Helper::computerFileSize($quota); |
|
| 210 | + } |
|
| 211 | + $data = [ |
|
| 212 | + 'quota' => $quota !== false ? $quota : 'none', |
|
| 213 | + 'used' => 0 |
|
| 214 | + ]; |
|
| 215 | + } |
|
| 216 | + return $data; |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | 219 | } |
@@ -34,62 +34,62 @@ |
||
| 34 | 34 | |
| 35 | 35 | class AccessibilityProvider { |
| 36 | 36 | |
| 37 | - /** @var string */ |
|
| 38 | - protected $appName; |
|
| 37 | + /** @var string */ |
|
| 38 | + protected $appName; |
|
| 39 | 39 | |
| 40 | - /** @var IURLGenerator */ |
|
| 41 | - private $urlGenerator; |
|
| 40 | + /** @var IURLGenerator */ |
|
| 41 | + private $urlGenerator; |
|
| 42 | 42 | |
| 43 | - /** @var IL10N */ |
|
| 44 | - private $l; |
|
| 43 | + /** @var IL10N */ |
|
| 44 | + private $l; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Account constructor. |
|
| 48 | - * |
|
| 49 | - * @param string $appName |
|
| 50 | - * @param IURLGenerator $urlGenerator |
|
| 51 | - * @param IL10N $l |
|
| 52 | - */ |
|
| 53 | - public function __construct(string $appName, |
|
| 54 | - IURLGenerator $urlGenerator, |
|
| 55 | - IL10N $l) { |
|
| 56 | - $this->appName = $appName; |
|
| 57 | - $this->urlGenerator = $urlGenerator; |
|
| 58 | - $this->l = $l; |
|
| 59 | - } |
|
| 46 | + /** |
|
| 47 | + * Account constructor. |
|
| 48 | + * |
|
| 49 | + * @param string $appName |
|
| 50 | + * @param IURLGenerator $urlGenerator |
|
| 51 | + * @param IL10N $l |
|
| 52 | + */ |
|
| 53 | + public function __construct(string $appName, |
|
| 54 | + IURLGenerator $urlGenerator, |
|
| 55 | + IL10N $l) { |
|
| 56 | + $this->appName = $appName; |
|
| 57 | + $this->urlGenerator = $urlGenerator; |
|
| 58 | + $this->l = $l; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - public function getThemes() { |
|
| 62 | - return [ |
|
| 63 | - [ |
|
| 64 | - 'id' => 'dark', |
|
| 65 | - 'img' => $this->urlGenerator->imagePath($this->appName, 'theme-dark.jpg'), |
|
| 66 | - 'title' => $this->l->t('Dark theme'), |
|
| 67 | - 'enableLabel' => $this->l->t('Enable dark theme'), |
|
| 68 | - 'text' => $this->l->t('A dark theme to ease your eyes by reducing the overall luminosity and brightness. It is still under development, so please report any issues you may find.') |
|
| 69 | - ] |
|
| 70 | - ]; |
|
| 71 | - } |
|
| 61 | + public function getThemes() { |
|
| 62 | + return [ |
|
| 63 | + [ |
|
| 64 | + 'id' => 'dark', |
|
| 65 | + 'img' => $this->urlGenerator->imagePath($this->appName, 'theme-dark.jpg'), |
|
| 66 | + 'title' => $this->l->t('Dark theme'), |
|
| 67 | + 'enableLabel' => $this->l->t('Enable dark theme'), |
|
| 68 | + 'text' => $this->l->t('A dark theme to ease your eyes by reducing the overall luminosity and brightness. It is still under development, so please report any issues you may find.') |
|
| 69 | + ] |
|
| 70 | + ]; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - public function getHighContrast() { |
|
| 74 | - return [ |
|
| 75 | - 'id' => 'highcontrast', |
|
| 76 | - 'img' => $this->urlGenerator->imagePath($this->appName, 'mode-highcontrast.jpg'), |
|
| 77 | - 'title' => $this->l->t('High contrast mode'), |
|
| 78 | - 'enableLabel' => $this->l->t('Enable high contrast mode'), |
|
| 79 | - 'text' => $this->l->t('A high contrast mode to ease your navigation. Visual quality will be reduced but clarity will be increased.') |
|
| 80 | - ]; |
|
| 81 | - } |
|
| 73 | + public function getHighContrast() { |
|
| 74 | + return [ |
|
| 75 | + 'id' => 'highcontrast', |
|
| 76 | + 'img' => $this->urlGenerator->imagePath($this->appName, 'mode-highcontrast.jpg'), |
|
| 77 | + 'title' => $this->l->t('High contrast mode'), |
|
| 78 | + 'enableLabel' => $this->l->t('Enable high contrast mode'), |
|
| 79 | + 'text' => $this->l->t('A high contrast mode to ease your navigation. Visual quality will be reduced but clarity will be increased.') |
|
| 80 | + ]; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - public function getFonts() { |
|
| 84 | - return [ |
|
| 85 | - [ |
|
| 86 | - 'id' => 'fontdyslexic', |
|
| 87 | - 'img' => $this->urlGenerator->imagePath($this->appName, 'font-opendyslexic.jpg'), |
|
| 88 | - 'title' => $this->l->t('Dyslexia font'), |
|
| 89 | - 'enableLabel' => $this->l->t('Enable dyslexia font'), |
|
| 90 | - 'text' => $this->l->t('OpenDyslexic is a free typeface/font designed to mitigate some of the common reading errors caused by dyslexia.') |
|
| 91 | - ] |
|
| 92 | - ]; |
|
| 93 | - } |
|
| 83 | + public function getFonts() { |
|
| 84 | + return [ |
|
| 85 | + [ |
|
| 86 | + 'id' => 'fontdyslexic', |
|
| 87 | + 'img' => $this->urlGenerator->imagePath($this->appName, 'font-opendyslexic.jpg'), |
|
| 88 | + 'title' => $this->l->t('Dyslexia font'), |
|
| 89 | + 'enableLabel' => $this->l->t('Enable dyslexia font'), |
|
| 90 | + 'text' => $this->l->t('OpenDyslexic is a free typeface/font designed to mitigate some of the common reading errors caused by dyslexia.') |
|
| 91 | + ] |
|
| 92 | + ]; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | 95 | } |
@@ -24,25 +24,25 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | |
| 26 | 26 | return [ |
| 27 | - 'routes' => [ |
|
| 28 | - ['name' => 'accessibility#getCss', 'url' => '/css/user-{md5}', 'verb' => 'GET'], |
|
| 29 | - ['name' => 'accessibility#getJavascript', 'url' => '/js/accessibility', 'verb' => 'GET'], |
|
| 30 | - ], |
|
| 31 | - 'ocs' => [ |
|
| 32 | - [ |
|
| 33 | - 'name' => 'Config#getConfig', |
|
| 34 | - 'url' => '/api/v1/config', |
|
| 35 | - 'verb' => 'GET', |
|
| 36 | - ], |
|
| 37 | - [ |
|
| 38 | - 'name' => 'Config#setConfig', |
|
| 39 | - 'url' => '/api/v1/config/{key}', |
|
| 40 | - 'verb' => 'PUT', |
|
| 41 | - ], |
|
| 42 | - [ |
|
| 43 | - 'name' => 'Config#deleteConfig', |
|
| 44 | - 'url' => '/api/v1/config/{key}', |
|
| 45 | - 'verb' => 'DELETE', |
|
| 46 | - ], |
|
| 47 | - ] |
|
| 27 | + 'routes' => [ |
|
| 28 | + ['name' => 'accessibility#getCss', 'url' => '/css/user-{md5}', 'verb' => 'GET'], |
|
| 29 | + ['name' => 'accessibility#getJavascript', 'url' => '/js/accessibility', 'verb' => 'GET'], |
|
| 30 | + ], |
|
| 31 | + 'ocs' => [ |
|
| 32 | + [ |
|
| 33 | + 'name' => 'Config#getConfig', |
|
| 34 | + 'url' => '/api/v1/config', |
|
| 35 | + 'verb' => 'GET', |
|
| 36 | + ], |
|
| 37 | + [ |
|
| 38 | + 'name' => 'Config#setConfig', |
|
| 39 | + 'url' => '/api/v1/config/{key}', |
|
| 40 | + 'verb' => 'PUT', |
|
| 41 | + ], |
|
| 42 | + [ |
|
| 43 | + 'name' => 'Config#deleteConfig', |
|
| 44 | + 'url' => '/api/v1/config/{key}', |
|
| 45 | + 'verb' => 'DELETE', |
|
| 46 | + ], |
|
| 47 | + ] |
|
| 48 | 48 | ]; |
@@ -29,59 +29,59 @@ |
||
| 29 | 29 | |
| 30 | 30 | class ShareRequest implements XmlDeserializable { |
| 31 | 31 | |
| 32 | - public $set = []; |
|
| 32 | + public $set = []; |
|
| 33 | 33 | |
| 34 | - public $remove = []; |
|
| 34 | + public $remove = []; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Constructor |
|
| 38 | - * |
|
| 39 | - * @param array $set |
|
| 40 | - * @param array $remove |
|
| 41 | - */ |
|
| 42 | - function __construct(array $set, array $remove) { |
|
| 36 | + /** |
|
| 37 | + * Constructor |
|
| 38 | + * |
|
| 39 | + * @param array $set |
|
| 40 | + * @param array $remove |
|
| 41 | + */ |
|
| 42 | + function __construct(array $set, array $remove) { |
|
| 43 | 43 | |
| 44 | - $this->set = $set; |
|
| 45 | - $this->remove = $remove; |
|
| 44 | + $this->set = $set; |
|
| 45 | + $this->remove = $remove; |
|
| 46 | 46 | |
| 47 | - } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - static function xmlDeserialize(Reader $reader) { |
|
| 49 | + static function xmlDeserialize(Reader $reader) { |
|
| 50 | 50 | |
| 51 | - $elements = $reader->parseInnerTree([ |
|
| 52 | - '{' . Plugin::NS_OWNCLOUD. '}set' => 'Sabre\\Xml\\Element\\KeyValue', |
|
| 53 | - '{' . Plugin::NS_OWNCLOUD . '}remove' => 'Sabre\\Xml\\Element\\KeyValue', |
|
| 54 | - ]); |
|
| 51 | + $elements = $reader->parseInnerTree([ |
|
| 52 | + '{' . Plugin::NS_OWNCLOUD. '}set' => 'Sabre\\Xml\\Element\\KeyValue', |
|
| 53 | + '{' . Plugin::NS_OWNCLOUD . '}remove' => 'Sabre\\Xml\\Element\\KeyValue', |
|
| 54 | + ]); |
|
| 55 | 55 | |
| 56 | - $set = []; |
|
| 57 | - $remove = []; |
|
| 56 | + $set = []; |
|
| 57 | + $remove = []; |
|
| 58 | 58 | |
| 59 | - foreach ($elements as $elem) { |
|
| 60 | - switch ($elem['name']) { |
|
| 59 | + foreach ($elements as $elem) { |
|
| 60 | + switch ($elem['name']) { |
|
| 61 | 61 | |
| 62 | - case '{' . Plugin::NS_OWNCLOUD . '}set' : |
|
| 63 | - $sharee = $elem['value']; |
|
| 62 | + case '{' . Plugin::NS_OWNCLOUD . '}set' : |
|
| 63 | + $sharee = $elem['value']; |
|
| 64 | 64 | |
| 65 | - $sumElem = '{' . Plugin::NS_OWNCLOUD . '}summary'; |
|
| 66 | - $commonName = '{' . Plugin::NS_OWNCLOUD . '}common-name'; |
|
| 65 | + $sumElem = '{' . Plugin::NS_OWNCLOUD . '}summary'; |
|
| 66 | + $commonName = '{' . Plugin::NS_OWNCLOUD . '}common-name'; |
|
| 67 | 67 | |
| 68 | - $set[] = [ |
|
| 69 | - 'href' => $sharee['{DAV:}href'], |
|
| 70 | - 'commonName' => isset($sharee[$commonName]) ? $sharee[$commonName] : null, |
|
| 71 | - 'summary' => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null, |
|
| 72 | - 'readOnly' => !array_key_exists('{' . Plugin::NS_OWNCLOUD . '}read-write', $sharee), |
|
| 73 | - ]; |
|
| 74 | - break; |
|
| 68 | + $set[] = [ |
|
| 69 | + 'href' => $sharee['{DAV:}href'], |
|
| 70 | + 'commonName' => isset($sharee[$commonName]) ? $sharee[$commonName] : null, |
|
| 71 | + 'summary' => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null, |
|
| 72 | + 'readOnly' => !array_key_exists('{' . Plugin::NS_OWNCLOUD . '}read-write', $sharee), |
|
| 73 | + ]; |
|
| 74 | + break; |
|
| 75 | 75 | |
| 76 | - case '{' . Plugin::NS_OWNCLOUD . '}remove' : |
|
| 77 | - $remove[] = $elem['value']['{DAV:}href']; |
|
| 78 | - break; |
|
| 76 | + case '{' . Plugin::NS_OWNCLOUD . '}remove' : |
|
| 77 | + $remove[] = $elem['value']['{DAV:}href']; |
|
| 78 | + break; |
|
| 79 | 79 | |
| 80 | - } |
|
| 81 | - } |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - return new self($set, $remove); |
|
| 83 | + return new self($set, $remove); |
|
| 84 | 84 | |
| 85 | - } |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | 87 | } |
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | static function xmlDeserialize(Reader $reader) { |
| 50 | 50 | |
| 51 | 51 | $elements = $reader->parseInnerTree([ |
| 52 | - '{' . Plugin::NS_OWNCLOUD. '}set' => 'Sabre\\Xml\\Element\\KeyValue', |
|
| 53 | - '{' . Plugin::NS_OWNCLOUD . '}remove' => 'Sabre\\Xml\\Element\\KeyValue', |
|
| 52 | + '{'.Plugin::NS_OWNCLOUD.'}set' => 'Sabre\\Xml\\Element\\KeyValue', |
|
| 53 | + '{'.Plugin::NS_OWNCLOUD.'}remove' => 'Sabre\\Xml\\Element\\KeyValue', |
|
| 54 | 54 | ]); |
| 55 | 55 | |
| 56 | 56 | $set = []; |
@@ -59,21 +59,21 @@ discard block |
||
| 59 | 59 | foreach ($elements as $elem) { |
| 60 | 60 | switch ($elem['name']) { |
| 61 | 61 | |
| 62 | - case '{' . Plugin::NS_OWNCLOUD . '}set' : |
|
| 62 | + case '{'.Plugin::NS_OWNCLOUD.'}set' : |
|
| 63 | 63 | $sharee = $elem['value']; |
| 64 | 64 | |
| 65 | - $sumElem = '{' . Plugin::NS_OWNCLOUD . '}summary'; |
|
| 66 | - $commonName = '{' . Plugin::NS_OWNCLOUD . '}common-name'; |
|
| 65 | + $sumElem = '{'.Plugin::NS_OWNCLOUD.'}summary'; |
|
| 66 | + $commonName = '{'.Plugin::NS_OWNCLOUD.'}common-name'; |
|
| 67 | 67 | |
| 68 | 68 | $set[] = [ |
| 69 | 69 | 'href' => $sharee['{DAV:}href'], |
| 70 | 70 | 'commonName' => isset($sharee[$commonName]) ? $sharee[$commonName] : null, |
| 71 | 71 | 'summary' => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null, |
| 72 | - 'readOnly' => !array_key_exists('{' . Plugin::NS_OWNCLOUD . '}read-write', $sharee), |
|
| 72 | + 'readOnly' => !array_key_exists('{'.Plugin::NS_OWNCLOUD.'}read-write', $sharee), |
|
| 73 | 73 | ]; |
| 74 | 74 | break; |
| 75 | 75 | |
| 76 | - case '{' . Plugin::NS_OWNCLOUD . '}remove' : |
|
| 76 | + case '{'.Plugin::NS_OWNCLOUD.'}remove' : |
|
| 77 | 77 | $remove[] = $elem['value']['{DAV:}href']; |
| 78 | 78 | break; |
| 79 | 79 | |