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

Space management actions followup #8229

Merged
merged 5 commits into from
Jan 13, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ https://github.com/owncloud/web/pull/8190
https://github.com/owncloud/web/pull/8192
https://github.com/owncloud/web/pull/8199
https://github.com/owncloud/web/pull/8224
https://github.com/owncloud/web/pull/8229
https://github.com/owncloud/web/issues/8219
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<span v-text="ownerUsernames" />
</td>
</tr>
<tr>
<tr v-if="!space.disabled">
<th scope="col" class="oc-pr-s" v-text="$gettext('Quota')" />
<td>
<space-quota :space-quota="space.spaceQuota" />
Expand Down
6 changes: 4 additions & 2 deletions packages/web-pkg/src/mixins/spaces/disable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mapActions, mapGetters, mapMutations, mapState } from 'vuex'
import { clientService } from 'web-pkg/src/services'
import { SpaceResource } from 'web-client'

export default {
computed: {
Expand Down Expand Up @@ -64,15 +65,16 @@ export default {
this.createModal(modal)
},

$_disable_disableSpace(space) {
$_disable_disableSpace(space: SpaceResource) {
const accessToken = this.$store.getters['runtime/auth/accessToken']
const graphClient = clientService.graphAuthenticated(this.configuration.server, accessToken)
return graphClient.drives
.deleteDrive(space.id)
.deleteDrive(space.id.toString())
.then(() => {
this.hideModal()
if (this.$router.currentRoute.name === 'admin-settings-spaces') {
space.disabled = true
space.spaceQuota = { total: space.spaceQuota.total }
}
this.UPDATE_SPACE_FIELD({
id: space.id,
Expand Down
8 changes: 5 additions & 3 deletions packages/web-pkg/src/mixins/spaces/restore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mapActions, mapGetters, mapMutations, mapState } from 'vuex'
import { clientService } from 'web-pkg/src/services'
import { SpaceResource } from 'web-client'

export default {
computed: {
Expand Down Expand Up @@ -62,23 +63,24 @@ export default {
this.createModal(modal)
},

$_restore_restoreSpace(space) {
$_restore_restoreSpace(space: SpaceResource) {
const accessToken = this.$store.getters['runtime/auth/accessToken']
const graphClient = clientService.graphAuthenticated(this.configuration.server, accessToken)
return graphClient.drives
.updateDrive(
space.id,
space.id.toString(),
{ name: space.name },
{
headers: {
Restore: true
}
}
)
.then(() => {
.then((updatedSpace) => {
this.hideModal()
if (this.$router.currentRoute.name === 'admin-settings-spaces') {
space.disabled = false
space.spaceQuota = updatedSpace.data.quota
}
this.UPDATE_SPACE_FIELD({
id: space.id,
Expand Down
12 changes: 6 additions & 6 deletions packages/web-pkg/src/services/permissionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ interface Permission {
type: string
}
}
export enum RoleName {
export enum UserRoleName {
Admin = 'admin',
SpaceAdmin = 'spaceadmin',
User = 'user',
Guest = 'guest'
}
interface Role {
name: RoleName
interface UserRole {
name: UserRoleName
settings: Array<Permission>
}
interface User {
role: Role
role: UserRole
}

export class PermissionManager {
Expand All @@ -35,11 +35,11 @@ export class PermissionManager {
}

public hasUserManagement() {
return this.user.role?.name === RoleName.Admin
return this.user.role?.name === UserRoleName.Admin
}

public hasSpaceManagement() {
return [RoleName.Admin, RoleName.SpaceAdmin].includes(this.user.role?.name)
return [UserRoleName.Admin, UserRoleName.SpaceAdmin].includes(this.user.role?.name)
}

public canEditSpaceQuota() {
Expand Down
4 changes: 2 additions & 2 deletions packages/web-pkg/tests/unit/mixins/spaces/disable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('disable', () => {
graphMock.drives.deleteDrive.mockResolvedValue(mockAxiosResolve())
const { wrapper } = getWrapper(graphMock)
const hideModalStub = jest.spyOn(wrapper.vm, 'hideModal')
await wrapper.vm.$_disable_disableSpace(1)
await wrapper.vm.$_disable_disableSpace({ id: 1 })

expect(hideModalStub).toHaveBeenCalledTimes(1)
})
Expand All @@ -98,7 +98,7 @@ describe('disable', () => {
graphMock.drives.deleteDrive.mockRejectedValue(new Error())
const { wrapper } = getWrapper(graphMock)
const showMessageStub = jest.spyOn(wrapper.vm, 'showMessage')
await wrapper.vm.$_disable_disableSpace(1)
await wrapper.vm.$_disable_disableSpace({ id: 1 })

expect(showMessageStub).toHaveBeenCalledTimes(1)
})
Expand Down
4 changes: 2 additions & 2 deletions packages/web-pkg/tests/unit/mixins/spaces/restore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('restore', () => {
graphMock.drives.updateDrive.mockResolvedValue(mockAxiosResolve())
const { wrapper } = getWrapper(graphMock)
const hideModalStub = jest.spyOn(wrapper.vm, 'hideModal')
await wrapper.vm.$_restore_restoreSpace(1, 'renamed space')
await wrapper.vm.$_restore_restoreSpace({ id: 1 }, 'renamed space')

expect(hideModalStub).toHaveBeenCalledTimes(1)
})
Expand All @@ -99,7 +99,7 @@ describe('restore', () => {
graphMock.drives.updateDrive.mockRejectedValue(new Error())
const { wrapper } = getWrapper(graphMock)
const showMessageStub = jest.spyOn(wrapper.vm, 'showMessage')
await wrapper.vm.$_restore_restoreSpace(1)
await wrapper.vm.$_restore_restoreSpace({ id: 1 })

expect(showMessageStub).toHaveBeenCalledTimes(1)
})
Expand Down