Skip to content

Commit 24326ff

Browse files
authored
Merge branch 'voting-feature' into copilot/fix-typecheck-issues
2 parents 7942a56 + 969d0c1 commit 24326ff

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

backend/src/services/rating-service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ export class RatingService implements IRatingService {
223223
* Check if the user is permitted to create/modify/delete this rating.
224224
*/
225225
private async checkPermission(rating: Rating, user: User): Promise<void> {
226+
if (!user.admitted) {
227+
throw new ForbiddenError("Only admitted users may rate projects");
228+
}
229+
226230
const settings = await this._settings.getSettings();
227231
if (!settings.application.allowRatingProjects) {
228232
throw new ForbiddenError(

backend/test/services/rating-service.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ describe("RatingService", () => {
5858
ratingUser.verifyToken = "";
5959
ratingUser.tokenSecret = "";
6060
ratingUser.forgotPasswordToken = "";
61+
ratingUser.admitted = true;
6162

6263
// A user who is a member of the project team
6364
teamMember = new User();
@@ -69,6 +70,7 @@ describe("RatingService", () => {
6970
teamMember.verifyToken = "";
7071
teamMember.tokenSecret = "";
7172
teamMember.forgotPasswordToken = "";
73+
teamMember.admitted = true;
7274

7375
[ratingUser, teamMember] = await userRepo.save([ratingUser, teamMember]);
7476

@@ -98,6 +100,23 @@ describe("RatingService", () => {
98100

99101
describe("checkPermission", () => {
100102
describe("via upsertRating", () => {
103+
it("throws ForbiddenError if user is not admitted", async () => {
104+
expect.assertions(1);
105+
106+
ratingUser.admitted = false;
107+
108+
const rating = Object.assign(new Rating(), {
109+
project: mockProject,
110+
user: ratingUser,
111+
criterion: mockCriterion,
112+
rating: 3,
113+
});
114+
115+
await expect(
116+
ratingService.upsertRating(rating, ratingUser),
117+
).rejects.toThrow(ForbiddenError);
118+
});
119+
101120
it("throws ForbiddenError when rating is globally disabled", async () => {
102121
expect.assertions(1);
103122

frontend/src/components/pages/view-project.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,16 @@ const EditProject = ({ project }: { project: ProjectDTO }) => {
9090
event.preventDefault();
9191
}, []);
9292

93+
const isAdmin = user?.role == UserRole.Root;
94+
9395
return (
9496
<Page>
9597
<PageHeader
9698
pageTitle={`Edit Project - ${project?.title}`}
9799
buttonText="Save Changes"
98100
buttonOnClick={sendSaveProjectRequest}
99101
buttonLoading={updateProjectInProgress}
100-
subTitle="You are part of the team of this project"
102+
subTitle={isAdmin ? null : "You are part of the team of this project"}
101103
/>
102104
{updateProjectError && (
103105
<div style={{ marginBottom: "1rem" }}>

0 commit comments

Comments
 (0)