bbmb 2.1.3 → 2.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -3
  3. data/Gemfile +2 -0
  4. data/History.txt +11 -8
  5. data/Rakefile +1 -1
  6. data/bbmb.gemspec +3 -3
  7. data/lib/bbmb.rb +1 -1
  8. data/lib/bbmb/config.rb +6 -2
  9. data/lib/bbmb/html/state/change_password.rb +3 -3
  10. data/lib/bbmb/html/state/current_order.rb +1 -1
  11. data/lib/bbmb/html/state/customer.rb +6 -6
  12. data/lib/bbmb/html/state/customers.rb +2 -2
  13. data/lib/bbmb/html/state/global.rb +4 -2
  14. data/lib/bbmb/html/state/init.rb +1 -0
  15. data/lib/bbmb/html/state/login.rb +5 -1
  16. data/lib/bbmb/html/state/viral/admin.rb +2 -1
  17. data/lib/bbmb/html/state/viral/customer.rb +4 -3
  18. data/lib/bbmb/html/util/known_user.rb +42 -10
  19. data/lib/bbmb/html/util/session.rb +32 -7
  20. data/lib/bbmb/html/util/validator.rb +5 -5
  21. data/lib/bbmb/html/view/customers.rb +7 -22
  22. data/lib/bbmb/html/view/head.rb +1 -1
  23. data/lib/bbmb/html/view/navigation.rb +1 -0
  24. data/lib/bbmb/model/customer.rb +19 -6
  25. data/lib/bbmb/model/order.rb +8 -5
  26. data/lib/bbmb/model/product.rb +14 -45
  27. data/lib/bbmb/persistence/odba.rb +4 -4
  28. data/lib/bbmb/util/invoicer.rb +1 -0
  29. data/lib/bbmb/util/mail.rb +1 -2
  30. data/lib/bbmb/util/polling_manager.rb +11 -6
  31. data/lib/bbmb/util/server.rb +122 -68
  32. data/lib/bbmb/util/transfer_dat.rb +1 -1
  33. data/lib/bbmb/util/updater.rb +3 -3
  34. data/lib/bbmb/version.rb +1 -1
  35. data/test/html/state/test_customers.rb +1 -2
  36. data/test/model/test_customer.rb +1 -1
  37. data/test/model/test_order.rb +2 -2
  38. data/test/model/test_product.rb +11 -27
  39. data/test/model/test_promotion.rb +3 -3
  40. data/test/test_bbmb.rb +0 -1
  41. data/test/util/test_invoicer.rb +8 -8
  42. data/test/util/test_polling_manager.rb +12 -17
  43. data/test/util/test_server.rb +2 -6
  44. data/test/util/test_transfer_dat.rb +0 -3
  45. metadata +5 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce9a5032fdcc3373fb7c9e71aad87962a8bcf544
4
- data.tar.gz: e1e8a51f597e798860dbdcc7e72ef05f44a74e17
3
+ metadata.gz: e3bf4ee6e274ed39fab6f5ba33c8ea2de97fb4ad
4
+ data.tar.gz: fc49c06f72935b949ddb983497337c97730e582f
5
5
  SHA512:
6
- metadata.gz: bcb5347927b02ea0c2c8a2cbc8a244cc0517f0c3630478feaa5469fdb11e35ae764684725543666d2fb4f4d78c8a6541337918e0dda88bc2bfc3aad91a4c58e7
7
- data.tar.gz: 902fb4f55adafccc2d580428cbd7e4236c13d92a1287848b6250e783a71100f058a83a41723ce1286d096c5d6720c7e0d3d7fe4330bc63df7bd28d43ead9d7f3
6
+ metadata.gz: 142d5480d2bbba2aad68dade8ee5ad11d9075d2e4de140d2d282bd315ed8d777d6edef257c5ac28bd787d4ae55f1532dad94adcdad32a28c22ba4234df55354a
7
+ data.tar.gz: fb162c84adfdb3ef9fc0d3b942a531b216b56dfaf662e07f1a90a7cbd817e2b706f0fce15e9682a125653f366b6068df48048c35a0f740d5bd69f0fb63a84bcb
@@ -8,10 +8,8 @@ sudo: false
8
8
  before_install:
9
9
  - gem --version
10
10
 
11
- script: bundle exec rake test
12
-
13
11
  rvm:
14
- - 2.2.3
12
+ - 2.4.0
15
13
  - 2.3.1
16
14
  - ruby-head
17
15
 
data/Gemfile CHANGED
@@ -1,5 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
+ gem 'sbsm', :path => '../sbsm'
4
+ gem 'ydim', :path => '../ydim'
3
5
 
4
6
  group :debugger do
5
7
  if RUBY_VERSION.match(/^1/)
@@ -1,18 +1,21 @@
1
- === 2.1.3 / 08.09.2016
1
+ === 2.1.4 / 15.05.2017
2
2
 
3
- * Improve mutex usage on model
3
+ * Admin users create new customer if it does not exist with the given customerid
4
+ * Fixed set new password for admin users
5
+ * Fixed importer
6
+ * Ported to SBSM with rack (Using SBSM.info/debug for logging)
4
7
 
5
- === 2.1.2 / 07.09.2016
8
+ === 2.1.3 / 09.09.2016
6
9
 
7
- * Prevent mail error by no price product
10
+ * minor improvements
8
11
 
9
- === 2.1.1 / 02.09.2016
12
+ === 2.1.2 / 07.09.2016
10
13
 
11
- * Fix conversion error for backup_dir at PopMission
14
+ * minor improvements
12
15
 
13
- === 2.1.0 / 19.08.2016
16
+ === 2.1.1 / 02.09.2016
14
17
 
15
- * Add ProductInfo#to_product utility method
18
+ * minor improvements
16
19
 
17
20
  === 2.0.9 / 20.07.2016
18
21
 
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ require "bundler/gem_tasks"
7
7
  require 'rspec/core/rake_task'
8
8
  require 'bbmb/version'
9
9
 
10
- task :default => :test
10
+ task :default => [:clobber, :test, :gem]
11
11
 
12
12
  # dependencies are now declared in bbmb.gemspec
13
13
 
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = BBMB::VERSION
9
9
  spec.author = "Masaomi Hatakeyama, Zeno R.R. Davatz, Niklaus Giger"
10
10
  spec.email = "mhatakeyama@ywesee.com, zdavatz@ywesee.com, ngiger@ywesee.com"
11
- spec.description = "ywesee distributed invoice manager. A Ruby gem"
12
- spec.summary = "ywesee distributed invoice manager"
11
+ spec.description = "A Ruby gem for browser based orders of approved medical drugs in Switzerland"
12
+ spec.summary = "browser based orders of medical drugs"
13
13
  spec.homepage = "https://github.com/zdavatz/bbmb"
14
14
  spec.license = "GPL-v2"
15
15
  spec.files = `git ls-files -z`.split("\x0")
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency "ydbd-pg", '>= 0.5.2'
22
22
  spec.add_dependency "ydbi", '>= 0.5.3'
23
23
  spec.add_dependency "json"
24
- spec.add_dependency "sbsm"
24
+ # spec.add_dependency "sbsm", '>= 1.3.5'
25
25
  spec.add_dependency "htmlgrid"
26
26
  spec.add_dependency "ydim", '>= 0.5.1'
27
27
  spec.add_dependency "syck"
@@ -4,6 +4,6 @@ require 'bbmb/version'
4
4
 
5
5
  module BBMB
6
6
  class << self
7
- attr_accessor :auth, :config, :logger, :persistence, :server
7
+ attr_accessor :auth, :config, :persistence, :server
8
8
  end
9
9
  end
@@ -59,8 +59,7 @@ module BBMB
59
59
  'invoice_percentage' => 0.1,
60
60
  'i2_100' => 'YWESEE',
61
61
  'load_files' => ['bbmb/util/csv_importer'],
62
- 'log_file' => STDERR,
63
- 'log_level' => 'INFO',
62
+ 'log_pattern' => File.join(Dir.pwd, 'log','/%Y/%m/%d/app_log'),
64
63
  'mail_suppress_sending' => false,
65
64
  'mail_confirm_body' => nil,
66
65
  'mail_confirm_cc' => [],
@@ -100,6 +99,11 @@ module BBMB
100
99
  'vat_rate' => 2.4,
101
100
  'ydim_config' => nil,
102
101
  'ydim_id' => nil,
102
+ 'yus_domain' => 'com.davaz',
103
+ 'yus_server' => nil,
104
+ 'test_user' => nil,
105
+ 'test_password' => nil,
106
+ 'yus_uri' => 'drbssl://localhost:9997',
103
107
  }
104
108
 
105
109
  config = RCLConf::RCLConf.new(ARGV, defaults)
@@ -24,7 +24,7 @@ class ChangePassword < Global
24
24
  update_user input
25
25
  unless(error?)
26
26
  BBMB.persistence.save(@model)
27
- return State::Info.new(@session, :message => :login_data_saved,
27
+ return State::Info.new(@session, :message => :login_data_saved,
28
28
  :event => :home)
29
29
  end
30
30
  end
@@ -36,8 +36,8 @@ class ChangePassword < Global
36
36
  @model.protect!(:email)
37
37
  if(passhash = input.delete(:confirm_pass))
38
38
  begin
39
- @session.user.set_password(email, passhash)
40
- rescue Yus::YusError => e
39
+ @session.auth_session.set_password(email, passhash)
40
+ rescue Yus::YusError => e
41
41
  @errors.store(:pass, create_error(:e_pass_not_set, :email, email))
42
42
  end
43
43
  end
@@ -30,7 +30,7 @@ class CurrentOrder < Global
30
30
  end
31
31
  def commit
32
32
  ## update most recent values and ensure @model = _customer.current_order
33
- do_update
33
+ do_update
34
34
  if @session.lookandfeel.enabled?(:terms_of_service, false)
35
35
  if @session.user_input(:accept_terms)
36
36
  _customer.terms_last_accepted ||= Time.now
@@ -31,9 +31,9 @@ class Customer < Global
31
31
  @cleartext = BBMB::Util::PasswordGenerator.generate(@model)
32
32
  passhash = @session.validate(:pass, @cleartext)
33
33
  begin
34
- @session.user.grant(email, 'login',
34
+ @session.auth_session.grant(email, 'login',
35
35
  BBMB.config.auth_domain + '.Customer')
36
- @session.user.set_password(email, passhash)
36
+ @session.auth_session.set_password(email, passhash)
37
37
  rescue Yus::YusError
38
38
  @errors.store(:pass, create_error(:e_pass_not_set, :pass, nil))
39
39
  end
@@ -69,7 +69,7 @@ class Customer < Global
69
69
  @errors.store(:error, create_error(:error, :error, nil))
70
70
  @errors.store(:user, create_error(:e_user_unsaved, :error, nil))
71
71
  else
72
- input.each { |key, val|
72
+ input.each { |key, val|
73
73
  writer = "#{key}="
74
74
  if(@model.respond_to?(writer) && @model.send(key) != val)
75
75
  @model.send(writer, val)
@@ -93,10 +93,10 @@ class Customer < Global
93
93
  @model.protect!(:email)
94
94
  if(passhash = input.delete(:confirm_pass))
95
95
  begin
96
- @session.user.grant(email, 'login',
96
+ @session.auth_session.grant(email, 'login',
97
97
  BBMB.config.auth_domain + '.Customer')
98
- @session.user.set_password(email, passhash)
99
- rescue Yus::YusError => e
98
+ @session.auth_session.set_password(email, passhash)
99
+ rescue Yus::YusError => e
100
100
  @errors.store(:pass, create_error(:e_pass_not_set, :email, email))
101
101
  end
102
102
  end
@@ -16,7 +16,7 @@ module BBMB
16
16
  start = Time.now
17
17
  @model = BBMB.persistence.all(Model::Customer)
18
18
  @sortby = [:organisation]
19
- BBMB.logger.debug('State') {
19
+ SBSM.debug('State') {
20
20
  sprintf("Customers#init: loaded %i customers in %1.5fs",
21
21
  @model.size, Time.now - start)
22
22
  }
@@ -51,7 +51,7 @@ module BBMB
51
51
 
52
52
  def page(model)
53
53
  index = @session.user_input(:index).to_i
54
- step = @session.user.pagestep || BBMB.config.pagestep
54
+ step = @session.user.get_preference(:pagestep) || BBMB.config.pagestep
55
55
  page = OpenStruct.new
56
56
  page.index = index
57
57
  page.first = index + 1
@@ -22,10 +22,12 @@ module BBMB
22
22
  module Html
23
23
  module State
24
24
  class Global < SBSM::State
25
- def initialize(first, second)
26
- super(first, second)
25
+ def initialize(session, model)
26
+ SBSM.info "BBMB::Html::State Global session #{session.class} model #{model.class}"
27
+ super(session, model)
27
28
  end
28
29
  def logout
30
+ SBSM.info "BBMB::Html::State Global logout"
29
31
  @session.logout
30
32
  State::Login.new(@session, nil)
31
33
  end
@@ -10,6 +10,7 @@ module BBMB
10
10
  class Init < SBSM::State
11
11
  VIEW = Html::View::LoginForm
12
12
  def login
13
+ SBSM.info "BBMB::Html::Init login #{user_input(:email)} #{user_input(:pass)} #{@user.class}"
13
14
  if(res = @session.login)
14
15
  Customers.new(@session, nil)
15
16
  end
@@ -15,6 +15,8 @@ module BBMB
15
15
  class Login < SBSM::State
16
16
  VIEW = View::Login
17
17
  def login
18
+ # is called from sbsm
19
+ SBSM.info "BBMB::Html::State Login login #{user_input(:email)} #{user_input(:pass)} #{@user.class}"
18
20
  reconsider_permissions(@session.login)
19
21
  trigger(:home)
20
22
  rescue Yus::UnknownEntityError
@@ -61,11 +63,13 @@ TVS/Virbac-Nr: #{input[:customer_id]}
61
63
  }
62
64
  end
63
65
  def viral_modules(user)
64
- [
66
+ [
65
67
  ['.Admin', State::Viral::Admin],
66
68
  ['.Customer', State::Viral::Customer],
67
69
  ].each { |key, mod|
70
+ puts "viral_modules trying #{key} #{mod}"
68
71
  if(user.allowed?("login", BBMB.config.auth_domain + key))
72
+ puts "Was allowed via user #{user} for #{mod}"
69
73
  yield mod
70
74
  end
71
75
  }
@@ -23,7 +23,8 @@ module Admin
23
23
  Model::Customer.find_by_customer_id(customer_id)
24
24
  end
25
25
  def home
26
- trigger(@session.user.home || :customers)
26
+ home = @session.user.get_preference(:home) || :customers
27
+ trigger(home)
27
28
  end
28
29
  def order
29
30
  if(order_id = @session.user_input(:order_id))
@@ -23,7 +23,7 @@ module Customer
23
23
  :search_favorites => State::FavoritesResult,
24
24
  }
25
25
  def _customer
26
- @customer ||= Model::Customer.find_by_email(@session.user.name)
26
+ @customer ||= Model::Customer.find_by_email(@session.auth_session.name)
27
27
  end
28
28
  def _increment_order(order)
29
29
  quantities = user_input(:quantity)
@@ -58,7 +58,7 @@ module Customer
58
58
  false
59
59
  else
60
60
  quantities.each { |article_number, quantity|
61
- order.add(quantity.to_i,
61
+ order.add(quantity.to_i,
62
62
  Model::Product.find_by_article_number(article_number))
63
63
  }
64
64
  BBMB.persistence.save(order, _customer)
@@ -91,7 +91,8 @@ module Customer
91
91
  _transfer(_customer.favorites)
92
92
  end
93
93
  def home
94
- trigger(@session.user.home || :current_order)
94
+ home = @session.user.get_preference(:home) || :current_order
95
+ trigger(home)
95
96
  end
96
97
  def increment_order
97
98
  if(_increment_order(_customer.current_order))
@@ -15,36 +15,68 @@ class KnownUser < SBSM::User
15
15
  #
16
16
  ### Customers need permissions for:
17
17
  # login BBMB.config.auth_domain + ".Customer"
18
- attr_reader :auth_session
18
+ attr_reader :auth_session
19
19
  PREFERENCE_KEYS = [ :home, :pagestep ]
20
20
  PREFERENCE_KEYS.each { |key|
21
21
  define_method(key) {
22
- remote_call(:get_preference, key)
22
+ remote_call(:get_preference, key)
23
23
  }
24
- }
24
+ } if false
25
25
  def initialize(session)
26
- @auth_session = session
26
+ puts "BBMB::Html::Util::KnownUser.new object_id is #{self.object_id} SBSM::Session ? #{self.is_a? SBSM::Session} auth_session is #{session.class}"
27
+ @auth_session = session.auth_session
28
+ # puts "backtrace #{caller.join("\n")}"
29
+ # @auth_session.auth.allowed?('edit', 'yus.entities')
27
30
  end
28
31
  def allowed?(action, key=nil)
32
+ if @auth_session
33
+ return @auth_session.allowed?(action, key)
34
+ return @auth_session.remote_call(:allowed?, action, key)
35
+ end
36
+ SBSM.debug('User ' + sprintf('allowed?(%s, %s)', action, key))
37
+ if defined?(yus_user) && yus_user
38
+ allowed = yus_user.send(:allowed?, action, key)
39
+ end if false
40
+ return true
41
+ # SBSM.debug('User'+ sprintf('allowed?(%s, %s) -> %s', action, key, allowed))
42
+ return allowed
43
+ # session.rb:25:in `login' BBMB::Html::Util::Session login claude.meier@gmx.net 5972659ce6c7f9b2356c0e650c7c40a3
29
44
  allowed = remote_call(:allowed?, action, key)
30
- BBMB.logger.debug('User') {
45
+ SBSM.debug('User') {
31
46
  sprintf('%s: allowed?(%s, %s) -> %s', name, action, key, allowed)
32
47
  }
33
48
  allowed
49
+ rescue => error
50
+ puts error
51
+ puts error.backtrace.join("\n")
34
52
  end
35
53
  def entity_valid?(email)
36
- !!(allowed?('edit', 'yus.entities') \
37
- && (entity = remote_call(:find_entity, email)) && entity.valid?)
54
+ !!(@auth_session.allowed?('edit', 'yus.entities') \
55
+ && (entity = @auth_session.find_entity(email)) && entity.valid?)
38
56
  end
39
57
  def navigation
58
+ puts "BBMB::Html::Util::KnownUser navigation returning [ :logout ]"
40
59
  [ :logout ]
41
60
  end
61
+ def get_preference(key)
62
+ return @auth_session.get_preference(key.to_s)
63
+ remote_call(:get_preference, key)
64
+ end
42
65
  def remote_call(method, *args, &block)
43
- @auth_session.send(method, *args, &block)
66
+ SBSM.debug("remote_call #{method} args #{args} block.nil? #{block.nil?}")
67
+ if defined?(@auth_session) && @auth_session.is_a?(DRb::DRbObject)
68
+ return @auth_session.send(method, *args, &block)
69
+ else
70
+ return false
71
+ return super(method, *args, &block)
72
+ end
44
73
  rescue RangeError, DRb::DRbError => e
45
- BBMB.logger.error('auth') { e }
74
+ SBSM.info('auth') { e }
75
+ rescue error
76
+ puts error
77
+ puts error.backtrace.join("\n")
46
78
  end
47
- alias :method_missing :remote_call
79
+ # alias :method_missing :remote_call
48
80
  end
49
81
  end
50
82
  end
@@ -1,14 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
 
4
+ require 'uri'
4
5
  require 'bbmb/config'
5
6
  require 'sbsm/session'
6
7
  require 'bbmb/html/state/global'
7
- begin
8
- require 'bbmb/html/util/lookandfeel'
9
- rescue LoadError
10
- # ignore it for unit tests
11
- end
12
8
  require 'bbmb/html/util/known_user'
13
9
 
14
10
 
@@ -21,12 +17,35 @@ class Session < SBSM::Session
21
17
  DEFAULT_STATE = State::Login
22
18
  EXPIRES = BBMB.config.session_timeout
23
19
  PERSISTENT_COOKIE_NAME = "bbmb-barcodereader"
20
+ if uri = URI.parse(BBMB.config.http_server)
21
+ SERVER_NAME = uri.host
22
+ end
23
+ attr_reader :email, :pass, :auth_session
24
+ def initializexx(app:, cookie_name:, trans_handler:, validator:)
25
+ super(app, cookie_name, trans_handler, validator)
26
+ end
24
27
  def login
25
- @user = @app.login(user_input(:email), user_input(:pass))
28
+ @email = user_input(:email)
29
+ @password = user_input(:pass)
30
+ # @user.respond_to?(:session=)) is FALSE!!!!
26
31
  @user.session = self if(@user.respond_to?(:session=))
32
+ # Before rack: @user = @app.login(user_input(:email), user_input(:pass))
33
+ @auth = DRb::DRbObject.new(nil, BBMB.config.auth_url)
34
+ @auth_session = @auth.login(user_input(:email), user_input(:pass), BBMB.config.auth_domain) # logs in claude meier without problem, but not admin
35
+ if @auth_session.valid?
36
+ @user = BBMB::Html::Util::KnownUser.new(self) # TODO:Should we set it already in the initialize method?
37
+ else
38
+ @user = SBSM::UnknownUser
39
+ end
40
+ SBSM.info "BBMB::Html::Util::Session login #{user_input(:email)} #{user_input(:pass)} #{@user.class} @auth #{@auth} auth_session #{@auth_session}"
41
+ pp @auth
42
+ pp @auth_session
43
+ pp @user
27
44
  @user
28
45
  end
29
46
  def logout
47
+ SBSM.info "BBMB::Html::Util::Session logout @auth_session #{@auth_session.class}"
48
+ $stdout.sync = true
30
49
  @app.logout(@user.auth_session) if(@user.respond_to?(:auth_session))
31
50
  super
32
51
  end
@@ -35,11 +54,12 @@ class Session < SBSM::Session
35
54
  if(@lookandfeel.nil? \
36
55
  || (@lookandfeel.language != persistent_user_input(:language)))
37
56
  require 'bbmb/html/util/lookandfeel'
38
- @lookandfeel = Lookandfeel.new(self) # dtsttcpw
57
+ @lookandfeel = Lookandfeel.new(self)
39
58
  end
40
59
  @lookandfeel
41
60
  end
42
61
  def process(request)
62
+ SBSM.info "BBMB::Html::Util::Session process"
43
63
  begin
44
64
  if(@user.is_a?(KnownUser) && @user.auth_session.expired?)
45
65
  logout
@@ -52,6 +72,11 @@ class Session < SBSM::Session
52
72
  def validate(key, value)
53
73
  @validator.validate(key, value)
54
74
  end
75
+ def remote_call(method, *args, &block)
76
+ @yus_user.send(method, *args, &block)
77
+ rescue RangeError, DRb::DRbError => e
78
+ BBMB.logger.error('auth') { e }
79
+ end
55
80
  end
56
81
  end
57
82
  end