diff options
| -rw-r--r-- | app/controllers/referentials_controller.rb | 10 | ||||
| -rw-r--r-- | app/decorators/referential_decorator.rb | 8 | ||||
| -rw-r--r-- | app/policies/referential_policy.rb | 6 | ||||
| -rw-r--r-- | app/views/referentials/select_compliance_control_set.html.slim | 20 | ||||
| -rw-r--r-- | config/locales/actions.en.yml | 1 | ||||
| -rw-r--r-- | config/locales/actions.fr.yml | 1 | ||||
| -rw-r--r-- | config/locales/referentials.en.yml | 3 | ||||
| -rw-r--r-- | config/locales/referentials.fr.yml | 3 | ||||
| -rw-r--r-- | config/routes.rb | 2 | ||||
| -rw-r--r-- | spec/controllers/referentials_controller_spec.rb | 8 | ||||
| -rw-r--r-- | spec/decorators/referential_decorator_spec.rb | 2 | ||||
| -rw-r--r-- | spec/helpers/table_builder_helper_spec.rb | 1 |
12 files changed, 63 insertions, 2 deletions
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index 6b479e938..b63741ef6 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -54,6 +54,16 @@ class ReferentialsController < InheritedResources::Base end end + def select_compliance_control_set + @compliance_control_sets = ComplianceControlSet.where(organisation: current_organisation) + end + + def validate + ComplianceControlSetCopyWorker.perform_async(params[:compliance_control_set], params[:id]) + flash[:notice] = I18n.t("referentials.operation_in_progress") + redirect_to(referential_path) + end + def destroy workbench = referential.workbench_id diff --git a/app/decorators/referential_decorator.rb b/app/decorators/referential_decorator.rb index dccf0052c..4103790aa 100644 --- a/app/decorators/referential_decorator.rb +++ b/app/decorators/referential_decorator.rb @@ -16,6 +16,14 @@ class ReferentialDecorator < Draper::Decorator href: h.new_referential_path(from: object.id, current_workbench_id: context[:current_workbench_id]) ) end + + if policy.validate? + links << Link.new( + content: h.t('actions.validate'), + href: h.referential_select_compliance_control_set_path(object.id) + ) + end + if policy.archive? links << Link.new( content: h.t('actions.archive'), diff --git a/app/policies/referential_policy.rb b/app/policies/referential_policy.rb index fdc80516c..bc8a3e24b 100644 --- a/app/policies/referential_policy.rb +++ b/app/policies/referential_policy.rb @@ -17,12 +17,14 @@ class ReferentialPolicy < ApplicationPolicy !archived? && organisation_match? && user.has_permission?('referentials.update') end - - def clone? !archived? && create? end + def validate? + !archived? && create? + end + def archive? record.archived_at.nil? && organisation_match? && user.has_permission?('referentials.update') end diff --git a/app/views/referentials/select_compliance_control_set.html.slim b/app/views/referentials/select_compliance_control_set.html.slim new file mode 100644 index 000000000..2d3f2344c --- /dev/null +++ b/app/views/referentials/select_compliance_control_set.html.slim @@ -0,0 +1,20 @@ +/ PageHeader +- header_params = ['jeux-de-controle', + t('referentials.select_compliance_control_set.title'), + ''] += pageheader(*header_params) do + +/ PageContent +.page_content + .container-fluid + .row + .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 + = form_tag validate_referential_path(params[:referential_id]), {class: 'form-horizontal', id: 'select_compliance_control_set', wrapper: :horizontal_form} do + .row + .col-lg-12 + .form-group + = label_tag 'name', nil, class: 'string required col-sm-4 col-xs-5 control-label' + .col-sm-8.col-xs-7 + = select_tag :compliance_control_set, options_from_collection_for_select(@compliance_control_sets, "id", "name"), class: 'select optional form-control' + .separator + = button_tag t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'select_compliance_control_set'
\ No newline at end of file diff --git a/config/locales/actions.en.yml b/config/locales/actions.en.yml index c34462d0d..2706ba69d 100644 --- a/config/locales/actions.en.yml +++ b/config/locales/actions.en.yml @@ -17,6 +17,7 @@ en: combine: 'Combine' actualize: 'Actualize' import: 'Import' + validate: 'Validate' filter: 'Filter' erase: 'Erase' create_api_key: "Create an API key" diff --git a/config/locales/actions.fr.yml b/config/locales/actions.fr.yml index df16d2aab..e796017c7 100644 --- a/config/locales/actions.fr.yml +++ b/config/locales/actions.fr.yml @@ -17,6 +17,7 @@ fr: combine: 'Combiner' actualize: 'Actualiser' import: 'Importer' + validate: 'Valider' filter: 'Filtrer' erase: 'Effacer' create_api_key: "Créer une clé d'API" diff --git a/config/locales/referentials.en.yml b/config/locales/referentials.en.yml index 7923ba5f2..8c58e53ee 100644 --- a/config/locales/referentials.en.yml +++ b/config/locales/referentials.en.yml @@ -5,6 +5,7 @@ en: name: 'Search by name' line: 'Seach by associated lines' search_no_results: 'No data space matching your query' + operation_in_progress: The validation process is in progress error_period_filter: "The period filter must have valid bounding dates" index: title: 'Data spaces' @@ -31,6 +32,8 @@ en: duplicated: title: 'Clone a data space' submit: "Create a data space" + select_jdc: + title: "Select a Compliance Control Set" actions: new: "Add a data space" destroy_confirm: "Do you confirm to destroy this data space ?" diff --git a/config/locales/referentials.fr.yml b/config/locales/referentials.fr.yml index 6aa81b33d..5b028233c 100644 --- a/config/locales/referentials.fr.yml +++ b/config/locales/referentials.fr.yml @@ -5,6 +5,7 @@ fr: name: 'Indiquez un nom de jeu de données...' line: 'Indiquez une ligne...' search_no_results: 'Aucun jeu de données ne correspond à votre recherche' + operation_in_progress: L'opération de validation est en cours error_period_filter: "Le filtre par période doit contenir une date de début et de fin valides" index: title: 'Jeux de données' @@ -31,6 +32,8 @@ fr: duplicated: title: 'Dupliquer un jeu de données' submit: "Valider" + select_compliance_control_set: + title: "Sélection du jeu de contôle" actions: new: "Créer un jeu de données" destroy_confirm: "Etes vous sûr de vouloir supprimer ce jeu de données ?" diff --git a/config/routes.rb b/config/routes.rb index 27c3c3044..2f332b2c9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -103,6 +103,8 @@ ChouetteIhm::Application.routes.draw do resources :autocomplete_stop_areas, only: [:show, :index] do get 'around', on: :member end + get :select_compliance_control_set + post :validate, on: :member resources :autocomplete_time_tables, only: [:index] resources :autocomplete_route_sections resources :autocomplete_timebands diff --git a/spec/controllers/referentials_controller_spec.rb b/spec/controllers/referentials_controller_spec.rb index a3be0dbd1..fba063085 100644 --- a/spec/controllers/referentials_controller_spec.rb +++ b/spec/controllers/referentials_controller_spec.rb @@ -22,4 +22,12 @@ describe ReferentialsController, :type => :controller do end end + describe 'GET select_compliance_control_set' do + it 'gets compliance control set for current organisation' do + compliance_control_set = create(:compliance_control_set, organisation: @user.organisation) + create(:compliance_control_set) + get :select_compliance_control_set, referential_id: referential.id + expect(assigns[:compliance_control_sets]).to eq([compliance_control_set]) + end + end end diff --git a/spec/decorators/referential_decorator_spec.rb b/spec/decorators/referential_decorator_spec.rb index 16da8d30b..3959a5924 100644 --- a/spec/decorators/referential_decorator_spec.rb +++ b/spec/decorators/referential_decorator_spec.rb @@ -34,6 +34,7 @@ RSpec.describe ReferentialDecorator, type: [:helper, :decorator] do expect_action_link_hrefs.to eq([ referential_time_tables_path(object), new_referential_path(from: object), + referential_select_compliance_control_set_path(object) ]) end end @@ -46,6 +47,7 @@ RSpec.describe ReferentialDecorator, type: [:helper, :decorator] do expect_action_link_hrefs.to eq([ referential_time_tables_path(object), new_referential_path(from: object), + referential_select_compliance_control_set_path(object), archive_referential_path(object), referential_path(object) ]) diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb index 4d9808044..a8854bf97 100644 --- a/spec/helpers/table_builder_helper_spec.rb +++ b/spec/helpers/table_builder_helper_spec.rb @@ -81,6 +81,7 @@ describe TableBuilderHelper, type: :helper do <li><a href="/referentials/#{referential.id}/edit">Editer</a></li> <li><a href="/referentials/#{referential.id}/time_tables">Calendriers</a></li> <li><a href="/referentials/new?from=#{referential.id}">Dupliquer</a></li> + <li><a href="/referentials/#{referential.id}/select_compliance_control_set">Valider</a></li> <li><a rel="nofollow" data-method="put" href="/referentials/#{referential.id}/archive">Conserver</a></li> <li class="delete-action"><a data-confirm="Etes vous sûr de vouloir supprimer ce jeu de données ?" rel="nofollow" data-method="delete" href="/referentials/#{referential.id}"><span class="fa fa-trash mr-xs"></span>Supprimer</a></li> </ul> |
