Simplify a method to remove Rubocop violation

This commit is contained in:
Maciej Szlosarczyk 2018-08-17 11:19:49 +03:00
parent cf16aa4039
commit 98f55fd48a
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765

View file

@ -34,20 +34,14 @@ module Versions
end end
def user_from_id_role_username(str) def user_from_id_role_username(str)
if str.match(/^(\d+)-(ApiUser:|api-)/) registrar = Registrar.find_by(name: str)
user = ApiUser.find_by(id: $1) user = registrar.api_users.first if registrar
end str_match = str.match(/^(\d+)-(ApiUser:|api-|AdminUser:)/)
unless user.present?
user = if str.match(/^(\d+)-AdminUser:/) if str_match
AdminUser.find_by(id: $1) user ||= User.find_by(id: str_match[1])
end
unless user.present?
# on import we copied Registrar name, which may eql code
registrar = Registrar.find_by(name: str)
# assume each registrar has only one user
user = registrar.api_users.first if registrar
end
end end
user user
end end