From 80bfa87237b78e426e4362a503fe4d72e130beb5 Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Mon, 20 Nov 2017 18:20:24 +0100 Subject: Rearrange policies and decorators folders to include them after renaming class names on several models --- app/decorators/chouette/company_decorator.rb | 53 +++++++++++++++ app/decorators/chouette/line_decorator.rb | 45 +++++++++++++ app/decorators/chouette/network_decorator.rb | 44 +++++++++++++ app/decorators/chouette/route_decorator.rb | 75 ++++++++++++++++++++++ .../chouette/routing_constraint_zone_decorator.rb | 42 ++++++++++++ app/decorators/chouette/stop_area_decorator.rb | 43 +++++++++++++ app/decorators/chouette/stop_point_decorator.rb | 9 +++ app/decorators/chouette/time_table_decorator.rb | 55 ++++++++++++++++ app/decorators/company_decorator.rb | 53 --------------- app/decorators/line_decorator.rb | 45 ------------- app/decorators/network_decorator.rb | 44 ------------- app/decorators/route_decorator.rb | 75 ---------------------- .../routing_constraint_zone_decorator.rb | 42 ------------ app/decorators/stop_area_decorator.rb | 43 ------------- app/decorators/stop_point_decorator.rb | 9 --- app/decorators/time_table_decorator.rb | 55 ---------------- app/policies/access_link_policy.rb | 19 ------ app/policies/access_point_policy.rb | 19 ------ app/policies/chouette/access_link_policy.rb | 19 ++++++ app/policies/chouette/access_point_policy.rb | 19 ++++++ app/policies/chouette/company_policy.rb | 7 ++ app/policies/chouette/connection_link_policy.rb | 19 ++++++ app/policies/chouette/group_of_line_policy.rb | 7 ++ app/policies/chouette/journey_pattern_policy.rb | 21 ++++++ app/policies/chouette/line_policy.rb | 23 +++++++ app/policies/chouette/network_policy.rb | 7 ++ app/policies/chouette/route_policy.rb | 23 +++++++ .../chouette/routing_constraint_zone_policy.rb | 19 ++++++ app/policies/chouette/stop_area_policy.rb | 7 ++ app/policies/chouette/time_table_policy.rb | 32 +++++++++ app/policies/chouette/vehicle_journey_policy.rb | 19 ++++++ app/policies/company_policy.rb | 7 -- app/policies/connection_link_policy.rb | 19 ------ app/policies/group_of_line_policy.rb | 7 -- app/policies/journey_pattern_policy.rb | 21 ------ app/policies/line_policy.rb | 23 ------- app/policies/network_policy.rb | 7 -- app/policies/route_policy.rb | 23 ------- app/policies/routing_constraint_zone_policy.rb | 19 ------ app/policies/stop_area_policy.rb | 7 -- app/policies/time_table_policy.rb | 32 --------- app/policies/vehicle_journey_policy.rb | 19 ------ spec/factories/chouette_lines.rb | 5 +- 43 files changed, 592 insertions(+), 589 deletions(-) create mode 100644 app/decorators/chouette/company_decorator.rb create mode 100644 app/decorators/chouette/line_decorator.rb create mode 100644 app/decorators/chouette/network_decorator.rb create mode 100644 app/decorators/chouette/route_decorator.rb create mode 100644 app/decorators/chouette/routing_constraint_zone_decorator.rb create mode 100644 app/decorators/chouette/stop_area_decorator.rb create mode 100644 app/decorators/chouette/stop_point_decorator.rb create mode 100644 app/decorators/chouette/time_table_decorator.rb delete mode 100644 app/decorators/company_decorator.rb delete mode 100644 app/decorators/line_decorator.rb delete mode 100644 app/decorators/network_decorator.rb delete mode 100644 app/decorators/route_decorator.rb delete mode 100644 app/decorators/routing_constraint_zone_decorator.rb delete mode 100644 app/decorators/stop_area_decorator.rb delete mode 100644 app/decorators/stop_point_decorator.rb delete mode 100644 app/decorators/time_table_decorator.rb delete mode 100644 app/policies/access_link_policy.rb delete mode 100644 app/policies/access_point_policy.rb create mode 100644 app/policies/chouette/access_link_policy.rb create mode 100644 app/policies/chouette/access_point_policy.rb create mode 100644 app/policies/chouette/company_policy.rb create mode 100644 app/policies/chouette/connection_link_policy.rb create mode 100644 app/policies/chouette/group_of_line_policy.rb create mode 100644 app/policies/chouette/journey_pattern_policy.rb create mode 100644 app/policies/chouette/line_policy.rb create mode 100644 app/policies/chouette/network_policy.rb create mode 100644 app/policies/chouette/route_policy.rb create mode 100644 app/policies/chouette/routing_constraint_zone_policy.rb create mode 100644 app/policies/chouette/stop_area_policy.rb create mode 100644 app/policies/chouette/time_table_policy.rb create mode 100644 app/policies/chouette/vehicle_journey_policy.rb delete mode 100644 app/policies/company_policy.rb delete mode 100644 app/policies/connection_link_policy.rb delete mode 100644 app/policies/group_of_line_policy.rb delete mode 100644 app/policies/journey_pattern_policy.rb delete mode 100644 app/policies/line_policy.rb delete mode 100644 app/policies/network_policy.rb delete mode 100644 app/policies/route_policy.rb delete mode 100644 app/policies/routing_constraint_zone_policy.rb delete mode 100644 app/policies/stop_area_policy.rb delete mode 100644 app/policies/time_table_policy.rb delete mode 100644 app/policies/vehicle_journey_policy.rb diff --git a/app/decorators/chouette/company_decorator.rb b/app/decorators/chouette/company_decorator.rb new file mode 100644 index 000000000..adf1e856f --- /dev/null +++ b/app/decorators/chouette/company_decorator.rb @@ -0,0 +1,53 @@ +class Chouette::CompanyDecorator < Draper::Decorator + decorates Chouette::Company + + delegate_all + + def self.collection_decorator_class + PaginatingDecorator + end + + def linecount + object.lines.count + end + + # Requires: + # context: { + # referential: + # } + def action_links + links = [] + + if h.policy(Chouette::Company).create? + links << Link.new( + content: h.t('companies.actions.new'), + href: h.new_line_referential_company_path(context[:referential]) + ) + end + + if h.policy(object).update? + links << Link.new( + content: h.t('companies.actions.edit'), + href: h.edit_line_referential_company_path( + context[:referential], + object + ) + ) + end + + if h.policy(object).destroy? + links << Link.new( + content: t('companies.actions.destroy'), + href: h.line_referential_company_path( + context[:referential], + object + ), + method: :delete, + data: { confirm: h.t('companies.actions.destroy_confirm') } + ) + end + + links + end + +end diff --git a/app/decorators/chouette/line_decorator.rb b/app/decorators/chouette/line_decorator.rb new file mode 100644 index 000000000..02caaed56 --- /dev/null +++ b/app/decorators/chouette/line_decorator.rb @@ -0,0 +1,45 @@ +class Chouette::LineDecorator < Draper::Decorator + decorates Chouette::Line + + delegate_all + + # Requires: + # context: { + # line_referential: , + # current_organisation: + # } + def action_links + links = [] + + links << Link.new( + content: h.t('lines.actions.show_network'), + href: [context[:line_referential], object.network] + ) + + links << Link.new( + content: h.t('lines.actions.show_company'), + href: [context[:line_referential], object.company] + ) + + if h.policy(Chouette::Line).create? && + context[:line_referential].organisations.include?( + context[:current_organisation] + ) + links << Link.new( + content: h.t('lines.actions.new'), + href: h.new_line_referential_line_path(context[:line_referential]) + ) + end + + if h.policy(object).destroy? + links << Link.new( + content: h.destroy_link_content('lines.actions.destroy_confirm'), + href: h.line_referential_line_path(context[:line_referential], object), + method: :delete, + data: { confirm: h.t('lines.actions.destroy_confirm') } + ) + end + + links + end +end diff --git a/app/decorators/chouette/network_decorator.rb b/app/decorators/chouette/network_decorator.rb new file mode 100644 index 000000000..b674d3f27 --- /dev/null +++ b/app/decorators/chouette/network_decorator.rb @@ -0,0 +1,44 @@ +class Chouette::NetworkDecorator < Draper::Decorator + decorates Chouette::Network + + delegate_all + + # Requires: + # context: { + # line_referential: , + # } + def action_links + links = [] + + if h.policy(Chouette::Network).create? + links << Link.new( + content: h.t('networks.actions.new'), + href: h.new_line_referential_network_path(context[:line_referential]) + ) + end + + if h.policy(object).update? + links << Link.new( + content: h.t('networks.actions.edit'), + href: h.edit_line_referential_network_path( + context[:line_referential], + object + ) + ) + end + + if h.policy(object).destroy? + links << Link.new( + content: h.destroy_link_content('networks.actions.destroy'), + href: h.line_referential_network_path( + context[:line_referential], + object + ), + method: :delete, + data: { confirm: t('networks.actions.destroy_confirm') } + ) + end + + links + end +end diff --git a/app/decorators/chouette/route_decorator.rb b/app/decorators/chouette/route_decorator.rb new file mode 100644 index 000000000..b03b03607 --- /dev/null +++ b/app/decorators/chouette/route_decorator.rb @@ -0,0 +1,75 @@ +class Chouette::RouteDecorator < Draper::Decorator + decorates Chouette::Route + + delegate_all + + # Requires: + # context: { + # referential: , + # line: + # } + def action_links + links = [] + + if object.stop_points.any? + links << Link.new( + content: h.t('journey_patterns.index.title'), + href: [ + context[:referential], + context[:line], + object, + :journey_patterns_collection + ] + ) + end + + if object.journey_patterns.present? + links << Link.new( + content: h.t('vehicle_journeys.actions.index'), + href: [ + context[:referential], + context[:line], + object, + :vehicle_journeys + ] + ) + end + + links << Link.new( + content: h.t('vehicle_journey_exports.new.title'), + href: h.referential_line_route_vehicle_journey_exports_path( + context[:referential], + context[:line], + object, + format: :zip + ) + ) + + if h.policy(object).duplicate? + links << Link.new( + content: h.t('routes.duplicate.title'), + href: h.duplicate_referential_line_route_path( + context[:referential], + context[:line], + object + ), + method: :post + ) + end + + if h.policy(object).destroy? + links << Link.new( + content: h.destroy_link_content, + href: h.referential_line_route_path( + context[:referential], + context[:line], + object + ), + method: :delete, + data: { confirm: h.t('routes.actions.destroy_confirm') } + ) + end + + links + end +end diff --git a/app/decorators/chouette/routing_constraint_zone_decorator.rb b/app/decorators/chouette/routing_constraint_zone_decorator.rb new file mode 100644 index 000000000..83f3411b2 --- /dev/null +++ b/app/decorators/chouette/routing_constraint_zone_decorator.rb @@ -0,0 +1,42 @@ +class Chouette::RoutingConstraintZoneDecorator < Draper::Decorator + decorates Chouette::RoutingConstraintZone + + delegate_all + + # Requires: + # context: { + # referential: , + # line: + # } + def action_links + links = [] + + if h.policy(object).update? + links << Link.new( + content: h.t('actions.edit'), + href: h.edit_referential_line_routing_constraint_zone_path( + context[:referential], + context[:line], + object + ) + ) + end + + if h.policy(object).destroy? + links << Link.new( + content: h.destroy_link_content, + href: h.referential_line_routing_constraint_zone_path( + context[:referential], + context[:line], + object + ), + method: :delete, + data: { + confirm: h.t('routing_constraint_zones.actions.destroy_confirm') + } + ) + end + + links + end +end diff --git a/app/decorators/chouette/stop_area_decorator.rb b/app/decorators/chouette/stop_area_decorator.rb new file mode 100644 index 000000000..132b6320a --- /dev/null +++ b/app/decorators/chouette/stop_area_decorator.rb @@ -0,0 +1,43 @@ +class Chouette::StopAreaDecorator < Draper::Decorator + decorates Chouette::StopArea + + delegate_all + + def action_links(stop_area = nil) + links = [] + stop_area ||= object + + if h.policy(Chouette::StopArea).new? + links << Link.new( + content: h.t('stop_areas.actions.new'), + href: h.new_stop_area_referential_stop_area_path( + stop_area.stop_area_referential + ) + ) + end + + if h.policy(stop_area).update? + links << Link.new( + content: h.t('stop_areas.actions.edit'), + href: h.edit_stop_area_referential_stop_area_path( + stop_area.stop_area_referential, + stop_area + ) + ) + end + + if h.policy(stop_area).destroy? + links << Link.new( + content: h.destroy_link_content('stop_areas.actions.destroy'), + href: h.stop_area_referential_stop_area_path( + stop_area.stop_area_referential, + stop_area + ), + method: :delete, + data: { confirm: t('stop_areas.actions.destroy_confirm') } + ) + end + + links + end +end diff --git a/app/decorators/chouette/stop_point_decorator.rb b/app/decorators/chouette/stop_point_decorator.rb new file mode 100644 index 000000000..9e540ff50 --- /dev/null +++ b/app/decorators/chouette/stop_point_decorator.rb @@ -0,0 +1,9 @@ +class Chouette::StopPointDecorator < StopAreaDecorator + decorates Chouette::StopPoint + + delegate_all + + def action_links + super(object.stop_area) + end +end diff --git a/app/decorators/chouette/time_table_decorator.rb b/app/decorators/chouette/time_table_decorator.rb new file mode 100644 index 000000000..419a0942e --- /dev/null +++ b/app/decorators/chouette/time_table_decorator.rb @@ -0,0 +1,55 @@ +class Chouette::TimeTableDecorator < Draper::Decorator + decorates Chouette::TimeTable + + delegate_all + + # Requires: + # context: { + # referential: , + # } + def action_links + links = [] + + if object.calendar + links << Link.new( + content: h.t('actions.actualize'), + href: h.actualize_referential_time_table_path( + context[:referential], + object + ), + method: :post + ) + end + + if h.policy(object).edit? + links << Link.new( + content: h.t('actions.combine'), + href: h.new_referential_time_table_time_table_combination_path( + context[:referential], + object + ) + ) + end + + if h.policy(object).duplicate? + links << Link.new( + content: h.t('actions.duplicate'), + href: h.duplicate_referential_time_table_path( + context[:referential], + object + ) + ) + end + + if h.policy(object).destroy? + links << Link.new( + content: h.destroy_link_content, + href: h.referential_time_table_path(context[:referential], object), + method: :delete, + data: { confirm: h.t('time_tables.actions.destroy_confirm') } + ) + end + + links + end +end diff --git a/app/decorators/company_decorator.rb b/app/decorators/company_decorator.rb deleted file mode 100644 index 764cce3a0..000000000 --- a/app/decorators/company_decorator.rb +++ /dev/null @@ -1,53 +0,0 @@ -class CompanyDecorator < Draper::Decorator - decorates Chouette::Company - - delegate_all - - def self.collection_decorator_class - PaginatingDecorator - end - - def linecount - object.lines.count - end - - # Requires: - # context: { - # referential: - # } - def action_links - links = [] - - if h.policy(Chouette::Company).create? - links << Link.new( - content: h.t('companies.actions.new'), - href: h.new_line_referential_company_path(context[:referential]) - ) - end - - if h.policy(object).update? - links << Link.new( - content: h.t('companies.actions.edit'), - href: h.edit_line_referential_company_path( - context[:referential], - object - ) - ) - end - - if h.policy(object).destroy? - links << Link.new( - content: t('companies.actions.destroy'), - href: h.line_referential_company_path( - context[:referential], - object - ), - method: :delete, - data: { confirm: h.t('companies.actions.destroy_confirm') } - ) - end - - links - end - -end diff --git a/app/decorators/line_decorator.rb b/app/decorators/line_decorator.rb deleted file mode 100644 index f351103b2..000000000 --- a/app/decorators/line_decorator.rb +++ /dev/null @@ -1,45 +0,0 @@ -class LineDecorator < Draper::Decorator - decorates Chouette::Line - - delegate_all - - # Requires: - # context: { - # line_referential: , - # current_organisation: - # } - def action_links - links = [] - - links << Link.new( - content: h.t('lines.actions.show_network'), - href: [context[:line_referential], object.network] - ) - - links << Link.new( - content: h.t('lines.actions.show_company'), - href: [context[:line_referential], object.company] - ) - - if h.policy(Chouette::Line).create? && - context[:line_referential].organisations.include?( - context[:current_organisation] - ) - links << Link.new( - content: h.t('lines.actions.new'), - href: h.new_line_referential_line_path(context[:line_referential]) - ) - end - - if h.policy(object).destroy? - links << Link.new( - content: h.destroy_link_content('lines.actions.destroy_confirm'), - href: h.line_referential_line_path(context[:line_referential], object), - method: :delete, - data: { confirm: h.t('lines.actions.destroy_confirm') } - ) - end - - links - end -end diff --git a/app/decorators/network_decorator.rb b/app/decorators/network_decorator.rb deleted file mode 100644 index 1f62fe512..000000000 --- a/app/decorators/network_decorator.rb +++ /dev/null @@ -1,44 +0,0 @@ -class NetworkDecorator < Draper::Decorator - decorates Chouette::Network - - delegate_all - - # Requires: - # context: { - # line_referential: , - # } - def action_links - links = [] - - if h.policy(Chouette::Network).create? - links << Link.new( - content: h.t('networks.actions.new'), - href: h.new_line_referential_network_path(context[:line_referential]) - ) - end - - if h.policy(object).update? - links << Link.new( - content: h.t('networks.actions.edit'), - href: h.edit_line_referential_network_path( - context[:line_referential], - object - ) - ) - end - - if h.policy(object).destroy? - links << Link.new( - content: h.destroy_link_content('networks.actions.destroy'), - href: h.line_referential_network_path( - context[:line_referential], - object - ), - method: :delete, - data: { confirm: t('networks.actions.destroy_confirm') } - ) - end - - links - end -end diff --git a/app/decorators/route_decorator.rb b/app/decorators/route_decorator.rb deleted file mode 100644 index 510c941a3..000000000 --- a/app/decorators/route_decorator.rb +++ /dev/null @@ -1,75 +0,0 @@ -class RouteDecorator < Draper::Decorator - decorates Chouette::Route - - delegate_all - - # Requires: - # context: { - # referential: , - # line: - # } - def action_links - links = [] - - if object.stop_points.any? - links << Link.new( - content: h.t('journey_patterns.index.title'), - href: [ - context[:referential], - context[:line], - object, - :journey_patterns_collection - ] - ) - end - - if object.journey_patterns.present? - links << Link.new( - content: h.t('vehicle_journeys.actions.index'), - href: [ - context[:referential], - context[:line], - object, - :vehicle_journeys - ] - ) - end - - links << Link.new( - content: h.t('vehicle_journey_exports.new.title'), - href: h.referential_line_route_vehicle_journey_exports_path( - context[:referential], - context[:line], - object, - format: :zip - ) - ) - - if h.policy(object).duplicate? - links << Link.new( - content: h.t('routes.duplicate.title'), - href: h.duplicate_referential_line_route_path( - context[:referential], - context[:line], - object - ), - method: :post - ) - end - - if h.policy(object).destroy? - links << Link.new( - content: h.destroy_link_content, - href: h.referential_line_route_path( - context[:referential], - context[:line], - object - ), - method: :delete, - data: { confirm: h.t('routes.actions.destroy_confirm') } - ) - end - - links - end -end diff --git a/app/decorators/routing_constraint_zone_decorator.rb b/app/decorators/routing_constraint_zone_decorator.rb deleted file mode 100644 index 0b438a554..000000000 --- a/app/decorators/routing_constraint_zone_decorator.rb +++ /dev/null @@ -1,42 +0,0 @@ -class RoutingConstraintZoneDecorator < Draper::Decorator - decorates Chouette::RoutingConstraintZone - - delegate_all - - # Requires: - # context: { - # referential: , - # line: - # } - def action_links - links = [] - - if h.policy(object).update? - links << Link.new( - content: h.t('actions.edit'), - href: h.edit_referential_line_routing_constraint_zone_path( - context[:referential], - context[:line], - object - ) - ) - end - - if h.policy(object).destroy? - links << Link.new( - content: h.destroy_link_content, - href: h.referential_line_routing_constraint_zone_path( - context[:referential], - context[:line], - object - ), - method: :delete, - data: { - confirm: h.t('routing_constraint_zones.actions.destroy_confirm') - } - ) - end - - links - end -end diff --git a/app/decorators/stop_area_decorator.rb b/app/decorators/stop_area_decorator.rb deleted file mode 100644 index 4e777292d..000000000 --- a/app/decorators/stop_area_decorator.rb +++ /dev/null @@ -1,43 +0,0 @@ -class StopAreaDecorator < Draper::Decorator - decorates Chouette::StopArea - - delegate_all - - def action_links(stop_area = nil) - links = [] - stop_area ||= object - - if h.policy(Chouette::StopArea).new? - links << Link.new( - content: h.t('stop_areas.actions.new'), - href: h.new_stop_area_referential_stop_area_path( - stop_area.stop_area_referential - ) - ) - end - - if h.policy(stop_area).update? - links << Link.new( - content: h.t('stop_areas.actions.edit'), - href: h.edit_stop_area_referential_stop_area_path( - stop_area.stop_area_referential, - stop_area - ) - ) - end - - if h.policy(stop_area).destroy? - links << Link.new( - content: h.destroy_link_content('stop_areas.actions.destroy'), - href: h.stop_area_referential_stop_area_path( - stop_area.stop_area_referential, - stop_area - ), - method: :delete, - data: { confirm: t('stop_areas.actions.destroy_confirm') } - ) - end - - links - end -end diff --git a/app/decorators/stop_point_decorator.rb b/app/decorators/stop_point_decorator.rb deleted file mode 100644 index 196d6d490..000000000 --- a/app/decorators/stop_point_decorator.rb +++ /dev/null @@ -1,9 +0,0 @@ -class StopPointDecorator < StopAreaDecorator - decorates Chouette::StopPoint - - delegate_all - - def action_links - super(object.stop_area) - end -end diff --git a/app/decorators/time_table_decorator.rb b/app/decorators/time_table_decorator.rb deleted file mode 100644 index c6eeac176..000000000 --- a/app/decorators/time_table_decorator.rb +++ /dev/null @@ -1,55 +0,0 @@ -class TimeTableDecorator < Draper::Decorator - decorates Chouette::TimeTable - - delegate_all - - # Requires: - # context: { - # referential: , - # } - def action_links - links = [] - - if object.calendar - links << Link.new( - content: h.t('actions.actualize'), - href: h.actualize_referential_time_table_path( - context[:referential], - object - ), - method: :post - ) - end - - if h.policy(object).edit? - links << Link.new( - content: h.t('actions.combine'), - href: h.new_referential_time_table_time_table_combination_path( - context[:referential], - object - ) - ) - end - - if h.policy(object).duplicate? - links << Link.new( - content: h.t('actions.duplicate'), - href: h.duplicate_referential_time_table_path( - context[:referential], - object - ) - ) - end - - if h.policy(object).destroy? - links << Link.new( - content: h.destroy_link_content, - href: h.referential_time_table_path(context[:referential], object), - method: :delete, - data: { confirm: h.t('time_tables.actions.destroy_confirm') } - ) - end - - links - end -end diff --git a/app/policies/access_link_policy.rb b/app/policies/access_link_policy.rb deleted file mode 100644 index 1f1147f60..000000000 --- a/app/policies/access_link_policy.rb +++ /dev/null @@ -1,19 +0,0 @@ -class AccessLinkPolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope - end - end - - def create? - !archived? && organisation_match? && user.has_permission?('access_links.create') - end - - def update? - !archived? && organisation_match? && user.has_permission?('access_links.update') - end - - def 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 deleted file mode 100644 index 41436e77c..000000000 --- a/app/policies/access_point_policy.rb +++ /dev/null @@ -1,19 +0,0 @@ -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.update') - end - - def destroy? - !archived? && organisation_match? && user.has_permission?('access_points.destroy') - end -end diff --git a/app/policies/chouette/access_link_policy.rb b/app/policies/chouette/access_link_policy.rb new file mode 100644 index 000000000..bee7984c0 --- /dev/null +++ b/app/policies/chouette/access_link_policy.rb @@ -0,0 +1,19 @@ +class Chouette::AccessLinkPolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end + end + + def create? + !archived? && organisation_match? && user.has_permission?('access_links.create') + end + + def update? + !archived? && organisation_match? && user.has_permission?('access_links.update') + end + + def destroy? + !archived? && organisation_match? && user.has_permission?('access_links.destroy') + end +end diff --git a/app/policies/chouette/access_point_policy.rb b/app/policies/chouette/access_point_policy.rb new file mode 100644 index 000000000..6a570c812 --- /dev/null +++ b/app/policies/chouette/access_point_policy.rb @@ -0,0 +1,19 @@ +class Chouette::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.update') + end + + def destroy? + !archived? && organisation_match? && user.has_permission?('access_points.destroy') + end +end diff --git a/app/policies/chouette/company_policy.rb b/app/policies/chouette/company_policy.rb new file mode 100644 index 000000000..8fa22b5df --- /dev/null +++ b/app/policies/chouette/company_policy.rb @@ -0,0 +1,7 @@ +class Chouette::CompanyPolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end + end +end diff --git a/app/policies/chouette/connection_link_policy.rb b/app/policies/chouette/connection_link_policy.rb new file mode 100644 index 000000000..65c4101f0 --- /dev/null +++ b/app/policies/chouette/connection_link_policy.rb @@ -0,0 +1,19 @@ +class Chouette::ConnectionLinkPolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end + end + + def create? + !archived? && organisation_match? && user.has_permission?('connection_links.create') + end + + def destroy? + !archived? && organisation_match? && user.has_permission?('connection_links.destroy') + end + + def update? + !archived? && organisation_match? && user.has_permission?('connection_links.update') + end +end diff --git a/app/policies/chouette/group_of_line_policy.rb b/app/policies/chouette/group_of_line_policy.rb new file mode 100644 index 000000000..9b4fbb4d8 --- /dev/null +++ b/app/policies/chouette/group_of_line_policy.rb @@ -0,0 +1,7 @@ +class Chouette::GroupOfLinePolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end + end +end diff --git a/app/policies/chouette/journey_pattern_policy.rb b/app/policies/chouette/journey_pattern_policy.rb new file mode 100644 index 000000000..2fb1c9fd4 --- /dev/null +++ b/app/policies/chouette/journey_pattern_policy.rb @@ -0,0 +1,21 @@ +class Chouette::JourneyPatternPolicy < ApplicationPolicy + + class Scope < Scope + def resolve + scope + end + end + + def create? + !archived? && organisation_match? && user.has_permission?('journey_patterns.create') + end + + def destroy? + !archived? && organisation_match? && user.has_permission?('journey_patterns.destroy') + end + + def update? + !archived? && organisation_match? && user.has_permission?('journey_patterns.update') + end +end + diff --git a/app/policies/chouette/line_policy.rb b/app/policies/chouette/line_policy.rb new file mode 100644 index 000000000..d07ad775c --- /dev/null +++ b/app/policies/chouette/line_policy.rb @@ -0,0 +1,23 @@ +class Chouette::LinePolicy < ApplicationPolicy + + class Scope < Scope + def resolve + scope + end + end + + def create_footnote? + !archived? && organisation_match? && user.has_permission?('footnotes.create') + end + + def edit_footnote? + !archived? && organisation_match? && user.has_permission?('footnotes.update') + end + + def destroy_footnote? + !archived? && organisation_match? && user.has_permission?('footnotes.destroy') + end + + def update_footnote? ; edit_footnote? end + def new_footnote? ; create_footnote? end +end diff --git a/app/policies/chouette/network_policy.rb b/app/policies/chouette/network_policy.rb new file mode 100644 index 000000000..faea4bb79 --- /dev/null +++ b/app/policies/chouette/network_policy.rb @@ -0,0 +1,7 @@ +class Chouette::NetworkPolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end + end +end diff --git a/app/policies/chouette/route_policy.rb b/app/policies/chouette/route_policy.rb new file mode 100644 index 000000000..5f467d98f --- /dev/null +++ b/app/policies/chouette/route_policy.rb @@ -0,0 +1,23 @@ +class Chouette::RoutePolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end + end + + def create? + !archived? && organisation_match? && user.has_permission?('routes.create') + end + + def destroy? + !archived? && organisation_match? && user.has_permission?('routes.destroy') + end + + def update? + !archived? && organisation_match? && user.has_permission?('routes.update') + end + + def duplicate? + create? + end +end \ No newline at end of file diff --git a/app/policies/chouette/routing_constraint_zone_policy.rb b/app/policies/chouette/routing_constraint_zone_policy.rb new file mode 100644 index 000000000..955ae21e6 --- /dev/null +++ b/app/policies/chouette/routing_constraint_zone_policy.rb @@ -0,0 +1,19 @@ +class Chouette::RoutingConstraintZonePolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end + end + + def create? + !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.create') + end + + def destroy? + !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.destroy') + end + + def update? + !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.update') + end +end diff --git a/app/policies/chouette/stop_area_policy.rb b/app/policies/chouette/stop_area_policy.rb new file mode 100644 index 000000000..75cbf15a3 --- /dev/null +++ b/app/policies/chouette/stop_area_policy.rb @@ -0,0 +1,7 @@ +class Chouette::StopAreaPolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end + end +end diff --git a/app/policies/chouette/time_table_policy.rb b/app/policies/chouette/time_table_policy.rb new file mode 100644 index 000000000..2eb21ddf1 --- /dev/null +++ b/app/policies/chouette/time_table_policy.rb @@ -0,0 +1,32 @@ +class Chouette::TimeTablePolicy < ApplicationPolicy + + class Scope < Scope + def resolve + scope + end + end + + def create? + !archived? && organisation_match? && user.has_permission?('time_tables.create') + end + + def destroy? + !archived? && organisation_match? && user.has_permission?('time_tables.destroy') + end + + def update? + !archived? && organisation_match? && user.has_permission?('time_tables.update') + end + + def actualize? + !archived? && organisation_match? && edit? + end + + def duplicate? + !archived? && organisation_match? && create? + end + + def month? + update? + end +end diff --git a/app/policies/chouette/vehicle_journey_policy.rb b/app/policies/chouette/vehicle_journey_policy.rb new file mode 100644 index 000000000..646b0c07d --- /dev/null +++ b/app/policies/chouette/vehicle_journey_policy.rb @@ -0,0 +1,19 @@ +class Chouette::VehicleJourneyPolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end + end + + def create? + !archived? && organisation_match? && user.has_permission?('vehicle_journeys.create') + end + + def destroy? + !archived? && organisation_match? && user.has_permission?('vehicle_journeys.destroy') + end + + def update? + !archived? && organisation_match? && user.has_permission?('vehicle_journeys.update') + end +end diff --git a/app/policies/company_policy.rb b/app/policies/company_policy.rb deleted file mode 100644 index 6106798be..000000000 --- a/app/policies/company_policy.rb +++ /dev/null @@ -1,7 +0,0 @@ -class CompanyPolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope - end - end -end diff --git a/app/policies/connection_link_policy.rb b/app/policies/connection_link_policy.rb deleted file mode 100644 index 240c2a804..000000000 --- a/app/policies/connection_link_policy.rb +++ /dev/null @@ -1,19 +0,0 @@ -class ConnectionLinkPolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope - end - end - - def create? - !archived? && organisation_match? && user.has_permission?('connection_links.create') - end - - def destroy? - !archived? && organisation_match? && user.has_permission?('connection_links.destroy') - end - - def update? - !archived? && organisation_match? && user.has_permission?('connection_links.update') - end -end diff --git a/app/policies/group_of_line_policy.rb b/app/policies/group_of_line_policy.rb deleted file mode 100644 index 03e94449d..000000000 --- a/app/policies/group_of_line_policy.rb +++ /dev/null @@ -1,7 +0,0 @@ -class GroupOfLinePolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope - end - end -end diff --git a/app/policies/journey_pattern_policy.rb b/app/policies/journey_pattern_policy.rb deleted file mode 100644 index 507a364b6..000000000 --- a/app/policies/journey_pattern_policy.rb +++ /dev/null @@ -1,21 +0,0 @@ -class JourneyPatternPolicy < ApplicationPolicy - - class Scope < Scope - def resolve - scope - end - end - - def create? - !archived? && organisation_match? && user.has_permission?('journey_patterns.create') - end - - def destroy? - !archived? && organisation_match? && user.has_permission?('journey_patterns.destroy') - end - - def update? - !archived? && organisation_match? && user.has_permission?('journey_patterns.update') - end -end - diff --git a/app/policies/line_policy.rb b/app/policies/line_policy.rb deleted file mode 100644 index acb0d79e7..000000000 --- a/app/policies/line_policy.rb +++ /dev/null @@ -1,23 +0,0 @@ -class LinePolicy < ApplicationPolicy - - class Scope < Scope - def resolve - scope - end - end - - def create_footnote? - !archived? && organisation_match? && user.has_permission?('footnotes.create') - end - - def edit_footnote? - !archived? && organisation_match? && user.has_permission?('footnotes.update') - end - - def destroy_footnote? - !archived? && organisation_match? && user.has_permission?('footnotes.destroy') - end - - def update_footnote? ; edit_footnote? end - def new_footnote? ; create_footnote? end -end diff --git a/app/policies/network_policy.rb b/app/policies/network_policy.rb deleted file mode 100644 index 9f86451a5..000000000 --- a/app/policies/network_policy.rb +++ /dev/null @@ -1,7 +0,0 @@ -class NetworkPolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope - end - end -end diff --git a/app/policies/route_policy.rb b/app/policies/route_policy.rb deleted file mode 100644 index 7e9fe251a..000000000 --- a/app/policies/route_policy.rb +++ /dev/null @@ -1,23 +0,0 @@ -class RoutePolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope - end - end - - def create? - !archived? && organisation_match? && user.has_permission?('routes.create') - end - - def destroy? - !archived? && organisation_match? && user.has_permission?('routes.destroy') - end - - def update? - !archived? && organisation_match? && user.has_permission?('routes.update') - end - - def duplicate? - create? - end -end diff --git a/app/policies/routing_constraint_zone_policy.rb b/app/policies/routing_constraint_zone_policy.rb deleted file mode 100644 index 3cfcf46ff..000000000 --- a/app/policies/routing_constraint_zone_policy.rb +++ /dev/null @@ -1,19 +0,0 @@ -class RoutingConstraintZonePolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope - end - end - - def create? - !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.create') - end - - def destroy? - !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.destroy') - end - - def update? - !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.update') - end -end diff --git a/app/policies/stop_area_policy.rb b/app/policies/stop_area_policy.rb deleted file mode 100644 index de8ecda8d..000000000 --- a/app/policies/stop_area_policy.rb +++ /dev/null @@ -1,7 +0,0 @@ -class StopAreaPolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope - end - end -end diff --git a/app/policies/time_table_policy.rb b/app/policies/time_table_policy.rb deleted file mode 100644 index 92d3aef3e..000000000 --- a/app/policies/time_table_policy.rb +++ /dev/null @@ -1,32 +0,0 @@ -class TimeTablePolicy < ApplicationPolicy - - class Scope < Scope - def resolve - scope - end - end - - def create? - !archived? && organisation_match? && user.has_permission?('time_tables.create') - end - - def destroy? - !archived? && organisation_match? && user.has_permission?('time_tables.destroy') - end - - def update? - !archived? && organisation_match? && user.has_permission?('time_tables.update') - end - - def actualize? - !archived? && organisation_match? && edit? - end - - def duplicate? - !archived? && organisation_match? && create? - end - - def month? - update? - end -end diff --git a/app/policies/vehicle_journey_policy.rb b/app/policies/vehicle_journey_policy.rb deleted file mode 100644 index 24040455f..000000000 --- a/app/policies/vehicle_journey_policy.rb +++ /dev/null @@ -1,19 +0,0 @@ -class VehicleJourneyPolicy < ApplicationPolicy - class Scope < Scope - def resolve - scope - end - end - - def create? - !archived? && organisation_match? && user.has_permission?('vehicle_journeys.create') - end - - def destroy? - !archived? && organisation_match? && user.has_permission?('vehicle_journeys.destroy') - end - - def update? - !archived? && organisation_match? && user.has_permission?('vehicle_journeys.update') - end -end diff --git a/spec/factories/chouette_lines.rb b/spec/factories/chouette_lines.rb index fb15e12de..f6542bf82 100644 --- a/spec/factories/chouette_lines.rb +++ b/spec/factories/chouette_lines.rb @@ -8,7 +8,10 @@ FactoryGirl.define do association :network, :factory => :network association :company, :factory => :company - association :line_referential, :factory => :line_referential + + before(:create) do |line| + line.line_referential ||= LineReferential.find_by! name: "first" + end sequence(:registration_number) { |n| "test-#{n}" } -- cgit v1.2.3