-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Setup schema and models for API Key authentication #9904
Conversation
4ed3a8d
to
a5a63b7
Compare
@kevinansfield When do you need a review on this? Let me know if it's blocking you. |
a5a63b7
to
0a42eb4
Compare
I am getting an error when running the migration
🤷🏻♀️ |
ca559e8
to
7d626e1
Compare
Oops, I pulled the role fixtures out for the tests but missed the relevant schema fixture. Should be fixed now 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a first review round. Left some first comments. I need to continue with my tasks, will try to review again later :)
ES6: I know you are used to liberal let 😁but server uses constantly const. If we do two different stylings, it's confusing.
}; | ||
|
||
return models.ApiKey.add(attrs).then((api_key) => { | ||
return models.ApiKey.where({id: api_key.id}).fetch({withRelated: ['role']}) |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
api_key.get('type').should.eql('admin'); | ||
|
||
// defaults | ||
api_key.related('role').should.exist; |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
}); | ||
}; | ||
|
||
module.exports.up = function setupIntegrations(options) { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
logging.info(message); | ||
} | ||
|
||
logging.warn(`(${result.done}/${result.expected}) ${message}`); |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
core/server/models/api-key.js
Outdated
add(data, unfilteredOptions) { | ||
const options = ApiKey.filterOptions(unfilteredOptions, 'add'); | ||
|
||
return ghostBookshelf.Model.add.call(this, data, options); |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
Updated, and ready for review again 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, few minor tiny comments
core/server/data/migrations/versions/2.2/2-add-integrations-and-api-key-tables.js
Show resolved
Hide resolved
core/server/models/api-key.js
Outdated
// - content key = no role | ||
if (this.hasChanged('type')) { | ||
if (this.get('type') === 'admin') { | ||
tasks.setAdminRole = Role.findOne({name: 'Admin API Client'}, {columns: ['id']}) |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
core/server/models/integration.js
Outdated
api_keys: function apiKeys() { | ||
return this.hasMany('ApiKey'); | ||
} | ||
}, { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
1ea8e8e
to
b7026bb
Compare
b7026bb
to
61ee9ce
Compare
Rebased and resolved conflicts |
61ee9ce
to
a1455bb
Compare
.invokeThen('destroy', options) | ||
.then(() => role.destroy()) | ||
.then(() => { | ||
logging.info(message); |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
a8cc2c0
to
cb983bb
Compare
@@ -10,6 +10,12 @@ Role = ghostBookshelf.Model.extend({ | |||
|
|||
tableName: 'roles', | |||
|
|||
relationships: ['permissions'], |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 comment and 1 question 👍
core/test/unit/models/role_spec.js
Outdated
const should = require('should'); | ||
|
||
describe('Unit: models/role', function () { | ||
before(function () { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
models.init(); | ||
}); | ||
|
||
before(testUtils.teardown); |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
cb983bb
to
df2833c
Compare
"description": "Blog Owner" | ||
}, | ||
{ | ||
"name": "Admin API Client", |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
from: relations.from, | ||
to: relations.to, | ||
entries: { | ||
'Admin API Client': relations.entries['Admin API Client'] |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
@kirrg001 do you have any insight on the integration test that has started to fail here? https://travis-ci.org/TryGhost/Ghost/jobs/436072806#L4875 It seems as though using |
{ | ||
id: ObjectId.generate(), | ||
type: 'admin' | ||
// integration_id: DataGenerator.Content.integrations[0].id |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
Bookshelf relation does not change the JSON output, it modifies the model. |
👍 ok, I'll update the test to match the internal behaviour we expect in this case. Thanks! |
@kevinansfield Pls let me know when the PR is ready for final test |
refs TryGhost#9865 - schema migrations - adds `integrations` and `api_keys` tables - inserts `integration` and `api_key` permissions and Administrator role relationships - inserts `Admin Integration` role and permissions - adds `Integration` model - adds `ApiKey` model - creates default secret if not given - hardcodes associated role based on key type - `admin` = `Admin API Client` - `content` = no role - updates `Role` model to use bookshelf-relationships for auto cleanup of relationships on destroy
657ec59
to
8bc2add
Compare
@kirrg001 good for final test 🙂 |
"integration": "all", | ||
"api_key": "all" | ||
}, | ||
"Admin Integration": { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kevinansfield Feel free to self merge 👍
refs #9865
integrations
andapi_keys
tablesAdmin API Client
role and permissionsIntegration
modelApiKey
modeladmin
=Admin API Client
content
= no roleSplit out from #9869 to make review easier.