Merge branch 'feature/update-admin-api' into 'master'
Update API urls in accordance with new docs Closes #19 See merge request pleroma/admin-fe!18
This commit is contained in:
commit
f9a17d6837
3 changed files with 55 additions and 44 deletions
|
@ -32,7 +32,7 @@ export async function searchUsers(query, filters, authHost, token, page = 1) {
|
|||
export async function addRight(nickname, right, authHost, token) {
|
||||
return await request({
|
||||
baseURL: baseName(authHost),
|
||||
url: `/api/pleroma/admin/permission_group/${nickname}/${right}`,
|
||||
url: `/api/pleroma/admin/users/${nickname}/permission_group/${right}`,
|
||||
method: 'post',
|
||||
headers: authHeaders(token)
|
||||
})
|
||||
|
@ -41,7 +41,7 @@ export async function addRight(nickname, right, authHost, token) {
|
|||
export async function deleteRight(nickname, right, authHost, token) {
|
||||
return await request({
|
||||
baseURL: baseName(authHost),
|
||||
url: `/api/pleroma/admin/permission_group/${nickname}/${right}`,
|
||||
url: `/api/pleroma/admin/users/${nickname}/permission_group/${right}`,
|
||||
method: 'delete',
|
||||
headers: authHeaders(token)
|
||||
})
|
||||
|
@ -50,29 +50,29 @@ export async function deleteRight(nickname, right, authHost, token) {
|
|||
export async function deleteUser(nickname, authHost, token) {
|
||||
return await request({
|
||||
baseURL: baseName(authHost),
|
||||
url: `/api/pleroma/admin/user.json?nickname=${nickname}`,
|
||||
url: `/api/pleroma/admin/users?nickname=${nickname}`,
|
||||
method: 'delete',
|
||||
headers: authHeaders(token)
|
||||
})
|
||||
}
|
||||
|
||||
export async function tagUser(nickname, tag, authHost, token) {
|
||||
export async function tagUser(nicknames, tags, authHost, token) {
|
||||
return await request({
|
||||
baseURL: baseName(authHost),
|
||||
url: '/api/pleroma/admin/users/tag',
|
||||
method: 'put',
|
||||
headers: authHeaders(token),
|
||||
data: { nicknames: [nickname], tags: [tag] }
|
||||
data: { nicknames, tags }
|
||||
})
|
||||
}
|
||||
|
||||
export async function untagUser(nickname, tag, authHost, token) {
|
||||
export async function untagUser(nicknames, tags, authHost, token) {
|
||||
return await request({
|
||||
baseURL: baseName(authHost),
|
||||
url: '/api/pleroma/admin/users/tag',
|
||||
method: 'delete',
|
||||
headers: authHeaders(token),
|
||||
data: { nicknames: [nickname], tags: [tag] }
|
||||
data: { nicknames, tags }
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,15 @@ const users = {
|
|||
a.nickname.localeCompare(b.nickname)
|
||||
)
|
||||
},
|
||||
SWAP_USERS: (state, users) => {
|
||||
const usersWithoutSwapped = users.reduce((acc, user) => {
|
||||
return acc.filter(u => u.id !== user.id)
|
||||
}, state.fetchedUsers)
|
||||
|
||||
state.fetchedUsers = [...usersWithoutSwapped, ...users].sort((a, b) =>
|
||||
a.nickname.localeCompare(b.nickname)
|
||||
)
|
||||
},
|
||||
SET_COUNT: (state, count) => {
|
||||
state.totalUsersCount = count
|
||||
},
|
||||
|
@ -47,6 +56,21 @@ const users = {
|
|||
}
|
||||
},
|
||||
actions: {
|
||||
async AddTag({ commit, getters }, { users, tag }) {
|
||||
const nicknames = users.map(user => user.nickname)
|
||||
await tagUser(nicknames, [tag], getters.authHost, getters.token)
|
||||
|
||||
commit('SWAP_USERS', users.map(user => ({ ...user, tags: [...user.tags, tag] })))
|
||||
},
|
||||
async ClearFilters({ commit, dispatch, state }) {
|
||||
commit('CLEAR_USERS_FILTERS')
|
||||
dispatch('SearchUsers', { query: state.searchQuery, page: 1 })
|
||||
},
|
||||
async DeleteUser({ commit, getters }, user) {
|
||||
await deleteUser(user.nickname, getters.authHost, getters.token)
|
||||
const updatedUser = { ...user, deactivated: true }
|
||||
commit('SWAP_USER', updatedUser)
|
||||
},
|
||||
async FetchUsers({ commit, state, getters }, { page }) {
|
||||
const filters = Object.keys(state.filters).filter(filter => state.filters[filter]).join()
|
||||
const response = await fetchUsers(filters, getters.authHost, getters.token, page)
|
||||
|
@ -55,10 +79,11 @@ const users = {
|
|||
|
||||
loadUsers(commit, page, response.data)
|
||||
},
|
||||
async ToggleUserActivation({ commit, getters }, nickname) {
|
||||
const response = await toggleUserActivation(nickname, getters.authHost, getters.token)
|
||||
async RemoveTag({ commit, getters }, { users, tag }) {
|
||||
const nicknames = users.map(user => user.nickname)
|
||||
await untagUser(nicknames, [tag], getters.authHost, getters.token)
|
||||
|
||||
commit('SWAP_USER', response.data)
|
||||
commit('SWAP_USERS', users.map(user => ({ ...user, tags: user.tags.filter(userTag => userTag !== tag) })))
|
||||
},
|
||||
async SearchUsers({ commit, dispatch, state, getters }, { query, page }) {
|
||||
if (query.length === 0) {
|
||||
|
@ -74,6 +99,10 @@ const users = {
|
|||
loadUsers(commit, page, response.data)
|
||||
}
|
||||
},
|
||||
async ToggleUserActivation({ commit, getters }, nickname) {
|
||||
const { data } = await toggleUserActivation(nickname, getters.authHost, getters.token)
|
||||
commit('SWAP_USER', data)
|
||||
},
|
||||
async ToggleUsersFilter({ commit, dispatch, state }, filters) {
|
||||
const defaultFilters = {
|
||||
local: false,
|
||||
|
@ -85,10 +114,6 @@ const users = {
|
|||
commit('SET_USERS_FILTERS', currentFilters)
|
||||
dispatch('SearchUsers', { query: state.searchQuery, page: 1 })
|
||||
},
|
||||
async ClearFilters({ commit, dispatch, state }) {
|
||||
commit('CLEAR_USERS_FILTERS')
|
||||
dispatch('SearchUsers', { query: state.searchQuery, page: 1 })
|
||||
},
|
||||
async ToggleRight({ commit, getters }, { user, right }) {
|
||||
user.roles[right]
|
||||
? await deleteRight(user.nickname, right, getters.authHost, getters.token)
|
||||
|
@ -96,22 +121,6 @@ const users = {
|
|||
|
||||
const updatedUser = { ...user, roles: { ...user.roles, [right]: !user.roles[right] }}
|
||||
commit('SWAP_USER', updatedUser)
|
||||
},
|
||||
async DeleteUser({ commit, getters }, user) {
|
||||
await deleteUser(user.nickname, getters.authHost, getters.token)
|
||||
const updatedUser = { ...user, deactivated: true }
|
||||
commit('SWAP_USER', updatedUser)
|
||||
},
|
||||
async ToggleTag({ commit, getters }, { user, tag }) {
|
||||
if (user.tags.includes(tag)) {
|
||||
await untagUser(user.nickname, tag, getters.authHost, getters.token)
|
||||
const updatedUser = { ...user, tags: user.tags.filter(userTag => userTag !== tag) }
|
||||
commit('SWAP_USER', updatedUser)
|
||||
} else {
|
||||
await tagUser(user.nickname, tag, getters.authHost, getters.token)
|
||||
const updatedUser = { ...user, tags: [...user.tags, tag] }
|
||||
commit('SWAP_USER', updatedUser)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,9 +159,18 @@ export default {
|
|||
this.$store.dispatch('FetchUsers', { page: 1 })
|
||||
},
|
||||
methods: {
|
||||
activationIcon(status) {
|
||||
return status ? 'el-icon-error' : 'el-icon-success'
|
||||
},
|
||||
getFirstLetter(str) {
|
||||
return str.charAt(0).toUpperCase()
|
||||
},
|
||||
handleDeactivation({ nickname }) {
|
||||
this.$store.dispatch('ToggleUserActivation', nickname)
|
||||
},
|
||||
handleDeletion(user) {
|
||||
this.$store.dispatch('DeleteUser', user)
|
||||
},
|
||||
handlePageChange(page) {
|
||||
const searchQuery = this.$store.state.users.searchQuery
|
||||
if (searchQuery === '') {
|
||||
|
@ -170,26 +179,19 @@ export default {
|
|||
this.$store.dispatch('SearchUsers', { query: searchQuery, page })
|
||||
}
|
||||
},
|
||||
showDeactivatedButton(id) {
|
||||
return this.$store.state.user.id !== id
|
||||
},
|
||||
showAdminAction({ local, id }) {
|
||||
return local && this.showDeactivatedButton(id)
|
||||
},
|
||||
activationIcon(status) {
|
||||
return status ? 'el-icon-error' : 'el-icon-success'
|
||||
showDeactivatedButton(id) {
|
||||
return this.$store.state.user.id !== id
|
||||
},
|
||||
toggleTag(user, tag) {
|
||||
user.tags.includes(tag)
|
||||
? this.$store.dispatch('RemoveTag', { users: [user], tag })
|
||||
: this.$store.dispatch('AddTag', { users: [user], tag })
|
||||
},
|
||||
toggleUserRight(user, right) {
|
||||
this.$store.dispatch('ToggleRight', { user, right })
|
||||
},
|
||||
handleDeletion(user) {
|
||||
this.$store.dispatch('DeleteUser', user)
|
||||
},
|
||||
toggleTag(user, tag) {
|
||||
this.$store.dispatch('ToggleTag', { user, tag })
|
||||
},
|
||||
getFirstLetter(str) {
|
||||
return str.charAt(0).toUpperCase()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue