- Remove legacy 'process' route from admin payouts (conflicted with Ruby's process method) - Reorganize admin routes to logical position with proper section comment - Simplify admin payout routes to only include actual functionality - Update admin controller tests to test approval workflow instead of legacy routes - Add proper test setup with banking info and onboarding completion - Improve test coverage for admin authentication and payout approval This resolves admin controller test failures and removes unnecessary legacy code since the application is not yet published. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
77 lines
2.6 KiB
Ruby
77 lines
2.6 KiB
Ruby
class Admin::PayoutsController < ApplicationController
|
|
before_action :authenticate_user!
|
|
before_action :ensure_admin!
|
|
before_action :set_payout, only: [:show, :approve, :reject, :mark_processing, :mark_completed, :mark_failed]
|
|
|
|
def index
|
|
@pending_payouts = Payout.pending.includes(:user, :event).order(created_at: :asc)
|
|
@approved_payouts = Payout.approved.includes(:user, :event).order(created_at: :asc)
|
|
@processing_payouts = Payout.processing.includes(:user, :event).order(created_at: :asc)
|
|
@completed_payouts = Payout.completed.includes(:user, :event).order(created_at: :desc).limit(10)
|
|
end
|
|
|
|
def show
|
|
@service = PayoutService.new(@payout)
|
|
@transfer_summary = @service.generate_transfer_summary
|
|
@banking_errors = @service.validate_banking_info
|
|
end
|
|
|
|
def approve
|
|
if @payout.approve!(current_user)
|
|
redirect_to admin_payout_path(@payout), notice: "Payout approved successfully."
|
|
else
|
|
redirect_to admin_payout_path(@payout), alert: "Cannot approve this payout."
|
|
end
|
|
end
|
|
|
|
def reject
|
|
reason = params[:rejection_reason].presence || "No reason provided"
|
|
if @payout.reject!(current_user, reason)
|
|
redirect_to admin_payouts_path, notice: "Payout rejected."
|
|
else
|
|
redirect_to admin_payout_path(@payout), alert: "Cannot reject this payout."
|
|
end
|
|
end
|
|
|
|
def mark_processing
|
|
transfer_reference = params[:bank_transfer_reference]
|
|
if @payout.mark_processing!(current_user, transfer_reference)
|
|
redirect_to admin_payout_path(@payout), notice: "Payout marked as processing."
|
|
else
|
|
redirect_to admin_payout_path(@payout), alert: "Cannot mark payout as processing."
|
|
end
|
|
end
|
|
|
|
def mark_completed
|
|
transfer_reference = params[:bank_transfer_reference]
|
|
if @payout.mark_completed!(current_user, transfer_reference)
|
|
redirect_to admin_payouts_path, notice: "Payout completed successfully."
|
|
else
|
|
redirect_to admin_payout_path(@payout), alert: "Cannot mark payout as completed."
|
|
end
|
|
end
|
|
|
|
def mark_failed
|
|
reason = params[:failure_reason].presence || "Transfer failed"
|
|
if @payout.mark_failed!(current_user, reason)
|
|
redirect_to admin_payouts_path, notice: "Payout marked as failed."
|
|
else
|
|
redirect_to admin_payout_path(@payout), alert: "Cannot mark payout as failed."
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def set_payout
|
|
@payout = Payout.find(params[:id])
|
|
end
|
|
|
|
def ensure_admin!
|
|
# For now, we'll just check if the user has a stripe account
|
|
# In a real app, you'd have an admin role check
|
|
unless current_user.has_stripe_account?
|
|
redirect_to dashboard_path, alert: "Access denied."
|
|
end
|
|
end
|
|
end
|