Add access rules bookshelf plugin #6080
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR, along with #6068, the pagination and includeCount plugins, and work on the 'filter' api functionality that I'm hoping to raise a PR for later, is all working towards trying to improve the maintainability of the model layer in Ghost.
At the moment,
models/base/index.js
and the individual model files inmodels/
all contain a big mix of configuration and logic which is very hard to follow. It's also very 'hard coded' meaning every new feature we add needs more code somewhere, and keeps adding to the surface area. Meanwhile, this code is only tested using integration tests, which do little more than test the use-cases we care about for the admin UI.My aim is to start composing more of the business logic for models by building up our plugins, moving code from the base model and individual model files. Each plugin should have some business logic, be unit tested, and provide for configuring if and how it works for a particular model if deviation from the standard is needed. In this way, each of the individual model files should start to become much more readable, containing mostly configuration and small pieces of custom logic.
E.g. the way bookshelf models define their relations - we should be able to use this to automatically configure joins, nested updates, nested deletes, and other complex logic based on the information we already have or with some small extra definitions.
There are also community plugins which we could be leveraging to provide some complex logic: ericclemmons/bookshelf-manager#7. If our own plugins become generic enough, then they can be split out into separate repos with their tests.
The aim being to reduce the weight of the code in Ghost itself, and defer complex logic elsewhere so that we don't have to think about it or maintain it as we add new features :)
Note: the new functionality in this PR doesn't get used yet :)
refs #5614
that makes it possible to use the context in the model layer without
significant wider changes
forge()
& caches it on the model instance