Sha256: 67d20b6af08a3c9f1da7e0ab4abfff1432d9d6a0041d9061e85f4cd8f3053d9e

Contents?: true

Size: 1.74 KB

Versions: 5

Compression:

Stored size: 1.74 KB

Contents

module Account::Users::ControllerBase
  extend ActiveSupport::Concern

  included do
    load_and_authorize_resource

    before_action do
      # for magic locales.
      @child_object = @user
    end
  end

  # GET /account/users/1/edit
  def edit
  end

  # GET /account/users/1
  def show
  end

  def updating_password?
    params[:user].key?(:password)
  end

  # PATCH/PUT /account/users/1
  # PATCH/PUT /account/users/1.json
  def update
    respond_to do |format|
      if updating_password? ? @user.update_with_password(user_params) : @user.update_without_password(user_params)
        # if you update your own user account, devise will normally kick you out, so we do this instead.
        bypass_sign_in current_user.reload
        format.html { redirect_to [:edit, :account, @user], notice: t("users.notifications.updated") }
        format.json { render :show, status: :ok, location: [:account, @user] }
      else
        format.html { render :edit, status: :unprocessable_entity }
        format.json { render json: @user.errors, status: :unprocessable_entity }
      end
    end
  end

  private

  # Never trust parameters from the scary internet, only allow the white list through.
  def user_params
    # TODO enforce permissions on updating the user's team name.
    params.require(:user).permit(
      :email,
      :first_name,
      :last_name,
      :time_zone,
      :current_password,
      :password,
      :password_confirmation,
      :profile_photo_id,
      :locale,
      # 🚅 super scaffolding will insert new fields above this line.
      current_team_attributes: [:name],
      # 🚅 super scaffolding will insert new arrays above this line.
    )

    # 🚅 super scaffolding will insert processing for new fields above this line.
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bullet_train-1.0.11 app/controllers/concerns/account/users/controller_base.rb
bullet_train-1.0.10 app/controllers/concerns/account/users/controller_base.rb
bullet_train-1.0.9 app/controllers/concerns/account/users/controller_base.rb
bullet_train-1.0.8 app/controllers/concerns/account/users/controller_base.rb
bullet_train-1.0.7 app/controllers/concerns/account/users/controller_base.rb