Sha256: 2538dc81eb4e41804e7afecd539d73d2837f7908d1ba6e430f2b7522e524fb16

Contents?: true

Size: 1.5 KB

Versions: 11

Compression:

Stored size: 1.5 KB

Contents

module Spina
  module Admin
    class UsersController < AdminController
      before_action :set_breadcrumbs
      before_action :authorize_admin, except: [:index]
      before_action :set_user, only: [:edit, :update, :destroy]

      def index
        @users = User.all
      end

      def new
        @user = User.new
        add_breadcrumb I18n.t('spina.users.new')
      end

      def create
        @user = User.new(user_params)
        add_breadcrumb I18n.t('spina.users.new')
        if @user.save
          redirect_to admin_users_url
        else
          flash.now[:alert] = I18n.t('spina.users.cannot_be_created')
          render :new
        end
      end

      def edit        
        add_breadcrumb "#{@user}"
      end

      def update        
        add_breadcrumb "#{@user}"
        if @user.update(user_params)
          redirect_to spina.admin_users_url
        else
          flash.now[:alert] = I18n.t('spina.users.cannot_be_created')
          render :edit
        end
      end

      def destroy        
        @user.destroy unless @user == current_spina_user
        redirect_to admin_users_url
      end

      private

        def set_breadcrumbs
          add_breadcrumb I18n.t('spina.preferences.users'), spina.admin_users_path
        end

        def user_params
          params.require(:user).permit(:admin, :email, :name, :password_digest, :password, :password_confirmation, :last_logged_in)
        end

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
spina-2.0.2 app/controllers/spina/admin/users_controller.rb
spina-2.0.1 app/controllers/spina/admin/users_controller.rb
spina-2.0.0 app/controllers/spina/admin/users_controller.rb
spina-2.0.0.beta app/controllers/spina/admin/users_controller.rb
spina-2.0.0.alpha app/controllers/spina/admin/users_controller.rb
spina-1.2.0 app/controllers/spina/admin/users_controller.rb
spina-1.1.4 app/controllers/spina/admin/users_controller.rb
spina-1.1.3 app/controllers/spina/admin/users_controller.rb
spina-1.1.2 app/controllers/spina/admin/users_controller.rb
spina-1.1.1 app/controllers/spina/admin/users_controller.rb
spina-1.1.0 app/controllers/spina/admin/users_controller.rb