PR comments (backend).
This commit is contained in:
parent
032d5b4f62
commit
dce38908c9
|
@ -71,27 +71,6 @@ export const bulkUpdateGlobalUsers = async (users: User[]) => {
|
||||||
return (await db.bulkDocs(users)) as BulkDocsResponse
|
return (await db.bulkDocs(users)) as BulkDocsResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
export const grantAppBuilderAccess = async (userId: string, appId: string) => {
|
|
||||||
const prodAppId = getProdAppID(appId)
|
|
||||||
const db = getGlobalDB()
|
|
||||||
const user = (await db.get(userId)) as User
|
|
||||||
if (!user.builder) {
|
|
||||||
user.builder = {}
|
|
||||||
}
|
|
||||||
if (!user.builder.apps) {
|
|
||||||
user.builder.apps = []
|
|
||||||
}
|
|
||||||
if (!user.builder.apps.includes(prodAppId)) {
|
|
||||||
user.builder.apps.push(prodAppId)
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
await db.put(user)
|
|
||||||
await userCache.invalidateUser(userId)
|
|
||||||
} catch (err: any) {
|
|
||||||
throw new Error(`Unable to grant user access: ${err.message}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getById(id: string, opts?: GetOpts): Promise<User> {
|
export async function getById(id: string, opts?: GetOpts): Promise<User> {
|
||||||
const db = context.getGlobalDB()
|
const db = context.getGlobalDB()
|
||||||
let user = await db.get<User>(id)
|
let user = await db.get<User>(id)
|
||||||
|
|
|
@ -56,7 +56,6 @@ import {
|
||||||
import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts"
|
import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts"
|
||||||
import sdk from "../../sdk"
|
import sdk from "../../sdk"
|
||||||
import { builderSocket } from "../../websockets"
|
import { builderSocket } from "../../websockets"
|
||||||
import { grantAppBuilderAccess } from "@budibase/backend-core/src/users"
|
|
||||||
|
|
||||||
// utility function, need to do away with this
|
// utility function, need to do away with this
|
||||||
async function getLayouts() {
|
async function getLayouts() {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { db as dbCore } from "@budibase/backend-core"
|
||||||
|
|
||||||
type Optional = string | null
|
type Optional = string | null
|
||||||
|
|
||||||
export enum AppStatus {
|
export const enum AppStatus {
|
||||||
DEV = "development",
|
DEV = "development",
|
||||||
ALL = "all",
|
ALL = "all",
|
||||||
DEPLOYED = "published",
|
DEPLOYED = "published",
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
import { env as coreEnv } from "@budibase/backend-core"
|
||||||
|
import { ServiceType } from "@budibase/types"
|
||||||
|
coreEnv._set("SERVICE_TYPE", ServiceType.APPS)
|
||||||
import { join } from "path"
|
import { join } from "path"
|
||||||
|
|
||||||
function isTest() {
|
function isTest() {
|
||||||
|
|
|
@ -4,7 +4,10 @@ const APP_PREFIX = prefixed(DocumentType.APP)
|
||||||
const APP_DEV_PREFIX = prefixed(DocumentType.APP_DEV)
|
const APP_DEV_PREFIX = prefixed(DocumentType.APP_DEV)
|
||||||
|
|
||||||
export function getDevAppID(appId: string) {
|
export function getDevAppID(appId: string) {
|
||||||
if (!appId || appId.startsWith(APP_DEV_PREFIX)) {
|
if (!appId) {
|
||||||
|
throw new Error("No app ID provided")
|
||||||
|
}
|
||||||
|
if (appId.startsWith(APP_DEV_PREFIX)) {
|
||||||
return appId
|
return appId
|
||||||
}
|
}
|
||||||
// split to take off the app_ element, then join it together incase any other app_ exist
|
// split to take off the app_ element, then join it together incase any other app_ exist
|
||||||
|
@ -18,7 +21,10 @@ export function getDevAppID(appId: string) {
|
||||||
* Convert a development app ID to a deployed app ID.
|
* Convert a development app ID to a deployed app ID.
|
||||||
*/
|
*/
|
||||||
export function getProdAppID(appId: string) {
|
export function getProdAppID(appId: string) {
|
||||||
if (!appId || !appId.startsWith(APP_DEV_PREFIX)) {
|
if (!appId) {
|
||||||
|
throw new Error("No app ID provided")
|
||||||
|
}
|
||||||
|
if (!appId.startsWith(APP_DEV_PREFIX)) {
|
||||||
return appId
|
return appId
|
||||||
}
|
}
|
||||||
// split to take off the app_dev element, then join it together incase any other app_ exist
|
// split to take off the app_dev element, then join it together incase any other app_ exist
|
||||||
|
|
|
@ -30,7 +30,6 @@ import {
|
||||||
tenancy,
|
tenancy,
|
||||||
platform,
|
platform,
|
||||||
ErrorCode,
|
ErrorCode,
|
||||||
db as dbCore,
|
|
||||||
} from "@budibase/backend-core"
|
} from "@budibase/backend-core"
|
||||||
import { checkAnyUserExists } from "../../../utilities/users"
|
import { checkAnyUserExists } from "../../../utilities/users"
|
||||||
import { isEmailConfigured } from "../../../utilities/email"
|
import { isEmailConfigured } from "../../../utilities/email"
|
||||||
|
|
|
@ -54,7 +54,7 @@ describe("/api/global/users/:userId/app/builder", () => {
|
||||||
await config.api.users.grantBuilderToApp(user._id!, MOCK_APP_ID)
|
await config.api.users.grantBuilderToApp(user._id!, MOCK_APP_ID)
|
||||||
let updated = await getUser(user._id!)
|
let updated = await getUser(user._id!)
|
||||||
expect(updated.builder?.apps![0]).toBe(MOCK_APP_ID)
|
expect(updated.builder?.apps![0]).toBe(MOCK_APP_ID)
|
||||||
await config.api.users.revokeBuilderToApp(user._id!, MOCK_APP_ID)
|
await config.api.users.revokeBuilderFromApp(user._id!, MOCK_APP_ID)
|
||||||
updated = await getUser(user._id!)
|
updated = await getUser(user._id!)
|
||||||
expect(updated.builder?.apps!.length).toBe(0)
|
expect(updated.builder?.apps!.length).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
|
@ -206,7 +206,7 @@ describe("/api/global/auth", () => {
|
||||||
const newPassword = "newpassword"
|
const newPassword = "newpassword"
|
||||||
const res = await config.api.auth.updatePassword(code!, newPassword)
|
const res = await config.api.auth.updatePassword(code!, newPassword)
|
||||||
|
|
||||||
user = (await config.getUser(user.email)) as User
|
user = await config.getUser(user.email)
|
||||||
delete user.password
|
delete user.password
|
||||||
|
|
||||||
expect(res.body).toEqual({ message: "password reset successfully." })
|
expect(res.body).toEqual({ message: "password reset successfully." })
|
||||||
|
|
|
@ -9,7 +9,6 @@ import {
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { TestConfiguration } from "../../../../tests"
|
import { TestConfiguration } from "../../../../tests"
|
||||||
import { events } from "@budibase/backend-core"
|
import { events } from "@budibase/backend-core"
|
||||||
import * as pro from "@budibase/pro"
|
|
||||||
|
|
||||||
mocks.licenses.useScimIntegration()
|
mocks.licenses.useScimIntegration()
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
const { join } = require("path")
|
import { env as coreEnv } from "@budibase/backend-core"
|
||||||
|
import { ServiceType } from "@budibase/types"
|
||||||
|
import { join } from "path"
|
||||||
|
|
||||||
|
coreEnv._set("SERVICE_TYPE", ServiceType.WORKER)
|
||||||
|
|
||||||
function isDev() {
|
function isDev() {
|
||||||
return process.env.NODE_ENV !== "production"
|
return process.env.NODE_ENV !== "production"
|
||||||
|
|
|
@ -10,7 +10,6 @@ import Application from "koa"
|
||||||
import { bootstrap } from "global-agent"
|
import { bootstrap } from "global-agent"
|
||||||
import * as db from "./db"
|
import * as db from "./db"
|
||||||
import { sdk as proSdk } from "@budibase/pro"
|
import { sdk as proSdk } from "@budibase/pro"
|
||||||
import { ServiceType } from "@budibase/types"
|
|
||||||
import {
|
import {
|
||||||
auth,
|
auth,
|
||||||
logging,
|
logging,
|
||||||
|
@ -20,7 +19,6 @@ import {
|
||||||
env as coreEnv,
|
env as coreEnv,
|
||||||
timers,
|
timers,
|
||||||
} from "@budibase/backend-core"
|
} from "@budibase/backend-core"
|
||||||
coreEnv._set("SERVICE_TYPE", ServiceType.WORKER)
|
|
||||||
db.init()
|
db.init()
|
||||||
import Koa from "koa"
|
import Koa from "koa"
|
||||||
import koaBody from "koa-body"
|
import koaBody from "koa-body"
|
||||||
|
|
|
@ -251,9 +251,9 @@ class TestConfiguration {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUser(email: string): Promise<User | undefined> {
|
async getUser(email: string): Promise<User> {
|
||||||
return context.doInTenant(this.getTenantId(), () => {
|
return context.doInTenant(this.getTenantId(), async () => {
|
||||||
return users.getGlobalUserByEmail(email)
|
return (await users.getGlobalUserByEmail(email)) as User
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -153,7 +153,7 @@ export class UserAPI extends TestAPI {
|
||||||
.expect(statusCode)
|
.expect(statusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
revokeBuilderToApp = (userId: string, appId: string) => {
|
revokeBuilderFromApp = (userId: string, appId: string) => {
|
||||||
return this.request
|
return this.request
|
||||||
.delete(`/api/global/users/${userId}/app/${appId}/builder`)
|
.delete(`/api/global/users/${userId}/app/${appId}/builder`)
|
||||||
.set(this.config.defaultHeaders())
|
.set(this.config.defaultHeaders())
|
||||||
|
|
|
@ -2,7 +2,7 @@ import * as email from "./email"
|
||||||
import { mocks } from "@budibase/backend-core/tests"
|
import { mocks } from "@budibase/backend-core/tests"
|
||||||
|
|
||||||
import * as _pro from "@budibase/pro"
|
import * as _pro from "@budibase/pro"
|
||||||
const pro = jest.mocked(_pro, { shallow: true })
|
const pro = jest.mocked(_pro, { shallow: false })
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
email,
|
email,
|
||||||
|
|
Loading…
Reference in New Issue