Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: delete_job_groups instance authorization #1534

Open
wants to merge 3 commits into
base: release-jobs
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ jobs:
ACCESS_GROUPS_STATIC_VALUES: "ess"
CREATE_JOB_GROUPS: group1,group2
UPDATE_JOB_GROUPS: group1
DELETE_JOB_GROUPS: "archivemanager"
DELETE_JOB_GROUPS: "archivemanager,admin"
PROPOSAL_GROUPS: "proposalingestor"
SAMPLE_PRIVILEGED_GROUPS: "sampleingestor"
SAMPLE_GROUPS: "group1"
Expand Down
21 changes: 11 additions & 10 deletions src/casl/casl-ability.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,16 +389,6 @@ export class CaslAbilityFactory {
can(Action.JobRead, JobClass);
can(Action.JobCreate, JobClass);
can(Action.JobStatusUpdate, JobClass);
cannot(Action.JobDelete, JobClass);
} else if (
user.currentGroups.some((g) =>
configuration().deleteJobGroups.includes(g),
)
) {
/**
* authenticated users belonging to any of the group listed in DELETE_JOB_GROUPS
*/
can(Action.JobDelete, JobClass);
} else {
const jobUserAuthorizationValues = [
...user.currentGroups.map((g) => "@" + g),
Expand Down Expand Up @@ -459,6 +449,17 @@ export class CaslAbilityFactory {
can(Action.JobStatusUpdate, JobClass);
}
}
}
if (
user.currentGroups.some((g) =>
configuration().deleteJobGroups.includes(g),
)
) {
/**
* authenticated users belonging to any of the group listed in DELETE_JOB_GROUPS
*/
can(Action.JobDelete, JobClass);
} else {
cannot(Action.JobDelete, JobClass);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/casl/guards/policies.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export class PoliciesGuard implements CanActivate {
private execPolicyHandler(handler: PolicyHandler, ability: AppAbility) {
if (typeof handler === "function") {
const res = handler(ability);
//console.log("PoliciesGuard:execPolicyHandler ", res);
return res;
}
return handler.handle(ability);
Expand Down
20 changes: 10 additions & 10 deletions test/Jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4085,18 +4085,18 @@ describe("1100: Jobs: Test New Job Model", () => {
.expect("Content-Type", /json/);
});

it("1920: Delete job 1 as Admin, which should fail", async () => {
it("1920: Delete job 1 as Admin", async () => {
return request(appUrl)
.delete("/api/v3/jobs/" + encodedJobIdUser1)
.delete("/api/v3/jobs/" + encodedJobIdUser2)
.set("Accept", "application/json")
.set({ Authorization: `Bearer ${accessTokenAdmin}` })
.expect(TestData.DeleteForbiddenStatusCode)
.expect(TestData.SuccessfulDeleteStatusCode)
.expect("Content-Type", /json/);
});

it("1930: Delete job 1 as CREATE_JOB_GROUPS user, which should fail", async () => {
return request(appUrl)
.delete("/api/v3/jobs/" + encodedJobIdUser1)
.delete("/api/v3/jobs/" + encodedJobIdUser3)
.set("Accept", "application/json")
.set({ Authorization: `Bearer ${accessTokenUser1}` })
.expect(TestData.DeleteForbiddenStatusCode)
Expand All @@ -4105,7 +4105,7 @@ describe("1100: Jobs: Test New Job Model", () => {

it("1940: Delete job 1 as normal user, which should fail", async () => {
return request(appUrl)
.delete("/api/v3/jobs/" + encodedJobIdUser1)
.delete("/api/v3/jobs/" + encodedJobIdUser3)
.set("Accept", "application/json")
.set({ Authorization: `Bearer ${accessTokenUser51}` })
.expect(TestData.DeleteForbiddenStatusCode)
Expand All @@ -4130,7 +4130,7 @@ describe("1100: Jobs: Test New Job Model", () => {
.expect(TestData.SuccessfulGetStatusCode)
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.be.an("array").to.have.lengthOf(63);
res.body.should.be.an("array").to.have.lengthOf(62);
});
});

Expand Down Expand Up @@ -4160,7 +4160,7 @@ describe("1100: Jobs: Test New Job Model", () => {
.expect(TestData.SuccessfulGetStatusCode)
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.be.an("array").to.have.lengthOf(36);
res.body.should.be.an("array").to.have.lengthOf(35);
});
});

Expand Down Expand Up @@ -4237,7 +4237,7 @@ describe("1100: Jobs: Test New Job Model", () => {
.expect(TestData.SuccessfulGetStatusCode)
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.be.an("array").to.have.lengthOf(14);
res.body.should.be.an("array").to.have.lengthOf(13);
});
});

Expand Down Expand Up @@ -4326,7 +4326,7 @@ describe("1100: Jobs: Test New Job Model", () => {
.expect(TestData.SuccessfulGetStatusCode)
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.be.an("array").that.deep.contains({ all: [{ totalSets: 36 }] });
res.body.should.be.an("array").that.deep.contains({ all: [{ totalSets: 35 }] });
});
});

Expand Down Expand Up @@ -4401,7 +4401,7 @@ describe("1100: Jobs: Test New Job Model", () => {
.expect(TestData.SuccessfulGetStatusCode)
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.be.an("array").that.deep.contains({ all: [{ totalSets: 14 }] });
res.body.should.be.an("array").that.deep.contains({ all: [{ totalSets: 13 }] });
});
});

Expand Down
Loading