debian-mirror-gitlab/app/helpers/admin/user_actions_helper.rb

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

72 lines
1.4 KiB
Ruby
Raw Normal View History

2021-02-22 17:27:13 +05:30
# frozen_string_literal: true
module Admin
module UserActionsHelper
def admin_actions(user)
return [] if user.internal?
@actions ||= ['edit']
return @actions if user == current_user
@user ||= user
blocked_actions
deactivate_actions
unlock_actions
delete_actions
2021-09-30 23:02:18 +05:30
ban_actions
2021-02-22 17:27:13 +05:30
@actions
end
private
def blocked_actions
if @user.ldap_blocked?
@actions << 'ldap'
elsif @user.blocked? && @user.blocked_pending_approval?
@actions << 'approve'
@actions << 'reject'
elsif @user.blocked?
2021-09-30 23:02:18 +05:30
@actions << 'unblock' unless @user.banned?
2021-02-22 17:27:13 +05:30
else
@actions << 'block'
end
end
def deactivate_actions
if @user.can_be_deactivated?
@actions << 'deactivate'
elsif @user.deactivated?
@actions << 'activate'
end
end
def unlock_actions
@actions << 'unlock' if @user.access_locked?
end
def delete_actions
2021-10-27 15:23:28 +05:30
return unless can?(current_user, :destroy_user, @user) && !@user.blocked_pending_approval?
2021-02-22 17:27:13 +05:30
2021-10-27 15:23:28 +05:30
@actions << 'delete' if @user.can_be_removed?
2021-02-22 17:27:13 +05:30
@actions << 'delete_with_contributions'
end
2021-09-30 23:02:18 +05:30
def ban_actions
return unless ban_feature_available?
return if @user.internal?
if @user.banned?
@actions << 'unban'
return
end
unless @user.blocked?
@actions << 'ban'
end
end
2021-02-22 17:27:13 +05:30
end
end