Skip to content

Add restricted roles to Alchemy pages - #4102

Closed
sascha-karnatz wants to merge 7 commits into
AlchemyCMS:mainfrom
sascha-karnatz:restricted-roles
Closed

Add restricted roles to Alchemy pages#4102
sascha-karnatz wants to merge 7 commits into
AlchemyCMS:mainfrom
sascha-karnatz:restricted-roles

Conversation

@sascha-karnatz

@sascha-karnatz sascha-karnatz commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

What is this pull request for?

Add a restricted_roles column to the Page model to extend the restricted page behavior. This way it is possible restrict the access to pages only for a smaller set of users with a given role.

Notable changes (remove if none)

There is an addition to the MemberUser permission that is now evaluating also the restricted_roles column on the page. The default value is "member" and it should behave same way as before.

Screenshots

CleanShot 2026-07-27 at 17 32 20@2x

Checklist

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have added tests to cover this change

@sascha-karnatz
sascha-karnatz requested a review from a team as a code owner July 27, 2026 15:36
@tvdeyen tvdeyen added this to the 8.4 milestone Jul 27, 2026
@tvdeyen tvdeyen added the enhancement New feature or enhancement label Jul 27, 2026
@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.27%. Comparing base (4ccf434) to head (cf8b482).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4102   +/-   ##
=======================================
  Coverage   98.26%   98.27%           
=======================================
  Files         350      351    +1     
  Lines        9184     9207   +23     
=======================================
+ Hits         9025     9048   +23     
  Misses        159      159           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The configuration is (or can be) a subset of the user_roles configuration. This way every user with correct role can access a page. The default values is "member" to don't break the previous behavior for restricted pages.
Add a new restricted_roles column with a space separated list of roles, that can access a page. The default values is "member" to support the same behavior as before.
...to test that feature better in the dummy app.
Add getter and setter to the page model to split and join the group collection. Extend the set_restrictions_to_child_pages behavior to update restricted_roles as well. It was necessary to move from before_save to after_save to update restricted and restricted_roles of child pages. Otherwise inherit_restricted_status would read old data from the database.
Test if the user has the correct role to read the page. This change only affects the MemberUser permission. GuestUser can't see restricted pages and AuthorUser includes the MemberUser module. If Alchemy will be extended by other roles (like restricted_test in the Dummy app), it is necessary to create new abilities to prevent misconfigurations (like to many redirects).
This small web component allow to toggle inputs in forms based on checkbox values. The idea is to show the restricted_roles select only, if the user enabled the restricted checkbox before.
Provide a new PageRestrictedRolesSelect view component to render a select with all configured restricted_roles. The select is only visible if the restricted checkbox is enabled.

@tvdeyen tvdeyen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should call this permitted_roles. The page is restricted and the users with these roles are permitted to access the page.

@sascha-karnatz

Copy link
Copy Markdown
Contributor Author

Closing this PR in favor of #4112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants