debian-mirror-gitlab/app/services/users/banned_user_base_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.1 KiB
Ruby
Raw Normal View History

2021-10-27 15:23:28 +05:30
# frozen_string_literal: true
module Users
class BannedUserBaseService < BaseService
def initialize(current_user)
@current_user = current_user
end
def execute(user)
return permission_error unless allowed?
2021-11-11 11:23:49 +05:30
return state_error(user) unless valid_state?(user)
2021-10-27 15:23:28 +05:30
if update_user(user)
log_event(user)
success
else
messages = user.errors.full_messages
error(messages.uniq.join('. '))
end
end
private
attr_reader :current_user
2021-11-11 11:23:49 +05:30
def state_error(user)
error(_("You cannot %{action} %{state} users." % { action: action.to_s, state: user.state }), :forbidden)
end
2021-10-27 15:23:28 +05:30
def allowed?
can?(current_user, :admin_all_resources)
end
def permission_error
error(_("You are not allowed to %{action} a user" % { action: action.to_s }), :forbidden)
end
def log_event(user)
2023-03-04 22:38:38 +05:30
Gitlab::AppLogger.info(message: "User #{action}", user: user.username.to_s, email: user.email.to_s, "#{action}_by": current_user.username.to_s, ip_address: current_user.current_sign_in_ip.to_s)
2021-10-27 15:23:28 +05:30
end
end
end