aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorAlban Peignier2018-01-11 21:43:22 +0100
committerAlban Peignier2018-01-11 22:03:34 +0100
commit13de613c6db20e32f58ca16b5b3c58e79b5e8d70 (patch)
tree99334c94543e6d7f13301b175dd3de48352a47fc /app
parent1fd6d7d0cfb63b024860d1c29fca089432fce2e1 (diff)
downloadchouette-core-13de613c6db20e32f58ca16b5b3c58e79b5e8d70.tar.bz2
Add Referential#merged_at and make Referentials archived and merged. Refs #5559
Diffstat (limited to 'app')
-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
6 files changed, 20 insertions, 6 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) },