Skip to content

Commit

Permalink
rewrite Entity edugain operators to new EntityEduGainController.php
Browse files Browse the repository at this point in the history
  • Loading branch information
temaotl committed Aug 2, 2024
1 parent a619881 commit 35aea93
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 48 deletions.
44 changes: 0 additions & 44 deletions app/Http/Controllers/EntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

use App\Http\Requests\StoreEntity;
use App\Jobs\GitAddToCategory;
use App\Jobs\GitAddToEdugain;
use App\Jobs\GitAddToHfd;
use App\Jobs\GitDeleteFromCategory;
use App\Jobs\GitDeleteFromEdugain;
use App\Jobs\GitDeleteFromHfd;
use App\Jobs\GitDeleteFromRs;
use App\Ldap\CesnetOrganization;
Expand All @@ -22,7 +20,6 @@
use App\Notifications\EntityDeletedFromHfd;
use App\Notifications\EntityDeletedFromRs;
use App\Notifications\EntityDestroyed;
use App\Notifications\EntityEdugainStatusChanged;
use App\Notifications\EntityRequested;
use App\Notifications\EntityUpdated;
use App\Notifications\IdpCategoryChanged;
Expand Down Expand Up @@ -299,47 +296,6 @@ function () use ($entity) {

break;

case 'edugain':
$this->authorize('update', $entity);

$entity = DB::transaction(function () use ($entity) {
$entity->edugain = $entity->edugain ? false : true;
$entity->update();

return $entity;
});

$status = $entity->edugain ? 'edugain' : 'no_edugain';
$color = $entity->edugain ? 'green' : 'red';

// TODO add and delete from EDUGAIN (functional)
/* if ($entity->edugain) {
Bus::chain([
new GitAddToEdugain($entity, Auth::user()),
function () use ($entity) {
$admins = User::activeAdmins()->select('id', 'email')->get();
Notification::send($entity->operators, new EntityEdugainStatusChanged($entity));
Notification::send($admins, new EntityEdugainStatusChanged($entity));
},
])->dispatch();
} else {
Bus::chain([
new GitDeleteFromEdugain($entity, Auth::user()),
function () use ($entity) {
$admins = User::activeAdmins()->select('id', 'email')->get();
Notification::send($entity->operators, new EntityEdugainStatusChanged($entity));
Notification::send($admins, new EntityEdugainStatusChanged($entity));
},
])->dispatch();
}*/

return redirect()
->back()
->with('status', __("entities.$status"))
->with('color', $color);

break;

case 'rs':
$this->authorize('do-everything');

Expand Down
29 changes: 29 additions & 0 deletions app/Http/Controllers/EntityEduGainController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Http\Controllers;

use App\Models\Entity;
use Illuminate\Support\Facades\DB;

class EntityEduGainController extends Controller
{
public function edugain(Entity $entity)
{
$this->authorize('update', $entity);

$entity = DB::transaction(function () use ($entity) {
$entity->edugain = ! $entity->edugain;
$entity->update();

return $entity;
});

$status = $entity->edugain ? 'edugain' : 'no_edugain';
$color = $entity->edugain ? 'green' : 'red';

return redirect()
->back()
->with('status', __("entities.$status"))
->with('color', $color);
}
}
5 changes: 1 addition & 4 deletions resources/views/entities/partials/edugain.blade.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<form x-data="{ open: false }" class="inline-block" action="{{ route('entities.update', $entity) }}" method="POST">
<form x-data="{ open: false }" class="inline-block" action="{{ route('entities.edugain', $entity) }}" method="POST">
@csrf
@method('patch')

<input type="hidden" name="action" value="edugain">

<input type="checkbox" name="edugainbox" @click.prevent="open = !open"
@if ($entity->edugain) checked @endif>

Expand Down
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\EduidczStatisticController;
use App\Http\Controllers\EntityController;
use App\Http\Controllers\EntityEduGainController;
use App\Http\Controllers\EntityFederationController;
use App\Http\Controllers\EntityManagementController;
use App\Http\Controllers\EntityMetadataController;
Expand Down Expand Up @@ -103,6 +104,7 @@
Route::delete('{entity}/operators', [EntityOperatorController::class, 'destroy'])->name('operators.destroy')->withTrashed();

Route::patch('{entity}/state', [EntityStateController::class, 'state'])->name('state')->withTrashed();
Route::patch('{entity}/edugain', [EntityEduGainController::class, 'edugain'])->name('edugain')->withTrashed();

Route::post('{entity}/rs', [EntityRsController::class, 'store'])->name('rs');

Expand Down

0 comments on commit 35aea93

Please sign in to comment.