2020-04-29 18:44:27 +03:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
|
|
|
const testUtils = require('../../utils');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const Promise = require('bluebird');
|
|
|
|
const Models = require('../../../core/server/models');
|
2015-08-18 16:08:52 +03:00
|
|
|
|
|
|
|
describe('Database Migration (special functions)', function () {
|
2020-02-24 23:51:09 +03:00
|
|
|
before(testUtils.teardownDb);
|
|
|
|
afterEach(testUtils.teardownDb);
|
2016-02-25 10:10:36 +03:00
|
|
|
afterEach(function () {
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.restore();
|
2016-02-25 10:10:36 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Fixtures', function () {
|
|
|
|
// Custom assertion for detection that a permissions is assigned to the correct roles
|
|
|
|
should.Assertion.add('AssignedToRoles', function (roles) {
|
2020-04-29 18:44:27 +03:00
|
|
|
let roleNames;
|
2016-02-25 10:10:36 +03:00
|
|
|
this.params = {operator: 'to have role'};
|
|
|
|
|
|
|
|
should.exist(this.obj);
|
|
|
|
|
|
|
|
this.obj.should.be.an.Object().with.property(['roles']);
|
|
|
|
this.obj.roles.should.be.an.Array();
|
2016-03-15 21:27:03 +03:00
|
|
|
|
|
|
|
// Ensure the roles are in id order
|
2016-06-11 21:23:27 +03:00
|
|
|
roleNames = _(this.obj.roles).sortBy('id').map('name').value();
|
2016-02-25 10:10:36 +03:00
|
|
|
roleNames.should.eql(roles);
|
|
|
|
});
|
|
|
|
|
2021-04-15 16:34:45 +03:00
|
|
|
should.Assertion.add('havePermission', function (name, roles = null) {
|
|
|
|
const permission = this.obj.find((p) => {
|
|
|
|
return p.name === name;
|
|
|
|
});
|
|
|
|
should.exist(permission, `Could not find permission ${name}`);
|
|
|
|
|
|
|
|
if (roles) {
|
|
|
|
permission.should.be.AssignedToRoles(roles);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-02-25 10:10:36 +03:00
|
|
|
// Custom assertion to wrap all permissions
|
|
|
|
should.Assertion.add('CompletePermissions', function () {
|
|
|
|
this.params = {operator: 'to have a complete set of permissions'};
|
2020-04-29 18:44:27 +03:00
|
|
|
const permissions = this.obj;
|
2016-02-25 10:10:36 +03:00
|
|
|
|
2021-04-15 16:34:45 +03:00
|
|
|
// If you have to change this number, please add the relevant `havePermission` checks below
|
2023-06-07 13:23:54 +03:00
|
|
|
permissions.length.should.eql(115);
|
2021-04-15 16:34:45 +03:00
|
|
|
|
|
|
|
permissions.should.havePermission('Export database', ['Administrator', 'DB Backup Integration']);
|
2023-03-21 23:42:00 +03:00
|
|
|
permissions.should.havePermission('Import database', ['Administrator', 'Self-Serve Migration Integration', 'DB Backup Integration']);
|
2021-04-15 16:34:45 +03:00
|
|
|
permissions.should.havePermission('Delete all content', ['Administrator', 'DB Backup Integration']);
|
|
|
|
permissions.should.havePermission('Backup database', ['Administrator', 'DB Backup Integration']);
|
|
|
|
|
|
|
|
permissions.should.havePermission('Send mail', ['Administrator', 'Admin Integration']);
|
|
|
|
|
|
|
|
permissions.should.havePermission('Browse notifications', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Add notifications', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Delete notifications', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
|
|
|
|
permissions.should.havePermission('Browse posts', ['Administrator', 'Editor', 'Author', 'Contributor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Read posts', ['Administrator', 'Editor', 'Author', 'Contributor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Edit posts', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Add posts', ['Administrator', 'Editor', 'Author', 'Contributor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Delete posts', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Publish posts', ['Administrator', 'Editor', 'Admin Integration', 'Scheduler Integration']);
|
|
|
|
|
|
|
|
permissions.should.havePermission('Browse settings', ['Administrator', 'Editor', 'Author', 'Contributor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Read settings', ['Administrator', 'Editor', 'Author', 'Contributor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Edit settings', ['Administrator', 'Admin Integration']);
|
|
|
|
|
|
|
|
permissions.should.havePermission('Generate slugs', ['Administrator', 'Editor', 'Author', 'Contributor', 'Admin Integration']);
|
|
|
|
|
|
|
|
permissions.should.havePermission('Browse tags', ['Administrator', 'Editor', 'Author', 'Contributor', 'Admin Integration']);
|
2023-03-21 23:42:00 +03:00
|
|
|
permissions.should.havePermission('Read tags', ['Administrator', 'Editor', 'Author', 'Contributor', 'Admin Integration', 'Self-Serve Migration Integration']);
|
2021-04-15 16:34:45 +03:00
|
|
|
permissions.should.havePermission('Edit tags', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Add tags', ['Administrator', 'Editor', 'Author', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Delete tags', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
|
|
|
|
permissions.should.havePermission('Browse themes', ['Administrator', 'Editor', 'Author', 'Contributor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Edit themes', ['Administrator', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Activate themes', ['Administrator', 'Admin Integration']);
|
2023-01-06 15:44:27 +03:00
|
|
|
permissions.should.havePermission('View active theme details', ['Administrator', 'Editor', 'Author', 'Admin Integration']);
|
2021-04-15 16:34:45 +03:00
|
|
|
permissions.should.havePermission('Upload themes', ['Administrator', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Download themes', ['Administrator', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Delete themes', ['Administrator', 'Admin Integration']);
|
|
|
|
|
|
|
|
permissions.should.havePermission('Browse users', ['Administrator', 'Editor', 'Author', 'Contributor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Read users', ['Administrator', 'Editor', 'Author', 'Contributor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Edit users', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Add users', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Delete users', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
|
|
|
|
permissions.should.havePermission('Assign a role', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Browse roles', ['Administrator', 'Editor', 'Author', 'Contributor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Browse invites', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Read invites', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Edit invites', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Add invites', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Delete invites', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
|
|
|
|
permissions.should.havePermission('Download redirects', ['Administrator', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Upload redirects', ['Administrator', 'Admin Integration']);
|
|
|
|
|
|
|
|
permissions.should.havePermission('Add webhooks', ['Administrator', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Edit webhooks', ['Administrator', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Delete webhooks', ['Administrator', 'Admin Integration']);
|
|
|
|
|
|
|
|
permissions.should.havePermission('Browse integrations', ['Administrator']);
|
|
|
|
permissions.should.havePermission('Read integrations', ['Administrator']);
|
|
|
|
permissions.should.havePermission('Edit integrations', ['Administrator']);
|
|
|
|
permissions.should.havePermission('Add integrations', ['Administrator']);
|
|
|
|
permissions.should.havePermission('Delete integrations', ['Administrator']);
|
|
|
|
|
|
|
|
permissions.should.havePermission('Browse API keys', ['Administrator']);
|
|
|
|
permissions.should.havePermission('Read API keys', ['Administrator']);
|
|
|
|
permissions.should.havePermission('Edit API keys', ['Administrator']);
|
|
|
|
permissions.should.havePermission('Add API keys', ['Administrator']);
|
|
|
|
permissions.should.havePermission('Delete API keys', ['Administrator']);
|
|
|
|
|
|
|
|
permissions.should.havePermission('Browse Actions', ['Administrator', 'Admin Integration']);
|
|
|
|
|
|
|
|
permissions.should.havePermission('Email preview', ['Administrator', 'Editor', 'Author', 'Contributor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Send test email', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Browse emails', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Read emails', ['Administrator', 'Editor', 'Author', 'Contributor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Retry emails', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
|
|
|
|
permissions.should.havePermission('Browse snippets', ['Administrator', 'Editor', 'Author', 'Contributor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Read snippets', ['Administrator', 'Editor', 'Author', 'Contributor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Edit snippets', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Add snippets', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Delete snippets', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
|
2022-05-12 16:53:32 +03:00
|
|
|
permissions.should.havePermission('Browse labels', ['Administrator', 'Editor', 'Author', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Read labels', ['Administrator', 'Editor', 'Author', 'Admin Integration']);
|
2021-05-07 12:51:44 +03:00
|
|
|
permissions.should.havePermission('Edit labels', ['Administrator', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Add labels', ['Administrator', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Delete labels', ['Administrator', 'Admin Integration']);
|
2021-04-15 16:34:45 +03:00
|
|
|
|
|
|
|
permissions.should.havePermission('Read member signin urls');
|
|
|
|
permissions.should.havePermission('Read identities');
|
|
|
|
permissions.should.havePermission('Auth Stripe Connect for Members');
|
|
|
|
|
|
|
|
permissions.should.havePermission('Browse Members');
|
|
|
|
permissions.should.havePermission('Read Members');
|
|
|
|
permissions.should.havePermission('Edit Members');
|
2023-03-21 23:42:00 +03:00
|
|
|
permissions.should.havePermission('Add Members', ['Administrator', 'Admin Integration', 'Self-Serve Migration Integration']);
|
2021-04-15 16:34:45 +03:00
|
|
|
permissions.should.havePermission('Delete Members');
|
|
|
|
|
2022-05-09 18:16:34 +03:00
|
|
|
permissions.should.havePermission('Browse offers');
|
|
|
|
permissions.should.havePermission('Read offers');
|
|
|
|
permissions.should.havePermission('Edit offers');
|
|
|
|
permissions.should.havePermission('Add offers');
|
|
|
|
|
|
|
|
permissions.should.havePermission('Browse Products', ['Administrator', 'Editor', 'Author', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Read Products', ['Administrator', 'Editor', 'Author', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Edit Products', ['Administrator', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Add Products', ['Administrator', 'Admin Integration']);
|
2021-04-15 16:34:45 +03:00
|
|
|
permissions.should.havePermission('Delete Products', ['Administrator']);
|
2021-06-23 15:54:28 +03:00
|
|
|
|
|
|
|
permissions.should.havePermission('Reset all passwords', ['Administrator']);
|
2021-09-27 11:59:09 +03:00
|
|
|
|
|
|
|
permissions.should.havePermission('Browse custom theme settings', ['Administrator']);
|
|
|
|
permissions.should.havePermission('Edit custom theme settings', ['Administrator']);
|
2022-03-31 11:52:04 +03:00
|
|
|
|
2022-05-12 13:32:30 +03:00
|
|
|
permissions.should.havePermission('Browse newsletters', ['Administrator', 'Editor', 'Author', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Read newsletters', ['Administrator', 'Editor', 'Author', 'Admin Integration']);
|
2022-05-09 18:16:34 +03:00
|
|
|
permissions.should.havePermission('Edit newsletters', ['Administrator', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Add newsletters', ['Administrator', 'Admin Integration']);
|
2022-07-08 11:19:09 +03:00
|
|
|
|
|
|
|
permissions.should.havePermission('Read explore data', ['Administrator', 'Admin Integration', 'Ghost Explore Integration']);
|
2022-07-05 16:18:56 +03:00
|
|
|
|
|
|
|
permissions.should.havePermission('Browse comments', ['Administrator', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Read comments', ['Administrator', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Edit comments', ['Administrator', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Add comments', ['Administrator', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Delete comments', ['Administrator', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Moderate comments', ['Administrator', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Like comments', ['Administrator', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Unlike comments', ['Administrator', 'Admin Integration']);
|
2022-07-22 13:03:05 +03:00
|
|
|
permissions.should.havePermission('Report comments', ['Administrator', 'Admin Integration']);
|
2022-10-20 05:48:29 +03:00
|
|
|
permissions.should.havePermission('Browse links', ['Administrator', 'Admin Integration']);
|
2023-01-31 11:40:44 +03:00
|
|
|
permissions.should.havePermission('Browse mentions', ['Administrator', 'Admin Integration']);
|
2023-06-07 13:23:54 +03:00
|
|
|
|
|
|
|
permissions.should.havePermission('Browse collections', ['Administrator', 'Editor', 'Author', 'Contributor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Read collections', ['Administrator', 'Editor', 'Author', 'Contributor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Edit collections', ['Administrator', 'Editor', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Add collections', ['Administrator', 'Editor', 'Author', 'Admin Integration']);
|
|
|
|
permissions.should.havePermission('Delete collections', ['Administrator', 'Editor', 'Admin Integration']);
|
2016-02-25 10:10:36 +03:00
|
|
|
});
|
|
|
|
|
2016-04-08 12:09:26 +03:00
|
|
|
describe('Populate', function () {
|
2017-01-25 16:47:49 +03:00
|
|
|
beforeEach(testUtils.setup('default'));
|
2016-04-14 18:54:49 +03:00
|
|
|
|
2017-11-28 21:32:03 +03:00
|
|
|
it('should populate all fixtures correctly', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const props = {
|
Sorted out the mixed usages of `include` and `withRelated` (#9425)
no issue
- this commit cleans up the usages of `include` and `withRelated`.
### API layer (`include`)
- as request parameter e.g. `?include=roles,tags`
- as theme API parameter e.g. `{{get .... include="author"}}`
- as internal API access e.g. `api.posts.browse({include: 'author,tags'})`
- the `include` notation is more readable than `withRelated`
- and it allows us to use a different easier format (comma separated list)
- the API utility transforms these more readable properties into model style (or into Ghost style)
### Model access (`withRelated`)
- e.g. `models.Post.findPage({withRelated: ['tags']})`
- driven by bookshelf
---
Commits explained.
* Reorder the usage of `convertOptions`
- 1. validation
- 2. options convertion
- 3. permissions
- the reason is simple, the permission layer access the model layer
- we have to prepare the options before talking to the model layer
- added `convertOptions` where it was missed (not required, but for consistency reasons)
* Use `withRelated` when accessing the model layer and use `include` when accessing the API layer
* Change `convertOptions` API utiliy
- API Usage
- ghost.api(..., {include: 'tags,authors'})
- `include` should only be used when calling the API (either via request or via manual usage)
- `include` is only for readability and easier format
- Ghost (Model Layer Usage)
- models.Post.findOne(..., {withRelated: ['tags', 'authors']})
- should only use `withRelated`
- model layer cannot read 'tags,authors`
- model layer has no idea what `include` means, speaks a different language
- `withRelated` is bookshelf
- internal usage
* include-count plugin: use `withRelated` instead of `include`
- imagine you outsource this plugin to git and publish it to npm
- `include` is an unknown option in bookshelf
* Updated `permittedOptions` in base model
- `include` is no longer a known option
* Remove all occurances of `include` in the model layer
* Extend `filterOptions` base function
- this function should be called as first action
- we clone the unfiltered options
- check if you are using `include` (this is a protection which could help us in the beginning)
- check for permitted and (later on default `withRelated`) options
- the usage is coming in next commit
* Ensure we call `filterOptions` as first action
- use `ghostBookshelf.Model.filterOptions` as first action
- consistent naming pattern for incoming options: `unfilteredOptions`
- re-added allowed options for `toJSON`
- one unsolved architecture problem:
- if you override a function e.g. `edit`
- then you should call `filterOptions` as first action
- the base implementation of e.g. `edit` will call it again
- future improvement
* Removed `findOne` from Invite model
- no longer needed, the base implementation is the same
2018-02-15 12:53:53 +03:00
|
|
|
posts: Models.Post.findAll({withRelated: ['tags']}),
|
2017-01-25 16:47:49 +03:00
|
|
|
tags: Models.Tag.findAll(),
|
|
|
|
users: Models.User.findAll({
|
|
|
|
filter: 'status:inactive',
|
|
|
|
context: {internal: true},
|
Sorted out the mixed usages of `include` and `withRelated` (#9425)
no issue
- this commit cleans up the usages of `include` and `withRelated`.
### API layer (`include`)
- as request parameter e.g. `?include=roles,tags`
- as theme API parameter e.g. `{{get .... include="author"}}`
- as internal API access e.g. `api.posts.browse({include: 'author,tags'})`
- the `include` notation is more readable than `withRelated`
- and it allows us to use a different easier format (comma separated list)
- the API utility transforms these more readable properties into model style (or into Ghost style)
### Model access (`withRelated`)
- e.g. `models.Post.findPage({withRelated: ['tags']})`
- driven by bookshelf
---
Commits explained.
* Reorder the usage of `convertOptions`
- 1. validation
- 2. options convertion
- 3. permissions
- the reason is simple, the permission layer access the model layer
- we have to prepare the options before talking to the model layer
- added `convertOptions` where it was missed (not required, but for consistency reasons)
* Use `withRelated` when accessing the model layer and use `include` when accessing the API layer
* Change `convertOptions` API utiliy
- API Usage
- ghost.api(..., {include: 'tags,authors'})
- `include` should only be used when calling the API (either via request or via manual usage)
- `include` is only for readability and easier format
- Ghost (Model Layer Usage)
- models.Post.findOne(..., {withRelated: ['tags', 'authors']})
- should only use `withRelated`
- model layer cannot read 'tags,authors`
- model layer has no idea what `include` means, speaks a different language
- `withRelated` is bookshelf
- internal usage
* include-count plugin: use `withRelated` instead of `include`
- imagine you outsource this plugin to git and publish it to npm
- `include` is an unknown option in bookshelf
* Updated `permittedOptions` in base model
- `include` is no longer a known option
* Remove all occurances of `include` in the model layer
* Extend `filterOptions` base function
- this function should be called as first action
- we clone the unfiltered options
- check if you are using `include` (this is a protection which could help us in the beginning)
- check for permitted and (later on default `withRelated`) options
- the usage is coming in next commit
* Ensure we call `filterOptions` as first action
- use `ghostBookshelf.Model.filterOptions` as first action
- consistent naming pattern for incoming options: `unfilteredOptions`
- re-added allowed options for `toJSON`
- one unsolved architecture problem:
- if you override a function e.g. `edit`
- then you should call `filterOptions` as first action
- the base implementation of e.g. `edit` will call it again
- future improvement
* Removed `findOne` from Invite model
- no longer needed, the base implementation is the same
2018-02-15 12:53:53 +03:00
|
|
|
withRelated: ['roles']
|
2017-01-25 16:47:49 +03:00
|
|
|
}),
|
|
|
|
roles: Models.Role.findAll(),
|
Sorted out the mixed usages of `include` and `withRelated` (#9425)
no issue
- this commit cleans up the usages of `include` and `withRelated`.
### API layer (`include`)
- as request parameter e.g. `?include=roles,tags`
- as theme API parameter e.g. `{{get .... include="author"}}`
- as internal API access e.g. `api.posts.browse({include: 'author,tags'})`
- the `include` notation is more readable than `withRelated`
- and it allows us to use a different easier format (comma separated list)
- the API utility transforms these more readable properties into model style (or into Ghost style)
### Model access (`withRelated`)
- e.g. `models.Post.findPage({withRelated: ['tags']})`
- driven by bookshelf
---
Commits explained.
* Reorder the usage of `convertOptions`
- 1. validation
- 2. options convertion
- 3. permissions
- the reason is simple, the permission layer access the model layer
- we have to prepare the options before talking to the model layer
- added `convertOptions` where it was missed (not required, but for consistency reasons)
* Use `withRelated` when accessing the model layer and use `include` when accessing the API layer
* Change `convertOptions` API utiliy
- API Usage
- ghost.api(..., {include: 'tags,authors'})
- `include` should only be used when calling the API (either via request or via manual usage)
- `include` is only for readability and easier format
- Ghost (Model Layer Usage)
- models.Post.findOne(..., {withRelated: ['tags', 'authors']})
- should only use `withRelated`
- model layer cannot read 'tags,authors`
- model layer has no idea what `include` means, speaks a different language
- `withRelated` is bookshelf
- internal usage
* include-count plugin: use `withRelated` instead of `include`
- imagine you outsource this plugin to git and publish it to npm
- `include` is an unknown option in bookshelf
* Updated `permittedOptions` in base model
- `include` is no longer a known option
* Remove all occurances of `include` in the model layer
* Extend `filterOptions` base function
- this function should be called as first action
- we clone the unfiltered options
- check if you are using `include` (this is a protection which could help us in the beginning)
- check for permitted and (later on default `withRelated`) options
- the usage is coming in next commit
* Ensure we call `filterOptions` as first action
- use `ghostBookshelf.Model.filterOptions` as first action
- consistent naming pattern for incoming options: `unfilteredOptions`
- re-added allowed options for `toJSON`
- one unsolved architecture problem:
- if you override a function e.g. `edit`
- then you should call `filterOptions` as first action
- the base implementation of e.g. `edit` will call it again
- future improvement
* Removed `findOne` from Invite model
- no longer needed, the base implementation is the same
2018-02-15 12:53:53 +03:00
|
|
|
permissions: Models.Permission.findAll({withRelated: ['roles']})
|
2017-01-25 16:47:49 +03:00
|
|
|
};
|
|
|
|
return Promise.props(props).then(function (result) {
|
|
|
|
// Post
|
|
|
|
should.exist(result.posts);
|
2017-06-08 18:36:14 +03:00
|
|
|
result.posts.length.should.eql(7);
|
2021-03-10 17:19:11 +03:00
|
|
|
result.posts.at(0).get('title').should.eql('Start here for a quick overview of everything you need to know');
|
|
|
|
result.posts.at(6).get('title').should.eql('Setting up apps and custom integrations');
|
2017-01-25 16:47:49 +03:00
|
|
|
|
|
|
|
// Tag
|
|
|
|
should.exist(result.tags);
|
|
|
|
result.tags.length.should.eql(1);
|
|
|
|
result.tags.at(0).get('name').should.eql('Getting Started');
|
|
|
|
|
|
|
|
// Post Tag relation
|
|
|
|
result.posts.at(0).related('tags').length.should.eql(1);
|
|
|
|
result.posts.at(0).related('tags').at(0).get('name').should.eql('Getting Started');
|
|
|
|
|
|
|
|
// User (Owner)
|
|
|
|
should.exist(result.users);
|
|
|
|
result.users.length.should.eql(1);
|
2017-05-29 20:25:19 +03:00
|
|
|
result.users.at(0).get('name').should.eql('Ghost');
|
2017-01-25 16:47:49 +03:00
|
|
|
result.users.at(0).get('status').should.eql('inactive');
|
|
|
|
result.users.at(0).related('roles').length.should.eql(1);
|
|
|
|
result.users.at(0).related('roles').at(0).get('name').should.eql('Owner');
|
|
|
|
|
|
|
|
// Roles
|
|
|
|
should.exist(result.roles);
|
2023-03-21 22:40:45 +03:00
|
|
|
result.roles.length.should.eql(10);
|
2017-01-25 16:47:49 +03:00
|
|
|
result.roles.at(0).get('name').should.eql('Administrator');
|
|
|
|
result.roles.at(1).get('name').should.eql('Editor');
|
|
|
|
result.roles.at(2).get('name').should.eql('Author');
|
2018-02-07 12:46:22 +03:00
|
|
|
result.roles.at(3).get('name').should.eql('Contributor');
|
|
|
|
result.roles.at(4).get('name').should.eql('Owner');
|
2018-10-02 19:46:38 +03:00
|
|
|
result.roles.at(5).get('name').should.eql('Admin Integration');
|
2022-07-08 10:55:58 +03:00
|
|
|
result.roles.at(6).get('name').should.eql('Ghost Explore Integration');
|
2023-03-21 22:40:45 +03:00
|
|
|
result.roles.at(7).get('name').should.eql('Self-Serve Migration Integration');
|
|
|
|
result.roles.at(8).get('name').should.eql('DB Backup Integration');
|
|
|
|
result.roles.at(9).get('name').should.eql('Scheduler Integration');
|
2017-01-25 16:47:49 +03:00
|
|
|
|
|
|
|
// Permissions
|
|
|
|
result.permissions.toJSON().should.be.CompletePermissions();
|
2017-11-28 21:32:03 +03:00
|
|
|
});
|
2016-04-08 12:09:26 +03:00
|
|
|
});
|
2015-08-18 16:08:52 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|