]> source.dussan.org Git - nextcloud-server.git/commitdiff
Show the displayname instead of the user id 20366/head
authorJoas Schilling <coding@schilljs.com>
Wed, 8 Apr 2020 14:09:03 +0000 (16:09 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Wed, 8 Apr 2020 17:38:14 +0000 (17:38 +0000)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/files/lib/Notification/Notifier.php

index 604408eee1026e4c6f4381d2dc7df00b8555eff9..e419586f29b50424503665adeaf1173f1e5d35f5 100644 (file)
@@ -34,6 +34,8 @@ use OCP\AppFramework\Http;
 use OCP\AppFramework\Http\DataResponse;
 use OCP\AppFramework\Utility\ITimeFactory;
 use OCP\IURLGenerator;
+use OCP\IUser;
+use OCP\IUserManager;
 use OCP\L10N\IFactory;
 use OCP\Notification\IAction;
 use OCP\Notification\IDismissableNotifier;
@@ -52,22 +54,22 @@ class Notifier implements INotifier, IDismissableNotifier {
        private $mapper;
        /** @var IManager */
        private $notificationManager;
+       /** @var IUserManager */
+       private $userManager;
        /** @var ITimeFactory */
        private $timeFactory;
 
-       /**
-        * @param IFactory $l10nFactory
-        * @param IURLGenerator $urlGenerator
-        */
        public function __construct(IFactory $l10nFactory,
                                                                IURLGenerator $urlGenerator,
                                                                TransferOwnershipMapper $mapper,
                                                                IManager $notificationManager,
+                                                               IUserManager $userManager,
                                                                ITimeFactory $timeFactory) {
                $this->l10nFactory = $l10nFactory;
                $this->urlGenerator = $urlGenerator;
                $this->mapper = $mapper;
                $this->notificationManager = $notificationManager;
+               $this->userManager = $userManager;
                $this->timeFactory = $timeFactory;
        }
 
@@ -140,6 +142,7 @@ class Notifier implements INotifier, IDismissableNotifier {
                                IAction::TYPE_DELETE
                        );
 
+               $sourceUser = $this->getUser($param['sourceUser']);
                $notification->addParsedAction($approveAction)
                        ->addParsedAction($disapproveAction)
                        ->setRichSubject(
@@ -147,11 +150,11 @@ class Notifier implements INotifier, IDismissableNotifier {
                                [
                                        'user' => [
                                                'type' => 'user',
-                                               'id' => $param['sourceUser'],
-                                               'name' => $param['sourceUser'],
+                                               'id' => $sourceUser->getUID(),
+                                               'name' => $sourceUser->getDisplayName(),
                                        ],
                                ])
-                       ->setParsedSubject(str_replace('{user}', $param['sourceUser'], $l->t('Incoming ownership transfer from {user}')))
+                       ->setParsedSubject(str_replace('{user}', $sourceUser->getDisplayName(), $l->t('Incoming ownership transfer from {user}')))
                        ->setRichMessage(
                                $l->t("Do you want to accept {path}?\n\nNote: The transfer process after accepting may take up to 1 hour."),
                                [
@@ -170,6 +173,7 @@ class Notifier implements INotifier, IDismissableNotifier {
                $l = $this->l10nFactory->get('files', $languageCode);
                $param = $notification->getSubjectParameters();
 
+               $targetUser = $this->getUser($param['targetUser']);
                $notification->setRichSubject($l->t('Ownership transfer failed'))
                        ->setParsedSubject($l->t('Ownership transfer failed'))
 
@@ -183,11 +187,11 @@ class Notifier implements INotifier, IDismissableNotifier {
                                        ],
                                        'user' => [
                                                'type' => 'user',
-                                               'id' => $param['targetUser'],
-                                               'name' => $param['targetUser'],
+                                               'id' => $targetUser->getUID(),
+                                               'name' => $targetUser->getDisplayName(),
                                        ],
                                ])
-                       ->setParsedMessage(str_replace(['{path}', '{user}'], [$param['nodeName'], $param['targetUser']], $l->t('Your ownership transfer of {path} to {user} failed.')));
+                       ->setParsedMessage(str_replace(['{path}', '{user}'], [$param['nodeName'], $targetUser->getDisplayName()], $l->t('Your ownership transfer of {path} to {user} failed.')));
                return $notification;
        }
 
@@ -195,6 +199,7 @@ class Notifier implements INotifier, IDismissableNotifier {
                $l = $this->l10nFactory->get('files', $languageCode);
                $param = $notification->getSubjectParameters();
 
+               $sourceUser = $this->getUser($param['sourceUser']);
                $notification->setRichSubject($l->t('Ownership transfer failed'))
                        ->setParsedSubject($l->t('Ownership transfer failed'))
 
@@ -208,11 +213,11 @@ class Notifier implements INotifier, IDismissableNotifier {
                                        ],
                                        'user' => [
                                                'type' => 'user',
-                                               'id' => $param['sourceUser'],
-                                               'name' => $param['sourceUser'],
+                                               'id' => $sourceUser->getUID(),
+                                               'name' => $sourceUser->getDisplayName(),
                                        ],
                                ])
-                       ->setParsedMessage(str_replace(['{path}', '{user}'], [$param['nodeName'], $param['sourceUser']], $l->t('The ownership transfer of {path} from {user} failed.')));
+                       ->setParsedMessage(str_replace(['{path}', '{user}'], [$param['nodeName'], $sourceUser->getDisplayName()], $l->t('The ownership transfer of {path} from {user} failed.')));
 
                return $notification;
        }
@@ -221,6 +226,7 @@ class Notifier implements INotifier, IDismissableNotifier {
                $l = $this->l10nFactory->get('files', $languageCode);
                $param = $notification->getSubjectParameters();
 
+               $targetUser = $this->getUser($param['targetUser']);
                $notification->setRichSubject($l->t('Ownership transfer done'))
                        ->setParsedSubject($l->t('Ownership transfer done'))
 
@@ -234,11 +240,11 @@ class Notifier implements INotifier, IDismissableNotifier {
                                        ],
                                        'user' => [
                                                'type' => 'user',
-                                               'id' => $param['targetUser'],
-                                               'name' => $param['targetUser'],
+                                               'id' => $targetUser->getUID(),
+                                               'name' => $targetUser->getDisplayName(),
                                        ],
                                ])
-                       ->setParsedMessage(str_replace(['{path}', '{user}'], [$param['nodeName'], $param['targetUser']], $l->t('Your ownership transfer of {path} to {user} has completed.')));
+                       ->setParsedMessage(str_replace(['{path}', '{user}'], [$param['nodeName'], $targetUser->getDisplayName()], $l->t('Your ownership transfer of {path} to {user} has completed.')));
 
                return $notification;
        }
@@ -247,6 +253,7 @@ class Notifier implements INotifier, IDismissableNotifier {
                $l = $this->l10nFactory->get('files', $languageCode);
                $param = $notification->getSubjectParameters();
 
+               $sourceUser = $this->getUser($param['sourceUser']);
                $notification->setRichSubject($l->t('Ownership transfer done'))
                        ->setParsedSubject($l->t('Ownership transfer done'))
 
@@ -260,11 +267,11 @@ class Notifier implements INotifier, IDismissableNotifier {
                                        ],
                                        'user' => [
                                                'type' => 'user',
-                                               'id' => $param['sourceUser'],
-                                               'name' => $param['sourceUser'],
+                                               'id' => $sourceUser->getUID(),
+                                               'name' => $sourceUser->getDisplayName(),
                                        ],
                                ])
-                       ->setParsedMessage(str_replace(['{path}', '{user}'], [$param['nodeName'], $param['sourceUser']], $l->t('The ownership transfer of {path} from {user} has completed.')));
+                       ->setParsedMessage(str_replace(['{path}', '{user}'], [$param['nodeName'], $sourceUser->getDisplayName()], $l->t('The ownership transfer of {path} from {user} has completed.')));
 
                return $notification;
        }
@@ -295,4 +302,12 @@ class Notifier implements INotifier, IDismissableNotifier {
 
                $this->mapper->delete($transferOwnership);
        }
+
+       protected function getUser(string $userId): IUser {
+               $user = $this->userManager->get($userId);
+               if ($user instanceof IUser) {
+                       return $user;
+               }
+               throw new \InvalidArgumentException('User not found');
+       }
 }