Sha256: e2b81bf78eadc2ce03802b29e0d6ffd8ac0242a3ca6800d2a5ffccd7457ff33a

Contents?: true

Size: 1.81 KB

Versions: 21

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

class Admin::UsersController < Admin::BaseController
  before_action :set_user, only: [:edit, :update, :destroy]

  def index
    @users = User.order("login asc").page(params[:page]).
      per(this_blog.admin_display_elements)
  end

  def new
    @user = User.new
    @user.text_filter_name = this_blog.text_filter
  end

  def edit
    @user = params[:id] ? User.find_by(id: params[:id]) : current_user
  end

  def create
    @user = User.new(user_params)
    @user.name = @user.login
    if @user.save
      redirect_to admin_users_url, notice: I18n.t("admin.users.new.success")
    else
      render :new
    end
  end

  def update
    if @user.update(update_params)
      redirect_to admin_users_url, notice: "User was successfully updated."
    else
      render :edit
    end
  end

  def destroy
    @user.destroy if User.where("profile = ? and id != ?", User::ADMIN, @user.id).count > 1
    redirect_to admin_users_url
  end

  private

  def set_user
    @user = User.find(params[:id])
  end

  def user_params
    params.require(:user).permit(:login, :password, :password_confirmation,
                                 :email, :firstname, :lastname, :nickname,
                                 :name, :notify_via_email,
                                 :notify_on_new_articles, :notify_on_comments,
                                 :profile, :text_filter_name, :state,
                                 :twitter_account, :twitter_oauth_token,
                                 :twitter_oauth_token_secret, :description,
                                 :url, :msn, :yahoo, :jabber, :aim, :twitter)
  end

  def update_params
    if user_params[:password].blank? && user_params[:password_confirmation].blank?
      user_params.except(:password_confirmation, :password)
    else
      user_params
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
HornsAndHooves-publify_core-10.5.0 app/controllers/admin/users_controller.rb
HornsAndHooves-publify_core-10.4.0 app/controllers/admin/users_controller.rb
HornsAndHooves-publify_core-10.3.0 app/controllers/admin/users_controller.rb
HornsAndHooves-publify_core-10.2.0 app/controllers/admin/users_controller.rb
publify_core-9.2.10 app/controllers/admin/users_controller.rb
HornsAndHooves-publify_core-10.1.1 app/controllers/admin/users_controller.rb
HornsAndHooves-publify_core-10.1.0 app/controllers/admin/users_controller.rb
HornsAndHooves-publify_core-10.0.3 app/controllers/admin/users_controller.rb
HornsAndHooves-publify_core-10.0.2 app/controllers/admin/users_controller.rb
HornsAndHooves-publify_core-10.0.1 app/controllers/admin/users_controller.rb
HornsAndHooves-publify_core-10.0.0 app/controllers/admin/users_controller.rb
publify_core-9.2.9 app/controllers/admin/users_controller.rb
publify_core-9.2.8 app/controllers/admin/users_controller.rb
publify_core-9.2.7 app/controllers/admin/users_controller.rb
publify_core-9.2.6 app/controllers/admin/users_controller.rb
publify_core-9.2.5 app/controllers/admin/users_controller.rb
publify_core-9.2.4 app/controllers/admin/users_controller.rb
publify_core-9.2.3 app/controllers/admin/users_controller.rb
publify_core-9.2.2 app/controllers/admin/users_controller.rb
publify_core-9.2.1 app/controllers/admin/users_controller.rb