akkounts/app/controllers/admin/invitations_controller.rb
Râu Cao c99d8545c1
All checks were successful
continuous-integration/drone/push Build is passing
Add username filter to admin invitations index
2025-05-28 12:34:52 +04:00

29 lines
750 B
Ruby

class Admin::InvitationsController < Admin::BaseController
before_action :set_current_section
def index
@username = params[:username].presence
accepted_scope = Invitation.used.order('used_at desc')
unused_scope = Invitation.unused
if @username
accepted_scope = accepted_scope.joins(:user).where(users: { cn: @username })
unused_scope = unused_scope.joins(:user).where(users: { cn: @username })
end
@pagy, @invitations_used = pagy(accepted_scope)
@stats = {
available: unused_scope.count,
accepted: accepted_scope.count,
users_with_referrals: accepted_scope.distinct.count(:user_id)
}
end
private
def set_current_section
@current_section = :invitations
end
end