2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
class Admin::IdentitiesController < Admin::ApplicationController
|
|
|
|
before_action :user
|
2015-12-23 02:04:40 +05:30
|
|
|
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-07-07 11:18:12 +05:30
|
|
|
redirect_to admin_user_identities_path(@user), notice: _('User identity was successfully created.')
|
2015-12-23 02:04:40 +05:30
|
|
|
else
|
|
|
|
render :new
|
|
|
|
end
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
|
|
|
def index
|
|
|
|
@identities = @user.identities
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2018-11-18 11:00:15 +05:30
|
|
|
if @identity.update(identity_params)
|
2020-01-01 13:55:28 +05:30
|
|
|
::Users::RepairLdapBlockedService.new(@user).execute
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
redirect_to admin_user_identities_path(@user), notice: _('User identity was successfully updated.')
|
2015-09-11 14:41:01 +05:30
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
if @identity.destroy
|
2020-01-01 13:55:28 +05:30
|
|
|
::Users::RepairLdapBlockedService.new(@user).execute
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
redirect_to admin_user_identities_path(@user), status: :found, notice: _('User identity was successfully removed.')
|
2015-09-11 14:41:01 +05:30
|
|
|
else
|
2019-12-26 22:10:19 +05:30
|
|
|
redirect_to admin_user_identities_path(@user), status: :found, alert: _('Failed to remove user identity.')
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2015-09-11 14:41:01 +05:30
|
|
|
def user
|
|
|
|
@user ||= User.find_by!(username: params[:user_id])
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2015-09-11 14:41:01 +05:30
|
|
|
|
|
|
|
def identity
|
|
|
|
@identity ||= user.identities.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def identity_params
|
|
|
|
params.require(:identity).permit(:provider, :extern_uid)
|
|
|
|
end
|
|
|
|
end
|