diff --git a/packages/builder/src/pages/builder/portal/overview/_components/AccessTab.svelte b/packages/builder/src/pages/builder/portal/overview/_components/AccessTab.svelte
index 258ef08f06..2329a796bc 100644
--- a/packages/builder/src/pages/builder/portal/overview/_components/AccessTab.svelte
+++ b/packages/builder/src/pages/builder/portal/overview/_components/AccessTab.svelte
@@ -16,54 +16,34 @@
import RoleSelect from "components/common/RoleSelect.svelte"
import { users, groups, apps, auth } from "stores/portal"
import AssignmentModal from "./AssignmentModal.svelte"
- import { createPaginationStore } from "helpers/pagination"
import { roles } from "stores/backend"
+ import { API } from "api"
+ import { fetchData } from "@budibase/frontend-core"
export let app
+ const usersFetch = fetchData({
+ API,
+ datasource: {
+ type: "user",
+ },
+ options: {
+ query: {
+ appId: apps.getProdAppID(app.devId),
+ },
+ },
+ })
+
let assignmentModal
let appGroups = []
let appUsers = []
- let prevSearch = undefined,
- search = undefined
- let pageInfo = createPaginationStore()
- let fixedAppId
- $: page = $pageInfo.page
$: fixedAppId = apps.getProdAppID(app.devId)
+ $: appUsers = $usersFetch.rows
$: appGroups = $groups.filter(x => {
return x.apps.includes(app.appId)
})
- async function addData(appData) {
- let gr_prefix = "gr"
- let us_prefix = "us"
- appData.forEach(async data => {
- if (data.id.startsWith(gr_prefix)) {
- let matchedGroup = $groups.find(group => {
- return group._id === data.id
- })
- matchedGroup.apps.push(app.appId)
- matchedGroup.roles[fixedAppId] = data.role
-
- groups.actions.save(matchedGroup)
- } else if (data.id.startsWith(us_prefix)) {
- let matchedUser = $users.data.find(user => {
- return user._id === data.id
- })
-
- let newUser = {
- ...matchedUser,
- roles: { [fixedAppId]: data.role, ...matchedUser.roles },
- }
-
- await users.save(newUser, { opts: { appId: fixedAppId } })
- await fetchUsers(page, search)
- }
- })
- await groups.actions.init()
- }
-
async function removeUser(user) {
// Remove the user role
const filteredRoles = { ...user.roles }
@@ -74,65 +54,35 @@
...filteredRoles,
},
})
- await fetchUsers(page, search)
+ await usersFetch.refresh()
}
async function removeGroup(group) {
- // Remove the user role
- let filteredApps = group.apps.filter(
+ const filteredApps = group.apps.filter(
x => apps.extractAppId(x) !== app.appId
)
const filteredRoles = { ...group.roles }
delete filteredRoles[fixedAppId]
-
await groups.actions.save({
...group,
apps: filteredApps,
roles: { ...filteredRoles },
})
-
- await fetchUsers(page, search)
+ await usersFetch.refresh()
}
async function updateUserRole(role, user) {
user.roles[fixedAppId] = role
- users.save(user)
+ await users.save(user)
}
async function updateGroupRole(role, group) {
group.roles[fixedAppId] = role
- groups.actions.save(group)
- }
-
- async function fetchUsers(page, search) {
- if ($pageInfo.loading) {
- return
- }
- // need to remove the page if they've started searching
- if (search && !prevSearch) {
- pageInfo.reset()
- page = undefined
- }
- prevSearch = search
- try {
- pageInfo.loading()
- await users.search({ page, appId: fixedAppId })
- pageInfo.fetched($users.hasNextPage, $users.nextPage)
- appUsers =
- $users.data?.filter(x => {
- return Object.keys(x.roles).find(y => {
- return y === fixedAppId
- })
- }) || []
- } catch (error) {
- notifications.error("Error getting user list")
- }
+ await groups.actions.save(group)
}
onMount(async () => {
try {
- await fetchUsers(page, search)
-
await groups.actions.init()
await apps.load()
await roles.fetch()
@@ -149,11 +99,11 @@