Skip to content
Snippets Groups Projects
Commit 158550cf authored by James Lopez's avatar James Lopez
Browse files

added service in the rest of controllers and classes

parent bf3a3f36
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -3,7 +3,7 @@ class Profiles::AvatarsController < Profiles::ApplicationController
@user = current_user
@user.remove_avatar!
 
@user.save
Users::UpdateService.new(@user, @user).execute
 
redirect_to profile_path, status: 302
end
Loading
Loading
Loading
Loading
@@ -10,7 +10,7 @@ class Profiles::TwoFactorAuthsController < Profiles::ApplicationController
current_user.otp_grace_period_started_at = Time.current
end
 
current_user.save! if current_user.changed?
Users::UpdateService.new(current_user, current_user).execute!
 
if two_factor_authentication_required? && !current_user.two_factor_enabled?
two_factor_authentication_reason(
Loading
Loading
@@ -43,7 +43,7 @@ class Profiles::TwoFactorAuthsController < Profiles::ApplicationController
if current_user.validate_and_consume_otp!(params[:pin_code])
current_user.otp_required_for_login = true
@codes = current_user.generate_otp_backup_codes!
current_user.save!
Users::UpdateService.new(current_user, current_user).execute!
 
render 'create'
else
Loading
Loading
@@ -71,7 +71,7 @@ class Profiles::TwoFactorAuthsController < Profiles::ApplicationController
 
def codes
@codes = current_user.generate_otp_backup_codes!
current_user.save!
Users::UpdateService.new(current_user, current_user).execute!
end
 
def destroy
Loading
Loading
Loading
Loading
@@ -61,7 +61,7 @@ class SessionsController < Devise::SessionsController
return unless user && user.require_password?
 
token = user.generate_reset_token
user.save
Users::UpdateService.new(user, user).execute
 
redirect_to edit_user_password_path(reset_password_token: token),
notice: "Please create a password for your new account."
Loading
Loading
module Users
# Service for creating a new user.
# Service for updating a user.
class UpdateService < BaseService
def initialize(current_user, user, params = {})
@current_user = current_user
Loading
Loading
@@ -7,10 +7,10 @@ module Users
@params = params.dup
end
 
def execute(skip_authorization: false, &block)
def execute(skip_authorization: false, validate: true, &block)
assign_attributes(skip_authorization, &block)
 
if @user.save || !@user.changed? && @user.errors.empty?
if @user.save(validate: validate) || !@user.changed? && @user.errors.empty?
success
else
error(@user.errors.full_messages.uniq.join('. '))
Loading
Loading
Loading
Loading
@@ -133,7 +133,7 @@ module API
end
 
codes = user.generate_otp_backup_codes!
user.save!
::Users::UpdateService.new(user, user).execute!
 
{ success: true, recovery_codes: codes }
end
Loading
Loading
Loading
Loading
@@ -278,7 +278,7 @@ module API
 
email.destroy
 
Users::UpdateService.new(current_user, user).execute do |user|
::Users::UpdateService.new(current_user, user).execute do |user|
user.update_secondary_emails!
end
end
Loading
Loading
@@ -511,7 +511,7 @@ module API
not_found!('Email') unless email
 
email.destroy
Users::UpdateService.new(current_user, user).execute do |user|
::Users::UpdateService.new(current_user, user).execute do |user|
user.update_secondary_emails!
end
end
Loading
Loading
Loading
Loading
@@ -17,7 +17,8 @@ module Gitlab
self.open(user) do |access|
if access.allowed?
user.last_credential_check_at = Time.now
user.save
Users::UpdateService.new(user, user).execute
true
else
false
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment