aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert2017-05-31 10:16:24 +0200
committerRobert2017-05-31 10:16:24 +0200
commit82921d0135bea20964e85ab10797f724414a9b24 (patch)
treed4835989f52727ad5e9da6891d7070f0fd08547a
parent19b000d64bf57e345d80fbf9a2c69aeef11fdee1 (diff)
downloadchouette-core-82921d0135bea20964e85ab10797f724414a9b24.tar.bz2
hotfix for broken code realoading due to standard vanilla AOP implementation
-rw-r--r--app/policies/boiv_policy.rb2
-rw-r--r--app/policies/chain.rb57
-rw-r--r--app/policies/journey_pattern_policy.rb1
-rw-r--r--app/policies/line_policy.rb10
-rw-r--r--app/policies/route_policy.rb9
-rw-r--r--app/policies/routing_constraint_zone_policy.rb9
-rw-r--r--app/policies/time_table_policy.rb11
7 files changed, 15 insertions, 84 deletions
diff --git a/app/policies/boiv_policy.rb b/app/policies/boiv_policy.rb
index 4270dc686..444006aa4 100644
--- a/app/policies/boiv_policy.rb
+++ b/app/policies/boiv_policy.rb
@@ -1,6 +1,6 @@
-require_relative 'chain'
class BoivPolicy < ApplicationPolicy
+
def boiv_read_offer?
organisation_match? && user.has_permission?('boiv:read-offer')
end
diff --git a/app/policies/chain.rb b/app/policies/chain.rb
deleted file mode 100644
index 4bf96bd84..000000000
--- a/app/policies/chain.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-module Policies
- # Implements the `chain_policies` macro as follows
- #
- # chain_policies <method_chain>, policies:
- #
- # e.g.
- #
- # chain_policies [:archived?, :!], policies: %i{create? edit?}
- #
- # which would establish a precondition `not archived` for the `create?` and `edit?`
- # method, it is semantically identical to instrumenting both methods
- # as follows:
- #
- # def create? # or edit?
- # archived?.! && <original code of method>
- # end
- module Chain
-
- # A local chain store implemented to avoid any possible side effect on client policies.
- defined_chains = {}
-
- # Using `define_method` in order to close over `defined_chains`
- # We need to store the chains because the methods they will apply to
- # are not defined yet.
- define_method :chain_policies do |*conditions, policies:|
- policies.each do | meth_name |
- # self represents the client Policy
- defined_chains[[self, meth_name]] = conditions
- end
- end
- # Intercept method definition and check if a policy_chain has been registered for it‥.
- define_method :method_added do |meth_name, *args, &blk|
- # Delete potentially registered criteria conditions to‥.
- # (i) protect against endless recursion via (:merthod_added → :define_method → :method_added → ‥.
- # (ii) get the condition
- conditions = defined_chains.delete([self, meth_name])
- return unless conditions
-
- instrument_method(meth_name, conditions)
- end
-
- private
-
- # Access to the closure is not necessary anymore, normal metaprogramming can take place :)
- def instrument_method(meth_name, conditions)
- orig_method = instance_method(meth_name)
- # In case of warnings remove original method here, depends on Ruby Version, ok in 2.3.1
- define_method meth_name do |*a, &b|
- # Method chain describing the chained policy precondition.
- conditions.inject(self) do | result, msg |
- result.send msg
- end &&
- orig_method.bind(self).(*a, &b)
- end
- end
- end
-end
diff --git a/app/policies/journey_pattern_policy.rb b/app/policies/journey_pattern_policy.rb
index 9d13624c5..01ce2cbbb 100644
--- a/app/policies/journey_pattern_policy.rb
+++ b/app/policies/journey_pattern_policy.rb
@@ -1,4 +1,5 @@
class JourneyPatternPolicy < BoivPolicy
+
class Scope < Scope
def resolve
scope
diff --git a/app/policies/line_policy.rb b/app/policies/line_policy.rb
index c3e0051c8..b829040af 100644
--- a/app/policies/line_policy.rb
+++ b/app/policies/line_policy.rb
@@ -1,8 +1,4 @@
-require_relative 'chain'
class LinePolicy < BoivPolicy
- extend Policies::Chain
-
- chain_policies :archived?, :!, policies: %i{create_footnote? destroy_footnote? edit_footnote?}
class Scope < Scope
def resolve
@@ -19,15 +15,15 @@ class LinePolicy < BoivPolicy
def destroy? ; create? end
def create_footnote?
- user.has_permission?('footnotes.create')
+ !archived? && user.has_permission?('footnotes.create')
end
def edit_footnote?
- user.has_permission?('footnotes.edit')
+ !archived? && user.has_permission?('footnotes.edit')
end
def destroy_footnote?
- user.has_permission?('footnotes.destroy')
+ !archived? && user.has_permission?('footnotes.destroy')
end
def update_footnote? ; edit_footnote? end
diff --git a/app/policies/route_policy.rb b/app/policies/route_policy.rb
index dba3a27da..ca9b02164 100644
--- a/app/policies/route_policy.rb
+++ b/app/policies/route_policy.rb
@@ -1,23 +1,20 @@
class RoutePolicy < BoivPolicy
- extend Policies::Chain
class Scope < Scope
def resolve
scope
end
end
- chain_policies :archived?, :!, policies: %i{create? destroy? edit?}
-
def create?
- user.has_permission?('routes.create') # organisation match via referential is checked in the view
+ !archived? && user.has_permission?('routes.create') # organisation match via referential is checked in the view
end
def edit?
- organisation_match? && user.has_permission?('routes.edit')
+ !archived? && organisation_match? && user.has_permission?('routes.edit')
end
def destroy?
- organisation_match? && user.has_permission?('routes.destroy')
+ !archived? && organisation_match? && user.has_permission?('routes.destroy')
end
def update? ; edit? end
diff --git a/app/policies/routing_constraint_zone_policy.rb b/app/policies/routing_constraint_zone_policy.rb
index abba5639c..da311bc03 100644
--- a/app/policies/routing_constraint_zone_policy.rb
+++ b/app/policies/routing_constraint_zone_policy.rb
@@ -1,23 +1,20 @@
class RoutingConstraintZonePolicy < BoivPolicy
- extend Policies::Chain
class Scope < Scope
def resolve
scope
end
end
- chain_policies :archived?, :!, policies: %i{create? destroy? edit?}
-
def create?
- user.has_permission?('routing_constraint_zones.create') # organisation match via referential is checked in the view
+ !archived? && user.has_permission?('routing_constraint_zones.create') # organisation match via referential is checked in the view
end
def edit?
- organisation_match? && user.has_permission?('routing_constraint_zones.edit')
+ !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.edit')
end
def destroy?
- organisation_match? && user.has_permission?('routing_constraint_zones.destroy')
+ !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.destroy')
end
def update? ; edit? end
diff --git a/app/policies/time_table_policy.rb b/app/policies/time_table_policy.rb
index efab6ac00..e915ede6a 100644
--- a/app/policies/time_table_policy.rb
+++ b/app/policies/time_table_policy.rb
@@ -1,5 +1,4 @@
class TimeTablePolicy < BoivPolicy
- extend Policies::Chain
class Scope < Scope
def resolve
@@ -7,22 +6,20 @@ class TimeTablePolicy < BoivPolicy
end
end
- chain_policies :archived?, :!, policies: %i{create? destroy? duplicate? edit?}
-
def create?
- user.has_permission?('time_tables.create') # organisation match via referential is checked in the view
+ !archived? && user.has_permission?('time_tables.create') # organisation match via referential is checked in the view
end
def edit?
- organisation_match? && user.has_permission?('time_tables.edit')
+ !archived? && organisation_match? && user.has_permission?('time_tables.edit')
end
def destroy?
- organisation_match? && user.has_permission?('time_tables.destroy')
+ !archived? && organisation_match? && user.has_permission?('time_tables.destroy')
end
def duplicate?
- organisation_match? && create?
+ !archived? && organisation_match? && create?
end
def update? ; edit? end