|
|
|
@ -9,19 +9,26 @@ function getAppRole(appId, user) { |
|
|
|
if (!user.roles) { |
|
|
|
return user |
|
|
|
} |
|
|
|
// always use the deployed app
|
|
|
|
user.roleId = user.roles[getDeployedAppID(appId)] |
|
|
|
if (!user.roleId) { |
|
|
|
user.roleId = BUILTIN_ROLE_IDS.PUBLIC |
|
|
|
if (user.builder && user.builder.global) { |
|
|
|
user.roleId = BUILTIN_ROLE_IDS.ADMIN |
|
|
|
} else { |
|
|
|
// always use the deployed app
|
|
|
|
user.roleId = user.roles[getDeployedAppID(appId)] |
|
|
|
if (!user.roleId) { |
|
|
|
user.roleId = BUILTIN_ROLE_IDS.PUBLIC |
|
|
|
} |
|
|
|
} |
|
|
|
delete user.roles |
|
|
|
return user |
|
|
|
} |
|
|
|
|
|
|
|
function request(ctx, request) { |
|
|
|
function request(ctx, request, noApiKey) { |
|
|
|
if (!request.headers) { |
|
|
|
request.headers = {} |
|
|
|
} |
|
|
|
if (!noApiKey) { |
|
|
|
request.headers["x-budibase-api-key"] = env.INTERNAL_API_KEY |
|
|
|
} |
|
|
|
if (request.body && Object.keys(request.body).length > 0) { |
|
|
|
request.headers["Content-Type"] = "application/json" |
|
|
|
request.body = |
|
|
|
@ -44,9 +51,6 @@ exports.sendSmtpEmail = async (to, from, subject, contents) => { |
|
|
|
checkSlashesInUrl(env.WORKER_URL + `/api/admin/email/send`), |
|
|
|
request(null, { |
|
|
|
method: "POST", |
|
|
|
headers: { |
|
|
|
"x-budibase-api-key": env.INTERNAL_API_KEY, |
|
|
|
}, |
|
|
|
body: { |
|
|
|
email: to, |
|
|
|
from, |
|
|
|
@ -86,16 +90,6 @@ exports.getDeployedApps = async ctx => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
exports.deleteGlobalUser = async (ctx, globalId) => { |
|
|
|
const endpoint = `/api/admin/users/${globalId}` |
|
|
|
const reqCfg = { method: "DELETE" } |
|
|
|
const response = await fetch( |
|
|
|
checkSlashesInUrl(env.WORKER_URL + endpoint), |
|
|
|
request(ctx, reqCfg) |
|
|
|
) |
|
|
|
return response.json() |
|
|
|
} |
|
|
|
|
|
|
|
exports.getGlobalUsers = async (ctx, appId = null, globalId = null) => { |
|
|
|
const endpoint = globalId |
|
|
|
? `/api/admin/users/${globalId}` |
|
|
|
@ -121,7 +115,8 @@ exports.getGlobalSelf = async (ctx, appId = null) => { |
|
|
|
const endpoint = `/api/admin/users/self` |
|
|
|
const response = await fetch( |
|
|
|
checkSlashesInUrl(env.WORKER_URL + endpoint), |
|
|
|
request(ctx, { method: "GET" }) |
|
|
|
// we don't want to use API key when getting self
|
|
|
|
request(ctx, { method: "GET" }, true) |
|
|
|
) |
|
|
|
if (response.status !== 200) { |
|
|
|
ctx.throw(400, "Unable to get self globally.") |
|
|
|
@ -172,9 +167,6 @@ exports.removeAppFromUserRoles = async appId => { |
|
|
|
checkSlashesInUrl(env.WORKER_URL + `/api/admin/roles/${deployedAppId}`), |
|
|
|
request(null, { |
|
|
|
method: "DELETE", |
|
|
|
headers: { |
|
|
|
"x-budibase-api-key": env.INTERNAL_API_KEY, |
|
|
|
}, |
|
|
|
}) |
|
|
|
) |
|
|
|
if (response.status !== 200) { |
|
|
|
|