aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Donnet2018-02-27 14:15:25 +0100
committerLuc Donnet2018-02-27 14:15:25 +0100
commit3d61b582389e0e1db73dc698d4c20f50153ea3fc (patch)
treed49fd53fadecc58ca74e64b7ff75ac42b3d087e0
parent69b901fa1223fb78142a1e4e76d1b88d879aec61 (diff)
downloadchouette-core-3d61b582389e0e1db73dc698d4c20f50153ea3fc.tar.bz2
Don't use all compliance_control_set from stif organisation. We will use later compliance_control_set selected by stif organisatoon Refs #5950 @25950_allow_user_to_see_ccset_from_other_organisation
-rw-r--r--app/controllers/compliance_control_sets_controller.rb25
-rw-r--r--app/policies/application_policy.rb6
-rw-r--r--app/policies/compliance_control_set_policy.rb2
3 files changed, 18 insertions, 15 deletions
diff --git a/app/controllers/compliance_control_sets_controller.rb b/app/controllers/compliance_control_sets_controller.rb
index 621eeb9a5..6461b38c8 100644
--- a/app/controllers/compliance_control_sets_controller.rb
+++ b/app/controllers/compliance_control_sets_controller.rb
@@ -27,15 +27,24 @@ class ComplianceControlSetsController < ChouetteController
redirect_to(compliance_control_sets_path)
end
+ protected
+
+ def begin_of_association_chain
+ current_organisation
+ end
+
private
def collection
- scope = ComplianceControlSet.joins(:organisation).where('organisation_id = ? OR organisations.code = ?', current_organisation.id, 'STIF')
- scope = self.ransack_period_range(scope: scope, error_message: t('imports.filters.error_period_filter'), query: :where_updated_at_between)
- @q_for_form = scope.ransack(params[:q])
- compliance_control_sets = @q_for_form.result
- compliance_control_sets = joins_with_associated_objects(compliance_control_sets).order(sort_column + ' ' + sort_direction) if sort_column && sort_direction
- @compliance_control_sets = compliance_control_sets.paginate(page: params[:page], per_page: 30)
+ @compliance_control_sets ||= begin
+ scope = end_of_association_chain.all
+ scope = self.ransack_period_range(scope: scope, error_message: t('imports.filters.error_period_filter'), query: :where_updated_at_between)
+ @q_for_form = scope.ransack(params[:q])
+ compliance_control_sets = @q_for_form.result
+ compliance_control_sets = joins_with_associated_objects(compliance_control_sets).order(sort_column + ' ' + sort_direction) if sort_column && sort_direction
+ compliance_control_sets = compliance_control_sets.paginate(page: params[:page], per_page: 30)
+ end
+
end
def decorate_compliance_control_sets(compliance_control_sets)
@@ -77,9 +86,9 @@ class ComplianceControlSetsController < ChouetteController
case params[:sort]
when 'owner_jdc'
collection.joins("LEFT JOIN organisations ON compliance_control_sets.organisation_id = organisations.id")
- when 'control_numbers'
+ when 'control_numbers'
collection.joins("LEFT JOIN compliance_controls ON compliance_controls.compliance_control_set_id = compliance_control_sets.id").group(:id)
- else
+ else
collection
end
end
diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb
index d14839bdf..33d88660c 100644
--- a/app/policies/application_policy.rb
+++ b/app/policies/application_policy.rb
@@ -95,12 +95,6 @@ class ApplicationPolicy
referential.try(:organisation_id) || record.try(:organisation_id)
end
-
- def belongs_to_stif?
- record.try(:organisation).try(:code) == "STIF"
- end
-
-
#
# Helpers
# -------
diff --git a/app/policies/compliance_control_set_policy.rb b/app/policies/compliance_control_set_policy.rb
index e3fb83e38..55507ffd9 100644
--- a/app/policies/compliance_control_set_policy.rb
+++ b/app/policies/compliance_control_set_policy.rb
@@ -6,7 +6,7 @@ class ComplianceControlSetPolicy < ApplicationPolicy
end
def show?
- organisation_match? or belongs_to_stif?
+ organisation_match?
end
def destroy?