Sha256: a722bc625cf5a2c6b4616712beb16e768ed11063df78ea3532269cf43417cbdb

Contents?: true

Size: 1.16 KB

Versions: 29

Compression:

Stored size: 1.16 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 update
    user_params = params[model_symbol].permit!
    if user_params && user_params['admin'] == false && model == current_user
      user_params.delete('admin')
      annouce_cannot_remove_self_from_admin_role
    end
    model.update_attributes!(user_params)
    response_for :update
  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 announce_cannot_delete_self
      flash[:error] = t('users_controller.cannot_delete_self')
    end

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

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
trusty-cms-3.8.0 app/controllers/admin/users_controller.rb
trusty-cms-3.7.1 app/controllers/admin/users_controller.rb
trusty-cms-3.7.0 app/controllers/admin/users_controller.rb
trusty-cms-3.6.2 app/controllers/admin/users_controller.rb
trusty-cms-3.6.1 app/controllers/admin/users_controller.rb
trusty-cms-3.6.0 app/controllers/admin/users_controller.rb
trusty-cms-3.5.5 app/controllers/admin/users_controller.rb
trusty-cms-3.5.4 app/controllers/admin/users_controller.rb
trusty-cms-3.5.3 app/controllers/admin/users_controller.rb
trusty-cms-3.5.2 app/controllers/admin/users_controller.rb
trusty-cms-3.5.1 app/controllers/admin/users_controller.rb
trusty-cms-3.5.0 app/controllers/admin/users_controller.rb
trusty-cms-3.4.0 app/controllers/admin/users_controller.rb
trusty-cms-3.3.7 app/controllers/admin/users_controller.rb
trusty-cms-3.3.6 app/controllers/admin/users_controller.rb
trusty-cms-3.3.5 app/controllers/admin/users_controller.rb
trusty-cms-3.3.3 app/controllers/admin/users_controller.rb
trusty-cms-3.3.2 app/controllers/admin/users_controller.rb
trusty-cms-3.3.1 app/controllers/admin/users_controller.rb
trusty-cms-3.2.1 app/controllers/admin/users_controller.rb