Class: CommandTower::Services::Admin::Users::UpdateUsername
- Inherits:
-
CommandTower::Services::ApplicationService
- Object
- CommandTower::ServiceBase
- CommandTower::Services::ApplicationService
- CommandTower::Services::Admin::Users::UpdateUsername
- Defined in:
- app/services/command_tower/services/admin/users.rb
Constant Summary
Constants inherited from CommandTower::ServiceBase
CommandTower::ServiceBase::ON_ARGUMENT_VALIDATION
Instance Method Summary collapse
Methods inherited from CommandTower::Services::ApplicationService
Methods included from Transactional
#fail_transaction!, #transaction
Methods inherited from CommandTower::ServiceBase
#command_tower_lifecycle, inherited, #internal_validate, #service_lifecycle_error_codes, #service_lifecycle_log_level, #validate!
Methods included from Logging::LifecycleDeclaration
Methods included from Execution::ContextAccess
#audit, #execution_context, #log_debug, #log_error, #log_info, #log_warn, #publish_event
Methods included from ArgumentValidation
Methods included from CommandTower::ServiceLogging
Instance Method Details
#call ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'app/services/command_tower/services/admin/users.rb', line 168 def call normalized = username.to_s.strip if user.username.to_s == normalized context.user = user context.changed = false return end result = CommandTower::UserAttributes::Mutate.call(user:, username: normalized) unless result.success? details = result.invalid_argument_hash.transform_values { _1[:msg].to_s } context.fail!(application_error: CommandTower::Errors::ValidationError.new(details:)) return end context.user = user.reload context.changed = true rescue ActiveRecord::RecordInvalid => error fail_uniqueness_or_raise(error) rescue ActiveRecord::RecordNotUnique context.fail!(application_error: IdentityUniqueness.uniqueness_error("username")) end |