Skip to content

Commit 9d86a04

Browse files
nfebeAndyScherzinger
authored andcommitted
Improve share logic for enforced password & expiry date
* 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]>
1 parent bcc1d57 commit 9d86a04

File tree

3 files changed

+35
-36
lines changed

3 files changed

+35
-36
lines changed

apps/files_sharing/src/components/SharingEntryLink.vue

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@
9595
</NcActionText>
9696
<NcActionInput v-if="pendingExpirationDate"
9797
class="share-link-expire-date"
98-
:disabled="saving || isExpiryDateEnforced"
98+
:disabled="saving"
9999
:is-native-picker="true"
100100
:hide-label="true"
101101
:value="new Date(share.expireDate)"
102102
type="date"
103103
:min="dateTomorrow"
104-
:max="dateMaxEnforced"
104+
:max="maxExpirationDateEnforced"
105105
@input="onExpirationChange">
106106
<!-- let's not submit when picked, the user
107107
might want to still edit or copy the password -->
@@ -300,12 +300,6 @@ export default {
300300
}
301301
return null
302302
},
303-
dateMaxEnforced() {
304-
if (this.config.isDefaultExpireDateEnforced) {
305-
return new Date(new Date().setDate(new Date().getDate() + this.config.defaultExpireDate))
306-
}
307-
return null
308-
},
309303
/**
310304
* Is the current share password protected ?
311305
*

apps/files_sharing/src/mixins/SharesMixin.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ export default {
132132
const shareType = this.share.shareType ?? this.share.type
133133
return [this.SHARE_TYPES.SHARE_TYPE_LINK, this.SHARE_TYPES.SHARE_TYPE_EMAIL].includes(shareType)
134134
},
135+
isRemoteShare() {
136+
return this.share.type === this.SHARE_TYPES.SHARE_TYPE_REMOTE_GROUP || this.share.type === this.SHARE_TYPES.SHARE_TYPE_REMOTE
137+
},
135138
isShareOwner() {
136139
return this.share && this.share.owner === getCurrentUser().uid
137140
},
@@ -152,6 +155,19 @@ export default {
152155
]
153156
return !bundledPermissions.includes(this.share.permissions)
154157
},
158+
maxExpirationDateEnforced() {
159+
if (this.isExpiryDateEnforced) {
160+
if (this.isPublicShare) {
161+
return this.config.defaultExpirationDate
162+
}
163+
if (this.isRemoteShare) {
164+
return this.config.defaultRemoteExpirationDateString
165+
}
166+
// If it get's here then it must be an internal share
167+
return this.config.defaultInternalExpirationDate
168+
}
169+
return null
170+
},
155171
},
156172

157173
methods: {

apps/files_sharing/src/views/SharingDetailsTab.vue

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@
7878
</div>
7979
</div>
8080
<div class="sharingTabDetailsView__advanced-control">
81-
<NcButton type="tertiary"
82-
id="advancedSectionAccordionAdvancedControl"
81+
<NcButton id="advancedSectionAccordionAdvancedControl"
82+
type="tertiary"
8383
alignment="end-reverse"
8484
aria-controls="advancedSectionAccordionAdvanced"
8585
:aria-expanded="advancedControlExpandedValue"
@@ -91,8 +91,11 @@
9191
</template>
9292
</NcButton>
9393
</div>
94-
<div v-if="advancedSectionAccordionExpanded" id="advancedSectionAccordionAdvanced" class="sharingTabDetailsView__advanced"
95-
aria-labelledby="advancedSectionAccordionAdvancedControl" role="region">
94+
<div v-if="advancedSectionAccordionExpanded"
95+
id="advancedSectionAccordionAdvanced"
96+
class="sharingTabDetailsView__advanced"
97+
aria-labelledby="advancedSectionAccordionAdvancedControl"
98+
role="region">
9699
<section>
97100
<NcInputField v-if="isPublicShare"
98101
:value.sync="share.label"
@@ -427,19 +430,6 @@ export default {
427430
isFolder() {
428431
return this.fileInfo.type === 'dir'
429432
},
430-
maxExpirationDateEnforced() {
431-
if (this.isExpiryDateEnforced) {
432-
if (this.isPublicShare) {
433-
return this.config.defaultExpirationDate
434-
}
435-
if (this.isRemoteShare) {
436-
return this.config.defaultRemoteExpirationDateString
437-
}
438-
// If it get's here then it must be an internal share
439-
return this.config.defaultInternalExpirationDate
440-
}
441-
return null
442-
},
443433
/**
444434
* @return {boolean}
445435
*/
@@ -478,9 +468,6 @@ export default {
478468
isGroupShare() {
479469
return this.share.type === this.SHARE_TYPES.SHARE_TYPE_GROUP
480470
},
481-
isRemoteShare() {
482-
return this.share.type === this.SHARE_TYPES.SHARE_TYPE_REMOTE_GROUP || this.share.type === this.SHARE_TYPES.SHARE_TYPE_REMOTE
483-
},
484471
isNewShare() {
485472
return this.share.id === null || this.share.id === undefined
486473
},
@@ -654,7 +641,7 @@ export default {
654641
},
655642
advancedControlExpandedValue() {
656643
return this.advancedSectionAccordionExpanded ? 'true' : 'false'
657-
}
644+
},
658645
},
659646
watch: {
660647
setCustomPermissions(isChecked) {
@@ -731,6 +718,12 @@ export default {
731718
return
732719
}
733720
721+
// If there is an enforced expiry date, then existing shares created before enforcement
722+
// have no expiry date, hence we set it here.
723+
if (!this.isValidShareAttribute(this.share.expireDate) && this.isExpiryDateEnforced) {
724+
this.hasExpirationDate = true
725+
}
726+
734727
if (
735728
this.isValidShareAttribute(this.share.password)
736729
|| this.isValidShareAttribute(this.share.expireDate)
@@ -786,16 +779,12 @@ export default {
786779
if (!this.writeNoteToRecipientIsChecked) {
787780
this.share.note = ''
788781
}
789-
790782
if (this.isPasswordProtected) {
791-
if (this.isValidShareAttribute(this.share.newPassword)) {
783+
if (this.hasUnsavedPassword && this.isValidShareAttribute(this.share.newPassword)) {
792784
this.share.password = this.share.newPassword
793785
this.$delete(this.share, 'newPassword')
794-
} else {
795-
if (this.isPasswordEnforced) {
796-
this.passwordError = true
797-
return
798-
}
786+
} else if (this.isPasswordEnforced && !this.isValidShareAttribute(this.share.password)) {
787+
this.passwordError = true
799788
}
800789
} else {
801790
this.share.password = ''

0 commit comments

Comments
 (0)