Skip to content

Commit 0fe0b30

Browse files
committed
feat: warning for folders public links
- only for folders with RW permissions - modal or div, based on if it was created or updated - alert message defined in config store by language - check if message exists before showing
1 parent d5d4086 commit 0fe0b30

File tree

5 files changed

+63
-7
lines changed

5 files changed

+63
-7
lines changed

packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue

+24-1
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,15 @@ export default defineComponent({
128128
return canShare({ space: unref(space), resource: unref(resource) })
129129
})
130130
131+
const language = useGettext()
132+
131133
const sharesStore = useSharesStore()
132134
const { updateLink, deleteLink } = sharesStore
133135
const { linkShares } = storeToRefs(sharesStore)
134136
135137
const configStore = useConfigStore()
136138
const { options: configOptions } = storeToRefs(configStore)
139+
const alertRwFolders = configStore.options.alertRwFolders
137140
138141
const { actions: createLinkActions } = useFileActionsCreateLink()
139142
const createLinkAction = computed<FileAction>(() =>
@@ -225,8 +228,23 @@ export default defineComponent({
225228
resource: unref(resource),
226229
linkShare,
227230
options
231+
}).then(() => {
232+
showMessage({ title: $gettext('Link was updated successfully') })
228233
})
229-
showMessage({ title: $gettext('Link was updated successfully') })
234+
if (options.type === 'edit' && unref(resource).isFolder && alertRwFolders) {
235+
if (!document.getElementById('files-file-link-warning')) {
236+
const warningMessage = document.createElement('div')
237+
warningMessage.className = 'oc-mb-m oc-p-s oc-background-secondary oc-rounded'
238+
warningMessage.id = 'files-file-link-warning'
239+
warningMessage.innerHTML = $gettext(
240+
alertRwFolders[language.current] ?? alertRwFolders[Object.keys(alertRwFolders)[0]]
241+
)
242+
document.getElementById('files-links-list').parentElement.prepend(warningMessage)
243+
setTimeout(() => {
244+
warningMessage.remove()
245+
}, 10000)
246+
}
247+
}
230248
} catch (e) {
231249
console.error(e)
232250
showErrorMessage({
@@ -376,4 +394,9 @@ export default defineComponent({
376394
margin-top: var(--oc-space-medium);
377395
}
378396
}
397+
#files-file-link-warning {
398+
color: var(--oc-color-swatch-danger-default);
399+
text-align: center;
400+
border: solid 1px var(--oc-color-swatch-danger-muted);
401+
}
379402
</style>

packages/web-pkg/src/components/CreateLinkModal.vue

+9-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
appearance="filled"
7575
variation="primary"
7676
:disabled="confirmButtonDisabled"
77-
@click="$emit('confirm')"
77+
@click="$emit('confirm', { isRW: selectedType === 'edit', isFolder })"
7878
>{{ confirmButtonText }}
7979
</oc-button>
8080
<oc-button
@@ -99,7 +99,13 @@
9999
<oc-button
100100
class="oc-modal-body-actions-confirm-password action-menu-item"
101101
appearance="raw"
102-
@click="$emit('confirm', { copyPassword: true })"
102+
@click="
103+
$emit('confirm', {
104+
copyPassword: true,
105+
isRW: selectedType === 'edit',
106+
isFolder
107+
})
108+
"
103109
>{{ $gettext('Copy link and password') }}
104110
</oc-button>
105111
</li>
@@ -347,6 +353,7 @@ export default defineComponent({
347353
setAdvancedMode,
348354
onExpiryDateChanged,
349355
confirmButtonDisabled,
356+
isFolder,
350357
DateTime,
351358
sharingPublicExpireDateMaxRWFolders,
352359

packages/web-pkg/src/composables/actions/files/useFileActionsCreateLink.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
useModals,
1212
useUserStore,
1313
useCapabilityStore,
14-
useSharesStore
14+
useSharesStore,
15+
useConfigStore
1516
} from '../../piniaStores'
1617
import { useClipboard } from '../../clipboard'
1718
import { useClientService } from '../../clientService'
@@ -32,6 +33,7 @@ export const useFileActionsCreateLink = ({
3233
const { addLink } = useSharesStore()
3334
const { dispatchModal } = useModals()
3435
const { copyToClipboard } = useClipboard()
36+
const configStore = useConfigStore()
3537

3638
const proceedResult = async ({
3739
result,
@@ -40,7 +42,7 @@ export const useFileActionsCreateLink = ({
4042
}: {
4143
result: PromiseSettledResult<LinkShare>[]
4244
password?: string
43-
options?: { copyPassword?: boolean }
45+
options?: { isRW?: boolean; isFolder?: boolean; copyPassword?: boolean }
4446
}) => {
4547
const succeeded = result.filter(
4648
(val): val is PromiseFulfilledResult<LinkShare> => val.status === 'fulfilled'
@@ -70,6 +72,20 @@ export const useFileActionsCreateLink = ({
7072
}
7173
}
7274

75+
const language = useGettext()
76+
const alertRwFolders = configStore.options.alertRwFolders
77+
78+
if (options.isRW && options.isFolder && alertRwFolders) {
79+
dispatchModal({
80+
variation: 'warning',
81+
title: 'Default expiration date',
82+
message: $gettext(
83+
alertRwFolders[language.current] ?? alertRwFolders[Object.keys(alertRwFolders)[0]]
84+
),
85+
confirmText: 'Got it'
86+
})
87+
}
88+
7389
showMessage({
7490
title: $ngettext(successMessage, 'Links have been created successfully.', succeeded.length)
7591
})

packages/web-pkg/src/composables/piniaStores/config/config.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ const defaultOptions = {
3737
runningOnEos: false,
3838
tokenStorageLocal: true,
3939
userListRequiresFilter: false,
40-
hideLogo: false
40+
hideLogo: false,
41+
alertRwFolders: {
42+
en: '',
43+
fr: ''
44+
}
4145
} satisfies Partial<OptionsConfig>
4246

4347
export const useConfigStore = defineStore('config', () => {

packages/web-pkg/src/composables/piniaStores/config/types.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,13 @@ const OptionsConfigSchema = z.object({
126126
hideAppSwitcher: z.boolean().optional(),
127127
hideAccountMenu: z.boolean().optional(),
128128
hideNavigation: z.boolean().optional(),
129-
defaultLanguage: z.string().optional()
129+
defaultLanguage: z.string().optional(),
130+
alertRwFolders: z
131+
.object({
132+
en: z.string().optional(),
133+
fr: z.string().optional()
134+
})
135+
.optional()
130136
})
131137

132138
export type OptionsConfig = z.infer<typeof OptionsConfigSchema>

0 commit comments

Comments
 (0)