fix(files_sharing): file request conditions with link/email global settings

Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
This commit is contained in:
skjnldsv 2024-07-16 17:59:03 +02:00
parent a5fdd1c64a
commit 365b647b60
3 changed files with 37 additions and 13 deletions

View file

@ -95,7 +95,7 @@
@click="onFinish">
<template #icon>
<NcLoadingIcon v-if="loading" />
<IconCheck v-else :size="20" />
<IconCheck v-else-if="success" :size="20" />
</template>
{{ finishButtonLabel }}
</NcButton>
@ -182,6 +182,7 @@ export default defineComponent({
return {
currentStep: STEP.FIRST,
loading: false,
success: false,
destination: this.context.path || '/',
label: '',
@ -244,10 +245,19 @@ export default defineComponent({
return
}
await this.setShareEmails()
await this.sendEmails()
showSuccess(this.t('files_sharing', 'File request created and emails sent'))
this.$emit('close')
if (sharingConfig.isMailShareAllowed && this.emails.length > 0) {
await this.setShareEmails()
await this.sendEmails()
showSuccess(this.n('files_sharing', 'File request created and email sent', 'File request created and {count} emails sent', this.emails.length, { count: this.emails.length }))
} else {
showSuccess(this.t('files_sharing', 'File request created'))
}
// Show success then close
this.success = true
setTimeout(() => {
this.$emit('close')
}, 3000)
},
async createShare() {
@ -258,7 +268,9 @@ export default defineComponent({
const shareUrl = generateOcsUrl('apps/files_sharing/api/v1/shares')
try {
const request = await axios.post<OCSResponse>(shareUrl, {
shareType: ShareType.Email,
// Always create a file request, but without mail share
// permissions, only a share link will be created.
shareType: sharingConfig.isMailShareAllowed ? ShareType.Email : ShareType.Link,
permissions: Permission.CREATE,
label: this.label,

View file

@ -4,22 +4,27 @@
*/
import type { Entry, Folder, Node } from '@nextcloud/files'
import { Permission } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import Vue, { defineAsyncComponent } from 'vue'
import FileUploadSvg from '@mdi/svg/svg/file-upload.svg?raw'
import Vue, { defineAsyncComponent } from 'vue'
import Config from '../services/ConfigService'
const NewFileRequestDialogVue = defineAsyncComponent(() => import('../components/NewFileRequestDialog.vue'))
const sharingConfig = new Config()
export const entry = {
id: 'file-request',
displayName: t('files', 'Create new file request'),
iconSvgInline: FileUploadSvg,
order: 30,
enabled(): boolean {
// TODO: determine requirements
// 1. user can share the root folder
// 2. OR user can create subfolders ?
return true
enabled(context: Folder): boolean {
if ((context.permissions & Permission.SHARE) !== 0) {
// We need to have either link shares creation permissions
return sharingConfig.isPublicShareAllowed
}
return false
},
async handler(context: Folder, content: Node[]) {
// Create document root

View file

@ -210,6 +210,13 @@ export default class Config {
return window.OC.appConfig.core.remoteShareAllowed === true
}
/**
* Is public sharing enabled ?
*/
get isPublicShareAllowed(): boolean {
return this._capabilities?.files_sharing?.public?.enabled === true
}
/**
* Is sharing my mail (link share) enabled ?
*/
@ -217,7 +224,7 @@ export default class Config {
// eslint-disable-next-line camelcase
return this._capabilities?.files_sharing?.sharebymail?.enabled === true
// eslint-disable-next-line camelcase
&& this._capabilities?.files_sharing?.public?.enabled === true
&& this.isPublicShareAllowed === true
}
/**