Skip to content

Commit

Permalink
fixes in controller
Browse files Browse the repository at this point in the history
  • Loading branch information
despadam committed Aug 7, 2024
1 parent ab25d1e commit aabe451
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions src/jobs/jobs.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,6 @@ export class JobsController {
);
}
// verify that the user meet the requested permissions on the datasets listed
// const datasetIds = await this.checkDatasetIds(jobCreateDto.jobParams);
// build the condition
interface datasetsWhere {
where: {
Expand Down Expand Up @@ -679,20 +678,17 @@ export class JobsController {
}
const currentJobInstance =
await this.generateJobInstanceForPermissions(currentJob);
currentJobInstance.configVersion = this.getJobTypeConfiguration(
currentJobInstance.type,
)[JobsConfigSchema.ConfigVersion];

const ability = this.caslAbilityFactory.createForUser(
request.user as JWTUser,
);
// check if he/she can create this dataset
// check if the user can update this job
const canUpdateStatus =
ability.can(AuthOp.JobStatusUpdateAny, JobClass) ||
ability.can(AuthOp.JobStatusUpdateOwner, currentJobInstance) ||
ability.can(AuthOp.JobStatusUpdateConfiguration, currentJobInstance);
if (!canUpdateStatus) {
throw new ForbiddenException("Unauthorized to update this dataset");
throw new ForbiddenException("Unauthorized to update this job.");
}

// Update job in database
Expand All @@ -704,15 +700,6 @@ export class JobsController {
if (updatedJob !== null) {
await this.performJobStatusUpdateAction(updatedJob);
}

// Emit update event
// MN: not needed
// if (updatedJob) {
// this.eventEmitter.emit("jobUpdated", {
// instance: updatedJob,
// hookState: { oldData: [updatedJob] },
// });
// }
return updatedJob;
}

Expand Down Expand Up @@ -750,11 +737,11 @@ export class JobsController {
const ability = this.caslAbilityFactory.createForUser(
request.user as JWTUser,
);
const canCreate =
const canGet =
ability.can(AuthOp.JobReadAny, JobClass) ||
ability.can(AuthOp.JobReadAccess, currentJobInstance);
if (!canCreate) {
throw new ForbiddenException("Unauthorized to update this dataset");
if (!canGet) {
throw new ForbiddenException("Unauthorized to get this job.");
}
return currentJob;
}
Expand Down Expand Up @@ -800,25 +787,25 @@ export class JobsController {
throw { message: "Invalid filter syntax." };
}
// for each job run a casl JobReadOwner on a jobInstance
const datasetsFound = await this.jobsService.findAll(parsedFilter);
const datasetsAccessible: JobClass[] = [];
const jobsFound = await this.jobsService.findAll(parsedFilter);
const jobsAccessible: JobClass[] = [];
const ability = this.caslAbilityFactory.createForUser(
request.user as JWTUser,
);

for (const i in datasetsFound) {
// check if he/she can create this dataset
for (const i in jobsFound) {
// check if the user can get this job
const jobInstance = await this.generateJobInstanceForPermissions(
datasetsFound[i],
jobsFound[i],
);
const canCreate =
ability.can(AuthOp.JobReadAny, JobClass) ||
ability.can(AuthOp.JobReadAccess, jobInstance);
if (canCreate) {
datasetsAccessible.push(datasetsFound[i]);
jobsAccessible.push(jobsFound[i]);
}
}
return datasetsAccessible;
return jobsAccessible;
} catch (e) {
throw new HttpException(
{
Expand Down

0 comments on commit aabe451

Please sign in to comment.