Sha256: 39f94d80a917a06e53b3a3efbf56d07c9af93ad0ad493b071437d89f98abcf61

Contents?: true

Size: 1.73 KB

Versions: 29

Compression:

Stored size: 1.73 KB

Contents

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

  module StrongParameters
    # Only allow a list of trusted parameters through.
    def user_params
      password_fields = [
        :password,
        :current_password,
        :password_confirmation
      ]
      general_fields = [
        :email,
        :first_name,
        :last_name,
        :time_zone,
        :locale,
        :profile_photo_id, # For Cloudinary
        :profile_photo,    # For ActiveStorage
        :profile_photo_removal
      ]

      selected_fields = if params.is_a?(BulletTrain::Api::StrongParametersReporter)
        password_fields + general_fields
      else
        (params["commit"] == t(".buttons.update_password")) ? password_fields : general_fields
      end

      strong_params = params.require(:user).permit(
        *permitted_fields,
        *selected_fields,
        # 🚅 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

  # PUT /api/v1/users/:id
  # TODO: Implement this!
  def update
    raise "Not implemented"
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
bullet_train-api-1.4.2 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.4.1 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.4.0 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.3.25 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.3.24 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.3.23 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.3.22 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.3.21 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.3.20 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.3.19 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.3.18 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.3.17 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.3.16 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.3.15 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.3.14 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.3.13 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.3.12 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.3.11 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.3.10 app/controllers/concerns/api/v1/users/controller_base.rb
bullet_train-api-1.3.9 app/controllers/concerns/api/v1/users/controller_base.rb