aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorZog2018-05-07 16:57:22 +0200
committerZog2018-05-07 16:57:22 +0200
commit430550b965035be3d78abad790e6c44fdc69087f (patch)
treeb5762d5055910c6ff14881c1f9101c0bfdc65ea5 /app
parentfb4d1c66cb4c0cd83e183a13ca5f9ea44803631b (diff)
downloadchouette-core-430550b965035be3d78abad790e6c44fdc69087f.tar.bz2
Refs #6960; Add a view to set the controls associated to each workbench
Diffstat (limited to 'app')
-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
6 files changed, 65 insertions, 4 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'