Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(password-protected-folders): add permissions dropdown #12141

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Password protected folder permissions

We've added the permissions dropdown into the create password protected folder dialog. Users can now decide what permissions they would like to add to the folder. Permissions are matching folder public link permissions.

https://github.com/owncloud/web/pull/12141
https://github.com/owncloud/web/issues/12039
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,28 @@
:label="$gettext('Password')"
class="oc-mt-s"
/>

<div class="oc-flex oc-flex-middle oc-mt-m">
<oc-icon class="oc-mr-s" :name="selectedTypeIcon" fill-type="line" />
<link-role-dropdown
id="input-folder-permissions"
v-model="formData.selectedType"
:available-link-type-options="availableLinkTypes"
/>
</div>

<input type="submit" class="oc-hidden" />
</form>
</template>

<script lang="ts" setup>
import { useMessages, useResourcesStore, useSpacesStore } from '@ownclouders/web-pkg'
import {
LinkRoleDropdown,
useLinkTypes,
useMessages,
useResourcesStore,
useSpacesStore
} from '@ownclouders/web-pkg'
import { computed, reactive, unref, watch } from 'vue'
import { useGettext } from 'vue3-gettext'
import { useCreateFileHandler } from '../composables/useCreateFileHandler'
Expand All @@ -32,13 +48,17 @@ const { showErrorMessage } = useMessages()
const { createFileHandler } = useCreateFileHandler()
const { currentFolder } = useResourcesStore()
const { currentSpace } = useSpacesStore()
const { defaultLinkType, getAvailableLinkTypes, getLinkRoleByType } = useLinkTypes()

const formData = reactive({
folderName: '',
password: ''
password: '',
selectedType: unref(defaultLinkType)
})

const isFormValid = computed(() => formData.folderName !== '' && formData.password !== '')
const availableLinkTypes = computed(() => getAvailableLinkTypes({ isFolder: true }))
const selectedTypeIcon = computed(() => getLinkRoleByType(formData.selectedType).icon)

const onConfirm = async () => {
if (!unref(isFormValid)) {
Expand All @@ -50,7 +70,8 @@ const onConfirm = async () => {
fileName: formData.folderName,
currentFolder: unref(currentFolder),
space: unref(currentSpace),
password: formData.password
password: formData.password,
type: formData.selectedType
})
} catch (error) {
console.error(error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ export const useCreateFileHandler = () => {
fileName,
space,
currentFolder,
password
password,
type
}: {
fileName: string
space: SpaceResource
currentFolder: Resource
password: string
type: SharingLinkType
}) => {
if (fileName === '') {
return
Expand All @@ -32,7 +34,7 @@ export const useCreateFileHandler = () => {
clientService,
space,
resource: folder,
options: { password, type: SharingLinkType.Edit }
options: { password, type }
})

const path = urlJoin(currentFolder.path, fileName + '.psec')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useCreateFileHandler } from '../../../src/composables/useCreateFileHand
import { mock } from 'vitest-mock-extended'
import { Resource, SpaceResource } from '@ownclouders/web-client'
import { VueWrapper } from '@vue/test-utils'
import { SharingLinkType } from '@ownclouders/web-client/graph/generated'

vi.mock('../../../src/composables/useCreateFileHandler', () => ({
useCreateFileHandler: vi.fn().mockReturnValue({ createFileHandler: vi.fn() })
Expand All @@ -14,7 +15,8 @@ const currentSpace = mock<SpaceResource>()

const SELECTORS = Object.freeze({
inputFolderName: '#input-folder-name',
inputFolderPassword: '#input-folder-password'
inputFolderPassword: '#input-folder-password',
inputFolderPermissions: '#input-folder-permissions'
})

describe('CreateFolderModal', () => {
Expand All @@ -23,17 +25,20 @@ describe('CreateFolderModal', () => {

const folderNameInput = wrapper.findComponent(SELECTORS.inputFolderName) as VueWrapper
const passwordInput = wrapper.findComponent(SELECTORS.inputFolderPassword) as VueWrapper
const permissionsInput = wrapper.findComponent(SELECTORS.inputFolderPermissions) as VueWrapper

folderNameInput.vm.$emit('update:modelValue', 'name')
passwordInput.vm.$emit('update:modelValue', 'password')
permissionsInput.vm.$emit('update:modelValue', SharingLinkType.Edit)

wrapper.vm.onConfirm()

expect(useCreateFileHandler().createFileHandler).toHaveBeenCalledWith({
fileName: 'name',
password: 'password',
space: currentSpace,
currentFolder
currentFolder,
type: SharingLinkType.Edit
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ describe('createFileHandler', () => {
fileName: 'protected',
space,
currentFolder,
password: 'Pass$123'
password: 'Pass$123',
type: SharingLinkType.Edit
})

expect(mocks.$clientService.webdav.createFolder).toHaveBeenCalledWith(space, {
Expand Down