bugfix: clearing sessions on backend update
This commit is contained in:
parent
20c624d3c9
commit
cb1fc286b1
|
@ -3,6 +3,8 @@ import { _deleteRecord } from "../recordApi/delete"
|
||||||
import { getAllIdsIterator } from "../indexing/allIds"
|
import { getAllIdsIterator } from "../indexing/allIds"
|
||||||
import { permission } from "../authApi/permissions"
|
import { permission } from "../authApi/permissions"
|
||||||
import { getCollectionDir } from "../recordApi/recordInfo"
|
import { getCollectionDir } from "../recordApi/recordInfo"
|
||||||
|
import { ensureCollectionIsInitialised } from "./initialise"
|
||||||
|
import { getNodeForCollectionPath } from "../templateApi/hierarchy"
|
||||||
|
|
||||||
export const deleteCollection = (app, disableCleanup = false) => async key =>
|
export const deleteCollection = (app, disableCleanup = false) => async key =>
|
||||||
apiWrapper(
|
apiWrapper(
|
||||||
|
@ -25,14 +27,19 @@ export const _deleteCollection = async (app, key, disableCleanup) => {
|
||||||
key = safeKey(key)
|
key = safeKey(key)
|
||||||
const collectionDir = getCollectionDir(app.hierarchy, key)
|
const collectionDir = getCollectionDir(app.hierarchy, key)
|
||||||
await deleteRecords(app, key)
|
await deleteRecords(app, key)
|
||||||
await deleteCollectionFolder(app, collectionDir)
|
await deleteCollectionFolder(app, key, collectionDir)
|
||||||
if (!disableCleanup) {
|
if (!disableCleanup) {
|
||||||
await app.cleanupTransactions()
|
await app.cleanupTransactions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleteCollectionFolder = async (app, dir) =>
|
const deleteCollectionFolder = async (app, key, dir) => {
|
||||||
await app.datastore.deleteFolder(dir)
|
await app.datastore.deleteFolder(dir)
|
||||||
|
await ensureCollectionIsInitialised(
|
||||||
|
app.datastore,
|
||||||
|
getNodeForCollectionPath(app.hierarchy)(key),
|
||||||
|
dir)
|
||||||
|
}
|
||||||
|
|
||||||
const deleteRecords = async (app, key) => {
|
const deleteRecords = async (app, key) => {
|
||||||
const iterate = await getAllIdsIterator(app)(key)
|
const iterate = await getAllIdsIterator(app)(key)
|
||||||
|
|
|
@ -6,7 +6,7 @@ import {
|
||||||
} from "../templateApi/hierarchy"
|
} from "../templateApi/hierarchy"
|
||||||
import { $, allTrue, joinKey } from "../common"
|
import { $, allTrue, joinKey } from "../common"
|
||||||
|
|
||||||
const ensureCollectionIsInitialised = async (datastore, node, dir) => {
|
export const ensureCollectionIsInitialised = async (datastore, node, dir) => {
|
||||||
if (!(await datastore.exists(dir))) {
|
if (!(await datastore.exists(dir))) {
|
||||||
await datastore.createFolder(dir)
|
await datastore.createFolder(dir)
|
||||||
await datastore.createFolder(joinKey(dir, node.nodeId))
|
await datastore.createFolder(joinKey(dir, node.nodeId))
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { permission } from "../src/authApi/permissions"
|
||||||
|
|
||||||
describe("collectionApi > delete", () => {
|
describe("collectionApi > delete", () => {
|
||||||
it("should remove every key in collection's path", async () => {
|
it("should remove every key in collection's path", async () => {
|
||||||
const { recordApi, collectionApi } = await setupApphierarchy(
|
const { recordApi, collectionApi, appHierarchy } = await setupApphierarchy(
|
||||||
basicAppHierarchyCreator_WithFields
|
basicAppHierarchyCreator_WithFields
|
||||||
)
|
)
|
||||||
const record1 = recordApi.getNew("/customers", "customer")
|
const record1 = recordApi.getNew("/customers", "customer")
|
||||||
|
@ -31,7 +31,10 @@ describe("collectionApi > delete", () => {
|
||||||
filter(k => splitKey(k)[0] === "customers"),
|
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 () => {
|
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"),
|
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")
|
await collectionApi.delete("/customers")
|
||||||
|
|
||||||
|
|
|
@ -6,5 +6,6 @@ module.exports = async ctx => {
|
||||||
accessLevels.version = existingAccessLevels.version
|
accessLevels.version = existingAccessLevels.version
|
||||||
await ctx.instance.authApi.saveAccessLevels(accessLevels)
|
await ctx.instance.authApi.saveAccessLevels(accessLevels)
|
||||||
await ctx.instance.templateApi.upgradeData(ctx.request.body.newHierarchy)
|
await ctx.instance.templateApi.upgradeData(ctx.request.body.newHierarchy)
|
||||||
|
await ctx.master.clearAllSessions(ctx.params.appname)
|
||||||
ctx.response.status = StatusCodes.OK
|
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 getApplicationWithInstances = async appname => {
|
||||||
const app = cloneDeep(await getApplication(appname))
|
const app = cloneDeep(await getApplication(appname))
|
||||||
app.instances = await bb.indexApi.listItems(
|
app.instances = await bb.indexApi.listItems(
|
||||||
|
@ -346,7 +355,7 @@ module.exports = async context => {
|
||||||
await bb.recordApi.save(userInMaster)
|
await bb.recordApi.save(userInMaster)
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleteLatestPackageFromCache = (appname) => {
|
const deleteLatestPackageFromCache = appname => {
|
||||||
deleteCachedPackage(context, appname, LATEST_VERSIONID)
|
deleteCachedPackage(context, appname, LATEST_VERSIONID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,5 +379,6 @@ module.exports = async context => {
|
||||||
getFullAccessApiForMaster,
|
getFullAccessApiForMaster,
|
||||||
getApplicationWithInstances,
|
getApplicationWithInstances,
|
||||||
deleteLatestPackageFromCache,
|
deleteLatestPackageFromCache,
|
||||||
|
clearAllSessions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue