diff options
Diffstat (limited to 'lib/stif')
| -rw-r--r-- | lib/stif/codifligne_line_id.rb | 19 | ||||
| -rw-r--r-- | lib/stif/dashboard.rb | 6 | ||||
| -rw-r--r-- | lib/stif/my_workbench_scopes.rb | 3 | ||||
| -rw-r--r-- | lib/stif/netex_file.rb | 93 | ||||
| -rw-r--r-- | lib/stif/permission_translator.rb | 16 | ||||
| -rw-r--r-- | lib/stif/reflex_synchronization.rb | 1 |
6 files changed, 93 insertions, 45 deletions
diff --git a/lib/stif/codifligne_line_id.rb b/lib/stif/codifligne_line_id.rb new file mode 100644 index 000000000..8c1bcc54b --- /dev/null +++ b/lib/stif/codifligne_line_id.rb @@ -0,0 +1,19 @@ +module STIF + module CodifligneLineId extend self + + LINE_OBJECT_ID_SEPERATOR = ':' + + def lines_set_from_functional_scope(functional_scope) + Set.new( + functional_scope + .map{ |line| extract_codif_line_id line }) + end + + + private + + def extract_codif_line_id line_name + line_name.split(LINE_OBJECT_ID_SEPERATOR).last + end + end +end diff --git a/lib/stif/dashboard.rb b/lib/stif/dashboard.rb index b6b6b8284..46c635091 100644 --- a/lib/stif/dashboard.rb +++ b/lib/stif/dashboard.rb @@ -4,12 +4,16 @@ module Stif @workbench ||= current_organisation.workbenches.find_by(name: "Gestion de l'offre") end + def workgroup + workbench.workgroup + end + def referentials @referentials ||= self.workbench.all_referentials end def calendars - @calendars ||= Calendar.where('organisation_id = ? OR shared = ?', current_organisation.id, true) + @calendars ||= Calendar.where('(organisation_id = ? OR shared = ?) AND workgroup_id = ?', current_organisation.id, true, workgroup.id) end end end diff --git a/lib/stif/my_workbench_scopes.rb b/lib/stif/my_workbench_scopes.rb index 89c4e659c..04bc93089 100644 --- a/lib/stif/my_workbench_scopes.rb +++ b/lib/stif/my_workbench_scopes.rb @@ -2,12 +2,13 @@ module Stif class MyWorkbenchScopes attr_accessor :workbench + def initialize(workbench) @workbench = workbench end def line_scope(initial_scope) - ids = self.parse_functional_scope + ids = parse_functional_scope ids ? initial_scope.where(objectid: ids) : initial_scope end diff --git a/lib/stif/netex_file.rb b/lib/stif/netex_file.rb index a977c1ad3..db0801bbe 100644 --- a/lib/stif/netex_file.rb +++ b/lib/stif/netex_file.rb @@ -2,8 +2,9 @@ module STIF class NetexFile CALENDAR_FILE_NAME = 'calendriers.xml' - LINE_FILE_FORMAT = /^offre_.*\.xml$/ - XML_NAME_SPACE = "http://www.netex.org.uk/netex" + LINE_FILE_FORMAT = %r{\A offre_ (?<line_object_id> .*?) _ .* \. xml \z}x + XML_NAME_SPACE = "http://www.netex.org.uk/netex" + def initialize(file_name) @file_name = file_name @@ -13,58 +14,72 @@ module STIF frames = Hash.new { |h,k| h[k] = NetexFile::Frame.new(k) } Zip::File.open(@file_name) do |zipfile| zipfile.each do |entry| - next unless entry.ftype == :file - - entry_dir_name, entry_file_name = File.split(entry.name) - case entry_file_name - when CALENDAR_FILE_NAME - entry.get_input_stream do |stream| - frames[entry_dir_name].parse_calendars(stream.read) - end - when LINE_FILE_FORMAT - frames[entry_dir_name].add_offer_file(entry_file_name) - end + add_frame(to_frames: frames, from_entry: entry) if entry.ftype == :file end end frames.values end - end - class NetexFile::Frame + private - attr_accessor :name + def add_frame(to_frames:, from_entry:) + entry_dir_name, entry_file_name = File.split(from_entry.name) - def initialize(name) - @name = name - end + if CALENDAR_FILE_NAME === entry_file_name + from_entry.get_input_stream do |stream| + to_frames[entry_dir_name].parse_calendars(stream.read) + end + return + end - def parse_calendars(calendars) - # <netex:ValidBetween> - # <netex:FromDate>2017-03-01</netex:FromDate> - # <netex:ToDate>2017-03-31</netex:ToDate> - # </netex:ValidBetween> - xml = Nokogiri::XML(calendars) - xml.xpath("//netex:ValidBetween", "netex" => NetexFile::XML_NAME_SPACE).each do |valid_between| - from_date = valid_between.xpath("netex:FromDate").try :text - to_date = valid_between.xpath("netex:ToDate").try :text - periods << Range.new(Date.parse(from_date), Date.parse(to_date)) + line_file_match = LINE_FILE_FORMAT.match( entry_file_name ) + if line_file_match + to_frames[entry_dir_name].add_offer_file( line_file_match['line_object_id']) end end - def add_offer_file(file_name) - if file_name =~ /^offre_([^_]*)_/ - line_refs << $1 + + class Frame + + class << self + def get_short_id file_name + base_name = File.basename(file_name) + STIF::NetexFile::LINE_FILE_FORMAT.match(base_name).try(:[], 'line_object_id') + end end - end - def periods - @periods ||= [] - end + attr_accessor :name - def line_refs - @line_refs ||= [] - end + def initialize(name) + @name = name + end + + def parse_calendars(calendars) + # <netex:ValidBetween> + # <netex:FromDate>2017-03-01</netex:FromDate> + # <netex:ToDate>2017-03-31</netex:ToDate> + # </netex:ValidBetween> + xml = Nokogiri::XML(calendars) + xml.xpath("//netex:ValidBetween", "netex" => NetexFile::XML_NAME_SPACE).each do |valid_between| + from_date = valid_between.xpath("netex:FromDate").try :text + to_date = valid_between.xpath("netex:ToDate").try :text + periods << Range.new(Date.parse(from_date), Date.parse(to_date)) + end + end + + def add_offer_file(line_object_id) + line_refs << line_object_id + end + def periods + @periods ||= [] + end + + def line_refs + @line_refs ||= [] + end + + end end end diff --git a/lib/stif/permission_translator.rb b/lib/stif/permission_translator.rb index 2d267bc7b..9e0feb9b8 100644 --- a/lib/stif/permission_translator.rb +++ b/lib/stif/permission_translator.rb @@ -1,11 +1,11 @@ module Stif module PermissionTranslator extend self - def translate(sso_extra_permissions) - sso_extra_permissions - .sort + def translate(sso_extra_permissions, organisation=nil) + permissions = sso_extra_permissions.sort .flat_map(&method(:extra_permission_translation)) - .uniq + permissions += extra_organisation_permissions(organisation) + permissions.uniq end private @@ -21,6 +21,7 @@ module Stif calendars footnotes imports + merges journey_patterns referentials routes @@ -49,5 +50,12 @@ module Stif "boiv:edit-offer" => all_destructive_permissions + %w{sessions.create}, } end + + def extra_organisation_permissions organisation + if organisation&.name&.downcase == "stif" + return %w{calendars.share stop_area_referentials.synchronize line_referentials.synchronize} + end + [] + end end end diff --git a/lib/stif/reflex_synchronization.rb b/lib/stif/reflex_synchronization.rb index 39a92bd1f..7570e4c49 100644 --- a/lib/stif/reflex_synchronization.rb +++ b/lib/stif/reflex_synchronization.rb @@ -151,6 +151,7 @@ module Stif def create_or_update_stop_area entry stop = Chouette::StopArea.find_or_create_by(objectid: entry['id'], stop_area_referential: self.defaut_referential ) + stop.kind = :commercial stop.deleted_at = nil { :comment => 'Description', |
