Skip to content

Commit 3d79086

Browse files
committed
fix(PublicFolders): Do not allow sharing publicly if disabled in global settings
fixes #1358 Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent 2af942c commit 3d79086

6 files changed

Lines changed: 21 additions & 20 deletions

File tree

lib/Controller/FoldersController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,8 @@ public function createFolderPublicToken(int $folderId): DataResponse {
620620
return new DataResponse(['status' => 'error', 'data' => ['Multiple objects returned']], Http::STATUS_INTERNAL_SERVER_ERROR);
621621
} catch (DoesNotExistException $e) {
622622
return new DataResponse(['status' => 'error', 'data' => ['Not found']], Http::STATUS_BAD_REQUEST);
623+
} catch (UnsupportedOperation $e) {
624+
return new DataResponse(['status' => 'error', 'data' => ['Unsupported operation']], Http::STATUS_BAD_REQUEST);
623625
}
624626
}
625627

lib/Controller/WebViewController.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use OCA\Bookmarks\Db\FolderMapper;
1414
use OCA\Bookmarks\Db\PublicFolder;
1515
use OCA\Bookmarks\Db\PublicFolderMapper;
16+
use OCA\Bookmarks\Service\SettingsService;
1617
use OCA\Bookmarks\Service\UserSettingsService;
1718
use OCP\AppFramework\Controller;
1819
use OCP\AppFramework\Db\DoesNotExistException;
@@ -22,7 +23,6 @@
2223
use OCP\AppFramework\Http\NotFoundResponse;
2324
use OCP\AppFramework\Http\StreamResponse;
2425
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
25-
use OCP\IInitialStateService;
2626
use OCP\IL10N;
2727
use OCP\IRequest;
2828
use OCP\IURLGenerator;
@@ -31,22 +31,8 @@
3131
class WebViewController extends Controller {
3232
private ?string $userId;
3333

34-
3534
/**
3635
* WebViewController constructor.
37-
*
38-
* @param string $appName
39-
* @param IRequest $request
40-
* @param string|null $userId
41-
* @param IL10N $l
42-
* @param PublicFolderMapper $publicFolderMapper
43-
* @param IUserManager $userManager
44-
* @param FolderMapper $folderMapper
45-
* @param IURLGenerator $urlGenerator
46-
* @param IInitialStateService $initialState
47-
* @param InternalFoldersController $folderController
48-
* @param InternalBookmarkController $bookmarkController
49-
* @param UserSettingsService $userSettingsService
5036
*/
5137
public function __construct(
5238
$appName,
@@ -62,6 +48,7 @@ public function __construct(
6248
private \OCA\Bookmarks\Controller\InternalBookmarkController $bookmarkController,
6349
private \OCA\Bookmarks\Controller\InternalTagsController $tagsController,
6450
private UserSettingsService $userSettingsService,
51+
private SettingsService $settings,
6552
) {
6653
parent::__construct($appName, $request);
6754
$this->userId = $userId;
@@ -71,8 +58,6 @@ public function __construct(
7158
* @NoAdminRequired
7259
*
7360
* @NoCSRFRequired
74-
*
75-
* @return AugmentedTemplateResponse
7661
*/
7762
public function index(): AugmentedTemplateResponse {
7863
$res = new AugmentedTemplateResponse($this->appName, 'main', ['url' => $this->urlGenerator]);
@@ -95,6 +80,7 @@ public function index(): AugmentedTemplateResponse {
9580
$this->initialState->provideInitialState($this->appName, 'tags', $this->tagsController->fullTags(true)->getData());
9681

9782
$settings = $this->userSettingsService->toArray();
83+
$settings['shareapi_allow_links'] = $this->settings->getLinkSharingAllowed();
9884
$this->initialState->provideInitialState($this->appName, 'settings', $settings);
9985

10086
return $res;

lib/Service/FolderService.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function __construct(
5555
private HtmlImporter $htmlImporter,
5656
private IEventDispatcher $eventDispatcher,
5757
private CirclesService $circlesService,
58+
private SettingsService $settings,
5859
) {
5960
}
6061

@@ -261,10 +262,12 @@ public function updateSharedFolderOrFolder(?string $userId, int $folderId, ?stri
261262
/**
262263
* @param $folderId
263264
* @return string
264-
* @throws DoesNotExistException
265-
* @throws MultipleObjectsReturnedException
265+
* @throws DoesNotExistException|MultipleObjectsReturnedException|UnsupportedOperation
266266
*/
267267
public function createFolderPublicToken($folderId): string {
268+
if (!$this->settings->getLinkSharingAllowed()) {
269+
throw new UnsupportedOperation('Link sharing is not enabled');
270+
}
268271
$this->folderMapper->find($folderId);
269272
try {
270273
$publicFolder = $this->publicFolderMapper->findByFolder($folderId);

lib/Service/SettingsService.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace OCA\Bookmarks\Service;
1111

1212
use OCP\AppFramework\Services\IAppConfig;
13+
use OCP\IConfig;
1314

1415
class SettingsService {
1516
/** @var array<string,string> */
@@ -26,6 +27,7 @@ class SettingsService {
2627

2728
public function __construct(
2829
private IAppConfig $config,
30+
private IConfig $globalConfig,
2931
) {
3032
}
3133

@@ -59,4 +61,8 @@ public function getAll(): array {
5961
}
6062
return $settings;
6163
}
64+
65+
public function getLinkSharingAllowed(): bool {
66+
return $this->globalConfig->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes';
67+
}
6268
}

src/components/SidebarFolder.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
@option:selected="onAddShare"
4242
@search="onParticipantSearch" />
4343
</div>
44-
<div class="share">
44+
<div class="share" v-if="publicLinksAllowed">
4545
<LinkIcon :size="20" :class="{'share__avatar': true, active: publicLink }" />
4646
<h3 class="share__title">
4747
{{ t('bookmarks', 'Share link') }}
@@ -172,6 +172,9 @@ export default {
172172
permissions() {
173173
return this.$store.getters.getPermissionsForFolder(this.folder.id)
174174
},
175+
publicLinksAllowed() {
176+
return this.$store.state.settings.shareapi_allow_links
177+
},
175178
isSharable() {
176179
if (!this.folder) return
177180
return this.isOwner || (!this.isOwner && this.permissions.canShare)

src/store/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export default {
5353
backupPath: '',
5454
backupEnabled: '1',
5555
hasSeenWhatsnew: '',
56+
shareapi_allow_links: true,
5657
},
5758
bookmarks: [],
5859
bookmarksById: {},

0 commit comments

Comments
 (0)