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

Empty session with _simple_filters #330

Closed
remibernard opened this issue Feb 5, 2016 · 0 comments
Closed

Empty session with _simple_filters #330

remibernard opened this issue Feb 5, 2016 · 0 comments
Assignees
Milestone

Comments

@remibernard
Copy link
Contributor

There is a huge caveat when using the _simple_filters scope query parameter. If the scope we wish to update with _simple_filters does not exist yet (with an empty session, for example) the filters will be placed in the default scope (default_scope_name). This is very rarely what is desired since this default is rarely used.

For example, a simple filtering URL like /userfiles?_simple_filters=1&data_provider_id=1 will create a userfiles#index scope instead of the expected userfiles one (if there is no userfiles scope yet) and the specified filters wont be applied, as the controller expects its scope to be userfiles, not userfiles#index.

view_scopes.rb:1235:

if (simple = params['_simple_filters'])
      # Determine which scope to update
      known      = (current_session['scopes'] ||= {})
      controller = params[:controller].to_s.downcase
      name   = simple     if known.has_key?(simple)
      name ||= controller if known.has_key?(controller)
      name ||= default_scope_name
# ...

Unfortunately, there is no way to know at that point in update_session_scopes where to place the given filters if the session does not contain either the parameter (simple) or the controller name (controller). This issue notably only concerns the first request made; on subsequent requests, the controller will have set up its scope and name ||= controller if known.has_key?(controller) will correctly assign the desired scope name.

Underlying cause of aces/cbrain-apis#5

@remibernard remibernard added this to the 4.3.0 milestone Feb 5, 2016
@remibernard remibernard self-assigned this Feb 5, 2016
remibernard added a commit to remibernard/cbrain that referenced this issue Mar 1, 2016
Trickier _simple_filters handling to cleanly (somewhat) allow new scopes
to be created when the session is empty. The new behavior is for a scope
to be created with _simple_filters's value when none can be found
(including other defaults), falling back to default_scope_name if
_simple_filters's value looks like '1' or 'true'.

While hard to precisely define, this behavior should hopefully be
simpler to use and fix the current issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant