2018-09-14 01:42:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-06-18 11:56:15 -04:00
|
|
|
class Admin::IdentitiesController < Admin::ApplicationController
|
2015-06-19 05:46:49 -04:00
|
|
|
before_action :user
|
2015-12-11 15:33:15 -05:00
|
|
|
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
|
2019-03-21 09:31:05 -04:00
|
|
|
redirect_to admin_user_identities_path(@user), notice: _('User identity was successfully created.')
|
2015-12-11 15:33:15 -05:00
|
|
|
else
|
|
|
|
render :new
|
|
|
|
end
|
|
|
|
end
|
2015-06-19 06:04:34 -04:00
|
|
|
|
|
|
|
def index
|
|
|
|
@identities = @user.identities
|
|
|
|
end
|
2015-06-18 11:56:15 -04:00
|
|
|
|
2015-06-19 05:46:49 -04:00
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2018-07-02 06:43:06 -04:00
|
|
|
if @identity.update(identity_params)
|
2019-12-02 10:06:36 -05:00
|
|
|
::Users::RepairLdapBlockedService.new(@user).execute
|
|
|
|
|
2019-03-21 09:31:05 -04:00
|
|
|
redirect_to admin_user_identities_path(@user), notice: _('User identity was successfully updated.')
|
2015-06-19 05:46:49 -04:00
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
|
|
|
end
|
2015-06-18 11:56:15 -04:00
|
|
|
|
2015-06-19 05:46:49 -04:00
|
|
|
def destroy
|
2015-06-22 12:01:52 -04:00
|
|
|
if @identity.destroy
|
2019-12-02 10:06:36 -05:00
|
|
|
::Users::RepairLdapBlockedService.new(@user).execute
|
|
|
|
|
2019-11-17 07:06:19 -05:00
|
|
|
redirect_to admin_user_identities_path(@user), status: :found, notice: _('User identity was successfully removed.')
|
2015-06-22 12:01:52 -04:00
|
|
|
else
|
2019-11-17 07:06:19 -05:00
|
|
|
redirect_to admin_user_identities_path(@user), status: :found, alert: _('Failed to remove user identity.')
|
2015-06-18 11:56:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2015-06-18 11:56:15 -04:00
|
|
|
def user
|
|
|
|
@user ||= User.find_by!(username: params[:user_id])
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2015-06-19 05:46:49 -04:00
|
|
|
|
|
|
|
def identity
|
|
|
|
@identity ||= user.identities.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def identity_params
|
2015-06-23 04:26:50 -04:00
|
|
|
params.require(:identity).permit(:provider, :extern_uid)
|
2015-06-19 05:46:49 -04:00
|
|
|
end
|
2015-06-18 11:56:15 -04:00
|
|
|
end
|