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 <fenn25.fn@gmail.com>
This commit is contained in:
fenn-cs 2023-09-11 21:06:23 +01:00
parent cec466ed3b
commit 51ad9cfcc8
4 changed files with 30 additions and 6 deletions

View file

@ -23,6 +23,7 @@ declare(strict_types=1);
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Files_Sharing\Listener;
use OCA\Files_Sharing\AppInfo\Application;
@ -30,13 +31,31 @@ 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;
class LoadSidebarListener implements IEventListener {
public function handle(Event $event): void {
/**
* @template-implements IEventListener<Event>
*/
class LoadSidebarListener implements IEventListener
{
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);
}
}

View file

@ -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)
}

View file

@ -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 ?
*
@ -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
}
/**

View file

@ -448,7 +448,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
}