Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: cb15cb07d6
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 72 lines (58 sloc) 2.019 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
module Admin
  class RegistrationsController < Admin::BaseController

    crudify :registration,
            :title_attribute => 'username', :xhr_paging => true

    helper_method :group_by_date

    before_filter :find_all_ham, :only => [:index, :approved, :rejected]
    before_filter :find_all_spam, :only => [:spam]
    before_filter :get_spam_count, :only => [:index, :spam, :approved, :rejected]

    def index
      @registrations = @registrations.unmoderated
      @registrations = @registrations.with_query(params[:search]) if searching?
      @registrations = @registrations.paginate({:page => params[:page]})
    end

    def approved
      unless params[:id].present?
        @registrations = @registrations.approved
        @registrations = @registrations.paginate({:page => params[:page]})
        render :action => 'index'
      else
        @registration = Registration.find(params[:id])
        @registration.approve!
        flash[:notice] = t('approved', :scope => 'admin.registration', :author => @registration.username)
        redirect_to :action => 'index'
      end
    end

    def rejected
      unless params[:id].present?
        @registrations = @registrations.rejected
        @registrations = @registrations.paginate({:page => params[:page]})
        render :action => 'index'
      else
        @registration = Registration.find(params[:id])
        @registration.reject!
        flash[:notice] = t('rejected', :scope => 'admin.registration', :author => @registration.username)
        redirect_to :action => 'index'
      end
    end

    def spam
      self.index
      render :action => 'index'
    end

    def toggle_spam
      find_registration
      @registration.toggle!(:spam)

      redirect_to :back
    end

  protected

    def find_all_ham
      @registrations = Registration.ham
    end

    def find_all_spam
      @registrations = Registration.spam
    end

    def get_spam_count
      @spam_count = Registration.count(:conditions => {:spam => true})
    end

  end
end
Something went wrong with that request. Please try again.