diff --git a/package.json b/package.json index 7f0dce47f..edafd3de8 100644 --- a/package.json +++ b/package.json @@ -76,5 +76,8 @@ ], "peerDependencies": { "owncloud-design-system": "^1.7.0" + }, + "dependencies": { + "validator": "^13.1.1" } } diff --git a/ui/components/App.vue b/ui/components/App.vue index c77b087db..403a8e870 100644 --- a/ui/components/App.vue +++ b/ui/components/App.vue @@ -2,7 +2,16 @@

- + + |
@@ -32,7 +41,11 @@

@@ -45,6 +58,9 @@ import AccountsList from './accounts/AccountsList.vue' export default { name: 'App', components: { AccountsList }, + data: () => ({ + isAccountCreationInProgress: false + }), computed: { ...mapGetters('Accounts', ['isInitialized', 'getAccountsSorted']), ...mapState('Accounts', ['selectedAccounts']), @@ -86,17 +102,34 @@ export default { } return actions + }, + + disabledCreateAccountBtnTooltip () { + if (!this.isInitialized) { + return this.$gettext('Loading users') + } + + if (this.isAccountCreationInProgress) { + return this.$gettext('User creation is already in progress') + } + + return null } }, methods: { ...mapActions('Accounts', ['initialize', 'toggleAccountStatus']), - ...mapMutations('Accounts', ['RESET_ACCOUNTS_SELECTION']) + ...mapMutations('Accounts', ['RESET_ACCOUNTS_SELECTION']), + + setAccountCreationProgress (isInProgress) { + this.isAccountCreationInProgress = isInProgress + } }, created () { this.initialize() }, beforeDestroy () { this.RESET_ACCOUNTS_SELECTION() + this.setAccountCreationProgress(false) } } diff --git a/ui/components/accounts/AccountsList.vue b/ui/components/accounts/AccountsList.vue index d8ef72303..e26b06c6b 100644 --- a/ui/components/accounts/AccountsList.vue +++ b/ui/components/accounts/AccountsList.vue @@ -22,6 +22,7 @@ + import { mapActions, mapGetters } from 'vuex' import AccountsListRow from './AccountsListRow.vue' +import AccountsListNewAccountRow from './AccountsListNewAccountRow.vue' export default { name: 'AccountsList', components: { - AccountsListRow + AccountsListRow, + AccountsListNewAccountRow }, props: { accounts: { type: Array, required: true + }, + isCreateNewRowDisplayed: { + type: Boolean, + required: false, + default: false } }, computed: { ...mapGetters('Accounts', ['areAllAccountsSelected']) }, methods: { - ...mapActions('Accounts', ['toggleSelectionAll']) + ...mapActions('Accounts', ['toggleSelectionAll']), + + emitCreationCancel () { + this.$emit('cancelAccountCreation') + } } } diff --git a/ui/components/accounts/AccountsListNewAccountRow.vue b/ui/components/accounts/AccountsListNewAccountRow.vue new file mode 100644 index 000000000..89c9ab945 --- /dev/null +++ b/ui/components/accounts/AccountsListNewAccountRow.vue @@ -0,0 +1,126 @@ + + + diff --git a/ui/store/index.js b/ui/store/index.js index aa2ccc012..b439c74fd 100644 --- a/ui/store/index.js +++ b/ui/store/index.js @@ -1,5 +1,5 @@ /* eslint-disable camelcase */ -import { AccountsService_ListAccounts, AccountsService_UpdateAccount } from '../client/accounts' +import { AccountsService_ListAccounts, AccountsService_UpdateAccount, AccountsService_CreateAccount } from '../client/accounts' import { RoleService_ListRoles } from '../client/settings' /* eslint-enable camelcase */ import { injectAuthToken } from '../helpers/auth' @@ -56,6 +56,10 @@ const mutations = { RESET_ACCOUNTS_SELECTION (state) { state.selectedAccounts = [] + }, + + PUSH_NEW_ACCOUNT (state, account) { + state.accounts.push(account) } } @@ -164,6 +168,35 @@ const actions = { } commit('RESET_ACCOUNTS_SELECTION') + }, + async createNewAccount ({ rootGetters, commit, dispatch }, account) { + injectAuthToken(rootGetters.user.token) + + const response = await AccountsService_CreateAccount({ + $domain: rootGetters.configuration.server, + body: { + account: { + on_premises_sam_account_name: account.username, + mail: account.email, + password_profile: { + password: account.password + }, + account_enabled: true, + display_name: account.username + } + } + }) + + if (response.status === 201) { + commit('PUSH_NEW_ACCOUNT', account) + console.log(response) + } else { + dispatch('showMessage', { + title: 'Failed to create account', + desc: response.statusText, + status: 'danger' + }, { root: true }) + } } } diff --git a/yarn.lock b/yarn.lock index 235035ada..dd480cbed 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6348,6 +6348,11 @@ validate-npm-package-license@^3.0.1: spdx-correct "^3.0.0" spdx-expression-parse "^3.0.0" +validator@^13.1.1: + version "13.1.1" + resolved "https://registry.yarnpkg.com/validator/-/validator-13.1.1.tgz#f8811368473d2173a9d8611572b58c5783f223bf" + integrity sha512-8GfPiwzzRoWTg7OV1zva1KvrSemuMkv07MA9TTl91hfhe+wKrsrgVN4H2QSFd/U/FhiU3iWPYVgvbsOGwhyFWw== + vasync@1.6.2: version "1.6.2" resolved "https://registry.yarnpkg.com/vasync/-/vasync-1.6.2.tgz#568edcf40b2b5c35b1cc048cad085de4739703fb"