Blacklight Plugin

Search history should save all params except blacklight, instead of only whitelist

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 2.5
  • Fix Version/s: 2.6
  • Component/s: None
  • Description:
    Hide
    The session[:search] value is used for eventually saving search history, and also for links to return to search results/next/prev on item detail page. It is set in CatalogController#delete_or_assign_search_session_params

    Right now session[:search] only includes request parameters that are on a whitelist. The current whitelist is:
    [:q, :qt, :search_field, :f, :per_page, :page, :sort]

    (Note it does include page, per_page, sort, etc).

    This makes it hard for extensions that add additional parameters, as they are not searched.

    Instead, it should save all request parameters except those on a blacklist. The blacklight, I think, should be simply:
    ["commit", "action", "controller"]

    Note this action also does not save keys with blank values, and saves all keys as symbols not strings.

    Changing to a whitelist with the above restrictions, it passes all existing specs/features. Will commit soon unless a reason not to appears.

    This way plugins can add additional parameters, and they'll just be saved for purposes of both search history and next/prev/back links etc.

    Making this change, all current tests still seem to pass.
    Show
    The session[:search] value is used for eventually saving search history, and also for links to return to search results/next/prev on item detail page. It is set in CatalogController#delete_or_assign_search_session_params Right now session[:search] only includes request parameters that are on a whitelist. The current whitelist is: [:q, :qt, :search_field, :f, :per_page, :page, :sort] (Note it does include page, per_page, sort, etc). This makes it hard for extensions that add additional parameters, as they are not searched. Instead, it should save all request parameters except those on a blacklist. The blacklight, I think, should be simply: ["commit", "action", "controller"] Note this action also does not save keys with blank values, and saves all keys as symbols not strings. Changing to a whitelist with the above restrictions, it passes all existing specs/features. Will commit soon unless a reason not to appears. This way plugins can add additional parameters, and they'll just be saved for purposes of both search history and next/prev/back links etc. Making this change, all current tests still seem to pass.

Activity

Hide
Jonathan Rochkind added a comment - 13/Jul/10 6:26 PM
Jessie suggested leaving controller/action off the blacklist , which is confusing for me to think about, but if it's convneient for him and it seems to work, will do. Also putting 'counter' on the blacklist, whcih would make the blacklist just "counter" and "commit". Okay.

On further testing, while this technique does seem to work for search history and back-to-search, it does NOT seem to work for next/prev and display of search constraints on item detail page.

Not sure why, need to investigate further. This whole sectio of code is kind of confusing, and some day I'd like to rewrite the whole thing, but not this day.
Show
Jonathan Rochkind added a comment - 13/Jul/10 6:26 PM Jessie suggested leaving controller/action off the blacklist , which is confusing for me to think about, but if it's convneient for him and it seems to work, will do. Also putting 'counter' on the blacklist, whcih would make the blacklist just "counter" and "commit". Okay. On further testing, while this technique does seem to work for search history and back-to-search, it does NOT seem to work for next/prev and display of search constraints on item detail page. Not sure why, need to investigate further. This whole sectio of code is kind of confusing, and some day I'd like to rewrite the whole thing, but not this day.
Hide
Jonathan Rochkind added a comment - 14/Jul/10 9:26 AM
Committed. Blacklist consists of only ["commit", "counter"] at present, left controller/action off for now per Jessie's input.
Show
Jonathan Rochkind added a comment - 14/Jul/10 9:26 AM Committed. Blacklist consists of only ["commit", "counter"] at present, left controller/action off for now per Jessie's input.
Hide
Jonathan Rochkind added a comment - 15/Jul/10 11:57 AM
Realized there was another part that had to be changed to completely implement the 'blacklist' concept.

CatalogController#save_current_search_params currently refused to save a search in history unless it had a :q or :f param:

return if search_session[:q].blank? && search_session[:f].blank?


But blacklist concept to accomodate plugins means we can't predict exactly what keys might be used to indicate a search. Using the blacklist concept, it now refuses to save a search if it _only_ includes keys on a 'blacklist' that mean 'home page, no search was done'. If it's got any keys not on the 'blacklist', it will be saved.

    return if (search_session.keys - [:controller, :action, :total, :counter, :commit ]) == []

All existing specs and features still pass with this change, including existing spec ""should have no search history if no search criteria"

Added new spec for "with index action with arbitrary key" "should save search history", to accomodate plugins and spec this change.

committed.
Show
Jonathan Rochkind added a comment - 15/Jul/10 11:57 AM Realized there was another part that had to be changed to completely implement the 'blacklist' concept. CatalogController#save_current_search_params currently refused to save a search in history unless it had a :q or :f param: return if search_session[:q].blank? && search_session[:f].blank? But blacklist concept to accomodate plugins means we can't predict exactly what keys might be used to indicate a search. Using the blacklist concept, it now refuses to save a search if it _only_ includes keys on a 'blacklist' that mean 'home page, no search was done'. If it's got any keys not on the 'blacklist', it will be saved.     return if (search_session.keys - [:controller, :action, :total, :counter, :commit ]) == [] All existing specs and features still pass with this change, including existing spec ""should have no search history if no search criteria" Added new spec for "with index action with arbitrary key" "should save search history", to accomodate plugins and spec this change. committed.

People

Dates

  • Created:
    13/Jul/10 6:01 PM
    Updated:
    15/Jul/10 11:57 AM
    Resolved:
    14/Jul/10 9:26 AM