Sha256: 92a79c9e130f9556a9d80e657c8b193366e36c63fcc6b95368768dacb763d0ca

Contents?: true

Size: 1.87 KB

Versions: 22

Compression:

Stored size: 1.87 KB

Contents

class Admin::UsersController < Admin::BaseController

  crudify :user, :order => 'login', :title_attribute => 'login', :conditions => "state = 'active'"

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

  filter_parameter_logging 'password', 'password_confirmation'

  layout 'admin'

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

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

    if @user.save
      @user.plugins = @selected_plugin_titles
      @user.register!
      @user.activate!
      flash[:notice] = "'#{@user.login}' was successfully created."
      redirect_to :action => 'index'
    else
      render :action => 'new'
    end
  end

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

  def update
    @selected_plugin_titles = 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?("Users")
      flash.now[:error] = "You cannot remove the 'Users' plugin from the currently logged in account."
      render :action => "edit"
    else
      @previously_selected_plugins_titles = @user.plugins.collect{|p| p.title}
      if @user.update_attributes params[:user]
        flash[:notice] = "'#{@user.login}' was successfully updated."
        redirect_to admin_users_url
      else
        @user.plugins = @previously_selected_plugins_titles
        @user.save
        render :action => 'edit'
      end
    end
  end

protected

  def can_create_public_user
    User.count == 0
  end

  def load_available_plugins
    @available_plugins = Refinery::Plugins.registered.in_menu.titles.sort
  end

end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
jacobat-refinerycms-0.9.6.14 vendor/plugins/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.6.19 vendor/plugins/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.6.18 vendor/plugins/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.6.17 vendor/plugins/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.6.16 vendor/plugins/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.6.15 vendor/plugins/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.6.14 vendor/plugins/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.6.13 vendor/plugins/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.6.12 vendor/plugins/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.6.11 vendor/plugins/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.6.10 vendor/plugins/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.6.9 vendor/plugins/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.6.8 vendor/plugins/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.6.7 vendor/plugins/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.6.6 vendor/plugins/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.6.5 vendor/plugins/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.6.4 vendor/plugins/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.6.3 vendor/plugins/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.6.2 vendor/plugins/authentication/app/controllers/admin/users_controller.rb
refinerycms-0.9.6.1 vendor/plugins/authentication/app/controllers/admin/users_controller.rb