diff --git a/app/Http/Controllers/FederationManagementController.php b/app/Http/Controllers/FederationManagementController.php deleted file mode 100644 index 750b0e0..0000000 --- a/app/Http/Controllers/FederationManagementController.php +++ /dev/null @@ -1,155 +0,0 @@ -authorize('do-everything'); - - $this->initializeGit(); - - $cfgfiles = []; - foreach (Storage::files() as $file) { - if (preg_match('/^'.config('git.edugain_cfg').'$/', $file)) { - continue; - } - - if (preg_match('/\.cfg$/', $file)) { - $cfgfiles[] = $file; - } - } - - $federations = Federation::select('cfgfile')->get()->pluck('cfgfile')->toArray(); - - $unknown = []; - foreach ($cfgfiles as $cfgfile) { - if (in_array($cfgfile, $federations)) { - continue; - } - - $content = Storage::get($cfgfile); - preg_match('/\[(.*)\]/', $content, $xml_id); - preg_match('/filters\s*=\s*(.*)/', $content, $filters); - preg_match('/name\s*=\s*(.*)/', $content, $name); - - $unknown[$cfgfile]['cfgfile'] = $cfgfile; - $unknown[$cfgfile]['xml_id'] = $xml_id[1]; - $unknown[$cfgfile]['filters'] = $filters[1]; - $unknown[$cfgfile]['name'] = $name[1]; - } - - if (empty($unknown)) { - return redirect() - ->route('federations.index') - ->with('status', __('federations.nothing_to_import')); - } - - return view('federations.import', [ - 'federations' => $unknown, - ]); - } - - public function store(Request $request) - { - $this->authorize('do-everything'); - - if (empty(request('federations'))) { - return back() - ->with('status', __('federations.empty_import')) - ->with('color', 'red'); - } - - $imported = 0; - $names = request('names'); - $descriptions = request('descriptions'); - foreach (request('federations') as $cfgfile) { - $content = Storage::get($cfgfile); - preg_match('/\[(.*)\]/', $content, $xml_id); - preg_match('/filters\s*=\s*(.*)/', $content, $filters); - preg_match('/name\s*=\s*(.*)/', $content, $xml_name); - - if (empty($names[$cfgfile])) { - $names[$cfgfile] = preg_replace('/\.cfg$/', '', $cfgfile); - } - - if (empty($descriptions[$cfgfile])) { - $descriptions[$cfgfile] = preg_replace('/\.cfg$/', '', $cfgfile); - } - - DB::transaction(function () use ($cfgfile, $names, $descriptions, $xml_id, $xml_name, $filters) { - $federation = Federation::create([ - 'name' => $names[$cfgfile], - 'description' => $descriptions[$cfgfile], - 'tagfile' => preg_replace('/\.cfg$/', '.tag', $cfgfile), - 'cfgfile' => $cfgfile, - 'xml_id' => $xml_id[1], - 'xml_name' => $xml_name[1], - 'filters' => $filters[1], - 'explanation' => 'Imported from Git repository.', - ]); - - $federation->approved = true; - $federation->update(); - }); - - // FIXME: Notification - - $imported++; - } - - return redirect('federations') - ->with('status', trans_choice('federations.imported', $imported)); - } - - public function update() - { - $this->authorize('do-everything'); - - $this->initializeGit(); - - $cfgfiles = []; - foreach (Storage::files() as $file) { - if (preg_match('/\.cfg/', $file)) { - $cfgfiles[] = $file; - } - } - - $federations = Federation::select('cfgfile')->get()->pluck('cfgfile')->toArray(); - - $refreshed = 0; - foreach ($cfgfiles as $cfgfile) { - if (! in_array($cfgfile, $federations)) { - continue; - } - - $content = Storage::get($cfgfile); - preg_match('/\[(.*)\]/', $content, $xml_id); - preg_match('/filters\s*=\s*(.*)/', $content, $filters); - preg_match('/name\s*=\s*(.*)/', $content, $xml_name); - - $federation = Federation::whereCfgfile($cfgfile)->first(); - $federation->update([ - 'xml_id' => $xml_id[1], - 'xml_name' => $xml_name[1], - 'filters' => $filters[1], - ]); - - if ($federation->wasChanged()) { - $refreshed++; - } - } - - return redirect('federations') - ->with('status', trans_choice('federations.refreshed', $refreshed)); - } -} diff --git a/resources/views/federations/index.blade.php b/resources/views/federations/index.blade.php index 91a5e47..ca929a1 100644 --- a/resources/views/federations/index.blade.php +++ b/resources/views/federations/index.blade.php @@ -1,11 +1,6 @@ @extends('layouts.index') @section('title', __('common.federations')) -@section('adminOnly_action') - {{ __('common.import') }} - {{ __('common.refresh') }} -@endsection - @section('create') {{ __('common.add') }} @endsection diff --git a/routes/web.php b/routes/web.php index 8e878be..4b79565 100644 --- a/routes/web.php +++ b/routes/web.php @@ -56,32 +56,6 @@ Route::get('fakelogout', [FakeController::class, 'destroy'])->name('fakelogout'); } -// Federation group -Route::group(['prefix' => 'federations', 'as' => 'federations.', 'middleware' => ['auth']], function () { - - Route::get('import', [FederationManagementController::class, 'index'])->name('unknown'); - Route::post('import', [FederationManagementController::class, 'store'])->name('import'); - Route::get('refresh', [FederationManagementController::class, 'update'])->name('refresh'); - - Route::get('{federation}/requests', [FederationJoinController::class, 'index'])->name('requests')->withTrashed(); - - Route::resource('{federation}/operators', FederationOperatorController::class)->only(['index', 'store'])->withTrashed(); - Route::delete('{federation}/operators', [FederationOperatorController::class, 'destroy'])->name('operators.destroy')->withTrashed(); - - Route::resource('{federation}/entities', FederationEntityController::class)->only(['index', 'store'])->withTrashed(); - Route::delete('{federation}/entities', [FederationEntityController::class, 'destroy'])->name('entities.destroy')->withTrashed(); - - Route::patch('{federation}/state', [FederationStateController::class, 'state'])->name('state')->withTrashed(); - - Route::post('{federation}/approve', [FederationApprovalController::class, 'store'])->name('approve'); - Route::delete('{federation}/reject', [FederationApprovalController::class, 'destroy'])->name('reject'); - - Route::resource('/', FederationController::class)->parameters(['' => 'federation'])->withTrashed(); - Route::get('{federation}', [FederationController::class, 'show'])->name('show')->withTrashed(); - Route::match(['put', 'patch'], '{federation}', [FederationController::class, 'update'])->name('update')->withTrashed(); - Route::delete('{federation}', [FederationController::class, 'destroy'])->name('destroy')->withTrashed(); -}); - // Entities groups Route::group(['prefix' => 'entities', 'as' => 'entities.', 'middleware' => ['auth']], function () { @@ -122,10 +96,37 @@ }); Route::middleware('auth')->group(function () { + // Dashboard Route::view('dashboard', 'dashboard')->name('dashboard'); + + // Federations + Route::post('federations/{federation}/approve', [FederationApprovalController::class, 'store'])->name('federations.approve'); + Route::delete('federations/{federation}/reject', [FederationApprovalController::class, 'destroy'])->name('federations.reject'); + + Route::patch('federations/{federation}/state', [FederationStateController::class, 'state'])->name('federations.state')->withTrashed(); + + Route::get('federations/{federation}/requests', [FederationJoinController::class, 'index'])->name('federations.requests')->withTrashed(); + + Route::get('federations/{federation}/operators', [FederationOperatorController::class, 'index'])->name('federations.operators.index')->withTrashed(); + Route::post('federations/{federation}/operators', [FederationOperatorController::class, 'store'])->name('federations.operators.store')->withTrashed(); + Route::delete('federations/{federation}/operators', [FederationOperatorController::class, 'destroy'])->name('federations.operators.destroy')->withTrashed(); + + Route::get('federations/{federation}/entities', [FederationEntityController::class, 'index'])->name('federations.entities.index')->withTrashed(); + Route::post('federations/{federation}/entities', [FederationEntityController::class, 'store'])->name('federations.entities.store')->withTrashed(); + Route::delete('federations/{federation}/entities', [FederationEntityController::class, 'destroy'])->name('federations.entities.destroy')->withTrashed(); + + Route::resource('federations', FederationController::class)->withTrashed(); + + // Categories Route::resource('categories', CategoryController::class)->only('index', 'show'); + + // Groups Route::resource('groups', GroupController::class)->only('index', 'show'); + + // Users Route::resource('users', UserController::class)->except('edit', 'destroy'); + + // Memberships Route::resource('memberships', MembershipController::class)->only('update', 'destroy'); });