Sha256: 5472ae76aacf74546471614b1c3e30b36b2eb1676d156c66520e404c78a1083e

Contents?: true

Size: 1.87 KB

Versions: 18

Compression:

Stored size: 1.87 KB

Contents

require_dependency "faalis/application_controller"

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

    def index
      @users = User.joins(:groups).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, @users
      @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? :groups and params[:groups]
        user_fields[:groups] =  Group.find(params[:groups]) || 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? :groups
        group = Group.find(params[:groups]) || nil
        @user.groups = 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

18 entries across 18 versions & 1 rubygems

Version Path
faalis-2.0.8 app/controllers/faalis/api/v1/users_controller.rb
faalis-2.0.7 app/controllers/faalis/api/v1/users_controller.rb
faalis-2.0.5 app/controllers/faalis/api/v1/users_controller.rb
faalis-2.0.4 app/controllers/faalis/api/v1/users_controller.rb
faalis-2.0.3 app/controllers/faalis/api/v1/users_controller.rb
faalis-2.0.1 app/controllers/faalis/api/v1/users_controller.rb
faalis-2.0.0 app/controllers/faalis/api/v1/users_controller.rb
faalis-2.0.0.rc6 app/controllers/faalis/api/v1/users_controller.rb
faalis-2.0.0.rc5 app/controllers/faalis/api/v1/users_controller.rb
faalis-2.0.0.rc4 app/controllers/faalis/api/v1/users_controller.rb
faalis-2.0.0.rc3 app/controllers/faalis/api/v1/users_controller.rb
faalis-2.0.0.rc2 app/controllers/faalis/api/v1/users_controller.rb
faalis-1.0.0 app/controllers/faalis/api/v1/users_controller.rb
faalis-1.0.0.alpha4 app/controllers/faalis/api/v1/users_controller.rb
faalis-1.0.0.alpha3 app/controllers/faalis/api/v1/users_controller.rb
faalis-1.0.0.alpha2 app/controllers/faalis/api/v1/users_controller.rb
faalis-1.0.0.alpha1 app/controllers/faalis/api/v1/users_controller.rb
faalis-1.0.0.alpha0 app/controllers/faalis/api/v1/users_controller.rb