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

Nmc 431-harmonizing of sharing permissions step 2 #28636

Closed
wants to merge 4 commits into from
Closed
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
137 changes: 110 additions & 27 deletions apps/files_sharing/src/components/SharingEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,40 +38,71 @@
<span>{{ share.status.icon || '' }}</span>
<span>{{ share.status.message || '' }}</span>
</p>

<template v-if="share.canEdit">
<!-- folder -->
<template v-if="isFolder && fileHasCreatePermission && config.isPublicUploadEnabled">
<select
:name="randomId"
@change="togglePermissions">
<option :value="publicUploadRValue" :selected="sharePermissions === publicUploadRValue">{{ t('files_sharing', 'Read only') }}</option>
<option :value="publicUploadRWValue" :selected="sharePermissions === publicUploadRWValue">{{ t('files_sharing', 'Allow upload and editing') }}</option>
</select>
</template>
<!-- files -->
<template v-else>
<select
:name="randomId"
@change="togglePermissions">
<option :value="publicUploadRValue" :selected="sharePermissions === publicUploadRValue">{{ t('files_sharing', 'Read only') }}</option>
<option :value="publicUploadEValue" :selected="sharePermissions === publicUploadEValue">{{ t('files_sharing', 'Editing') }}</option>
</select>
</template>
</template>
</component>
<Actions
menu-align="right"
class="sharing-entry__actions"
@close="onMenuClose">
<template v-if="share.canEdit">
<!-- edit permission -->
<ActionCheckbox
ref="canEdit"
:checked.sync="canEdit"
:value="permissionsEdit"
:disabled="saving || !canSetEdit">
{{ t('files_sharing', 'Allow editing') }}
</ActionCheckbox>
<!-- folder -->
<template v-if="isFolder && config.isPublicUploadEnabled">

<!-- create permission -->
<ActionCheckbox
v-if="isFolder"
ref="canCreate"
:checked.sync="canCreate"
:value="permissionsCreate"
:disabled="saving || !canSetCreate">
{{ t('files_sharing', 'Allow creating') }}
</ActionCheckbox>
<ActionRadio :checked="sharePermissions === publicUploadRValue"
:value="publicUploadRValue"
:name="randomId"
:disabled="saving"
@change="togglePermissions">
{{ t('files_sharing', 'Read only') }}
</ActionRadio>

<!-- delete permission -->
<ActionCheckbox
v-if="isFolder"
ref="canDelete"
:checked.sync="canDelete"
:value="permissionsDelete"
:disabled="saving || !canSetDelete">
{{ t('files_sharing', 'Allow deleting') }}
</ActionCheckbox>
<ActionRadio :checked="sharePermissions === publicUploadRWValue"
:value="publicUploadRWValue"
:disabled="saving"
:name="randomId"
@change="togglePermissions">
{{ t('files_sharing', 'Allow upload and editing') }}
</ActionRadio>

</template>
<!-- file -->
<template v-else>
<ActionRadio :checked="sharePermissions === publicUploadRValue"
:value="publicUploadRValue"
:name="randomId"
:disabled="saving"
@change="togglePermissions">
{{ t('files_sharing', 'Read only') }}
</ActionRadio>

<ActionRadio :checked="sharePermissions === publicUploadEValue"
:value="publicUploadEValue"
:disabled="saving"
:name="randomId"
@change="togglePermissions">
{{ t('files_sharing', 'Editing') }}
</ActionRadio>
</template>

<!-- reshare permission -->
<ActionCheckbox
Expand All @@ -84,7 +115,9 @@
</ActionCheckbox>

