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

fix(service): Ignore current_user if it's not an instance of User #2134

Merged
merged 1 commit into from
Jun 6, 2024

Conversation

julienbourdeau
Copy link
Contributor

Description

All services inherit from BaseService. Many services override the initialize constructor method and call super.

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 with super(nil). I think a better way is to ignore the current_user if it's not an instance of User.

Example

module AddOns
  class DestroyService < BaseService
    def initialize(add_on:)
      @add_on = add_on
      super
    end

    # ...

  end
end

CleanShot 2024-06-05 at 14 43 16@2x

@julienbourdeau julienbourdeau self-assigned this Jun 5, 2024
@julienbourdeau julienbourdeau merged commit abccdc1 into main Jun 6, 2024
6 checks passed
@julienbourdeau julienbourdeau deleted the fix/current-user-service branch June 6, 2024 09:40
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