Skip to content

Commit

Permalink
made add in group by entity window
Browse files Browse the repository at this point in the history
  • Loading branch information
temaotl committed Dec 9, 2024
1 parent a59a439 commit cef6b58
Show file tree
Hide file tree
Showing 14 changed files with 308 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/Console/Commands/PrepareTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PrepareTestCase extends Command implements Isolatable
*
* @var string
*/
protected $signature = 'app:prefed';
protected $signature = 'app:pre';

/**
* The console command description.
Expand Down
60 changes: 60 additions & 0 deletions app/Http/Controllers/EntityCategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,70 @@
use App\Models\Entity;
use App\Models\User;
use App\Notifications\IdpCategoryChanged;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Notification;

class EntityCategoryController extends Controller
{
/**
* Display a listing of the resource.
*
* @throws AuthorizationException if do-everything not define in provider
*/
public function index(Entity $entity)
{
$this->authorize('do-everything');
$categories = $entity->category() ? $entity->category()->get() : collect();
$joinable = Category::orderBy('name')
->whereNotIn('id', $categories->pluck('id'))
->get();

return view('entities.categories', [
'entity' => $entity,
'categories' => $categories,
'joinable' => $joinable,
]);

}

/**
* Store a newly created resource in storage.
*/
public function store(Request $request, Entity $entity)
{
$this->authorize('do-everything');

if (empty(request('category'))) {
return back()
->with('status', __('entities.join_empty_category'))
->with('color', 'red');
}
$entity->category()->associate(request('category'));
$entity->save();

return redirect()
->back()
->with('status', __('entities.join_category', [
'name' => Category::findOrFail($request->input('category'))->name,
]));
}

/**
* Remove the specified resource from storage.
*/
public function destroy(Request $request, Entity $entity)
{
$this->authorize('do-everything');
$entity->category()->dissociate();
$entity->save();

return redirect()
->back()
->with('status', __('entities.leave_category'));

}

public function update(Entity $entity)
{
$this->authorize('do-everything');
Expand Down
72 changes: 72 additions & 0 deletions app/Http/Controllers/EntityGroupController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace App\Http\Controllers;

use App\Models\Entity;
use App\Models\Group;
use Illuminate\Http\Request;

class EntityGroupController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(Entity $entity)
{
$this->authorize('do-everything');

$groups = $entity->groups() ? $entity->groups()->get() : collect();
$joinable = Group::orderBy('name')
->whereNotIn('id', $groups->pluck('id'))
->get();

return view('entities.groups', [
'entity' => $entity,
'groups' => $groups,
'joinable' => $joinable,
]);

}

/**
* Store a newly created resource in storage.
*/
public function store(Request $request, Entity $entity)
{
$this->authorize('do-everything');

if (empty(request('group'))) {
return back()
->with('status', __('entities.join_empty_group'))
->with('color', 'red');
}

$entity->groups()->attach(request('group'));

return redirect()
->back()
->with('status', __('entities.join_group'));
}

/**
* Remove the specified resource from storage.
*/
public function destroy(Entity $entity)
{
$this->authorize('do-everything');

if (empty(request('groups'))) {
return back()
->with('status', __('entities.leave_empty_group'))
->with('color', 'red');
}
$entity
->groups()
->detach(request('groups'));

return redirect()
->back()
->with('status', __('entities.leave_group'));

}
}
2 changes: 2 additions & 0 deletions lang/cs/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,6 @@
'confirm' => 'Potvrdit',
'organization' => 'Organizace',
'add_sp_idp' => 'Přidat IdP a Sp feedy',
'confirm_leave_groups' => 'Opustit skupiny?',
'confirm_leave_groups_body' => 'Opravdu chcete opustit zvolené skupiny?',
];
7 changes: 7 additions & 0 deletions lang/cs/entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,11 @@
'organization_assigned' => 'Organizace byla úspěšně přiřazena.',
'not_yet_approved' => 'Tato entity ještě není schválená, proto nelze požadavek provést.',
'without_federation' => 'Tato entity nemá přidělenout federaci',

