Skip to content

Add scoping by to find_by or create new element  #15

@emaglio

Description

@emaglio

It might be worth to see if possible or just makes sense to add a scope_by key in the Model arguments.
This comes from experience where people prefer to do this:

step :set_model

def set_model(ctx, params:, current_user:, **)
  ctx[:model] = current_user.broadacsts.find_by(id: params[:id)
end

Over

step Model(Broadcast, :find_by)

Simply for "security" reason.
So this is what we could have:

step Model(Broadcast, :find_by, scope_by: :current_user)

where current_user is passed in ctx -> ctx[:current_user]

We add a step to extract the scope with failure end similar on what is done in Contract::Validate.

Should we think to add this or not really?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions