diff --git a/app/Http/Controllers/EntityController.php b/app/Http/Controllers/EntityController.php index f89a5d8..f3202a0 100644 --- a/app/Http/Controllers/EntityController.php +++ b/app/Http/Controllers/EntityController.php @@ -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; @@ -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; @@ -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'); diff --git a/app/Http/Controllers/EntityRsController.php b/app/Http/Controllers/EntityRsController.php index 1f5a5ef..4340327 100644 --- a/app/Http/Controllers/EntityRsController.php +++ b/app/Http/Controllers/EntityRsController.php @@ -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); @@ -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); + } } diff --git a/resources/views/entities/partials/askrs.blade.php b/resources/views/entities/partials/askrs.blade.php index bab34b2..d6c0df0 100644 --- a/resources/views/entities/partials/askrs.blade.php +++ b/resources/views/entities/partials/askrs.blade.php @@ -1,4 +1,4 @@ -
+ @csrf {{ __('entities.ask_rs') }} diff --git a/resources/views/entities/partials/rs.blade.php b/resources/views/entities/partials/rs.blade.php index 0728a5b..1a691ec 100644 --- a/resources/views/entities/partials/rs.blade.php +++ b/resources/views/entities/partials/rs.blade.php @@ -1,9 +1,6 @@ - + @csrf @method('patch') - - - rs) checked @endif> diff --git a/routes/web.php b/routes/web.php index 16b0fbd..0c1bd71 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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'); diff --git a/tests/Feature/Http/Controllers/EntityControllerTest.php b/tests/Feature/Http/Controllers/EntityControllerTest.php index 131a4e3..7faa696 100644 --- a/tests/Feature/Http/Controllers/EntityControllerTest.php +++ b/tests/Feature/Http/Controllers/EntityControllerTest.php @@ -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')); @@ -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')); diff --git a/tests/Feature/Mail/AskRsTest.php b/tests/Feature/Mail/AskRsTest.php index 631f109..2bcc7d0 100644 --- a/tests/Feature/Mail/AskRsTest.php +++ b/tests/Feature/Mail/AskRsTest.php @@ -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) { @@ -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);