* fix: restrict parts of manage navigation to admins * fix: restrict stats cards on manage home page * fix: restrict access to amount of certain stats for manage home * fix: restrict visibility of board create button * fix: restrict access to integration pages * fix: restrict access to tools pages for admins * fix: restrict access to user and group pages * test: adjust tests to match permission changes for routes * fix: remove certain pages from spotlight without admin * fix: app management not restricted
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
import { observable } from "@trpc/server/observable";
|
|
|
|
import { jobNameSchema, triggerCronJobAsync } from "@homarr/cron-job-runner";
|
|
import type { TaskStatus } from "@homarr/cron-job-status";
|
|
import { createCronJobStatusChannel } from "@homarr/cron-job-status";
|
|
import { jobGroup } from "@homarr/cron-jobs";
|
|
import { logger } from "@homarr/log";
|
|
|
|
import { createTRPCRouter, permissionRequiredProcedure } from "../trpc";
|
|
|
|
export const cronJobsRouter = createTRPCRouter({
|
|
triggerJob: permissionRequiredProcedure
|
|
.requiresPermission("admin")
|
|
.input(jobNameSchema)
|
|
.mutation(async ({ input }) => {
|
|
await triggerCronJobAsync(input);
|
|
}),
|
|
getJobs: permissionRequiredProcedure.requiresPermission("admin").query(() => {
|
|
const registry = jobGroup.getJobRegistry();
|
|
return [...registry.values()].map((job) => ({
|
|
name: job.name,
|
|
expression: job.cronExpression,
|
|
}));
|
|
}),
|
|
subscribeToStatusUpdates: permissionRequiredProcedure.requiresPermission("admin").subscription(() => {
|
|
return observable<TaskStatus>((emit) => {
|
|
const unsubscribes: (() => void)[] = [];
|
|
|
|
for (const job of jobGroup.getJobRegistry().values()) {
|
|
const channel = createCronJobStatusChannel(job.name);
|
|
const unsubscribe = channel.subscribe((data) => {
|
|
emit.next(data);
|
|
});
|
|
unsubscribes.push(unsubscribe);
|
|
}
|
|
|
|
logger.info("A tRPC client has connected to the cron job status updates procedure");
|
|
|
|
return () => {
|
|
unsubscribes.forEach((unsubscribe) => {
|
|
unsubscribe();
|
|
});
|
|
};
|
|
});
|
|
}),
|
|
});
|