<!-- expiration date -->
<ActionCheckbox :checked.sync="hasExpirationDate"
<ActionCheckbox
v-if="canHaveExpirationDate"
:checked.sync="hasExpirationDate"
:disabled="config.isDefaultInternalExpireDateEnforced || saving"
@uncheck="onExpirationDisable">
{{ config.isDefaultInternalExpireDateEnforced
Expand Down Expand Up @@ -149,6 +182,7 @@
import Avatar from '@nextcloud/vue/dist/Components/Avatar'
import Actions from '@nextcloud/vue/dist/Components/Actions'
import ActionButton from '@nextcloud/vue/dist/Components/ActionButton'
import ActionRadio from '@nextcloud/vue/dist/Components/ActionRadio'
import ActionCheckbox from '@nextcloud/vue/dist/Components/ActionCheckbox'
import ActionInput from '@nextcloud/vue/dist/Components/ActionInput'
import ActionTextEditable from '@nextcloud/vue/dist/Components/ActionTextEditable'
Expand All @@ -162,6 +196,7 @@ export default {
components: {
Actions,
ActionButton,
ActionRadio,
ActionCheckbox,
ActionInput,
ActionTextEditable,
Expand All @@ -181,10 +216,34 @@ export default {
permissionsDelete: OC.PERMISSION_DELETE,
permissionsRead: OC.PERMISSION_READ,
permissionsShare: OC.PERMISSION_SHARE,

publicUploadRWValue: OC.PERMISSION_UPDATE | OC.PERMISSION_CREATE | OC.PERMISSION_READ | OC.PERMISSION_DELETE,
publicUploadRValue: OC.PERMISSION_READ,
publicUploadWValue: OC.PERMISSION_CREATE | OC.PERMISSION_READ,
publicUploadEValue: OC.PERMISSION_UPDATE | OC.PERMISSION_READ,
}
},

computed: {
/**
* Return the current share permissions
* We always ignore the SHARE permission as this is used for the
* federated sharing.
* @returns {number}
*/
sharePermissions() {
return this.share.permissions & ~OC.PERMISSION_SHARE
},
/**
* Generate a unique random id for this SharingEntryLink only
* This allows ActionRadios to have the same name prop
* but not to impact others SharingEntryLink
* @returns {string}
*/
randomId() {
return Math.random().toString(27).substr(2)
},

title() {
let title = this.share.shareWithDisplayName
if (this.share.type === this.SHARE_TYPES.SHARE_TYPE_GROUP) {
Expand Down Expand Up @@ -225,6 +284,10 @@ export default {
return !this.isRemote
},

canHaveExpirationDate() {
return !this.isRemoteShare
},

isRemote() {
return this.share.type === this.SHARE_TYPES.SHARE_TYPE_REMOTE
|| this.share.type === this.SHARE_TYPES.SHARE_TYPE_REMOTE_GROUP
Expand Down Expand Up @@ -344,6 +407,15 @@ export default {
return this.fileInfo.type === 'dir'
},

/**
* Does the current file/folder have create permissions
* TODO: move to a proper FileInfo model?
* @returns {boolean}
*/
fileHasCreatePermission() {
return Boolean(this.fileInfo.permissions & OC.PERMISSION_CREATE)
},

/**
* Does the current share have an expiration date
* @returns {boolean}
Expand Down Expand Up @@ -398,6 +470,17 @@ export default {
this.queueUpdate('permissions')
},

/**
* On permissions change
* @param {Event} event js event
*/
togglePermissions(event) {
const permissions = parseInt(event.target.value, 10)
| (this.canReshare ? this.permissionsShare : 0)
this.share.permissions = permissions
this.queueUpdate('permissions')
},

/**
* Save potential changed data on menu close
*/
Expand Down
61 changes: 55 additions & 6 deletions apps/files_sharing/src/components/SharingEntryLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@
<p v-if="subtitle">
{{ subtitle }}
</p>

<template v-if="share">
<template v-if="share.canEdit">
<!-- folder -->
<template v-if="isFolder && fileHasCreatePermission && config.isPublicUploadEnabled">
<select
:name="randomId"
@change="togglePermissions">
<option :value="publicUploadRValue" :selected="sharePermissions === publicUploadRValue">{{ t('files_sharing', 'Read only') }}</option>
<option :value="publicUploadRWValue" :selected="sharePermissions === publicUploadRWValue">{{ t('files_sharing', 'Allow upload and editing') }}</option>
<option :value="publicUploadWValue" :selected="sharePermissions === publicUploadWValue">{{ t('files_sharing', 'File drop (upload only)') }}</option>
</select>
</template>

<!-- file -->
<template v-else>
<select
:name="randomId"
@change="togglePermissions">
<option :value="publicUploadRValue" :selected="sharePermissions === publicUploadRValue">{{ t('files_sharing', 'Read only') }}</option>
<option :value="publicUploadEValue" :selected="sharePermissions === publicUploadEValue">{{ t('files_sharing', 'Editing') }}</option>
</select>
</template>
</template>
</template>
</div>

<!-- clipboard -->
Expand Down Expand Up @@ -178,12 +203,23 @@
</template>

<!-- file -->
<ActionCheckbox v-else
:checked.sync="canUpdate"
:disabled="saving"
@change="queueUpdate('permissions')">
{{ t('files_sharing', 'Allow editing') }}
</ActionCheckbox>
<template v-else>
<ActionRadio :checked="sharePermissions === publicUploadRValue"
:value="publicUploadRValue"
:name="randomId"
:disabled="saving"
@change="togglePermissions">
{{ t('files_sharing', 'Read only') }}
</ActionRadio>

<ActionRadio :checked="sharePermissions === publicUploadEValue"
:value="publicUploadEValue"
:disabled="saving"
:name="randomId"
@change="togglePermissions">
{{ t('files_sharing', 'Editing') }}
</ActionRadio>
</template>

<ActionCheckbox
:checked.sync="share.hideDownload"
Expand Down Expand Up @@ -380,6 +416,7 @@ export default {
publicUploadRWValue: OC.PERMISSION_UPDATE | OC.PERMISSION_CREATE | OC.PERMISSION_READ | OC.PERMISSION_DELETE,
publicUploadRValue: OC.PERMISSION_READ,
publicUploadWValue: OC.PERMISSION_CREATE,
publicUploadEValue: OC.PERMISSION_UPDATE | OC.PERMISSION_READ,

ExternalLinkActions: OCA.Sharing.ExternalLinkActions.state,
}
Expand Down Expand Up @@ -575,6 +612,18 @@ export default {
},
},

/**
* Can the sharee edit the shared file ?
*/
canEdit: {
get() {
return this.share.hasUpdatePermission
},
set(checked) {
this.updatePermissions({ isEditChecked: checked })
},
},

// if newPassword exists, but is empty, it means
// the user deleted the original password
hasUnsavedPassword() {
Expand Down