Remove users that should not be there anymore when syncGlobalUsers
This commit is contained in:
parent
0257617ba1
commit
e25429632b
|
@ -6,25 +6,33 @@ import {
|
|||
InternalTables,
|
||||
} from "../../db/utils"
|
||||
import { isEqual } from "lodash"
|
||||
import { ContextUser, UserMetadata } from "@budibase/types"
|
||||
|
||||
export function combineMetadataAndUser(user: any, metadata: any) {
|
||||
export function combineMetadataAndUser(
|
||||
user: ContextUser,
|
||||
metadata: UserMetadata | UserMetadata[]
|
||||
) {
|
||||
const metadataId = generateUserMetadataID(user._id!)
|
||||
const found = Array.isArray(metadata)
|
||||
? metadata.find(doc => doc._id === metadataId)
|
||||
: metadata
|
||||
// skip users with no access
|
||||
if (
|
||||
user.roleId == null ||
|
||||
user.roleId === rolesCore.BUILTIN_ROLE_IDS.PUBLIC
|
||||
) {
|
||||
// If it exists and it should not, we must remove it
|
||||
if (found) {
|
||||
return { ...found, _deleted: true }
|
||||
}
|
||||
return null
|
||||
}
|
||||
delete user._rev
|
||||
const metadataId = generateUserMetadataID(user._id)
|
||||
const newDoc = {
|
||||
...user,
|
||||
_id: metadataId,
|
||||
tableId: InternalTables.USER_METADATA,
|
||||
}
|
||||
const found = Array.isArray(metadata)
|
||||
? metadata.find(doc => doc._id === metadataId)
|
||||
: metadata
|
||||
// copy rev over for the purposes of equality check
|
||||
if (found) {
|
||||
newDoc._rev = found._rev
|
||||
|
@ -58,7 +66,7 @@ export async function syncGlobalUsers() {
|
|||
])
|
||||
const toWrite = []
|
||||
for (let user of users) {
|
||||
const combined = await combineMetadataAndUser(user, metadata)
|
||||
const combined = combineMetadataAndUser(user, metadata)
|
||||
if (combined) {
|
||||
toWrite.push(combined)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue