1
0
Fork 0
mirror of synced 2024-10-03 10:36:59 +13:00

Adding licensing checks to import/export API.

This commit is contained in:
mike12345567 2023-09-22 17:38:34 +01:00
parent 07c7192154
commit fe5cc6878b
6 changed files with 23 additions and 32 deletions

View file

@ -86,8 +86,8 @@ export const useAuditLogs = () => {
return useFeature(Feature.AUDIT_LOGS)
}
export const usePublicApiUserRoles = () => {
return useFeature(Feature.USER_ROLE_PUBLIC_API)
export const useExpandedPublicApi = () => {
return useFeature(Feature.EXPANDED_PUBLIC_API)
}
export const useScimIntegration = () => {

@ -1 +1 @@
Subproject commit 4638ae916e55ce89166095578cbd01745d0ee9ee
Subproject commit 6c193aa50bc5eca7757db886c8457f516dafc1b8

View file

@ -584,7 +584,14 @@ export async function importToApp(ctx: UserCtx) {
ctx.throw(400, "Must only supply one app export")
}
const fileAttributes = { type: appExport.type!, path: appExport.path! }
await sdk.applications.updateWithExport(appId, fileAttributes, password)
try {
await sdk.applications.updateWithExport(appId, fileAttributes, password)
} catch (err: any) {
ctx.throw(
500,
`Unable to perform update, please retry - ${err?.message || err}`
)
}
ctx.body = { message: "app updated" }
}

View file

@ -6,6 +6,7 @@ import * as backupController from "../backup"
import { Application } from "../../../definitions/common"
import { UserCtx } from "@budibase/types"
import { Next } from "koa"
import { sdk as proSdk } from "@budibase/pro"
function fixAppID(app: Application, params: any) {
if (!params) {
@ -94,30 +95,13 @@ export async function publish(ctx: UserCtx, next: Next) {
})
}
export async function importToApp(ctx: UserCtx, next: Next) {
if (!ctx.request.files?.appExport) {
ctx.throw(400, "Must provide app export file for import.")
}
await context.doInAppContext(ctx.params.appId, async () => {
await controller.importToApp(ctx)
ctx.body = undefined
ctx.status = 204
await next()
})
}
export async function exportApp(ctx: UserCtx, next: Next) {
const { encryptPassword, excludeRows } = ctx.request.body
await context.doInAppContext(ctx.params.appId, async () => {
// make sure no other inputs
ctx.request.body = {
encryptPassword,
excludeRows,
}
await backupController.exportAppDump(ctx)
await next()
})
}
// get licensed endpoints from pro
export const importToApp = proSdk.publicApi.applications.buildImportFn(
controller.importToApp
)
export const exportApp = proSdk.publicApi.applications.buildExportFn(
backupController.exportAppDump
)
export default {
create,

View file

@ -92,7 +92,7 @@ describe("no user role update in free", () => {
describe("no user role update in business", () => {
beforeAll(() => {
updateMock()
mocks.licenses.usePublicApiUserRoles()
mocks.licenses.useExpandedPublicApi()
})
it("should allow 'roles' to be updated", async () => {
@ -105,7 +105,7 @@ describe("no user role update in business", () => {
})
it("should allow 'admin' to be updated", async () => {
mocks.licenses.usePublicApiUserRoles()
mocks.licenses.useExpandedPublicApi()
const res = await makeRequest("post", "/users", {
...base(),
admin: { global: true },
@ -115,7 +115,7 @@ describe("no user role update in business", () => {
})
it("should allow 'builder' to be updated", async () => {
mocks.licenses.usePublicApiUserRoles()
mocks.licenses.useExpandedPublicApi()
const res = await makeRequest("post", "/users", {
...base(),
builder: { global: true },

View file

@ -11,7 +11,7 @@ export enum Feature {
SYNC_AUTOMATIONS = "syncAutomations",
APP_BUILDERS = "appBuilders",
OFFLINE = "offline",
USER_ROLE_PUBLIC_API = "userRolePublicApi",
EXPANDED_PUBLIC_API = "expandedPublicApi",
VIEW_PERMISSIONS = "viewPermissions",
}