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

KG - Admin Protocol Filters to Radios (1.7.5) #478

Merged
merged 1 commit into from
Jun 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/dashboard/protocols_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def index
# if we are an admin we want to default to admin organizations
if @admin
@organizations = Dashboard::IdentityOrganizations.new(@user.id).admin_organizations_with_protocols
default_filter_params[:filtered_for_admin] = @user.id.to_s
default_filter_params[:admin_filter] = "for_admin #{current_user.id}"
else
@organizations = Dashboard::IdentityOrganizations.new(@user.id).general_user_organizations_with_protocols
default_filter_params[:for_identity_id] = @user.id.to_s
default_filter_params[:admin_filter] = "for_identity #{current_user.id}"
end

@filterrific =
Expand Down
13 changes: 11 additions & 2 deletions app/models/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ class Protocol < ActiveRecord::Base
default_filter_params: { show_archived: 0 },
available_filters: [
:search_query,
:for_identity_id,
:filtered_for_admin,
:admin_filter,
:show_archived,
:with_status,
:with_organization
Expand Down Expand Up @@ -164,6 +163,16 @@ class Protocol < ActiveRecord::Base
where.not(project_roles: { project_rights: 'none' })
}

scope :admin_filter, -> (params) {
filter, id = params.split(" ")

if filter == 'for_admin'
return filtered_for_admin(id)
elsif filter == 'for_identity'
return for_identity_id(id)
end
}

