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

Permitted require option for edit, destroy, findOne #9948

Merged
merged 1 commit into from Oct 12, 2018
Merged

Permitted require option for edit, destroy, findOne #9948

merged 1 commit into from Oct 12, 2018

Conversation

allouis
Copy link
Contributor

@allouis allouis commented Oct 5, 2018

no-issue

With the new framework it is hard to handle 404 errors outside of the
serialization layer, this is because we cannot force deestroy or edit
to error if the model is missing. This lets us do that.

@allouis
Copy link
Contributor Author

allouis commented Oct 5, 2018

Yo @kirrg001 I assigned you to this because i'm not 100% this isn't gonna have bad repercussions for the v0.1 api?

@kirrg001
Copy link
Contributor

kirrg001 commented Oct 5, 2018

@allouis Could you share why it's hard? And what the use case is? :)

@allouis
Copy link
Contributor Author

allouis commented Oct 5, 2018

// in a controller object for new api
query(data, options) {
  return SomeModel.destroy(Object.assign({id: data.id}, options}))
}

If you DELETE with a non existent id and this runs, you will encounter an error here (Cannot read property destroy of undefined) : https://github.com/TryGhost/Ghost/blob/master/core/server/models/base/index.js#L828

So we look at how posts does it, posts sets the required property to true https://github.com/TryGhost/Ghost/blob/master/core/server/api/v0.1/posts.js#L247

So we change query to:

// in a controller object for new api
query(data, options) {
  return SomeModel.destroy(Object.assign({id: data.id, require: true}, options}))
}

But still doesn't work because it's not a permitted option. We could just add it in the ApiKey model - but it doesn't not seem correct behaviour, it seems to me that destroy should never give an error like cannot read property of undefined

@allouis
Copy link
Contributor Author

allouis commented Oct 5, 2018

Other options instead of this:

  • Add check to destroy method, if (object) { object.destroy()
  • Add permitted option just to ApiKey model
  • others...

@kirrg001
Copy link
Contributor

kirrg001 commented Oct 5, 2018

Can't we just force options.require=true in the model layer?
There are a couple of examples in the model layer already. (Search for require=true)

@allouis
Copy link
Contributor Author

allouis commented Oct 5, 2018

Yeah I can do that 👍

@allouis allouis closed this Oct 5, 2018
@allouis allouis deleted the allow-require-option branch October 5, 2018 09:42
@allouis allouis restored the allow-require-option branch October 12, 2018 05:53
@allouis allouis reopened this Oct 12, 2018
@allouis
Copy link
Contributor Author

allouis commented Oct 12, 2018

@kirrg001 reopened this as discussed on #9954 🎉

no-issue

With the new framework it is hard to handle 404 errors outside of the
serialization layer, this is because we cannot force destroy, edit or
findOne to error if the model is missing. This lets us do that.
@allouis allouis changed the title Permitted require option for basemodel edit, destroy Permitted require option for edit, destroy, findOne Oct 12, 2018
@allouis
Copy link
Contributor Author

allouis commented Oct 12, 2018

I've added support for findOne as well 👍

Copy link
Contributor

@kirrg001 kirrg001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks klitzeklein

@allouis
Copy link
Contributor Author

allouis commented Oct 12, 2018

🔸

@allouis allouis merged commit 48ebbf9 into TryGhost:master Oct 12, 2018
@allouis allouis deleted the allow-require-option branch October 12, 2018 11:00
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.

None yet

2 participants