Skip to content

Commit

Permalink
Improve share logic for enforced password & expiry date
Browse files Browse the repository at this point in the history
* It's possible for the admin to enforce and expiry date after, some
 shares have been created. This commit makes possible to update the
 share with the new admin constraints.

* This commit would users to modify enforced expiry to anything within
 range and less than the enforced limit in the pre-create dialog for public
 shares.

* This commit fixes, unable to update share without updating password.

Signed-off-by: fenn-cs <[email protected]>
  • Loading branch information
nfebe committed Nov 30, 2023
1 parent fe35710 commit b84bcde
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 31 deletions.
10 changes: 2 additions & 8 deletions apps/files_sharing/src/components/SharingEntryLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@
</NcActionText>
<NcActionInput v-if="pendingExpirationDate"
class="share-link-expire-date"
:disabled="saving || isExpiryDateEnforced"
:disabled="saving"
:is-native-picker="true"
:hide-label="true"
:value="new Date(share.expireDate)"
type="date"
:min="dateTomorrow"
:max="dateMaxEnforced"
:max="maxExpirationDateEnforced"
@input="onExpirationChange">
<!-- let's not submit when picked, the user
might want to still edit or copy the password -->
Expand Down Expand Up @@ -302,12 +302,6 @@ export default {
}
return null
},
dateMaxEnforced() {
if (this.config.isDefaultExpireDateEnforced) {
return new Date(new Date().setDate(new Date().getDate() + this.config.defaultExpireDate))
}
return null
},
/**
* Is the current share password protected ?
*
Expand Down
16 changes: 16 additions & 0 deletions apps/files_sharing/src/mixins/SharesMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ export default {
const shareType = this.share.shareType ?? this.share.type
return [this.SHARE_TYPES.SHARE_TYPE_LINK, this.SHARE_TYPES.SHARE_TYPE_EMAIL].includes(shareType)
},
isRemoteShare() {
return this.share.type === this.SHARE_TYPES.SHARE_TYPE_REMOTE_GROUP || this.share.type === this.SHARE_TYPES.SHARE_TYPE_REMOTE
},
isShareOwner() {
return this.share && this.share.owner === getCurrentUser().uid
},
Expand All @@ -152,6 +155,19 @@ export default {
]
return !bundledPermissions.includes(this.share.permissions)
},
maxExpirationDateEnforced() {
if (this.isExpiryDateEnforced) {
if (this.isPublicShare) {
return this.config.defaultExpirationDate
}
if (this.isRemoteShare) {
return this.config.defaultRemoteExpirationDateString
}
// If it get's here then it must be an internal share
return this.config.defaultInternalExpirationDate
}
return null
},
},

methods: {
Expand Down
138 changes: 115 additions & 23 deletions apps/files_sharing/src/views/SharingDetailsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<h1>{{ title }}</h1>
</span>
</div>
<<<<<<< HEAD
<div class="sharingTabDetailsView__quick-permissions">
<div>
<NcCheckboxRadioSwitch :button-variant="true"
Expand All @@ -37,6 +38,81 @@
<EditIcon :size="20" />
<template v-if="allowsFileDrop">
<span>{{ t('files_sharing', 'Allow upload and editing') }}</span>
=======
<div class="sharingTabDetailsView__wrapper">
<div ref="quickPermissions"
class="sharingTabDetailsView__quick-permissions">
<div>
<NcCheckboxRadioSwitch :button-variant="true"
:checked.sync="sharingPermission"
:value="bundledPermissions.READ_ONLY.toString()"
name="sharing_permission_radio"
type="radio"
button-variant-grouped="vertical"
@update:checked="toggleCustomPermissions">
{{ t('files_sharing', 'View only') }}
<template #icon>
<ViewIcon :size="20" />
</template>
</NcCheckboxRadioSwitch>
<NcCheckboxRadioSwitch :button-variant="true"
:checked.sync="sharingPermission"
:value="bundledPermissions.ALL.toString()"
name="sharing_permission_radio"
type="radio"
button-variant-grouped="vertical"
@update:checked="toggleCustomPermissions">
<template v-if="allowsFileDrop">
{{ t('files_sharing', 'Allow upload and editing') }}
</template>
<template v-else>
{{ t('files_sharing', 'Allow editing') }}
</template>
<template #icon>
<EditIcon :size="20" />
</template>
</NcCheckboxRadioSwitch>
<NcCheckboxRadioSwitch v-if="allowsFileDrop"
:button-variant="true"
:checked.sync="sharingPermission"
:value="bundledPermissions.FILE_DROP.toString()"
name="sharing_permission_radio"
type="radio"
button-variant-grouped="vertical"
@update:checked="toggleCustomPermissions">
{{ t('files_sharing', 'File drop') }}
<small>{{ t('files_sharing', 'Upload only') }}</small>
<template #icon>
<UploadIcon :size="20" />
</template>
</NcCheckboxRadioSwitch>
<NcCheckboxRadioSwitch :button-variant="true"
:checked.sync="sharingPermission"
:value="'custom'"
name="sharing_permission_radio"
type="radio"
button-variant-grouped="vertical"
@update:checked="expandCustomPermissions">
{{ t('files_sharing', 'Custom permissions') }}
<small>{{ customPermissionsList }}</small>
<template #icon>
<DotsHorizontalIcon :size="20" />
</template>
</NcCheckboxRadioSwitch>
</div>
</div>
<div class="sharingTabDetailsView__advanced-control">
<NcButton id="advancedSectionAccordionAdvancedControl"
type="tertiary"
alignment="end-reverse"
aria-controls="advancedSectionAccordionAdvanced"
:aria-expanded="advancedControlExpandedValue"
@click="advancedSectionAccordionExpanded = !advancedSectionAccordionExpanded">
{{ t('files_sharing', 'Advanced settings') }}
<template #icon>
<MenuDownIcon v-if="!advancedSectionAccordionExpanded" />
<MenuUpIcon v-else />
>>>>>>> 9d86a0444da (Improve share logic for enforced password & expiry date)
</template>
<template v-else>
<span>{{ t('files_sharing', 'Allow editing') }}</span>
Expand Down Expand Up @@ -66,6 +142,7 @@
<small>{{ customPermissionsList }}</small>
</NcCheckboxRadioSwitch>
</div>
<<<<<<< HEAD
</div>
<div class="sharingTabDetailsView__advanced-control">
<NcButton type="tertiary"
Expand Down Expand Up @@ -94,6 +171,29 @@
:required="isPasswordEnforced"
:label="t('files_sharing', 'Password')"
@update:value="onPasswordChange" />
=======
<div v-if="advancedSectionAccordionExpanded"
id="advancedSectionAccordionAdvanced"
class="sharingTabDetailsView__advanced"
aria-labelledby="advancedSectionAccordionAdvancedControl"
role="region">
<section>
<NcInputField v-if="isPublicShare"
:value.sync="share.label"
type="text"
:label="t('files_sharing', 'Share label')" />
<template v-if="isPublicShare">
<NcCheckboxRadioSwitch :checked.sync="isPasswordProtected" :disabled="isPasswordEnforced">
{{ t('files_sharing', 'Set password') }}
</NcCheckboxRadioSwitch>
<NcInputField v-if="isPasswordProtected"
:type="hasUnsavedPassword ? 'text' : 'password'"
:value="hasUnsavedPassword ? share.newPassword : '***************'"
:error="passwordError"
:required="isPasswordEnforced"
:label="t('files_sharing', 'Password')"
@update:value="onPasswordChange" />
>>>>>>> 9d86a0444da (Improve share logic for enforced password & expiry date)

<!-- Migrate icons and remote -> icon="icon-info"-->
<span v-if="isEmailShareType && passwordExpirationTime" icon="icon-info">
Expand Down Expand Up @@ -401,19 +501,6 @@ export default {
isFolder() {
return this.fileInfo.type === 'dir'
},
maxExpirationDateEnforced() {
if (this.isExpiryDateEnforced) {
if (this.isPublicShare) {
return this.config.defaultExpirationDate
}
if (this.isRemoteShare) {
return this.config.defaultRemoteExpirationDateString
}
// If it get's here then it must be an internal share
return this.config.defaultInternalExpirationDate
}
return null
},
/**
* @return {boolean}
*/
Expand Down Expand Up @@ -452,9 +539,6 @@ export default {
isGroupShare() {
return this.share.type === this.SHARE_TYPES.SHARE_TYPE_GROUP
},
isRemoteShare() {
return this.share.type === this.SHARE_TYPES.SHARE_TYPE_REMOTE_GROUP || this.share.type === this.SHARE_TYPES.SHARE_TYPE_REMOTE
},
isNewShare() {
return this.share.id === null || this.share.id === undefined
},
Expand Down Expand Up @@ -626,6 +710,12 @@ export default {
: translatedPermissions[permission].toLocaleLowerCase(getLanguage()))
.join(', ')
},
<<<<<<< HEAD
=======
advancedControlExpandedValue() {
return this.advancedSectionAccordionExpanded ? 'true' : 'false'
},
>>>>>>> 9d86a0444da (Improve share logic for enforced password & expiry date)
},
watch: {
setCustomPermissions(isChecked) {
Expand Down Expand Up @@ -698,6 +788,12 @@ export default {
return
}
// If there is an enforced expiry date, then existing shares created before enforcement
// have no expiry date, hence we set it here.
if (!this.isValidShareAttribute(this.share.expireDate) && this.isExpiryDateEnforced) {
this.hasExpirationDate = true
}
if (
this.isValidShareAttribute(this.share.password)
|| this.isValidShareAttribute(this.share.expireDate)
Expand Down Expand Up @@ -753,16 +849,12 @@ export default {
if (!this.writeNoteToRecipientIsChecked) {
this.share.note = ''
}
if (this.isPasswordProtected) {
if (this.isValidShareAttribute(this.share.newPassword)) {
if (this.hasUnsavedPassword && this.isValidShareAttribute(this.share.newPassword)) {
this.share.password = this.share.newPassword
this.$delete(this.share, 'newPassword')
} else {
if (this.isPasswordEnforced) {
this.passwordError = true
return
}
} else if (this.isPasswordEnforced && !this.isValidShareAttribute(this.share.password)) {
this.passwordError = true
}
} else {
this.share.password = ''
Expand Down

0 comments on commit b84bcde

Please sign in to comment.