diff --git a/src/api/__mocks__/users.js b/src/api/__mocks__/users.js
index 73a93174..b763c92d 100644
--- a/src/api/__mocks__/users.js
+++ b/src/api/__mocks__/users.js
@@ -1,11 +1,27 @@
const users = [
- { deactivated: false, id: '2', nickname: 'allis', local: true, roles: { admin: true, moderator: false }, tags: [] },
- { deactivated: false, id: '10', nickname: 'bob', local: false, roles: { admin: false, moderator: true }, tags: ['sandbox'] },
- { deactivated: true, id: 'abc', nickname: 'john', local: true, roles: { admin: false, moderator: false }, tags: ['strip_media'] }
+ { 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: true }, tags: ['sandbox'] },
+ { active: false, deactivated: true, id: 'abc', nickname: 'john', local: true, external: false, roles: { admin: false, moderator: false }, tags: ['strip_media'] }
]
-export async function fetchUsers(showLocalUsersOnly, authHost, token, page = 1) {
- const filteredUsers = showLocalUsersOnly ? users.filter(user => user.local) : users
+const filterUsers = (str) => {
+ const filters = str.split(',').filter(item => item.length > 0)
+ if (filters.length === 0) {
+ return users
+ }
+ const applyFilters = (acc, filters, users) => {
+ if (filters.length === 0) {
+ return acc
+ }
+ const filteredUsers = users.filter(user => user[filters[0]])
+ const newAcc = [...filteredUsers]
+ return applyFilters(newAcc, filters.slice(1), filteredUsers)
+ }
+ return applyFilters([], filters, users)
+}
+
+export async function fetchUsers(filters, authHost, token, page = 1) {
+ const filteredUsers = filterUsers(filters)
return Promise.resolve({ data: {
users: filteredUsers,
count: filteredUsers.length,
@@ -18,8 +34,8 @@ export async function toggleUserActivation(nickname, authHost, token) {
return Promise.resolve({ data: { ...response, deactivated: !response.deactivated }})
}
-export async function searchUsers(query, showLocalUsersOnly, authHost, token, page = 1) {
- const filteredUsers = showLocalUsersOnly ? users.filter(user => user.local) : users
+export async function searchUsers(query, filters, authHost, token, page = 1) {
+ const filteredUsers = filterUsers(filters)
const response = filteredUsers.filter(user => user.nickname === query)
return Promise.resolve({ data: {
users: response,
diff --git a/src/api/users.js b/src/api/users.js
index 2ec6a2ab..4b26c162 100644
--- a/src/api/users.js
+++ b/src/api/users.js
@@ -2,10 +2,10 @@ import request from '@/utils/request'
import { getToken } from '@/utils/auth'
import { baseName } from './utils'
-export async function fetchUsers(showLocalUsersOnly, authHost, token, page = 1) {
+export async function fetchUsers(filters, authHost, token, page = 1) {
return await request({
baseURL: baseName(authHost),
- url: `/api/pleroma/admin/users?page=${page}&local_only=${showLocalUsersOnly}`,
+ url: `/api/pleroma/admin/users?page=${page}&filters=${filters}`,
method: 'get',
headers: authHeaders(token)
})
@@ -20,10 +20,10 @@ export async function toggleUserActivation(nickname, authHost, token) {
})
}
-export async function searchUsers(query, showLocalUsersOnly, authHost, token, page = 1) {
+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}&local_only=${showLocalUsersOnly}`,
+ url: `/api/pleroma/admin/users?query=${query}&page=${page}&filters=${filters}`,
method: 'get',
headers: authHeaders(token)
})
diff --git a/src/lang/en.js b/src/lang/en.js
index 1c4097e7..4ec4b96c 100644
--- a/src/lang/en.js
+++ b/src/lang/en.js
@@ -189,5 +189,14 @@ export default {
sandbox: 'Force posts to be followers-only',
disableRemoteSubscription: 'Disallow following user from remote instances',
disableAnySubscription: 'Disallow following user at all'
+ },
+ usersFilter: {
+ inputPlaceholder: 'Select filter',
+ byUserType: 'By user type',
+ local: 'Local',
+ external: 'External',
+ byStatus: 'By status',
+ active: 'Active',
+ deactivated: 'Deactivated'
}
}
diff --git a/src/store/modules/users.js b/src/store/modules/users.js
index 09854c59..56eb07a0 100644
--- a/src/store/modules/users.js
+++ b/src/store/modules/users.js
@@ -7,7 +7,12 @@ const users = {
searchQuery: '',
totalUsersCount: 0,
currentPage: 1,
- showLocalUsersOnly: false
+ filters: {
+ local: false,
+ external: false,
+ active: false,
+ deactivated: false
+ }
},
mutations: {
SET_USERS: (state, users) => {
@@ -37,13 +42,14 @@ const users = {
SET_SEARCH_QUERY: (state, query) => {
state.searchQuery = query
},
- SET_LOCAL_USERS_FILTER: (state, value) => {
- state.showLocalUsersOnly = value
+ SET_USERS_FILTERS: (state, filters) => {
+ state.filters = filters
}
},
actions: {
async FetchUsers({ commit, state, getters }, { page }) {
- const response = await fetchUsers(state.showLocalUsersOnly, getters.authHost, getters.token, page)
+ const filters = Object.keys(state.filters).filter(filter => state.filters[filter]).join()
+ const response = await fetchUsers(filters, getters.authHost, getters.token, page)
commit('SET_LOADING', true)
@@ -62,13 +68,25 @@ const users = {
commit('SET_LOADING', true)
commit('SET_SEARCH_QUERY', query)
- const response = await searchUsers(query, state.showLocalUsersOnly, getters.authHost, getters.token, page)
+ const filters = Object.keys(state.filters).filter(filter => state.filters[filter]).join()
+ const response = await searchUsers(query, filters, getters.authHost, getters.token, page)
loadUsers(commit, page, response.data)
}
},
- async ToggleLocalUsersFilter({ commit, dispatch, state }, value) {
- commit('SET_LOCAL_USERS_FILTER', value)
+ async ToggleUsersFilter({ commit, dispatch, state }, filters) {
+ const defaultFilters = {
+ local: false,
+ external: false,
+ active: false,
+ deactivated: false
+ }
+ const currentFilters = { ...defaultFilters, ...filters }
+ 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 }) {
diff --git a/src/views/users/components/UsersFilter.vue b/src/views/users/components/UsersFilter.vue
new file mode 100644
index 00000000..edb3d75d
--- /dev/null
+++ b/src/views/users/components/UsersFilter.vue
@@ -0,0 +1,72 @@
+
+