rnsap 0.4.9 → 0.4.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f56fd75d15077d529ed8ad93e58c4e772714acb91c8fb997a7ac8791a898d54
4
- data.tar.gz: a391550e77f21bdbb1518d5079f55aaad75457b964db5849c9d1dd50025f7e71
3
+ metadata.gz: 46c579462ff6f422f25681f0294a21888e8f2a22bb0462a11f079cd9b72fbbdd
4
+ data.tar.gz: b727dcb22d0b4672f5cb1b6740bfa3801a06a9ca9a040e1fb93c7bca5794b7e1
5
5
  SHA512:
6
- metadata.gz: b0c57556326309f03c1d917f1c2071e8641cff6afe8c0efe60911b044c9415fdeabe7e8420dc4dd88a95591132fdb73d6a118f26c5e331d928e1d619a4edd3b4
7
- data.tar.gz: 466291a12816596a8ab6a84c0bf46d4b9b08981444664c6cc228c29a903b3455f3a1d7be6120bb744b8dffe8470651f9032cd086807ea5c60d4774908af292da
6
+ metadata.gz: 912238c4977896355b9f9fe7cb08bc9f4f1b450f3ce085968ec4bad3bbc70ca01ab0a0ca07e64e315a2dc9383f4021aadc3dd9d17604200d37dbffb84091a417
7
+ data.tar.gz: 8d378a789e570455b8b002a5f6475fc3de4e8462a29ea672993ae02f109a372bc60089c668ba83ec6732388eceeed6618aada48c0f56f1ae9ab97ad0ae1c9bb7
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
@@ -1,5 +1,5 @@
1
1
  module UtilHelper
2
- require 'JSON'
2
+ require 'json'
3
3
 
4
4
  def log(msg='no message')
5
5
  puts obj_to_s(msg)
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,21 @@ 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
+ if value.nil? || value == '00000000'
166
166
  eval("obj.#{field} = nil")
167
167
  else
168
- value = Date.new(
169
- value[0..3],
170
- value[4..5],
171
- value[6..7]
172
- )
173
- eval("obj.#{field} = #{value}")
168
+ year = value[0..3].to_i
169
+ month = value[4..5].to_i
170
+ day = value[6..7].to_i
171
+ # value = Date.new(year, month, day)
172
+ eval("obj.#{field} = Date.new(#{year}, #{month}, #{day}) ")
174
173
  end
175
174
  else
176
- value = wa[pos].strip
175
+ begin
176
+ value = wa[pos].strip
177
+ rescue
178
+ value = ''
179
+ end
177
180
  eval("obj.#{field} = '#{value}'")
178
181
  end
179
182
 
@@ -438,6 +441,37 @@ module RnSap
438
441
 
439
442
  end
440
443
 
444
+ ##
445
+ # Gets a list of users with authorization for a given
446
+ # authorization object and content
447
+ # @params:
448
+ # - obj [String] SAP authorization Object
449
+ # Ex: for Purchase Requisitions M_EINK_FRG
450
+ # - field1 [String] Object authorization's field.
451
+ # Ex: for Release Group FRGGR
452
+ # - value1 [String] Field Value
453
+ # Ex: any valid Release Group in the instalation
454
+ # - field2 [String] Object authorization's field.
455
+ # Ex: for Release Code FRGCO
456
+ # - value2 [String] Field Value
457
+ # Ex: any valid Release Code in the instalation
458
+ # @return [Array] Array of strings with the SAP userids
459
+ def users_for_auth_object(obj, field1, value1, field2, value2)
460
+ Auth.for_object(
461
+ conn: self,
462
+ obj: obj,
463
+ field1: field1,
464
+ value1: value1,
465
+ field2: field2,
466
+ value2: value2,
467
+ )
468
+ end
469
+
470
+
471
+
472
+ private
473
+ attr_writer :conn
474
+
441
475
  def api_return_success(obj=nil )
442
476
  UtilHelper.api_return(0, 'Success!', obj)
443
477
  end
@@ -450,9 +484,7 @@ module RnSap
450
484
  UtilHelper.api_return(rc, message, obj, exception)
451
485
  end
452
486
 
453
- private
454
-
455
- attr_writer :conn
487
+
456
488
 
457
489
  # Dumps to the output the content of an object
458
490
  def dump_instance_variables(obj)
@@ -462,6 +494,8 @@ module RnSap
462
494
  end
463
495
  end
464
496
 
497
+ KLASS_LIST = {}
498
+
465
499
  # Dynamically returns a class instance with the name 'name' and with each
466
500
  # of its fields as an attribute
467
501
  # @param name [String] name of the intended class instance
@@ -469,7 +503,13 @@ module RnSap
469
503
  # @return [Object] instance of the object 'Name'
470
504
  def get_class_instance(name, fields)
471
505
  # puts "Class name: #{name}"
472
- klass = Object.const_set(name, Class.new).new # , Struct.new(*attributes)
506
+ pre_created = KLASS_LIST[name]
507
+ if pre_created
508
+ klass = pre_created.new
509
+ else
510
+ KLASS_LIST[name] = Object.const_set(name, Class.new)
511
+ klass = KLASS_LIST[name].new # , Struct.new(*attributes)
512
+ end
473
513
  fields.each do |field|
474
514
  klass.class.module_eval { attr_accessor field.downcase }
475
515
  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.9
4
+ version: 0.4.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rogerio Nascimento
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-30 00:00:00.000000000 Z
11
+ date: 2021-03-26 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
41
+ description: By encapsulating SAPs NW RFC library calls, Ruby routines achieve SAP
42
+ bunsiness functionalitys power in a simpler manner
43
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