From 657966f57ab15234effcc56d58ff49dace885576 Mon Sep 17 00:00:00 2001 From: Marc Florisson Date: Mon, 26 Jan 2015 10:00:13 +0100 Subject: add restrictions specific to Hub --- lib/ninoxe_extension/hub/route_restrictions.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/ninoxe_extension/hub/route_restrictions.rb (limited to 'lib') diff --git a/lib/ninoxe_extension/hub/route_restrictions.rb b/lib/ninoxe_extension/hub/route_restrictions.rb new file mode 100644 index 000000000..c6c403796 --- /dev/null +++ b/lib/ninoxe_extension/hub/route_restrictions.rb @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +module NinoxeExtension::Hub::RouteRestrictions + extend ActiveSupport::Concern + + included do + validate :max_instance_limitation, :wayback_code_limitation + + def wayback_code_limitation + return unless hub_restricted? + errors.add( :wayback_code, "déjà pris!") if line.routes.reject {|r| r.id==id}.map(&:wayback_code).include?( wayback_code) + end + + def max_instance_limitation + return unless hub_restricted? + errors.add( :flash, "2 routes max") + end + + with_options if: :hub_restricted? do |route| + route.validates_format_of :objectid, :with => %r{^\w+:\w+:[\w]{1,8}$} + #admin.validates :password, length: { minimum: 10 } + #admin.validates :email, presence: true + end + end +end + -- cgit v1.2.3 From a98cf1bdae71922512abb284429c96777d01db18 Mon Sep 17 00:00:00 2001 From: Marc Florisson Date: Tue, 3 Feb 2015 12:26:37 +0100 Subject: first refactor to add rule parameter set to organisation --- lib/ninoxe_extension/hub/company_restrictions.rb | 20 ++++++++ .../hub/connection_link_restrictions.rb | 16 +++++++ .../hub/group_of_line_restrictions.rb | 21 +++++++++ .../hub/journey_pattern_restrictions.rb | 20 ++++++++ lib/ninoxe_extension/hub/line_restrictions.rb | 25 ++++++++++ lib/ninoxe_extension/hub/network_restrictions.rb | 20 ++++++++ lib/ninoxe_extension/hub/objectid_restrictions.rb | 22 +++++++++ lib/ninoxe_extension/hub/route_restrictions.rb | 10 ++-- lib/ninoxe_extension/hub/stop_area_restrictions.rb | 53 ++++++++++++++++++++++ .../hub/time_table_restrictions.rb | 18 ++++++++ .../hub/vehicle_journey_restrictions.rb | 16 +++++++ 11 files changed, 238 insertions(+), 3 deletions(-) create mode 100644 lib/ninoxe_extension/hub/company_restrictions.rb create mode 100644 lib/ninoxe_extension/hub/connection_link_restrictions.rb create mode 100644 lib/ninoxe_extension/hub/group_of_line_restrictions.rb create mode 100644 lib/ninoxe_extension/hub/journey_pattern_restrictions.rb create mode 100644 lib/ninoxe_extension/hub/line_restrictions.rb create mode 100644 lib/ninoxe_extension/hub/network_restrictions.rb create mode 100644 lib/ninoxe_extension/hub/objectid_restrictions.rb create mode 100644 lib/ninoxe_extension/hub/stop_area_restrictions.rb create mode 100644 lib/ninoxe_extension/hub/time_table_restrictions.rb create mode 100644 lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb (limited to 'lib') diff --git a/lib/ninoxe_extension/hub/company_restrictions.rb b/lib/ninoxe_extension/hub/company_restrictions.rb new file mode 100644 index 000000000..780e0e4d9 --- /dev/null +++ b/lib/ninoxe_extension/hub/company_restrictions.rb @@ -0,0 +1,20 @@ +module NinoxeExtension::Hub + module CompanyRestrictions + extend ActiveSupport::Concern + + included do + include ObjectidRestrictions + + with_options if: :hub_restricted? do |g| + # HUB-7 + g.validates_format_of :objectid, :with => %r{^\w+:\w+:[\w]{1,3}$} + # HUB-8 + g.validates_format_of :name, :with => %r{^[\w]{1,75}$} + # HUB-9 + g.validates_format_of :registration_number, :with => %r{^[\d]{1,8}$} + g.validates_uniqueness_of :registration_number + end + end + end +end + diff --git a/lib/ninoxe_extension/hub/connection_link_restrictions.rb b/lib/ninoxe_extension/hub/connection_link_restrictions.rb new file mode 100644 index 000000000..bf433379b --- /dev/null +++ b/lib/ninoxe_extension/hub/connection_link_restrictions.rb @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +module NinoxeExtension::Hub + module ConnectionLinkRestrictions + extend ActiveSupport::Concern + + included do + include ObjectidRestrictions + + with_options if: :hub_restricted? do |jp| + # HUB-34 + jp.validates :link_distance, :numericality => { :max => 10000.0 } + end + end + end +end + diff --git a/lib/ninoxe_extension/hub/group_of_line_restrictions.rb b/lib/ninoxe_extension/hub/group_of_line_restrictions.rb new file mode 100644 index 000000000..13688376f --- /dev/null +++ b/lib/ninoxe_extension/hub/group_of_line_restrictions.rb @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +module NinoxeExtension::Hub + module GroupOfLineRestrictions + extend ActiveSupport::Concern + + included do + include ObjectidRestrictions + + with_options if: :hub_restricted? do |g| + # HUB-11 + g.validates_format_of :objectid, :with => %r{^\w+:\w+:[\w]{1,6}$} + # HUB-12 + g.validates_format_of :name, :with => %r{^[\w]{1,75}$} + # HUB-13 + g.validates_format_of :registration_number, :with => %r{^[\d]{1,8}$} + g.validates_uniqueness_of :registration_number + end + end + end +end + diff --git a/lib/ninoxe_extension/hub/journey_pattern_restrictions.rb b/lib/ninoxe_extension/hub/journey_pattern_restrictions.rb new file mode 100644 index 000000000..2726c563a --- /dev/null +++ b/lib/ninoxe_extension/hub/journey_pattern_restrictions.rb @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +module NinoxeExtension::Hub + module JourneyPatternRestrictions + extend ActiveSupport::Concern + + included do + include ObjectidRestrictions + + with_options if: :hub_restricted? do |jp| + # HUB-39 + jp.validates_format_of :objectid, :with => %r{^\w+:\w+:[\w]{1,30}$} + # HUB-40 + jp.validates :registration_number, :numericality => { :less_than => 10 ** 8 } + # HUB-41 + jp.validates_format_of :name, :with => %r{^[\w]{0,75}$} + end + end + end +end + diff --git a/lib/ninoxe_extension/hub/line_restrictions.rb b/lib/ninoxe_extension/hub/line_restrictions.rb new file mode 100644 index 000000000..119ab07b6 --- /dev/null +++ b/lib/ninoxe_extension/hub/line_restrictions.rb @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +module NinoxeExtension::Hub + module LineRestrictions + extend ActiveSupport::Concern + + + included do + include ObjectidRestrictions + + with_options if: :hub_restricted? do |l| + # HUB-15 + l.validates_format_of :objectid, :with => %r{^\w+:\w+:[\w]{1,14}$} + # HUB-16 + l.validates_format_of :number, :with => %r{^[\w]{1,6}$} + # HUB-17 + l.validates_format_of :name, :with => %r{^[\w]{0,75}$} + # HUB-21 + l.validates :registration_number, :numericality => { :less_than => 10 ** 8 } + # HUB-22 + l.validates_uniqueness_of :name, :allow_blank => true + end + end + end +end + diff --git a/lib/ninoxe_extension/hub/network_restrictions.rb b/lib/ninoxe_extension/hub/network_restrictions.rb new file mode 100644 index 000000000..b2e8d4be5 --- /dev/null +++ b/lib/ninoxe_extension/hub/network_restrictions.rb @@ -0,0 +1,20 @@ +module NinoxeExtension::Hub + module NetworkRestrictions + extend ActiveSupport::Concern + + included do + include ObjectidRestrictions + + with_options if: :hub_restricted? do |g| + # HUB-3 + g.validates_format_of :objectid, :with => %r{^\w+:\w+:[\w]{1,3}$} + # HUB-4 + g.validates_format_of :name, :with => %r{^[\w]{1,75}$} + # HUB-5 + g.validates_format_of :registration_number, :with => %r{^[\d]{1,8}$} + g.validates_uniqueness_of :registration_number + end + end + end +end + diff --git a/lib/ninoxe_extension/hub/objectid_restrictions.rb b/lib/ninoxe_extension/hub/objectid_restrictions.rb new file mode 100644 index 000000000..675994359 --- /dev/null +++ b/lib/ninoxe_extension/hub/objectid_restrictions.rb @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +module NinoxeExtension::Hub::ObjectidRestrictions + extend ActiveSupport::Concern + + included do + # HUB 1 + validate :third_part_objectid_uniqueness + + def third_part_objectid + self.objectid.match(/:(\w+)$/)[1] + end + def third_part_objectid_uniqueness + return unless hub_restricted? + + return true unless third_part_objectid + likes = Chouette::Line.where( "objectid LIKE ?", "%:#{self.third_part_objectid}" ) + likes.size.zero? || ( likes.size==1 && likes.first.id==self.id) + end + + end +end + diff --git a/lib/ninoxe_extension/hub/route_restrictions.rb b/lib/ninoxe_extension/hub/route_restrictions.rb index c6c403796..6b996ec3d 100644 --- a/lib/ninoxe_extension/hub/route_restrictions.rb +++ b/lib/ninoxe_extension/hub/route_restrictions.rb @@ -1,25 +1,29 @@ # -*- coding: utf-8 -*- -module NinoxeExtension::Hub::RouteRestrictions +module NinoxeExtension::Hub + module RouteRestrictions extend ActiveSupport::Concern included do + include ObjectidRestrictions validate :max_instance_limitation, :wayback_code_limitation + # HUB-37 def wayback_code_limitation return unless hub_restricted? errors.add( :wayback_code, "déjà pris!") if line.routes.reject {|r| r.id==id}.map(&:wayback_code).include?( wayback_code) end + # HUB-37 def max_instance_limitation return unless hub_restricted? errors.add( :flash, "2 routes max") end + # HUB-38 with_options if: :hub_restricted? do |route| route.validates_format_of :objectid, :with => %r{^\w+:\w+:[\w]{1,8}$} - #admin.validates :password, length: { minimum: 10 } - #admin.validates :email, presence: true end end + end end diff --git a/lib/ninoxe_extension/hub/stop_area_restrictions.rb b/lib/ninoxe_extension/hub/stop_area_restrictions.rb new file mode 100644 index 000000000..f09510cc4 --- /dev/null +++ b/lib/ninoxe_extension/hub/stop_area_restrictions.rb @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +module NinoxeExtension::Hub + module StopAreaRestrictions + extend ActiveSupport::Concern + + included do + #include ObjectidRestrictions + def physical? + self.area_type=="BoardingPosition" || self.area_type=="Quay" + end + def commercial? + self.area_type=="CommercialStopPoint" + end + def self.physical_hub_restricted? + Proc.new { |s| s.hub_restricted? && s.commercial?} + end + def self.commercial_hub_restricted? + Proc.new { |s| s.hub_restricted? && s.physical?} + end + def self.commercial_and_physical_hub_restricted? + physical_hub_restricted? || commercial_hub_restricted? + end + + + with_options if: commercial_and_physical_hub_restricted? do |sa| + # HUB-23 + sa.validates_format_of :objectid, :with => %r{^\w+:\w+:[\w]{1,12}$} + sa.validates_format_of :name, :with => %r{^[\w]{1,75}$} + end + with_options if: commercial_hub_restricted? do |sa| + # HUB-24 + validates_format_of :nearest_topic_name, :with => %r{^[\w]{0,255}$} + end + + with_options if: physical_hub_restricted? do |sa| + # HUB-25 + sa.validates_format_of :nearest_topic_name, :with => %r{^[\w]{0,60}$} + # HUB-28 + sa.validates_presence_of :longitude + sa.validates_presence_of :latitude + # HUB-29 + sa.validates_format_of :city_name, :with => %r{^[\w]{1,80}$} + # HUB-30 + sa.validates_format_of :zip_code, :with => %r{^[\d]{5}$} + # HUB-31 + sa.validates_format_of :comment, :with => %r{^[\w]{0,255}$} + # HUB-32 + sa.validates_format_of :registration_number, :with => %r{^[\w]{1,8}$}, :allow_blank => true, :allow_nil => true + end + end + end +end + diff --git a/lib/ninoxe_extension/hub/time_table_restrictions.rb b/lib/ninoxe_extension/hub/time_table_restrictions.rb new file mode 100644 index 000000000..6f2984dda --- /dev/null +++ b/lib/ninoxe_extension/hub/time_table_restrictions.rb @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +module NinoxeExtension::Hub + module TimeTableRestrictions + extend ActiveSupport::Concern + + included do + include ObjectidRestrictions + + with_options if: :hub_restricted? do |jp| + # HUB-44 + jp.validates_format_of :objectid, :with => %r{^\w+:\w+:[\w]{1,6}$} + # HUB-45 + jp.validates_format_of :comment, :with => %r{^[\w]{0,75}$} + end + end + end +end + diff --git a/lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb b/lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb new file mode 100644 index 000000000..81a023dca --- /dev/null +++ b/lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +module NinoxeExtension::Hub + module VehicleJourneyRestrictions + extend ActiveSupport::Concern + + included do + include ObjectidRestrictions + + # HUB-42 + with_options if: :hub_restricted? do |jp| + jp.validates_format_of :objectid, :with => %r{^\w+:\w+:[\w]{1,8}$} + end + end + end +end + -- cgit v1.2.3 From a3635f558a832ad6adecb885c6fd1d3403cfa15a Mon Sep 17 00:00:00 2001 From: Marc Florisson Date: Tue, 3 Feb 2015 12:27:01 +0100 Subject: add stats for 2015 --- lib/tasks/stats.rake | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') diff --git a/lib/tasks/stats.rake b/lib/tasks/stats.rake index 4907bb4eb..4f2739664 100644 --- a/lib/tasks/stats.rake +++ b/lib/tasks/stats.rake @@ -19,6 +19,9 @@ namespace :stats do 1.upto(12) do |i| stats << class_for_stat.all.select {|o| o.created_at.month==i && o.created_at.year==2014}.count end + 1.upto(12) do |i| + stats << class_for_stat.all.select {|o| o.created_at.month==i && o.created_at.year==2015}.count + end s.puts stats.join(",") end end -- cgit v1.2.3 From b55347596bf7f385c577ce0e28baa755030c4887 Mon Sep 17 00:00:00 2001 From: Marc Florisson Date: Sat, 28 Feb 2015 15:12:33 +0100 Subject: add missing locale for hub constraints --- lib/ninoxe_extension/hub/route_restrictions.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/ninoxe_extension/hub/route_restrictions.rb b/lib/ninoxe_extension/hub/route_restrictions.rb index 6b996ec3d..a5f4c8019 100644 --- a/lib/ninoxe_extension/hub/route_restrictions.rb +++ b/lib/ninoxe_extension/hub/route_restrictions.rb @@ -10,13 +10,13 @@ module NinoxeExtension::Hub # HUB-37 def wayback_code_limitation return unless hub_restricted? - errors.add( :wayback_code, "déjà pris!") if line.routes.reject {|r| r.id==id}.map(&:wayback_code).include?( wayback_code) + errors.add( :wayback_code, I18n.t('hub.routes.wayback_code_exclusive')) if line.routes.reject {|r| r.id==id}.map(&:wayback_code).include?( wayback_code) end # HUB-37 def max_instance_limitation return unless hub_restricted? - errors.add( :flash, "2 routes max") + errors.add( :flash, I18n.t('hub.routes.max_by_line')) end # HUB-38 -- cgit v1.2.3