-
Notifications
You must be signed in to change notification settings - Fork 0
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
Built out shift signup endpoints #90
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just jumping in to point out a small issue with the order of migrations 🙂
backend/prisma/migrations/20220121012944_add_volunteer_users/migration.sql
Outdated
Show resolved
Hide resolved
backend/prisma/migrations/20220116032551_add_note_to_signup/migration.sql
Outdated
Show resolved
Hide resolved
...sma/migrations/20220116173256_added_unique_and_forign_key_contraints_to_signup/migration.sql
Outdated
Show resolved
Hide resolved
Sorry for the late response, I've been busy these past two days. I've made the changes now! |
@@ -128,6 +132,7 @@ const authorizedByAllRoles = () => | |||
const authorizedByAdmin = () => isAuthorizedByRole(new Set(["ADMIN"])); | |||
const authorizedByAdminAndVolunteer = () => | |||
isAuthorizedByRole(new Set(["ADMIN", "VOLUNTEER"])); | |||
const authorizedByVolunteer = () => isAuthorizedByRole(new Set(["VOLUNTEER"])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we also want to check isAuthorizedByUserId
here to check that the userid in the token is the same as the userid they are signingup the shift as
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added!
backend/prisma/migrations/20220116032551_add_note_to_signup/migration.sql
Outdated
Show resolved
Hide resolved
backend/graphql/index.ts
Outdated
@@ -128,6 +132,11 @@ const authorizedByAllRoles = () => | |||
const authorizedByAdmin = () => isAuthorizedByRole(new Set(["ADMIN"])); | |||
const authorizedByAdminAndVolunteer = () => | |||
isAuthorizedByRole(new Set(["ADMIN", "VOLUNTEER"])); | |||
const authorizedByVolunteer = () => { | |||
return ( | |||
isAuthorizedByRole(new Set(["VOLUNTEER"])) && isAuthorizedByUserId("userid") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think isAuthorizedByUserId
can be used as-is because it just checks the top-level argument with name userId
, but in this case, we want a field called userId
under an top-evel argument called shifts
(which is an array). Would likely need a new middleware function to do this check.
@LenaNguyen Thoughts about making this a separate task as it was not included in the original ticket description?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will likely need another ticket for sorting out access control anyways, we've been restricting nearly everything to admins only right now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah we can do it in a separate ticket
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made a ticket: #115
@@ -124,15 +124,16 @@ model Shift { | |||
} | |||
|
|||
model Signup { | |||
id Int @id @default(autoincrement()) | |||
shift Shift @relation(fields: [shiftId], references: [id]) | |||
shiftId Int @map("shifts_id") | |||
user User @relation(fields: [userId], references: [id]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thought: we can just make the foreign key reference on the volunteers table rather than the base users table to enforce the "only volunteers can sign up" rule
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That also works but I think our middleware for checking the role is good enough for now. We would still need to go through each shift to check that the volunteerID is the same as the volunteerID associated with the user in the token.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just one small thing and then i'll approve :))
backend/graphql/index.ts
Outdated
@@ -128,6 +132,11 @@ const authorizedByAllRoles = () => | |||
const authorizedByAdmin = () => isAuthorizedByRole(new Set(["ADMIN"])); | |||
const authorizedByAdminAndVolunteer = () => | |||
isAuthorizedByRole(new Set(["ADMIN", "VOLUNTEER"])); | |||
const authorizedByVolunteer = () => { | |||
return ( | |||
isAuthorizedByRole(new Set(["VOLUNTEER"])) && isAuthorizedByUserId("userid") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since the isAuthorizedByUserId
doesn't work in this case, pls remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for handling the changes!
Ticket link
Closes #54
Implementation description
CreateShiftSignupRequestDTO
,UpdateShiftSignupRequestDTO
,ShiftSignupResponseDTO
typescreateShiftSignups
updateShiftSignup
getShiftSignupsForUser
note
varchar toSignup
prisma modeluserId
inSignup
model.shiftId
anduserId
pair inSignup
modelSteps to test
migration
andgenerate
commandsusers
,shifts
,postings
,branches
.insert into branches (id, name) values (1, 'test branch');
insert into postings (id, branch_id, type, title, description, auto_closing_date, start_date, end_date, status) values (1, 1, 'GROUP', 'a', 'a', '2022-01-09T21:33:51.302Z', '2022-01-09T21:33:51.302Z', '2022-01-09T21:33:51.302Z', 'DRAFT');
localhost:5000/graphql
):mutation { createShifts( shifts: { postingId: "1" times: [ { startTime: "2022-01-25T13:30", endTime: "2022-01-25T15:00" } { startTime: "2022-01-26T12:00", endTime: "2022-01-26T16:00" } ] endDate: "2022-03-15" recurrenceInterval: BIWEEKLY } ) { id postingId startTime endTime } }
localhost:5000/graphql
and test the following new endpoints:createShiftSignups
,updateShiftSignup
, andgetShiftSignupsForUser
. The following are some query/mutations that I wrote in my own testing that you might be able to use:What should reviewers focus on?
Checklist