diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/link.rb | 6 | ||||
| -rw-r--r-- | lib/stif/codifligne_line_id.rb | 19 | ||||
| -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 | 15 |
5 files changed, 90 insertions, 46 deletions
diff --git a/lib/link.rb b/lib/link.rb index 7683a808f..33995c2f7 100644 --- a/lib/link.rb +++ b/lib/link.rb @@ -1,10 +1,12 @@ class Link - attr_reader :content, :href, :method, :data + attr_reader :content, :href, :method, :data, :extra_class, :disabled - def initialize(content: nil, href:, method: nil, data: nil) + def initialize(content: nil, href:, method: nil, data: nil, extra_class: nil, disabled: false) @content = content @href = href @method = method @data = data + @extra_class = extra_class + @disabled = disabled end end 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/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..4acf42884 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 @@ -49,5 +49,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 |
