feat: add guest role for new user registrations #2318
Conversation
- Add `guest` as a new user role (integer value 3) with read-only access - Guest users cannot download releases: disabled lock button in UI and server-side redirect on both show and download actions - Default role for new users is configurable via Setting.preset_role or ZEALOT_DEFAULT_USER_ROLE environment variable - Add grant_guest!/revoke_guest! methods consistent with other role helpers - Add scope :guests and guest? delegation in ApplicationPolicy - Add RSpec coverage for guest role behavior and download restrictions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
感谢你提交的问题或反馈,我会在有时间的时候来审查代码。 |
|
Thank you for the contribution! The general direction of this PR is correct, but I noticed a potential security vulnerability. The role check you added only covers the Web interface controllers, meaning the API endpoints are still missing these restrictions. Furthermore, we prefer to keep all permission-related logic encapsulated within Pundit policies( If you're open to it, could you please integrate these checks into the corresponding Pundit policies? This would help secure both the Web and API layers properly. |
4682eba to
6eca4c7
Compare
Add `download?` to ReleasePolicy so guest checks apply to both web and API layers. Replace manual `current_user&.guest?` guards in Download::ReleasesController with `authorize @Release, :download?` and a `rescue_from Pundit::NotAuthorizedError` handler. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Thanks for the feedback! I've moved the guest restriction out of the controllers and into |
Summary
guestas a new user role with read-only access (no download permission)showanddownloadactions areprotected server-side
Setting.preset_role(admin UI) orZEALOT_DEFAULT_USER_ROLEenv variableChanges
Usermodel: addguestto role enum (integer value 3, backward-compatible)Download::ReleasesController: block guest access on bothshowanddownloadactionsSetting.preset_role: supportZEALOT_DEFAULT_USER_ROLEenv var for container deploymentsUserRoles: addgrant_guest!/revoke_guest!methods,:guestsscope,guest?inrole_nameApplicationPolicy: delegateguest?to userTest plan
guestwhenpreset_roleis set to guestspec/models/user_spec.rbandspec/controllers/download/releases_controller_spec.rb