Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: split link upload activity type #1745

Merged
merged 1 commit into from
Aug 7, 2024
Merged
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
1 change: 1 addition & 0 deletions lib/Extension/Files_Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@

class Files_Sharing {
public const TYPE_SHARED = 'shared';
public const TYPE_PUBLIC_UPLOAD = 'public_links_upload';
}
10 changes: 5 additions & 5 deletions lib/FilesHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function fileCreate($path) {
if ($this->currentUser->getUserIdentifier() !== '') {
$this->addNotificationsForFileAction($path, Files::TYPE_SHARE_CREATED, 'created_self', 'created_by');
} else {
$this->addNotificationsForFileAction($path, Files::TYPE_SHARE_CREATED, '', 'created_public');
$this->addNotificationsForFileAction($path, Files_Sharing::TYPE_PUBLIC_UPLOAD, '', 'created_public');
}
}

Expand Down Expand Up @@ -108,9 +108,9 @@ public function fileRestore($path) {
$this->addNotificationsForFileAction($path, Files::TYPE_SHARE_RESTORED, 'restored_self', 'restored_by');
}

private function getFileChangeActivitySettings(int $fileId, array $users): array {
$filteredEmailUsers = $this->userSettings->filterUsersBySetting($users, 'email', Files::TYPE_FILE_CHANGED);
$filteredNotificationUsers = $this->userSettings->filterUsersBySetting($users, 'notification', Files::TYPE_FILE_CHANGED);
private function getFileChangeActivitySettings(int $fileId, array $users, $type = Files::TYPE_FILE_CHANGED): array {
$filteredEmailUsers = $this->userSettings->filterUsersBySetting($users, 'email', $type);
$filteredNotificationUsers = $this->userSettings->filterUsersBySetting($users, 'notification', $type);

/** @psalm-suppress UndefinedMethod */
$favoriteUsers = $this->tagManager->getUsersFavoritingObject('files', $fileId);
Expand Down Expand Up @@ -159,7 +159,7 @@ protected function addNotificationsForFileAction($filePath, $activityType, $subj
}

[$filteredEmailUsers, $filteredNotificationUsers] =
$this->getFileChangeActivitySettings($fileId, array_keys($affectedUsers));
$this->getFileChangeActivitySettings($fileId, array_keys($affectedUsers), $activityType);

foreach ($affectedUsers as $user => $path) {
$user = (string)$user;
Expand Down
8 changes: 4 additions & 4 deletions tests/FilesHooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ protected function getUserMock(string $uid): IUser {

public function dataFileCreate(): array {
return [
['user', 'created_self', 'created_by'],
['', '', 'created_public'],
['user', 'created_self', 'created_by', Files::TYPE_SHARE_CREATED],
['', '', 'created_public', Files_Sharing::TYPE_PUBLIC_UPLOAD],
];
}

Expand All @@ -190,14 +190,14 @@ public function dataFileCreate(): array {
* @param string $selfSubject
* @param string $othersSubject
*/
public function testFileCreate(string $currentUser, string $selfSubject, string $othersSubject): void {
public function testFileCreate(string $currentUser, string $selfSubject, string $othersSubject, string $type): void {
$filesHooks = $this->getFilesHooks([
'addNotificationsForFileAction',
], $currentUser);

$filesHooks->expects($this->once())
->method('addNotificationsForFileAction')
->with('path', Files::TYPE_SHARE_CREATED, $selfSubject, $othersSubject);
->with('path', $type, $selfSubject, $othersSubject);

$filesHooks->fileCreate('path');
}
Expand Down
Loading