From 867fc9611e5d7136fd38c26174c10ac239f53ef9 Mon Sep 17 00:00:00 2001 From: Marcin Juraszek Date: Sun, 26 Feb 2023 09:31:55 -0800 Subject: [PATCH] Ensure indexes for Roles and Subjects collections as part of boot (#7902) * Allow DELETE via PATCH/UPDATE operation too * rollback wrong commit * Ensure indexes for Roles and Subjects collections as part of boot --------- Co-authored-by: Milos Kozak --- lib/authorization/storage.js | 5 +++++ lib/server/bootevent.js | 1 + 2 files changed, 6 insertions(+) diff --git a/lib/authorization/storage.js b/lib/authorization/storage.js index 054f9a07b0d..614f8c78051 100644 --- a/lib/authorization/storage.js +++ b/lib/authorization/storage.js @@ -122,6 +122,11 @@ function init (env, ctx) { , { name: 'activity', permissions: [ 'api:activity:create' ] } ]; + storage.ensureIndexes = function ensureIndexes() { + ctx.store.ensureIndexes(rolesCollection, ['name']); + ctx.store.ensureIndexes(subjectsCollection, ['name']); + } + storage.getSHA1 = function getSHA1 (message) { var shasum = crypto.createHash('sha1'); shasum.update(message); diff --git a/lib/server/bootevent.js b/lib/server/bootevent.js index edcd35c11cd..60b02b541c8 100644 --- a/lib/server/bootevent.js +++ b/lib/server/bootevent.js @@ -185,6 +185,7 @@ function boot (env, language) { } ctx.authorization = require('../authorization')(env, ctx); + ctx.authorization.storage.ensureIndexes(); ctx.authorization.storage.reload(function loaded (err) { if (err) { ctx.bootErrors = ctx.bootErrors || [ ];