Sha256: 542938205c5b0a0469e896778862463b1393092adc5fc4385d132e3189317354

Contents?: true

Size: 1.76 KB

Versions: 10

Compression:

Stored size: 1.76 KB

Contents

class Admin::UsersController < Admin::BaseController

  crudify :user, :order => 'login', :title_attribute => 'login'

  # Protect these actions behind an admin login
  before_filter :find_user, :except => [:index, :new, :create]
  before_filter :load_available_plugins, :only => [:new, :create, :edit, :update]

  layout 'admin'

  def new
    @user = User.new
    @selected_plugin_names = []
  end

  def create
    @user = User.new(params[:user])
    @selected_plugin_names = params[:user][:plugins] || []
    @user.add_role(:refinery)

    if @user.save
      @user.plugins = @selected_plugin_names
      redirect_to(admin_users_url, :notice => t('refinery.crudify.created', :what => @user.login))
    else
      render :action => 'new'
    end
  end

  def edit
    @user = User.find params[:id]
    @selected_plugin_names = @user.plugins.collect{|p| p.name}
  end

  def update
    @selected_plugin_names = params[:user][:plugins]
    # Prevent the current user from locking themselves out of the User manager
    if current_user.id == @user.id and !params[:user][:plugins].include?("refinery_users")
      flash.now[:error] = t('admin.users.update.cannot_remove_user_plugin_from_current_user')
      render :action => "edit"
    else
      @previously_selected_plugin_names = @user.plugins.collect{|p| p.name}
      if @user.update_attributes params[:user]
        redirect_to admin_users_url, :notice => t('refinery.crudify.updated', :what => @user.login)
      else
        @user.plugins = @previously_selected_plugin_names
        @user.save
        render :action => 'edit'
      end
    end
  end

protected

  def load_available_plugins
    @available_plugins = ::Refinery::Plugins.registered.in_menu.collect{|a| {:name => a.name, :title => a.title} }.sort_by {|a| a[:title]}
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
refinerycms-0.9.8.9 vendor/refinerycms/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.8.8 vendor/refinerycms/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.8.7 vendor/refinerycms/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.8.6 vendor/refinerycms/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.8.5 vendor/refinerycms/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.8.4 vendor/refinerycms/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.8.3 vendor/refinerycms/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.8.2 vendor/refinerycms/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.8.1 vendor/refinerycms/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.8 vendor/refinerycms/authentication/app/controllers/admin/users_controller.rb