Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/BackgroundJob/ImportTableJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use OCA\Tables\Activity\ActivityManager;
use OCA\Tables\Db\TableMapper;
use OCA\Tables\Db\ViewMapper;
use OCA\Tables\Notification\NotificationHelper;
use OCA\Tables\Service\ImportService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\QueuedJob;
Expand All @@ -25,6 +26,7 @@ public function __construct(
private ActivityManager $activityManager,
private TableMapper $tableMapper,
private ViewMapper $viewMapper,
private NotificationHelper $notificationHelper,
) {
parent::__construct($time);
}
Expand Down Expand Up @@ -79,5 +81,11 @@ public function run($argument): void {
],
author: $userId
);
$this->notificationHelper->sendNotification(
objectType: ActivityManager::TABLES_OBJECT_TABLE,
object: $this->tableMapper->find($tableId),
subject: ActivityManager::SUBJECT_IMPORT_FINISHED,
author: $userId
);
}
}
29 changes: 27 additions & 2 deletions lib/Notification/NotificationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,19 @@ public function __construct(
}

/**
* @param Row2|Column $object
* @param Table|Row2|Column $object
* @param string $subject
* @param array<string, mixed> $additionalParams
* @param string|null $author
*/
public function sendNotification(string $objectType, Row2|Column $object, string $subject, $additionalParams = [], ?string $author = null): void {
public function sendNotification(string $objectType, Table|Row2|Column $object, string $subject, array $additionalParams = [], ?string $author = null): void {
try {
switch ($objectType) {
case ActivityManager::TABLES_OBJECT_TABLE:
if ($object instanceof Table) {
$this->sendTableNotification($object, $subject, $author);
}
break;
case ActivityManager::TABLES_OBJECT_ROW:
if ($object instanceof Row2) {
$this->sendRowNotification($object, $subject, $additionalParams, $author);
Expand All @@ -72,6 +77,26 @@ public function sendNotification(string $objectType, Row2|Column $object, string
}
}

private function sendTableNotification(Table $object, string $subject, ?string $author): void {
$subjectParams = [
'author' => $author,
'objectType' => ActivityManager::TABLES_OBJECT_TABLE,
'table' => [
'id' => $object->getId(),
'title' => $object->getTitle(),
]
];
$this->sendNotifiesByElement(
element: $object,
subject: $subject,
subjectParams: $subjectParams,
objectType: ActivityManager::TABLES_OBJECT_TABLE,
objectId: (string)$object->getId(),
authorId: null,
configKey: null,
);
}

Comment on lines +80 to +99

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i havent tested yet, but it seems this sends the async import completion notification through the table-recipient path. So for imports started from a view, the importing user may only have access to the view and therefore may not be included in findRecipientsByElement($table) ?

Also, doesn't this notify unrelated table recipients about someone else’s import

/**
* @param string|null $author
*/
Expand Down
17 changes: 17 additions & 0 deletions lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,23 @@ public function prepare(INotification $notification, string $languageCode): INot
: $l->t('{user} has deleted the column {column} from table {table}');
break;

case ActivityManager::SUBJECT_IMPORT_FINISHED:
$link = $richParams['table']['link'];
$recipient = $notification->getUser();
$isActivityOwner = $params['author'] === $recipient;
$parsedSubject = $isActivityOwner
? $l->t('You have imported file to table {table}', [
$richParams['table']['name'] ?? '',
])
: $l->t('{user} has imported file to table {table}', [
$richParams['user']['name'] ?? '',
$richParams['table']['name'] ?? '',
]);
$subject = $isActivityOwner
? $l->t('You have imported file to table {table}')
: $l->t('{user} has imported file to table {table}');
break;

default:
throw new UnknownNotificationException();
}
Expand Down
Loading