Skip to content

Commit

Permalink
Use board permissions to be applied for the shares
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliushaertl committed Jan 4, 2021
1 parent 0c6dfb2 commit 79468e6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
7 changes: 6 additions & 1 deletion lib/Service/FilesAppService.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public function extendData(Attachment $attachment) {
'mimetype' => $file->getMimeType(),
'info' => pathinfo($file->getName()),
'hasPreview' => $this->preview->isAvailable($file),
'permissions' => $share->getPermissions(),
]);
return $attachment;
}
Expand Down Expand Up @@ -170,7 +171,11 @@ public function create(Attachment $attachment) {
$fileName = $file['name'];

$userFolder = $this->rootFolder->getUserFolder($this->userId);
$folder = $userFolder->get($this->configService->getAttachmentFolder());
try {
$folder = $userFolder->get($this->configService->getAttachmentFolder());
} catch (NotFoundException $e) {
$folder = $userFolder->newFolder($this->configService->getAttachmentFolder());
}

$fileName = $folder->getNonExistingName($fileName);
$target = $folder->newFile($fileName);
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/PermissionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function checkPermission($mapper, $id, $permission, $userId = null) {
}

if ($permission === Acl::PERMISSION_SHARE && $this->shareManager->sharingDisabledForUser($this->userId)) {
return false;
throw new NoPermissionException('Permission denied');
}

if ($this->userIsBoardOwner($boardId, $userId)) {
Expand Down
21 changes: 18 additions & 3 deletions lib/Sharing/DeckShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Constants;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Folder;
Expand Down Expand Up @@ -267,10 +268,25 @@ private function createShareObject(array $data): IShare {
$entryData['parent'] = $entryData['f_parent'];
$share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData, \OC::$server->get(IMimeTypeLoader::class)));
}

return $share;
}

private function applyBoardPermission($share, $permissions) {
try {
$this->permissionService->checkPermission($this->cardMapper, $share->getSharedWith(), Acl::PERMISSION_EDIT);
} catch (NoPermissionException $e) {
$permissions &= Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE;
$permissions &= Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE;
$permissions &= Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE;
}

try {
$this->permissionService->checkPermission($this->cardMapper, $share->getSharedWith(), Acl::PERMISSION_SHARE);
} catch (NoPermissionException $e) {
$permissions &= Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE;
}
$share->setPermissions($permissions);
}
/**
* @inheritDoc
*/
Expand Down Expand Up @@ -629,7 +645,7 @@ private function resolveSharesForRecipient(array $shares, string $userId): array
$stmt = $query->execute();

while ($data = $stmt->fetch()) {
$shareMap[$data['parent']]->setPermissions((int)$data['permissions']);
$this->applyBoardPermission($shareMap[$data['parent']], (int)$data['permissions']);
$shareMap[$data['parent']]->setTarget($data['file_target']);
}

Expand Down Expand Up @@ -740,7 +756,6 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset): arra
$offset--;
continue;
}

$shares[] = $this->createShareObject($data);
}
$cursor->closeCursor();
Expand Down
1 change: 0 additions & 1 deletion src/components/card/AttachmentList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ export default {
axios.post(generateOcsUrl('apps/files_sharing/api/v1', 2) + 'shares', {
path,
permissions: 19,
shareType: 12,
shareWith: '' + this.cardId,
}).then(() => {
Expand Down

0 comments on commit 79468e6

Please sign in to comment.