aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlban Peignier2018-01-11 21:43:22 +0100
committerAlban Peignier2018-01-11 22:03:34 +0100
commit13de613c6db20e32f58ca16b5b3c58e79b5e8d70 (patch)
tree99334c94543e6d7f13301b175dd3de48352a47fc
parent1fd6d7d0cfb63b024860d1c29fca089432fce2e1 (diff)
downloadchouette-core-13de613c6db20e32f58ca16b5b3c58e79b5e8d70.tar.bz2
Add Referential#merged_at and make Referentials archived and merged. Refs #5559
-rw-r--r--app/controllers/merges_controller.rb2
-rw-r--r--app/models/merge.rb2
-rw-r--r--app/models/referential.rb12
-rw-r--r--app/policies/referential_policy.rb4
-rw-r--r--app/views/referentials/show.html.slim2
-rw-r--r--app/views/workbenches/show.html.slim4
-rw-r--r--config/locales/referentials.en.yml2
-rw-r--r--config/locales/referentials.fr.yml2
-rw-r--r--db/migrate/20180111200406_add_merged_at_to_referentials.rb5
-rw-r--r--db/schema.rb9
-rw-r--r--spec/helpers/table_builder_helper_spec.rb4
11 files changed, 34 insertions, 14 deletions
diff --git a/app/controllers/merges_controller.rb b/app/controllers/merges_controller.rb
index a95768139..1ce64ed58 100644
--- a/app/controllers/merges_controller.rb
+++ b/app/controllers/merges_controller.rb
@@ -11,7 +11,7 @@ class MergesController < ChouetteController
private
def set_mergeable_controllers
- @mergeable_referentials ||= parent.referentials.ready.not_in_referential_suite
+ @mergeable_referentials ||= parent.referentials.mergeable
Rails.logger.debug "Mergeables: #{@mergeable_referentials.inspect}"
end
diff --git a/app/models/merge.rb b/app/models/merge.rb
index 26bd5398b..eebf1d2e1 100644
--- a/app/models/merge.rb
+++ b/app/models/merge.rb
@@ -360,6 +360,8 @@ class Merge < ActiveRecord::Base
def save_current
output.update current: new, new: nil
output.current.update referential_suite: output
+
+ referentials.update_all merged_at: created_at, archived_at: created_at
end
def fixme_functional_scope
diff --git a/app/models/referential.rb b/app/models/referential.rb
index 718f60ffd..92931564d 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -463,6 +463,18 @@ class Referential < ActiveRecord::Base
not metadatas_overlap?
end
+ def merged?
+ merged_at.present?
+ end
+
+ def self.not_merged
+ where merged_at: nil
+ end
+
+ def self.mergeable
+ ready.not_merged.not_in_referential_suite
+ end
+
private
def lock_table
diff --git a/app/policies/referential_policy.rb b/app/policies/referential_policy.rb
index af5c14880..f5c2d7c08 100644
--- a/app/policies/referential_policy.rb
+++ b/app/policies/referential_policy.rb
@@ -18,7 +18,7 @@ class ReferentialPolicy < ApplicationPolicy
end
def clone?
- !referential_read_only? && create?
+ !record.in_referential_suite? && create?
end
def validate?
@@ -30,7 +30,7 @@ class ReferentialPolicy < ApplicationPolicy
end
def unarchive?
- !record.archived_at.nil? && organisation_match? && user.has_permission?('referentials.update')
+ record.archived? && !record.merged? && organisation_match? && user.has_permission?('referentials.update')
end
def common_lines?
diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim
index 305d04f6b..cbb622c44 100644
--- a/app/views/referentials/show.html.slim
+++ b/app/views/referentials/show.html.slim
@@ -25,7 +25,7 @@
- attributes[@referential.human_attribute_name(:status)] = @referential.referential_read_only? ? "<div class='td-block'><span class='fa fa-archive'></span><span>#{t('activerecord.attributes.referential.archived_at')}</span></div>".html_safe : "<div class='td-block'><span class='sb sb-lg sb-preparing'></span><span>#{t('activerecord.attributes.referential.archived_at_null')}</span></div>".html_safe unless @referential.in_referential_suite?
- attributes[@referential.human_attribute_name(:validity_period)] = (@referential.validity_period.present? ? t('validity_range', debut: l(@referential.try(:validity_period).try(:begin), format: :short), end: l(@referential.try(:validity_period).try(:end), format: :short)) : '-')
- attributes[@referential.human_attribute_name(:organisation)] = @referential.organisation.name
- - attributes[@referential.human_attribute_name(:published_at)] = '-' unless @referential.in_referential_suite?
+ - attributes[@referential.human_attribute_name(:merged_at)] = @referential.merged_at ? l(@referential.merged_at, format: :short) : '-' unless @referential.in_referential_suite?
= definition_list t('metadatas'), attributes
- if params[:q].present? or @reflines.any?
diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim
index 17ad75051..8907f3f08 100644
--- a/app/views/workbenches/show.html.slim
+++ b/app/views/workbenches/show.html.slim
@@ -54,8 +54,8 @@
attribute: Proc.new {|w| l(w.updated_at, format: :short)} \
), \
TableBuilderHelper::Column.new( \
- key: :published_at, \
- attribute: '' \
+ key: :merged_at, \
+ attribute: Proc.new {|w| w.merged_at ? l(w.merged_at, format: :short) : '-'} \
) \
],
selectable: ->(ref){ @workbench.referentials.include?(ref) },
diff --git a/config/locales/referentials.en.yml b/config/locales/referentials.en.yml
index f41e35446..eb8eae98d 100644
--- a/config/locales/referentials.en.yml
+++ b/config/locales/referentials.en.yml
@@ -91,7 +91,7 @@ en:
routing_constraint_zone: Routing constraint zone
validity_period: "Inclusive validity period"
updated_at: "Updated"
- published_at: "Integrated"
+ merged_at: "Finalized"
archived_at: "Archived"
archived_at_null: "Unarchived"
created_from: 'Created from'
diff --git a/config/locales/referentials.fr.yml b/config/locales/referentials.fr.yml
index 0f6e71520..37af8a4eb 100644
--- a/config/locales/referentials.fr.yml
+++ b/config/locales/referentials.fr.yml
@@ -92,7 +92,7 @@ fr:
validity_period: "Période de validité englobante"
updated_at: "Edité le"
created_at: "Créé le"
- published_at: "Intégré le"
+ merged_at: "Finalisé le"
archived_at: "Conservé"
archived_at_null: "En préparation"
created_from: 'Créé à partir de'
diff --git a/db/migrate/20180111200406_add_merged_at_to_referentials.rb b/db/migrate/20180111200406_add_merged_at_to_referentials.rb
new file mode 100644
index 000000000..27b11fa29
--- /dev/null
+++ b/db/migrate/20180111200406_add_merged_at_to_referentials.rb
@@ -0,0 +1,5 @@
+class AddMergedAtToReferentials < ActiveRecord::Migration
+ def change
+ add_column :referentials, :merged_at, :datetime
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index f55800c8b..f2cf6b4b6 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: 20180109180350) do
+ActiveRecord::Schema.define(version: 20180111200406) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -676,6 +676,7 @@ ActiveRecord::Schema.define(version: 20180109180350) do
t.boolean "ready", default: false
t.integer "referential_suite_id", limit: 8
t.string "objectid_format"
+ t.datetime "merged_at"
end
add_index "referentials", ["created_from_id"], name: "index_referentials_on_created_from_id", using: :btree
@@ -955,7 +956,7 @@ ActiveRecord::Schema.define(version: 20180109180350) do
t.integer "route_id", limit: 8
t.integer "journey_pattern_id", limit: 8
t.integer "company_id", limit: 8
- t.string "objectid", null: false
+ t.string "objectid", null: false
t.integer "object_version", limit: 8
t.string "comment"
t.string "status_value"
@@ -967,13 +968,13 @@ ActiveRecord::Schema.define(version: 20180109180350) do
t.integer "number", limit: 8
t.boolean "mobility_restricted_suitability"
t.boolean "flexible_service"
- t.integer "journey_category", default: 0, null: false
+ t.integer "journey_category", default: 0, null: false
t.datetime "created_at"
t.datetime "updated_at"
t.string "checksum"
t.text "checksum_source"
t.string "data_source_ref"
- t.jsonb "custom_field_values", default: {}
+ t.jsonb "custom_field_values"
end
add_index "vehicle_journeys", ["objectid"], name: "vehicle_journeys_objectid_key", unique: true, using: :btree
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index e82697b0a..8b383d88d 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -55,7 +55,7 @@ describe TableBuilderHelper, type: :helper do
<th><a href="/workbenches/#{workbench.id}?direction=desc&amp;sort=lines">Lignes<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th>
<th><a href="/workbenches/#{workbench.id}?direction=desc&amp;sort=created_at">Créé le<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th>
<th><a href="/workbenches/#{workbench.id}?direction=desc&amp;sort=updated_at">Edité le<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th>
- <th><a href="/workbenches/#{workbench.id}?direction=desc&amp;sort=published_at">Intégré le<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th>
+ <th><a href="/workbenches/#{workbench.id}?direction=desc&amp;sort=merged_at">Finalisé le<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th>
<th></th>
</tr>
</thead>
@@ -144,7 +144,7 @@ describe TableBuilderHelper, type: :helper do
attribute: Proc.new {|w| l(w.updated_at, format: :short)}
),
TableBuilderHelper::Column.new(
- key: :published_at,
+ key: :merged_at,
attribute: ''
)
],