'join_empty_group' => 'Nezvolili jste žádnou skupinu k připojení.',
'join_group' => 'Připojit ke skupině',
'leave_empty_group' => 'Nezvolili jste žádnou skupinu k opuštění.',
'leave_group' => 'Opustit skupinu',
'choose_group_placeholder' => 'Zvolte skupinu, v níž bude entita členem',
'not_part_of_a_group' => 'Tato entita není členem žádné skupiny.',
];
1 change: 1 addition & 0 deletions lang/cs/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
'profile' => 'Profil skupiny',
'searchbox' => 'Hledat skupinu podle jména, popisu nebo .tag souboru...',
'show' => 'Skupina :name',
'no_members' => 'Tato entita není součástí žádnou skupiny',
];
2 changes: 2 additions & 0 deletions lang/en/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,6 @@
'confirm' => 'Confirm',
'organization' => 'Organization',
'add_sp_idp' => 'Add additional IdP and Sp feeds',
'confirm_leave_groups' => 'Leave groups?',
'confirm_leave_groups_body' => 'Would you really like to leave the selected groups?',
];
7 changes: 7 additions & 0 deletions lang/en/entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,11 @@
'organization_assigned' => 'Organization has been successfully assigned.',
'not_yet_approved' => "This entity isn't approved, yet, thus the request cannot be completed.",
'without_federation' => 'This entity does not have any federations.',

'join_empty_group' => 'You have not selected any group to join.',
'join_group' => 'Join group',
'leave_empty_group' => 'You have not selected any group to leave.',
'leave_group' => 'Leave group',
'choose_group_placeholder' => 'Choose a group to be a member of',
'not_part_of_a_group' => 'This entity is not a member of any group.',
];
1 change: 1 addition & 0 deletions lang/en/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
'profile' => "Group's profile",
'searchbox' => 'Search groups by name, description or tagfile...',
'show' => ':name Group',
'no_members' => 'This entity is not part of a group ',
];
51 changes: 51 additions & 0 deletions resources/views/entities/groupForm/add.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<form x-data="{ open: false }" id="add_members" action="{{ route('entities.group.join', $entity) }}"
method="post">
@csrf
<div class="overflow-x-auto bg-white border rounded-lg">
<table class="min-w-full border-b border-gray-300">
<thead>
<tr>
<th class="px-6 py-3 text-xs tracking-widest text-left uppercase bg-gray-100 border-b">&nbsp;
</th>
<th class="px-6 py-3 text-xs tracking-widest text-left uppercase bg-gray-100 border-b">
{{ __('common.name') }}</th>
<th class="px-6 py-3 text-xs tracking-widest text-left uppercase bg-gray-100 border-b">
{{ __('common.description') }}</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200">
@forelse ($joinable as $group)
<tr x-data class="hover:bg-blue-50" role="button"
@click="checkbox = $el.querySelector('input[type=checkbox]'); checkbox.checked = !checkbox.checked">
<td class="px-6 py-3 text-sm">
<input @click.stop class="rounded" type="checkbox" name="group[]"
value="{{ $group->id }}">
</td>
<td class="whitespace-nowrap px-6 py-3 text-sm">
{{ $group->name }}
</td>
<td class="px-6 py-3 text-sm">
{{ $group->description }}
</td>
</tr>
@empty
<tr class="hover:bg-blue-50">
<td class="px-6 py-3 font-bold text-center">
{{ __('groups.empty') }}
</td>
</tr>
@endforelse
</tbody>
</table>
@if (count($joinable))
<div class="px-4 py-2 bg-gray-100">
<x-button @click.prevent="open = !open">{{ __('common.add_members') }}</x-button>

<x-modal>
<x-slot:title>{{ __('common.confirm_add_members') }}</x-slot:title>
{{ __('common.confirm_add_members_body') }}
</x-modal>
</div>
@endif
</div>
</form>
53 changes: 53 additions & 0 deletions resources/views/entities/groupForm/delete.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<form x-data="{ open: false }" id="delete_members" action="{{ route('entities.group.leave', $entity) }}"
method="post">
@csrf
@method('DELETE')
<div class="overflow-x-auto bg-white border rounded-lg">
<table class="min-w-full border-b border-gray-300">
<thead>
<tr>
<th class="px-6 py-3 text-xs tracking-widest text-left uppercase bg-gray-100 border-b">&nbsp;</th>
<th class="px-6 py-3 text-xs tracking-widest text-left uppercase bg-gray-100 border-b">
{{ __('common.name') }}
</th>
<th class="px-6 py-3 text-xs tracking-widest text-left uppercase bg-gray-100 border-b">
{{ __('common.description') }}
</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200">
@forelse ($groups as $group)
<tr x-data class="hover:bg-blue-50" role="button"
@click="checkbox = $el.querySelector('input[type=checkbox]'); checkbox.checked = !checkbox.checked">
<td class="px-6 py-3 text-sm">
<input @click.stop class="rounded" type="checkbox" name="groups[]"
value="{{ $group->id }}">
</td>
<td class="whitespace-nowrap px-6 py-3 text-sm">
{{ $group->name }}
</td>
<td class="px-6 py-3 text-sm">
{{ $group->description }}
</td>
</tr>
@empty
<tr class="hover:bg-blue-50">
<td class="px-6 py-3 font-bold text-center" colspan="4">
{{ __('groups.no_members') }}
</td>
</tr>
@endforelse
</tbody>
</table>
@if (count($groups))
<div class="px-4 py-2 bg-gray-100">
<x-button color="red" @click.prevent="open = !open">{{ __('common.delete_members') }}</x-button>

