Updated gerbil key handeling

This commit is contained in:
Owen Schwartz 2024-10-26 17:02:11 -04:00
parent 6cee5703b5
commit 7feb21e727
No known key found for this signature in database
GPG key ID: 8271FDFFD9E0CCBD
5 changed files with 25 additions and 17 deletions

View file

@ -20,9 +20,10 @@ export async function ensureActions() {
// Add new actions
for (const actionId of actionsToAdd) {
logger.debug(`Adding action: ${actionId}`);
await db.insert(actions).values({ actionId }).execute();
// Add new actions to the Default role
if (defaultRoles.length === 0) {
if (defaultRoles.length != 0) {
await db.insert(roleActions)
.values(defaultRoles.map(role => ({ roleId: role.roleId!, actionId, orgId: role.orgId! })))
.execute();
@ -31,6 +32,7 @@ export async function ensureActions() {
// Remove deprecated actions
if (actionsToRemove.length > 0) {
logger.debug(`Removing actions: ${actionsToRemove.join(', ')}`);
await db.delete(actions).where(inArray(actions.actionId, actionsToRemove)).execute();
await db.delete(roleActions).where(inArray(roleActions.actionId, actionsToRemove)).execute();
}

View file

@ -6,7 +6,13 @@ import { eq, and } from "drizzle-orm";
import { __DIRNAME } from "@server/config";
// Load the names from the names.json file
const file = join(__DIRNAME, "names.json");
const dev = process.env.ENVIRONMENT !== "prod";
let file;
if (!dev) {
file = join(__DIRNAME, "names.json");
} else {
file = join(__DIRNAME, "/db/names.json");
}
export const names = JSON.parse(readFileSync(file, "utf-8"));
export async function getUniqueSiteName(orgId: string): Promise<string> {