1
0
Fork 0
mirror of synced 2024-06-28 11:00:55 +12:00

PR comments (backend).

This commit is contained in:
mike12345567 2023-08-01 10:56:47 +01:00
parent 032d5b4f62
commit dce38908c9
14 changed files with 24 additions and 37 deletions

View file

@ -71,27 +71,6 @@ export const bulkUpdateGlobalUsers = async (users: User[]) => {
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> {
const db = context.getGlobalDB()
let user = await db.get<User>(id)

View file

@ -56,7 +56,6 @@ import {
import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts"
import sdk from "../../sdk"
import { builderSocket } from "../../websockets"
import { grantAppBuilderAccess } from "@budibase/backend-core/src/users"
// utility function, need to do away with this
async function getLayouts() {

View file

@ -3,7 +3,7 @@ import { db as dbCore } from "@budibase/backend-core"
type Optional = string | null
export enum AppStatus {
export const enum AppStatus {
DEV = "development",
ALL = "all",
DEPLOYED = "published",

View file

@ -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"
function isTest() {

View file

@ -4,7 +4,10 @@ const APP_PREFIX = prefixed(DocumentType.APP)
const APP_DEV_PREFIX = prefixed(DocumentType.APP_DEV)
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
}
// 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.
*/
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
}
// split to take off the app_dev element, then join it together incase any other app_ exist

View file

@ -30,7 +30,6 @@ import {
tenancy,
platform,
ErrorCode,
db as dbCore,
} from "@budibase/backend-core"
import { checkAnyUserExists } from "../../../utilities/users"
import { isEmailConfigured } from "../../../utilities/email"

View file

@ -54,7 +54,7 @@ describe("/api/global/users/:userId/app/builder", () => {
await config.api.users.grantBuilderToApp(user._id!, MOCK_APP_ID)
let updated = await getUser(user._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!)
expect(updated.builder?.apps!.length).toBe(0)
})

View file

@ -206,7 +206,7 @@ describe("/api/global/auth", () => {
const newPassword = "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
expect(res.body).toEqual({ message: "password reset successfully." })

View file

@ -9,7 +9,6 @@ import {
} from "@budibase/types"
import { TestConfiguration } from "../../../../tests"
import { events } from "@budibase/backend-core"
import * as pro from "@budibase/pro"
mocks.licenses.useScimIntegration()

View file

@ -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() {
return process.env.NODE_ENV !== "production"

View file

@ -10,7 +10,6 @@ import Application from "koa"
import { bootstrap } from "global-agent"
import * as db from "./db"
import { sdk as proSdk } from "@budibase/pro"
import { ServiceType } from "@budibase/types"
import {
auth,
logging,
@ -20,7 +19,6 @@ import {
env as coreEnv,
timers,
} from "@budibase/backend-core"
coreEnv._set("SERVICE_TYPE", ServiceType.WORKER)
db.init()
import Koa from "koa"
import koaBody from "koa-body"

View file

@ -251,9 +251,9 @@ class TestConfiguration {
})
}
async getUser(email: string): Promise<User | undefined> {
return context.doInTenant(this.getTenantId(), () => {
return users.getGlobalUserByEmail(email)
async getUser(email: string): Promise<User> {
return context.doInTenant(this.getTenantId(), async () => {
return (await users.getGlobalUserByEmail(email)) as User
})
}

View file

@ -153,7 +153,7 @@ export class UserAPI extends TestAPI {
.expect(statusCode)
}
revokeBuilderToApp = (userId: string, appId: string) => {
revokeBuilderFromApp = (userId: string, appId: string) => {
return this.request
.delete(`/api/global/users/${userId}/app/${appId}/builder`)
.set(this.config.defaultHeaders())

View file

@ -2,7 +2,7 @@ import * as email from "./email"
import { mocks } from "@budibase/backend-core/tests"
import * as _pro from "@budibase/pro"
const pro = jest.mocked(_pro, { shallow: true })
const pro = jest.mocked(_pro, { shallow: false })
export default {
email,