Skip to content

Commit 58e265d

Browse files
authored
Merge pull request #107 from topcoder-platform/PM-5349-1
PM-5349: allow Talent Managers to access Talent report API
2 parents 7ed909f + ca47130 commit 58e265d

3 files changed

Lines changed: 31 additions & 12 deletions

File tree

src/reports/member/guards/member-talent-report.guard.spec.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,24 @@ describe("MemberTalentReportGuard", () => {
6868
).toBe(true);
6969
});
7070

71-
it("denies talent manager users", () => {
72-
expect(() =>
71+
it("allows talent manager users", () => {
72+
expect(
7373
guard.canActivate(
7474
createExecutionContext({
7575
roles: [UserRoles.TalentManager],
7676
}),
7777
),
78-
).toThrow(ForbiddenException);
78+
).toBe(true);
79+
});
80+
81+
it("allows role claim with topcoder talent manager prefix", () => {
82+
expect(
83+
guard.canActivate(
84+
createExecutionContext({
85+
role: "Topcoder Talent Manager",
86+
}),
87+
),
88+
).toBe(true);
7989
});
8090

8191
it("denies machine clients without all reports scope", () => {

src/reports/member/guards/member-talent-report.guard.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@ import {
55
Injectable,
66
UnauthorizedException,
77
} from "@nestjs/common";
8-
import { Scopes } from "src/app-constants";
8+
import { Scopes, UserRoles } from "src/app-constants";
99
import {
1010
AuthUserLike,
1111
getNormalizedRoles,
1212
hasAccessToScopes,
1313
hasAdminRole,
1414
} from "../../../auth/permissions.util";
1515

16+
const allowedHumanRoles = new Set<string>([
17+
UserRoles.TalentManager.toLowerCase(),
18+
]);
19+
1620
/**
17-
* Allows only administrator users, or machine clients with all-reports scope,
18-
* to access the open-to-work Talent report and contact export.
21+
* Allows administrator and Talent Manager users, or machine clients with
22+
* all-reports scope, to access the open-to-work Talent report and contact export.
1923
*/
2024
@Injectable()
2125
export class MemberTalentReportGuard implements CanActivate {
@@ -38,7 +42,12 @@ export class MemberTalentReportGuard implements CanActivate {
3842
);
3943
}
4044

41-
if (hasAdminRole(getNormalizedRoles(authUser))) {
45+
const roles = getNormalizedRoles(authUser);
46+
47+
if (
48+
hasAdminRole(roles) ||
49+
roles.some((role) => allowedHumanRoles.has(role))
50+
) {
4251
return true;
4352
}
4453

src/reports/member/member-search.controller.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class MemberSearchController {
3535
constructor(private readonly memberSearchService: MemberSearchService) {}
3636

3737
/**
38-
* Returns dashboard data for the admin-only open-to-work Talent report.
38+
* Returns dashboard data for the open-to-work Talent report.
3939
* @param query Role, availability, and pagination filters.
4040
* @returns Dashboard summary and paginated member rows.
4141
*/
@@ -45,11 +45,11 @@ export class MemberSearchController {
4545
summary: "List open-to-work members by preferred role",
4646
description:
4747
"Returns open-to-work member totals, preferred-role counts, and a paginated member list. " +
48-
"Accessible by Administrator users only.",
48+
"Accessible by Administrator and Talent Manager users only.",
4949
})
5050
@ApiResponse({ status: 200, type: OpenToWorkTalentResponseDto })
5151
@ApiResponse({ status: 401, description: "Unauthenticated" })
52-
@ApiResponse({ status: 403, description: "Forbidden – admin role required" })
52+
@ApiResponse({ status: 403, description: "Forbidden – insufficient role" })
5353
getOpenToWorkTalent(
5454
@Query() query: OpenToWorkTalentQueryDto,
5555
): Promise<OpenToWorkTalentResponseDto> {
@@ -69,11 +69,11 @@ export class MemberSearchController {
6969
summary: "Export open-to-work members by preferred role",
7070
description:
7171
"Exports open-to-work members with email and phone fields. " +
72-
"Accessible by Administrator users only.",
72+
"Accessible by Administrator and Talent Manager users only.",
7373
})
7474
@ApiResponse({ status: 200, description: "Export successful." })
7575
@ApiResponse({ status: 401, description: "Unauthenticated" })
76-
@ApiResponse({ status: 403, description: "Forbidden – admin role required" })
76+
@ApiResponse({ status: 403, description: "Forbidden – insufficient role" })
7777
exportOpenToWorkTalent(@Query() query: OpenToWorkTalentQueryDto) {
7878
return this.memberSearchService.exportOpenToWorkTalent(query);
7979
}

0 commit comments

Comments
 (0)