Skip to content

Commit

Permalink
no useful category rewriting
Browse files Browse the repository at this point in the history
  • Loading branch information
temaotl committed Aug 2, 2024
1 parent 2f41f13 commit fb934bd
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 39 deletions.
45 changes: 45 additions & 0 deletions app/Http/Controllers/EntityCategoryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Http\Controllers;

use App\Models\Category;
use App\Models\Entity;

class EntityCategoryController extends Controller
{
public function store(Entity $entity)
{
$this->authorize('do-everything');

if (empty(request('category'))) {
return redirect()
->back()
->with('status', __('categories.no_category_selected'))
->with('color', 'red');
}

$category = Category::findOrFail(request('category'));
$entity->category()->associate($category);
$entity->save();

// TODO work with category (not ready)
/* Bus::chain([
new GitDeleteFromCategory($old_category, $entity, Auth::user()),
new GitAddToCategory($category, $entity, Auth::user()),
function () use ($entity, $category) {
$admins = User::activeAdmins()->select('id', 'email')->get();
Notification::send($admins, new IdpCategoryChanged($entity, $category));
},
])->dispatch();*/

if (! $entity->wasChanged()) {
return redirect()
->back();
}

return redirect()
->route('entities.show', $entity)
->with('status', __('entities.category_updated'));

}
}
39 changes: 0 additions & 39 deletions app/Http/Controllers/EntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
namespace App\Http\Controllers;

use App\Http\Requests\StoreEntity;
use App\Jobs\GitAddToCategory;
use App\Jobs\GitAddToHfd;
use App\Jobs\GitDeleteFromCategory;
use App\Jobs\GitDeleteFromHfd;
use App\Ldap\CesnetOrganization;
use App\Ldap\EduidczOrganization;
Expand All @@ -19,7 +17,6 @@
use App\Notifications\EntityDestroyed;
use App\Notifications\EntityRequested;
use App\Notifications\EntityUpdated;
use App\Notifications\IdpCategoryChanged;
use App\Traits\DumpFromGit\EntitiesHelp\DeleteFromEntity;
use App\Traits\DumpFromGit\EntitiesHelp\UpdateEntity;
use App\Traits\GitTrait;
Expand Down Expand Up @@ -293,42 +290,6 @@ function () use ($entity) {

break;

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

if (empty(request('category'))) {
return redirect()
->back()
->with('status', __('categories.no_category_selected'))
->with('color', 'red');
}

$old_category = $entity->category ?? null;
$category = Category::findOrFail(request('category'));
$entity->category()->associate($category);
$entity->save();

// TODO work with category (not ready)
/* Bus::chain([
new GitDeleteFromCategory($old_category, $entity, Auth::user()),
new GitAddToCategory($category, $entity, Auth::user()),
function () use ($entity, $category) {
$admins = User::activeAdmins()->select('id', 'email')->get();
Notification::send($admins, new IdpCategoryChanged($entity, $category));
},
])->dispatch();*/

if (! $entity->wasChanged()) {
return redirect()
->back();
}

return redirect()
->route('entities.show', $entity)
->with('status', __('entities.category_updated'));

break;

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

Expand Down
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use App\Http\Controllers\CategoryManagementController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\EduidczStatisticController;
use App\Http\Controllers\EntityCategoryController;
use App\Http\Controllers\EntityController;
use App\Http\Controllers\EntityEduGainController;
use App\Http\Controllers\EntityFederationController;
Expand Down Expand Up @@ -109,6 +110,8 @@
Route::post('{entity}/rs', [EntityRsController::class, 'store'])->name('rs.store');
Route::patch('{entity}/rs', [EntityRsController::class, 'rsState'])->name('rs.state')->withTrashed();

Route::post('{entity}/category', [EntityCategoryController::class, 'store'])->name('category.store');

Route::get('{entity}/metadata', [EntityMetadataController::class, 'store'])->name('metadata');
Route::get('{entity}/showmetadata', [EntityMetadataController::class, 'show'])->name('showmetadata');
Route::get('{entity}/previewmetadata', [EntityPreviewMetadataController::class, 'show'])->name('previewmetadata');
Expand Down

0 comments on commit fb934bd

Please sign in to comment.