Updating to maintain the old worker API for deprecation purposes, but removing from frontend usage.
This commit is contained in:
parent
062d834950
commit
1efd77c790
|
@ -35,7 +35,7 @@
|
|||
|
||||
async function fetchUsers(page, search) {
|
||||
try {
|
||||
await users.fetch({ page, search })
|
||||
await users.search({ page, search })
|
||||
pageInfo.fetched($users.hasNextPage, $users.nextPage)
|
||||
} catch (error) {
|
||||
notifications.error("Error getting user list")
|
||||
|
|
|
@ -6,8 +6,8 @@ export function createUsersStore() {
|
|||
const { subscribe, set } = writable({})
|
||||
|
||||
// opts can contain page and search params
|
||||
async function fetch(opts = {}) {
|
||||
const paged = await API.getUsers(opts)
|
||||
async function search(opts = {}) {
|
||||
const paged = await API.searchUsers(opts)
|
||||
set({
|
||||
...paged,
|
||||
...opts,
|
||||
|
@ -60,8 +60,8 @@ export function createUsersStore() {
|
|||
body.admin = { global: true }
|
||||
}
|
||||
await API.saveUser(body)
|
||||
// re-fetch from first page
|
||||
await fetch()
|
||||
// re-search from first page
|
||||
await search()
|
||||
}
|
||||
|
||||
async function del(id) {
|
||||
|
@ -75,7 +75,7 @@ export function createUsersStore() {
|
|||
|
||||
return {
|
||||
subscribe,
|
||||
fetch,
|
||||
search,
|
||||
get,
|
||||
invite,
|
||||
acceptInvite,
|
||||
|
|
|
@ -1,10 +1,19 @@
|
|||
export const buildUserEndpoints = API => ({
|
||||
/**
|
||||
* Gets a list of users in the current tenant.
|
||||
*/
|
||||
getUsers: async () => {
|
||||
return await API.get({
|
||||
url: "/api/global/users",
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets a list of users in the current tenant.
|
||||
* @param {string} page The page to retrieve
|
||||
* @param {string} search The starts with string to search username/email by.
|
||||
*/
|
||||
getUsers: async ({ page, search } = {}) => {
|
||||
searchUsers: async ({ page, search } = {}) => {
|
||||
const opts = {}
|
||||
if (page) {
|
||||
opts.page = page
|
||||
|
@ -12,9 +21,9 @@ export const buildUserEndpoints = API => ({
|
|||
if (search) {
|
||||
opts.search = search
|
||||
}
|
||||
const params = new URLSearchParams(opts)
|
||||
return await API.get({
|
||||
url: `/api/global/users?${params.toString()}`,
|
||||
return await API.post({
|
||||
url: `/api/global/users/search`,
|
||||
body: opts,
|
||||
})
|
||||
},
|
||||
|
||||
|
|
|
@ -3,22 +3,11 @@ const {
|
|||
getAllApps,
|
||||
getProdAppID,
|
||||
DocumentTypes,
|
||||
getGlobalUserParams,
|
||||
} = require("@budibase/backend-core/db")
|
||||
const { doInAppContext, getAppDB } = require("@budibase/backend-core/context")
|
||||
const { user: userCache } = require("@budibase/backend-core/cache")
|
||||
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
||||
|
||||
// TODO: this function needs to be removed and replaced
|
||||
export const allUsers = async () => {
|
||||
const db = getGlobalDB()
|
||||
const response = await db.allDocs(
|
||||
getGlobalUserParams(null, {
|
||||
include_docs: true,
|
||||
})
|
||||
)
|
||||
return response.rows.map(row => row.doc)
|
||||
}
|
||||
const { allUsers } = require("../../../sdk/users")
|
||||
|
||||
exports.fetch = async ctx => {
|
||||
const tenantId = ctx.user.tenantId
|
||||
|
|
|
@ -88,9 +88,8 @@ export const destroy = async (ctx: any) => {
|
|||
}
|
||||
}
|
||||
|
||||
// called internally by app server user fetch
|
||||
export const fetch = async (ctx: any) => {
|
||||
const paginated = await users.paginatedUsers(ctx.request.query)
|
||||
export const search = async (ctx: any) => {
|
||||
const paginated = await users.paginatedUsers(ctx.request.body)
|
||||
// user hashed password shouldn't ever be returned
|
||||
for (let user of paginated.data) {
|
||||
if (user) {
|
||||
|
@ -100,6 +99,18 @@ export const fetch = async (ctx: any) => {
|
|||
ctx.body = paginated
|
||||
}
|
||||
|
||||
// called internally by app server user fetch
|
||||
export const fetch = async (ctx: any) => {
|
||||
const all = await users.allUsers()
|
||||
// user hashed password shouldn't ever be returned
|
||||
for (let user of all) {
|
||||
if (user) {
|
||||
delete user.password
|
||||
}
|
||||
}
|
||||
ctx.body = all
|
||||
}
|
||||
|
||||
// called internally by app server user find
|
||||
export const find = async (ctx: any) => {
|
||||
ctx.body = await users.getUser(ctx.params.id)
|
||||
|
|
|
@ -46,6 +46,7 @@ router
|
|||
controller.save
|
||||
)
|
||||
.get("/api/global/users", builderOrAdmin, controller.fetch)
|
||||
.post("/api/global/users/search", builderOrAdmin, controller.search)
|
||||
.delete("/api/global/users/:id", adminOnly, controller.destroy)
|
||||
.get("/api/global/roles/:appId")
|
||||
.post(
|
||||
|
|
|
@ -19,6 +19,16 @@ import { MigrationType } from "@budibase/types"
|
|||
|
||||
const PAGE_LIMIT = 8
|
||||
|
||||
export const allUsers = async () => {
|
||||
const db = tenancy.getGlobalDB()
|
||||
const response = await db.allDocs(
|
||||
dbUtils.getGlobalUserParams(null, {
|
||||
include_docs: true,
|
||||
})
|
||||
)
|
||||
return response.rows.map((row: any) => row.doc)
|
||||
}
|
||||
|
||||
export const paginatedUsers = async ({
|
||||
page,
|
||||
search,
|
||||
|
|
Loading…
Reference in New Issue