aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
authorLuc Donnet2017-09-27 09:56:59 +0200
committerLuc Donnet2017-09-27 09:56:59 +0200
commit16fc6a184311c0ab5e1463398b91f8a716bcf4db (patch)
treeeea2b4b703c6e7960077a0ad1f1b61e079822950 /app/controllers
parent7ec5867ec7bd7365bb4c97d7d4c1bdc2cf580bc2 (diff)
parent28a42fb19174eafee38fe3c5f8fa58f89991f44a (diff)
downloadchouette-core-16fc6a184311c0ab5e1463398b91f8a716bcf4db.tar.bz2
Merge branch 'master' of github.com:AF83/stif-boiv
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/compliance_control_sets_controller.rb37
-rw-r--r--app/controllers/imports_controller.rb2
2 files changed, 37 insertions, 2 deletions
diff --git a/app/controllers/compliance_control_sets_controller.rb b/app/controllers/compliance_control_sets_controller.rb
index 6edfa3fcc..20ddcbe97 100644
--- a/app/controllers/compliance_control_sets_controller.rb
+++ b/app/controllers/compliance_control_sets_controller.rb
@@ -1,10 +1,12 @@
class ComplianceControlSetsController < BreadcrumbController
defaults resource_class: ComplianceControlSet
+ before_action :ransack_updated_at_params, only: [:index]
respond_to :html
def index
index! do |format|
- @q_for_form = @compliance_control_sets.ransack(params[:q])
+ scope = ransack_period @compliance_control_sets
+ @q_for_form = scope.ransack(params[:q])
format.html {
@compliance_control_sets = decorate_compliance_control_sets(@q_for_form.result)
}
@@ -24,8 +26,41 @@ class ComplianceControlSetsController < BreadcrumbController
)
end
+ protected
+
+ # def begin_of_association_chain
+ # current_organisation
+ # end
+
private
+ def ransack_updated_at_params
+ start_date = []
+ end_date = []
+
+ if params[:q] && params[:q][:updated_at] && !params[:q][:updated_at].has_value?(nil) && !params[:q][:updated_at].has_value?("")
+ [1, 2, 3].each do |key|
+ start_date << params[:q][:updated_at]["begin(#{key}i)"].to_i
+ end_date << params[:q][:updated_at]["end(#{key}i)"].to_i
+ end
+ params[:q].delete([:updated_at])
+ @begin_range = DateTime.new(*start_date,0,0,0) rescue nil
+ @end_range = DateTime.new(*end_date,23,59,59) rescue nil
+ end
+ end
+
+ # Fake ransack filter
+ def ransack_period scope
+ return scope unless !!@begin_range && !!@end_range
+
+ if @begin_range > @end_range
+ flash.now[:error] = t('imports.filters.error_period_filter')
+ else
+ scope = scope.where_updated_at_between(@begin_range, @end_range)
+ end
+ scope
+ end
+
def compliance_control_set_params
params.require(:compliance_control_set).permit(:name, :id)
end
diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb
index fa8919f20..f2e65e445 100644
--- a/app/controllers/imports_controller.rb
+++ b/app/controllers/imports_controller.rb
@@ -1,4 +1,5 @@
class ImportsController < BreadcrumbController
+ include PolicyChecker
skip_before_action :authenticate_user!, only: [:download]
defaults resource_class: Import, collection_name: 'imports', instance_name: 'import'
before_action :ransack_started_at_params, only: [:index]
@@ -89,7 +90,6 @@ class ImportsController < BreadcrumbController
def ransack_status_params
if params[:q]
- binding.pry
return params[:q].delete(:status_eq_any) if params[:q][:status_eq_any].empty? || ( (Import.status.values & params[:q][:status_eq_any]).length >= 4 )
params[:q][:status_eq_any].push("new", "running") if params[:q][:status_eq_any].include?("pending")
params[:q][:status_eq_any].push("aborted", "canceled") if params[:q][:status_eq_any].include?("failed")