Sha256: 56e943e0dc5c2a9ed1492618504fbc7d7cd109f7bb7a2e419b9c43475946a543

Contents?: true

Size: 1.8 KB

Versions: 14

Compression:

Stored size: 1.8 KB

Contents

class Admin::UsersController < Admin::ResourceController
  paginate_models
  only_allow_access_to :index, :show, :new, :create, :edit, :update, :remove, :destroy,
    :when => :admin,
    :denied_url => { :controller => 'pages', :action => 'index' },
    :denied_message => 'You must have administrative privileges to perform this action.'

  before_action :ensure_deletable, :only => [:remove, :destroy]

  def show
    redirect_to edit_admin_user_path(params[:id])
  end

  def create
    user = User.new(user_params)
    if user.save
      flash[:notice] = 'User was created.'
      redirect_to admin_users_path
    else
      flash[:error] = 'There was an error saving the user. Please try again.'
      render :new
    end
  end 

  def update
    user_params = params[model_symbol].permit!
    if user_params && user_params['admin'] == false && model == current_user
      user_params.delete('admin')
      announce_cannot_remove_self_from_admin_role
    end
    model.skip_password_validation = true unless user_params[:password_confirmation].present?
    if model.update_attributes(user_params)
      response_for :update
    else
      flash[:error] = 'There was an error saving the user. Please try again.'
      render :edit
    end    
  end

  def ensure_deletable
    if current_user.id.to_s == params[:id].to_s
      announce_cannot_delete_self
      redirect_to admin_users_path
    end
  end

  private

    def user_params
      params.require(:user).permit(:first_name, :last_name, :admin, :designer, 
        :password, :password_confirmation, :email, :site_id, :notes)
    end

    def announce_cannot_delete_self
      flash[:error] = t('users_controller.cannot_delete_self')
    end

    def announce_cannot_remove_self_from_admin_role
      flash[:error] = 'You cannot remove yourself from the admin role.'
    end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
trusty-cms-4.1.2 app/controllers/admin/users_controller.rb
trusty-cms-4.1.1 app/controllers/admin/users_controller.rb
trusty-cms-4.1.0 app/controllers/admin/users_controller.rb
trusty-cms-4.0.2 app/controllers/admin/users_controller.rb
trusty-cms-3.9.7 app/controllers/admin/users_controller.rb
trusty-cms-3.9.6 app/controllers/admin/users_controller.rb
trusty-cms-3.9.5 app/controllers/admin/users_controller.rb
trusty-cms-4.0.1 app/controllers/admin/users_controller.rb
trusty-cms-3.9.4 app/controllers/admin/users_controller.rb
trusty-cms-3.9.3 app/controllers/admin/users_controller.rb
trusty-cms-3.9.2 app/controllers/admin/users_controller.rb
trusty-cms-4.0.0 app/controllers/admin/users_controller.rb
trusty-cms-3.9.1 app/controllers/admin/users_controller.rb
trusty-cms-3.9.0 app/controllers/admin/users_controller.rb