Skip to content

Commit

Permalink
Fix strong params usage in Dashboard::ProtocolsController. Use a fork…
Browse files Browse the repository at this point in the history
… of filterrific gem until bug is fixed.

See jhund/filterrific#116
  • Loading branch information
Jay Hardee authored and William Holt committed Mar 17, 2017
1 parent d86c46c commit 4568642
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ gem 'devise', '~> 4.2'
gem 'dynamic_form'
gem 'execjs'
gem 'exception_notification'
gem 'filterrific'
gem 'filterrific', git: 'https://github.com/ayaman/filterrific.git'
gem 'gon', '~> 6.1'
gem 'grape', '0.7.0'
gem 'grape-entity', '~> 0.4.4'
Expand Down
9 changes: 7 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ GIT
acts_as_list (0.9.2)
activerecord (>= 3.0)

GIT
remote: https://github.com/ayaman/filterrific.git
revision: 292ecd953df4ec70f2f9a879105ef5aba5b77e95
specs:
filterrific (2.1.2)

GIT
remote: https://github.com/jleonardw9/grouped_validations.git
revision: dc4207a7966fe691a240a47718b3d9689861a76f
Expand Down Expand Up @@ -206,7 +212,6 @@ GEM
railties (>= 3.0.0)
faker (1.7.3)
i18n (~> 0.5)
filterrific (2.1.2)
formtastic (2.2.1)
actionpack (>= 3.0)
globalid (0.3.7)
Expand Down Expand Up @@ -562,7 +567,7 @@ DEPENDENCIES
execjs
factory_girl_rails
faker
filterrific
filterrific!
gon (~> 6.1)
grape (= 0.7.0)
grape-entity (~> 0.4.4)
Expand Down
25 changes: 21 additions & 4 deletions app/controllers/dashboard/protocols_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ def index
else
@organizations = Dashboard::IdentityOrganizations.new(@user.id).general_user_organizations_with_protocols
@default_filter_params[:admin_filter] = "for_identity #{@user.id}"
params[:filterrific][:admin_filter] = "for_identity #{@user.id}" if params[:filterrific]
end

@filterrific =
initialize_filterrific(Protocol, params[:filterrific],
initialize_filterrific(Protocol, params[:filterrific] && filterrific_params,
default_filter_params: @default_filter_params,
select_options: {
with_status: AVAILABLE_STATUSES.invert,
Expand Down Expand Up @@ -213,6 +212,24 @@ def view_details

private

def filterrific_params
temp = params.require(:filterrific).permit(:identity_id,
:search_name,
:show_archived,
:admin_filter,
:search_query,
:sorted_by,
with_organization: [],
with_status: [],
with_owner: [])

unless @admin
temp[:admin_filter] = "for_identity #{@user.id}"
end

temp
end

def protocol_params
@protocol_params ||= begin
params.require(:protocol).permit(:archived,
Expand Down Expand Up @@ -284,9 +301,9 @@ def find_protocol

def setup_sorting_variables
# Set filterrific params for sorting logic, store sorted by to re-apply styling
@filterrific_params = params[:filterrific] ? params[:filterrific].except(:sorted_by) : @default_filter_params
@filterrific_params = params[:filterrific] ? filterrific_params.except(:sorted_by) : @default_filter_params
@page = params[:page]
@sorted_by = params[:filterrific][:sorted_by] if params[:filterrific]
@sorted_by = filterrific_params[:sorted_by] if params[:filterrific]
@sort_name = @sorted_by.split(' ')[0] if @sorted_by
@sort_order = @sorted_by.split(' ')[1] if @sorted_by
@new_sort_order = (@sort_order == 'asc' ? 'desc' : 'asc') if @sort_order
Expand Down

0 comments on commit 4568642

Please sign in to comment.