Skip to content

Commit

Permalink
rewrite Entity rs operators to EntityRsController.php
Browse files Browse the repository at this point in the history
  • Loading branch information
temaotl committed Aug 2, 2024
1 parent 35aea93 commit 2f41f13
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 55 deletions.
40 changes: 0 additions & 40 deletions app/Http/Controllers/EntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use App\Jobs\GitAddToHfd;
use App\Jobs\GitDeleteFromCategory;
use App\Jobs\GitDeleteFromHfd;
use App\Jobs\GitDeleteFromRs;
use App\Ldap\CesnetOrganization;
use App\Ldap\EduidczOrganization;
use App\Mail\NewIdentityProvider;
Expand All @@ -16,9 +15,7 @@
use App\Models\Federation;
use App\Models\User;
use App\Notifications\EntityAddedToHfd;
use App\Notifications\EntityAddedToRs;
use App\Notifications\EntityDeletedFromHfd;
use App\Notifications\EntityDeletedFromRs;
use App\Notifications\EntityDestroyed;
use App\Notifications\EntityRequested;
use App\Notifications\EntityUpdated;
Expand Down Expand Up @@ -296,43 +293,6 @@ function () use ($entity) {

break;

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

if ($entity->type->value !== 'sp') {
return redirect()
->back()
->with('status', __('categories.rs_controlled_for_sps_only'));
}

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

return $entity;
});

$status = $entity->rs ? 'rs' : 'no_rs';
$color = $entity->rs ? 'green' : 'red';

// TODO notification (not ready ask about this)
/* if ($entity->rs) {
GitAddToRs::dispatch($entity, Auth::user());
Notification::send($entity->operators, new EntityAddedToRs($entity));
Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToRs($entity));
} else {
GitDeleteFromRs::dispatch($entity, Auth::user());
Notification::send($entity->operators, new EntityDeletedFromRs($entity));
Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityDeletedFromRs($entity));
}*/

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

break;

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

Expand Down
32 changes: 27 additions & 5 deletions app/Http/Controllers/EntityRsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@

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

class EntityRsController extends Controller
{
public function __construct()
{

}

public function store(Entity $entity)
{
$this->authorize('update', $entity);
Expand All @@ -26,4 +22,30 @@ public function store(Entity $entity)
->back()
->with('status', __('entities.rs_asked'));
}

public function rsState(Entity $entity)
{
$this->authorize('do-everything');

if ($entity->type->value !== 'sp') {
return redirect()
->back()
->with('status', __('categories.rs_controlled_for_sps_only'));
}

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

return $entity;
});

$status = $entity->rs ? 'rs' : 'no_rs';
$color = $entity->rs ? 'green' : 'red';

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

<x-button @click.prevent="open = !open">{{ __('entities.ask_rs') }}</x-button>
Expand Down
5 changes: 1 addition & 4 deletions resources/views/entities/partials/rs.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.rs.state', $entity) }}" method="POST">
@csrf
@method('patch')

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

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

<x-modal>
Expand Down
3 changes: 2 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@
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');
Route::post('{entity}/rs', [EntityRsController::class, 'store'])->name('rs.store');
Route::patch('{entity}/rs', [EntityRsController::class, 'rsState'])->name('rs.state')->withTrashed();

Route::get('{entity}/metadata', [EntityMetadataController::class, 'store'])->name('metadata');
Route::get('{entity}/showmetadata', [EntityMetadataController::class, 'show'])->name('showmetadata');
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/Http/Controllers/EntityControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ public function ask_rs_isnt_shown_for_sp_entities_not_in_rs_federation()
$this
->followingRedirects()
->actingAs($user)
->post(route('entities.rs', $entity))
->post(route('entities.rs.store', $entity))
->assertStatus(403)
->assertSeeText(__('entities.rs_only_for_eduidcz_members'));

Expand Down Expand Up @@ -1556,7 +1556,7 @@ public function ask_rs_is_shown_for_sp_entities_in_rs_federation()
$this
->followingRedirects()
->actingAs($user)
->post(route('entities.rs', $entity))
->post(route('entities.rs.store', $entity))
->assertStatus(200)
->assertSeeText(__('entities.rs_asked'));

Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/Mail/AskRsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function email_is_queued_for_rs_federation_only()
$this
->followingRedirects()
->actingAs($user)
->post(route('entities.rs', $entity))
->post(route('entities.rs.store', $entity))
->assertStatus(200);

Mail::assertQueued(AskRs::class, function ($email) use ($entity) {
Expand All @@ -56,7 +56,7 @@ public function email_isnt_queued_for_non_rs_federation()

$this
->actingAs($user)
->post(route('entities.rs', $entity))
->post(route('entities.rs.store', $entity))
->assertStatus(403);

Mail::assertNotQueued(AskRs::class);
Expand Down

0 comments on commit 2f41f13

Please sign in to comment.