Merge branch 'new-backend'
This commit is contained in:
commit
d18fd05022
|
@ -44,7 +44,7 @@ export const _createUser = async (app, user, password = null) => {
|
|||
|
||||
const userErrors = validateUser(app)([...users, user], user)
|
||||
if (userErrors.length > 0) {
|
||||
throw new BadRequestError(`User is invalid. ${join("; ")(userErrors)}`)
|
||||
throw new BadRequestError(`User is invalid. ${join("; ")(userErrors.map(e => e.error))}`)
|
||||
}
|
||||
|
||||
const { auth, tempCode, temporaryAccessId } = await getAccess(app, password)
|
||||
|
|
|
@ -3,6 +3,8 @@ import { _deleteRecord } from "../recordApi/delete"
|
|||
import { getAllIdsIterator } from "../indexing/allIds"
|
||||
import { permission } from "../authApi/permissions"
|
||||
import { getCollectionDir } from "../recordApi/recordInfo"
|
||||
import { ensureCollectionIsInitialised } from "./initialise"
|
||||
import { getNodeForCollectionPath } from "../templateApi/hierarchy"
|
||||
|
||||
export const deleteCollection = (app, disableCleanup = false) => async key =>
|
||||
apiWrapper(
|
||||
|
@ -25,14 +27,19 @@ export const _deleteCollection = async (app, key, disableCleanup) => {
|
|||
key = safeKey(key)
|
||||
const collectionDir = getCollectionDir(app.hierarchy, key)
|
||||
await deleteRecords(app, key)
|
||||
await deleteCollectionFolder(app, collectionDir)
|
||||
await deleteCollectionFolder(app, key, collectionDir)
|
||||
if (!disableCleanup) {
|
||||
await app.cleanupTransactions()
|
||||
}
|
||||
}
|
||||
|
||||
const deleteCollectionFolder = async (app, dir) =>
|
||||
const deleteCollectionFolder = async (app, key, dir) => {
|
||||
await app.datastore.deleteFolder(dir)
|
||||
await ensureCollectionIsInitialised(
|
||||
app.datastore,
|
||||
getNodeForCollectionPath(app.hierarchy)(key),
|
||||
dir)
|
||||
}
|
||||
|
||||
const deleteRecords = async (app, key) => {
|
||||
const iterate = await getAllIdsIterator(app)(key)
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
} from "../templateApi/hierarchy"
|
||||
import { $, allTrue, joinKey } from "../common"
|
||||
|
||||
const ensureCollectionIsInitialised = async (datastore, node, dir) => {
|
||||
export const ensureCollectionIsInitialised = async (datastore, node, dir) => {
|
||||
if (!(await datastore.exists(dir))) {
|
||||
await datastore.createFolder(dir)
|
||||
await datastore.createFolder(joinKey(dir, node.nodeId))
|
||||
|
|
|
@ -8,7 +8,7 @@ import { permission } from "../src/authApi/permissions"
|
|||
|
||||
describe("collectionApi > delete", () => {
|
||||
it("should remove every key in collection's path", async () => {
|
||||
const { recordApi, collectionApi } = await setupApphierarchy(
|
||||
const { recordApi, collectionApi, appHierarchy } = await setupApphierarchy(
|
||||
basicAppHierarchyCreator_WithFields
|
||||
)
|
||||
const record1 = recordApi.getNew("/customers", "customer")
|
||||
|
@ -31,7 +31,10 @@ describe("collectionApi > delete", () => {
|
|||
filter(k => splitKey(k)[0] === "customers"),
|
||||
])
|
||||
|
||||
expect(remainingKeys).toEqual([])
|
||||
expect(remainingKeys).toEqual([
|
||||
"/customers",
|
||||
`/customers/${appHierarchy.customerRecord.nodeId}`,
|
||||
])
|
||||
})
|
||||
|
||||
it("should not delete anything that is not in its path", async () => {
|
||||
|
@ -51,7 +54,8 @@ describe("collectionApi > delete", () => {
|
|||
filter(k => splitKey(k)[0] === "customers"),
|
||||
])
|
||||
|
||||
const expectedRemainingKeys = allKeys.length - customerKeys.length
|
||||
const expectedRemainingKeys = allKeys.length - customerKeys.length + 2
|
||||
// +2 because is should keep the collection folders: /customers & /customers/1
|
||||
|
||||
await collectionApi.delete("/customers")
|
||||
|
||||
|
|
|
@ -6,5 +6,6 @@ module.exports = async ctx => {
|
|||
accessLevels.version = existingAccessLevels.version
|
||||
await ctx.instance.authApi.saveAccessLevels(accessLevels)
|
||||
await ctx.instance.templateApi.upgradeData(ctx.request.body.newHierarchy)
|
||||
await ctx.master.clearAllSessions(ctx.params.appname)
|
||||
ctx.response.status = StatusCodes.OK
|
||||
}
|
||||
|
|
|
@ -325,6 +325,15 @@ module.exports = async context => {
|
|||
}
|
||||
}
|
||||
|
||||
const clearAllSessions = async appname => {
|
||||
if (isMaster(appname)) {
|
||||
await bb.collectionApi.delete("/mastersessions")
|
||||
} else {
|
||||
const app = await getApplication(appname)
|
||||
await bb.collectionApi.delete(`/applications/${app.id}/sessions`)
|
||||
}
|
||||
}
|
||||
|
||||
const getApplicationWithInstances = async appname => {
|
||||
const app = cloneDeep(await getApplication(appname))
|
||||
app.instances = await bb.indexApi.listItems(
|
||||
|
@ -370,5 +379,6 @@ module.exports = async context => {
|
|||
getFullAccessApiForMaster,
|
||||
getApplicationWithInstances,
|
||||
deleteLatestPackageFromCache,
|
||||
clearAllSessions,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue