ooor 2.2.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d891fa43f53c6874d616400d37c2805cea7ddc1a
4
- data.tar.gz: 1d8d0f527525a111762c53328307bc5a340dabe4
3
+ metadata.gz: 22e71fb9d4c4cea9db686436090802d441be0b84
4
+ data.tar.gz: 60dd0f5380c63fdec5184d8befe4538bb294855b
5
5
  SHA512:
6
- metadata.gz: bf0f99297dfdc754b059be24b48c2292e7520b43c789c97ec4cf4415826e3a56de0c06ef54777c03c1b8eb8422a060bb3134f96fc2bee781ddd1caf9995b78d3
7
- data.tar.gz: cc6e0c73cf713dc4ea8d01c6abfaf1c07168d6ec022ffe851443c079c183b1f72a1653e70ebc5197adaa52a3ea04b8dc33811d709abd176ace16abe5b10224f4
6
+ metadata.gz: ee6dc17416c26483fdb596efd393127826d282be9ea9587c479bb57c8604a2f4ed394692991fc0265e128c0cd9e83638f599c4c4848fc0d83bae63d965df067b
7
+ data.tar.gz: 8a316e8d2c3f78c84d470561cd6861596eebd9a8c0b8fe22dd9c01103367aa330fa9a8e314262695e2a4f89aa266cc2f96af683278d516d62bb2492b96133b46
data/README.md CHANGED
@@ -18,7 +18,7 @@ Related projects - a full web stack!
18
18
  ------------------------------------
19
19
 
