Commit ab6daccf authored by Nick Thomas's avatar Nick Thomas

Merge branch 'brodock/repair-ldap-service-refactor' into 'master'

Refactor RepairLdapBlockedUserService

See merge request gitlab-org/gitlab!21018
parents fe97fddc 8aaf8767
......@@ -28,7 +28,8 @@ class Admin::IdentitiesController < Admin::ApplicationController
def update
if @identity.update(identity_params)
RepairLdapBlockedUserService.new(@user).execute
::Users::RepairLdapBlockedService.new(@user).execute
redirect_to admin_user_identities_path(@user), notice: _('User identity was successfully updated.')
else
render :edit
......@@ -37,7 +38,8 @@ class Admin::IdentitiesController < Admin::ApplicationController
def destroy
if @identity.destroy
RepairLdapBlockedUserService.new(@user).execute
::Users::RepairLdapBlockedService.new(@user).execute
redirect_to admin_user_identities_path(@user), status: :found, notice: _('User identity was successfully removed.')
else
redirect_to admin_user_identities_path(@user), status: :found, alert: _('Failed to remove user identity.')
......
# frozen_string_literal: true
class RepairLdapBlockedUserService
attr_accessor :user
def initialize(user)
@user = user
end
def execute
user.block if ldap_hard_blocked?
end
private
def ldap_hard_blocked?
user.ldap_blocked? && !user.ldap_user?
end
end
# frozen_string_literal: true
module Users
class RepairLdapBlockedService
attr_accessor :user
def initialize(user)
@user = user
end
def execute
user.block if ldap_hard_blocked?
end
private
def ldap_hard_blocked?
user.ldap_blocked? && !user.ldap_user?
end
end
end
......@@ -13,7 +13,7 @@ describe Admin::IdentitiesController do
let(:user) { create(:omniauth_user, provider: 'ldapmain', extern_uid: 'uid=myuser,ou=people,dc=example,dc=com') }
it 'repairs ldap blocks' do
expect_next_instance_of(RepairLdapBlockedUserService) do |instance|
expect_next_instance_of(::Users::RepairLdapBlockedService) do |instance|
expect(instance).to receive(:execute)
end
......@@ -25,7 +25,7 @@ describe Admin::IdentitiesController do
let(:user) { create(:omniauth_user, provider: 'ldapmain', extern_uid: 'uid=myuser,ou=people,dc=example,dc=com') }
it 'repairs ldap blocks' do
expect_next_instance_of(RepairLdapBlockedUserService) do |instance|
expect_next_instance_of(::Users::RepairLdapBlockedService) do |instance|
expect(instance).to receive(:execute)
end
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
describe RepairLdapBlockedUserService do
describe Users::RepairLdapBlockedService do
let(:user) { create(:omniauth_user, provider: 'ldapmain', state: 'ldap_blocked') }
let(:identity) { user.ldap_identity }
subject(:service) { described_class.new(user) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment