Skip to content

Commit

Permalink
Fetch and show quota limitations (#7467)
Browse files Browse the repository at this point in the history
Fetch an show quota limitations
  • Loading branch information
Jan authored Aug 26, 2022
1 parent d06baa8 commit e2633fa
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 5 deletions.
5 changes: 4 additions & 1 deletion packages/web-app-files/src/components/Spaces/QuotaModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<quota-select
:title="$gettext('Space quota')"
:total-quota="selectedOption"
:max-quota="spaceQuotas.maxProjectQuota || 0"
@selectedOptionChange="changeSelectedQuotaOption"
/>
</template>
Expand All @@ -21,7 +22,7 @@

<script lang="ts">
import { defineComponent } from '@vue/runtime-core'
import { mapActions, mapMutations } from 'vuex'
import { mapActions, mapMutations, mapState } from 'vuex'
import { useGraphClient } from 'web-client/src/composables'
import QuotaSelect from 'web-pkg/src/components/QuotaSelect.vue'
Expand Down Expand Up @@ -51,6 +52,8 @@ export default defineComponent({
}
},
computed: {
...mapState('runtime/spaces', ['spaceQuotas']),
confirmButtonDisabled() {
return this.space.spaceQuota.total === this.selectedOption
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ function createStore(activeFiles) {
disablePreviews: true
}
}),
user: () => user
user: () => user,
capabilities: () => {}
},
modules: {
Files: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ function createWrapper(
runningOnEos
}
}
}
},
capabilities: () => {}
},
modules: {
Files: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
:key="'quota-select-' + user.id"
:title="$gettext('Personal quota')"
:total-quota="editUser.drive.quota.total || 0"
:max-quota="spaceQuotas.maxPersonalQuota || 0"
@selectedOptionChange="changeSelectedQuotaOption"
/>
<p v-else v-translate class="oc-m-rm">
Expand All @@ -66,6 +67,7 @@ import UserInfoBox from './UserInfoBox.vue'
import CompareSaveDialog from 'web-pkg/src/components/sidebar/CompareSaveDialog.vue'
import QuotaSelect from 'web-pkg/src/components/QuotaSelect.vue'
import { cloneDeep } from 'lodash-es'
import { mapState } from 'vuex'
export default {
name: 'EditPanel',
Expand Down Expand Up @@ -100,6 +102,8 @@ export default {
}
},
computed: {
...mapState('runtime/spaces', ['spaceQuotas']),
userRole() {
return this.user ? this.userRoles[this.user.id] : null
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Vuex from 'vuex'
import { mount, createLocalVue } from '@vue/test-utils'
import { createStore } from 'vuex-extensions'
import EditPanel from '../../../../../src/components/Users/SideBar/EditPanel.vue'

const localVue = createLocalVue()
Expand Down Expand Up @@ -74,6 +75,21 @@ describe('EditPanel', () => {
function getWrapper({ propsData = {} } = {}) {
return mount(EditPanel, {
localVue,
store: createStore(Vuex.Store, {
modules: {
runtime: {
namespaced: true,
modules: {
spaces: {
namespaced: true,
state: {
spaceQuotas: {}
}
}
}
}
}
}),
directives: {
translate: jest.fn()
},
Expand Down
5 changes: 5 additions & 0 deletions packages/web-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ export const renderSuccess = (): void => {
store.getters.configuration.server,
store.getters['runtime/auth/accessToken']
)
const httpAuthenticatedClient = clientService.httpAuthenticated(
store.getters['runtime/auth/accessToken']
)

store.dispatch('runtime/spaces/loadSpaces', { graphClient })
store.dispatch('runtime/spaces/loadSpaceQuotas', { httpAuthenticatedClient })
}
},
{
Expand Down
20 changes: 18 additions & 2 deletions packages/web-runtime/src/store/spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import Vue from 'vue'
import { set, has } from 'lodash-es'

const state = {
spaces: []
spaces: [],
spaceQuotas: {}
}

const getters = {
spaces: (state) => state.spaces
spaces: (state) => state.spaces,
spaceQuotas: (state) => state.spaceQuotas
}

const mutations = {
Expand Down Expand Up @@ -57,6 +59,9 @@ const mutations = {
},
CLEAR_SPACES(state) {
state.spaces = []
},
LOAD_SPACE_QUOTAS(state, spaceQuotas) {
state.spaceQuotas = spaceQuotas
}
}

Expand All @@ -69,6 +74,17 @@ const actions = {

const spaces = graphResponse.data.value.map((space) => buildSpace(space))
context.commit('LOAD_SPACES', spaces)
},
async loadSpaceQuotas(context, { httpAuthenticatedClient }) {
// FIXME: Use graphClient after added to libre-graph-api specs https://github.com/owncloud/libre-graph-api
const { data } = await httpAuthenticatedClient.get(
`${context.rootGetters.configuration.server}graph/v1.0/drivequotas`
)
context.commit('LOAD_SPACE_QUOTAS', {
maxProjectQuota: data.max_project_quota || 0,
maxPersonalQuota: data.max_personal_quota || 0,
defaultProjectQuota: data.default_project_quota || 0
})
}
}

Expand Down

0 comments on commit e2633fa

Please sign in to comment.