Commit feec84cf authored by Jacob Priddy's avatar Jacob Priddy 👌

fix code styles also overrides docs

parent 20e5a5c4
......@@ -3,31 +3,27 @@
namespace App\Documentation\Strategies;
use ReflectionClass;
use ReflectionMethod;
use Illuminate\Routing\Route;
use Source\Gateways\Users\UsersRepository;
use Source\Gateways\Doors\DoorsRepository;
use Source\Gateways\Groups\GroupsRepository;
use Source\Gateways\Tokens\TokensRepository;
use Mpociot\ApiDoc\Tools\DocumentationConfig;
use Source\Gateways\Users\LocalUsersRepository;
use Source\Gateways\Doors\LocalDoorsRepository;
use Source\Gateways\Users\LocalUsersRepository;
use Illuminate\Contracts\Foundation\Application;
use Source\Gateways\Attempts\AttemptsRepository;
use Source\Gateways\DoorUser\DoorUserRepository;
use Source\Gateways\Groups\LocalGroupsRepository;
use Source\Gateways\Tokens\LocalTokensRepository;
use Mpociot\ApiDoc\Extracting\Strategies\Strategy;
use Source\Gateways\Schedules\SchedulesRepository;
use Source\Gateways\DoorGroup\DoorGroupRepository;
use Source\Gateways\GroupUser\GroupUserRepository;
use Source\Gateways\Attempts\LocalAttemptsRepository;
use Source\Gateways\Schedules\SchedulesRepository;
use Source\Gateways\DoorUser\LocalDoorUserRepository;
use Source\Gateways\Schedules\LocalSchedulesRepository;
use Source\Gateways\DoorGroup\LocalDoorGroupRepository;
use Source\Gateways\GroupUser\LocalGroupUserRepository;
use Source\Gateways\Schedules\LocalSchedulesRepository;
use Source\Gateways\DoorSchedule\DoorScheduleRepository;
use Source\Gateways\DoorSchedule\LocalDoorScheduleRepository;
......
......@@ -103,7 +103,7 @@ class AuthController extends ApiController
} catch (UserCreationException $e) {
$this->setStatusCode(400);
return $this->respondWithError(
'Invalid SAML user given. If you believe this is in error, please contact and administrator.'
'Invalid SAML user given. If you believe this is in error, please contact an administrator.'
);
}
......
......@@ -14,9 +14,28 @@ use Source\UseCases\Overrides\OverrideCreate\OverrideCreateUseCase;
use Source\UseCases\Overrides\OverrideUpdate\OverrideUpdateUseCase;
use Source\UseCases\Overrides\OverrideCreate\ApiPresenter as OverrideCreateApiPresenter;
/**
* @group Override Management
*
* Overrides apply to single doors and have precedence over regular schedules.
* This set of endpoints deals with creating/removing overrides as well as viewing override log history.
* Any overrides from doors are logged and can be reviewed from this API.
*/
class OverridesController extends ApiController
{
/**
* Create Override
*
* This endpoint creates an override for a door. Overrides have 2 types.
* A type of 0 means open mode, and a type of 1 means to keep it locked (overrides any access schedules).
*
* @authenticated
* @bodyParam reason string required Documentation field for why the override was created. Example: Demonstration
* @bodyParam door_id int required The door to apply the override to. Example: 1
* @bodyParam type int required The type of override. Example: 0
* @bodyParam start datetime required The start date/time for the override. Example: 2020-06-04 13:35:50
* @bodyParam end datetime required The end date/time for the override. Example: 2020-07-04 13:35:50
*
* @param \Source\UseCases\Overrides\OverrideCreate\OverrideCreateUseCase $overrideCreate
* @param \App\Guards\ApiGuard $apiGuard
* @return \Illuminate\Http\JsonResponse
......@@ -48,6 +67,16 @@ class OverridesController extends ApiController
}
/**
* Update Override
*
* This endpoint updates an existing override. It cannot update the override type or the applied door.
*
* @authenticated
* @urlParam overrideId required The ID of the override to update. Example: 2
* @bodyParam reason string Documentation field for why the override was created. Example: Demonstration updated
* @bodyParam start datetime The start date/time for the override. Example: 2020-06-04 13:35:50
* @bodyParam end datetime The end date/time for the override. Example: 2020-07-04 13:35:50
*
* @param string $overrideId
* @param \Source\UseCases\Overrides\OverrideUpdate\OverrideUpdateUseCase $overrideUpdate
* @return \Illuminate\Http\JsonResponse
......@@ -74,6 +103,13 @@ class OverridesController extends ApiController
}
/**
* Get Override
*
* This endpoint gets a specific override.
*
* @authenticated
* @urlParam overrideId required The ID of the override to update. Example: 2
*
* @param string $overrideId
* @param \Source\UseCases\Overrides\OverrideGet\OverrideGetUseCase $overrideGet
* @return \Illuminate\Http\JsonResponse
......@@ -93,6 +129,18 @@ class OverridesController extends ApiController
}
/**
* Filter Overrides
*
* This endpoint searches/filters overrides.
*
* @authenticated
* @paginated
* @queryParam start The start time to start filtering overrides. Example: 1900-06-04
* @queryParam end The end time to stop filtering overrides. Example: 2900-06-04 12:43:33
* @queryParam door_id This parameter filters overrides by door. Example: 1
* @queryParam user_id This parameter filters overrides by the user who created them. Example: 1
*
*
* @param \Source\UseCases\Overrides\OverridesGet\OverridesGetUseCase $overridesInDateRange
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Validation\ValidationException
......
......@@ -29,8 +29,13 @@ class InMemoryOverridesRepository implements OverridesRepository
$include = $include && $override->hasUserIdOf($userId);
}
if ($begin || $end) {
$include = $override->isActiveForDate($begin) || $override->isActiveForDate($end);
if ($begin && $end) {
$include = $include &&
($begin->lessThanOrEqualTo($override->getEnd()) && $end->greaterThanOrEqualTo($override->getStart()));
} elseif ($begin) {
$include = $include && $begin->lessThanOrEqualTo($override->getEnd());
} elseif ($end) {
$include = $include && $end->greaterThanOrEqualTo($override->getStart());
}
return $include;
......@@ -44,8 +49,7 @@ class InMemoryOverridesRepository implements OverridesRepository
{
$overrides = collect(array_filter($this->overrides, static function (Override $override) use ($doorId, $begin, $end) {
return $override->hasDoorIdOf($doorId) &&
($override->isActiveForDate($begin) || $override->isActiveForDate($end) ||
($begin->isBefore($override->getStart()) && $end->isAfter($override->getEnd())));
($begin->lessThanOrEqualTo($override->getEnd()) && $end->greaterThanOrEqualTo($override->getStart()));
}));
return $overrides
......
......@@ -6,7 +6,6 @@ namespace Source\UseCases\Door\Commands;
use Carbon\Carbon;
use Source\Entities\User;
use Source\Entities\Override;
use Source\Gateways\Doors\DoorsRepository;
use Source\Exceptions\EntityNotFoundException;
use Source\Gateways\Overrides\OverridesRepository;
......
......@@ -36,10 +36,13 @@ class AuthControllerTest extends TestCase
new Token(1, 1, 'token_string')
);
$response = $this->postJson('api/login', ['Hello' => 'There', 'General', 'Kenobi']);
$response = $this->postJson('api/login', ['email' => 'test@test.com', 'password' => 'password']);
$response->assertStatus(200);
$this->assertEquals(['Hello' => 'There', 'General', 'Kenobi'], $this->useCase->getAttemptedCredentials());
$this->assertEquals(
['email' => 'test@test.com', 'password' => 'password'],
$this->useCase->getAttemptedCredentials()
);
$response->assertCookie('api_token', 'token_string');
$response->assertJsonFragment(['first_name' => 'Tea']);
}
......@@ -63,8 +66,8 @@ class AuthControllerTest extends TestCase
{
$this->useCase->throwCreationException = true;
$response = $this->get('api/handle-login');
$response->assertStatus(200);
$response->assertJson(['status' => 'error', 'message' => 'There was an error authenticating the user. Please contact an administrator.']);
$response->assertStatus(400);
$response->assertJson(['status' => 'error', 'message' => 'Invalid SAML user given. If you believe this is in error, please contact an administrator.']);
}
/**
......
Markdown is supported
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