Class | Admin::UsersController
In: | app/controllers/admin/users_controller.rb
Parent: | Admin::BaseController

### Methods

create destroy edit index new permisos pwd_edit pwd_update search show update

### Public Instance methods

create()

[Source]

        # File app/controllers/admin/users_controller.rb, line 42
    42:   def create
    43:     @user = User.new(params[:user])
    44:     @user.type= params[:user][:type] if params[:user][:type]
    45:     @user.department_id = params[:user][:department_id] if params[:user][:department_id]
    46:     @user.status= params[:user][:status]
    47:
    48:     if @user.save
    49:       flash[:notice] = "El usuario ha sido dado de alta!"
    50:       redirect_to admin_users_url(:t => @user.type)
    51:     else
    52:       render :action => "new"
    53:     end
    54:   end

destroy()

[Source]

         # File app/controllers/admin/users_controller.rb, line 117
    117:   def destroy
    118:     @user = User.find(params[:id])
    119:     user_type = @user.type
    120:
    121:     if @user.destroy
    122:       flash[:notice] = "El usuario se ha borrado correctamente"
    123:       redirect_to admin_users_url(:t => user_type) and return
    124:     else
    125:       flash[:error] = "No ha podido borrarse el usuario"
    126:       redirect_to edit_admin_user_path(@user) and return
    127:     end
    128:   end

edit()

[Source]

        # File app/controllers/admin/users_controller.rb, line 61
    61:   def edit
    62:     @user = User.find(params[:id])
    63:     get_document_counters
    64:   end

index()

[Source]

        # File app/controllers/admin/users_controller.rb, line 5
     5:   def index
     6:     @t = params[:t] || 'Admin'
     7:
     8:     conditions = ["type=?", @t]
     9:     if params[:q].present?
    10:       conditions[0] << "AND lower(tildes(name || coalesce(last_names, '') || coalesce(telephone, '') || email)) like ?"
    11:       conditions << "%#{params[:q].tildes.downcase}%"
    12:     end
    13:
    14:     @users = User.paginate(:page => params[:page],
    15:       :conditions => conditions,
    16:       :order => "(CASE WHEN status = 'pendiente' THEN 0 ELSE 1 end), tildes(lower(name)), email")
    17:
    18:     @sessions = SessionLog.find :all, :joins => :user, :conditions => ["type=?", @t],
    19:       :order => "action_at DESC", :limit => 20
    20:   end

new()

render new.rhtml

[Source]

        # File app/controllers/admin/users_controller.rb, line 27
    27:   def new
    28:     @user = Admin.new(:email => params[:email])
    29:   end

permisos()

[Source]

         # File app/controllers/admin/users_controller.rb, line 130
    130:   def permisos
    131:     send_file("#{RAILS_ROOT}/app/views/admin/users/permisos.pdf")
    132:   end

pwd_edit()

[Source]

         # File app/controllers/admin/users_controller.rb, line 103
    103:   def pwd_edit
    104:     @user=User.find(params[:id])
    105:   end

pwd_update()

[Source]

         # File app/controllers/admin/users_controller.rb, line 107
    107:   def pwd_update
    108:     @user=User.find(params[:id])
    109:     if @user.update_attributes(:password=>params[:user][:password], :password_confirmation => params[:user][:password_confirmation])
    110:       flash[:notice] = "Contraseña modificada"
    111:       redirect_to(params[:return_to].empty? ? admin_users_path : params[:return_to])
    112:     else
    113:       render :action => "pwd_edit"
    114:     end
    115:   end

search()

[Source]

        # File app/controllers/admin/users_controller.rb, line 31
    31:   def search
    32:     if params[:email]
    33:       @user = User.find_by_email(params[:email])
    34:       if @user
    35:         render :action => "make_admin"
    36:       else
    37:         redirect_to :action => 'new', :email => params[:email], :t => params[:t]
    38:       end
    39:     end
    40:   end

show()

[Source]

        # File app/controllers/admin/users_controller.rb, line 56
    56:   def show
    57:     @user = User.find(params[:id])
    58:     @sessions = @user.session_logs.find :all, :order => "action_at DESC", :limit => 20
    59:   end

update()

[Source]

         # File app/controllers/admin/users_controller.rb, line 66
     66:   def update
     67:     if params[:submit_cancel]
     68:       redirect_to admin_users_path
     69:     else
     70:       @user = User.find(params[:id])
     71:       get_document_counters
     72:       if params[:user][:type]
     73:         # Tengo que hacer esto para que cambie el class de user y actualice bien el departamento
     74:         @user.type= params[:user][:type]
     75:         @user.save
     76:         @user = User.find(params[:id])
     77:       end
     78:
     79:       approving_user = @user.status.eql?("pendiente") && params[:user][:status].eql?("aprobado")
     80:
     81:       if @user.update_attributes(params[:user])
     82:         flash[:notice] = 'El usuario se ha actualizado correctamente.'
     83:
     84:         if @user.is_a?(Journalist) && approving_user
     85:           email = Notifier.create_welcome_journalist(@user)
     86:
     87:           begin
     88:             logger.info("Mandando bienvenida a #{@user.email}")
     89:             Notifier.deliver(email)
     90:           rescue Net::SMTPServerBusy, Net::SMTPSyntaxError => err_type
     91:             logger.info("Error al mandar mail de bienvenida: " + err_type)
     92:             flash[:error] = t('session.Error_servidor_correo')
     93:           end
     94:         end
     95:
     96:         redirect_to admin_users_url(:t => @user.type)
     97:       else
     98:         render :action => 'edit'
     99:       end
    100:     end
    101:   end

[Validate]