aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZog2018-05-07 16:57:22 +0200
committerZog2018-05-07 16:57:22 +0200
commit430550b965035be3d78abad790e6c44fdc69087f (patch)
treeb5762d5055910c6ff14881c1f9101c0bfdc65ea5
parentfb4d1c66cb4c0cd83e183a13ca5f9ea44803631b (diff)
downloadchouette-core-430550b965035be3d78abad790e6c44fdc69087f.tar.bz2
Refs #6960; Add a view to set the controls associated to each workbench
-rw-r--r--app/controllers/workgroups_controller.rb13
-rw-r--r--app/models/workbench.rb10
-rw-r--r--app/models/workgroup.rb20
-rw-r--r--app/views/layouts/navigation/_main_nav_left_content_stif.html.slim3
-rw-r--r--app/views/workgroups/_form.html.slim15
-rw-r--r--app/views/workgroups/edit.html.slim8
-rw-r--r--config/breadcrumbs.rb4
-rw-r--r--config/locales/layouts.en.yml1
-rw-r--r--config/locales/layouts.fr.yml1
-rw-r--r--config/locales/workgroups.en.yml10
-rw-r--r--config/locales/workgroups.fr.yml11
-rw-r--r--db/schema.rb19
-rw-r--r--db/seeds/stif.seeds.rb1
-rw-r--r--spec/controllers/workgroups_controller_spec.rb40
14 files changed, 143 insertions, 13 deletions
diff --git a/app/controllers/workgroups_controller.rb b/app/controllers/workgroups_controller.rb
new file mode 100644
index 000000000..5d422380c
--- /dev/null
+++ b/app/controllers/workgroups_controller.rb
@@ -0,0 +1,13 @@
+class WorkgroupsController < ChouetteController
+ defaults resource_class: Workgroup
+
+ include PolicyChecker
+
+ def show
+ redirect_to "/"
+ end
+
+ def workgroup_params
+ params[:workgroup].permit(workbenches_attributes: [:id, owner_compliance_control_set_ids: @workgroup.available_compliance_control_sets.keys])
+ end
+end
diff --git a/app/models/workbench.rb b/app/models/workbench.rb
index d99197b47..64e9ae92d 100644
--- a/app/models/workbench.rb
+++ b/app/models/workbench.rb
@@ -51,8 +51,14 @@ class Workbench < ApplicationModel
where(name: DEFAULT_WORKBENCH_NAME).last
end
- def import_compliance_control_set
- import_compliance_control_set_id && ComplianceControlSet.find(import_compliance_control_set_id)
+ # XXX
+ # def import_compliance_control_set
+ # import_compliance_control_set_id && ComplianceControlSet.find(import_compliance_control_set_id)
+ # end
+
+ def compliance_control_set key
+ id = (owner_compliance_control_set_ids || {})[key.to_s]
+ id.present? && ComplianceControlSet.find(id)
end
private
diff --git a/app/models/workgroup.rb b/app/models/workgroup.rb
index a264247c7..b1cdde2c1 100644
--- a/app/models/workgroup.rb
+++ b/app/models/workgroup.rb
@@ -17,6 +17,8 @@ class Workgroup < ApplicationModel
has_many :custom_fields
+ accepts_nested_attributes_for :workbenches
+
def custom_fields_definitions
Hash[*custom_fields.map{|cf| [cf.code, cf]}.flatten]
end
@@ -25,7 +27,21 @@ class Workgroup < ApplicationModel
export_types.include? export_name
end
- def import_compliance_control_sets
- @import_compliance_control_sets ||= import_compliance_control_set_ids.map{|id| ComplianceControlSet.find(id)}
+ def available_compliance_control_sets
+ %i(
+ import
+ merge
+ automatic
+ workgroup
+ workbench
+ ).inject({}) do |h, k|
+ h[k] = "workgroups.available_compliance_control_sets.#{k}".t.capitalize
+ h
+ end
end
+
+ # XXX
+ # def import_compliance_control_sets
+ # @import_compliance_control_sets ||= import_compliance_control_set_ids.map{|id| ComplianceControlSet.find(id)}
+ # end
end
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 9404eeae6..382d80e0d 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
@@ -14,6 +14,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
diff --git a/app/views/workgroups/_form.html.slim b/app/views/workgroups/_form.html.slim
new file mode 100644
index 000000000..c32be6d22
--- /dev/null
+++ b/app/views/workgroups/_form.html.slim
@@ -0,0 +1,15 @@
+= simple_form_for @workgroup, html: { class: 'form-horizontal', id: 'workgroup_form' }, wrapper: :horizontal_form do |f|
+ table.table
+ thead
+ th
+ - @workgroup.available_compliance_control_sets.values.each do |cc|
+ th= cc
+ - @workgroup.workbenches.each_with_index do |w,i|
+ tr
+ th= w.organisation.name
+ - @workgroup.available_compliance_control_sets.keys.each do |cc|
+ td
+ = hidden_field_tag "workgroup[workbenches_attributes][#{i}][id]", w.id
+ = select_tag "workgroup[workbenches_attributes][#{i}][owner_compliance_control_set_ids][#{cc}]", options_from_collection_for_select(w.organisation.compliance_control_sets, :id, :name, w.compliance_control_set(cc).try(:id)), include_blank: true
+
+ = f.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'workgroup_form'
diff --git a/app/views/workgroups/edit.html.slim b/app/views/workgroups/edit.html.slim
new file mode 100644
index 000000000..49847acf2
--- /dev/null
+++ b/app/views/workgroups/edit.html.slim
@@ -0,0 +1,8 @@
+- breadcrumb @workgroup
+- page_header_content_for @workgroup
+
+.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
+ == render 'form'
diff --git a/config/breadcrumbs.rb b/config/breadcrumbs.rb
index 6285be71c..babaa2c8c 100644
--- a/config/breadcrumbs.rb
+++ b/config/breadcrumbs.rb
@@ -272,6 +272,10 @@ crumb :vehicle_journeys do |referential, route|
parent :route, referential, route
end
+crumb :workgroup do |w|
+ link I18n.t('layouts.navbar.workbench_outputs.edit_workgroup')
+end
+
# crumb :compliance_controls do|compliance_control_sets|
# link
# parent :compliance_control_sets, compliance_control_sets
diff --git a/config/locales/layouts.en.yml b/config/locales/layouts.en.yml
index 31bff403c..70e95646e 100644
--- a/config/locales/layouts.en.yml
+++ b/config/locales/layouts.en.yml
@@ -23,6 +23,7 @@ en:
workbench_output:
organisation: Organisation offers
workgroup: Workgroup offers
+ edit_workgroup: Application settings
tools: Tools
sync: Synchronization
sync_icar: iCAR synchronization
diff --git a/config/locales/layouts.fr.yml b/config/locales/layouts.fr.yml
index 019c72701..810ede34c 100644
--- a/config/locales/layouts.fr.yml
+++ b/config/locales/layouts.fr.yml
@@ -23,6 +23,7 @@ fr:
workbench_outputs:
organisation: Offre de mon organisation
workgroup: Offre du groupe de travail
+ edit_workgroup: Paramétrages de l'application
tools: Outils
sync: Synchronisation
sync_icar: Synchronisation iCAR
diff --git a/config/locales/workgroups.en.yml b/config/locales/workgroups.en.yml
new file mode 100644
index 000000000..deb5b58f9
--- /dev/null
+++ b/config/locales/workgroups.en.yml
@@ -0,0 +1,10 @@
+en:
+ workgroups:
+ edit:
+ title: "Paramétrages de l'application"
+ available_compliance_control_sets:
+ import_id:
+ merge_id:
+ automatic_id:
+ workgroup_id:
+ workbench_id:
diff --git a/config/locales/workgroups.fr.yml b/config/locales/workgroups.fr.yml
new file mode 100644
index 000000000..3fb932c18
--- /dev/null
+++ b/config/locales/workgroups.fr.yml
@@ -0,0 +1,11 @@
+fr:
+ workgroups:
+ edit:
+ title: "Paramétrages de l'application"
+
+ available_compliance_control_sets:
+ import_id: jeu de données après import
+ merge_id: jeu de données avant intégration
+ automatic_id: offre transporteur
+ workgroup_id: offre idf
+ workbench_id: automatique
diff --git a/db/schema.rb b/db/schema.rb
index 4a049d7ae..9951b7be0 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: 20180430122530) do
+ActiveRecord::Schema.define(version: 20180507130455) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -774,7 +774,7 @@ ActiveRecord::Schema.define(version: 20180430122530) do
t.string "objectid", null: false
t.integer "object_version", limit: 8
t.integer "route_id", limit: 8
- t.integer "stop_point_ids", array: true
+ t.integer "stop_point_ids", limit: 8, array: true
t.string "checksum"
t.text "checksum_source"
t.string "data_source_ref"
@@ -1077,6 +1077,7 @@ ActiveRecord::Schema.define(version: 20180430122530) do
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
@@ -1088,13 +1089,13 @@ ActiveRecord::Schema.define(version: 20180430122530) do
create_table "workgroups", id: :bigserial, force: :cascade do |t|
t.string "name"
- t.integer "line_referential_id", limit: 8
- t.integer "stop_area_referential_id", limit: 8
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.string "import_types", default: [], array: true
- t.string "export_types", default: [], array: true
- t.integer "import_compliance_control_set_ids", default: [], array: true
+ t.integer "line_referential_id", limit: 8
+ t.integer "stop_area_referential_id", limit: 8
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.string "import_types", default: [], array: true
+ t.string "export_types", default: [], array: true
+ t.integer "owner_id", limit: 8
end
add_foreign_key "access_links", "access_points", name: "aclk_acpt_fkey"
diff --git a/db/seeds/stif.seeds.rb b/db/seeds/stif.seeds.rb
index 98192385f..e2c5542f5 100644
--- a/db/seeds/stif.seeds.rb
+++ b/db/seeds/stif.seeds.rb
@@ -20,6 +20,7 @@ workgroup = Workgroup.seed_by(name: "Gestion de l'offre théorique IDFm") do |w|
w.line_referential = line_referential
w.stop_area_referential = stop_area_referential
w.export_types = ["Export::Netex"]
+ w.owner = stif
end
Workbench.update_all workgroup_id: workgroup
diff --git a/spec/controllers/workgroups_controller_spec.rb b/spec/controllers/workgroups_controller_spec.rb
new file mode 100644
index 000000000..2f8565088
--- /dev/null
+++ b/spec/controllers/workgroups_controller_spec.rb
@@ -0,0 +1,40 @@
+RSpec.describe WorkgroupsController, :type => :controller do
+ login_user
+
+ let(:workgroup) { create :workgroup }
+ let(:workbench) { create :workbench, workgroup: workgroup }
+ let(:compliance_control_set) { create :compliance_control_set, organisation: @user.organisation }
+
+ describe 'PATCH update' do
+ let(:params){
+ {
+ id: workgroup.id,
+ workgroup: {
+ workbenches_attributes: {
+ "0" => {
+ id: workbench.id,
+ owner_compliance_control_set_ids: {
+ import: compliance_control_set.id
+ }
+ }
+ }
+ }
+ }
+ }
+ let(:request){ patch :update, params }
+
+ it 'should respond with 403' do
+ expect(request).to have_http_status 403
+ end
+
+ context "when belonging to the owner" do
+ before do
+ workgroup.update owner: @user.organisation
+ end
+ it 'returns HTTP success' do
+ expect(request).to be_redirect
+ expect(workbench.reload.compliance_control_set(:import)).to eq compliance_control_set
+ end
+ end
+ end
+end