Sha256: 598483b5914d3b38b2879bc83fb7f96843b0a5fdbd0eeb4e540b6730c10109a2

Contents?: true

Size: 1.86 KB

Versions: 15

Compression:

Stored size: 1.86 KB

Contents

require_dependency "faalis/application_controller"

module Faalis
  class API::V1::UsersController < ::APIController

    def index
      @users = User.joins(:group).all
      authorize! :read, @users
      respond_with(@users)
    end

    def show
      @user = User.find(params[:id])
      authorize! :read, @user
      respond_with(@user)
    end

    def destroy
      ids = params[:id].split(",")
      @users = User.where(:id => ids)
      authorize! :destory, @groups
      @users.destroy_all
    end

    def update
      @user = User.find(params[:id])
      authorize! :update, @user
      user_fields = {
        :first_name => params[:first_name],
        :last_name => params[:last_name],
        :email => params[:email],
      }

      if params.include? :password and params[:password]
        user_fields[:password] =  params[:password]
      end

      if params.include? :group and params[:group]
        user_fields[:group] =  Group.find(params[:group]) || nil
      end

      if @user.update(user_fields)
        respond_with(@user)
      else
        respond_to do |format|
          format.json { render :json => {:fields => @user.errors}, :status => :unprocessable_entity }
        end
      end
    end

    def create
      authorize! :create, Faalis::User

      @user = User.new({
                         first_name: params[:first_name],
                         last_name: params[:last_name],
                         email: params[:email],
                         password: params[:password],
                       })

      if params.include? :group
        group = Group.find(params[:group]) || nil
        @user.group = group
      end

      if @user.save
        respond_with(@user)
      else
        respond_to do |format|
          format.json { render :json => {:fields => @user.errors}, :status => :unprocessable_entity }
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
faalis-0.24.3 app/controllers/faalis/api/v1/users_controller.rb
faalis-0.24.2 app/controllers/faalis/api/v1/users_controller.rb
faalis-0.24.0 app/controllers/faalis/api/v1/users_controller.rb
faalis-0.23.0 app/controllers/faalis/api/v1/users_controller.rb
faalis-0.22.0 app/controllers/faalis/api/v1/users_controller.rb
faalis-0.21.1 app/controllers/faalis/api/v1/users_controller.rb
faalis-0.21.0 app/controllers/faalis/api/v1/users_controller.rb
faalis-0.20.0 app/controllers/faalis/api/v1/users_controller.rb
faalis-0.19.0 app/controllers/faalis/api/v1/users_controller.rb
faalis-0.18.1 app/controllers/faalis/api/v1/users_controller.rb
faalis-0.18.0 app/controllers/faalis/api/v1/users_controller.rb
faalis-0.17.0 app/controllers/faalis/api/v1/users_controller.rb
faalis-0.16.3 app/controllers/faalis/api/v1/users_controller.rb
faalis-0.16.1 app/controllers/faalis/api/v1/users_controller.rb
faalis-0.16.0 app/controllers/faalis/api/v1/users_controller.rb