From 37b2fb3199c0f337a907c23d44c2f48a3af38de0 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Sat, 3 Oct 2020 13:29:34 +0300 Subject: [PATCH] Add api for fetching a list of tags --- src/api/users.js | 95 +++++++++++++++++++++----------------- src/store/modules/users.js | 19 ++++++-- src/views/users/index.vue | 1 + 3 files changed, 67 insertions(+), 48 deletions(-) diff --git a/src/api/users.js b/src/api/users.js index 71028fd7..9084c566 100644 --- a/src/api/users.js +++ b/src/api/users.js @@ -22,6 +22,26 @@ export async function addRight(nicknames, right, authHost, token) { }) } +export async function approveUserAccount(nicknames, authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: '/api/pleroma/admin/users/approve', + method: 'patch', + headers: authHeaders(token), + data: { nicknames } + }) +} + +export async function confirmUserEmail(nicknames, authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: '/api/pleroma/admin/users/confirm_email', + method: 'patch', + headers: authHeaders(token), + data: { nicknames } + }) +} + export async function createNewAccount(nickname, email, password, authHost, token) { return await request({ baseURL: baseName(authHost), @@ -81,6 +101,15 @@ export async function fetchUser(id, 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 fetchUserCredentials(nickname, authHost, token) { return await request({ baseURL: baseName(authHost), @@ -90,22 +119,22 @@ export async function fetchUserCredentials(nickname, authHost, token) { }) } -export async function updateUserCredentials(nickname, credentials, authHost, token) { +export async function fetchUserStatuses(id, authHost, godmode, token) { return await request({ baseURL: baseName(authHost), - url: `/api/pleroma/admin/users/${nickname}/credentials`, - method: 'patch', - headers: authHeaders(token), - data: credentials + url: `/api/pleroma/admin/users/${id}/statuses?godmode=${godmode}`, + method: 'get', + headers: authHeaders(token) }) } -export async function fetchUsers(filters, authHost, token, page = 1) { +export async function forcePasswordReset(nicknames, authHost, token) { return await request({ baseURL: baseName(authHost), - url: `/api/pleroma/admin/users?page=${page}&filters=${filters}`, - method: 'get', - headers: authHeaders(token) + url: `/api/pleroma/admin/users/force_password_reset`, + method: 'patch', + headers: authHeaders(token), + data: { nicknames } }) } @@ -118,10 +147,19 @@ export async function getPasswordResetToken(nickname, authHost, token) { }) } -export async function forcePasswordReset(nicknames, authHost, token) { +export async function listAllTags(authHost, token) { return await request({ baseURL: baseName(authHost), - url: `/api/pleroma/admin/users/force_password_reset`, + url: `/api/pleroma/admin/users/tag`, + method: 'get', + headers: authHeaders(token) + }) +} + +export async function resendConfirmationEmail(nicknames, authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: '/api/pleroma/admin/users/resend_confirmation_email', method: 'patch', headers: authHeaders(token), data: { nicknames } @@ -157,42 +195,13 @@ export async function untagUser(nicknames, tags, authHost, token) { }) } -export async function fetchUserStatuses(id, authHost, godmode, token) { +export async function updateUserCredentials(nickname, credentials, authHost, token) { return await request({ baseURL: baseName(authHost), - url: `/api/pleroma/admin/users/${id}/statuses?godmode=${godmode}`, - method: 'get', - headers: authHeaders(token) - }) -} - -export async function approveUserAccount(nicknames, authHost, token) { - return await request({ - baseURL: baseName(authHost), - url: '/api/pleroma/admin/users/approve', + url: `/api/pleroma/admin/users/${nickname}/credentials`, method: 'patch', headers: authHeaders(token), - data: { nicknames } - }) -} - -export async function confirmUserEmail(nicknames, authHost, token) { - return await request({ - baseURL: baseName(authHost), - url: '/api/pleroma/admin/users/confirm_email', - method: 'patch', - headers: authHeaders(token), - data: { nicknames } - }) -} - -export async function resendConfirmationEmail(nicknames, authHost, token) { - return await request({ - baseURL: baseName(authHost), - url: '/api/pleroma/admin/users/resend_confirmation_email', - method: 'patch', - headers: authHeaders(token), - data: { nicknames } + data: credentials }) } diff --git a/src/store/modules/users.js b/src/store/modules/users.js index ef272356..572c0fd7 100644 --- a/src/store/modules/users.js +++ b/src/store/modules/users.js @@ -3,20 +3,21 @@ import i18n from '@/lang' import { activateUsers, addRight, + approveUserAccount, + confirmUserEmail, createNewAccount, deactivateUsers, deleteRight, deleteUsers, disableMfa, fetchUsers, + forcePasswordReset, getPasswordResetToken, + listAllTags, + resendConfirmationEmail, searchUsers, tagUser, untagUser, - forcePasswordReset, - approveUserAccount, - confirmUserEmail, - resendConfirmationEmail, updateUserCredentials } from '@/api/users' import { fetchSettings, updateSettings } from '@/api/settings' @@ -40,7 +41,8 @@ const users = { passwordResetToken: { token: '', link: '' - } + }, + tags: [] }, mutations: { SET_USERS: (state, users) => { @@ -83,6 +85,9 @@ const users = { SET_TAG_POLICY: (state, mrfPolicies) => { state.mrfPolicies = mrfPolicies }, + SET_TAGS: (state, tags) => { + state.tags = tags + }, SET_USERS_FILTERS: (state, filters) => { state.filters = filters } @@ -246,6 +251,10 @@ const users = { RemovePasswordToken({ commit }) { commit('SET_PASSWORD_RESET_TOKEN', { link: '', token: '' }) }, + async ListTags({ commit, getters }) { + const { data } = await listAllTags(getters.authHost, getters.token) + commit('SET_TAGS', data) + }, async RemoveTag({ dispatch, getters }, { users, tag, _userId, _statusId }) { const updatedUsers = users.map(user => { return { ...user, tags: user.tags.filter(userTag => userTag !== tag) } diff --git a/src/views/users/index.vue b/src/views/users/index.vue index ad45742f..d31f1e81 100644 --- a/src/views/users/index.vue +++ b/src/views/users/index.vue @@ -226,6 +226,7 @@ export default { this.$store.dispatch('NeedReboot') this.$store.dispatch('FetchTagPolicySetting') this.$store.dispatch('FetchUsers', { page: 1 }) + this.$store.dispatch('ListTags') }, destroyed() { this.$store.dispatch('ClearUsersState')