Skip to content

Commit

Permalink
Disable actions on certain paths
Browse files Browse the repository at this point in the history
Currently, hardcoded to disable all above home/project root.

The discussed solution with oC is for actions to be enabled depending on dav response' permission bits
  • Loading branch information
diocas committed Jun 1, 2023
1 parent 11ad6f4 commit 1563e15
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 6 deletions.
7 changes: 2 additions & 5 deletions packages/web-app-files/src/helpers/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ export function getParentPaths(path = '', includeCurrent = false) {
}

sections.pop()
while (sections.length > 0) {
if (!sections.join('/')) {
sections.pop()
continue
}
while (sections.length > 4) {
// CERNBox ignore paths above user/project dir
paths.push(sections.join('/'))
sections.pop()
}
Expand Down
5 changes: 5 additions & 0 deletions packages/web-app-files/src/mixins/actions/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export default {
if (isLocationPublicActive(this.$router, 'files-public-link')) {
return this.currentFolder.canCreate()
}
// CERNBox do not allow actions above home/project root
const elems = resources[0].path?.split('/').filter(Boolean) || [] //"/eos/project/c/cernbox"
if (isLocationSpacesActive(this.$router, 'files-spaces-generic') && elems.length < 5) {
return false
}

// copy can't be restricted in authenticated context, because
// a user always has their home dir with write access
Expand Down
6 changes: 6 additions & 0 deletions packages/web-app-files/src/mixins/actions/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export default {
return false
}

// CERNBox do not allow actions above home/project root
const elems = resources[0].path?.split('/').filter(Boolean) || [] //"/eos/project/c/cernbox"
if (isLocationSpacesActive(this.$router, 'files-spaces-generic') && elems.length < 5) {
return false
}

const deleteDisabled = resources.some((resource) => {
return !resource.canBeDeleted()
})
Expand Down
5 changes: 5 additions & 0 deletions packages/web-app-files/src/mixins/actions/downloadArchive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export default {
) {
return false
}
// CERNBox do not allow actions above home/project root
const elems = resources[0].path?.split('/').filter(Boolean) || [] //"/eos/project/c/cernbox"
if (isLocationSpacesActive(this.$router, 'files-spaces-generic') && elems.length < 5) {
return false
}
const downloadDisabled = resources.some((resource) => {
return !resource.canDownload()
})
Expand Down
5 changes: 5 additions & 0 deletions packages/web-app-files/src/mixins/actions/downloadFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export default {
if (resources[0].isFolder) {
return false
}
// CERNBox do not allow actions above home/project root
const elems = resources[0].path?.split('/').filter(Boolean) || [] //"/eos/project/c/cernbox"
if (isLocationSpacesActive(this.$router, 'files-spaces-generic') && elems.length < 5) {
return false
}
return resources[0].canDownload()
},
canBeDefault: true,
Expand Down
5 changes: 5 additions & 0 deletions packages/web-app-files/src/mixins/actions/move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export default {
if (!this.currentFolder) {
return false
}
// CERNBox do not allow actions above home/project root
const elems = resources[0].path?.split('/').filter(Boolean) || [] //"/eos/project/c/cernbox"
if (isLocationSpacesActive(this.$router, 'files-spaces-generic') && elems.length < 5) {
return false
}

const moveDisabled = resources.some((resource) => {
return canBeMoved(resource, this.currentFolder.path) === false
Expand Down
5 changes: 5 additions & 0 deletions packages/web-app-files/src/mixins/actions/paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export default {
if (isLocationPublicActive(this.$router, 'files-public-link')) {
return this.currentFolder.canCreate()
}
// CERNBox do not allow actions above home/project root
const elems = this.$router.currentRoute?.path?.split('/').filter(Boolean) || [] //"/files/spaces/eos/project/c/cernbox"
if (isLocationSpacesActive(this.$router, 'files-spaces-generic') && elems.length < 6) { //WE CAN PASTE IN ROOT
return false
}

// copy can't be restricted in authenticated context, because
// a user always has their home dir with write access
Expand Down
7 changes: 6 additions & 1 deletion packages/web-app-files/src/mixins/actions/rename.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mapActions, mapGetters, mapMutations, mapState } from 'vuex'
import { isSameResource } from '../../helpers/resource'
import { isLocationTrashActive, isLocationSharesActive } from '../../router'
import { isLocationTrashActive, isLocationSharesActive, isLocationSpacesActive } from '../../router'
import { Resource } from 'web-client'
import { dirname, join } from 'path'
import { WebDAV } from 'web-client/src/webdav'
Expand Down Expand Up @@ -40,6 +40,11 @@ export default {
if (resources.length !== 1) {
return false
}
// CERNBox do not allow actions above home/project root
const elems = resources[0].path?.split('/').filter(Boolean) || [] //"/eos/project/c/cernbox"
if (isLocationSpacesActive(this.$router, 'files-spaces-generic') && elems.length < 5) {
return false
}

// FIXME: Remove this check as soon as renaming shares works as expected
// see https://github.com/owncloud/ocis/issues/4866
Expand Down
5 changes: 5 additions & 0 deletions packages/web-app-files/src/quickActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { eventBus } from 'web-pkg/src/services/eventBus'
import { SideBarEventTopics } from 'web-pkg/src/composables/sideBar'

export function canShare(item, store) {
// CERNBox do not allow actions above home/project root
const elems = item.path?.split('/').filter(Boolean) //"/eos/project/c/cernbox"
if (elems.length < 5) {
return false
}
const { capabilities } = store.state.user
if (!capabilities.files_sharing || !capabilities.files_sharing.api_enabled) {
return false
Expand Down
5 changes: 5 additions & 0 deletions packages/web-pkg/src/mixins/spaces/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export default {
},
handler: this.$_delete_trigger,
isEnabled: ({ resources }) => {
// CERNBox do not allow actions above home/project root
const elems = resources[0].path?.split('/').filter(Boolean) || [] //"/eos/project/c/cernbox"
if (elems.length < 5) {
return false
}
return !!this.filterResourcesToDelete(resources).length
},
componentType: 'button',
Expand Down
5 changes: 5 additions & 0 deletions packages/web-pkg/src/mixins/spaces/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export default {
if (resources.length !== 1) {
return false
}
// CERNBox do not allow actions above home/project root
const elems = resources[0].path?.split('/').filter(Boolean) || [] //"/eos/project/c/cernbox"
if (elems.length < 5) {
return false
}

return resources[0].canRename({ user: this.user })
},
Expand Down

0 comments on commit 1563e15

Please sign in to comment.