rnsap 0.4.10 → 0.4.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/auth.rb +131 -0
  3. data/lib/rnsap.rb +54 -13
  4. metadata +10 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07f418d676742bf4e3102352227400ca2913f5c0299e6eb408ac2a2dc18126ab
4
- data.tar.gz: 3e3601ed9fdbf771af8b5ddf98fc260c7f71822b9c914d567c80166a7097dee6
3
+ metadata.gz: 84ea02c182e13acafaa92672819c1476f6d6af25211987bae5996b56a93ab201
4
+ data.tar.gz: 79bdba08c9fdc893a93bd9cae699d29cb1bd75a4bdfa7a933a7dad6eadc2a000
5
5
  SHA512:
6
- metadata.gz: f2392d3c7b782641a1de705764be7999012cb3eb3ba676547f7b8b52e7cb665e3ddb0229f8a9ec23ee73ffc2f1534b596f79098ce9849683d5193ea947048179
7
- data.tar.gz: 3676bee49742167c466652e6cd04acd9aa36ec621431a887aac3b0c5c2e79d6d5556ae14673cca38eb0097ede9d22e8be6c8207f87333e8441bb80503f699646
6
+ metadata.gz: a4e327670f7c89b37c1e02eed463c3e2699313a77bffd21fd4ee9274286e4b8b9b508b720591f376bbfb5d9dbc5b0ac0beedd91edcba6e76d364916482d9d255
7
+ data.tar.gz: 921aa5b6cf9c1046e0e52c82cf6d794c9fb04aafe2028456ad6435c09cadeaddeb4931ccd38ee75d7ff74e7b39e4bf30d1c8c20e00d8eea5fd8613fd5c3eb55b
data/lib/auth.rb ADDED
@@ -0,0 +1,131 @@
1
+ # Class to handle authorization related SAP information
2
+ # @author Rogerio Nascimento (26/03/2021)
3
+ class Auth
4
+
5
+ # Return a list of users with authorization
6
+ # for an object
7
+ # @param json containing authorization object and optionaly
8
+ # the tuples with field and value to be checked
9
+ # @return [Array] an array of strings with the list of users
10
+ def self.for_object(*options)
11
+ users = []
12
+ conn, obj, field1, value1, field2, value2 = validate_options(options)
13
+ return users unless conn && obj
14
+
15
+ ## Busca o AUTH na tabela UST12
16
+ ust12_list = Auth.auth_list(conn, obj, field1, value1, field2, value2)
17
+ return users unless ust12_list
18
+
19
+ ## Busca o PROFN na tabela UST10S
20
+ ust10s_list = Auth.profile_list(conn, obj, ust12_list)
21
+
22
+ ## Busca os Usuários na tabela UST04
23
+ Auth.user_list(conn, obj, ust10s_list)
24
+ end
25
+
26
+ #
27
+ # Select Authorization roles for the Profile
28
+ # @param list List of profiles to be searched
29
+ # @return Array<string> with list of authorizations
30
+ def self.profiles_for_composite(conn, list = [])
31
+ return [] if list.empty?
32
+
33
+ fname = conn.conn.get_function('SIAG_PROF_GET_AUTH')
34
+ fcall = fname.get_function_call
35
+
36
+ fcall[:IV_PROFILE_TYPE] = 'C'
37
+ list.each do |prof|
38
+ row = fcall[:IT_PROFILE_RANGE].new_row
39
+ row[:SIGN] = 'I'
40
+ row[:OPTION] = 'EQ'
41
+ row[:LOW] = prof
42
+ end
43
+
44
+ fcall.invoke
45
+
46
+ ret = []
47
+ fcall[:ET_COMPOSITE_PROFILE].each do |row|
48
+ ret.push(row[:SINGLE_PROFILE])
49
+ end
50
+
51
+ ret
52
+ end
53
+
54
+
55
+ private
56
+
57
+ def self.validate_options(options)
58
+ return [] if options.empty?
59
+ params = options.first
60
+
61
+ conn = params[:conn]
62
+ obj = params[:obj]
63
+
64
+ return [] unless conn && obj
65
+ return [] unless conn.class.name == 'RnSap::Sap'
66
+
67
+ field1 = params[:field1]
68
+ value1 = params[:value1]
69
+ field2 = params[:field2]
70
+ value2 = params[:value2]
71
+
72
+ [conn, obj, field1, value1, field2, value2]
73
+ end
74
+
75
+ def self.auth_list( conn, obj, field1, value1, field2, value2)
76
+
77
+ fields = ['AUTH']
78
+ filter = ["OBJCT = '#{obj}' "]
79
+ if field1 && value1
80
+ filter.push(" AND ( FIELD = '#{field1}' AND ( VON = '*' OR VON = '#{value1}' ) ")
81
+ if field2 && value2
82
+ filter.push(" OR FIELD = '#{field2}' AND ( VON = '*' OR VON = '#{value2}' ) )")
83
+ else
84
+ filter.push( ')')
85
+ end
86
+ end
87
+
88
+ conn.read_table('UST12', fields, filter)
89
+ end
90
+
91
+ def self.profile_list( conn, obj, ust12_list)
92
+ sap_all = 'SAP_ALL'
93
+ profiles = Auth.profiles_for_composite(conn, [sap_all])
94
+ profiles.push(sap_all)
95
+
96
+ fields = ['PROFN']
97
+ filter = ["OBJCT = '#{obj}' AND AUTH IN ("]
98
+ profiles.each do |prof|
99
+ filter.push( "'#{prof}' , ")
100
+ end
101
+ ust12_list.each do |ust|
102
+ filter.push( "'#{ust.auth}' , ")
103
+ end
104
+ filter = filter.uniq
105
+
106
+ new_last = "#{filter.last[0..(filter.last.length - 4)]} )"
107
+ filter = filter[0..-1].push(new_last)
108
+
109
+ conn.read_table('UST10S', fields, filter)
110
+ end
111
+
112
+ def self.user_list(conn, obj, ust10s_list)
113
+ users = []
114
+ fields = ['BNAME']
115
+ filter = ['PROFILE IN (']
116
+ filter.push("'SAP_ALL' , ")
117
+ ust10s_list.each do |ust|
118
+ filter.push("'#{ust.profn}' , ")
119
+ end
120
+ new_last = "#{filter.last[0..(filter.last.length - 4)]} )"
121
+ filter = filter[0..-1].push(new_last)
122
+
123
+ ust04_list = conn.read_table('UST04', fields, filter)
124
+
125
+ ust04_list.each do |ust|
126
+ users.push( ust.bname )
127
+ end
128
+
129
+ users.uniq.sort
130
+ end
131
+ end
data/lib/rnsap.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'nwrfc'
4
4
  require 'read_table/table_column'
5
+ require 'auth'
5
6
 
6
7
  require 'return'
7
8
 
@@ -161,19 +162,22 @@ module RnSap
161
162
  value = wa[pos].to_f
162
163
  eval("obj.#{field} = #{value}")
163
164
  elsif DATE_TYPES.include?(column.type)
164
- value = wa[pos].strip
165
- if value == '00000000'
165
+ value = wa[pos]
166
+ if value.nil? || value == '00000000'
166
167
  eval("obj.#{field} = nil")
167
168
  else
168
- value = Date.new(
169
- value[0..3],
170
- value[4..5],
171
- value[6..7]
172
- )
173
- eval("obj.#{field} = #{value}")
169
+ year = value[0..3].to_i
170
+ month = value[4..5].to_i
171
+ day = value[6..7].to_i
172
+ # value = Date.new(year, month, day)
173
+ eval("obj.#{field} = Date.new(#{year}, #{month}, #{day}) ")
174
174
  end
175
175
  else
176
- value = wa[pos].strip
176
+ begin
177
+ value = wa[pos].strip
178
+ rescue
179
+ value = ''
180
+ end
177
181
  eval("obj.#{field} = '#{value}'")
178
182
  end
179
183
 
@@ -438,6 +442,37 @@ module RnSap
438
442
 
439
443
  end
440
444
 
445
+ ##
446
+ # Gets a list of users with authorization for a given
447
+ # authorization object and content
448
+ # @params:
449
+ # - obj [String] SAP authorization Object
450
+ # Ex: for Purchase Requisitions M_EINK_FRG
451
+ # - field1 [String] Object authorization's field.
452
+ # Ex: for Release Group FRGGR
453
+ # - value1 [String] Field Value
454
+ # Ex: any valid Release Group in the instalation
455
+ # - field2 [String] Object authorization's field.
456
+ # Ex: for Release Code FRGCO
457
+ # - value2 [String] Field Value
458
+ # Ex: any valid Release Code in the instalation
459
+ # @return [Array] Array of strings with the SAP userids
460
+ def users_for_auth_object(obj, field1, value1, field2, value2)
461
+ Auth.for_object(
462
+ conn: self,
463
+ obj: obj,
464
+ field1: field1,
465
+ value1: value1,
466
+ field2: field2,
467
+ value2: value2,
468
+ )
469
+ end
470
+
471
+
472
+
473
+ private
474
+ attr_writer :conn
475
+
441
476
  def api_return_success(obj=nil )
442
477
  UtilHelper.api_return(0, 'Success!', obj)
443
478
  end
@@ -450,9 +485,7 @@ module RnSap
450
485
  UtilHelper.api_return(rc, message, obj, exception)
451
486
  end
452
487
 
453
- private
454
-
455
- attr_writer :conn
488
+
456
489
 
457
490
  # Dumps to the output the content of an object
458
491
  def dump_instance_variables(obj)
@@ -462,6 +495,8 @@ module RnSap
462
495
  end
463
496
  end
464
497
 
498
+ KLASS_LIST = {}
499
+
465
500
  # Dynamically returns a class instance with the name 'name' and with each
466
501
  # of its fields as an attribute
467
502
  # @param name [String] name of the intended class instance
@@ -469,7 +504,13 @@ module RnSap
469
504
  # @return [Object] instance of the object 'Name'
470
505
  def get_class_instance(name, fields)
471
506
  # puts "Class name: #{name}"
472
- klass = Object.const_set(name, Class.new).new # , Struct.new(*attributes)
507
+ pre_created = KLASS_LIST[name]
508
+ if pre_created
509
+ klass = pre_created.new
510
+ else
511
+ KLASS_LIST[name] = Object.const_set(name, Class.new)
512
+ klass = KLASS_LIST[name].new # , Struct.new(*attributes)
513
+ end
473
514
  fields.each do |field|
474
515
  klass.class.module_eval { attr_accessor field.downcase }
475
516
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rnsap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.10
4
+ version: 0.4.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rogerio Nascimento
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-30 00:00:00.000000000 Z
11
+ date: 2021-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nwrfc
@@ -38,13 +38,14 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: By encapsulating SAPs NW RFC library calls, Ruby routines can access
42
- SAP power in a simpler manner
43
- email:
41
+ description: By encapsulating SAPs NW RFC library calls, Ruby routines achieve SAP
42
+ bunsiness functionalitys power in a simpler manner
43
+ email:
44
44
  executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - lib/auth.rb
48
49
  - lib/helper/rfc_helper.rb
49
50
  - lib/helper/util_helper.rb
50
51
  - lib/po_detail/all.rb
@@ -100,7 +101,7 @@ licenses:
100
101
  - MIT
101
102
  metadata:
102
103
  source_code_uri: https://github.com/rnasc/rnsap
103
- post_install_message:
104
+ post_install_message:
104
105
  rdoc_options: []
105
106
  require_paths:
106
107
  - lib
@@ -115,8 +116,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
116
  - !ruby/object:Gem::Version
116
117
  version: '0'
117
118
  requirements: []
118
- rubygems_version: 3.2.11
119
- signing_key:
119
+ rubygems_version: 3.2.3
120
+ signing_key:
120
121
  specification_version: 4
121
122
  summary: Facilitates SAP RFC calls in Ruby
122
123
  test_files: []