Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect space quota permission #7401

Merged
merged 4 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/bugfix-space-quota-permission
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Respect space quota permission

By taking the space quota permission into account, we've fixed a bug where a regular space member could see the "Edit space quota" action.

https://github.com/owncloud/web/issues/7400
https://github.com/owncloud/web/pull/7401
4 changes: 0 additions & 4 deletions packages/web-app-files/src/helpers/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,6 @@ export function buildSpace(space) {
]
return user && allowedRoles.includes(user.uuid)
},
canEditQuota: function ({ user }: { user?: User } = {}) {
const allowedRoles = [...this.spaceRoles[spaceRoleManager.name]]
return user && allowedRoles.includes(user.uuid)
},
canCreate: function () {
return true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default {
return false
}

return resources[0].canEditQuota({ user: this.user })
return this.$permissionManager.canEditSpaceQuota()
},
componentType: 'oc-button',
class: 'oc-files-actions-edit-quota-trigger'
Expand Down
17 changes: 11 additions & 6 deletions packages/web-app-files/tests/unit/mixins/spaces/editQuota.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,43 @@ describe('editQuota', () => {
const wrapper = getWrapper()
expect(wrapper.vm.$_editQuota_items[0].isEnabled({ resources: [] })).toBe(false)
})
it('should be true when the current user is a manager', () => {
it('should be true when the current user has the "set-space-quota"-permission', () => {
const spaceMock = {
id: '1',
quota: {},
root: {
permissions: [{ roles: ['manager'], grantedTo: [{ user: { id: 1 } }] }]
}
}
const wrapper = getWrapper()
const wrapper = getWrapper({ canEditSpaceQuota: true })
expect(
wrapper.vm.$_editQuota_items[0].isEnabled({ resources: [buildSpace(spaceMock)] })
).toBe(true)
})
it('should be false when the current user is a viewer', () => {
it('should be false when the current user does not have the "set-space-quota"-permission', () => {
const spaceMock = {
id: '1',
quota: {},
root: {
permissions: [{ roles: ['viewer'], grantedTo: [{ user: { id: 1 } }] }]
permissions: [{ roles: ['manager'], grantedTo: [{ user: { id: 1 } }] }]
}
}
const wrapper = getWrapper()
const wrapper = getWrapper({ canEditSpaceQuota: false })
expect(
wrapper.vm.$_editQuota_items[0].isEnabled({ resources: [buildSpace(spaceMock)] })
).toBe(false)
})
})
})

function getWrapper() {
function getWrapper({ canEditSpaceQuota = false } = {}) {
return mount(Component, {
localVue,
mocks: {
$permissionManager: {
canEditSpaceQuota: () => canEditSpaceQuota
}
},
store: createStore(Vuex.Store, {
modules: {
user: {
Expand Down
19 changes: 19 additions & 0 deletions packages/web-pkg/src/services/permissionManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import { Store } from 'vuex'
interface Permission {
description: string
displayName: string
id: string
name: string
permissionValue: {
constraint: string
operation: string
}
resource: {
id: string
type: string
}
}
interface Role {
name: 'admin' | 'spaceadmin' | 'user' | 'guest'
settings: Array<Permission>
}
interface User {
role: Role
Expand All @@ -21,6 +36,10 @@ export class PermissionManager {
return ['admin', 'spaceadmin'].includes(this.user.role?.name)
}

public canEditSpaceQuota() {
return !!this.user.role?.settings.find((s) => s.name === 'set-space-quota')
}

get user(): User {
return this.store.getters.user
}
Expand Down