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

#1964 - Added role to restrict MSFAA reissue #1985

Merged
merged 11 commits into from
Jun 6, 2023
1 change: 1 addition & 0 deletions sources/packages/backend/apps/api/src/auth/roles.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ export enum Role {
InstitutionCreateNote = "institution-create-note",
InstitutionApproveDeclineDesignation = "institution-approve-decline-designation",
InstitutionApproveDeclineOfferingChanges = "institution-approve-decline-offering-changes",
StudentReissueMSFAA = "student-reissue-msfaa",
}
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ describe("ApplicationAESTController(e2e)-reissueMSFAA", () => {
// Arrange
const endpoint = `/aest/application/9999/reissue-msfaa`;
const token = await getAESTToken(AESTGroups.BusinessAdministrators);

// Act/Assert
await request(app.getHttpServer())
.post(endpoint)
Expand Down Expand Up @@ -349,6 +350,23 @@ describe("ApplicationAESTController(e2e)-reissueMSFAA", () => {
}
}

it("Should not reissue an MSFAA when user is not a business administrator.", async () => {
// Arrange
const endpoint = "/aest/application/123/reissue-msfaa";
const token = await getAESTToken(AESTGroups.OperationsAdministrators);

// Act/Assert
await request(app.getHttpServer())
.post(endpoint)
.auth(token, BEARER_AUTH_TYPE)
.expect(HttpStatus.FORBIDDEN)
.expect({
statusCode: HttpStatus.FORBIDDEN,
message: "Forbidden resource",
error: "Forbidden",
});
});

afterAll(async () => {
await app?.close();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import {
import { ApplicationService } from "../../services";
import BaseController from "../BaseController";
import { ApplicationBaseAPIOutDTO } from "./models/application.dto";
import { AllowAuthorizedParty, Groups, UserToken } from "../../auth/decorators";
import {
AllowAuthorizedParty,
Groups,
Roles,
UserToken,
} from "../../auth/decorators";
import { AuthorizedParties } from "../../auth/authorized-parties.enum";
import { UserGroups } from "../../auth/user-groups.enum";
import {
Expand All @@ -28,7 +33,7 @@ import {
APPLICATION_NOT_FOUND,
INVALID_OPERATION_IN_THE_CURRENT_STATUS,
} from "@sims/services/constants";
import { IUserToken } from "../../auth";
import { IUserToken, Role } from "../../auth";

@AllowAuthorizedParty(AuthorizedParties.aest)
@Groups(UserGroups.AESTUser)
Expand Down Expand Up @@ -80,6 +85,7 @@ export class ApplicationAESTController extends BaseController {
* @param applicationId reference application id.
* @returns the newly created MSFAA.
*/
@Roles(Role.StudentReissueMSFAA)
@Post(":applicationId/reissue-msfaa")
@ApiNotFoundResponse({ description: "Application id not found." })
@ApiUnprocessableEntityResponse({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { JwtService } from "@nestjs/jwt";
import { IUserToken, Role } from "../../../../auth";
import { AESTGroups, getAESTToken } from "../../..";

const jwtService = new JwtService();

describe("Auth(e2e)-getAESTToken()", () => {
it("Should have all roles when ministry user is a business administrator.", async () => {
// Act
const token = await getAESTToken(AESTGroups.BusinessAdministrators);
const decodedToken = jwtService.decode(token) as IUserToken;
decodedToken.resource_access.aest.roles.sort((a, b) => a.localeCompare(b));
const allAESTRoles = Object.values(Role).sort((a, b) => a.localeCompare(b));

// Assert
expect(decodedToken.resource_access.aest.roles).toEqual(allAESTRoles);
});
});
1 change: 1 addition & 0 deletions sources/packages/web/src/types/contracts/aest/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ export enum Role {
InstitutionCreateNote = "institution-create-note",
InstitutionApproveDeclineDesignation = "institution-approve-decline-designation",
InstitutionApproveDeclineOfferingChanges = "institution-approve-decline-offering-changes",
StudentReissueMSFAA = "student-reissue-msfaa",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding <check-permission-role> in the vue side. I know the Vue button is inside form.io. But is there a way to disable the button when the user does not have right permission?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm working on that. Thanks.

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</template>
<notice-of-assessment-form-view
:assessment-id="assessmentId"
:can-reissue-m-s-f-a-a="true"
:can-reissue-m-s-f-a-a="hasStudentReissueMSFAARole"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that usually, the vue is disabling the component instead of hiding it. For this case to keep it simple I would no mind having it removed.

@reissue-m-s-f-a-a="reissueMSFAA"
/>
</full-page-container>
Expand All @@ -23,7 +23,8 @@ import { defineComponent } from "vue";
import NoticeOfAssessmentFormView from "@/components/common/NoticeOfAssessmentFormView.vue";
import { AESTRoutesConst } from "@/constants/routes/RouteConstants";
import { ApplicationService } from "@/services/ApplicationService";
import { useSnackBar } from "@/composables";
import { useAuth, useSnackBar } from "@/composables";
import { Role } from "@/types";

export default defineComponent({
components: {
Expand All @@ -45,6 +46,8 @@ export default defineComponent({
},
setup() {
const snackBar = useSnackBar();
const { hasRole } = useAuth();
const hasStudentReissueMSFAARole = hasRole(Role.StudentReissueMSFAA);
const reissueMSFAA = async (
applicationId: number,
reloadNOA: () => Promise<void>,
Expand All @@ -62,7 +65,7 @@ export default defineComponent({
}
};

return { reissueMSFAA, AESTRoutesConst };
return { reissueMSFAA, AESTRoutesConst, hasStudentReissueMSFAARole };
},
});
</script>