notification added in with subs :D
This commit is contained in:
26
backend/utils/auth.permissions.ts
Normal file
26
backend/utils/auth.permissions.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { createAccessControl } from "better-auth/plugins/access";
|
||||
|
||||
export const statement = {
|
||||
app: ["read", "create", "share", "update", "delete", "readAll"],
|
||||
user: ["ban"],
|
||||
quality: ["read", "create", "share", "update", "delete", "readAll"],
|
||||
notifications: ["read", "create", "share", "update", "delete", "readAll"],
|
||||
} as const;
|
||||
|
||||
export const ac = createAccessControl(statement);
|
||||
|
||||
export const user = ac.newRole({
|
||||
app: ["read", "create"],
|
||||
notifications: ["read", "create"],
|
||||
});
|
||||
|
||||
export const admin = ac.newRole({
|
||||
app: ["read", "create", "update"],
|
||||
});
|
||||
|
||||
export const systemAdmin = ac.newRole({
|
||||
app: ["read", "create", "share", "update", "delete", "readAll"],
|
||||
user: ["ban"],
|
||||
quality: ["read", "create", "share", "update", "delete", "readAll"],
|
||||
notifications: ["read", "create", "share", "update", "delete", "readAll"],
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
import { betterAuth } from "better-auth";
|
||||
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
||||
import {
|
||||
admin,
|
||||
admin as adminPlugin,
|
||||
// apiKey,
|
||||
// createAuthMiddleware,
|
||||
//customSession,
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
//import { eq } from "drizzle-orm";
|
||||
import { db } from "../db/db.controller.js";
|
||||
import * as rawSchema from "../db/schema/auth.schema.js";
|
||||
import { ac, admin, systemAdmin, user } from "./auth.permissions.js";
|
||||
import { allowedOrigins } from "./cors.utils.js";
|
||||
import { sendEmail } from "./sendEmail.utils.js";
|
||||
|
||||
@@ -44,7 +45,14 @@ export const auth = betterAuth({
|
||||
plugins: [
|
||||
jwt({ jwt: { expirationTime: "1h" } }),
|
||||
//apiKey(),
|
||||
admin(),
|
||||
adminPlugin({
|
||||
ac,
|
||||
roles: {
|
||||
admin,
|
||||
user,
|
||||
systemAdmin,
|
||||
},
|
||||
}),
|
||||
lastLoginMethod(),
|
||||
username({
|
||||
minUsernameLength: 5,
|
||||
|
||||
38
backend/utils/croner.minConvert.ts
Normal file
38
backend/utils/croner.minConvert.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { createLogger } from "../logger/logger.controller.js";
|
||||
|
||||
const minTime = 5;
|
||||
export const minutesToCron = (minutes: number): string => {
|
||||
const log = createLogger({ module: "system", subModule: "croner" });
|
||||
if (minutes < minTime) {
|
||||
log.error(
|
||||
{},
|
||||
`Conversion of less then ${minTime} min and is not allowed on this server`,
|
||||
);
|
||||
}
|
||||
|
||||
// Every X minutes (under 60)
|
||||
if (minutes < 60) {
|
||||
return `*/${minutes} * * * *`;
|
||||
}
|
||||
|
||||
// Every X hours (clean division)
|
||||
if (minutes % 60 === 0 && minutes < 1440) {
|
||||
const hours = minutes / 60;
|
||||
return `0 0 */${hours} * * *`;
|
||||
}
|
||||
|
||||
// Every day
|
||||
if (minutes === 1440) {
|
||||
return `0 0 8 * * *`; // 8am
|
||||
}
|
||||
|
||||
// Every X days (clean division)
|
||||
if (minutes % 1440 === 0) {
|
||||
const days = minutes / 1440;
|
||||
return `0 0 0 */${days} * *`;
|
||||
}
|
||||
|
||||
// Fallback (not cleanly divisible)
|
||||
// Cron can't represent this perfectly → run every X minutes as approximation
|
||||
return `0 */${minutes} * * * *`;
|
||||
};
|
||||
@@ -3,7 +3,14 @@ import { createLogger } from "../logger/logger.controller.js";
|
||||
|
||||
interface Data<T = unknown[]> {
|
||||
success: boolean;
|
||||
module: "system" | "ocp" | "routes" | "datamart" | "utils" | "opendock";
|
||||
module:
|
||||
| "system"
|
||||
| "ocp"
|
||||
| "routes"
|
||||
| "datamart"
|
||||
| "utils"
|
||||
| "opendock"
|
||||
| "notification";
|
||||
subModule:
|
||||
| "db"
|
||||
| "labeling"
|
||||
@@ -15,7 +22,13 @@ interface Data<T = unknown[]> {
|
||||
| "datamart"
|
||||
| "jobs"
|
||||
| "apt"
|
||||
| "settings";
|
||||
| "settings"
|
||||
| "get"
|
||||
| "update"
|
||||
| "delete"
|
||||
| "post"
|
||||
| "notification"
|
||||
| "delete";
|
||||
level: "info" | "error" | "debug" | "fatal";
|
||||
message: string;
|
||||
room?: string;
|
||||
|
||||
Reference in New Issue
Block a user