Skip to content

Commit

Permalink
change getJobMatchingConfiguration function to explicitly use job typ…
Browse files Browse the repository at this point in the history
…e, st it can be used for all cases where we need to extract the configuration, without having to pass the full dto
  • Loading branch information
sofyalaski committed Jul 14, 2024
1 parent eb1962f commit 070e964
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/jobs/jobs.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ export class JobsController {
const jobInstance = new JobClass();
jobInstance._id = job._id;
jobInstance.id = job.id;
jobInstance.configuration = job.configuration;
jobInstance.type = job.type;
//jobInstance.configuration = configuration().statusUpdateJobGroups;
jobInstance.ownerGroup = job.ownerGroup;
jobInstance.ownerUser = job.ownerUser;

Expand All @@ -364,25 +365,25 @@ export class JobsController {
/**
* Check job type matching configuration
*/
getJobMatchingConfiguration = (createJobDto: CreateJobDtoWithConfig) => {
getJobMatchingConfiguration = (createJobDtoType: string) => {
const jobConfigs = configuration().jobConfiguration;
const matchingConfig = jobConfigs.filter(
(j) => j.jobType == createJobDto.type,
(j) => j.jobType == createJobDtoType,
);

if (matchingConfig.length != 1) {
if (matchingConfig.length > 1) {
Logger.error(
"More than one job configurations matching type " + createJobDto.type,
"More than one job configurations matching type " + createJobDtoType,
);
} else {
Logger.error("No job configuration matching type " + createJobDto.type);
Logger.error("No job configuration matching type " + createJobDtoType);
}
// return error that job type does not exists
throw new HttpException(
{
status: HttpStatus.BAD_REQUEST,
message: "Invalid job type: " + createJobDto.type,
message: "Invalid job type: " + createJobDtoType,
},
HttpStatus.BAD_REQUEST,
);
Expand All @@ -400,15 +401,15 @@ export class JobsController {
// NOTE: We need JobClass instance because casl module works only on that.
// If other fields are needed can be added later.
const jobInstance = new JobClass();
const jobConfiguration = this.getJobMatchingConfiguration(jobCreateDto);
const jobConfiguration = this.getJobMatchingConfiguration(jobCreateDto.type);

jobInstance._id = "";
jobInstance.accessGroups = [];
jobInstance.type = jobCreateDto.type;
jobInstance.contactEmail = jobCreateDto.contactEmail;
jobInstance.jobParams = jobCreateDto.jobParams;
jobInstance.datasetsValidation = false;
jobInstance.configuration = jobConfiguration;
jobInstance.configuration = jobConfiguration;
jobInstance.statusCode = "Initializing";
jobInstance.statusMessage =
"Building and validating job, verifying authorization";
Expand Down Expand Up @@ -551,7 +552,7 @@ export class JobsController {
* Send off to external service, update job in database if needed
*/
async performJobCreateAction(jobInstance: JobClass): Promise<void> {
const jobConfig = this.getJobMatchingConfiguration(jobInstance);
const jobConfig = this.getJobMatchingConfiguration(jobInstance.type);
for (const action of jobConfig.create.actions) {
await action.performJob(jobInstance).catch((err: Error) => {
if (err instanceof HttpException) {
Expand Down Expand Up @@ -654,6 +655,7 @@ export class JobsController {
);
}
const currentJobInstance = await this.generateJobInstanceForPermissions(currentJob);
currentJobInstance.configuration = this.getJobMatchingConfiguration(currentJobInstance.type)

const ability = this.caslAbilityFactory.createForUser(request.user as JWTUser);
// check if he/she can create this dataset
Expand Down

0 comments on commit 070e964

Please sign in to comment.