Skip to content

Commit 0e4e782

Browse files
committed
Enfore allowPublicShares admin setting
Use the the modern intial-state library to pass data about `allowPublicUploads` to the sharing frontend. Signed-off-by: fenn-cs <[email protected]>
1 parent 36ec915 commit 0e4e782

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

apps/files_sharing/lib/Listener/LoadSidebarListener.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,36 @@
2323
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2424
*
2525
*/
26+
2627
namespace OCA\Files_Sharing\Listener;
2728

2829
use OCA\Files_Sharing\AppInfo\Application;
2930
use OCA\Files\Event\LoadSidebar;
3031
use OCP\EventDispatcher\Event;
3132
use OCP\EventDispatcher\IEventListener;
3233
use OCP\Util;
34+
use OCP\AppFramework\Services\IInitialState;
35+
use OCP\Share\IManager;
36+
37+
class LoadSidebarListener implements IEventListener
38+
{
39+
40+
public function __construct(private IInitialState $initialState, private IManager $shareManager)
41+
{
42+
}
3343

34-
class LoadSidebarListener implements IEventListener {
35-
public function handle(Event $event): void {
44+
public function handle(Event $event): void
45+
{
3646
if (!($event instanceof LoadSidebar)) {
3747
return;
3848
}
3949

4050
Util::addScript(Application::APP_ID, 'files_sharing_tab', 'files');
51+
52+
$shareConfig = [
53+
'allowPublicUploads' => $this->shareManager->shareApiLinkAllowPublicUpload(),
54+
];
55+
56+
$this->initialState->provideInitialState('shareConfig', $shareConfig);
4157
}
4258
}

apps/files_sharing/src/components/SharingEntryQuickShareSelect.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export default {
100100
return options
101101
},
102102
supportsFileDrop() {
103-
if (this.isFolder) {
103+
if (this.isFolder && this.config.isPublicUploadEnabled) {
104104
const shareType = this.share.type ?? this.share.shareType
105105
return [this.SHARE_TYPES.SHARE_TYPE_LINK, this.SHARE_TYPES.SHARE_TYPE_EMAIL].includes(shareType)
106106
}

apps/files_sharing/src/services/ConfigService.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@
2222
*
2323
*/
2424

25+
import { loadState } from '@nextcloud/initial-state'
26+
2527
export default class Config {
2628

29+
constructor() {
30+
this._shareConfig = loadState('files_sharing', 'shareConfig', {})
31+
}
32+
2733
/**
2834
* Is public upload allowed on link shares ?
2935
*
@@ -32,8 +38,7 @@ export default class Config {
3238
* @memberof Config
3339
*/
3440
get isPublicUploadEnabled() {
35-
return document.getElementsByClassName('files-filestable')[0]
36-
&& document.getElementsByClassName('files-filestable')[0].dataset.allowPublicUpload === 'yes'
41+
return this._shareConfig.allowPublicUploads
3742
}
3843

3944
/**

apps/files_sharing/src/views/SharingDetailsTab.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ export default {
453453
return this.share.id === null || this.share.id === undefined
454454
},
455455
allowsFileDrop() {
456-
if (this.isFolder) {
456+
if (this.isFolder && this.config.isPublicUploadEnabled) {
457457
if (this.share.type === this.SHARE_TYPES.SHARE_TYPE_LINK || this.share.type === this.SHARE_TYPES.SHARE_TYPE_EMAIL) {
458458
return true
459459
}

0 commit comments

Comments
 (0)