Commit af8c6b14 authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

Add page to show users that can access a door

parent 0e5df5e4
Pipeline #12524 failed with stages
in 1 minute and 33 seconds
...@@ -165,7 +165,6 @@ class UsersController extends ApiController ...@@ -165,7 +165,6 @@ class UsersController extends ApiController
* @throws \Illuminate\Validation\ValidationException * @throws \Illuminate\Validation\ValidationException
* @throws \Source\Exceptions\EntityNotFoundException * @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\AuthorizationException * @throws \Source\Exceptions\AuthorizationException
* @throws \Source\Exceptions\EntityExistsException
*/ */
public function update(UpdateUserUseCase $updateUser, string $userId): JsonResponse public function update(UpdateUserUseCase $updateUser, string $userId): JsonResponse
{ {
......
...@@ -14,13 +14,15 @@ use Source\UseCases\Groups\GetGroups\GetGroupsUseCase; ...@@ -14,13 +14,15 @@ use Source\UseCases\Groups\GetGroups\GetGroupsUseCase;
use Source\UseCases\Doors\CreateDoor\CreateDoorUseCase; use Source\UseCases\Doors\CreateDoor\CreateDoorUseCase;
use Source\UseCases\Doors\DeleteDoor\DeleteDoorUseCase; use Source\UseCases\Doors\DeleteDoor\DeleteDoorUseCase;
use Source\UseCases\Doors\UpdateDoor\UpdateDoorUseCase; use Source\UseCases\Doors\UpdateDoor\UpdateDoorUseCase;
use Source\UseCases\DoorUser\UserDoorAccess\UsersWebPresenter;
use Source\UseCases\Doors\CreateDoor\WebTokenGeneratePresenter; use Source\UseCases\Doors\CreateDoor\WebTokenGeneratePresenter;
use Source\UseCases\DoorGroup\GetDoorGroups\GetDoorGroupsUseCase; use Source\UseCases\DoorGroup\GetDoorGroups\GetDoorGroupsUseCase;
use Source\UseCases\DoorGroup\AddDoorToGroup\AddDoorToGroupUseCase; use Source\UseCases\DoorUser\UserDoorAccess\UserDoorAccessUseCase;
use Source\UseCases\Doors\GetDoor\APIPresenter as GetDoorPresenter; use Source\UseCases\Doors\GetDoor\APIPresenter as GetDoorPresenter;
use Source\UseCases\Doors\GenerateDoorToken\GenerateDoorTokenUseCase; use Source\UseCases\DoorGroup\AddDoorToGroup\AddDoorToGroupUseCase;
use Source\UseCases\Doors\GetDoors\WebPresenter as GetDoorsPresenter; use Source\UseCases\Doors\GetDoors\WebPresenter as GetDoorsPresenter;
use Source\UseCases\Groups\GetGroups\WebPresenter as GroupsPresenter; use Source\UseCases\Groups\GetGroups\WebPresenter as GroupsPresenter;
use Source\UseCases\Doors\GenerateDoorToken\GenerateDoorTokenUseCase;
use Source\UseCases\Doors\CreateDoor\WebPresenter as CreateDoorPresenter; use Source\UseCases\Doors\CreateDoor\WebPresenter as CreateDoorPresenter;
use Source\UseCases\Doors\DeleteDoor\APIPresenter as DeleteDoorPresenter; use Source\UseCases\Doors\DeleteDoor\APIPresenter as DeleteDoorPresenter;
use Source\UseCases\Doors\UpdateDoor\APIPresenter as UpdateDoorPresenter; use Source\UseCases\Doors\UpdateDoor\APIPresenter as UpdateDoorPresenter;
...@@ -225,4 +227,24 @@ class DoorsController extends Controller ...@@ -225,4 +227,24 @@ class DoorsController extends Controller
return redirect()->back()->with($presenter->getViewModel()); return redirect()->back()->with($presenter->getViewModel());
} }
/**
* @param string $doorId
* @param \Source\UseCases\DoorUser\UserDoorAccess\UserDoorAccessUseCase $doorUsers
* @return \Illuminate\View\View
* @throws \Source\Exceptions\EntityNotFoundException
*/
public function users(string $doorId, UserDoorAccessUseCase $doorUsers): View
{
$presenter = new UsersWebPresenter();
$doorUsers->getDoorUserRelationships($doorId, $presenter);
return view('layouts.admin.tableData', array_merge(
$presenter->getViewModel(),
[
'route' => route('web.admin.doors.users', ['doorId' => $doorId]),
]
));
}
} }
<a class="btn btn-success" href="{{ route('web.admin.doors.users', ['doorId' => $id]) }}" data-toggle="tooltip" title="View users that have access to the door.">
<i class="fas fa-users"></i>
</a>
<a class="btn btn-secondary" href="{{ route('web.admin.doors.groups', ['doorId' => $id]) }}" data-toggle="tooltip" title="Manage groups for the door."> <a class="btn btn-secondary" href="{{ route('web.admin.doors.groups', ['doorId' => $id]) }}" data-toggle="tooltip" title="Manage groups for the door.">
<i class="fas fa-object-group"></i> <i class="fas fa-object-group"></i>
</a> </a>
......
...@@ -71,6 +71,7 @@ Route::name('web.')->middleware(['auth:api'])->group(static function () { ...@@ -71,6 +71,7 @@ Route::name('web.')->middleware(['auth:api'])->group(static function () {
Route::get('/{doorId}', [DoorsController::class, 'schedule'])->name('schedule'); Route::get('/{doorId}', [DoorsController::class, 'schedule'])->name('schedule');
Route::post('/{doorId}/regenerate-token', [DoorsController::class, 'regenerateToken'])->name('regenerate'); Route::post('/{doorId}/regenerate-token', [DoorsController::class, 'regenerateToken'])->name('regenerate');
Route::get('/{doorId}/users', [DoorsController::class, 'users'])->name('users');
Route::get('/{doorId}/groups', [DoorsController::class, 'groups'])->name('groups'); Route::get('/{doorId}/groups', [DoorsController::class, 'groups'])->name('groups');
Route::post('/{doorId}/groups', [DoorsController::class, 'addGroup'])->name('addGroup'); Route::post('/{doorId}/groups', [DoorsController::class, 'addGroup'])->name('addGroup');
Route::delete('/{doorId}/groups', [DoorsController::class, 'removeGroup'])->name('removeGroup'); Route::delete('/{doorId}/groups', [DoorsController::class, 'removeGroup'])->name('removeGroup');
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Source\UseCases\DoorUser\UserDoorAccess; namespace Source\UseCases\DoorUser\UserDoorAccess;
use Source\Entities\Door; use Source\Entities\Door;
use Source\Entities\User;
use Source\Entities\Group; use Source\Entities\Group;
use Source\Entities\Schedule; use Source\Entities\Schedule;
...@@ -13,6 +14,11 @@ class ResponseModel ...@@ -13,6 +14,11 @@ class ResponseModel
*/ */
protected array $groupDoorMap = []; protected array $groupDoorMap = [];
/**
* @var \Source\Entities\User[]
*/
protected array $userGroupMap = [];
/** /**
* @var \Source\Entities\Schedule[] * @var \Source\Entities\Schedule[]
*/ */
...@@ -57,6 +63,19 @@ class ResponseModel ...@@ -57,6 +63,19 @@ class ResponseModel
} }
} }
/**
* @param string $groupId
* @param \Source\Entities\User $user
*/
public function addUserToGroup(string $groupId, User $user): void
{
if (isset($this->userGroupMap[$groupId])) {
$this->userGroupMap[$groupId][] = $user;
} else {
$this->userGroupMap[$groupId] = [$user];
}
}
/** /**
* @return \Source\Entities\Group[] * @return \Source\Entities\Group[]
*/ */
...@@ -82,4 +101,13 @@ class ResponseModel ...@@ -82,4 +101,13 @@ class ResponseModel
{ {
return $this->groupScheduleMap[$group->getId()] ?? []; return $this->groupScheduleMap[$group->getId()] ?? [];
} }
/**
* @param \Source\Entities\Group $group
* @return \Source\Entities\User[]
*/
public function getUsersForGroup(Group $group): array
{
return $this->userGroupMap[$group->getId()] ?? [];
}
} }
...@@ -70,4 +70,40 @@ class UserDoorAccess implements UserDoorAccessUseCase ...@@ -70,4 +70,40 @@ class UserDoorAccess implements UserDoorAccessUseCase
$presenter->present($response); $presenter->present($response);
} }
/**
* @inheritDoc
*/
public function getDoorUserRelationships(string $doorId, Presenter $presenter): void
{
$response = new ResponseModel();
$groups = $this->doorGroupRepository->getGroupsForDoor($doorId);
foreach ($groups as $group) {
$response->addGroup($group);
$groupId = $group->getId();
$users = $this->groupUserRepository->getUsersForGroup($groupId);
$schedules = [];
try {
$schedules = $this->schedulesRepository->getSchedulesForGroup($groupId);
} catch (EntityNotFoundException $e) {
}
foreach ($users as $user) {
$response->addUserToGroup($groupId, $user);
}
foreach ($schedules as $schedule) {
if ($schedule->hasTypeOf(Schedule::TYPE_USER_ACCESS)) {
$response->addScheduleToGroup($groupId, $schedule);
}
}
}
$presenter->present($response);
}
} }
...@@ -13,4 +13,14 @@ interface UserDoorAccessUseCase ...@@ -13,4 +13,14 @@ interface UserDoorAccessUseCase
* @throws \Source\Exceptions\EntityNotFoundException * @throws \Source\Exceptions\EntityNotFoundException
*/ */
public function getUserDoorRelationships(string $userId, Presenter $presenter): void; public function getUserDoorRelationships(string $userId, Presenter $presenter): void;
/**
* Gets a door and their user-schedule-group relationships
*
* @param string $doorId
* @param \Source\UseCases\DoorUser\UserDoorAccess\Presenter $presenter
* @throws \Source\Exceptions\EntityNotFoundException
*/
public function getDoorUserRelationships(string $doorId, Presenter $presenter): void;
} }
<?php
namespace Source\UseCases\DoorUser\UserDoorAccess;
use Source\Entities\Door;
use Source\Entities\Group;
use Source\Entities\Schedule;
use Source\Sanitize\Paginates;
use Source\UseCases\BasePresenter;
class UsersWebPresenter extends BasePresenter implements Presenter
{
use Paginates;
protected array $viewModel = [];
/**
* @inheritDoc
*/
public function present(ResponseModel $responseModel): void
{
foreach ($responseModel->getGroups() as $group) {
foreach ($responseModel->getUsersForGroup($group) as $user) {
$this->viewModel[] = [
'user_id' => $user->getId(),
'group_id' => $group->getId(),
'group_title' => $group->getTitle(),
];
}
}
}
/**
* @inheritDoc
*/
public function getViewModel(): array
{
return [
'title' => 'Door Users',
'tableParams' => [
'headers' => [
'User' => 'user_id',
'Group' => 'group_id',
'Group Title' => 'group_title',
],
'paginatedData' => $this->webPaginate($this->viewModel),
],
];
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment