feat: allow admins to upload attachments to tickets - #64
Merged
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Change
Labels
p2-mediumfeatsecuritybackendWhat Changed
AttachmentController: openedPOST /api/tickets/{id}/attachmentstoADMINrole in addition toSTUDENTAttachmentService: gated ownership check, email-verified check, and admin notifications behind aisStudentflag; admins bypass these gates and can upload to any ticketSecurityUtils: hardenedgetCurrentRole()— replaced fragileiterator().next()with an explicit stream search byROLE_prefix; added null guards ongetAuthentication()in bothgetCurrentUserId()andgetCurrentRole()to throw controlledAppException(401)instead of NPEAttachmentService: added explicit unknown-role rejection (403) before the student/admin branching so no unexpected role can silently bypass ownership checks; added null-safe check onticket.getUserId()before.equals()roles-permissions.mdandapi-contract.mdto reflect admin upload permissionWhy
Admins needed the ability to attach supporting documents (e.g. resolution screenshots, policy PDFs) directly to tickets. The original implementation restricted uploads to students only. The fix also closes three security gaps found during code review: a fragile role-lookup that could silently mis-identify a role, an implicit role guard that any unknown role value could bypass, and a potential NPE on tickets with a null owner.
How to Test
POST /api/tickets/{id}/attachmentswithform-datakeyfilepointing to a JPEG or PDF201response with a signed URL in the payload403 FORBIDDENCLOSEDticket — expect403 TICKET_CLOSEDRelated Issues
Screenshots
N/A
Checklist
ApiResponse<T>wrapperapplication.yamlis NOT staged