Sha256: 8a11950402eab0537126c3444c763d6dc6e7955e02148c86fa22f46006f0f716

Contents?: true

Size: 1.63 KB

Versions: 18

Compression:

Stored size: 1.63 KB

Contents

class Kuroko2::UsersController < Kuroko2::ApplicationController
  before_action :set_user, only: [:edit, :update, :destroy]
  before_action :require_group_user, only: [:edit, :update, :destroy]

  def index
    @user  = Kuroko2::User.new
    if params[:target] == 'group'
      @users = Kuroko2::User.group_user.all.page(page_params[:page])
    else
      @users = Kuroko2::User.all.page(page_params[:page])
    end
  end

  def show
    @user = Kuroko2::User.find(params[:id])
    @input_tags  = params[:tag] || []

    @definitions = @user.assigned_job_definitions
    if @input_tags.present?
      @definitions = @definitions.tagged_by(@input_tags)
    end

    @instances    = Kuroko2::JobInstance.working.where(job_definition: @definitions)
    @related_tags = @definitions.includes(:tags).map(&:tags).flatten.uniq
  end

  def edit
  end

  def update
    if @user.update(user_params)
      redirect_to user_path(@user)
    else
      render action: :edit
    end
  end

  def create
    @user = Kuroko2::User.new(user_params)
    @user.provider = Kuroko2::User::GROUP_PROVIDER
    @user.uid      = @user.email

    if @user.save
      redirect_to users_path
    else
      @users = Kuroko2::User.all

      render action: :index
    end
  end

  def destroy
    if @user.destroy
      redirect_to users_url
    else
      @users = Kuroko2::User.all

      render :index
    end
  end

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

  def user_params
    params.require(:user).permit(:name, :email)
  end

  def page_params
    params.permit(:page)
  end

  def require_group_user
    head :bad_request if @user.google_account?
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
kuroko2-0.8.0 app/controllers/kuroko2/users_controller.rb
kuroko2-0.7.0 app/controllers/kuroko2/users_controller.rb
kuroko2-0.6.0 app/controllers/kuroko2/users_controller.rb
kuroko2-0.5.2 app/controllers/kuroko2/users_controller.rb
kuroko2-0.5.1 app/controllers/kuroko2/users_controller.rb
kuroko2-0.5.0 app/controllers/kuroko2/users_controller.rb
kuroko2-0.4.6 app/controllers/kuroko2/users_controller.rb
kuroko2-0.4.5 app/controllers/kuroko2/users_controller.rb
kuroko2-0.4.4 app/controllers/kuroko2/users_controller.rb
kuroko2-0.4.3 app/controllers/kuroko2/users_controller.rb
kuroko2-0.4.2 app/controllers/kuroko2/users_controller.rb
kuroko2-0.4.1 app/controllers/kuroko2/users_controller.rb
kuroko2-0.4.0 app/controllers/kuroko2/users_controller.rb
kuroko2-0.3.4 app/controllers/kuroko2/users_controller.rb
kuroko2-0.3.3 app/controllers/kuroko2/users_controller.rb
kuroko2-0.3.2 app/controllers/kuroko2/users_controller.rb
kuroko2-0.3.1 app/controllers/kuroko2/users_controller.rb
kuroko2-0.3.0 app/controllers/kuroko2/users_controller.rb