Updating per review comments.
This commit is contained in:
parent
472af5d4e5
commit
51b6687262
|
@ -259,6 +259,24 @@ exports.getAllApps = async (CouchDB, { dev, all, idsOnly } = {}) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility function for getAllApps but filters to production apps only.
|
||||||
|
*/
|
||||||
|
exports.getDeployedAppIDs = async CouchDB => {
|
||||||
|
return (await exports.getAllApps(CouchDB, { idsOnly: true })).filter(
|
||||||
|
id => !exports.isDevAppID(id)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility function for the inverse of above.
|
||||||
|
*/
|
||||||
|
exports.getDevAppIDs = async CouchDB => {
|
||||||
|
return (await exports.getAllApps(CouchDB, { idsOnly: true })).filter(id =>
|
||||||
|
exports.isDevAppID(id)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
exports.dbExists = async (CouchDB, dbName) => {
|
exports.dbExists = async (CouchDB, dbName) => {
|
||||||
let exists = false
|
let exists = false
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -8,11 +8,7 @@ const { getGlobalUsers, getRawGlobalUser } = require("../../utilities/global")
|
||||||
const { getFullUser } = require("../../utilities/users")
|
const { getFullUser } = require("../../utilities/users")
|
||||||
const { isEqual } = require("lodash")
|
const { isEqual } = require("lodash")
|
||||||
const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles")
|
const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles")
|
||||||
const {
|
const { getDevelopmentAppID, getDeployedAppIDs } = require("@budibase/auth/db")
|
||||||
getDevelopmentAppID,
|
|
||||||
getAllApps,
|
|
||||||
isDevAppID,
|
|
||||||
} = require("@budibase/auth/db")
|
|
||||||
const { doesDatabaseExist } = require("../../utilities")
|
const { doesDatabaseExist } = require("../../utilities")
|
||||||
const { UserStatus } = require("@budibase/auth/constants")
|
const { UserStatus } = require("@budibase/auth/constants")
|
||||||
|
|
||||||
|
@ -78,8 +74,12 @@ exports.syncUser = async function (ctx) {
|
||||||
try {
|
try {
|
||||||
user = await getRawGlobalUser(userId)
|
user = await getRawGlobalUser(userId)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
user = {}
|
if (err && err.status === 404) {
|
||||||
deleting = true
|
user = {}
|
||||||
|
deleting = true
|
||||||
|
} else {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const roles = user.roles
|
const roles = user.roles
|
||||||
// remove props which aren't useful to metadata
|
// remove props which aren't useful to metadata
|
||||||
|
@ -90,9 +90,7 @@ exports.syncUser = async function (ctx) {
|
||||||
let prodAppIds
|
let prodAppIds
|
||||||
// if they are a builder then get all production app IDs
|
// if they are a builder then get all production app IDs
|
||||||
if ((user.builder && user.builder.global) || deleting) {
|
if ((user.builder && user.builder.global) || deleting) {
|
||||||
prodAppIds = (await getAllApps(CouchDB, { idsOnly: true })).filter(
|
prodAppIds = await getDeployedAppIDs(CouchDB)
|
||||||
id => !isDevAppID(id)
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
prodAppIds = Object.entries(roles)
|
prodAppIds = Object.entries(roles)
|
||||||
.filter(entry => entry[1] !== BUILTIN_ROLE_IDS.PUBLIC)
|
.filter(entry => entry[1] !== BUILTIN_ROLE_IDS.PUBLIC)
|
||||||
|
|
|
@ -35,7 +35,7 @@ router
|
||||||
controller.destroyMetadata
|
controller.destroyMetadata
|
||||||
)
|
)
|
||||||
.post(
|
.post(
|
||||||
"/api/users/sync/:id",
|
"/api/users/metadata/sync/:id",
|
||||||
authorized(PermissionTypes.USER, PermissionLevels.WRITE),
|
authorized(PermissionTypes.USER, PermissionLevels.WRITE),
|
||||||
controller.syncUser
|
controller.syncUser
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,7 +4,7 @@ const { getTenantId, isTenantIdSet } = require("@budibase/auth/tenancy")
|
||||||
const { checkSlashesInUrl } = require("../utilities")
|
const { checkSlashesInUrl } = require("../utilities")
|
||||||
const env = require("../environment")
|
const env = require("../environment")
|
||||||
|
|
||||||
exports.syncUserInApps = async userId => {
|
async function makeAppRequest(url, method, body) {
|
||||||
if (env.isTest()) {
|
if (env.isTest()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,19 @@ exports.syncUserInApps = async userId => {
|
||||||
if (isTenantIdSet()) {
|
if (isTenantIdSet()) {
|
||||||
request.headers[Headers.TENANT_ID] = getTenantId()
|
request.headers[Headers.TENANT_ID] = getTenantId()
|
||||||
}
|
}
|
||||||
request.headers["Content-Type"] = "application/json"
|
if (body) {
|
||||||
request.body = JSON.stringify({})
|
request.headers["Content-Type"] = "application/json"
|
||||||
request.method = "POST"
|
request.body = JSON.stringify(body)
|
||||||
const response = await fetch(
|
}
|
||||||
checkSlashesInUrl(env.APPS_URL + `/api/users/sync/${userId}`),
|
request.method = method
|
||||||
request
|
return fetch(checkSlashesInUrl(env.APPS_URL + url), request)
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.syncUserInApps = async userId => {
|
||||||
|
const response = await makeAppRequest(
|
||||||
|
`/api/users/metadata/sync/${userId}`,
|
||||||
|
"POST",
|
||||||
|
{}
|
||||||
)
|
)
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
throw "Unable to sync user."
|
throw "Unable to sync user."
|
||||||
|
|
Loading…
Reference in New Issue