BigW Consortium Gitlab

identities_controller.rb 1.33 KB
Newer Older
1
class Admin::IdentitiesController < Admin::ApplicationController
2
  before_action :user
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
  before_action :identity, except: [:index, :new, :create]

  def new
    @identity = Identity.new
  end

  def create
    @identity = Identity.new(identity_params)
    @identity.user_id = user.id

    if @identity.save
      redirect_to admin_user_identities_path(@user), notice: 'User identity was successfully created.'
    else
      render :new
    end
  end
19 20 21 22

  def index
    @identities = @user.identities
  end
23

24 25 26 27 28
  def edit
  end

  def update
    if @identity.update_attributes(identity_params)
29
      RepairLdapBlockedUserService.new(@user).execute
30
      redirect_to admin_user_identities_path(@user), notice: 'User identity was successfully updated.'
31 32 33 34
    else
      render :edit
    end
  end
35

36
  def destroy
37
    if @identity.destroy
38
      RepairLdapBlockedUserService.new(@user).execute
39 40 41
      redirect_to admin_user_identities_path(@user), notice: 'User identity was successfully removed.'
    else
      redirect_to admin_user_identities_path(@user), alert: 'Failed to remove user identity.'
42 43 44 45 46 47 48 49
    end
  end

  protected

  def user
    @user ||= User.find_by!(username: params[:user_id])
  end
50 51 52 53 54 55

  def identity
    @identity ||= user.identities.find(params[:id])
  end

  def identity_params
56
    params.require(:identity).permit(:provider, :extern_uid)
57
  end
58
end