From 0f59b9c1d0133393f68194a366aafc27ca23392b Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Tue, 23 Jan 2018 22:46:16 -0800 Subject: First draft for including calendars into workgroup for having appropriate scoping --- lib/stif/dashboard.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/stif/dashboard.rb b/lib/stif/dashboard.rb index b6b6b8284..7dd83efbc 100644 --- a/lib/stif/dashboard.rb +++ b/lib/stif/dashboard.rb @@ -9,7 +9,7 @@ module Stif end def calendars - @calendars ||= Calendar.where('organisation_id = ? OR shared = ?', current_organisation.id, true) + @calendars ||= Calendar.where('workgroup_id = ? OR shared = ?', @workbench.workgroup_id, true) end end end -- cgit v1.2.3 From f32d869cc3f34a939764cc3fa4d612a5d6544d08 Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Wed, 24 Jan 2018 19:55:56 -0800 Subject: update calendar build_links for table builder --- lib/stif/dashboard.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/stif/dashboard.rb b/lib/stif/dashboard.rb index 7dd83efbc..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('workgroup_id = ? OR shared = ?', @workbench.workgroup_id, true) + @calendars ||= Calendar.where('(organisation_id = ? OR shared = ?) AND workgroup_id = ?', current_organisation.id, true, workgroup.id) end end end -- cgit v1.2.3 From fe7915ffac359db41c7737a3847f31a728f502e6 Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 31 Jan 2018 11:39:39 +0100 Subject: Refs #5683 @2H; Fix specs and refactor action_links Note: Did not fix the missing workgroup in the calendar mailer --- lib/af83/decorator.rb | 63 ++++++++++++++++++-------------- lib/af83/decorator/enhanced_decorator.rb | 22 +++++++++-- lib/af83/decorator/link.rb | 3 +- 3 files changed, 56 insertions(+), 32 deletions(-) (limited to 'lib') diff --git a/lib/af83/decorator.rb b/lib/af83/decorator.rb index f990555fe..71cf1170d 100644 --- a/lib/af83/decorator.rb +++ b/lib/af83/decorator.rb @@ -2,40 +2,49 @@ class AF83::Decorator < ModelDecorator include AF83::Decorator::EnhancedDecorator extend AF83::Decorator::EnhancedDecorator::ClassMethods - def self.decorates klass - instance_decorator.decorates klass - end + class << self + def decorates klass + instance_decorator.decorates klass + end - def self.instance_decorator - @instance_decorator ||= begin - klass = Class.new(AF83::Decorator::InstanceDecorator) - klass.delegate_all - klass + def instance_decorator + @instance_decorator ||= begin + klass = Class.new(AF83::Decorator::InstanceDecorator) + klass.delegate_all + klass + end end - end - def self.with_instance_decorator - @_with_instance_decorator = true - yield instance_decorator - @_with_instance_decorator = false - end + def with_instance_decorator + @_with_instance_decorator = true + yield instance_decorator + @_with_instance_decorator = false + end + + def decorate object, options = {} + if object.is_a?(ActiveRecord::Base) + return instance_decorator.decorate object, options + else + self.new object, options.update(with: instance_decorator) + end + end - def self.decorate object, options = {} - if object.is_a?(ActiveRecord::Base) - return instance_decorator.decorate object, options - else - self.new object, options.update(with: instance_decorator) + def define_instance_method method_name, &block + instance_decorator.send(:define_method, method_name, &block) end - end - def self.define_instance_method method_name, &block - instance_decorator.send(:define_method, method_name, &block) - end + # Defines a class method on the decorated object's class. These + # can be called like `object.class.my_method`. + def define_instance_class_method method_name, &block + instance_decorator.send(:define_singleton_method, method_name, &block) + end + + def set_scope_with_instance_decorator value=nil, &block + set_scope_without_instance_decorator value, &block + instance_decorator.set_scope value, &block + end - # Defines a class method on the decorated object's class. These - # can be called like `object.class.my_method`. - def self.define_instance_class_method method_name, &block - instance_decorator.send(:define_singleton_method, method_name, &block) + alias_method_chain :set_scope, :instance_decorator end class ActionLinks diff --git a/lib/af83/decorator/enhanced_decorator.rb b/lib/af83/decorator/enhanced_decorator.rb index 904d1b2da..fff8bb8b3 100644 --- a/lib/af83/decorator/enhanced_decorator.rb +++ b/lib/af83/decorator/enhanced_decorator.rb @@ -25,7 +25,7 @@ module AF83::Decorator::EnhancedDecorator policy: :create, before_block: -> (l){ l.content { h.t('actions.add') } - l.href { [:new, object.klass.name.underscore.singularize] } + l.href { [:new, scope, object.klass.model_name.singular] } } } action_link opts.update(args), &block @@ -37,7 +37,7 @@ module AF83::Decorator::EnhancedDecorator primary: :index, before_block: -> (l){ l.content { h.t('actions.show') } - l.href { [object] } + l.href { [scope, object] } } } action_link opts.update(args), &block @@ -49,7 +49,7 @@ module AF83::Decorator::EnhancedDecorator policy: :edit, before_block: -> (l){ l.content { h.t('actions.edit') } - l.href { [:edit, object] } + l.href { [:edit, scope, object] } } } action_link opts.update(args), &block @@ -62,7 +62,7 @@ module AF83::Decorator::EnhancedDecorator secondary: :show, before_block: -> (l){ l.content { h.destroy_link_content } - l.href { [object] } + l.href { [scope, object] } l.method :delete l.data {{ confirm: h.t('actions.destroy_confirm') }} } @@ -70,6 +70,14 @@ module AF83::Decorator::EnhancedDecorator action_link opts.update(args), &block end + def set_scope value=nil, &block + @scope = value || block + end + + def scope + @scope + end + def t key eval "-> (l){ h.t('#{key}') }" end @@ -142,4 +150,10 @@ module AF83::Decorator::EnhancedDecorator def check_feature feature h.has_feature? feature end + + def scope + scope = self.class.scope + scope = instance_exec &scope if scope.is_a? Proc + scope + end end diff --git a/lib/af83/decorator/link.rb b/lib/af83/decorator/link.rb index 7d2896e6a..de7106740 100644 --- a/lib/af83/decorator/link.rb +++ b/lib/af83/decorator/link.rb @@ -30,7 +30,8 @@ class AF83::Decorator::Link @options[name] = block elsif args.size == 0 out = @options[name] - out = context.instance_exec(self, &out) if out.is_a?(Proc) + out = context.instance_exec(self, &out) if out.is_a?(Proc) + out = out.flatten.compact if name.to_s == "href" && out.is_a?(Array) out else # we can use l.foo("bar") or l.foo = "bar" -- cgit v1.2.3 From 32bb2b43d463a071164a8e87a3e995f6ddceb17e Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 31 Jan 2018 14:34:48 +0100 Subject: Fix Reflex import --- lib/stif/reflex_synchronization.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') 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', -- cgit v1.2.3 From 38cadb07b47648c3d9ea2424a4b62229d0f468d3 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Thu, 1 Feb 2018 11:02:46 +0100 Subject: Add env variable to disable ci:jest if needed. Refs #5802 --- lib/tasks/ci.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index 3e73b7a3b..82619d04b 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -38,7 +38,7 @@ namespace :ci do end task :jest => "ci:assets" do - sh "node_modules/.bin/jest" + sh "node_modules/.bin/jest" unless ["CHOUETTE_JEST_DISABLED"] end desc "Deploy after CI" -- cgit v1.2.3 From 387450bd2a929d4a8ae6cc77182859f8c8587786 Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Thu, 1 Feb 2018 11:31:56 +0100 Subject: Fix yarn installation with no production for ci and force yarn install before jest launch du to webpacker bug --- lib/tasks/ci.rake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index 82619d04b..13d7b8d73 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -3,7 +3,7 @@ namespace :ci do task :setup do cp "config/database/jenkins.yml", "config/database.yml" sh "RAILS_ENV=test rake db:drop db:create db:migrate" - sh "yarn --production --no-progress install" + sh "yarn --no-progress install" end def git_branch @@ -38,6 +38,7 @@ namespace :ci do end task :jest => "ci:assets" do + sh "yarn --no-progress install" # Hack to force install jest after webpack sh "node_modules/.bin/jest" unless ["CHOUETTE_JEST_DISABLED"] end -- cgit v1.2.3