Files
nairobi/app/lib/manager_authenticator.rb
dependabot[bot] 123c97771a Bump rubocop from 1.71.2 to 1.75.8
Bumps [rubocop](https://github.com/rubocop/rubocop) from 1.71.2 to 1.75.8.
- [Release notes](https://github.com/rubocop/rubocop/releases)
- [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop/rubocop/compare/v1.71.2...v1.75.8)

---
updated-dependencies:
- dependency-name: rubocop
  dependency-version: 1.75.8
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Notes:

This commit also includes several style and lint fixes required after
updating RuboCop:

- Removed redundant parentheses now detected by improved
  'Style/RedundantParentheses' (1.72 and 1.75.3).
- Replaced ternary expressions with logical OR when the ternary was
  returning 'true', as flagged by 'Style/RedundantCondition' (1.73).
- Adjusted block variables to resolve new 'Lint/ShadowingOuterLocalVariable'
  offenses (1.75), helping avoid future conflicts during upgrades with
  'rails app:updates'

Signed-off-by: dependabot[bot] <support@github.com>
2025-06-16 16:07:32 +02:00

59 lines
1.6 KiB
Ruby

class ManagerAuthenticator
def initialize(data = {})
@manager = {
login: data[:login],
user_key: data[:clave_usuario],
date: data[:fecha_conexion]
}.with_indifferent_access
end
def auth
return false unless [@manager[:login], @manager[:user_key], @manager[:date]].all?(&:present?)
return @manager if manager_exists? && application_authorized?
false
end
private
def manager_exists?
response = client.call(
:get_status_user_data,
message: { ub: { user_key: @manager[:user_key], date: @manager[:date] }}
).body
parsed_response = parser.parse(response[:get_status_user_data_response][:get_status_user_data_return])
@manager[:login] == parsed_response["USUARIO"]["LOGIN"]
rescue
false
end
def application_authorized?
response = client.call(
:get_applications_user_list,
message: { ub: { user_key: @manager[:user_key] }}
).body
user_list_return = response[:get_applications_user_list_response][:get_applications_user_list_return]
parsed_response = parser.parse(user_list_return)
aplication_value = parsed_response["APLICACIONES"]["APLICACION"]
# aplication_value from UWEB can be an array of hashes or a hash
aplication_value.include?("CLAVE_APLICACION" => application_key) ||
aplication_value["CLAVE_APLICACION"] == application_key
rescue
false
end
def client
@client ||= Savon.client(wsdl: Tenant.current_secrets.managers_url)
end
def parser
@parser ||= Nori.new
end
def application_key
Tenant.current_secrets.managers_application_key.to_s
end
end