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

Enforce Stricter Validation on Access Type Edits #392

Merged
merged 3 commits into from
Feb 8, 2024

Conversation

nik-dange
Copy link
Member

@nik-dange nik-dange commented Jan 28, 2024

Info

Closes #389

Description

Moving forward, we'll only allow admin edits to be done manually in the DB. This PR adds a few checks to ensure accidental self-demotions cannot occur, as well as the ability to demote admins/promote others to admin.

Changes

  • A few conditional checks for access type edits

Type of Change

  • Patch (non-breaking change/bugfix)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to not work as
    expected)
  • Documentation (A change to a README/description)
  • Continuous Integration/DevOps Change (Related to deployment steps, continuous integration
    workflows, linting, etc.)
  • Other: (Fill In)

If you've selected Patch, Minor, or Major as your change type, make sure to bump the version before merging in package.json!

Testing

I have tested that my changes fully resolve the linked issue ...

  • locally.
  • on the testing API/testing database.
  • with appropriate Postman routes. Screenshots are included below.

Checklist

  • I have performed a self-review of my own code.
  • I have followed the style guidelines of this project.
  • I have appropriately edited the API version in the package.json file.
  • My changes produce no new warnings.

Screenshots

Please include a screenshot of your Postman testing passing successfully.

Copy link

Thanks for contributing!
If you've made changes to the API's functionality, please make sure to bump the package
version—see this guide to semantic versioning for details—and
document those changes as appropriate.

@nik-dange
Copy link
Member Author

Don't merge I didn't test yet 🥱

@nik-dange
Copy link
Member Author

Screenshot 2024-01-29 at 10 13 55 PM Screenshot 2024-01-29 at 10 14 07 PM Screenshot 2024-01-29 at 10 14 30 PM

const oldAccess = currUser.accessType;
// Prevent a user from demoting themselves
if (currentUser.email === userEmail) {
throw new BadRequestError('Cannot alter own access level');
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this should be a ForbiddenError but I'll get around to changing it in a bit

@nik-dange nik-dange marked this pull request as ready for review January 30, 2024 06:15
Copy link
Contributor

@dowhep dowhep left a comment

Choose a reason for hiding this comment

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

LGTM 🚀 🚀 I love that you added more details to the "attempting to demote oneself" test

@nik-dange nik-dange merged commit 93d90ad into master Feb 8, 2024
5 checks passed
@nik-dange nik-dange deleted the bug/restrict-admin-accessType-changes branch February 29, 2024 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

patch /admin/access route has no role level validation
2 participants