Delete External user

Added logic to managed on PublishUserDeleted Message Broker event

Change-Id: I7698a210c0768358f97635332799b50366ebf225
Signed-off-by: smarcet <smarcet@gmail.com>
This commit is contained in:
smarcet 2021-07-12 15:04:32 -03:00
parent 45050049a4
commit a776d6fe0d
4 changed files with 40 additions and 8 deletions

View File

@ -1,6 +1,6 @@
<?php namespace App\Jobs;
/**
* Copyright 2020 OpenStack Foundation
* Copyright 2021 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -11,12 +11,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Services\Model\IMemberService;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Log;
use models\exceptions\EntityNotFoundException;
use Exception;
/**
* Class PublishUserDeleted
* @package App\Jobs
@ -34,14 +37,21 @@ class PublishUserDeleted implements ShouldQueue
*/
public $user_email;
/**
* Execute the job.
*
* @return void
* @param IMemberService $service
*/
public function handle()
public function handle(IMemberService $service)
{
Log::debug(sprintf("PublishUserDeleted::handle user %s %s", $this->user_id, $this->user_email));
try {
$service->deleteExternalUserById($this->user_id);
}
catch (EntityNotFoundException $ex){
Log::warning($ex);
}
catch (Exception $ex){
Log::error($ex);
}
}
}

View File

@ -11,7 +11,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Models\Foundation\Main\IGroup;
use models\summit\SummitMetric;
use Illuminate\Support\Facades\App;
@ -38,7 +37,6 @@ use models\summit\SummitRoomReservation;
use models\summit\SummitTrackChair;
use models\utils\SilverstripeBaseModel;
use Doctrine\ORM\Mapping AS ORM;
/**
* @ORM\Table(name="`Member`")
* @ORM\Entity(repositoryClass="App\Repositories\Summit\DoctrineMemberRepository")

View File

@ -66,6 +66,12 @@ interface IMemberService
*/
public function registerExternalUserById($user_external_id):Member;
/**
* @param mixed $user_external_id
* @throws EntityNotFoundException
*/
public function deleteExternalUserById($user_external_id):void;
/**
* @param Member $member
* @param array $groups

View File

@ -370,6 +370,23 @@ final class MemberService
});
}
/**
* @param mixed $user_external_id
* @throws EntityNotFoundException
*/
public function deleteExternalUserById($user_external_id): void
{
$this->tx_service->transaction(function () use ($user_external_id) {
Log::debug(sprintf("MemberService::deleteExternalUserById trying to get user by external id %s", $user_external_id));
$member = $this->member_repository->getByExternalIdExclusiveLock(intval($user_external_id));
// if we dont registered yet a member with that external id try to get by email
if(is_null($member)) {
throw new EntityNotFoundException(sprintf("Member not found (%s)", $user_external_id));
}
Log::debug(sprintf("MemberService::deleteExternalUserById deleting user %s (%s)", $member->getId(), $member->getEmail()));
$this->member_repository->delete($member);
});
}
/**
* @param Member $member
* @param array $groups
@ -575,4 +592,5 @@ final class MemberService
});
}
}