Skip to content
Prev Previous commit
Next Next commit
Fixed the rectified issues and cleaned up the code
Signed-off-by: Yogesh Shejwadkar <[email protected]>
  • Loading branch information
TSI-yogeshshejwadkar committed Feb 9, 2022
commit 6fc67ca995b5b85874ac131d7c5a7393ade31c20
29 changes: 28 additions & 1 deletion apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ public function deleteShare(string $id): DataResponse {
* @param string $sendPasswordByTalk
* @param string $expireDate
* @param string $label
* @param string $hideDownload
*
* @return DataResponse
* @throws NotFoundException
Expand All @@ -449,7 +450,8 @@ public function createShare(
string $password = '',
string $sendPasswordByTalk = null,
string $expireDate = '',
string $label = ''
string $label = '',
string $hideDownload = null
): DataResponse {
$share = $this->shareManager->newShare();

Expand Down Expand Up @@ -506,6 +508,15 @@ public function createShare(
}
$share->setSharedWith($shareWith);
$share->setPermissions($permissions);

if ($expireDate !== '') {
try {
$expireDate = $this->parseDate($expireDate);
$share->setExpirationDate($expireDate);
} catch (\Exception $e) {
throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
}
}
} elseif ($shareType === IShare::TYPE_GROUP) {
if (!$this->shareManager->allowGroupSharing()) {
throw new OCSNotFoundException($this->l->t('Group sharing is disabled by the administrator'));
Expand All @@ -517,6 +528,15 @@ public function createShare(
}
$share->setSharedWith($shareWith);
$share->setPermissions($permissions);

if ($expireDate !== '') {
try {
$expireDate = $this->parseDate($expireDate);
$share->setExpirationDate($expireDate);
} catch (\Exception $e) {
throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
}
}
} elseif ($shareType === IShare::TYPE_LINK
|| $shareType === IShare::TYPE_EMAIL) {

Expand Down Expand Up @@ -544,6 +564,13 @@ public function createShare(
$permissions = Constants::PERMISSION_READ;
}

// Update hide download state
if ($hideDownload === 'true') {
$share->setHideDownload(true);
} elseif ($hideDownload === 'false') {
$share->setHideDownload(false);
}

// TODO: It might make sense to have a dedicated setting to allow/deny converting link shares into federated ones
if (($permissions & Constants::PERMISSION_READ) && $this->shareManager->outgoingServer2ServerSharesAllowed()) {
$permissions |= Constants::PERMISSION_SHARE;
Expand Down
79 changes: 0 additions & 79 deletions apps/files_sharing/src/components/SharingEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,63 +166,11 @@ export default {
return null
},

canHaveNote() {
return !this.isRemote
},

isRemote() {
return this.share.type === this.SHARE_TYPES.SHARE_TYPE_REMOTE
|| this.share.type === this.SHARE_TYPES.SHARE_TYPE_REMOTE_GROUP
},

/**
* Can the sharer set whether the sharee can edit the file ?
*
* @returns {boolean}
*/
canSetEdit() {
// If the owner revoked the permission after the resharer granted it
// the share still has the permission, and the resharer is still
// allowed to revoke it too (but not to grant it again).
return (this.fileInfo.sharePermissions & OC.PERMISSION_UPDATE) || this.canEdit
},

/**
* Can the sharer set whether the sharee can create the file ?
*
* @returns {boolean}
*/
canSetCreate() {
// If the owner revoked the permission after the resharer granted it
// the share still has the permission, and the resharer is still
// allowed to revoke it too (but not to grant it again).
return (this.fileInfo.sharePermissions & OC.PERMISSION_CREATE) || this.canCreate
},

/**
* Can the sharer set whether the sharee can delete the file ?
*
* @returns {boolean}
*/
canSetDelete() {
// If the owner revoked the permission after the resharer granted it
// the share still has the permission, and the resharer is still
// allowed to revoke it too (but not to grant it again).
return (this.fileInfo.sharePermissions & OC.PERMISSION_DELETE) || this.canDelete
},

/**
* Can the sharer set whether the sharee can reshare the file ?
*
* @returns {boolean}
*/
canSetReshare() {
// If the owner revoked the permission after the resharer granted it
// the share still has the permission, and the resharer is still
// allowed to revoke it too (but not to grant it again).
return (this.fileInfo.sharePermissions & OC.PERMISSION_SHARE) || this.canReshare
},

/**
* Can the sharee edit the shared file ?
*/
Expand Down Expand Up @@ -289,33 +237,6 @@ export default {
return this.fileInfo.type === 'dir'
},

/**
* Does the current share have an expiration date
* @returns {boolean}
*/
// hasExpirationDate: {
// get() {
// return this.config.isDefaultInternalExpireDateEnforced || !!this.share.expireDate
// },
// set(enabled) {
// this.share.expireDate = enabled
// ? this.config.defaultInternalExpirationDateString !== ''
// ? this.config.defaultInternalExpirationDateString
// : moment().format('YYYY-MM-DD')
// : ''
// },
// },

// dateMaxEnforced() {
// if (!this.isRemote) {
// return this.config.isDefaultInternalExpireDateEnforced
// && moment().add(1 + this.config.defaultInternalExpireDate, 'days')
// } else {
// return this.config.isDefaultRemoteExpireDateEnforced
// && moment().add(1 + this.config.defaultRemoteExpireDate, 'days')
// }
// },

/**
* @returns {bool}
*/
Expand Down
134 changes: 0 additions & 134 deletions apps/files_sharing/src/components/SharingEntryLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -309,32 +309,6 @@ export default {
return null
},

/**
* Does the current share have an expiration date
* @returns {boolean}
*/
hasExpirationDate: {
get() {
return this.config.isDefaultExpireDateEnforced
|| !!this.share.expireDate
},
set(enabled) {
let dateString = moment(this.config.defaultExpirationDateString)
if (!dateString.isValid()) {
dateString = moment()
}
this.share.state.expiration = enabled
? dateString.format('YYYY-MM-DD')
: ''
console.debug('Expiration date status', enabled, this.share.expireDate)
},
},

dateMaxEnforced() {
return this.config.isDefaultExpireDateEnforced
&& moment().add(1 + this.config.defaultExpireDate, 'days')
},

/**
* Is the current share password protected ?
* @returns {boolean}
Expand All @@ -351,35 +325,6 @@ export default {
},
},

/**
* Is Talk enabled?
* @returns {boolean}
*/
isTalkEnabled() {
return OC.appswebroots.spreed !== undefined
},

/**
* Is it possible to protect the password by Talk?
* @returns {boolean}
*/
isPasswordProtectedByTalkAvailable() {
return this.isPasswordProtected && this.isTalkEnabled
},

/**
* Is the current share password protected by Talk?
* @returns {boolean}
*/
isPasswordProtectedByTalk: {
get() {
return this.share.sendPasswordByTalk
},
async set(enabled) {
this.share.sendPasswordByTalk = enabled
},
},

/**
* Is the current share an email share ?
* @returns {boolean}
Expand All @@ -390,20 +335,6 @@ export default {
: false
},

canTogglePasswordProtectedByTalkAvailable() {
if (!this.isPasswordProtected) {
// Makes no sense
return false
} else if (this.isEmailShareType && !this.hasUnsavedPassword) {
// For email shares we need a new password in order to enable or
// disable
return false
}

// Anything else should be fine
return true
},

/**
* Pending data.
* If the share still doesn't have an id, it is not synced
Expand All @@ -417,21 +348,6 @@ export default {
return this.config.isDefaultExpireDateEnforced && this.share && !this.share.id
},

/**
* Can the recipient edit the file ?
* @returns {boolean}
*/
canUpdate: {
get() {
return this.share.hasUpdatePermission
},
set(enabled) {
this.share.permissions = enabled
? OC.PERMISSION_READ | OC.PERMISSION_UPDATE
: OC.PERMISSION_READ
},
},

// if newPassword exists, but is empty, it means
// the user deleted the original password
hasUnsavedPassword() {
Expand Down Expand Up @@ -649,24 +565,6 @@ export default {
this.queueUpdate('permissions')
},

/**
* Label changed, let's save it to a different key
* @param {String} label the share label
*/
onLabelChange(label) {
this.$set(this.share, 'newLabel', label.trim())
},

/**
* When the note change, we trim, save and dispatch
*/
onLabelSubmit() {
if (typeof this.share.newLabel === 'string') {
this.share.label = this.share.newLabel
this.$delete(this.share, 'newLabel')
this.queueUpdate('label')
}
},
async copyLink() {
try {
await this.$copyText(this.shareLink)
Expand All @@ -686,19 +584,6 @@ export default {
}
},

/**
* Update newPassword values
* of share. If password is set but not newPassword
* then the user did not changed the password
* If both co-exists, the password have changed and
* we show it in plain text.
* Then on submit (or menu close), we sync it.
* @param {string} password the changed password
*/
onPasswordChange(password) {
this.$set(this.share, 'newPassword', password)
},

/**
* Uncheck password protection
* We need this method because @update:checked
Expand Down Expand Up @@ -733,22 +618,6 @@ export default {
}
},

/**
* Update the password along with "sendPasswordByTalk".
*
* If the password was modified the new password is sent; otherwise
* updating a mail share would fail, as in that case it is required that
* a new password is set when enabling or disabling
* "sendPasswordByTalk".
*/
onPasswordProtectedByTalkChange() {
if (this.hasUnsavedPassword) {
this.share.password = this.share.newPassword.trim()
}

this.queueUpdate('sendPasswordByTalk', 'password')
},

/**
* Save potential changed data on menu close
*/
Expand All @@ -762,9 +631,6 @@ export default {
* Used in the pending popover
*/
onCancel() {
// this.share already exists at this point,
// but is incomplete as not pushed to server
// YET. We can safely delete the share :)
this.$emit('remove:share', this.share)
},

Expand Down
2 changes: 2 additions & 0 deletions apps/files_sharing/src/components/SharingInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ export default {
this.$store.commit('addFromInput', true)
const newShare = new Share({})
newShare.permissions = OC.PERMISSION_READ
newShare.expireDate = ''
newShare.password = ''
this.$store.commit('addShare', newShare)
this.$store.commit('addCurrentTab', 'permissions')
},
Expand Down
Loading