Sha256: ccba6305fb03f8b240827335d602d54337430eb4ee7fd49c6848665a6fa4f22d

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

class Curupira::UsersController < Curupira::AuthorizedController
  def index
    if current_user.admin?
      @users = User.all
    else
      @users = User.all_belonging_to(current_user)
    end
  end

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

  def new
    @user = User.new
  end

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

  def create
    @user = User.new(user_params)

    if @user.save
      redirect_to @user, notice: "Usuário criado com sucesso"
    else
      render :new
    end
  end

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

    if @user.update user_params
      redirect_to @user, notice: "Usuário atualizado com sucesso"
    else
      render :edit
    end
  end

  def permission
    @user = User.find(params[:user_id])
    @group_user = @user.group_users.find(params[:group_user_id])
    @group = @group_user.group
  end

  private

  def user_params
    params.require(:user).permit(:email, :name, :username, :password, group_users_attributes: [:id, :group_id, :_destroy, role_group_users_attributes: [:id, :role_id]])
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
curupira-0.1.7 app/controllers/curupira/users_controller.rb
curupira-0.1.6 app/controllers/curupira/users_controller.rb
curupira-0.1.4 app/controllers/curupira/users_controller.rb