Update API urls in accordance with new docs
This commit is contained in:
parent
2145acb4c4
commit
ca65a93e81
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) {
|
export async function addRight(nickname, right, authHost, token) {
|
||||||
return await request({
|
return await request({
|
||||||
baseURL: baseName(authHost),
|
baseURL: baseName(authHost),
|
||||||
url: `/api/pleroma/admin/permission_group/${nickname}/${right}`,
|
url: `/api/pleroma/admin/users/${nickname}/permission_group/${right}`,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
headers: authHeaders(token)
|
headers: authHeaders(token)
|
||||||
})
|
})
|
||||||
|
@ -41,7 +41,7 @@ export async function addRight(nickname, right, authHost, token) {
|
||||||
export async function deleteRight(nickname, right, authHost, token) {
|
export async function deleteRight(nickname, right, authHost, token) {
|
||||||
return await request({
|
return await request({
|
||||||
baseURL: baseName(authHost),
|
baseURL: baseName(authHost),
|
||||||
url: `/api/pleroma/admin/permission_group/${nickname}/${right}`,
|
url: `/api/pleroma/admin/users/${nickname}/permission_group/${right}`,
|
||||||
method: 'delete',
|
method: 'delete',
|
||||||
headers: authHeaders(token)
|
headers: authHeaders(token)
|
||||||
})
|
})
|
||||||
|
@ -50,29 +50,29 @@ export async function deleteRight(nickname, right, authHost, token) {
|
||||||
export async function deleteUser(nickname, authHost, token) {
|
export async function deleteUser(nickname, authHost, token) {
|
||||||
return await request({
|
return await request({
|
||||||
baseURL: baseName(authHost),
|
baseURL: baseName(authHost),
|
||||||
url: `/api/pleroma/admin/user.json?nickname=${nickname}`,
|
url: `/api/pleroma/admin/users?nickname=${nickname}`,
|
||||||
method: 'delete',
|
method: 'delete',
|
||||||
headers: authHeaders(token)
|
headers: authHeaders(token)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function tagUser(nickname, tag, authHost, token) {
|
export async function tagUser(nicknames, tags, authHost, token) {
|
||||||
return await request({
|
return await request({
|
||||||
baseURL: baseName(authHost),
|
baseURL: baseName(authHost),
|
||||||
url: '/api/pleroma/admin/users/tag',
|
url: '/api/pleroma/admin/users/tag',
|
||||||
method: 'put',
|
method: 'put',
|
||||||
headers: authHeaders(token),
|
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({
|
return await request({
|
||||||
baseURL: baseName(authHost),
|
baseURL: baseName(authHost),
|
||||||
url: '/api/pleroma/admin/users/tag',
|
url: '/api/pleroma/admin/users/tag',
|
||||||
method: 'delete',
|
method: 'delete',
|
||||||
headers: authHeaders(token),
|
headers: authHeaders(token),
|
||||||
data: { nicknames: [nickname], tags: [tag] }
|
data: { nicknames, tags }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,15 @@ const users = {
|
||||||
a.nickname.localeCompare(b.nickname)
|
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) => {
|
SET_COUNT: (state, count) => {
|
||||||
state.totalUsersCount = count
|
state.totalUsersCount = count
|
||||||
},
|
},
|
||||||
|
@ -47,6 +56,21 @@ const users = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
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 }) {
|
async FetchUsers({ commit, state, getters }, { page }) {
|
||||||
const filters = Object.keys(state.filters).filter(filter => state.filters[filter]).join()
|
const filters = Object.keys(state.filters).filter(filter => state.filters[filter]).join()
|
||||||
const response = await fetchUsers(filters, getters.authHost, getters.token, page)
|
const response = await fetchUsers(filters, getters.authHost, getters.token, page)
|
||||||
|
@ -55,10 +79,11 @@ const users = {
|
||||||
|
|
||||||
loadUsers(commit, page, response.data)
|
loadUsers(commit, page, response.data)
|
||||||
},
|
},
|
||||||
async ToggleUserActivation({ commit, getters }, nickname) {
|
async RemoveTag({ commit, getters }, { users, tag }) {
|
||||||
const response = await toggleUserActivation(nickname, getters.authHost, getters.token)
|
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 }) {
|
async SearchUsers({ commit, dispatch, state, getters }, { query, page }) {
|
||||||
if (query.length === 0) {
|
if (query.length === 0) {
|
||||||
|
@ -74,6 +99,10 @@ const users = {
|
||||||
loadUsers(commit, page, response.data)
|
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) {
|
async ToggleUsersFilter({ commit, dispatch, state }, filters) {
|
||||||
const defaultFilters = {
|
const defaultFilters = {
|
||||||
local: false,
|
local: false,
|
||||||
|
@ -85,10 +114,6 @@ const users = {
|
||||||
commit('SET_USERS_FILTERS', currentFilters)
|
commit('SET_USERS_FILTERS', currentFilters)
|
||||||
dispatch('SearchUsers', { query: state.searchQuery, page: 1 })
|
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 }) {
|
async ToggleRight({ commit, getters }, { user, right }) {
|
||||||
user.roles[right]
|
user.roles[right]
|
||||||
? await deleteRight(user.nickname, right, getters.authHost, getters.token)
|
? 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] }}
|
const updatedUser = { ...user, roles: { ...user.roles, [right]: !user.roles[right] }}
|
||||||
commit('SWAP_USER', updatedUser)
|
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 })
|
this.$store.dispatch('FetchUsers', { page: 1 })
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
activationIcon(status) {
|
||||||
|
return status ? 'el-icon-error' : 'el-icon-success'
|
||||||
|
},
|
||||||
|
getFirstLetter(str) {
|
||||||
|
return str.charAt(0).toUpperCase()
|
||||||
|
},
|
||||||
handleDeactivation({ nickname }) {
|
handleDeactivation({ nickname }) {
|
||||||
this.$store.dispatch('ToggleUserActivation', nickname)
|
this.$store.dispatch('ToggleUserActivation', nickname)
|
||||||
},
|
},
|
||||||
|
handleDeletion(user) {
|
||||||
|
this.$store.dispatch('DeleteUser', user)
|
||||||
|
},
|
||||||
handlePageChange(page) {
|
handlePageChange(page) {
|
||||||
const searchQuery = this.$store.state.users.searchQuery
|
const searchQuery = this.$store.state.users.searchQuery
|
||||||
if (searchQuery === '') {
|
if (searchQuery === '') {
|
||||||
|
@ -170,26 +179,19 @@ export default {
|
||||||
this.$store.dispatch('SearchUsers', { query: searchQuery, page })
|
this.$store.dispatch('SearchUsers', { query: searchQuery, page })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
showDeactivatedButton(id) {
|
|
||||||
return this.$store.state.user.id !== id
|
|
||||||
},
|
|
||||||
showAdminAction({ local, id }) {
|
showAdminAction({ local, id }) {
|
||||||
return local && this.showDeactivatedButton(id)
|
return local && this.showDeactivatedButton(id)
|
||||||
},
|
},
|
||||||
activationIcon(status) {
|
showDeactivatedButton(id) {
|
||||||
return status ? 'el-icon-error' : 'el-icon-success'
|
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) {
|
toggleUserRight(user, right) {
|
||||||
this.$store.dispatch('ToggleRight', { 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