fix(service): Ignore current_user if it's not an instance of User #2134
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.
Description
All services inherit from
BaseService
. Many services override theinitialize
constructor method and callsuper
.The BaseService constructor only accepts one argument: the current user. When we call
super
without parenthesis, the argument are forwarded to the parent. Most of the time, we call the parent constructor without the parenthesis.It means that in many many case, the result returned by the service has a
result.user
which old something else, not a user.We heavily use the named parameters so most of the time, it's a hash with the argument of the descendant service.
One way to fix this is to go and modify all calls to
super
and replace them withsuper(nil)
. I think a better way is to ignore the current_user if it's not an instance ofUser
.Example