From 3f75ebf853c0bacf69d677b2c8dc7c4feb6c7b1c Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 12 May 2021 17:43:01 +0100 Subject: [PATCH] Adding dev endpoint to clear lock. --- packages/server/src/api/controllers/dev.js | 15 +++++++++++++++ packages/server/src/api/routes/dev.js | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/packages/server/src/api/controllers/dev.js b/packages/server/src/api/controllers/dev.js index 003f82faa8..3f1a6a11cd 100644 --- a/packages/server/src/api/controllers/dev.js +++ b/packages/server/src/api/controllers/dev.js @@ -2,6 +2,8 @@ const fetch = require("node-fetch") const env = require("../../environment") const { checkSlashesInUrl } = require("../../utilities") const { request } = require("../../utilities/workerRequests") +const { getGlobalIDFromUserMetadataID } = require("../../db/utils") +const { clearLock } = require("../../utilities/redis") async function redirect(ctx, method) { const { devPath } = ctx.params @@ -32,3 +34,16 @@ exports.redirectPost = async ctx => { exports.redirectDelete = async ctx => { await redirect(ctx, "DELETE") } + +exports.removeLock = async ctx => { + const { appId } = ctx.params + const globalUserId = getGlobalIDFromUserMetadataID(ctx.user._id) + try { + await clearLock(appId, globalUserId) + } catch (err) { + ctx.throw(400, "Unable to remove lock.") + } + ctx.body = { + message: "Lock removed successfully." + } +} diff --git a/packages/server/src/api/routes/dev.js b/packages/server/src/api/routes/dev.js index 341d48c7b5..c6203cc221 100644 --- a/packages/server/src/api/routes/dev.js +++ b/packages/server/src/api/routes/dev.js @@ -1,6 +1,8 @@ const Router = require("@koa/router") const controller = require("../controllers/dev") const env = require("../../environment") +const authorized = require("../../middleware/authorized") +const { BUILDER } = require("../../utilities/security/permissions") const router = Router() @@ -11,4 +13,6 @@ if (env.isDev() || env.isTest()) { .delete("/api/admin/:devPath(.*)", controller.redirectDelete) } +router.delete("/api/dev/:appId/lock", authorized(BUILDER), controller.removeLock) + module.exports = router