refs #4035 fix attachment creator name: show display name instead of user id

Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
This commit is contained in:
Julien Veyssier
2022-09-07 16:53:26 +02:00
parent 552e10d79d
commit 5b2c03f733
2 changed files with 41 additions and 2 deletions

View File

@@ -39,6 +39,7 @@ use OCA\Deck\StatusException;
use OCP\AppFramework\Db\IMapperException;
use OCP\AppFramework\Http\Response;
use OCP\IL10N;
use OCP\IUserManager;
class AttachmentService {
private $attachmentMapper;
@@ -58,8 +59,18 @@ class AttachmentService {
private $activityManager;
/** @var ChangeHelper */
private $changeHelper;
private IUserManager $userManager;
public function __construct(AttachmentMapper $attachmentMapper, CardMapper $cardMapper, ChangeHelper $changeHelper, PermissionService $permissionService, Application $application, AttachmentCacheHelper $attachmentCacheHelper, $userId, IL10N $l10n, ActivityManager $activityManager) {
public function __construct(AttachmentMapper $attachmentMapper,
CardMapper $cardMapper,
IUserManager $userManager,
ChangeHelper $changeHelper,
PermissionService $permissionService,
Application $application,
AttachmentCacheHelper $attachmentCacheHelper,
$userId,
IL10N $l10n,
ActivityManager $activityManager) {
$this->attachmentMapper = $attachmentMapper;
$this->cardMapper = $cardMapper;
$this->permissionService = $permissionService;
@@ -69,6 +80,7 @@ class AttachmentService {
$this->l10n = $l10n;
$this->activityManager = $activityManager;
$this->changeHelper = $changeHelper;
$this->userManager = $userManager;
// Register shipped attachment services
// TODO: move this to a plugin based approach once we have different types of attachments
@@ -127,6 +139,7 @@ class AttachmentService {
try {
$service = $this->getService($attachment->getType());
$service->extendData($attachment);
$this->addCreator($attachment);
} catch (InvalidAttachmentType $e) {
// Ingore invalid attachment types when extending the data
}
@@ -210,6 +223,7 @@ class AttachmentService {
}
$service->extendData($attachment);
$this->addCreator($attachment);
} catch (InvalidAttachmentType $e) {
// just store the data
}
@@ -313,6 +327,7 @@ class AttachmentService {
$this->attachmentMapper->update($attachment);
// extend data so the frontend can use it properly after creating
$service->extendData($attachment);
$this->addCreator($attachment);
$this->changeHelper->cardChanged($attachment->getCardId());
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_UPDATE);
@@ -387,4 +402,28 @@ class AttachmentService {
}
throw new NoPermissionException('Restore is not allowed.');
}
/**
* @param Attachment $attachment
* @return Attachment
* @throws \ReflectionException
*/
private function addCreator(Attachment $attachment): Attachment {
$createdBy = $attachment->jsonSerialize()['createdBy'] ?? '';
$creator = [
'displayName' => $createdBy,
'id' => $createdBy,
'email' => null,
];
if ($this->userManager->userExists($createdBy)) {
$user = $this->userManager->get($createdBy);
$creator['displayName'] = $user->getDisplayName();
$creator['email'] = $user->getEMailAddress();
}
$extendedData = $attachment->jsonSerialize()['extendedData'] ?? [];
$extendedData['attachmentCreator'] = $creator;
$attachment->setExtendedData($extendedData);
return $attachment;
}
}

View File

@@ -63,7 +63,7 @@
<div v-if="attachment.deletedAt === 0">
<span class="filesize">{{ formattedFileSize(attachment.extendedData.filesize) }}</span>
<span class="filedate">{{ relativeDate(attachment.createdAt*1000) }}</span>
<span class="filedate">{{ attachment.createdBy }}</span>
<span class="filedate">{{ attachment.extendedData.attachmentCreator.displayName }}</span>
</div>
<div v-else>
<span class="attachment--info">{{ t('deck', 'Pending share') }}</span>