Skip to content

Commit

Permalink
notifications (without Membership accepted )
Browse files Browse the repository at this point in the history
  • Loading branch information
temaotl committed Jul 16, 2024
1 parent c3fbdc7 commit 7c08067
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 6 deletions.
3 changes: 3 additions & 0 deletions app/Jobs/EduGainAddEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use App\Facades\EntityFacade;
use App\Models\Entity;
use App\Notifications\EntityEdugainStatusChanged;
use App\Services\NotificationService;
use App\Traits\EdugainTrait;
use App\Traits\HandlesJobsFailuresTrait;
use Exception;
Expand Down Expand Up @@ -56,6 +58,7 @@ public function handle(): void
$lock->block(61);
EntityFacade::saveEntityMetadataToFolder($this->entity->id, $folderName);

NotificationService::sendEntityNotification($this->entity, new EntityEdugainStatusChanged($this->entity));
EduGainRunMdaScript::dispatch($lock->owner());

} catch (Exception $e) {
Expand Down
4 changes: 3 additions & 1 deletion app/Jobs/EduGainDeleteEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use App\Facades\EntityFacade;
use App\Models\Entity;
use App\Notifications\EntityEdugainStatusChanged;
use App\Services\NotificationService;
use App\Traits\EdugainTrait;
use App\Traits\HandlesJobsFailuresTrait;
use Exception;
Expand Down Expand Up @@ -60,7 +62,7 @@ public function handle(): void
try {
$lock->block(61);
EntityFacade::deleteEntityMetadataFromFolder($this->entity->file, $folderName);

NotificationService::sendEntityNotification($this->entity, new EntityEdugainStatusChanged($this->entity));
EduGainRunMdaScript::dispatch($lock->owner());
} catch (Exception $e) {
Log::error($e->getMessage());
Expand Down
12 changes: 9 additions & 3 deletions app/Jobs/FolderAddEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,16 @@ public function handle(): void
$lock->block(61);
EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id);

if ($this->entity->wasRecentlyCreated) {
NotificationService::sendEntityNotification($this->entity, EntityUpdated::class);
} elseif ($this->entity->wasChanged('deleted_at') && is_null($this->entity->deleted_at)) {
if ($this->entity->wasChanged('deleted_at') && is_null($this->entity->deleted_at)) {
NotificationService::sendEntityNotification($this->entity, EntityStateChanged::class);
} else
{
if($this->entity->wasChanged('approved') && $this->entity->approved == 1) {
NotificationService::sendEntityNotification($this->entity,);
}
else {
NotificationService::sendEntityNotification($this->entity, EntityUpdated::class);
}
}

RunMdaScript::dispatch($federation, $lock->owner());
Expand Down
6 changes: 5 additions & 1 deletion app/Listeners/SendUpdatedEntityToSaveJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
use App\Jobs\EduGainAddEntity;
use App\Jobs\EduGainDeleteEntity;
use App\Jobs\FolderAddEntity;
use App\Notifications\EntityAddedToHfd;
use App\Notifications\EntityAddedToRs;
use App\Notifications\EntityDeletedFromHfd;
use App\Notifications\EntityDeletedFromRs;
use App\Notifications\EntityUpdated;
use App\Services\NotificationService;

Expand All @@ -32,7 +36,7 @@ public function handle(UpdateEntity $event): void
) {
FolderAddEntity::dispatch($event->entity);
} elseif ($entity->approved == 1 && ! $entity->wasChanged('edugain')) {
NotificationService::sendEntityNotification($entity, EntityUpdated::class);
NotificationService::sendUpdateNotification($entity);
}
if ($entity->wasChanged('edugain')) {
if ($entity->edugain == 1) {
Expand Down
45 changes: 44 additions & 1 deletion app/Services/NotificationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@

use App\Models\Entity;
use App\Models\User;
use App\Notifications\EntityAddedToHfd;
use App\Notifications\EntityAddedToRs;
use App\Notifications\EntityDeletedFromHfd;
use App\Notifications\EntityDeletedFromRs;
use App\Notifications\EntityUpdated;
use Illuminate\Support\Facades\Notification;

class NotificationService
{
public static function sendEntityNotification(Entity $entity, $notification)
public static function sendEntityNotification(Entity $entity, $notification): void
{
$admins = User::activeAdmins()->select('id', 'email')->get();

Expand All @@ -21,4 +26,42 @@ public static function sendEntityNotification(Entity $entity, $notification)
Notification::sendNow($entity->operators, new $notification($entity));
Notification::sendNow($filteredAdmins, new $notification($entity));
}

private static function sendRsNotification(Entity $entity): bool
{
if($entity->wasChanged('rs')) {

if($entity->rs == 1) {
self::sendEntityNotification($entity,EntityAddedToRs::class);
} else {
self::sendEntityNotification($entity,EntityDeletedFromRs::class);
}
return true;
}
return false;
}
private static function sendHfDNotification(Entity $entity): bool
{
if ($entity->wasChanged('hfd')) {

if($entity->hfd) {
self::sendEntityNotification($entity,EntityAddedToHfd::class);
} else {
self::sendEntityNotification($entity,EntityDeletedFromHfd::class);
}
return true;
}
return false;
}


public static function sendUpdateNotification(Entity $entity): void
{

if( !self::sendRsNotification($entity) && !self::sendHfDNotification($entity)){
self::sendEntityNotification($entity,EntityUpdated::class);
}

}

}

0 comments on commit 7c08067

Please sign in to comment.