BigW Consortium Gitlab

Commit aa158dd7 by James Lopez

finish off refactoring users controller

parent 85b5a8cf
...@@ -54,7 +54,7 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -54,7 +54,7 @@ class Admin::UsersController < Admin::ApplicationController
end end
def block def block
if user.block if update_user { |user| user.block }
redirect_back_or_admin_user(notice: "Successfully blocked") redirect_back_or_admin_user(notice: "Successfully blocked")
else else
redirect_back_or_admin_user(alert: "Error occurred. User was not blocked") redirect_back_or_admin_user(alert: "Error occurred. User was not blocked")
...@@ -64,7 +64,7 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -64,7 +64,7 @@ class Admin::UsersController < Admin::ApplicationController
def unblock def unblock
if user.ldap_blocked? if user.ldap_blocked?
redirect_back_or_admin_user(alert: "This user cannot be unlocked manually from GitLab") redirect_back_or_admin_user(alert: "This user cannot be unlocked manually from GitLab")
elsif user.activate elsif update_user { |user| user.activate }
redirect_back_or_admin_user(notice: "Successfully unblocked") redirect_back_or_admin_user(notice: "Successfully unblocked")
else else
redirect_back_or_admin_user(alert: "Error occurred. User was not unblocked") redirect_back_or_admin_user(alert: "Error occurred. User was not unblocked")
...@@ -72,7 +72,7 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -72,7 +72,7 @@ class Admin::UsersController < Admin::ApplicationController
end end
def unlock def unlock
if user.unlock_access! if update_user { |user| user.unlock_access! }
redirect_back_or_admin_user(alert: "Successfully unlocked") redirect_back_or_admin_user(alert: "Successfully unlocked")
else else
redirect_back_or_admin_user(alert: "Error occurred. User was not unlocked") redirect_back_or_admin_user(alert: "Error occurred. User was not unlocked")
...@@ -80,7 +80,7 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -80,7 +80,7 @@ class Admin::UsersController < Admin::ApplicationController
end end
def confirm def confirm
if user.confirm if update_user { |user| user.confirm }
redirect_back_or_admin_user(notice: "Successfully confirmed") redirect_back_or_admin_user(notice: "Successfully confirmed")
else else
redirect_back_or_admin_user(alert: "Error occurred. User was not confirmed") redirect_back_or_admin_user(alert: "Error occurred. User was not confirmed")
...@@ -88,7 +88,8 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -88,7 +88,8 @@ class Admin::UsersController < Admin::ApplicationController
end end
def disable_two_factor def disable_two_factor
user.disable_two_factor! update_user { |user| user.disable_two_factor! }
redirect_to admin_user_path(user), redirect_to admin_user_path(user),
notice: 'Two-factor Authentication has been disabled for this user' notice: 'Two-factor Authentication has been disabled for this user'
end end
...@@ -126,9 +127,9 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -126,9 +127,9 @@ class Admin::UsersController < Admin::ApplicationController
respond_to do |format| respond_to do |format|
user.skip_reconfirmation! user.skip_reconfirmation!
result = Users::UpdateService.new(current_user, @user, user_params_with_pass).execute result = Users::UpdateService.new(current_user, user, user_params_with_pass).execute
if result[:succcess] if result[:status] == :success
format.html { redirect_to [:admin, user], notice: 'User was successfully updated.' } format.html { redirect_to [:admin, user], notice: 'User was successfully updated.' }
format.json { head :ok } format.json { head :ok }
else else
...@@ -153,11 +154,17 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -153,11 +154,17 @@ class Admin::UsersController < Admin::ApplicationController
email = user.emails.find(params[:email_id]) email = user.emails.find(params[:email_id])
email.destroy email.destroy
result = Users::UpdateService.new(current_user, @user).execute do
user.update_secondary_emails! user.update_secondary_emails!
end
respond_to do |format| if result[:status] == :success
format.html { redirect_back_or_admin_user(notice: "Successfully removed email.") } format.html { redirect_back_or_admin_user(notice: "Successfully removed email.") }
format.js { head :ok } format.json { head :ok }
else
# restore username to keep form action url.
format.html { redirect_back_or_admin_user(notice: result[:message]) }
format.json { render json: result[:message], status: result[:status] }
end end
end end
...@@ -205,4 +212,12 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -205,4 +212,12 @@ class Admin::UsersController < Admin::ApplicationController
:website_url :website_url
] ]
end end
def update_user
result = Users::UpdateService.new(current_user, user).execute do
yield(user)
end
result[:status] == :success
end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment