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 rules bookshelf plugin #6080

Merged
merged 1 commit into from
Nov 16, 2015
Merged

Conversation

ErisDS
Copy link
Member

@ErisDS ErisDS commented Nov 16, 2015

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 in models/ 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

  • change isPublicContext to detectPublicContext
    • behaviour now expands the context object out
    • this is a bit of a sideeffect, but this is the simplest change
      that makes it possible to use the context in the model layer without
      significant wider changes
  • add new access rules plugin
    • takes a context object as part of forge() & caches it on the model instance
    • provides helper functions for testing access rules later on

refs TryGhost#5614

- change isPublicContext to detectPublicContext
  - behaviour now expands the context object out
  - this is a bit of a sideeffect, but this is the simplest change
    that makes it possible to use the context in the model layer without
    significant wider changes
- add new access rules plugin
  - takes a context object as part of `forge()` & caches it on the model instance
  - provides helper functions for testing access rules later on
sebgie added a commit that referenced this pull request Nov 16, 2015
Add access rules bookshelf plugin
@sebgie sebgie merged commit 88ee22d into TryGhost:master Nov 16, 2015
@ErisDS ErisDS mentioned this pull request Nov 16, 2015
@ErisDS ErisDS deleted the model-access-rules branch November 16, 2015 18:20
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