Merge branch 'feat/user-groups-tab' of github.com:Budibase/budibase into feat/user-groups-tab
This commit is contained in:
commit
10e046d8a2
|
@ -8,12 +8,10 @@
|
|||
Layout,
|
||||
} from "@budibase/bbui"
|
||||
import { groups, auth } from "stores/portal"
|
||||
import { createEventDispatcher } from "svelte"
|
||||
import { Constants } from "@budibase/frontend-core"
|
||||
|
||||
export let showOnboardingTypeModal
|
||||
const password = Math.random().toString(36).substring(2, 22)
|
||||
const dispatch = createEventDispatcher()
|
||||
let disabled
|
||||
let userGroups = []
|
||||
|
||||
|
@ -41,10 +39,8 @@
|
|||
</script>
|
||||
|
||||
<ModalContent
|
||||
onConfirm={() => {
|
||||
showOnboardingTypeModal()
|
||||
dispatch("change", { users: userData, groups: userGroups })
|
||||
}}
|
||||
onConfirm={async () =>
|
||||
showOnboardingTypeModal({ users: userData, groups: userGroups })}
|
||||
size="M"
|
||||
title="Add new user"
|
||||
confirmText="Add user"
|
||||
|
|
|
@ -112,12 +112,15 @@
|
|||
}
|
||||
})
|
||||
}
|
||||
function showOnboardingTypeModal() {
|
||||
const showOnboardingTypeModal = async addUsersData => {
|
||||
userData = await removingDuplicities(addUsersData)
|
||||
if (!userData?.users?.length) return
|
||||
|
||||
onboardingTypeModal.show()
|
||||
}
|
||||
|
||||
async function createUserFlow() {
|
||||
let emails = userData.map(x => x.email)
|
||||
let emails = userData?.users?.map(x => x.email) || []
|
||||
try {
|
||||
const res = await users.invite({
|
||||
emails: emails,
|
||||
|
@ -132,8 +135,29 @@
|
|||
}
|
||||
}
|
||||
|
||||
const removingDuplicities = async userData => {
|
||||
const currentUserEmails = (await users.fetch())?.map(x => x.email) || []
|
||||
const newUsers = []
|
||||
|
||||
for (const user of userData?.users) {
|
||||
const { email } = user
|
||||
|
||||
if (
|
||||
newUsers.find(x => x.email === email) ||
|
||||
currentUserEmails.includes(email)
|
||||
)
|
||||
continue
|
||||
|
||||
newUsers.push(user)
|
||||
}
|
||||
|
||||
if (!newUsers.length)
|
||||
notifications.info("Duplicated! There is no new users to add.")
|
||||
return { ...userData, users: newUsers }
|
||||
}
|
||||
|
||||
const createUsersFromCsv = async userCsvData => {
|
||||
const { userEmails, usersRole, userGroups } = userCsvData
|
||||
const { userEmails, usersRole, userGroups: groups } = userCsvData
|
||||
|
||||
const users = []
|
||||
for (const email of userEmails) {
|
||||
|
@ -147,13 +171,15 @@
|
|||
users.push(newUser)
|
||||
}
|
||||
|
||||
userData = { groups: userGroups, users: users }
|
||||
userData = await removingDuplicities({ groups, users })
|
||||
if (!userData.users.length) return
|
||||
|
||||
return createUser()
|
||||
}
|
||||
|
||||
async function createUser() {
|
||||
try {
|
||||
await users.create(userData)
|
||||
await users.create(await removingDuplicities(userData))
|
||||
notifications.success("Successfully created user")
|
||||
await groups.actions.init()
|
||||
passwordModal.show()
|
||||
|
@ -272,14 +298,7 @@
|
|||
</Layout>
|
||||
|
||||
<Modal bind:this={createUserModal}>
|
||||
<AddUserModal
|
||||
on:change={e => (userData = e.detail)}
|
||||
on:created={async () => {
|
||||
pageInfo.reset()
|
||||
await fetchUsers()
|
||||
}}
|
||||
{showOnboardingTypeModal}
|
||||
/>
|
||||
<AddUserModal {showOnboardingTypeModal} />
|
||||
</Modal>
|
||||
|
||||
<Modal bind:this={inviteConfirmationModal}>
|
||||
|
|
|
@ -23,6 +23,10 @@ export function createUsersStore() {
|
|||
}
|
||||
}
|
||||
|
||||
const fetch = async () => {
|
||||
return await API.getUsers()
|
||||
}
|
||||
|
||||
async function invite({ emails, builder, admin }) {
|
||||
return API.inviteUsers({
|
||||
emails,
|
||||
|
@ -87,6 +91,7 @@ export function createUsersStore() {
|
|||
subscribe,
|
||||
search,
|
||||
get,
|
||||
fetch,
|
||||
invite,
|
||||
acceptInvite,
|
||||
create,
|
||||
|
|
|
@ -23,10 +23,23 @@ export const save = async (ctx: any) => {
|
|||
}
|
||||
|
||||
export const bulkSave = async (ctx: any) => {
|
||||
let { users: newUsers, groups } = ctx.request.body
|
||||
let { users: newUsersRequested, groups } = ctx.request.body
|
||||
let usersToSave: any[] = []
|
||||
let groupsToSave: any[] = []
|
||||
const newUsers: any[] = []
|
||||
const db = tenancy.getGlobalDB()
|
||||
const currentUserEmails =
|
||||
(await users.allUsers())?.map((x: any) => x.email) || []
|
||||
|
||||
for (const newUser of newUsersRequested) {
|
||||
if (
|
||||
newUsers.find((x: any) => x.email === newUser.email) ||
|
||||
currentUserEmails.includes(newUser.email)
|
||||
)
|
||||
continue
|
||||
|
||||
newUsers.push(newUser)
|
||||
}
|
||||
|
||||
newUsers.forEach((user: any) => {
|
||||
usersToSave.push(
|
||||
|
|
Loading…
Reference in New Issue