diff options
| author | Zog | 2018-05-09 10:19:33 +0200 |
|---|---|---|
| committer | Zog | 2018-05-09 10:19:33 +0200 |
| commit | 64933b6903583b585f7de5bc391a9ab2ade1c6a7 (patch) | |
| tree | 844875f2cc8f62f9561e2b9b840dee2c6d2128d4 | |
| parent | 9434284e4f12b4b576762dabbd2b0a308e28bc61 (diff) | |
| download | chouette-core-64933b6903583b585f7de5bc391a9ab2ade1c6a7.tar.bz2 | |
Refs #6961; Update Workbench#edit
- Update the form
- Use policies and update the seeds accordingly
- Add a link in the navbar(s)
| -rw-r--r-- | app/controllers/workbenches_controller.rb | 2 | ||||
| -rw-r--r-- | app/policies/workbench_policy.rb | 2 | ||||
| -rw-r--r-- | app/views/layouts/navigation/_main_nav_left_content.html.slim | 8 | ||||
| -rw-r--r-- | app/views/layouts/navigation/_main_nav_left_content_stif.html.slim | 3 | ||||
| -rw-r--r-- | app/views/workbenches/_form.html.slim | 5 | ||||
| -rw-r--r-- | config/locales/workbenches.en.yml | 2 | ||||
| -rw-r--r-- | config/locales/workbenches.fr.yml | 1 | ||||
| -rw-r--r-- | db/migrate/20180509071833_remove_deprected_fields_from_workbenches.rb | 6 | ||||
| -rw-r--r-- | db/schema.rb | 6 | ||||
| -rw-r--r-- | lib/stif/permission_translator.rb | 2 | ||||
| -rw-r--r-- | spec/controllers/workbenches_controller_spec.rb | 31 | ||||
| -rw-r--r-- | spec/controllers/workgroups_controller_spec.rb | 5 |
12 files changed, 59 insertions, 14 deletions
diff --git a/app/controllers/workbenches_controller.rb b/app/controllers/workbenches_controller.rb index 43415ff60..cecd071d8 100644 --- a/app/controllers/workbenches_controller.rb +++ b/app/controllers/workbenches_controller.rb @@ -42,7 +42,7 @@ class WorkbenchesController < ChouetteController private def workbench_params - params.require(:workbench).permit(:import_compliance_control_set_id, :merge_compliance_control_set_id) + params.require(:workbench).permit(owner_compliance_control_set_ids: @workbench.workgroup.available_compliance_control_sets.keys) end def resource diff --git a/app/policies/workbench_policy.rb b/app/policies/workbench_policy.rb index 7b925e91a..9f2279c38 100644 --- a/app/policies/workbench_policy.rb +++ b/app/policies/workbench_policy.rb @@ -6,6 +6,6 @@ class WorkbenchPolicy < ApplicationPolicy end def update? - true + user.has_permission?('workbenches.update') end end diff --git a/app/views/layouts/navigation/_main_nav_left_content.html.slim b/app/views/layouts/navigation/_main_nav_left_content.html.slim index 0b55578a7..889f8f944 100644 --- a/app/views/layouts/navigation/_main_nav_left_content.html.slim +++ b/app/views/layouts/navigation/_main_nav_left_content.html.slim @@ -15,6 +15,9 @@ span = t('layouts.navbar.workbench_outputs.organisation') = link_to '#', class: 'list-group-item disabled' do span = t('layouts.navbar.workbench_outputs.workgroup') + - if policy(workbench.workgroup).edit? + = link_to [:edit, workbench.workgroup], class: 'list-group-item' do + span = t('layouts.navbar.workbench_outputs.edit_workgroup') .menu-item.panel .panel-heading @@ -36,7 +39,10 @@ span = t('activerecord.models.compliance_check_set.other').capitalize = link_to compliance_control_sets_path, class: 'list-group-item' do span = t('activerecord.models.compliance_control_set.other').capitalize - + - if policy(workbench).edit? + = link_to [:edit, workbench], class: 'list-group-item' do + span = t('workbenches.edit.link') + .menu-item.panel .panel-heading h4.panel-title diff --git a/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim b/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim index 382d80e0d..a7bb3f511 100644 --- a/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim +++ b/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim @@ -38,6 +38,9 @@ span = t('activerecord.models.compliance_check_set.other').capitalize = link_to compliance_control_sets_path, class: 'list-group-item' do span = t('activerecord.models.compliance_control_set.other').capitalize + - if policy(workbench).edit? + = link_to [:edit, workbench], class: 'list-group-item' do + span = t('workbenches.edit.link') .menu-item.panel .panel-heading diff --git a/app/views/workbenches/_form.html.slim b/app/views/workbenches/_form.html.slim index 534a5f378..a6b778e94 100644 --- a/app/views/workbenches/_form.html.slim +++ b/app/views/workbenches/_form.html.slim @@ -1,8 +1,9 @@ = simple_form_for @workbench, html: { class: 'form-horizontal', id: 'workbench_form' }, wrapper: :horizontal_form do |f| .row .col-lg-12 - = f.input :import_compliance_control_set_id, as: :select, collection: current_organisation.compliance_control_sets, value_method: :id - = f.input :merge_compliance_control_set_id, as: :select, collection: current_organisation.compliance_control_sets, value_method: :id + = f.fields_for :owner_compliance_control_set_ids do |ff| + - @workbench.workgroup.available_compliance_control_sets.each do |cc, label| + = ff.input cc, as: :select, collection: current_organisation.compliance_control_sets, value_method: :id, label: label, selected: @workbench.compliance_control_set(cc).try(:id).try(:to_s), include_blank: true .separator diff --git a/config/locales/workbenches.en.yml b/config/locales/workbenches.en.yml index 876f18766..99df24397 100644 --- a/config/locales/workbenches.en.yml +++ b/config/locales/workbenches.en.yml @@ -4,6 +4,7 @@ en: title: "Transport offer %{name}" edit: title: "Configure the workbench" + link: "Settings" update: title: "Configure the workbench" referential_count: @@ -33,4 +34,3 @@ en: workbench: import_compliance_control_set_id: Space data before import merge_compliance_control_set_id: Space data before merge - diff --git a/config/locales/workbenches.fr.yml b/config/locales/workbenches.fr.yml index 1d97ab623..e7e836169 100644 --- a/config/locales/workbenches.fr.yml +++ b/config/locales/workbenches.fr.yml @@ -4,6 +4,7 @@ fr: title: "Offre de transport %{name}" edit: title: "Configurer l'espace de travail" + link: "Paramétrages" update: title: "Configurer l'espace de travail" referential_count: diff --git a/db/migrate/20180509071833_remove_deprected_fields_from_workbenches.rb b/db/migrate/20180509071833_remove_deprected_fields_from_workbenches.rb new file mode 100644 index 000000000..0ef056914 --- /dev/null +++ b/db/migrate/20180509071833_remove_deprected_fields_from_workbenches.rb @@ -0,0 +1,6 @@ +class RemoveDeprectedFieldsFromWorkbenches < ActiveRecord::Migration + def change + remove_column :workbenches, :import_compliance_control_set_id, :bigint + remove_column :workbenches, :merge_compliance_control_set_id, :bigint + end +end diff --git a/db/schema.rb b/db/schema.rb index 9951b7be0..2bc979abb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180507130455) do +ActiveRecord::Schema.define(version: 20180509071833) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -1075,14 +1075,10 @@ ActiveRecord::Schema.define(version: 20180507130455) do t.integer "output_id", limit: 8 t.string "objectid_format" t.integer "workgroup_id", limit: 8 - t.integer "import_compliance_control_set_id", limit: 8 - t.integer "merge_compliance_control_set_id", limit: 8 t.hstore "owner_compliance_control_set_ids" end - add_index "workbenches", ["import_compliance_control_set_id"], name: "index_workbenches_on_import_compliance_control_set_id", using: :btree add_index "workbenches", ["line_referential_id"], name: "index_workbenches_on_line_referential_id", using: :btree - add_index "workbenches", ["merge_compliance_control_set_id"], name: "index_workbenches_on_merge_compliance_control_set_id", using: :btree add_index "workbenches", ["organisation_id"], name: "index_workbenches_on_organisation_id", using: :btree add_index "workbenches", ["stop_area_referential_id"], name: "index_workbenches_on_stop_area_referential_id", using: :btree add_index "workbenches", ["workgroup_id"], name: "index_workbenches_on_workgroup_id", using: :btree diff --git a/lib/stif/permission_translator.rb b/lib/stif/permission_translator.rb index 09a7c610c..aefe50fe1 100644 --- a/lib/stif/permission_translator.rb +++ b/lib/stif/permission_translator.rb @@ -48,7 +48,7 @@ module Stif def translation_table { "boiv:read-offer" => %w{sessions.create}, - "boiv:edit-offer" => all_destructive_permissions + %w{sessions.create}, + "boiv:edit-offer" => all_destructive_permissions + %w{sessions.create workbenches.update}, } end diff --git a/spec/controllers/workbenches_controller_spec.rb b/spec/controllers/workbenches_controller_spec.rb index bc0843a07..c6a37a8c0 100644 --- a/spec/controllers/workbenches_controller_spec.rb +++ b/spec/controllers/workbenches_controller_spec.rb @@ -1,7 +1,10 @@ require 'spec_helper' RSpec.describe WorkbenchesController, :type => :controller do - let(:workbench) { create :workbench } + login_user + + let(:workbench) { create :workbench, organisation: @user.organisation } + let(:compliance_control_set) { create :compliance_control_set, organisation: @user.organisation } describe "GET show" do it "returns http success" do @@ -10,4 +13,30 @@ RSpec.describe WorkbenchesController, :type => :controller do end end + describe 'PATCH update' do + let(:workbench_params){ + { + owner_compliance_control_set_ids: { + import: compliance_control_set.id, + merge: 2**64/2 - 1 + } + } + } + let(:request){ patch :update, id: workbench.id, workbench: workbench_params } + + it 'should respond with 403' do + expect(request).to have_http_status 403 + end + + with_permission "workbenches.update" do + it 'returns HTTP success' do + expect(request).to redirect_to [workbench] + p workbench.reload.owner_compliance_control_set_ids + expect(workbench.reload.compliance_control_set(:import)).to eq compliance_control_set + # Let's check we support Bigint + expect(workbench.reload.owner_compliance_control_set_ids["merge"]).to eq (2**64/2 - 1).to_s + end + end + end + end diff --git a/spec/controllers/workgroups_controller_spec.rb b/spec/controllers/workgroups_controller_spec.rb index 2f8565088..0841b6081 100644 --- a/spec/controllers/workgroups_controller_spec.rb +++ b/spec/controllers/workgroups_controller_spec.rb @@ -14,7 +14,8 @@ RSpec.describe WorkgroupsController, :type => :controller do "0" => { id: workbench.id, owner_compliance_control_set_ids: { - import: compliance_control_set.id + import: compliance_control_set.id, + merge: 2**64/2 - 1 } } } @@ -34,6 +35,8 @@ RSpec.describe WorkgroupsController, :type => :controller do it 'returns HTTP success' do expect(request).to be_redirect expect(workbench.reload.compliance_control_set(:import)).to eq compliance_control_set + # Let's check we support Bigint + expect(workbench.reload.owner_compliance_control_set_ids["merge"]).to eq (2**64/2 - 1).to_s end end end |
