-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from uwblueprint/review-access-verification
implement isAuthorizedToReview
- Loading branch information
Showing
12 changed files
with
206 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { gql } from "apollo-server-express"; | ||
|
||
const reviewType = gql` | ||
extend type Query { | ||
isAuthorizedToReview(applicationId: Int!, reviewerUserId: String!): Boolean! | ||
} | ||
`; | ||
|
||
export default reviewType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,23 +10,20 @@ const SEEDED_DATA = [ | |
last_name: "Doe", | ||
email: "[email protected]", | ||
auth_id: "bide", | ||
id: 1, | ||
role: "User", | ||
}, | ||
{ | ||
first_name: "Jane", | ||
last_name: "Doe", | ||
email: "[email protected]", | ||
auth_id: "none", | ||
id: 2, | ||
role: "Admin", | ||
}, | ||
{ | ||
first_name: "UW", | ||
last_name: "Blueprint", | ||
email: "[email protected]", | ||
auth_id: "1Z4wyuonu9MhAi4VoAEiTMVj1iT2", | ||
id: 4, | ||
role: "Admin", | ||
}, | ||
]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ const userEmails = ["[email protected]", "[email protected]"]; | |
|
||
const SEEDED_DATA = [ | ||
{ | ||
id: 1, | ||
applicationId: 1, | ||
reviewerId: 1, | ||
reviewerEmail: userEmails[0], | ||
|
@@ -21,7 +20,6 @@ const SEEDED_DATA = [ | |
skillCategory: "junior", | ||
}, | ||
{ | ||
id: 2, | ||
applicationId: 1, | ||
reviewerId: 2, | ||
reviewerEmail: userEmails[1], | ||
|
@@ -42,6 +40,7 @@ export const up: Migration = async ({ context: sequelize }) => { | |
allowNull: false, | ||
primaryKey: true, | ||
unique: true, | ||
autoIncrement: true, | ||
}, | ||
applicationId: { | ||
type: DataType.INTEGER, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
backend/typescript/services/implementations/reviewService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import User from "../../models/user.model"; | ||
import IReviewService from "../interfaces/reviewService"; | ||
import ApplicationDashboardTable from "../../models/applicationDashboard.model"; | ||
|
||
class ReviewService implements IReviewService { | ||
/* eslint-disable class-methods-use-this */ | ||
async isAuthorizedToReview( | ||
applicationId: number, | ||
userId: string, | ||
): Promise<boolean> { | ||
const users: Array<User> | null = await User.findAll({ | ||
where: { | ||
auth_id: userId, | ||
}, | ||
}); | ||
if (users && users.length === 1) { | ||
const user = users[0]; | ||
const application: ApplicationDashboardTable | null = await ApplicationDashboardTable.findOne( | ||
{ | ||
where: { | ||
reviewerId: user.id, | ||
applicationId, | ||
}, | ||
}, | ||
); | ||
if (application) return true; | ||
return false; | ||
} | ||
throw Error("Multiple or no user(s) found with same firebase userId"); | ||
} | ||
} | ||
|
||
export default ReviewService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
interface IReviewService { | ||
/** | ||
* Determine if the reviewerUserId has been assigned to the application with id applicationId | ||
* with the specified email address | ||
* @param applicationId the id of the application the reviewer is trying to review | ||
* @param reviewerUserId the firebase user id of the revieweer | ||
* @returns true if user is authorized to review the application and authorized, false otherwise | ||
*/ | ||
isAuthorizedToReview(applicationId: number, userId: string): Promise<boolean>; | ||
} | ||
|
||
export default IReviewService; |