scope :for_admin, -> (identity_id) {
# returns protocols with ssrs in orgs authorized for identity_id
return nil if identity_id == '0'
Expand Down
6 changes: 2 additions & 4 deletions app/models/protocol_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ class ProtocolFilter < ActiveRecord::Base

attr_accessible :search_name
attr_accessible :show_archived
attr_accessible :filtered_for_admin
attr_accessible :for_identity_id
attr_accessible :admin_filter
attr_accessible :search_query
attr_accessible :with_organization
attr_accessible :with_status
Expand All @@ -46,8 +45,7 @@ def href
dashboard_root_path(
filterrific: {
show_archived: (self.show_archived ? 1 : 0),
filtered_for_admin: self.filtered_for_admin,
for_identity_id: self.for_identity_id,
admin_filter: self.admin_filter,
search_query: self.search_query,
with_organization: self.with_organization,
with_status: self.with_status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@
= form.select :with_organization, filterrific.select_options[:with_organization], {}, class: "form-control selectpicker core-select", multiple: true, data: { none_selected_text: t(:constants)[:prompts][:any] }
- if admin
%hr
.form-group.row
= form.label :for_identity_id, t(:dashboard)[:protocol_filters][:my_protocols], class: 'col-lg-10 control-label'
.form-group.row.identity-protocols
= form.label :admin_filter, t(:dashboard)[:protocol_filters][:my_protocols], class: 'col-lg-10 control-label'
.col-lg-2
= form.check_box :for_identity_id, {}, current_user.id, "0"
= form.radio_button :admin_filter, "for_identity #{current_user.id}"

.form-group.row
= form.label :filtered_for_admin, t(:dashboard)[:protocol_filters][:my_admin_orgs], class: 'col-lg-10 control-label'
.form-group.row.admin-protocols
= form.label :admin_filter, t(:dashboard)[:protocol_filters][:my_admin_protocols], class: 'col-lg-10 control-label'
.col-lg-2
= form.check_box :filtered_for_admin, {}, current_user.id, "0"
= form.radio_button :admin_filter, "for_admin #{current_user.id}"

.panel-footer
.pull-right
Expand Down
3 changes: 1 addition & 2 deletions app/views/dashboard/protocol_filters/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
.col-md-12
= form.hidden_field :identity_id
= form.hidden_field :show_archived
= form.hidden_field :filtered_for_admin
= form.hidden_field :for_identity_id
= form.hidden_field :admin_filter
= form.hidden_field :search_query
- protocol_filter.with_organization.each do |core_id|
= form.hidden_field :with_organization, multiple: true, value: core_id
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ en:
archived: "Archived"
status: "Status"
my_protocols: "My Protocols"
my_admin_orgs: "My Admin Organizations"
my_admin_protocols: "My Admin Protocols"
organization: "Organization"
filter: "Filter"
saved_filters:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ConsolidateAdminProtocolFilters < ActiveRecord::Migration
def change
add_column :protocol_filters, :admin_filter, :string
remove_column :protocol_filters, :for_identity_id
remove_column :protocol_filters, :filtered_for_admin
end
end
20 changes: 12 additions & 8 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160527143837) do
ActiveRecord::Schema.define(version: 20160608151717) do

create_table "admin_rates", force: :cascade do |t|
t.integer "line_item_id", limit: 4
Expand Down Expand Up @@ -381,6 +381,7 @@

add_index "identities", ["approved"], name: "index_identities_on_approved", using: :btree
add_index "identities", ["email"], name: "index_identities_on_email", using: :btree
add_index "identities", ["first_name", "last_name"], name: "full_name", type: :fulltext
add_index "identities", ["last_name"], name: "index_identities_on_last_name", using: :btree
add_index "identities", ["ldap_uid"], name: "index_identities_on_ldap_uid", unique: true, using: :btree
add_index "identities", ["reset_password_token"], name: "index_identities_on_reset_password_token", unique: true, using: :btree
Expand Down Expand Up @@ -631,16 +632,15 @@
add_index "project_roles", ["protocol_id"], name: "index_project_roles_on_protocol_id", using: :btree

create_table "protocol_filters", force: :cascade do |t|
t.integer "identity_id", limit: 4
t.string "search_name", limit: 255
t.integer "identity_id", limit: 4
t.string "search_name", limit: 255
t.boolean "show_archived"
t.integer "for_identity_id", limit: 4
t.string "search_query", limit: 255
t.string "with_organization", limit: 255
t.string "with_status", limit: 255
t.string "search_query", limit: 255
t.string "with_organization", limit: 255
t.string "with_status", limit: 255
t.datetime "created_at"
t.datetime "updated_at"
t.integer "filtered_for_admin", limit: 4
t.string "admin_filter", limit: 255
end

create_table "protocols", force: :cascade do |t|
Expand Down Expand Up @@ -1114,6 +1114,10 @@
add_index "tokens", ["identity_id"], name: "index_tokens_on_identity_id", using: :btree
add_index "tokens", ["service_request_id"], name: "index_tokens_on_service_request_id", using: :btree

create_table "user_notifications", force: :cascade do |t|
t.integer "identity_id", limit: 4
end

create_table "validation_conditions", force: :cascade do |t|
t.integer "validation_id", limit: 4
t.string "rule_key", limit: 255
Expand Down
27 changes: 3 additions & 24 deletions spec/features/dashboard/protocols/index/filters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,31 +254,10 @@ def visit_protocols_index_page
end
end

describe "my protocols" do
context "user is a service provider and a superuser for an Organization" do
let!(:organization) { create(:organization, admin: user) }

context "user unchecks My Admin Orgs and clicks the filter button" do
it "should display all Protocols, including those to which the user does not have a ProjectRole" do
protocol = create_protocol(archived: false, short_title: "Protocol1")
create(:project_role, identity: user, role: "very-important", project_rights: "to-party", protocol: protocol)
create_protocol(archived: false, short_title: "Protocol2")

visit_protocols_index_page

@page.filter_protocols.my_admin_organizations_checkbox.click # unchecking My Admin Orgs
@page.filter_protocols.apply_filter_button.click

expect(@page.search_results).to have_protocols(count: 2)
end
end
end
end

describe "my admin organizations" do
describe "My Admin Protocols" do
let(:organization) { create(:organization, admin: user, name: "MegaCorp") }

context "user checks My Admin Organizations and clicks the filter button" do
context "user checks My Admin Protocols and clicks the filter button" do
it "should only display Protocols contain SSRs belonging to users authorized Organizations" do
# protocol belonging to user's admin organization
protocol1 = create_protocol(archived: false, short_title: "Protocol1", organization: organization)
Expand All @@ -303,7 +282,7 @@ def visit_protocols_index_page
let(:trump_organization) { create(:organization, admin: user, name: "TrumpPenitentiaries", type: 'Institution') }
let(:some_organization) { create(:organization, admin: user, name: "SomeLLC", type: 'Institution') }

context "user selects multiple admin Organizations by name and clicks the Filter button" do
context "user selects multiple admin protocols by name and clicks the Filter button" do
it "should restrict listing to Protocols with SSRs belonging to those Organizations" do
mega_corp_protocol = create_protocol(archived: false, short_title: "MegaCorpProtocol", organization: mega_corp_organization)
mega_corp_protocol.project_roles.create(identity_id: user.id, role: "very-important", project_rights: "to-party")
Expand Down
4 changes: 2 additions & 2 deletions spec/support/pages/dashboard/protocols/index_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class IndexPage < SitePrism::Page
elements :core_options, "div.core-select li"

# these appear if user is an admin
element :my_protocols_checkbox, "#filterrific_for_identity_id"
element :my_admin_organizations_checkbox, "#filterrific_filtered_for_admin"
element :my_protocols_checkbox, ".identity-protocols input"
element :my_admin_organizations_checkbox, ".admin-protocols input"

element :apply_filter_button, :button, "Filter"

Expand Down
17 changes: 8 additions & 9 deletions spec/views/dashboard/protocols/index.html.haml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
with_status: [],
search_query: '',
show_archived: 0,
for_identity_id: jug2.id,
filtered_for_admin: false,
admin_filter: "for_identity #{jug2.id}",
with_organization: false
))
end
Expand Down Expand Up @@ -59,12 +58,12 @@
render
end

it 'should not show "My Protocols" checkbox' do
it 'should not show "My Protocols" radio' do
expect(response).not_to have_content('My Protocols')
end

it 'should not show "My Admin Organizations" select' do
expect(response).not_to have_content('My Admin Organizations')
it 'should not show "My Admin Protocols" radio' do
expect(response).not_to have_content('My Admin Protocols')
end

it 'should show "Organization" select' do
Expand All @@ -80,12 +79,12 @@
render
end

it 'should show "My Protocols" checkbox' do
expect(response).to have_field('My Protocols')
it 'should show "My Protocols" radio' do
expect(response).to have_selector('label', text: 'My Protocols')
end

it 'should show "My Admin Organizations" checkbox' do
expect(response).to have_field('My Admin Organizations')
it 'should show "My Admin Protocols" radio' do
expect(response).to have_selector('label', text: 'My Admin Protocols')
end
end
end
Expand Down