<x-modal>
<x-slot:title>{{ __('common.confirm_delete_members') }}</x-slot:title>
{{ __('common.confirm_delete_members_body') }}
</x-modal>
</div>
@endif
</div>
</form>
26 changes: 26 additions & 0 deletions resources/views/entities/groups.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@extends('layout')
@section('title', __('entities.show', ['name' => $entity->{"name_$locale"}]))

@section('content')

@include('entities.navigation')

@can('do-everything')

<div class="mb-4">
<h3 class="text-lg font-semibold">
{{ __('common.delete_members') }}
</h3>
@include('entities.groupForm.delete')
</div>

<div>
<h3 class="text-lg font-semibold">
{{ __('common.add_members') }}
</h3>
@include('entities.groupForm.add')
</div>

@endcan

@endsection
20 changes: 20 additions & 0 deletions resources/views/entities/navigation.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,24 @@
'cursor-default' => request()->routeIs('entities.federations'),
])
href="{{ route('entities.federations', $entity) }}">{{ __('common.federations') }}</a>

@can('do-everything')
<a @class([
'px-2',
'py-1',
'mr-2',
'rounded-lg',
'shadow',
'bg-gray-300' => request()->routeIs('entities.category '),
'bg-blue-100 hover:bg-blue-300' => !request()->routeIs(
'entities.category '
),
'cursor-default' => request()->routeIs('entities.category '),
])
href="{{ route('entities.groups', $entity) }}">{{ __('common.groups') }}</a>

@endcan



</div>
5 changes: 5 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Http\Controllers\EntityController;
use App\Http\Controllers\EntityEduGainController;
use App\Http\Controllers\EntityFederationController;
use App\Http\Controllers\EntityGroupController;
use App\Http\Controllers\EntityHfdController;
use App\Http\Controllers\EntityMetadataController;
use App\Http\Controllers\EntityOperatorController;
Expand Down Expand Up @@ -94,13 +95,17 @@
Route::get('entities/{entity}/showmetadata', [EntityMetadataController::class, 'show'])->name('entities.showmetadata');

Route::get('entities/{entity}/federations', [EntityFederationController::class, 'index'])->name('entities.federations')->withTrashed();
Route::get('entities/{entity}/group', [EntityGroupController::class, 'index'])->name('entities.groups')->withTrashed();

Route::middleware('throttle:anti-ddos-limit')->group(function () {
Route::post('entities/{entity}/join', [EntityFederationController::class, 'store'])->name('entities.join');
Route::post('entities/{entity}/leave', [EntityFederationController::class, 'destroy'])->name('entities.leave');
Route::patch('entities/{entity}/state', [EntityStateController::class, 'update'])->name('entities.state')->withTrashed();
Route::patch('entities/{entity}/edugain', [EntityEduGainController::class, 'update'])->name('entities.edugain');
Route::match(['put', 'patch'], 'entities/{entity}', [EntityController::class, 'update'])->name('entities.update')->withTrashed();

Route::post('entities/{entity}/group/join', [EntityGroupController::class, 'store'])->name('entities.group.join');
Route::delete('entities/{entity}/group/leave', [EntityGroupController::class, 'destroy'])->name('entities.group.leave')->withTrashed();
});

Route::resource('entities', EntityController::class)->except('update')->withTrashed(['show', 'destroy']);
Expand Down

0 comments on commit cef6b58

Please sign in to comment.