Skip to content

Commit

Permalink
Merge pull request #274 from deanblackborough/v3.17.0
Browse files Browse the repository at this point in the history
v3.16.1
  • Loading branch information
deanblackborough authored Oct 13, 2023
2 parents 2bfcb74 + 0d4bf49 commit 9236e75
Show file tree
Hide file tree
Showing 11 changed files with 260 additions and 17 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

The complete changelog for the Costs to Expect REST API, our changelog follows the format defined at https://keepachangelog.com/en/1.0.0/

## [v3.16.1] - 2023-10-13
### Added
- Added additional authentication tests.
### Fixed
- Corrected the options response for /update-profile.
- Updating user profile clears the permitted users collection for a resource type.
- Minor token tweaks.

## [v3.16.0] - 2023-08-29
### Added
- Added a command to prune partial users (bots) from the database.
Expand Down
2 changes: 2 additions & 0 deletions app/Cache/KeyGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class KeyGroup

public const PERMITTED_USER_CREATE = 'permitted_user_create';
public const PERMITTED_USER_DELETE = 'permitted_user_delete';
public const PERMITTED_USER_UPDATE = 'permitted_user_update';

public const RESOURCE_CREATE = 'resource_create';
public const RESOURCE_DELETE = 'resource_delete';
Expand Down Expand Up @@ -122,6 +123,7 @@ public function keys(string $group_key): array
];

case self::PERMITTED_USER_CREATE:
case self::PERMITTED_USER_UPDATE:
return [
$this->key->permittedUsers(
(int) $this->parameters['resource_type_id']
Expand Down
19 changes: 18 additions & 1 deletion app/Http/Controllers/Action/AuthenticationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Action;

use App\HttpResponse\Response;
use App\Jobs\ClearCache;
use App\Jobs\DeleteAccount;
use App\Jobs\DeleteResource;
use App\Jobs\DeleteResourceType;
Expand Down Expand Up @@ -553,7 +554,23 @@ public function updateProfile(Request $request): Http\JsonResponse
$user->$field = $value;
}

$user->save();
if ($user->save()) {

$permitted_resource_types = (new Permission())->permittedResourceTypesForUser($user->id);
foreach ($permitted_resource_types as $permitted_resource_type) {
$cache_job_payload = (new \App\Cache\JobPayload())
->setGroupKey(\App\Cache\KeyGroup::PERMITTED_USER_UPDATE)
->setRouteParameters([
'resource_type_id' => $permitted_resource_type
])
->setUserId($user->id);

ClearCache::dispatchSync($cache_job_payload->payload());
}
}



} catch (Exception $e) {
return response()->json(['message' => trans('auth.unable-to-update-profile')], 401);
}
Expand Down
7 changes: 6 additions & 1 deletion app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ class User extends Authenticatable

public function revokeOldTokens(): void
{
$this->tokens()->where('last_used_at', '<', now()->subYear())->delete();
$this->tokens()
->where(static function ($query) {
$query->where('last_used_at', '<', now()->subYear())
->orWhereNull('last_used_at');
})
->delete();
}

public function instance(int $user_id): ?User
Expand Down
4 changes: 2 additions & 2 deletions config/api/app/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
declare(strict_types=1);

