Skip to content

Commit

Permalink
rename statusUpdate to update
Browse files Browse the repository at this point in the history
  • Loading branch information
despadam committed Oct 24, 2024
1 parent f1d6dc5 commit 03214be
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 102 deletions.
9 changes: 4 additions & 5 deletions src/casl/action.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export enum Action {
ReadOwn = "readown",
ReadAll = "readall",
Update = "update",
StatusUpdate = "statusUpdate",
Delete = "delete",
ListOwn = "listown",
ListAll = "listall",
Expand Down Expand Up @@ -182,17 +181,17 @@ export enum Action {
// endpoint authorization
JobCreate = "jobs_create",
JobRead = "jobs_read",
JobStatusUpdate = "job_update",
JobUpdate = "job_update",
JobDelete = "job_delete",
// data instance authorization
JobCreateConfiguration = "job_create_configuration",
JobCreateOwner = "job_create_owner",
JobCreateAny = "job_create_any",
JobReadAccess = "job_read_access",
JobReadAny = "job_read_any",
JobStatusUpdateConfiguration = "job_status_update_configuration",
JobStatusUpdateOwner = "job_status_update_owner",
JobStatusUpdateAny = "job_status_update_any",
JobUpdateConfiguration = "job_update_configuration",
JobUpdateOwner = "job_update_owner",
JobUpdateAny = "job_update_any",
//JobDeleteAny = "job_delete_any",

// -------------
Expand Down
52 changes: 26 additions & 26 deletions src/casl/casl-ability.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { Action } from "./action.enum";
import configuration from "src/config/configuration";
import {

Check failure on line 29 in src/casl/casl-ability.factory.ts

View workflow job for this annotation

GitHub Actions / eslint

Replace `⏎··CreateJobAuth,⏎··UpdateJobAuth,⏎` with `·CreateJobAuth,·UpdateJobAuth·`
CreateJobAuth,
StatusUpdateJobAuth,
UpdateJobAuth,
} from "src/jobs/types/jobs-auth.enum";

import { JobConfig } from "src/jobs/config/jobconfig";
Expand Down Expand Up @@ -367,12 +367,12 @@ export class CaslAbilityFactory {
cannot(Action.JobRead, JobClass);
if (
configuration().jobConfiguration.some(
(j) => j.statusUpdate.auth == StatusUpdateJobAuth.All,
(j) => j.update.auth == UpdateJobAuth.All,
)
) {
can(Action.JobStatusUpdate, JobClass);
can(Action.JobUpdate, JobClass);
} else {
cannot(Action.JobStatusUpdate, JobClass);
cannot(Action.JobUpdate, JobClass);
}
cannot(Action.JobDelete, JobClass);
} else {
Expand All @@ -388,7 +388,7 @@ export class CaslAbilityFactory {
*/
can(Action.JobRead, JobClass);
can(Action.JobCreate, JobClass);
can(Action.JobStatusUpdate, JobClass);
can(Action.JobUpdate, JobClass);
cannot(Action.JobDelete, JobClass);
} else if (
user.currentGroups.some((g) =>
Expand Down Expand Up @@ -437,26 +437,26 @@ export class CaslAbilityFactory {
}
}
const jobUpdateEndPointAuthorizationValues = [
...Object.values(StatusUpdateJobAuth),
...Object.values(UpdateJobAuth),
...jobUserAuthorizationValues,
];
if (
user.currentGroups.some((g) =>
configuration().statusUpdateJobGroups.includes(g),
configuration().updateJobGroups.includes(g),
)
) {
can(Action.JobStatusUpdate, JobClass);
can(Action.JobUpdate, JobClass);
} else {
if (
configuration().jobConfiguration.some(
(j) =>
j.statusUpdate.auth &&
j.update.auth &&
jobUpdateEndPointAuthorizationValues.includes(
j.statusUpdate.auth as string,
j.update.auth as string,
),
)
) {
can(Action.JobStatusUpdate, JobClass);
can(Action.JobUpdate, JobClass);
}
}
cannot(Action.JobDelete, JobClass);
Expand Down Expand Up @@ -1375,8 +1375,8 @@ export class CaslAbilityFactory {
datasetsValidation: true,
});
}
if (jobConfiguration.statusUpdate.auth === StatusUpdateJobAuth.All) {
can(Action.JobStatusUpdateConfiguration, JobClass, {
if (jobConfiguration.update.auth === UpdateJobAuth.All) {
can(Action.JobUpdateConfiguration, JobClass, {
ownerGroup: undefined,
});
}
Expand All @@ -1393,7 +1393,7 @@ export class CaslAbilityFactory {
*/
can(Action.JobReadAny, JobClass);
can(Action.JobCreateAny, JobClass);
can(Action.JobStatusUpdateAny, JobClass);
can(Action.JobUpdateAny, JobClass);
} else {
const jobUserAuthorizationValues = [
...user.currentGroups.map((g) => "@" + g),
Expand Down Expand Up @@ -1452,45 +1452,45 @@ export class CaslAbilityFactory {
}
}
const jobUpdateInstanceAuthorizationValues = [
...Object.values(StatusUpdateJobAuth).filter(
...Object.values(UpdateJobAuth).filter(
(v) => !String(v).includes("#job"),
),
...jobUserAuthorizationValues,
];

if (
user.currentGroups.some((g) =>
configuration().statusUpdateJobGroups.includes(g),
configuration().updateJobGroups.includes(g),
)
) {
if (
jobUpdateInstanceAuthorizationValues.some(
(a) => jobConfiguration.statusUpdate.auth === a,
(a) => jobConfiguration.update.auth === a,
)
) {
can(Action.JobStatusUpdateConfiguration, JobClass);
can(Action.JobUpdateConfiguration, JobClass);
}
can(Action.JobStatusUpdateOwner, JobClass, {
can(Action.JobUpdateOwner, JobClass, {
ownerUser: user.username,
});
can(Action.JobStatusUpdateOwner, JobClass, {
can(Action.JobUpdateOwner, JobClass, {
ownerGroup: { $in: user.currentGroups },
});
} else {
if (
jobUpdateInstanceAuthorizationValues.some(
(a) => jobConfiguration.statusUpdate.auth === a,
(a) => jobConfiguration.update.auth === a,
)
) {
can(Action.JobStatusUpdateConfiguration, JobClass);
can(Action.JobUpdateConfiguration, JobClass);
}
if (jobConfiguration.statusUpdate.auth === "#jobOwnerUser") {
can(Action.JobStatusUpdateConfiguration, JobClass, {
if (jobConfiguration.update.auth === "#jobOwnerUser") {
can(Action.JobUpdateConfiguration, JobClass, {
ownerUser: user.username,
});
}
if (jobConfiguration.statusUpdate.auth === "#jobOwnerGroup") {
can(Action.JobStatusUpdateConfiguration, JobClass, {
if (jobConfiguration.update.auth === "#jobOwnerGroup") {
can(Action.JobUpdateConfiguration, JobClass, {
ownerGroup: { $in: user.currentGroups },
});
}
Expand Down
14 changes: 7 additions & 7 deletions src/config/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
loadJobConfig,
registerCreateAction,
registerStatusUpdateAction,
registerUpdateAction,
} from "../jobs/config/jobconfig";
import { LogJobAction } from "../jobs/actions/logaction";
import { EmailJobAction } from "../jobs/actions/emailaction";
Expand Down Expand Up @@ -29,7 +29,7 @@ const configuration = () => {
process.env.DATASET_CREATION_VALIDATION_REGEX || ("" as string);

const createJobGroups = process.env.CREATE_JOB_GROUPS || ("" as string);
const statusUpdateJobGroups = process.env.UPDATE_JOB_GROUPS || ("" as string);
const updateJobGroups = process.env.UPDATE_JOB_GROUPS || ("" as string);
const deleteJobGroups = process.env.DELETE_JOB_GROUPS || ("" as string);

const proposalGroups = process.env.PROPOSAL_GROUPS || ("" as string);
Expand Down Expand Up @@ -98,7 +98,7 @@ const configuration = () => {
datasetCreationValidationEnabled: datasetCreationValidationEnabled,
datasetCreationValidationRegex: datasetCreationValidationRegex,
createJobGroups: createJobGroups,
statusUpdateJobGroups: statusUpdateJobGroups,
updateJobGroups: updateJobGroups,
deleteJobGroups: deleteJobGroups,
logoutURL: process.env.LOGOUT_URL ?? "", // Example: http://localhost:3000/
accessGroupsGraphQlConfig: {
Expand Down Expand Up @@ -230,10 +230,10 @@ export function registerDefaultActions() {
registerCreateAction(EmailJobAction);
registerCreateAction(URLAction);
registerCreateAction(RabbitMQJobAction);
// Status Update
registerStatusUpdateAction(LogJobAction);
registerStatusUpdateAction(EmailJobAction);
registerStatusUpdateAction(RabbitMQJobAction);
// Update
registerUpdateAction(LogJobAction);
registerUpdateAction(EmailJobAction);
registerUpdateAction(RabbitMQJobAction);
}

export type OidcConfig = ReturnType<typeof configuration>["oidc"];
Expand Down
4 changes: 2 additions & 2 deletions src/jobs/config/jobConfig.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
}
]
},
"statusUpdate": {
"update": {
"auth": "archivemanager",
"actions": [
{
Expand All @@ -60,7 +60,7 @@
"create": {
"auth": "#all"
},
"statusUpdate": {
"update": {
"auth": "#all"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/config/jobConfig.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const JobConfigSchema = {
},
additionalProperties: true,
},
statusUpdate: {
update: {
type: "object",
properties: {
auth: { type: "string" },
Expand Down
38 changes: 19 additions & 19 deletions src/jobs/config/jobconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import * as fs from "fs";
import { JobClass } from "../schemas/job.schema";
import { CreateJobDto } from "../dto/create-job.dto";
import { StatusUpdateJobDto } from "../dto/status-update-job.dto";
import { UpdateJobDto } from "../dto/update-job.dto";
import { JobsConfigSchema } from "../types/jobs-config-schema.enum";
import { Action } from "src/casl/action.enum";
import { CreateJobAuth, JobsAuth } from "../types/jobs-auth.enum";
Expand All @@ -30,18 +30,18 @@ export class JobConfig {
jobType: string;
configVersion: string;
create: JobOperation<CreateJobDto>;
statusUpdate: JobOperation<StatusUpdateJobDto>;
update: JobOperation<UpdateJobDto>;

constructor(
jobType: string,
configVersion: string,
create: JobOperation<CreateJobDto>,
statusUpdate: JobOperation<StatusUpdateJobDto>,
update: JobOperation<UpdateJobDto>,
) {
this.jobType = jobType;
this.configVersion = configVersion;
this.create = create;
this.statusUpdate = statusUpdate;
this.update = update;
}

/**
Expand All @@ -64,25 +64,25 @@ export class JobConfig {
if (!(Action.Create in jobData)) {
throw new Error(`No ${Action.Create} configured for job type "${type}"`);
}
if (!(Action.StatusUpdate in jobData)) {
if (!(Action.Update in jobData)) {
throw new Error(

Check failure on line 68 in src/jobs/config/jobconfig.ts

View workflow job for this annotation

GitHub Actions / eslint

Replace `⏎········`No·${Action.Update}·configured·for·job·type·"${type}"`,⏎······` with ``No·${Action.Update}·configured·for·job·type·"${type}"``
`No ${Action.StatusUpdate} configured for job type "${type}"`,
`No ${Action.Update} configured for job type "${type}"`,
);
}
const create = JobOperation.parse<CreateJobDto>(
createActions,
jobData[Action.Create] as Record<string, unknown>,
);
const statusUpdate = JobOperation.parse<StatusUpdateJobDto>(
statusUpdateActions,
jobData[Action.StatusUpdate] as Record<string, unknown>,
const update = JobOperation.parse<UpdateJobDto>(
updateActions,
jobData[Action.Update] as Record<string, unknown>,
);
return new JobConfig(type, configVersion, create, statusUpdate);
return new JobConfig(type, configVersion, create, update);
}
}

/**
* Encapsulates all information for a particular job operation (eg "create", "statusUpdate")
* Encapsulates all information for a particular job operation (eg "create", "update")
*/
export class JobOperation<DtoType> {
auth: JobsAuth | undefined;
Expand Down Expand Up @@ -180,15 +180,15 @@ export interface JobActionClass<DtoType> {

export type JobCreateAction = JobAction<CreateJobDto>;
// export type JobReadAction = JobAction<ReadJobDto>;
export type JobStatusUpdateAction = JobAction<StatusUpdateJobDto>;
export type JobUpdateAction = JobAction<UpdateJobDto>;

/**
* Action registration
*/
const createActions: Record<string, JobActionClass<CreateJobDto>> = {};
const statusUpdateActions: Record<
const updateActions: Record<

Check failure on line 189 in src/jobs/config/jobconfig.ts

View workflow job for this annotation

GitHub Actions / eslint

Replace `⏎··string,⏎··JobActionClass<UpdateJobDto>⏎` with `string,·JobActionClass<UpdateJobDto>`
string,
JobActionClass<StatusUpdateJobDto>
JobActionClass<UpdateJobDto>
> = {};

/**
Expand All @@ -199,10 +199,10 @@ export function registerCreateAction(action: JobActionClass<CreateJobDto>) {
createActions[action.actionType] = action;
}

export function registerStatusUpdateAction(
action: JobActionClass<StatusUpdateJobDto>,
export function registerUpdateAction(

Check failure on line 202 in src/jobs/config/jobconfig.ts

View workflow job for this annotation

GitHub Actions / eslint

Replace `⏎··action:·JobActionClass<UpdateJobDto>,⏎` with `action:·JobActionClass<UpdateJobDto>`
action: JobActionClass<UpdateJobDto>,
) {
statusUpdateActions[action.actionType] = action;
updateActions[action.actionType] = action;
}

/**
Expand All @@ -213,8 +213,8 @@ export function getRegisteredCreateActions(): string[] {
return Object.keys(createActions);
}

export function getRegisteredStatusUpdateActions(): string[] {
return Object.keys(statusUpdateActions);
export function getRegisteredUpdateActions(): string[] {
return Object.keys(updateActions);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApiProperty, ApiTags } from "@nestjs/swagger";
import { IsOptional, IsString, IsObject } from "class-validator";

@ApiTags("jobs")
export class StatusUpdateJobDto {
export class UpdateJobDto {
@ApiProperty({
type: String,
required: true,
Expand Down
Loading

0 comments on commit 03214be

Please sign in to comment.