Code style fixes and some code simplified
This commit is contained in:
parent
ec67e9be1d
commit
47e4613f4a
4 changed files with 16 additions and 12 deletions
|
@ -26,7 +26,7 @@ class Admin::IdentitiesController < Admin::ApplicationController
|
|||
|
||||
def update
|
||||
if @identity.update_attributes(identity_params)
|
||||
RepairLdapBlockedUserService.new(@user, @identity).execute
|
||||
RepairLdapBlockedUserService.new(@user).execute
|
||||
redirect_to admin_user_identities_path(@user), notice: 'User identity was successfully updated.'
|
||||
else
|
||||
render :edit
|
||||
|
@ -35,7 +35,7 @@ class Admin::IdentitiesController < Admin::ApplicationController
|
|||
|
||||
def destroy
|
||||
if @identity.destroy
|
||||
RepairLdapBlockedUserService.new(@user, @identity).execute
|
||||
RepairLdapBlockedUserService.new(@user).execute
|
||||
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.'
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
class RepairLdapBlockedUserService
|
||||
attr_accessor :user, :identity
|
||||
attr_accessor :user
|
||||
|
||||
def initialize(user, identity)
|
||||
@user, @identity = user, identity
|
||||
def initialize(user)
|
||||
@user = user
|
||||
end
|
||||
|
||||
def execute
|
||||
if identity.destroyed?
|
||||
user.block if identity.is_ldap? && user.ldap_blocked? && !user.ldap_user?
|
||||
else
|
||||
user.block if !identity.is_ldap? && user.ldap_blocked? && !user.ldap_user?
|
||||
end
|
||||
user.block if ldap_hard_blocked?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ldap_hard_blocked?
|
||||
user.ldap_blocked? && !user.ldap_user?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -40,7 +40,9 @@ module Gitlab
|
|||
user.ldap_block
|
||||
false
|
||||
else
|
||||
user.activate if (user.blocked? && !ldap_config.block_auto_created_users) || user.ldap_blocked?
|
||||
if (user.blocked? && !ldap_config.block_auto_created_users) || user.ldap_blocked?
|
||||
user.activate
|
||||
end
|
||||
true
|
||||
end
|
||||
else
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
|||
describe RepairLdapBlockedUserService, services: true do
|
||||
let(:user) { create(:omniauth_user, provider: 'ldapmain', state: 'ldap_blocked') }
|
||||
let(:identity) { user.ldap_identity }
|
||||
subject(:service) { RepairLdapBlockedUserService.new(user, identity) }
|
||||
subject(:service) { RepairLdapBlockedUserService.new(user) }
|
||||
|
||||
describe '#execute' do
|
||||
it 'change to normal block after destroying last ldap identity' do
|
||||
|
|
Loading…
Reference in a new issue