return [
'version'=> 'v3.16.0',
'version'=> 'v3.16.1',
'prefix' => 'v3',
'release_date' => '2023-08-29',
'release_date' => '2023-10-13',
'changelog' => [
'api' => '/v3/changelog',
'markdown' => 'https://github.com/costs-to-expect/api/blob/master/CHANGELOG.md'
Expand Down
17 changes: 7 additions & 10 deletions config/api/auth/update-profile/fields-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@
declare(strict_types=1);

return [
'name' => [
'field' => 'name',
'title' => 'auth/update-profile/fields.title-name',
'description' => 'auth/update-profile/fields.description-name',
'type' => 'string',
'required' => false
],
'email' => [
'field' => 'email',
'title' => 'auth/update-profile/fields.title-email',
'description' => 'auth/update-profile/fields.description-email',
'type' => 'email',
'required' => false
],
'password' => [
'field' => 'password',
'title' => 'auth/update-profile/fields.title-password',
'description' => 'auth/update-profile/fields.description-password',
'type' => 'string',
'validation' => [
'min-length' => 12
],
'required' => false
]
];
104 changes: 104 additions & 0 deletions public/api/schema/auth/options/update-password.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"$id": "https://api.costs-to-expect.com/v2/api/schema/auth/options/update-password.json",
"type": "object",
"properties": {
"POST": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"authentication": {
"type": "object",
"properties": {
"required": {
"type": "boolean"
},
"authenticated": {
"type": "boolean"
}
}
},
"fields": {
"type": "object",
"properties": {
"password": {
"type": "object",
"properties": {
"field": {
"type": "string"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"type": {
"type": "string"
},
"validation": {
"type": "object",
"properties": {
"min-length": {
"type": "integer"
}
},
"required": [
"min-length"
]
},
"required": {
"type": "boolean"
}
}
},
"password_confirmation": {
"type": "object",
"properties": {
"field": {
"type": "string"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"type": {
"type": "string"
},
"validation": {
"type": "object",
"properties": {
"min-length": {
"type": "integer"
}
},
"required": [
"min-length"
]
},
"required": {
"type": "boolean"
}
}
}
},
"required": [
"password",
"password_confirmation"
]
}
},
"required": [
"description",
"authentication",
"fields"
]
}
},
"required": [
"POST"
]
}
82 changes: 82 additions & 0 deletions public/api/schema/auth/options/update-profile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"$id": "https://api.costs-to-expect.com/v2/api/schema/auth/options/update-profile.json",
"type": "object",
"properties": {
"POST": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"authentication": {
"type": "object",
"properties": {
"required": {
"type": "boolean"
},
"authenticated": {
"type": "boolean"
}
}
},
"fields": {
"type": "object",
"properties": {
"name": {
"type": "object",
"properties": {
"field": {
"type": "string"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"type": {
"type": "string"
},
"required": {
"type": "boolean"
}
}
},
"email": {
"type": "object",
"properties": {
"field": {
"type": "string"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"type": {
"type": "string"
},
"required": {
"type": "boolean"
}
}
}
},
"required": [
"name",
"email"
]
}
},
"required": [
"description",
"authentication",
"fields"
]
}
},
"required": [
"POST"
]
}
6 changes: 3 additions & 3 deletions resources/lang/en/auth/update-profile/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
declare(strict_types=1);

return [
'title-name' => 'Name',
'description-name' => 'Enter your name',

'title-email' => 'Email',
'description-email' => 'Enter your email address',

'title-password' => 'Password',
'description-password' => 'Enter your password'
];
10 changes: 10 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,16 @@ protected function fetchOptionsForSubcategoryCollection(array $parameters = []):
return $this->optionsRoute('subcategory.list.options', $parameters);
}

protected function fetchOptionsForUpdatePassword(array $parameters = []): TestResponse
{
return $this->optionsRoute('auth.update-password.options', $parameters);
}

protected function fetchOptionsForUpdateProfile(array $parameters = []): TestResponse
{
return $this->optionsRoute('auth.update-profile.options', $parameters);
}

protected function route(string $route, array $parameters = []): TestResponse
{
return $this->get(route($route, $parameters));
Expand Down
18 changes: 18 additions & 0 deletions tests/View/Http/Controllers/AuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,22 @@ public function optionsRequestForRegister(): void

$this->assertProvidedJsonMatchesDefinedSchema($response->content(), 'api/schema/auth/options/register.json');
}

/** @test */
public function optionsRequestForUpdatePassword(): void
{
$response = $this->fetchOptionsForUpdatePassword();
$response->assertStatus(200);

$this->assertProvidedJsonMatchesDefinedSchema($response->content(), 'api/schema/auth/options/update-password.json');
}

/** @test */
public function optionsRequestForUpdateProfile(): void
{
$response = $this->fetchOptionsForUpdateProfile();
$response->assertStatus(200);

$this->assertProvidedJsonMatchesDefinedSchema($response->content(), 'api/schema/auth/options/update-profile.json');
}
}

0 comments on commit 9236e75

Please sign in to comment.