Class: CommandTower::Services::Admin::Users::UpdateEmail
- Inherits:
-
CommandTower::Services::ApplicationService
- Object
- CommandTower::ServiceBase
- CommandTower::Services::ApplicationService
- CommandTower::Services::Admin::Users::UpdateEmail
- 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
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'app/services/command_tower/services/admin/users.rb', line 207 def call normalized = email.to_s.strip if user.email.to_s == normalized context.user = user context.changed = false return end result = CommandTower::UserAttributes::Mutate.call(user:, email: 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 user.reload user.update!(email_validated: false) if user.email_validated context.user = user context.changed = true rescue ActiveRecord::RecordInvalid => error fail_uniqueness_or_raise(error) rescue ActiveRecord::RecordNotUnique context.fail!(application_error: IdentityUniqueness.uniqueness_error("email")) end |