diff options
| author | Robert | 2017-07-05 11:54:33 +0200 |
|---|---|---|
| committer | Robert | 2017-07-05 11:59:06 +0200 |
| commit | e53aa88c442bd0057c4e0ae66e2684d62d3193ed (patch) | |
| tree | 1ba7c8c082dde92ba215659fde9293e231e7c7df /app | |
| parent | 841bd65847066e92bf5a4d6de112fed1ada73c1c (diff) | |
| download | chouette-core-e53aa88c442bd0057c4e0ae66e2684d62d3193ed.tar.bz2 | |
Refs: #3478@1h;
- All permissions tied to `!archived?`
- Tests adapted
- Policies refactored
? Is `create?` permission bound to `organisation_match?`
Diffstat (limited to 'app')
| -rw-r--r-- | app/helpers/table_builder_helper/custom_links.rb | 4 | ||||
| -rw-r--r-- | app/policies/acces_point_policy.rb | 25 | ||||
| -rw-r--r-- | app/policies/access_link_policy.rb | 6 | ||||
| -rw-r--r-- | app/policies/access_point_policy.rb | 6 | ||||
| -rw-r--r-- | app/policies/calendar_policy.rb | 6 | ||||
| -rw-r--r-- | app/policies/connection_link_policy.rb | 6 | ||||
| -rw-r--r-- | app/policies/journey_pattern_policy.rb | 7 | ||||
| -rw-r--r-- | app/policies/referential_policy.rb | 20 | ||||
| -rw-r--r-- | app/policies/routing_constraint_zone_policy.rb | 2 | ||||
| -rw-r--r-- | app/policies/time_table_policy.rb | 2 | ||||
| -rw-r--r-- | app/policies/vehicle_journey_policy.rb | 6 |
11 files changed, 57 insertions, 33 deletions
diff --git a/app/helpers/table_builder_helper/custom_links.rb b/app/helpers/table_builder_helper/custom_links.rb index 68cb24c7a..e3ffb18ac 100644 --- a/app/helpers/table_builder_helper/custom_links.rb +++ b/app/helpers/table_builder_helper/custom_links.rb @@ -33,7 +33,7 @@ module TableBuilderHelper polymorph_url << action end - polymorph_url += URL.polymorphic_url_parts(@object) + polymorph_url += URL.polymorphic_url_parts(object) end def method_for_action(action) @@ -41,7 +41,7 @@ module TableBuilderHelper end def authorized_actions - @actions.select(&policy.method(:authorizes_action?)) + actions.select(&policy.method(:authorizes_action?)) end private diff --git a/app/policies/acces_point_policy.rb b/app/policies/acces_point_policy.rb new file mode 100644 index 000000000..ce3a8a1ef --- /dev/null +++ b/app/policies/acces_point_policy.rb @@ -0,0 +1,25 @@ +class AccessPointPolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end + end + + def create? + !archived? && + organisation_match? && + user.has_permission?('access_points.create') + end + + def update? + !archived? && + organisation_match? && + user.has_permission?('access_points.edit') + end + + def destroy? + !archived? && + organisation_match? + && user.has_permission?('access_points.destroy') + end +end diff --git a/app/policies/access_link_policy.rb b/app/policies/access_link_policy.rb index 4c6473f18..a4f0e40e8 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? - user.has_permission?('access_links.create') # organisation match via referential is checked in the view + !archived? && oragnisation_mathc? && user.has_permission?('access_links.create') end def update? - organisation_match? && user.has_permission?('access_links.edit') + !archived? && organisation_match? && user.has_permission?('access_links.edit') end def destroy? - organisation_match? && user.has_permission?('access_links.destroy') + !archived? && 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 4e017eae4..a1b57a3e5 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? - user.has_permission?('access_points.create') # organisation match via referential is checked in the view + !archived? && organisation_match? && user.has_permission?('access_points.create') end def update? - organisation_match? && user.has_permission?('access_points.edit') + !archived? && organisation_match? && user.has_permission?('access_points.edit') end def destroy? - organisation_match? && user.has_permission?('access_points.destroy') + !archived? && organisation_match? && user.has_permission?('access_points.destroy') end end diff --git a/app/policies/calendar_policy.rb b/app/policies/calendar_policy.rb index 927a985b3..3353988bd 100644 --- a/app/policies/calendar_policy.rb +++ b/app/policies/calendar_policy.rb @@ -6,13 +6,13 @@ class CalendarPolicy < ApplicationPolicy end def create? - organisation_match? + !archived? && organisation_match? end def destroy? - organisation_match? + !archived? && organisation_match? end def update? - organisation_match? + !archived? && organisation_match? end def share? diff --git a/app/policies/connection_link_policy.rb b/app/policies/connection_link_policy.rb index 7dccd30a9..acadc807d 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? - user.has_permission?('connection_links.create') # organisation match via referential is checked in the view + !archived? && organisation_match? && user.has_permission?('connection_links.create') end def destroy? - organisation_match? && user.has_permission?('connection_links.destroy') + !archived? && organisation_match? && user.has_permission?('connection_links.destroy') end def update? - organisation_match? && user.has_permission?('connection_links.edit') + !archived? && organisation_match? && user.has_permission?('connection_links.edit') end end diff --git a/app/policies/journey_pattern_policy.rb b/app/policies/journey_pattern_policy.rb index 99e39eeff..810ead170 100644 --- a/app/policies/journey_pattern_policy.rb +++ b/app/policies/journey_pattern_policy.rb @@ -7,16 +7,15 @@ class JourneyPatternPolicy < ApplicationPolicy end def create? - # organisation match via referential is checked in the view - user.has_permission?('journey_patterns.create') + !archived? && organisation_match? && user.has_permission?('journey_patterns.create') end def destroy? - organisation_match? && user.has_permission?('journey_patterns.destroy') + !archived? && organisation_match? && user.has_permission?('journey_patterns.destroy') end def update? - organisation_match? && user.has_permission?('journey_patterns.edit') + !archived? && organisation_match? && user.has_permission?('journey_patterns.edit') end end diff --git a/app/policies/referential_policy.rb b/app/policies/referential_policy.rb index 371cae218..7f8c9e939 100644 --- a/app/policies/referential_policy.rb +++ b/app/policies/referential_policy.rb @@ -10,20 +10,25 @@ class ReferentialPolicy < ApplicationPolicy end def destroy? - organisation_match? && user.has_permission?('referentials.destroy') + !archived? && organisation_match? && user.has_permission?('referentials.destroy') end def update? - organisation_match? && user.has_permission?('referentials.edit') + !archived? && organisation_match? && user.has_permission?('referentials.edit') end + + def clone? + !archived? && organisation_match? && create? + end + def archive? - edit? + !archived? && update? end - def clone? - organisation_match? && create? + def unarchive? + archived? && update? end def common_lines? @@ -31,11 +36,6 @@ class ReferentialPolicy < ApplicationPolicy true end - def show? - true - end - - def unarchive? ; archive? end end diff --git a/app/policies/routing_constraint_zone_policy.rb b/app/policies/routing_constraint_zone_policy.rb index a10a2c909..3f2ad99a9 100644 --- a/app/policies/routing_constraint_zone_policy.rb +++ b/app/policies/routing_constraint_zone_policy.rb @@ -6,7 +6,7 @@ class RoutingConstraintZonePolicy < ApplicationPolicy end def create? - !archived? && user.has_permission?('routing_constraint_zones.create') # organisation match via referential is checked in the view + !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.create') end def destroy? diff --git a/app/policies/time_table_policy.rb b/app/policies/time_table_policy.rb index acd31e9b1..acdc2d13c 100644 --- a/app/policies/time_table_policy.rb +++ b/app/policies/time_table_policy.rb @@ -7,7 +7,7 @@ class TimeTablePolicy < ApplicationPolicy end def create? - !archived? && user.has_permission?('time_tables.create') # organisation match via referential is checked in the view + !archived? && organisation_match? && user.has_permission?('time_tables.create') end def destroy? diff --git a/app/policies/vehicle_journey_policy.rb b/app/policies/vehicle_journey_policy.rb index 7737f6d7e..27d96e43b 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? - user.has_permission?('vehicle_journeys.create') # organisation match via referential is checked in the view + !archived? && organisation_match? && user.has_permission?('vehicle_journeys.create') end def destroy? - organisation_match? && user.has_permission?('vehicle_journeys.destroy') + !archived? && organisation_match? && user.has_permission?('vehicle_journeys.destroy') end def update? - organisation_match? && user.has_permission?('vehicle_journeys.edit') + !archived? && organisation_match? && user.has_permission?('vehicle_journeys.edit') end end |
