diff --git a/src/api/__mocks__/users.js b/src/api/__mocks__/users.js index 39d08100..646a5dd3 100644 --- a/src/api/__mocks__/users.js +++ b/src/api/__mocks__/users.js @@ -1,4 +1,4 @@ -export const users = [ +export let users = [ { active: true, deactivated: false, id: '2', nickname: 'allis', local: true, external: false, roles: { admin: true, moderator: false }, tags: [] }, { active: true, deactivated: false, id: '10', nickname: 'bob', local: false, external: true, roles: { admin: false, moderator: false }, tags: ['sandbox'] }, { active: false, deactivated: true, id: 'abc', nickname: 'john', local: true, external: false, roles: { admin: false, moderator: false }, tags: ['strip_media'] } @@ -69,3 +69,9 @@ export async function tagUser(nickname, tag, authHost, token) { export async function untagUser(nickname, tag, authHost, token) { return Promise.resolve() } + +export async function createNewAccount(nickname, email, password, authHost, token) { + const newUser = { active: true, deactivated: false, id: '15', nickname, local: true, external: false, roles: { admin: false, moderator: false }, tags: [] } + users = [...users, newUser] + return Promise.resolve() +} diff --git a/src/api/users.js b/src/api/users.js index cdf6476c..a751302a 100644 --- a/src/api/users.js +++ b/src/api/users.js @@ -2,33 +2,6 @@ import request from '@/utils/request' import { getToken } from '@/utils/auth' import { baseName } from './utils' -export async function fetchUsers(filters, authHost, token, page = 1) { - return await request({ - baseURL: baseName(authHost), - url: `/api/pleroma/admin/users?page=${page}&filters=${filters}`, - method: 'get', - headers: authHeaders(token) - }) -} - -export async function toggleUserActivation(nickname, authHost, token) { - return await request({ - baseURL: baseName(authHost), - url: `/api/pleroma/admin/users/${nickname}/toggle_activation`, - method: 'patch', - headers: authHeaders(token) - }) -} - -export async function searchUsers(query, filters, authHost, token, page = 1) { - return await request({ - baseURL: baseName(authHost), - url: `/api/pleroma/admin/users?query=${query}&page=${page}&filters=${filters}`, - method: 'get', - headers: authHeaders(token) - }) -} - export async function addRight(nickname, right, authHost, token) { return await request({ baseURL: baseName(authHost), @@ -38,6 +11,16 @@ export async function addRight(nickname, right, authHost, token) { }) } +export async function createNewAccount(nickname, email, password, authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: '/api/pleroma/admin/users', + method: 'post', + headers: authHeaders(token), + data: { nickname, email, password } + }) +} + export async function deleteRight(nickname, right, authHost, token) { return await request({ baseURL: baseName(authHost), @@ -56,6 +39,24 @@ export async function deleteUser(nickname, authHost, token) { }) } +export async function fetchUsers(filters, authHost, token, page = 1) { + return await request({ + baseURL: baseName(authHost), + url: `/api/pleroma/admin/users?page=${page}&filters=${filters}`, + method: 'get', + headers: authHeaders(token) + }) +} + +export async function searchUsers(query, filters, authHost, token, page = 1) { + return await request({ + baseURL: baseName(authHost), + url: `/api/pleroma/admin/users?query=${query}&page=${page}&filters=${filters}`, + method: 'get', + headers: authHeaders(token) + }) +} + export async function tagUser(nicknames, tags, authHost, token) { return await request({ baseURL: baseName(authHost), @@ -66,6 +67,15 @@ export async function tagUser(nicknames, tags, authHost, token) { }) } +export async function toggleUserActivation(nickname, authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: `/api/pleroma/admin/users/${nickname}/toggle_activation`, + method: 'patch', + headers: authHeaders(token) + }) +} + export async function untagUser(nicknames, tags, authHost, token) { return await request({ baseURL: baseName(authHost), diff --git a/src/lang/en.js b/src/lang/en.js index 137426d4..0897740f 100644 --- a/src/lang/en.js +++ b/src/lang/en.js @@ -182,16 +182,46 @@ export default { revokeModerator: 'Revoke Moderator', grantModerator: 'Grant Moderator', activateAccount: 'Activate Account', + activateAccounts: 'Activate Accounts', deactivateAccount: 'Deactivate Account', + deactivateAccounts: 'Deactivate Accounts', deleteAccount: 'Delete Account', + deleteAccounts: 'Delete Accounts', forceNsfw: 'Force posts to be NSFW', stripMedia: 'Force posts not to have media', forceUnlisted: 'Force posts to be unlisted', sandbox: 'Force posts to be followers-only', disableRemoteSubscription: 'Disallow following user from remote instances', + disableRemoteSubscriptionForMultiple: 'Disallow following users from remote instances', disableAnySubscription: 'Disallow following user at all', + disableAnySubscriptionForMultiple: 'Disallow following users at all', selectUsers: 'Select users to apply actions to multiple users', - moderateUsers: 'Moderate multiple users' + moderateUsers: 'Moderate multiple users', + createAccount: 'Create new user account', + apply: 'apply', + remove: 'remove', + grantRightConfirmation: 'Are you sure you want to grant {right} rights to all selected users?', + revokeRightConfirmation: 'Are you sure you want to revoke {right} rights from all selected users?', + activateMultipleUsersConfirmation: 'Are you sure you want to activate accounts of all selected users?', + deactivateMultipleUsersConfirmation: 'Are you sure you want to deactivate accounts of all selected users?', + deleteMultipleUsersConfirmation: 'Are you sure you want to delete accounts of all selected users?', + addTagForMultipleUsersConfirmation: 'Are you sure you want to apply tag to all selected users?', + removeTagFromMultipleUsersConfirmation: 'Are you sure you want to remove tag from all selected users?', + ok: 'Okay', + completed: 'Completed', + cancel: 'Cancel', + canceled: 'Canceled', + username: 'Username', + email: 'E-mail', + password: 'Password', + create: 'Create', + submitFormError: 'There are errors on the form. Please fix them before continuing.', + emptyEmailError: 'Please input the e-mail', + invalidEmailError: 'Please input valid e-mail', + emptyPasswordError: 'Please input the password', + emptyNicknameError: 'Please input the username', + invalidNicknameError: 'Username can include "a-z", "A-Z" and "0-9" characters' + }, usersFilter: { inputPlaceholder: 'Select filter', diff --git a/src/store/modules/users.js b/src/store/modules/users.js index 22c450d6..80fb0c22 100644 --- a/src/store/modules/users.js +++ b/src/store/modules/users.js @@ -1,4 +1,4 @@ -import { addRight, fetchUsers, deleteRight, deleteUser, searchUsers, tagUser, toggleUserActivation, untagUser } from '@/api/users' +import { addRight, createNewAccount, fetchUsers, deleteRight, deleteUser, searchUsers, tagUser, toggleUserActivation, untagUser } from '@/api/users' const users = { state: { @@ -61,6 +61,10 @@ const users = { commit('CLEAR_USERS_FILTERS') dispatch('SearchUsers', { query: state.searchQuery, page: 1 }) }, + async CreateNewAccount({ dispatch, getters, state }, { nickname, email, password }) { + await createNewAccount(nickname, email, password, getters.authHost, getters.token) + dispatch('FetchUsers', { page: state.currentPage }) + }, async DeleteUser({ commit, getters }, user) { await deleteUser(user.nickname, getters.authHost, getters.token) const updatedUser = { ...user, deactivated: true } @@ -83,7 +87,7 @@ const users = { async SearchUsers({ commit, dispatch, state, getters }, { query, page }) { if (query.length === 0) { commit('SET_SEARCH_QUERY', query) - dispatch('FetchUsers', page) + dispatch('FetchUsers', { page }) } else { commit('SET_LOADING', true) commit('SET_SEARCH_QUERY', query) diff --git a/src/views/users/components/DropdownActionsMenu.vue b/src/views/users/components/MultipleUsersMenu.vue similarity index 79% rename from src/views/users/components/DropdownActionsMenu.vue rename to src/views/users/components/MultipleUsersMenu.vue index e310ed6f..96b76ace 100644 --- a/src/views/users/components/DropdownActionsMenu.vue +++ b/src/views/users/components/MultipleUsersMenu.vue @@ -29,22 +29,26 @@ - {{ $t('users.activateAccount') }} + {{ $t('users.activateAccounts') }} - {{ $t('users.deactivateAccount') }} + {{ $t('users.deactivateAccounts') }} - {{ $t('users.deleteAccount') }} + {{ $t('users.deleteAccounts') }}
{{ $t('users.forceNsfw') }} - apply - remove + + {{ $t('users.apply') }} + + + {{ $t('users.remove') }} +
@@ -52,8 +56,12 @@
{{ $t('users.stripMedia') }} - apply - remove + + {{ $t('users.apply') }} + + + {{ $t('users.remove') }} +
@@ -61,8 +69,12 @@
{{ $t('users.forceUnlisted') }} - apply - remove + + {{ $t('users.apply') }} + + + {{ $t('users.remove') }} +
@@ -70,26 +82,38 @@
{{ $t('users.sandbox') }} - apply - remove + + {{ $t('users.apply') }} + + + {{ $t('users.remove') }} +
- {{ $t('users.disableRemoteSubscription') }} + {{ $t('users.disableRemoteSubscriptionForMultiple') }} - apply - remove + + {{ $t('users.apply') }} + + + {{ $t('users.remove') }} +
- {{ $t('users.disableAnySubscription') }} + {{ $t('users.disableAnySubscriptionForMultiple') }} - apply - remove + + {{ $t('users.apply') }} + + + {{ $t('users.remove') }} +
@@ -157,68 +181,68 @@ export default { grantRightToMultipleUsers(right) { const { grantRight } = this.mappers() this.confirmMessage( - `Are you sure you want to grant ${right} rights to all selected users?`, + this.$t('users.grantRightConfirmation', { right }), grantRight(right) ) }, revokeRightFromMultipleUsers(right) { const { revokeRight } = this.mappers() this.confirmMessage( - `Are you sure you want to revoke ${right} rights from all selected users?`, + this.$t('users.revokeRightConfirmation', { right }), revokeRight(right) ) }, activateMultipleUsers() { const { activate } = this.mappers() this.confirmMessage( - 'Are you sure you want to activate accounts of all selected users?', + this.$t('users.activateMultipleUsersConfirmation'), activate ) }, deactivateMultipleUsers() { const { deactivate } = this.mappers() this.confirmMessage( - 'Are you sure you want to deactivate accounts of all selected users?', + this.$t('users.deactivateMultipleUsersConfirmation'), deactivate ) }, deleteMultipleUsers() { const { remove } = this.mappers() this.confirmMessage( - 'Are you sure you want to delete accounts of all selected users?', + this.$t('users.deleteMultipleUsersConfirmation'), remove ) }, addTagForMultipleUsers(tag) { const { addTag } = this.mappers() this.confirmMessage( - 'Are you sure you want to apply tag to all selected users?', + this.$t('users.addTagForMultipleUsersConfirmation'), addTag(tag) ) }, removeTagFromMultipleUsers(tag) { const { removeTag } = this.mappers() this.confirmMessage( - 'Are you sure you want to remove tag from all selected users?', + this.$t('users.removeTagFromMultipleUsersConfirmation'), removeTag(tag) ) }, confirmMessage(message, applyAction) { this.$confirm(message, { - confirmButtonText: 'OK', - cancelButtonText: 'Cancel', + confirmButtonText: this.$t('users.ok'), + cancelButtonText: this.$t('users.cancel'), type: 'warning' }).then(() => { applyAction() this.$emit('apply-action') this.$message({ type: 'success', - message: 'Completed' + message: this.$t('users.completed') }) }).catch(() => { this.$message({ type: 'info', - message: 'Canceled' + message: this.$t('users.canceled') }) }) } @@ -229,9 +253,8 @@ export default { diff --git a/src/views/users/index.vue b/src/views/users/index.vue index b453e816..04c0bcd9 100644 --- a/src/views/users/index.vue +++ b/src/views/users/index.vue @@ -4,13 +4,25 @@ {{ $t('users.users') }} ({{ normalizedUsersCount }}) -
+
- +
+ + +
+