Skip to content

Add Access Control Layer #40

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

Merged
merged 4 commits into from
Sep 16, 2024
Merged

Add Access Control Layer #40

merged 4 commits into from
Sep 16, 2024

Conversation

doekenorg
Copy link
Collaborator

This feature adds an Access Control Layer on the SDK.

There is an abstract AccessController that needs an implementation in the proper context; for which I created one for WordPress on the plugin. It has a check on a Capability which is also an interface.

The Capability needs to declare whether its mutative (editing, moving, etc) or destructive (deleting). Every Capability is its own class type which defines its own contexts. To aid in the process there is an abstract DataViewCapability which requires a DataView as its context.

In the future extra Capabilities can be added without introducing immediate breaking changes to the Capability or AccessController interface. Adding a Capability class does require all AccessController instances to do a specific check.

This PR also introduces an AccessControlManager which defaults to a ReadOnlyAccessController. This will automatically allow any read capabilities, but reject any mutative and destructive ones.

The manager is a singleton which manages the current AccessController. Meaning the WordPress plugin, for example, will register a specific WordPressAccessController with the SDK. The manager keeps track of any set controllers, and can reset() to the previous one(s).

Anywhere in the code we need to check for capabilities, we need to call AccessControllManager::current() which will return the latest set AccessController. Then we can check the capability there with its context.

doekenorg and others added 3 commits September 11, 2024 14:38
- Add Access Controller interface
- Add Access Controller Manager with tests
- Add Capability enum
- Add All Access Controller implementation
@doekenorg doekenorg merged commit dc89bc1 into main Sep 16, 2024
5 checks passed
@doekenorg doekenorg deleted the feature/acl branch September 16, 2024 09:56
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.

2 participants