Skip to content
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
20 changes: 20 additions & 0 deletions lib/CurrentUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,31 @@ public function getCloudId() {
return $this->cloudId;
}

/**
* Check if the current request is via a public share link
*/
public function isPublicShareToken(): bool {
/** @psalm-suppress NoInterfaceProperties */
if (!empty($this->request->server['PHP_AUTH_USER'])) {
$token = $this->request->server['PHP_AUTH_USER'];
try {
$share = $this->shareManager->getShareByToken($token);
return $share->getShareType() === IShare::TYPE_LINK
|| $share->getShareType() === IShare::TYPE_EMAIL;
} catch (ShareNotFound $e) {
// No share found for this token
}
}

return false;
}

/**
* Get the cloud ID from the sharing token
* @return string|null
*/
protected function getCloudIDFromToken() {
/** @psalm-suppress NoInterfaceProperties */
if (!empty($this->request->server['PHP_AUTH_USER'])) {
$token = $this->request->server['PHP_AUTH_USER'];
/**
Expand Down
2 changes: 1 addition & 1 deletion lib/FilesHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function fileCreate($path) {
return;
}

if ($this->currentUser->getUserIdentifier() !== '') {
if ($this->currentUser->getUserIdentifier() !== '' || !$this->currentUser->isPublicShareToken()) {
$this->addNotificationsForFileAction($path, Files::TYPE_SHARE_CREATED, 'created_self', 'created_by');
} else {
$this->addNotificationsForFileAction($path, Files_Sharing::TYPE_PUBLIC_UPLOAD, '', 'created_public');
Expand Down
38 changes: 32 additions & 6 deletions tests/FilesHooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,42 @@ protected function getUserMock(string $uid): IUser {

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

#[DataProvider('dataFileCreate')]
public function testFileCreate(string $currentUser, string $selfSubject, string $othersSubject, string $type): void {
$filesHooks = $this->getFilesHooks([
'addNotificationsForFileAction',
], $currentUser);
public function testFileCreate(string $currentUser, bool $isPublicShare, string $selfSubject, string $othersSubject, string $type): void {
$currentUserMock = $this->createMock(CurrentUser::class);
$currentUserMock->method('getUID')->willReturn($currentUser);
$currentUserMock->method('getUserIdentifier')->willReturn($currentUser);
$currentUserMock->method('isPublicShareToken')->willReturn($isPublicShare);

$logger = $this->createMock(LoggerInterface::class);

$filesHooks = $this->getMockBuilder(FilesHooks::class)
->setConstructorArgs([
$this->activityManager,
$this->data,
$this->settings,
$this->groupManager,
$this->view,
$this->rootFolder,
$this->shareHelper,
Server::get(IDBConnection::class),
$this->urlGenerator,
$logger,
$currentUserMock,
$this->userMountCache,
$this->config,
$this->notificationGenerator,
$this->tagManager,
$this->teamManager,
])
->onlyMethods(['addNotificationsForFileAction'])
->getMock();

$filesHooks->expects($this->once())
->method('addNotificationsForFileAction')
Expand Down
7 changes: 1 addition & 6 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="6.12.1@e71404b0465be25cf7f8a631b298c01c5ddd864f">
<files psalm-version="6.15.1@28dc127af1b5aecd52314f6f645bafc10d0e11f9">
<file src="lib/BackgroundJob/RemoteActivity.php">
<UndefinedClass>
<code><![CDATA[ClientException]]></code>
</UndefinedClass>
</file>
<file src="lib/CurrentUser.php">
<NoInterfaceProperties>
<code><![CDATA[$this->request->server]]></code>
</NoInterfaceProperties>
</file>
<file src="lib/Data.php">
<UndefinedDocblockClass>
<code><![CDATA[$favoriteFilter->filterFavorites($query);]]></code>
Expand Down
Loading