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

Add scoping by to find_by or create new element #15

Open
emaglio opened this issue Mar 29, 2019 · 2 comments
Open

Add scoping by to find_by or create new element #15

emaglio opened this issue Mar 29, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@emaglio
Copy link
Member

emaglio commented Mar 29, 2019

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?

@emaglio emaglio added the enhancement New feature or request label Mar 29, 2019
@seuros
Copy link
Member

seuros commented Dec 11, 2019

How are you thinking to figure out the relation ? You provided a symbol and a model.
i could have

class User < ...
has_many :youtube_broadcasts, class_name: 'Broadcast'
has_many :tags, class_name: 'UserTag'

@yogeshjain999
Copy link
Member

Good idea @emaglio

@seuros how about we accept the scope like this ?

step Model(Broadcast, :find_by, scope: { column: :user_id, value: :current_user })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants