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

Add access control #10222

Merged
merged 182 commits into from
Oct 4, 2024
Merged

Add access control #10222

merged 182 commits into from
Oct 4, 2024

Conversation

djhi
Copy link
Collaborator

@djhi djhi commented Sep 18, 2024

Problems

  1. Using authProvider.getPermissions() leads developers to put the access control logic in the components. It's hard to keep track of the rules.
  2. The authentication checks are optimistic, so react-admin sometimes renders restricted content for a brief moment even though the user is anonymous

Solution

  1. Invert the logic: put the access control logic in the authProvider, and have the components rely on it. Add access control to the main pages, disabled by default.
  2. Make authentication check pessimistic

To do

How To Test

  • Open the ra-core/Admin/Resource stories
  • Open the ra-ui-materialui/layout/ResourceMenuItem stories

History

This is a big feature, so it was split into multiple PRs that got merged into this branch before merging it to next:

@djhi djhi added the WIP Work In Progress label Sep 18, 2024
@djhi djhi changed the title Access control resources Add access control to resources views Sep 18, 2024
Copy link
Member

@fzaninotto fzaninotto left a comment

Choose a reason for hiding this comment

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

Awesome! Can't wait to use that one.

I think the Permissions documentation needs some rewrite, though, to introduce this canAccess feature as an alternative to getPermissions. canAccess should be the recommended way. And we should rename the chapter to Access Control.

docs/Admin.md Outdated Show resolved Hide resolved
docs/Admin.md Outdated Show resolved Hide resolved
docs/Admin.md Outdated Show resolved Hide resolved
docs/AuthProviderWriting.md Outdated Show resolved Hide resolved
docs/useCanAccess.md Outdated Show resolved Hide resolved
packages/ra-core/src/core/Resource.spec.tsx Outdated Show resolved Hide resolved
packages/ra-core/src/core/Resource.spec.tsx Outdated Show resolved Hide resolved
packages/ra-core/src/core/Resource.tsx Outdated Show resolved Hide resolved
djhi and others added 3 commits September 19, 2024 11:32
Co-authored-by: Francois Zaninotto <francois@marmelab.com>
@djhi
Copy link
Collaborator Author

djhi commented Sep 19, 2024

Awesome! Can't wait to use that one.

I think the Permissions documentation needs some rewrite, though, to introduce this canAccess feature as an alternative to getPermissions. canAccess should be the recommended way. And we should rename the chapter to Access Control.

I'd rather do that in a dedicated PR

docs/CustomRoutes.md Outdated Show resolved Hide resolved
@@ -152,7 +152,7 @@ export type UseAuthStateResult<ErrorType = Error> = QueryObserverResult<
boolean,
ErrorType
> & {
authenticated: QueryObserverResult<boolean, ErrorType>['data'];
authenticated?: QueryObserverResult<boolean, ErrorType>['data'];
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Wrong fix IMO, we must introduce the same types as the other hooks for each state

Copy link
Member

Choose a reason for hiding this comment

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

Nice to have?

@fzaninotto fzaninotto merged commit 0dffc3b into next Oct 4, 2024
14 checks passed
@fzaninotto fzaninotto deleted the access-control-resources branch October 4, 2024 15:42
@fzaninotto fzaninotto added this to the 5.3.0 milestone Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants