aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorcedricnjanga2017-10-24 19:10:11 +0200
committercedricnjanga2017-10-24 19:10:11 +0200
commita8ae0d3bf9105b17bfdb6dc22f527140f8edb6dd (patch)
tree50bb2f3af42be39b85c17d070971b218c2b495a5 /app
parent545671efd71380722dbc3272f5f513ea684891bd (diff)
parent2568e7f7553c82adb0bed1521ef9f013df9df87e (diff)
downloadchouette-core-a8ae0d3bf9105b17bfdb6dc22f527140f8edb6dd.tar.bz2
Merge branch 'master' into staging
Diffstat (limited to 'app')
-rw-r--r--app/assets/stylesheets/components/_tables.sass10
-rw-r--r--app/controllers/api/v1/imports_controller.rb6
-rw-r--r--app/controllers/compliance_control_sets_controller.rb8
-rw-r--r--app/controllers/compliance_controls_controller.rb2
-rw-r--r--app/controllers/time_tables_controller.rb1
-rw-r--r--app/decorators/compliance_control_set_decorator.rb7
-rw-r--r--app/models/compliance_control.rb1
-rw-r--r--app/models/generic_attribute_control/min_max.rb1
-rw-r--r--app/models/generic_attribute_control/pattern.rb1
-rw-r--r--app/models/generic_attribute_control/uniqueness.rb1
-rw-r--r--app/models/import.rb1
-rw-r--r--app/models/route_control/minimum_length.rb1
-rw-r--r--app/models/route_control/opposite_route.rb1
-rw-r--r--app/models/vehicle_journey_control/time_table.rb1
-rw-r--r--app/models/vehicle_journey_control/vehicle_journey_at_stops.rb1
-rw-r--r--app/services/zip_service.rb18
-rw-r--r--app/views/compliance_control_blocks/edit.html.slim2
-rw-r--r--app/views/compliance_control_blocks/new.html.slim2
-rw-r--r--app/views/compliance_control_sets/edit.html.slim2
-rw-r--r--app/views/compliance_control_sets/index.html.slim2
-rw-r--r--app/views/compliance_control_sets/new.html.slim2
-rw-r--r--app/views/compliance_control_sets/show.html.slim12
-rw-r--r--app/views/compliance_controls/edit.html.slim2
-rw-r--r--app/views/compliance_controls/new.html.slim2
-rw-r--r--app/views/compliance_controls/select_type.html.slim2
-rw-r--r--app/views/compliance_controls/show.html.slim6
-rw-r--r--app/views/imports/_form.html.slim2
-rw-r--r--app/views/time_tables/_filter.html.slim2
-rw-r--r--app/workers/compliance_control_set_cloning_worker.rb8
-rw-r--r--app/workers/workbench_import_worker.rb31
30 files changed, 104 insertions, 34 deletions
diff --git a/app/assets/stylesheets/components/_tables.sass b/app/assets/stylesheets/components/_tables.sass
index 8fe7be374..178ec2f36 100644
--- a/app/assets/stylesheets/components/_tables.sass
+++ b/app/assets/stylesheets/components/_tables.sass
@@ -247,6 +247,16 @@
width: 35px
height: 35px
margin: 5px
+ &.with_text
+ width: initial
+ > a, > button
+ border-radius: 4%
+ text-decoration: none
+ span
+ &.fa
+ padding-left: 10px
+ span
+ padding: 0 10px 0 0
> a, > button
display: block
diff --git a/app/controllers/api/v1/imports_controller.rb b/app/controllers/api/v1/imports_controller.rb
index 6050418d8..3d7f4ca79 100644
--- a/app/controllers/api/v1/imports_controller.rb
+++ b/app/controllers/api/v1/imports_controller.rb
@@ -5,7 +5,11 @@ class Api::V1::ImportsController < Api::V1::IbooController
def create
args = workbench_import_params.merge(creator: 'Webservice')
@import = parent.workbench_imports.create(args)
- create!
+ if @import.valid?
+ create!
+ else
+ render json: { status: "error", messages: @import.errors.full_messages }
+ end
end
private
diff --git a/app/controllers/compliance_control_sets_controller.rb b/app/controllers/compliance_control_sets_controller.rb
index 9de90c21c..e5c2e19dd 100644
--- a/app/controllers/compliance_control_sets_controller.rb
+++ b/app/controllers/compliance_control_sets_controller.rb
@@ -23,6 +23,12 @@ class ComplianceControlSetsController < BreadcrumbController
end
end
+ def clone
+ ComplianceControlSetCloner.new.copy(params[:id], current_organisation.id)
+ flash[:notice] = I18n.t("compliance_control_sets.errors.operation_in_progress")
+ redirect_to(compliance_control_sets_path)
+ end
+
protected
def begin_of_association_chain
@@ -48,4 +54,4 @@ class ComplianceControlSetsController < BreadcrumbController
def compliance_control_set_params
params.require(:compliance_control_set).permit(:name, :id)
end
-end
+end \ No newline at end of file
diff --git a/app/controllers/compliance_controls_controller.rb b/app/controllers/compliance_controls_controller.rb
index e51d1eb74..0a9c7d52b 100644
--- a/app/controllers/compliance_controls_controller.rb
+++ b/app/controllers/compliance_controls_controller.rb
@@ -1,6 +1,7 @@
class ComplianceControlsController < BreadcrumbController
defaults resource_class: ComplianceControl
belongs_to :compliance_control_set
+ actions :all, :except => [:show, :index]
def select_type
@sti_subclasses = ComplianceControl.subclasses
@@ -15,7 +16,6 @@ class ComplianceControlsController < BreadcrumbController
end
def create
- puts build_resource.inspect
create! do |success, failure|
success.html { redirect_to compliance_control_set_path(parent) }
failure.html { render( :action => 'new' ) }
diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb
index 2d24d5aa6..af74f635f 100644
--- a/app/controllers/time_tables_controller.rb
+++ b/app/controllers/time_tables_controller.rb
@@ -130,7 +130,6 @@ class TimeTablesController < ChouetteController
scope = select_time_tables
if params[:q] && params[:q]["tag_search"]
tags = params[:q]["tag_search"].reject {|c| c.empty?}
- params[:q].delete("tag_search")
scope = select_time_tables.tagged_with(tags, :any => true) if tags.any?
end
scope = self.ransack_period_range(scope: scope, error_message: t('referentials.errors.validity_period'), query: :overlapping)
diff --git a/app/decorators/compliance_control_set_decorator.rb b/app/decorators/compliance_control_set_decorator.rb
index f4aa607e1..7515316ce 100644
--- a/app/decorators/compliance_control_set_decorator.rb
+++ b/app/decorators/compliance_control_set_decorator.rb
@@ -4,6 +4,13 @@ class ComplianceControlSetDecorator < Draper::Decorator
def action_links
links = []
+ # if policy.clone?
+ links << Link.new(
+ content: h.t('actions.clone'),
+ href: h.clone_compliance_control_set_path(object.id)
+ )
+ # end
+
# if h.policy(object).destroy?
links << Link.new(
content: h.destroy_link_content,
diff --git a/app/models/compliance_control.rb b/app/models/compliance_control.rb
index baf491e8a..08efa7e9a 100644
--- a/app/models/compliance_control.rb
+++ b/app/models/compliance_control.rb
@@ -24,7 +24,6 @@ class ComplianceControl < ActiveRecord::Base
end
class << self
- def default_criticity; :warning end
def default_code; "" end
def dynamic_attributes
hstore_metadata_for_control_attributes.keys
diff --git a/app/models/generic_attribute_control/min_max.rb b/app/models/generic_attribute_control/min_max.rb
index a83ab64ab..ab6f546a7 100644
--- a/app/models/generic_attribute_control/min_max.rb
+++ b/app/models/generic_attribute_control/min_max.rb
@@ -9,7 +9,6 @@ module GenericAttributeControl
class << self
def attribute_type; :integer end
- def default_criticity; :warning end
def default_code; "3-Generic-2" end
end
end
diff --git a/app/models/generic_attribute_control/pattern.rb b/app/models/generic_attribute_control/pattern.rb
index 027d6948e..3a4a55d5c 100644
--- a/app/models/generic_attribute_control/pattern.rb
+++ b/app/models/generic_attribute_control/pattern.rb
@@ -7,7 +7,6 @@ module GenericAttributeControl
class << self
def attribute_type; :string end
- def default_criticity; :warning end
def default_code; "3-Generic-1" end
end
end
diff --git a/app/models/generic_attribute_control/uniqueness.rb b/app/models/generic_attribute_control/uniqueness.rb
index 36a270d74..f707c944b 100644
--- a/app/models/generic_attribute_control/uniqueness.rb
+++ b/app/models/generic_attribute_control/uniqueness.rb
@@ -6,7 +6,6 @@ module GenericAttributeControl
class << self
def attribute_type; :string end
- def default_criticity; :warning end
def default_code; "3-Generic-3" end
end
end
diff --git a/app/models/import.rb b/app/models/import.rb
index 64f713914..4ff8326ab 100644
--- a/app/models/import.rb
+++ b/app/models/import.rb
@@ -18,6 +18,7 @@ class Import < ActiveRecord::Base
validates :file, presence: true
validates_presence_of :workbench, :creator
+ validates_format_of :file, with: %r{\.zip\z}i, message: I18n.t('activerecord.errors.models.imports.wrong_file_extension')
before_create :initialize_fields
diff --git a/app/models/route_control/minimum_length.rb b/app/models/route_control/minimum_length.rb
index 56becfb2b..7aee4da21 100644
--- a/app/models/route_control/minimum_length.rb
+++ b/app/models/route_control/minimum_length.rb
@@ -1,5 +1,6 @@
module RouteControl
class MinimumLength < ComplianceControl
+ enumerize :criticity, in: %i(error), scope: true, default: :error
def self.default_code; "3-Route-6" end
end
diff --git a/app/models/route_control/opposite_route.rb b/app/models/route_control/opposite_route.rb
index 0148087ca..3921bb0a2 100644
--- a/app/models/route_control/opposite_route.rb
+++ b/app/models/route_control/opposite_route.rb
@@ -1,5 +1,6 @@
module RouteControl
class OppositeRoute < ComplianceControl
+ enumerize :criticity, in: %i(error), scope: true, default: :error
def self.default_code; "3-Route-2" end
end
diff --git a/app/models/vehicle_journey_control/time_table.rb b/app/models/vehicle_journey_control/time_table.rb
index 617ead12b..1e3166693 100644
--- a/app/models/vehicle_journey_control/time_table.rb
+++ b/app/models/vehicle_journey_control/time_table.rb
@@ -1,5 +1,6 @@
module VehicleJourneyControl
class TimeTable < ComplianceControl
+ enumerize :criticity, in: %i(error), scope: true, default: :error
def self.default_code; "3-VehicleJourney-4" end
end
diff --git a/app/models/vehicle_journey_control/vehicle_journey_at_stops.rb b/app/models/vehicle_journey_control/vehicle_journey_at_stops.rb
index 47ee26f82..392e7764f 100644
--- a/app/models/vehicle_journey_control/vehicle_journey_at_stops.rb
+++ b/app/models/vehicle_journey_control/vehicle_journey_at_stops.rb
@@ -1,5 +1,6 @@
module VehicleJourneyControl
class VehicleJourneyAtStops < ComplianceControl
+ enumerize :criticity, in: %i(error), scope: true, default: :error
def self.default_code; "3-VehicleJourney-5" end
end
diff --git a/app/services/zip_service.rb b/app/services/zip_service.rb
index cab301b01..7a4bdad1b 100644
--- a/app/services/zip_service.rb
+++ b/app/services/zip_service.rb
@@ -1,10 +1,9 @@
class ZipService
- # TODO: Remove me before merge https://github.com/rubyzip/rubyzip
- class Subdir < Struct.new(:name, :stream)
+ class Subdir < Struct.new(:name, :stream, :spurious)
end
- attr_reader :current_key, :current_output, :yielder
+ attr_reader :current_key, :current_output, :current_spurious, :yielder
def initialize data
@zip_data = StringIO.new(data)
@@ -36,6 +35,7 @@ class ZipService
end
def add_to_current_output entry
+ return if is_spurious! entry.name
current_output.put_next_entry entry.name
write_to_current_output entry.get_input_stream
end
@@ -51,7 +51,8 @@ class ZipService
@yielder << Subdir.new(
current_key,
# Second part of the solution, yield the closed stream
- current_output.close_buffer)
+ current_output.close_buffer,
+ current_spurious)
end
end
@@ -59,10 +60,19 @@ class ZipService
@current_key = entry_key
# First piece of the solution, use internal way to create a Zip::OutputStream
@current_output = Zip::OutputStream.new(StringIO.new(''), true, nil)
+ @current_spurious = []
end
def entry_key entry
# last dir name File.dirname.split("/").last
entry.name.split('/', -1)[-2]
end
+
+ def is_spurious! entry_name
+ segments = entry_name.split('/', 3)
+ return false if segments.size < 3
+
+ current_spurious << segments.second
+ return true
+ end
end
diff --git a/app/views/compliance_control_blocks/edit.html.slim b/app/views/compliance_control_blocks/edit.html.slim
index 0ac507ece..637bb7311 100644
--- a/app/views/compliance_control_blocks/edit.html.slim
+++ b/app/views/compliance_control_blocks/edit.html.slim
@@ -1,5 +1,5 @@
/ PageHeader
-= pageheader 'modele-calendrier',
+= pageheader 'jeux-de-controle',
t('compliance_control_blocks.edit.title', compliance_control_block: @compliance_control_block.id)
diff --git a/app/views/compliance_control_blocks/new.html.slim b/app/views/compliance_control_blocks/new.html.slim
index 654a0dc7f..49404c552 100644
--- a/app/views/compliance_control_blocks/new.html.slim
+++ b/app/views/compliance_control_blocks/new.html.slim
@@ -1,5 +1,5 @@
/ PageHeader
-= pageheader 'modele-calendrier',
+= pageheader 'jeux-de-controle',
t('compliance_control_blocks.new.title')
diff --git a/app/views/compliance_control_sets/edit.html.slim b/app/views/compliance_control_sets/edit.html.slim
index 934bd81b0..649154b91 100644
--- a/app/views/compliance_control_sets/edit.html.slim
+++ b/app/views/compliance_control_sets/edit.html.slim
@@ -1,5 +1,5 @@
/ PageHeader
-= pageheader 'modele-calendrier',
+= pageheader 'jeux-de-controle',
t('compliance_control_sets.edit.title', name: @compliance_control_set.name)
/ PageContent
diff --git a/app/views/compliance_control_sets/index.html.slim b/app/views/compliance_control_sets/index.html.slim
index 68173fee9..1120ed186 100644
--- a/app/views/compliance_control_sets/index.html.slim
+++ b/app/views/compliance_control_sets/index.html.slim
@@ -1,5 +1,5 @@
/ PageHeader
-- header_params = ['jeux-de-donnees',
+- header_params = ['jeux-de-controle',
t('compliance_control_sets.index.title'),
'']
- header_params << link_to(t('compliance_control_sets.actions.new'), new_compliance_control_set_path, class: 'btn btn-default') if policy(Calendar).create?
diff --git a/app/views/compliance_control_sets/new.html.slim b/app/views/compliance_control_sets/new.html.slim
index d6be41ee8..35654b4d6 100644
--- a/app/views/compliance_control_sets/new.html.slim
+++ b/app/views/compliance_control_sets/new.html.slim
@@ -1,5 +1,5 @@
/ PageHeader
-= pageheader 'modele-calendrier',
+= pageheader 'jeux-de-controle',
t('compliance_control_sets.index.new')
diff --git a/app/views/compliance_control_sets/show.html.slim b/app/views/compliance_control_sets/show.html.slim
index b6e203a9e..f45b0227a 100644
--- a/app/views/compliance_control_sets/show.html.slim
+++ b/app/views/compliance_control_sets/show.html.slim
@@ -1,5 +1,5 @@
/ PageHeader
-= pageheader 'jeux-de-donnees',
+= pageheader 'jeux-de-controle',
t('compliance_control_sets.show.title', name: @compliance_control_set.name),
'Lorem ipsum dolor sit amet'
@@ -96,9 +96,13 @@
cls: 'table has-filter has-search'
.select_toolbox
ul
- li.st_action
+ li.st_action.with_text
= link_to select_type_compliance_control_set_compliance_controls_path(@compliance_control_set.id)
span.fa.fa-plus
- li.st_action
+ span
+ = t('compliance_control_sets.actions.add_compliance_control')
+ li.st_action.with_text
= link_to new_compliance_control_set_compliance_control_block_path(@compliance_control_set.id)
- span.fa.fa-plus-square
+ span.fa.fa-plus
+ span
+ = t('compliance_control_sets.actions.add_compliance_control_block')
diff --git a/app/views/compliance_controls/edit.html.slim b/app/views/compliance_controls/edit.html.slim
index d7497c0e2..1d478e845 100644
--- a/app/views/compliance_controls/edit.html.slim
+++ b/app/views/compliance_controls/edit.html.slim
@@ -1,4 +1,4 @@
-= pageheader 'compliance-control',
+= pageheader 'jeux-de-controle',
t('compliance_controls.edit.title')
diff --git a/app/views/compliance_controls/new.html.slim b/app/views/compliance_controls/new.html.slim
index 962f70ecc..181f49a15 100644
--- a/app/views/compliance_controls/new.html.slim
+++ b/app/views/compliance_controls/new.html.slim
@@ -1,5 +1,5 @@
/ PageHeader
-- header_params = ['jeux-de-donnees',
+- header_params = ['jeux-de-controle',
t('compliance_controls.new.title'),
'']
= pageheader(*header_params) do
diff --git a/app/views/compliance_controls/select_type.html.slim b/app/views/compliance_controls/select_type.html.slim
index c6e3b0427..98cc5a943 100644
--- a/app/views/compliance_controls/select_type.html.slim
+++ b/app/views/compliance_controls/select_type.html.slim
@@ -1,5 +1,5 @@
/ PageHeader
-- header_params = ['jeux-de-donnees',
+- header_params = ['jeux-de-controle',
t('compliance_controls.select_type.title'),
'']
= pageheader(*header_params) do
diff --git a/app/views/compliance_controls/show.html.slim b/app/views/compliance_controls/show.html.slim
index 8232dbe28..12a28cd4b 100644
--- a/app/views/compliance_controls/show.html.slim
+++ b/app/views/compliance_controls/show.html.slim
@@ -1,7 +1,9 @@
/ PageHeader
-= pageheader 'jeux-de-donnees',
+= pageheader 'jeux-de-controle',
t('compliance_controls.show.title'),
- ''
+ '',
+ link_to(t('actions.edit'), edit_compliance_control_set_compliance_control_path(params[:compliance_control_set_id], params[:id]), class: 'btn btn-default') do
+
/ PageContent
.page_content
.container-fluid
diff --git a/app/views/imports/_form.html.slim b/app/views/imports/_form.html.slim
index 0fbf578be..95d97c534 100644
--- a/app/views/imports/_form.html.slim
+++ b/app/views/imports/_form.html.slim
@@ -9,6 +9,6 @@
.form-group
= form.label :file, t('activerecord.attributes.import.resources'), class: 'control-label col-sm-4 col-xs-5'
.col-sm-8.col-xs-7
- = form.input_field :file, label: false, class: 'form-control'
+ = form.input :file, label: false, class: 'form-control'
= form.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'wb_import_form'
diff --git a/app/views/time_tables/_filter.html.slim b/app/views/time_tables/_filter.html.slim
index 2672f7dfc..11e9987c4 100644
--- a/app/views/time_tables/_filter.html.slim
+++ b/app/views/time_tables/_filter.html.slim
@@ -9,7 +9,7 @@
.ffg-row
.form-group
= f.label Chouette::TimeTable.human_attribute_name(:tag_search), required: false, class: 'control-label'
- = f.input :tag_search, as: :tags, collection: Chouette::TimeTable.tags_on(:tags).pluck(:name), label: false, input_html: { 'data-select2ed': 'true', 'data-select2ed-placeholder': 'Indiquez une étiquette...' }, wrapper_html: { class: 'select2ed'}, include_blank: false
+ = f.input :tag_search, as: :tags, collection: Chouette::TimeTable.tags_on(:tags).pluck(:name), label: false, input_html: { 'data-select2ed': 'true', 'data-select2ed-placeholder': 'Indiquez une étiquette...' }, wrapper_html: { class: 'select2ed'}, include_blank: false, selected: params[:q] ? params[:q]['tag_search'] : nil
.form-group.togglable
= f.label Chouette::TimeTable.human_attribute_name(:bounding_dates), required: false, class: 'control-label'
diff --git a/app/workers/compliance_control_set_cloning_worker.rb b/app/workers/compliance_control_set_cloning_worker.rb
new file mode 100644
index 000000000..9cbe5c81a
--- /dev/null
+++ b/app/workers/compliance_control_set_cloning_worker.rb
@@ -0,0 +1,8 @@
+class ComplianceControlSetCloningWorker
+ include Sidekiq::Worker
+
+ def perform id, organisation_id
+ ComplianceControlSetCloner.new.copy id, organisation_id
+ end
+
+end
diff --git a/app/workers/workbench_import_worker.rb b/app/workers/workbench_import_worker.rb
index 994493944..300fad9e2 100644
--- a/app/workers/workbench_import_worker.rb
+++ b/app/workers/workbench_import_worker.rb
@@ -14,11 +14,13 @@ class WorkbenchImportWorker
zip_service = ZipService.new(downloaded)
upload zip_service
@workbench_import.update(ended_at: Time.now)
+ rescue Zip::Error
+ handle_corrupt_zip_file
end
def download
logger.info "HTTP GET #{import_url}"
- @zipfile_data = HTTPService.get_resource(
+ HTTPService.get_resource(
host: import_host,
path: import_path,
params: {token: @workbench_import.token_download}).body
@@ -32,6 +34,10 @@ class WorkbenchImportWorker
params: params(eg_file, eg_name))
end
+ def handle_corrupt_zip_file
+ @workbench_import.messages.create(criticity: :error, message_key: 'corrupt_zip_file', message_attributes: {import_name: @workbench_import.name})
+ end
+
def upload zip_service
entry_group_streams = zip_service.subdirs
@workbench_import.update total_steps: entry_group_streams.size
@@ -42,11 +48,24 @@ class WorkbenchImportWorker
raise
end
- def upload_entry_group entry_pair, element_count
- @workbench_import.update( current_step: element_count.succ )
- # status = retry_service.execute(&upload_entry_group_proc(entry_pair))
- eg_name = entry_pair.name
- eg_stream = entry_pair.stream
+ def update_object_state entry, count
+ @workbench_import.update( current_step: count )
+ unless entry.spurious.empty?
+ @workbench_import.messages.create(
+ criticity: :warning,
+ message_key: 'inconsistent_zip_file',
+ message_attributes: {
+ 'import_name' => @workbench_import.name,
+ 'spurious_dirs' => entry.spurious.join(', ')
+ })
+ end
+ end
+
+ def upload_entry_group entry, element_count
+ update_object_state entry, element_count.succ
+ # status = retry_service.execute(&upload_entry_group_proc(entry))
+ eg_name = entry.name
+ eg_stream = entry.stream
FileUtils.mkdir_p(Rails.root.join('tmp', 'imports'))