aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorAlban Peignier2018-01-10 21:34:47 +0100
committerGitHub2018-01-10 21:34:47 +0100
commitcd14af8a507eb927f5e10675c3069a820f99fb9c (patch)
treec64edd02cd025c7847e1c1e301b83f58c59f3414 /app
parent17a3d2437a4eb60ec4046137fb37d7b433dc48aa (diff)
parent5ab41aaf9978abe89faf3c11dafa8c3c372f7cfb (diff)
downloadchouette-core-cd14af8a507eb927f5e10675c3069a820f99fb9c.tar.bz2
Merge pull request #204 from af83/5413-read_only_policy_for_finalised_refs
Read only policy for referentials in suite. Refs #5413
Diffstat (limited to 'app')
-rw-r--r--app/helpers/newapplication_helper.rb3
-rw-r--r--app/models/referential.rb11
-rw-r--r--app/policies/access_link_policy.rb6
-rw-r--r--app/policies/access_point_policy.rb6
-rw-r--r--app/policies/application_policy.rb14
-rw-r--r--app/policies/connection_link_policy.rb6
-rw-r--r--app/policies/journey_pattern_policy.rb6
-rw-r--r--app/policies/line_policy.rb6
-rw-r--r--app/policies/purchase_window_policy.rb8
-rw-r--r--app/policies/referential_policy.rb10
-rw-r--r--app/policies/route_policy.rb6
-rw-r--r--app/policies/routing_constraint_zone_policy.rb6
-rw-r--r--app/policies/time_table_combination_policy.rb2
-rw-r--r--app/policies/time_table_policy.rb10
-rw-r--r--app/policies/vehicle_journey_policy.rb6
-rw-r--r--app/views/referentials/show.html.slim6
-rw-r--r--app/views/workbenches/show.html.slim2
17 files changed, 67 insertions, 47 deletions
diff --git a/app/helpers/newapplication_helper.rb b/app/helpers/newapplication_helper.rb
index df19113db..6600a03f7 100644
--- a/app/helpers/newapplication_helper.rb
+++ b/app/helpers/newapplication_helper.rb
@@ -1,3 +1,4 @@
+# coding: utf-8
module NewapplicationHelper
# Table Builder
@@ -147,7 +148,7 @@ module NewapplicationHelper
content_tag :li, link_to(t("actions.#{action}"), polymorph_url)
end
elsif action == :archive
- unless item.archived?
+ unless item.referential_read_only?
content_tag :li, link_to(t("actions.#{action}"), polymorph_url, method: :put)
end
elsif action == :unarchive
diff --git a/app/models/referential.rb b/app/models/referential.rb
index 75525c441..3eb5d3283 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -252,6 +252,14 @@ class Referential < ActiveRecord::Base
before_destroy :destroy_schema
before_destroy :destroy_jobs
+ def referential_read_only?
+ in_referential_suite? || archived?
+ end
+
+ def in_referential_suite?
+ referential_suite_id.present?
+ end
+
def in_workbench?
workbench_id.present?
end
@@ -334,9 +342,6 @@ class Referential < ActiveRecord::Base
end
end
- def in_referential_suite?
- referential_suite_id.present?
- end
attr_accessor :inline_clone
def clone_schema
diff --git a/app/policies/access_link_policy.rb b/app/policies/access_link_policy.rb
index 1f1147f60..f2ea7027f 100644
--- a/app/policies/access_link_policy.rb
+++ b/app/policies/access_link_policy.rb
@@ -6,14 +6,14 @@ class AccessLinkPolicy < ApplicationPolicy
end
def create?
- !archived? && organisation_match? && user.has_permission?('access_links.create')
+ !referential_read_only? && organisation_match? && user.has_permission?('access_links.create')
end
def update?
- !archived? && organisation_match? && user.has_permission?('access_links.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('access_links.update')
end
def destroy?
- !archived? && organisation_match? && user.has_permission?('access_links.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('access_links.destroy')
end
end
diff --git a/app/policies/access_point_policy.rb b/app/policies/access_point_policy.rb
index 41436e77c..4fa887b9e 100644
--- a/app/policies/access_point_policy.rb
+++ b/app/policies/access_point_policy.rb
@@ -6,14 +6,14 @@ class AccessPointPolicy < ApplicationPolicy
end
def create?
- !archived? && organisation_match? && user.has_permission?('access_points.create')
+ !referential_read_only? && organisation_match? && user.has_permission?('access_points.create')
end
def update?
- !archived? && organisation_match? && user.has_permission?('access_points.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('access_points.update')
end
def destroy?
- !archived? && organisation_match? && user.has_permission?('access_points.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('access_points.destroy')
end
end
diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb
index dbe4542e7..c44937c9e 100644
--- a/app/policies/application_policy.rb
+++ b/app/policies/application_policy.rb
@@ -81,6 +81,11 @@ class ApplicationPolicy
@is_archived = is_archived
end
+ def referential_read_only?
+ return @is_referential_read_only if instance_variable_defined?(:@is_referential_read_only)
+ @is_referential_read_only = is_referential_read_only
+ end
+
def organisation_match?
user.organisation_id == organisation_id
end
@@ -124,4 +129,13 @@ class ApplicationPolicy
current_referential.try(:archived_at)
end
end
+
+ def is_referential_read_only
+ !!case referential
+ when Referential
+ referential.referential_read_only?
+ else
+ current_referential.try(:referential_read_only?)
+ end
+ end
end
diff --git a/app/policies/connection_link_policy.rb b/app/policies/connection_link_policy.rb
index 240c2a804..9bab5e4db 100644
--- a/app/policies/connection_link_policy.rb
+++ b/app/policies/connection_link_policy.rb
@@ -6,14 +6,14 @@ class ConnectionLinkPolicy < ApplicationPolicy
end
def create?
- !archived? && organisation_match? && user.has_permission?('connection_links.create')
+ !referential_read_only? && organisation_match? && user.has_permission?('connection_links.create')
end
def destroy?
- !archived? && organisation_match? && user.has_permission?('connection_links.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('connection_links.destroy')
end
def update?
- !archived? && organisation_match? && user.has_permission?('connection_links.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('connection_links.update')
end
end
diff --git a/app/policies/journey_pattern_policy.rb b/app/policies/journey_pattern_policy.rb
index 12bcced17..beb18d151 100644
--- a/app/policies/journey_pattern_policy.rb
+++ b/app/policies/journey_pattern_policy.rb
@@ -7,14 +7,14 @@ class JourneyPatternPolicy < ApplicationPolicy
end
def create?
- !archived? && organisation_match? && user.has_permission?('journey_patterns.create')
+ !referential_read_only? && organisation_match? && user.has_permission?('journey_patterns.create')
end
def destroy?
- !archived? && organisation_match? && user.has_permission?('journey_patterns.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('journey_patterns.destroy')
end
def update?
- !archived? && organisation_match? && user.has_permission?('journey_patterns.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('journey_patterns.update')
end
end
diff --git a/app/policies/line_policy.rb b/app/policies/line_policy.rb
index e7263cc3b..f7b03b0b5 100644
--- a/app/policies/line_policy.rb
+++ b/app/policies/line_policy.rb
@@ -26,15 +26,15 @@ class LinePolicy < ApplicationPolicy
end
def create_footnote?
- !archived? && organisation_match? && user.has_permission?('footnotes.create')
+ !referential_read_only? && organisation_match? && user.has_permission?('footnotes.create')
end
def edit_footnote?
- !archived? && organisation_match? && user.has_permission?('footnotes.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('footnotes.update')
end
def destroy_footnote?
- !archived? && organisation_match? && user.has_permission?('footnotes.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('footnotes.destroy')
end
def update_footnote? ; edit_footnote? end
diff --git a/app/policies/purchase_window_policy.rb b/app/policies/purchase_window_policy.rb
index 75143a8bd..eb3b04bf7 100644
--- a/app/policies/purchase_window_policy.rb
+++ b/app/policies/purchase_window_policy.rb
@@ -6,15 +6,15 @@ class PurchaseWindowPolicy < ApplicationPolicy
end
def create?
- !archived? && organisation_match? && user.has_permission?('purchase_windows.create')
+ !referential_read_only? && organisation_match? && user.has_permission?('purchase_windows.create')
end
def update?
- !archived? && organisation_match? && user.has_permission?('purchase_windows.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('purchase_windows.update')
end
def destroy?
- !archived? && organisation_match? && user.has_permission?('purchase_windows.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('purchase_windows.destroy')
end
-end \ No newline at end of file
+end
diff --git a/app/policies/referential_policy.rb b/app/policies/referential_policy.rb
index 253917509..af5c14880 100644
--- a/app/policies/referential_policy.rb
+++ b/app/policies/referential_policy.rb
@@ -10,23 +10,23 @@ class ReferentialPolicy < ApplicationPolicy
end
def destroy?
- !archived? && organisation_match? && user.has_permission?('referentials.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('referentials.destroy')
end
def update?
- !archived? && organisation_match? && user.has_permission?('referentials.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('referentials.update')
end
def clone?
- !archived? && create?
+ !referential_read_only? && create?
end
def validate?
- !archived? && create? && organisation_match?
+ !referential_read_only? && create? && organisation_match?
end
def archive?
- record.archived_at.nil? && organisation_match? && user.has_permission?('referentials.update')
+ !referential_read_only? && record.archived_at.nil? && organisation_match? && user.has_permission?('referentials.update')
end
def unarchive?
diff --git a/app/policies/route_policy.rb b/app/policies/route_policy.rb
index 7e9fe251a..0337a5300 100644
--- a/app/policies/route_policy.rb
+++ b/app/policies/route_policy.rb
@@ -6,15 +6,15 @@ class RoutePolicy < ApplicationPolicy
end
def create?
- !archived? && organisation_match? && user.has_permission?('routes.create')
+ !referential_read_only? && organisation_match? && user.has_permission?('routes.create')
end
def destroy?
- !archived? && organisation_match? && user.has_permission?('routes.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('routes.destroy')
end
def update?
- !archived? && organisation_match? && user.has_permission?('routes.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('routes.update')
end
def duplicate?
diff --git a/app/policies/routing_constraint_zone_policy.rb b/app/policies/routing_constraint_zone_policy.rb
index 3cfcf46ff..fd8081bef 100644
--- a/app/policies/routing_constraint_zone_policy.rb
+++ b/app/policies/routing_constraint_zone_policy.rb
@@ -6,14 +6,14 @@ class RoutingConstraintZonePolicy < ApplicationPolicy
end
def create?
- !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.create')
+ !referential_read_only? && organisation_match? && user.has_permission?('routing_constraint_zones.create')
end
def destroy?
- !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('routing_constraint_zones.destroy')
end
def update?
- !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('routing_constraint_zones.update')
end
end
diff --git a/app/policies/time_table_combination_policy.rb b/app/policies/time_table_combination_policy.rb
index daa6808e4..bba458c18 100644
--- a/app/policies/time_table_combination_policy.rb
+++ b/app/policies/time_table_combination_policy.rb
@@ -7,6 +7,6 @@ class TimeTableCombinationPolicy < ApplicationPolicy
end
def create?
- !archived? && organisation_match? && user.has_permission?('time_tables.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('time_tables.update')
end
end
diff --git a/app/policies/time_table_policy.rb b/app/policies/time_table_policy.rb
index 92d3aef3e..390c170c7 100644
--- a/app/policies/time_table_policy.rb
+++ b/app/policies/time_table_policy.rb
@@ -7,23 +7,23 @@ class TimeTablePolicy < ApplicationPolicy
end
def create?
- !archived? && organisation_match? && user.has_permission?('time_tables.create')
+ !referential_read_only? && organisation_match? && user.has_permission?('time_tables.create')
end
def destroy?
- !archived? && organisation_match? && user.has_permission?('time_tables.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('time_tables.destroy')
end
def update?
- !archived? && organisation_match? && user.has_permission?('time_tables.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('time_tables.update')
end
def actualize?
- !archived? && organisation_match? && edit?
+ !referential_read_only? && organisation_match? && edit?
end
def duplicate?
- !archived? && organisation_match? && create?
+ !referential_read_only? && organisation_match? && create?
end
def month?
diff --git a/app/policies/vehicle_journey_policy.rb b/app/policies/vehicle_journey_policy.rb
index 24040455f..adbc5fd89 100644
--- a/app/policies/vehicle_journey_policy.rb
+++ b/app/policies/vehicle_journey_policy.rb
@@ -6,14 +6,14 @@ class VehicleJourneyPolicy < ApplicationPolicy
end
def create?
- !archived? && organisation_match? && user.has_permission?('vehicle_journeys.create')
+ !referential_read_only? && organisation_match? && user.has_permission?('vehicle_journeys.create')
end
def destroy?
- !archived? && organisation_match? && user.has_permission?('vehicle_journeys.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('vehicle_journeys.destroy')
end
def update?
- !archived? && organisation_match? && user.has_permission?('vehicle_journeys.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('vehicle_journeys.update')
end
end
diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim
index 96755359c..51041198c 100644
--- a/app/views/referentials/show.html.slim
+++ b/app/views/referentials/show.html.slim
@@ -1,7 +1,7 @@
- breadcrumb @referential
- page_header_content_for @referential
- content_for :page_header_actions do
- - unless (@referential.archived? || !policy(@referential).edit?)
+ - unless (@referential.referential_read_only? || !policy(@referential).edit?)
= link_to(t('actions.edit'), edit_referential_path(@referential), class: 'btn btn-default')
- content_for :page_header_content do
@@ -22,7 +22,7 @@
.row
.col-lg-6.col-md-6.col-sm-12.col-xs-12
= definition_list t('metadatas'),
- { t('activerecord.attributes.referential.status') => @referential.archived? ? "<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,
+ { t('activerecord.attributes.referential.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,
@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)) : '-'),
@referential.human_attribute_name(:organisation) => @referential.organisation.name,
@referential.human_attribute_name(:published_at) => '-' }
@@ -102,5 +102,5 @@
.modal-footer
button.btn.btn-link type='button' data-dismiss='modal' #{t('cancel')}
- - unless policy(@referential).archived?
+ - unless policy(@referential).referential_read_only?
= f.button :submit, t('actions.clean_up') , class: 'btn btn-primary'
diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim
index fe0b05330..17ad75051 100644
--- a/app/views/workbenches/show.html.slim
+++ b/app/views/workbenches/show.html.slim
@@ -30,7 +30,7 @@
), \
TableBuilderHelper::Column.new( \
key: :status, \
- attribute: Proc.new {|w| w.archived? ? ("<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} \
+ attribute: Proc.new {|w| w.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} \
), \
TableBuilderHelper::Column.new( \
key: :organisation, \