Sha256: d707436861bfd01e5cda4f9fd7ef97838692747c7493d0dcfe304a1da134cd4f

Contents?: true

Size: 1.18 KB

Versions: 5

Compression:

Stored size: 1.18 KB

Contents

module Api::V1::Users::ControllerBase
  extend ActiveSupport::Concern

  module StrongParameters
    # Only allow a list of trusted parameters through.
    def user_params
      strong_params = params.require(:user).permit(
        *permitted_fields,
        :email,
        :first_name,
        :last_name,
        :time_zone,
        :locale,
        :current_password,
        :password,
        :password_confirmation,
        # 🚅 super scaffolding will insert new fields above this line.
        *permitted_arrays,
        # 🚅 super scaffolding will insert new arrays above this line.
      )

      process_params(strong_params)

      strong_params
    end
  end

  included do
    load_and_authorize_resource :user, class: "User", prepend: true,
      member_actions: (defined?(MEMBER_ACTIONS) ? MEMBER_ACTIONS : []),
      collection_actions: (defined?(COLLECTION_ACTIONS) ? COLLECTION_ACTIONS : [])

    prepend_before_action :resolve_me

    private

    include StrongParameters
  end

  # GET /api/v1/users
  def index
  end

  def resolve_me
    if current_user && params[:id]&.downcase == "me"
      params[:id] = current_user.id
    end
  end

  # GET /api/v1/users/:id
  def show
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bullet_train-api-1.2.9 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.2.8 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.2.7 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.2.6 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.2.5 app/controllers/concerns/api/v1/users/controller_base.rb