1.0.36
This commit is contained in:
63 files changed
+1324
-281
No files matched your search
@@ -22,6 +22,7 @@ import {
|
||||
} from '$lib/server/db';
|
||||
import { getNextRun, getSystemSchedules } from '$lib/server/scheduler';
|
||||
import { getGlobalScannerDefaults, getScannerSettingsWithDefaults } from '$lib/server/scanner';
|
||||
import { authorize } from '$lib/server/authorize';
|
||||
|
||||
export interface ScheduleInfo {
|
||||
id: number;
|
||||
@@ -43,7 +44,12 @@ export interface ScheduleInfo {
|
||||
vulnerabilityCriteria?: VulnerabilityCriteria | null;
|
||||
}
|
||||
|
||||
export const GET: RequestHandler = async () => {
|
||||
export const GET: RequestHandler = async ({ cookies }) => {
|
||||
const auth = await authorize(cookies);
|
||||
|
||||
const permDenied = await auth.requirePermission('schedules', 'view');
|
||||
if (permDenied) return permDenied;
|
||||
|
||||
try {
|
||||
const schedules: ScheduleInfo[] = [];
|
||||
|
||||
@@ -233,13 +239,23 @@ export const GET: RequestHandler = async () => {
|
||||
);
|
||||
schedules.push(...sysSchedules);
|
||||
|
||||
// Filter by per-env access (enterprise): caller sees only schedules
|
||||
// for envs they can access, plus all system schedules (env null).
|
||||
// Free edition / admin: getAccessibleEnvironmentIds returns null,
|
||||
// no filtering applied.
|
||||
const accessibleEnvIds = await auth.getAccessibleEnvironmentIds();
|
||||
const filtered = accessibleEnvIds === null
|
||||
? schedules
|
||||
: schedules.filter(s =>
|
||||
s.environmentId === null || accessibleEnvIds.includes(s.environmentId));
|
||||
|
||||
// Sort: system jobs last, then by name
|
||||
schedules.sort((a, b) => {
|
||||
filtered.sort((a, b) => {
|
||||
if (a.isSystem !== b.isSystem) return a.isSystem ? 1 : -1;
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
|
||||
return json({ schedules });
|
||||
return json({ schedules: filtered });
|
||||
} catch (error: any) {
|
||||
console.error('Failed to get schedules:', error);
|
||||
return json({ error: error.message }, { status: 500 });
|
||||
|
||||
@@ -8,6 +8,7 @@ import type { RequestHandler } from './$types';
|
||||
import {
|
||||
getAutoUpdateSettingById,
|
||||
deleteAutoUpdateSchedule,
|
||||
getGitStack,
|
||||
updateGitStack,
|
||||
deleteEnvUpdateCheckSettings,
|
||||
deleteImagePruneSettings
|
||||
@@ -17,9 +18,9 @@ import { authorize } from '$lib/server/authorize';
|
||||
|
||||
export const DELETE: RequestHandler = async ({ params, cookies }) => {
|
||||
const auth = await authorize(cookies);
|
||||
if (auth.authEnabled && !await auth.can('schedules', 'edit')) {
|
||||
return json({ error: 'Permission denied' }, { status: 403 });
|
||||
}
|
||||
|
||||
const permDenied = await auth.requirePermission('schedules', 'edit');
|
||||
if (permDenied) return permDenied;
|
||||
|
||||
try {
|
||||
const { type, id } = params;
|
||||
@@ -33,6 +34,8 @@ export const DELETE: RequestHandler = async ({ params, cookies }) => {
|
||||
// Hard delete container schedule
|
||||
const schedule = await getAutoUpdateSettingById(scheduleId);
|
||||
if (schedule) {
|
||||
const envDenied = await auth.requireEnvAccess(schedule.environmentId);
|
||||
if (envDenied) return envDenied;
|
||||
await deleteAutoUpdateSchedule(schedule.containerName, schedule.environmentId ?? undefined);
|
||||
// Unregister from croner
|
||||
unregisterSchedule(scheduleId, 'container_update');
|
||||
@@ -40,6 +43,12 @@ export const DELETE: RequestHandler = async ({ params, cookies }) => {
|
||||
return json({ success: true });
|
||||
|
||||
} else if (type === 'git_stack_sync') {
|
||||
const stack = await getGitStack(scheduleId);
|
||||
if (!stack) {
|
||||
return json({ error: 'Schedule not found' }, { status: 404 });
|
||||
}
|
||||
const envDenied = await auth.requireEnvAccess(stack.environmentId);
|
||||
if (envDenied) return envDenied;
|
||||
// Disable auto-update for git stack (don't delete the stack itself)
|
||||
await updateGitStack(scheduleId, {
|
||||
autoUpdate: false,
|
||||
@@ -52,12 +61,16 @@ export const DELETE: RequestHandler = async ({ params, cookies }) => {
|
||||
|
||||
} else if (type === 'env_update_check') {
|
||||
// Delete env update check settings (scheduleId is environmentId)
|
||||
const envDenied = await auth.requireEnvAccess(scheduleId);
|
||||
if (envDenied) return envDenied;
|
||||
await deleteEnvUpdateCheckSettings(scheduleId);
|
||||
unregisterSchedule(scheduleId, 'env_update_check');
|
||||
return json({ success: true });
|
||||
|
||||
} else if (type === 'image_prune') {
|
||||
// Delete image prune settings (scheduleId is environmentId)
|
||||
const envDenied = await auth.requireEnvAccess(scheduleId);
|
||||
if (envDenied) return envDenied;
|
||||
await deleteImagePruneSettings(scheduleId);
|
||||
unregisterSchedule(scheduleId, 'image_prune');
|
||||
return json({ success: true });
|
||||
|
||||
@@ -12,12 +12,13 @@ import { json } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { triggerContainerUpdate, triggerGitStackSync, triggerSystemJob, triggerEnvUpdateCheck, triggerImagePrune } from '$lib/server/scheduler';
|
||||
import { authorize } from '$lib/server/authorize';
|
||||
import { getAutoUpdateSettingById, getGitStack } from '$lib/server/db';
|
||||
|
||||
export const POST: RequestHandler = async ({ params, cookies }) => {
|
||||
const auth = await authorize(cookies);
|
||||
if (auth.authEnabled && !await auth.can('schedules', 'run')) {
|
||||
return json({ error: 'Permission denied' }, { status: 403 });
|
||||
}
|
||||
|
||||
const permDenied = await auth.requirePermission('schedules', 'run');
|
||||
if (permDenied) return permDenied;
|
||||
|
||||
try {
|
||||
const { type, id } = params;
|
||||
@@ -27,6 +28,37 @@ export const POST: RequestHandler = async ({ params, cookies }) => {
|
||||
return json({ error: 'Invalid schedule ID' }, { status: 400 });
|
||||
}
|
||||
|
||||
// Resolve schedule → environmentId so we can enforce per-env access
|
||||
// before triggering. System schedules (env null) are gated only by
|
||||
// the global schedules:run check above.
|
||||
let scheduleEnvId: number | null = null;
|
||||
switch (type) {
|
||||
case 'container_update': {
|
||||
const setting = await getAutoUpdateSettingById(scheduleId);
|
||||
if (!setting) return json({ error: 'Schedule not found' }, { status: 404 });
|
||||
scheduleEnvId = setting.environmentId;
|
||||
break;
|
||||
}
|
||||
case 'git_stack_sync': {
|
||||
const stack = await getGitStack(scheduleId);
|
||||
if (!stack) return json({ error: 'Schedule not found' }, { status: 404 });
|
||||
scheduleEnvId = stack.environmentId;
|
||||
break;
|
||||
}
|
||||
case 'env_update_check':
|
||||
case 'image_prune':
|
||||
scheduleEnvId = scheduleId;
|
||||
break;
|
||||
case 'system_cleanup':
|
||||
scheduleEnvId = null;
|
||||
break;
|
||||
default:
|
||||
return json({ error: 'Invalid schedule type' }, { status: 400 });
|
||||
}
|
||||
|
||||
const envDenied = await auth.requireEnvAccess(scheduleEnvId);
|
||||
if (envDenied) return envDenied;
|
||||
|
||||
let result: { success: boolean; executionId?: number; error?: string };
|
||||
|
||||
switch (type) {
|
||||
@@ -46,6 +78,7 @@ export const POST: RequestHandler = async ({ params, cookies }) => {
|
||||
result = await triggerImagePrune(scheduleId);
|
||||
break;
|
||||
default:
|
||||
// Unreachable — validated in the resolution switch above.
|
||||
return json({ error: 'Invalid schedule type' }, { status: 400 });
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@ import { authorize } from '$lib/server/authorize';
|
||||
|
||||
export const POST: RequestHandler = async ({ params, cookies }) => {
|
||||
const auth = await authorize(cookies);
|
||||
if (auth.authEnabled && !await auth.can('schedules', 'edit')) {
|
||||
return json({ error: 'Permission denied' }, { status: 403 });
|
||||
}
|
||||
|
||||
const permDenied = await auth.requirePermission('schedules', 'edit');
|
||||
if (permDenied) return permDenied;
|
||||
|
||||
try {
|
||||
const { type, id } = params;
|
||||
@@ -28,6 +28,8 @@ export const POST: RequestHandler = async ({ params, cookies }) => {
|
||||
if (!setting) {
|
||||
return json({ error: 'Schedule not found' }, { status: 404 });
|
||||
}
|
||||
const envDenied = await auth.requireEnvAccess(setting.environmentId);
|
||||
if (envDenied) return envDenied;
|
||||
|
||||
const newEnabled = !setting.enabled;
|
||||
await updateAutoUpdateSettingById(scheduleId, {
|
||||
@@ -47,6 +49,8 @@ export const POST: RequestHandler = async ({ params, cookies }) => {
|
||||
if (!stack) {
|
||||
return json({ error: 'Schedule not found' }, { status: 404 });
|
||||
}
|
||||
const envDenied = await auth.requireEnvAccess(stack.environmentId);
|
||||
if (envDenied) return envDenied;
|
||||
|
||||
const newEnabled = !stack.autoUpdate;
|
||||
await updateGitStack(scheduleId, {
|
||||
@@ -63,6 +67,8 @@ export const POST: RequestHandler = async ({ params, cookies }) => {
|
||||
return json({ success: true, enabled: newEnabled });
|
||||
} else if (type === 'env_update_check') {
|
||||
// scheduleId is environmentId for env update check
|
||||
const envDenied = await auth.requireEnvAccess(scheduleId);
|
||||
if (envDenied) return envDenied;
|
||||
const config = await getEnvUpdateCheckSettings(scheduleId);
|
||||
if (!config) {
|
||||
return json({ error: 'Schedule not found' }, { status: 404 });
|
||||
@@ -84,6 +90,8 @@ export const POST: RequestHandler = async ({ params, cookies }) => {
|
||||
return json({ success: true, enabled: newEnabled });
|
||||
} else if (type === 'image_prune') {
|
||||
// scheduleId is environmentId for image prune
|
||||
const envDenied = await auth.requireEnvAccess(scheduleId);
|
||||
if (envDenied) return envDenied;
|
||||
const config = await getImagePruneSettings(scheduleId);
|
||||
if (!config) {
|
||||
return json({ error: 'Schedule not found' }, { status: 404 });
|
||||
|
||||
Reference in new issue
Block a user