summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2017-06-16 11:12:06 +0200
committerJames Lopez <james@jameslopez.es>2017-06-23 11:41:42 +0200
commit158550cf37cc2db9590f0212962f10ecc73082de (patch)
tree3b48192a0eda2b96cf7de3c3f705a60346e18026
parentbf3a3f3652704fb261e6220e2199830ea22ec8d3 (diff)
downloadgitlab-ce-158550cf37cc2db9590f0212962f10ecc73082de.tar.gz
added service in the rest of controllers and classes
-rw-r--r--app/controllers/profiles/avatars_controller.rb2
-rw-r--r--app/controllers/profiles/two_factor_auths_controller.rb6
-rw-r--r--app/controllers/sessions_controller.rb2
-rw-r--r--app/services/users/update_service.rb6
-rw-r--r--lib/api/internal.rb2
-rw-r--r--lib/api/users.rb4
-rw-r--r--lib/gitlab/ldap/access.rb3
7 files changed, 13 insertions, 12 deletions
diff --git a/app/controllers/profiles/avatars_controller.rb b/app/controllers/profiles/avatars_controller.rb
index 933e0f3bceb..538604f8866 100644
--- a/app/controllers/profiles/avatars_controller.rb
+++ b/app/controllers/profiles/avatars_controller.rb
@@ -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
diff --git a/app/controllers/profiles/two_factor_auths_controller.rb b/app/controllers/profiles/two_factor_auths_controller.rb
index 313cdcd1c15..a8b7e756ad1 100644
--- a/app/controllers/profiles/two_factor_auths_controller.rb
+++ b/app/controllers/profiles/two_factor_auths_controller.rb
@@ -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(
@@ -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
@@ -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
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
index 0d8186dce02..f7d9d3c80c8 100644
--- a/app/controllers/sessions_controller.rb
+++ b/app/controllers/sessions_controller.rb
@@ -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."
diff --git a/app/services/users/update_service.rb b/app/services/users/update_service.rb
index b76950ac700..a1db1dbc583 100644
--- a/app/services/users/update_service.rb
+++ b/app/services/users/update_service.rb
@@ -1,5 +1,5 @@
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
@@ -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('. '))
diff --git a/lib/api/internal.rb b/lib/api/internal.rb
index 479ee16a611..8606ff75e11 100644
--- a/lib/api/internal.rb
+++ b/lib/api/internal.rb
@@ -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
diff --git a/lib/api/users.rb b/lib/api/users.rb
index ba59818ba84..2c632c85243 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -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
@@ -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
diff --git a/lib/gitlab/ldap/access.rb b/lib/gitlab/ldap/access.rb
index 54a5b1d31cd..7430db828a3 100644
--- a/lib/gitlab/ldap/access.rb
+++ b/lib/gitlab/ldap/access.rb
@@ -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