mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-18 21:46:19 -04:00
Handle disable and enable actions
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
<template>
|
||||
<div>
|
||||
<div class="uk-container uk-padding">
|
||||
<h1>
|
||||
Accounts
|
||||
</h1>
|
||||
<h1 v-text="$gettext('Accounts')" />
|
||||
<oc-grid v-if="selectedAccountsAmount > 0" key="selected-accounts-info" gutter="small" class="uk-flex-middle">
|
||||
<span v-text="selectionInfoText" />
|
||||
<div>
|
||||
@@ -20,6 +18,7 @@
|
||||
role="menuitem"
|
||||
:class="{ 'uk-margin-small-bottom': index + 1 !== actions.length }"
|
||||
class="uk-width-1-1 uk-flex-left"
|
||||
@click="action.handler"
|
||||
>
|
||||
{{ action.label }}
|
||||
</oc-button>
|
||||
@@ -66,13 +65,15 @@ export default {
|
||||
|
||||
if (isAnyAccountDisabled) {
|
||||
actions.push({
|
||||
label: this.$gettext('Enable')
|
||||
label: this.$gettext('Enable'),
|
||||
handler: this.enableAccounts
|
||||
})
|
||||
}
|
||||
|
||||
if (isAnyAccountEnabled) {
|
||||
actions.push({
|
||||
label: this.$gettext('Disable')
|
||||
label: this.$gettext('Disable'),
|
||||
handler: this.disableAccounts
|
||||
})
|
||||
}
|
||||
|
||||
@@ -80,7 +81,7 @@ export default {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
...mapActions('Accounts', ['initialize'])
|
||||
...mapActions('Accounts', ['initialize', 'enableAccounts', 'disableAccounts'])
|
||||
},
|
||||
created () {
|
||||
this.initialize()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* eslint-disable camelcase */
|
||||
import { AccountsService_ListAccounts } from '../client/accounts'
|
||||
import { AccountsService_ListAccounts, AccountsService_UpdateAccount } from '../client/accounts'
|
||||
import { RoleService_ListRoles } from '../client/settings'
|
||||
/* eslint-enable camelcase */
|
||||
import { injectAuthToken } from '../helpers/auth'
|
||||
@@ -101,6 +101,74 @@ const actions = {
|
||||
|
||||
toggleSelectionAll ({ commit, getters, state }) {
|
||||
getters.areAllAccountsSelected ? commit('SET_SELECTED_ACCOUNTS', []) : commit('SET_SELECTED_ACCOUNTS', [...state.accounts])
|
||||
},
|
||||
|
||||
async enableAccounts ({ dispatch, rootGetters }, accounts) {
|
||||
const failedAccounts = []
|
||||
injectAuthToken(rootGetters.user.token)
|
||||
|
||||
for (const account in accounts) {
|
||||
const response = await AccountsService_UpdateAccount({
|
||||
$domain: rootGetters.configuration.server,
|
||||
body: {
|
||||
account: account
|
||||
}
|
||||
})
|
||||
|
||||
if (response.status !== 201) {
|
||||
failedAccounts.push({ account: account.diisplayName, statusText: response.statusText })
|
||||
}
|
||||
}
|
||||
|
||||
if (failedAccounts.length === 1) {
|
||||
dispatch('showMessage', {
|
||||
title: 'Failed to enable account.',
|
||||
desc: failedAccounts[0].statusText,
|
||||
status: 'danger'
|
||||
}, { root: true })
|
||||
}
|
||||
|
||||
if (failedAccounts.length > 1) {
|
||||
dispatch('showMessage', {
|
||||
title: 'Failed to enable accounts.',
|
||||
desc: 'Could not enable multiple accounts',
|
||||
status: 'danger'
|
||||
}, { root: true })
|
||||
}
|
||||
},
|
||||
|
||||
async disableAccounts ({ dispatch, state, rootGetters }) {
|
||||
const failedAccounts = []
|
||||
injectAuthToken(rootGetters.user.token)
|
||||
|
||||
for (const account of state.selectedAccounts) {
|
||||
const response = await AccountsService_UpdateAccount({
|
||||
$domain: rootGetters.configuration.server,
|
||||
body: {
|
||||
account: account
|
||||
}
|
||||
})
|
||||
|
||||
if (response.status !== 201) {
|
||||
failedAccounts.push({ account: account.diisplayName, statusText: response.statusText })
|
||||
}
|
||||
}
|
||||
|
||||
if (failedAccounts.length === 1) {
|
||||
dispatch('showMessage', {
|
||||
title: 'Failed to disable account.',
|
||||
desc: failedAccounts[0].statusText,
|
||||
status: 'danger'
|
||||
}, { root: true })
|
||||
}
|
||||
|
||||
if (failedAccounts.length > 1) {
|
||||
dispatch('showMessage', {
|
||||
title: 'Failed to disable accounts.',
|
||||
desc: 'Could not disable multiple accounts',
|
||||
status: 'danger'
|
||||
}, { root: true })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user