20
20
  * [Ooorest](http://github.com/akretion/ooorest), Ooor is the **Model** layer of **MVC**. Ooorest is the **Controller** layer, enforcing a clean Railish **REST API** and offering handy **helper** to use OpenERP in your Rails application.
21
- * [Aktooor](http://github.com/akretion/aktooor), Aktoor is the missing **View** layer of **MVC**. It's based on [SimpleForm](https://github.com/plataformatec/simple_form), that is a clean minimalist framework that extend Rails form framework over [Twitter Bootstrap](http://getbootstrap.com)
21
+ * [Aktooor](http://github.com/akretion/aktooor), Aktooor is the missing **View** layer of **MVC**. It's based on [SimpleForm](https://github.com/plataformatec/simple_form), that is a clean minimalist framework that extend Rails form framework over [Twitter Bootstrap](http://getbootstrap.com)
22
22
  * [Erpify](http://github.com/akretion/erpify), Erpify is OpenERP inside the Liquid non evaling language, that is the templating language of Shopify or LocomotiveCMS for instance.
23
23
  * [Locomotive-erpify](http://github.com/akretion/locomtive-erpify), Erpify for LocomotiveCMS, both the engine and the Wagon local editor
24
24
  * [Solarize](http://github.com/akretion/solarize), pulling data from OpenERP relational database may not scale to your need. No problem with Solarize: you can index your OpenERP data with the [Solerp](http://github.com/akretion/solerp) OpenERP module, then search it using SolR API and even load it from SolR without even hitting OpenERP!
@@ -29,7 +29,7 @@ module Ooor
29
29
  fields[k]["type"] != "binary" && (options[:include_functions] || !fields[k]["function"])
30
30
  end
31
31
  end
32
-
32
+
33
33
  private
34
34
 
35
35
  def generate_accessors #TODO we should cache this is a module cached like the template, or eventually generate source code or both
@@ -126,7 +126,7 @@ module Ooor
126
126
  end
127
127
 
128
128
  def get_attribute(meth, *args)
129
- lazy_load(meth, *args) if @lazy && @attributes["id"]
129
+ lazy_load(meth, *args) if @lazy && @attributes["id"] && !@attributes.has_key?(meth)
130
130
  if @attributes.has_key?(meth)
131
131
  @attributes[meth]
132
132
  elsif @attributes["id"] # if field is computed for instance
@@ -1,10 +1,8 @@
1
1
  module Ooor
2
2
  module Locale
3
- # OpenERP requirs a locale+zone mapping while Rails uses locale only, so mapping is likely to be required
3
+ # Odoo requires a locale+zone mapping while Rails uses locale only, so mapping is likely to be required
4
4
  def self.to_erp_locale(locale)
5
- if Ooor.default_config[:locale_mapping]
6
- mapping = Ooor.default_config[:locale_mapping]
7
- else
5
+ unless mapping = Ooor.default_config[:locale_mapping]
8
6
  mapping = {'fr' => 'fr_FR', 'en' => 'en_US'}
9
7
  end
10
8
  (mapping[locale.to_s] || locale.to_s).gsub('-', '_')
@@ -11,7 +11,7 @@ module Ooor
11
11
  @plural = klass.openerp_model # OpenERP doesn't enforce plural / singular conventions sadly...
12
12
  @element = klass.openerp_model
13
13
  @human = klass.description || klass.openerp_model
14
- @param_key = klass.openerp_model.gsub('.', '_')
14
+ @param_key = klass.openerp_model.gsub('.', '_')
15
15
  @i18n_key = klass.openerp_model
16
16
  @route_key = klass.openerp_model.gsub('.', '-')
17
17
  @singular_route_key = klass.openerp_model.gsub('.', '-')
@@ -58,8 +58,14 @@ module Ooor
58
58
 
59
59
  def find_by_permalink(param, options={})
60
60
  # NOTE in v8, see if we can use PageConverter here https://github.com/akretion/openerp-addons/blob/trunk-website-al/website/models/ir_http.py#L138
61
- param = param.to_i unless param.to_i == 0
62
- options.merge!(domain: {param_field => param})
61
+ param.gsub!('-', ' ')
62
+ if param.split(' ').last.to_i != 0
63
+ options.merge!(domain: {:id => param.split(' ').last.to_i})
64
+ elsif param.to_i == 0
65
+ options.merge!(domain: [param_field, 'ilike', param])
66
+ else
67
+ options.merge!(domain: {:id => param.to_i})
68
+ end
63
69
  find(:first, options)
64
70
  end
65
71
 
@@ -1,16 +1,17 @@
1
1
  require 'active_support/concern'
2
2
 
3
3
  module Ooor
4
- class Rack
5
4
 
6
5
  DEFAULT_OOOR_SESSION_CONFIG_MAPPER = Proc.new do |env|
7
6
  Ooor.logger.debug "\n\nWARNING: using DEFAULT_OOOR_SESSION_CONFIG_MAPPER, you should probably define your own instead!
8
7
  You can define an Ooor::Rack.ooor_session_config_mapper block that will be evaled
9
8
  in the context of the rack middleware call after user is authenticated using Warden.
10
9
  Use it to map a Warden authentication to the OpenERP authentication you want.\n"""
11
- Ooor.default_config
10
+ {}
12
11
  end
13
12
 
13
+ DEFAULT_OOOR_PUBLIC_SESSION_CONFIG_MAPPER = DEFAULT_OOOR_SESSION_CONFIG_MAPPER
14
+
14
15
  module RackBehaviour
15
16
  extend ActiveSupport::Concern
16
17
  module ClassMethods
@@ -18,10 +19,16 @@ module Ooor
18
19
  @ooor_session_config_mapper = block if block
19
20
  @ooor_session_config_mapper || DEFAULT_OOOR_SESSION_CONFIG_MAPPER
20
21
  end
22
+
23
+ def ooor_public_session_config_mapper(&block)
24
+ @ooor_public_session_config_mapper = block if block
25
+ @ooor_public_session_config_mapper || DEFAULT_OOOR_PUBLIC_SESSION_CONFIG_MAPPER
26
+ end
21
27
  end
22
28
 
23
29
  def set_ooor!(env)
24
30
  ooor_session = self.get_ooor_session(env)
31
+ ooor_public_session = self.get_ooor_public_session(env)
25
32
  if defined?(I18n) && I18n.locale
26
33
  lang = Ooor::Locale.to_erp_locale(I18n.locale)
27
34
  elsif http_lang = env["HTTP_ACCEPT_LANGUAGE"]
@@ -30,16 +37,29 @@ module Ooor
30
37
  lang = ooor_session.config['lang'] || 'en_US'
31
38
  end
32
39
  context = {'lang' => lang} #TODO also deal with timezone
33
- env['ooor'] = {'context' => context, 'ooor_session'=> ooor_session}
40
+ env['ooor'] = {'context' => context, 'ooor_session'=> ooor_session, 'ooor_public_session' => ooor_public_session}
41
+ end
42
+
43
+ def session_key
44
+ if defined?(Rails)
45
+ Rails.application.config.session_options[:key]
46
+ else
47
+ 'rack.session'
48
+ end
49
+ end
50
+
51
+ def get_ooor_public_session(env)
52
+ config = Ooor::Rack.ooor_public_session_config_mapper.call(env)
53
+ Ooor.session_handler.retrieve_session(config)
34
54
  end
35
55
 
36
56
  def get_ooor_session(env)
37
57
  cookies_hash = env['rack.request.cookie_hash'] || ::Rack::Request.new(env).cookies
38
- session = Ooor.session_handler.sessions[cookies_hash['ooor_session_id']]
58
+ session = Ooor.session_handler.sessions[cookies_hash[self.session_key()]]
39
59
  session ||= Ooor.session_handler.sessions[cookies_hash['session_id']]
40
60
  unless session # session could have been used by an other worker, try getting it
41
- config = Ooor::Rack.ooor_session_config_mapper.call(env)
42
- spec = config[:session_sharing] ? cookies_hash['session_id'] : cookies_hash['ooor_session_id']
61
+ config = Ooor.default_config.merge(Ooor::Rack.ooor_session_config_mapper.call(env))
62
+ spec = config[:session_sharing] ? cookies_hash['session_id'] : cookies_hash[self.session_key()]
43
63
  web_session = Ooor.session_handler.get_web_session(spec) if spec # created by some other worker?
44
64
  unless web_session
45
65
  if config[:session_sharing]
@@ -51,10 +71,11 @@ module Ooor
51
71
  end
52
72
  end
53
73
  session = Ooor.session_handler.retrieve_session(config, spec, web_session)
54
- end
74
+ session.config[:params] = {email: env['warden'].try(:user).try(:email)}
75
+ end
55
76
  session
56
77
  end
57
-
78
+
58
79
  def set_ooor_session!(env, status, headers, body)
59
80
  case headers["Set-Cookie"]
60
81
  when nil, ''
@@ -62,19 +83,15 @@ module Ooor
62
83
  when Array
63
84
  headers["Set-Cookie"] = headers["Set-Cookie"].join("\n")
64
85
  end
65
-
86
+
66
87
  ooor_session = env['ooor']['ooor_session']
67
88
  if ooor_session.config[:session_sharing]
68
89
  share_openerp_session!(headers, ooor_session)
69
- else # NOTE: we don't put that in a Rails session because we want to remain server agnostic
70
- headers["Set-Cookie"] = [headers["Set-Cookie"],
71
- "ooor_session_id=#{ooor_session.id}; Path=/",
72
- ].join("\n")
73
90
  end
74
91
  response = ::Rack::Response.new body, status, headers
75
92
  response.finish
76
93
  end
77
-
94
+
78
95
  def share_openerp_session!(headers, ooor_session)
79
96
  if ooor_session.config[:username] == 'admin'
80
97
  if ooor_session.config[:force_session_sharing]
@@ -98,17 +115,18 @@ module Ooor
98
115
 
99
116
  end
100
117
 
101
- include RackBehaviour
118
+ class Rack
119
+ include RackBehaviour
102
120
 
103
- def initialize(app=nil)
104
- @app=app
105
- end
121
+ def initialize(app=nil)
122
+ @app=app
123
+ end
106
124
 
107
- def call(env)
108
- set_ooor!(env)
109
- status, headers, body = @app.call(env)
110
- set_ooor_session!(env, status, headers, body)
125
+ def call(env)
126
+ set_ooor!(env)
127
+ status, headers, body = @app.call(env)
128
+ set_ooor_session!(env, status, headers, body)
129
+ end
111
130
  end
112
131
 
113
- end
114
132
  end
@@ -29,7 +29,7 @@ module Ooor
29
29
  class CommonService < Service
30
30
  define_service(:common, %w[ir_get ir_set ir_del about ooor_alias_login logout timezone_get get_available_updates get_migration_scripts get_server_environment login_message check_connectivity about get_stats list_http_services version authenticate get_available_updates set_loglevel get_os_time get_sqlcount])
31
31
 
32
- def login(db, username, password)
32
+ def login(db, username, password, kw={})
33
33
  @session.logger.debug "OOOR login - db: #{db}, username: #{username}"
34
34
 
35
35
  if @session.config[:force_xml_rpc]
@@ -39,7 +39,7 @@ module Ooor
39
39
  response = conn.post do |req|
40
40
  req.url '/web/session/authenticate'
41
41
  req.headers['Content-Type'] = 'application/json'
42
- req.body = {method: 'call', params: { db: db, login: username, password: password}}.to_json
42
+ req.body = {method: 'call', params: {db: db, login: username, password: password, base_location: kw}}.to_json
43
43
  end
44
44
  @session.web_session[:cookie] = response.headers["set-cookie"]
45
45
  json_response = JSON.parse(response.body)
@@ -52,8 +52,10 @@ module Ooor
52
52
  end
53
53
 
54
54
  @session.web_session[:session_id] = json_response['result']['session_id']
55
- user_id = json_response['result']['uid']
55
+ user_id = json_response['result'].delete('uid')
56
56
  @session.config[:user_id] = user_id
57
+ @session.web_session.merge!(json_response['result'].delete('user_context'))
58
+ @session.config.merge!(json_response['result'])
57
59
  Ooor.session_handler.register_session(@session)
58
60
  user_id
59
61
  else
@@ -96,7 +98,7 @@ module Ooor
96
98
 
97
99
  def object_service(service, obj, method, *args)
98
100
  unless @session.config[:user_id]
99
- @session.common.login(@session.config[:database], @session.config[:username], @session.config[:password])
101
+ @session.common.login(@session.config[:database], @session.config[:username], @session.config[:password], @session.config[:params])
100
102
  end
101
103
  args = inject_session_context(service, method, *args)
102
104
  uid = @session.config[:user_id]
@@ -1,6 +1,6 @@
1
1
  module Ooor
2
2
  MAJOR = 2
3
- MINOR = 2
3
+ MINOR = 4
4
4
  TINY = 0
5
5
  PRE = nil
6
6
 
metadata CHANGED
@@ -1,46 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ooor
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raphael Valyi - www.akretion.com
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2013-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activemodel
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
18
  version: 3.2.0
20
- type: :runtime
19
+ name: activemodel
21
20
  prerelease: false
21
+ type: :runtime
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: faraday
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - ">="
32
31
  - !ruby/object:Gem::Version
33
32
  version: '0'
34
- type: :runtime
33
+ name: faraday
35
34
  prerelease: false
35
+ type: :runtime
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: OOOR exposes OpenERP business object proxies to your Ruby (Rails or not)
42
- application. It extends the standard ActiveResource API. Running on JRuby, OOOR
43
- also offers a convenient bridge between OpenERP and the Java eco-system
41
+ description: OOOR exposes OpenERP business object proxies to your Ruby (Rails or not) application. It extends the standard ActiveResource API. Running on JRuby, OOOR also offers a convenient bridge between OpenERP and the Java eco-system
44
42
  email: raphael.valyi@akretion.com
45
43
  executables:
46
44
  - ooor
@@ -88,7 +86,7 @@ files:
88
86
  homepage: http://github.com/akretion/ooor
89
87
  licenses: []
90
88
  metadata: {}
91
- post_install_message:
89
+ post_install_message:
92
90
  rdoc_options: []
93
91
  require_paths:
94
92
  - lib
@@ -103,11 +101,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
101
  - !ruby/object:Gem::Version
104
102
  version: '0'
105
103
  requirements: []
106
- rubyforge_project:
107
- rubygems_version: 2.4.5.1
108
- signing_key:
104
+ rubyforge_project:
105
+ rubygems_version: 2.6.4
106
+ signing_key:
109
107
  specification_version: 4
110
108
  summary: OOOR - OpenObject On Ruby
111
109
  test_files:
112
- - spec/helpers/test_helper.rb
113
110
  - spec/ooor_spec.rb
111
+ - spec/helpers/test_helper.rb