diff --git a/app/avo/resources/image_color.rb b/app/avo/resources/image_color.rb index af72e277a47317d3c29e552cd227af49e5af46fc..e9447d3a0727018f5b1a36e278c847dac54a6c6a 100644 --- a/app/avo/resources/image_color.rb +++ b/app/avo/resources/image_color.rb @@ -6,7 +6,7 @@ class Avo::Resources::ImageColor < Avo::BaseResource # } def fields - field :sample, as: :belongs_to + field :sample, as: :belongs_to, searchable: true field :hue, as: :number field :saturation, as: :number field :brightness, as: :number diff --git a/app/avo/resources/sample.rb b/app/avo/resources/sample.rb index c2be8364efb00a6f6f9577e161f54574de076819..e386baf6c2da71fcc0734863cb66f8fbcbdaff99 100644 --- a/app/avo/resources/sample.rb +++ b/app/avo/resources/sample.rb @@ -4,9 +4,9 @@ class Avo::Resources::Sample < Avo::BaseResource # self.includes = [] # self.attachments = [] - # self.search = { - # query: -> { query.ransack(id_eq: params[:q], m: "or").result(distinct: false) } - # } + self.search = { + query: -> { query.ransack(sample_no_cont: params[:q], m: "or").result(distinct: false) } + } def fields field :sample_no, as: :text, sortable: true diff --git a/app/models/sample.rb b/app/models/sample.rb index 0131a0f45f2b79fc4c7217120c96ac6aad571882..56b89a195dce32f92840bc215ef9f00d3b2184cb 100644 --- a/app/models/sample.rb +++ b/app/models/sample.rb @@ -18,6 +18,10 @@ class Sample < ApplicationRecord validates :sample_no, presence: true + def self.ransackable_attributes(auth_object = nil) + %w[sample_no] + end + serialize :analysis_method_ids, coder: MultiValueWrapper serialize :voids_form_ids, coder: MultiValueWrapper serialize :sorting_ids, coder: MultiValueWrapper diff --git a/app/policies/sample_policy.rb b/app/policies/sample_policy.rb index 1b78a671affb5e36f8ce205e7993b6f94aa82bf8..1688e9f40a6944b5f481a9efa8faa63258379f58 100644 --- a/app/policies/sample_policy.rb +++ b/app/policies/sample_policy.rb @@ -5,6 +5,10 @@ class SamplePolicy < ApplicationPolicy user? && user.apprentice? end + def search? + user? && user.apprentice? + end + class Scope < ApplicationPolicy::Scope def resolve scope.all diff --git a/spec/policies/sample_policy_spec.rb b/spec/policies/sample_policy_spec.rb index a473b455482e3f82d6f861913e4ef4f5ff45803f..3bf43d5ed2c4b0fc92dafaf84de371b2a7431cbb 100644 --- a/spec/policies/sample_policy_spec.rb +++ b/spec/policies/sample_policy_spec.rb @@ -12,6 +12,7 @@ RSpec.describe SamplePolicy do it { is_expected.to forbid_new_and_create_actions } it { is_expected.to forbid_edit_and_update_actions } it { is_expected.to forbid_action(:destroy) } + it { is_expected.to forbid_action(:search) } end context "for an apprentice" do @@ -22,6 +23,7 @@ RSpec.describe SamplePolicy do it { is_expected.to permit_new_and_create_actions } it { is_expected.to permit_edit_and_update_actions } it { is_expected.to permit_action(:destroy) } + it { is_expected.to permit_action(:search) } end context "for an editor" do @@ -32,6 +34,7 @@ RSpec.describe SamplePolicy do it { is_expected.to permit_new_and_create_actions } it { is_expected.to permit_edit_and_update_actions } it { is_expected.to permit_action(:destroy) } + it { is_expected.to permit_action(:search) } end context "for an admin" do @@ -42,6 +45,7 @@ RSpec.describe SamplePolicy do it { is_expected.to permit_new_and_create_actions } it { is_expected.to permit_edit_and_update_actions } it { is_expected.to permit_action(:destroy) } + it { is_expected.to permit_action(:search) } end describe "Scope" do