Skip to content

feat: add guest role for new user registrations #2318

Open
longfei91 wants to merge 2 commits into
tryzealot:developfrom
longfei91:feat/guest-role-for-new-users
Open

feat: add guest role for new user registrations #2318
longfei91 wants to merge 2 commits into
tryzealot:developfrom
longfei91:feat/guest-role-for-new-users

Conversation

@longfei91

@longfei91 longfei91 commented May 6, 2026

Copy link
Copy Markdown

Summary

  • Add guest as a new user role with read-only access (no download permission)
  • Guest users see a disabled lock button on release pages; both show and download actions are
    protected server-side
  • Default role for new users is configurable via Setting.preset_role (admin UI) or
    ZEALOT_DEFAULT_USER_ROLE env variable

Changes

  • User model: add guest to role enum (integer value 3, backward-compatible)
  • Download::ReleasesController: block guest access on both show and download actions
  • Setting.preset_role: support ZEALOT_DEFAULT_USER_ROLE env var for container deployments
  • UserRoles: add grant_guest! / revoke_guest! methods, :guests scope, guest? in role_name
  • ApplicationPolicy: delegate guest? to user
  • i18n: add translations for guest role and no-permission messages (en + zh-CN)

Test plan

  • Register a new user → verify role is guest when preset_role is set to guest
  • As guest, visit a release page → download button is disabled (lock icon)
  • As guest, directly access download URL → redirected with alert
  • As member/developer/admin, download works normally
  • Admin panel: role selector includes Guest option
  • RSpec: spec/models/user_spec.rb and spec/controllers/download/releases_controller_spec.rb

- 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>
@welcome

welcome Bot commented May 6, 2026

Copy link
Copy Markdown

感谢你提交的问题或反馈,我会在有时间的时候来审查代码。
Thanks so much for opening your first PR here!

@icyleaf

icyleaf commented May 8, 2026

Copy link
Copy Markdown
Member

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(app/policies directory) rather than in the controllers themselves to ensure consistency and maintainability.

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.

@icyleaf icyleaf force-pushed the develop branch 2 times, most recently from 4682eba to 6eca4c7 Compare May 9, 2026 13:43
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>
@longfei91

Copy link
Copy Markdown
Author

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(app/policies directory) rather than in the controllers themselves to ensure consistency and maintainability.

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.

Thanks for the feedback! I've moved the guest restriction out of the controllers and into
ReleasePolicy#download?. Download::ReleasesController now uses authorize @Release, :download? with a
rescue_from Pundit::NotAuthorizedError handler, keeping all permission logic in the policy layer and
covering both web and API endpoints consistently.

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.

3 participants