Skip to content

Commit

Permalink
Enfore allowPublicShares admin setting
Browse files Browse the repository at this point in the history
Use the the modern intial-state library to pass data about
`allowPublicUploads` to the sharing frontend.

Signed-off-by: fenn-cs <[email protected]>
  • Loading branch information
nfebe committed Sep 12, 2023
1 parent 8ce0cad commit 3fff09c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
23 changes: 21 additions & 2 deletions apps/files_sharing/lib/Listener/LoadSidebarListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,39 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Files_Sharing\Listener;

use OCA\Files_Sharing\AppInfo\Application;
use OCA\Files\Event\LoadSidebar;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Util;
use OCP\AppFramework\Services\IInitialState;
use OCP\Share\IManager;

/**
* @template-implements IEventListener<Event>
*/
class LoadSidebarListener implements IEventListener
{

class LoadSidebarListener implements IEventListener {
public function handle(Event $event): void {
public function __construct(private IInitialState $initialState, private IManager $shareManager)
{
}

public function handle(Event $event): void
{
if (!($event instanceof LoadSidebar)) {
return;
}

Util::addScript(Application::APP_ID, 'files_sharing_tab', 'files');

$shareConfig = [
'allowPublicUploads' => $this->shareManager->shareApiLinkAllowPublicUpload(),
];

$this->initialState->provideInitialState('shareConfig', $shareConfig);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default {
return options
},
supportsFileDrop() {
if (this.isFolder) {
if (this.isFolder && this.config.isPublicUploadEnabled) {
const shareType = this.share.type ?? this.share.shareType
return [this.SHARE_TYPES.SHARE_TYPE_LINK, this.SHARE_TYPES.SHARE_TYPE_EMAIL].includes(shareType)
}
Expand Down
9 changes: 7 additions & 2 deletions apps/files_sharing/src/services/ConfigService.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@
*
*/

import { loadState } from '@nextcloud/initial-state'

export default class Config {

constructor() {
this._shareConfig = loadState('files_sharing', 'shareConfig', {})
}

/**
* Is public upload allowed on link shares ?
*
Expand All @@ -32,8 +38,7 @@ export default class Config {
* @memberof Config
*/
get isPublicUploadEnabled() {
return document.getElementsByClassName('files-filestable')[0]
&& document.getElementsByClassName('files-filestable')[0].dataset.allowPublicUpload === 'yes'
return this._shareConfig.allowPublicUploads
}

/**
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/src/views/SharingDetailsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ export default {
return this.share.id === null || this.share.id === undefined
},
allowsFileDrop() {
if (this.isFolder) {
if (this.isFolder && this.config.isPublicUploadEnabled) {
if (this.share.type === this.SHARE_TYPES.SHARE_TYPE_LINK || this.share.type === this.SHARE_TYPES.SHARE_TYPE_EMAIL) {
return true
}
Expand Down

0 comments on commit 3fff09c

Please sign in to comment.