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

Do not show all objects if collection is given nil #595

Closed
dnagir opened this issue Jun 21, 2012 · 5 comments · Fixed by #598
Closed

Do not show all objects if collection is given nil #595

dnagir opened this issue Jun 21, 2012 · 5 comments · Fixed by #598

Comments

@dnagir
Copy link

dnagir commented Jun 21, 2012

The problem

Let's asume the following piece of code:

= simple_form_for [@project, @story] do |f|
  = f.association :documents, :as => :check_boxes, collection: @documents

This will show the list of documents that come from the @documents variable.
BUT when the variable is not assigned (probably by mistake, not being speced) and thus is treated as nil, then all the documents are loaded.

This is a "security" flow because all users from all projects will see all documents on the system.

Proposed solution

If nil (or something non-eumerable I guess) is passed as collection option, then raise an exception warning about it.

For backwards compatibility it may be an configuration option that can enable this behaviour.

@nashby
Copy link
Collaborator

nashby commented Jun 21, 2012

👍 for something like that.

@carlosantoniodasilva
Copy link
Member

Sounds ok to raise an exception when collection key is present but nil. I think there's no need for a config option though, if anyone is doing that by mistake we'll probably be nicer by telling them as you said :)

As a side note, we'd expect something like that to be caught by the developer before sending something to production, hopefully :D.

@nashby
Copy link
Collaborator

nashby commented Jun 21, 2012

What about just render a blank select without exception?

@rafaelfranca
Copy link
Collaborator

@nashby for me sounds good.

@carlosantoniodasilva
Copy link
Member

Yeah, I think it's fine 🤘.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

4 participants