Skip to content

Commit

Permalink
Added expiration date to collaborators
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasHirt committed Feb 27, 2020
1 parent 53c5d4a commit 8979763
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 34 deletions.
8 changes: 5 additions & 3 deletions apps/files/src/components/Collaborators/Collaborator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
(me)
</translate>
</div>
<span class="oc-text"><span class="files-collaborators-collaborator-role">{{ originalRole.label }}</span><template v-if="collaborator.expires"> | <translate :translate-params="{expires: formDateFromNow(collaborator.expires)}">Expires: %{expires}</translate></template></span>
<span class="uk-text-meta files-collaborators-collaborator-share-type" v-text="$_ocCollaborators_collaboratorType(collaborator.shareType)" />
<span class="oc-text"><span class="files-collaborators-collaborator-role">{{ originalRole.label }}</span><template v-if="collaborator.expires"> | <translate :translate-params="{expires: formDateFromNow(collaborator.expires)}">Expires %{expires}</translate></template></span>
</div>
</oc-table-cell>
<oc-table-cell shrink>
Expand Down Expand Up @@ -94,12 +94,14 @@
import { mapGetters } from 'vuex'
import { shareTypes } from '../../helpers/shareTypes'
import { basename, dirname } from 'path'
import Mixins from '../../mixins/collaborators'
import CollaboratorsMixins from '../../mixins/collaborators'
import Mixins from '../../mixins'
export default {
name: 'Collaborator',
mixins: [
Mixins
Mixins,
CollaboratorsMixins
],
props: {
collaborator: {
Expand Down
164 changes: 152 additions & 12 deletions apps/files/src/components/Collaborators/CollaboratorsEditOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,54 @@
:collaboratorsPermissions="collaboratorsPermissions"
@permissionChecked="checkAdditionalPermissions"
/>
<oc-grid v-if="$_ocCollaborators_expirationSupported" gutter="small">
<div class="uk-width-1-1">
<label class="oc-label" for="files-collaborators-new-collaborator-expiration">
<translate>Expiration date</translate>
<translate class="uk-text-meta uk-remove-margin">(optional)</translate>
</label>
<oc-text-input type="date" class="uk-width-1-1 oc-button-role" id="files-collaborators-new-collaborator-expiration" :value="expirationDate">04 - 07 - 2019</oc-text-input>
<div v-if="expirationSupported">
<label for="files-collaborators-collaborator-expiration-input">
<translate>Expiration date:</translate>
<translate v-if="expirationDateEnforced" tag="em">(required)</translate>
</label>
<div class="uk-position-relative">
<oc-datepicker
id="files-collaborators-collaborator-expiration-input"
:key="`collaborator-datepicker-${enteredExpirationDate}`"
:date="enteredExpirationDate"
:maxDatetime="maxExpirationDate"
:minDatetime="minExpirationDate"
:placeholder="expirationDatePlaceholder"
@input="setExpirationDate"
/>
<div
v-if="canResetExpirationDate"
id="files-collaborators-collaborator-expiration-delete"
class="uk-position-small uk-position-center-right oc-cursor-pointer"
:uk-tooltip="expirationDateRemoveTooltip"
@click="resetExpirationDate"
uk-close
/>
</div>
</oc-grid>
</div>
</oc-grid>
</template>

<script>
import { mapGetters } from 'vuex'
import moment from 'moment'
import collaboratorsMixins from '../../mixins/collaborators'
const RolesSelect = () => import('../Roles/RolesSelect.vue')
const AdditionalPermissions = () => import('./AdditionalPermissions.vue')
export default {
name: 'CollaboratorsEditOptions',
components: {
RolesSelect,
AdditionalPermissions
},
mixins: [
collaboratorsMixins
],
props: {
existingRole: {
type: Object,
Expand All @@ -53,17 +74,34 @@ export default {
expirationDate: {
type: String,
required: false
},
existingCollaboratorType: {
type: [Boolean, String],
required: false,
validator: function (value) {
return ['user', 'group'].indexOf(value) > -1
}
}
},
data () {
return {
selectedRole: null,
additionalPermissions: null
additionalPermissions: null,
enteredExpirationDate: null
}
},
computed: {
$_ocCollaborators_expirationSupported () {
return false
...mapGetters(['capabilities']),
editingUser () {
console.log(this.existingCollaboratorType)
return this.existingCollaboratorType === 'user'
},
editingGroup () {
return this.existingCollaboratorType === 'group'
},
$_ocCollaborators_hasAdditionalPermissions () {
Expand Down Expand Up @@ -98,8 +136,96 @@ export default {
}
return this.selectedRole
},
expirationSupported () {
return this.userExpirationDate && this.groupExpirationDate
},
defaultExpirationDateSet () {
if (this.editingUser) {
return this.userExpirationDate.enabled
}
if (this.editingGroup) {
return this.groupExpirationDate.enabled
}
return this.userExpirationDate.enabled && this.groupExpirationDate.enabled
},
userExpirationDate () {
return this.capabilities.files_sharing.user.expire_date
},
groupExpirationDate () {
return this.capabilities.files_sharing.group.expire_date
},
defaultExpirationDate () {
if (!this.defaultExpirationDateSet) {
return null
}
// Since we are not separating process for adding users and groups as collaborators
// we are using the one which is smaller as enforced date
const userMaxExpirationDays = this.editingUser ? parseInt(this.userExpirationDate.days, 10) : null
const groupMaxExpirationDays = this.editingGorup ? parseInt(this.groupExpirationDate.days, 10) : null
if (this.editingUser) {
return moment().add(userMaxExpirationDays, 'days').endOf('day').toISOString()
}
if (this.editingGroup) {
return moment().add(groupMaxExpirationDays, 'days').endOf('day').toISOString()
}
const days = Math.min(userMaxExpirationDays, groupMaxExpirationDays)
return moment().add(days, 'days').endOf('day').toISOString()
},
expirationDateEnforced () {
if (this.editingUser) {
return this.userExpirationDate.enforced
}
if (this.editingGroup) {
return this.groupExpirationDate.enforced
}
return this.userExpirationDate.enforced || this.groupExpirationDate.enforced
},
maxExpirationDate () {
if (!this.expirationDateEnforced) {
return null
}
return this.defaultExpirationDate
},
minExpirationDate () {
return moment().add(1, 'days').endOf('day').toISOString()
},
expirationDatePlaceholder () {
return this.$gettext('Expiration date')
},
expirationDateRemoveTooltip () {
return this.$gettext('Remove expiration date')
},
canResetExpirationDate () {
return !this.expirationDateEnforced && this.enteredExpirationDate
}
},
mounted () {
this.enteredExpirationDate = this.expirationDate ? this.expirationDate : this.defaultExpirationDate
},
methods: {
selectRole (role) {
this.selectedRole = role
Expand All @@ -111,8 +237,22 @@ export default {
this.publishChange()
},
setExpirationDate (date) {
this.enteredExpirationDate = date
this.publishChange()
},
resetExpirationDate () {
this.enteredExpirationDate = null
this.publishChange()
},
publishChange () {
this.$emit('optionChange', { role: this.selectedRole, permissions: this.additionalPermissions, expirationDate: this.expirationDate })
this.$emit('optionChange', {
role: this.selectedRole,
permissions: this.additionalPermissions,
expirationDate: this.enteredExpirationDate
})
}
}
}
Expand Down
38 changes: 36 additions & 2 deletions apps/files/src/components/Collaborators/EditCollaborator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<collaborators-edit-options
:existingRole="$_originalRole"
:collaboratorsPermissions="$_originalPermissions"
:expirationDate="originalExpirationDate"
:existingCollaboratorType="collaboratorType"
@optionChange="collaboratorOptionChanged"
class="uk-margin-bottom"
/>
Expand Down Expand Up @@ -55,13 +57,26 @@ export default {
return {
selectedRole: null,
additionalPermissions: null,
saving: false
saving: false,
expirationDate: null
}
},
computed: {
...mapGetters('Files', ['highlightedFile']),
...mapGetters(['user']),
collaboratorType () {
if (this.collaborator.shareType === 0 || this.collaborator.shareType === 6) {
return 'user'
}
if (this.collaborator.shareType === 1) {
return 'group'
}
return null
},
$_originalPermissions () {
const permissions = this.collaborator.customPermissions
return filterObject(permissions, (key, value) => value)
Expand All @@ -82,8 +97,25 @@ export default {
// if the role has changed, always return true. The user doesn't need to understand if two bitmasks of different roles are the same!
return true
}
if (this.expirationDate && this.expirationDate !== this.originalExpirationDate) {
return true
}
const originalBitmask = roleToBitmask(this.$_originalRole, Object.keys(this.$_originalPermissions))
return originalBitmask !== this.$_permissionsBitmask
},
originalExpirationDate () {
const dateUnixTimestamp = this.collaborator.expires
if (dateUnixTimestamp) {
const date = new Date(dateUnixTimestamp).toISOString()
return date
}
return null
}
},
methods: {
Expand All @@ -100,7 +132,8 @@ export default {
share: this.collaborator,
// Map bitmask to role to get the correct role in case the advanced role was mapped to existing role
role: bitmaskToRole(bitmask, this.highlightedFile.type === 'folder'),
permissions: bitmask
permissions: bitmask,
expirationDate: this.expirationDate
})
.then(() => this.$_ocCollaborators_cancelChanges())
.catch(() => {
Expand All @@ -111,6 +144,7 @@ export default {
$_ocCollaborators_cancelChanges () {
this.selectedRole = null
this.additionalPermissions = null
this.expirationDate = this.originalExpirationDate
this.saving = false
this.close()
},
Expand Down
6 changes: 4 additions & 2 deletions apps/files/src/components/Collaborators/NewCollaborator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export default {
selectedCollaborators: [],
selectedRole: null,
additionalPermissions: null,
saving: false
saving: false,
expirationDate: null
}
},
computed: {
Expand Down Expand Up @@ -209,7 +210,8 @@ export default {
$gettext: this.$gettext,
shareWith: collaborator.value.shareWith,
shareType: collaborator.value.shareType,
permissions: roleToBitmask(this.selectedRole, this.additionalPermissions)
permissions: roleToBitmask(this.selectedRole, this.additionalPermissions),
expirationDate: this.expirationDate
})))
})
Expand Down
3 changes: 2 additions & 1 deletion apps/files/src/mixins/collaborators.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ export default {

return this.$gettext('Group')
},
collaboratorOptionChanged ({ role, permissions }) {
collaboratorOptionChanged ({ role, permissions, expirationDate }) {
this.selectedRole = role
this.additionalPermissions = permissions
this.expirationDate = expirationDate
}
}
}
11 changes: 6 additions & 5 deletions apps/files/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,9 +631,10 @@ export default {
context.commit('INCOMING_SHARES_LOAD', [])
context.commit('INCOMING_SHARES_ERROR', null)
},
changeShare ({ commit, getters }, { client, share, role, permissions }) {
changeShare ({ commit, getters }, { client, share, role, permissions, expirationDate }) {
const params = {
permissions: permissions
permissions: permissions,
expireDate: expirationDate
}

if (!params.permissions) {
Expand All @@ -650,9 +651,9 @@ export default {
console.log(e)
})
},
addShare (context, { client, path, $gettext, shareWith, shareType, permissions }) {
addShare (context, { client, path, $gettext, shareWith, shareType, permissions, expirationDate }) {
if (shareType === shareTypes.group) {
client.shares.shareFileWithGroup(path, shareWith, { permissions: permissions })
client.shares.shareFileWithGroup(path, shareWith, { permissions: permissions, expirationDate: expirationDate })
.then(share => {
context.commit('CURRENT_FILE_OUTGOING_SHARES_ADD', _buildCollaboratorShare(share.shareInfo, context.getters.highlightedFile))
context.commit('UPDATE_CURRENT_FILE_SHARE_TYPES')
Expand All @@ -668,7 +669,7 @@ export default {
}

const remoteShare = shareType === shareTypes.remote
client.shares.shareFileWithUser(path, shareWith, { permissions: permissions, remoteUser: remoteShare })
client.shares.shareFileWithUser(path, shareWith, { permissions: permissions, remoteUser: remoteShare, expirationDate: expirationDate })
.then(share => {
context.commit('CURRENT_FILE_OUTGOING_SHARES_ADD', _buildCollaboratorShare(share.shareInfo, context.getters.highlightedFile))
context.commit('UPDATE_CURRENT_FILE_SHARE_TYPES')
Expand Down
Loading

0 comments on commit 8979763

Please sign in to comment.