Merge pull request #24728 from nextcloud/backport/24721/stable20
[stable20] Cancel user search requests to avoid duplicate results being added
This commit is contained in:
commit
fc327ee9de
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -63,8 +63,8 @@ export default {
|
||||||
requireAdmin() {
|
requireAdmin() {
|
||||||
return confirmPassword()
|
return confirmPassword()
|
||||||
},
|
},
|
||||||
get(url) {
|
get(url, options) {
|
||||||
return axios.get(sanitize(url))
|
return axios.get(sanitize(url), options)
|
||||||
},
|
},
|
||||||
post(url, data) {
|
post(url, data) {
|
||||||
return axios.post(sanitize(url), data)
|
return axios.post(sanitize(url), data)
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import api from './api'
|
import api from './api'
|
||||||
|
import axios from '@nextcloud/axios'
|
||||||
import { generateOcsUrl } from '@nextcloud/router'
|
import { generateOcsUrl } from '@nextcloud/router'
|
||||||
|
|
||||||
const orderGroups = function(groups, orderBy) {
|
const orderGroups = function(groups, orderBy) {
|
||||||
|
@ -189,6 +190,9 @@ const getters = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CancelToken = axios.CancelToken
|
||||||
|
let searchRequestCancelSource = null
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -203,29 +207,45 @@ const actions = {
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
getUsers(context, { offset, limit, search, group }) {
|
getUsers(context, { offset, limit, search, group }) {
|
||||||
|
if (searchRequestCancelSource) {
|
||||||
|
searchRequestCancelSource.cancel('Operation canceled by another search request.')
|
||||||
|
}
|
||||||
|
searchRequestCancelSource = CancelToken.source()
|
||||||
search = typeof search === 'string' ? search : ''
|
search = typeof search === 'string' ? search : ''
|
||||||
group = typeof group === 'string' ? group : ''
|
group = typeof group === 'string' ? group : ''
|
||||||
if (group !== '') {
|
if (group !== '') {
|
||||||
return api.get(generateOcsUrl(`cloud/groups/${encodeURIComponent(encodeURIComponent(group))}/users/details?offset=${offset}&limit=${limit}&search=${search}`, 2))
|
return api.get(generateOcsUrl(`cloud/groups/${encodeURIComponent(encodeURIComponent(group))}/users/details?offset=${offset}&limit=${limit}&search=${search}`, 2), {
|
||||||
|
cancelToken: searchRequestCancelSource.token,
|
||||||
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (Object.keys(response.data.ocs.data.users).length > 0) {
|
if (Object.keys(response.data.ocs.data.users).length > 0) {
|
||||||
context.commit('appendUsers', response.data.ocs.data.users)
|
context.commit('appendUsers', response.data.ocs.data.users)
|
||||||
return true
|
return Object.keys(response.data.ocs.data.users).length === limit
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
.catch((error) => context.commit('API_FAILURE', error))
|
.catch((error) => {
|
||||||
|
if (!axios.isCancel(error)) {
|
||||||
|
context.commit('API_FAILURE', error)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return api.get(generateOcsUrl(`cloud/users/details?offset=${offset}&limit=${limit}&search=${search}`, 2))
|
return api.get(generateOcsUrl(`cloud/users/details?offset=${offset}&limit=${limit}&search=${search}`, 2), {
|
||||||
|
cancelToken: searchRequestCancelSource.token,
|
||||||
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (Object.keys(response.data.ocs.data.users).length > 0) {
|
if (Object.keys(response.data.ocs.data.users).length > 0) {
|
||||||
context.commit('appendUsers', response.data.ocs.data.users)
|
context.commit('appendUsers', response.data.ocs.data.users)
|
||||||
return true
|
return Object.keys(response.data.ocs.data.users).length === limit
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
.catch((error) => context.commit('API_FAILURE', error))
|
.catch((error) => {
|
||||||
|
if (!axios.isCancel(error)) {
|
||||||
|
context.commit('API_FAILURE', error)
|
||||||
|
}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
getGroups(context, { offset, limit, search }) {
|
getGroups(context, { offset, limit, search }) {
|
||||||
|
|
Loading…
Reference in New Issue