Skip to content

Commit

Permalink
chore: pint code format
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentauger committed Nov 5, 2024
1 parent 6e0552b commit ffdada0
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/Actions/Expertise/SyncExpertiseWithScience.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static function handle(): bool
$termsToRemove = [
'bio-informatics',
'biological',
'Forage plant'
'Forage plant',
];

// Taken from RESE guidance - retreived on: 2023-10-27
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/AuthorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function store(Request $request): JsonResource
]);

$author = Author::create($validated);

return new AuthorResource($author);
}

Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/AuthorEmploymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,4 @@ public function destroy(Author $author, AuthorEmployment $authorEmployment)

return response()->noContent();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class DeleteEmploymentRequest extends Request

protected ActivitiesScopeEndpoint $endpoint = ActivitiesScopeEndpoint::EMPLOYMENT;


public function __construct(readonly protected string $putCode)
{

Expand All @@ -30,6 +29,6 @@ public function __construct(readonly protected string $putCode)
*/
public function resolveEndpoint(): string
{
return $this->endpoint->value . '/' . $this->putCode;
return $this->endpoint->value.'/'.$this->putCode;
}
}
8 changes: 3 additions & 5 deletions app/Http/Integrations/Orcid/Requests/PutEmploymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@

class PutEmploymentRequest extends Request implements HasBody
{

use HasJsonBody;

/**
* The HTTP method of the request
*/
protected Method $method = Method::PUT;


public function __construct(
readonly protected EmploymentData $employmentData,
protected ActivitiesScopeEndpoint $endpoint = ActivitiesScopeEndpoint::EMPLOYMENT
)
{
) {
if (empty($this->employmentData->putCode)) {
throw new OrcidIntegrationException('Putcode is required for this request');
}
Expand All @@ -40,6 +38,6 @@ protected function defaultBody(): array
*/
public function resolveEndpoint(): string
{
return $this->endpoint->value . '/' . $this->employmentData->putCode;
return $this->endpoint->value.'/'.$this->employmentData->putCode;
}
}
18 changes: 11 additions & 7 deletions app/Jobs/SyncAuthorEmploymentWithOrcid.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class SyncAuthorEmploymentWithOrcid implements ShouldQueue
use Queueable;

const SYNC_TYPE_CREATE = 'create';

const SYNC_TYPE_UPDATE = 'update';

const SYNC_TYPE_DELETE = 'delete';

public $tries = 3;
Expand All @@ -45,8 +47,9 @@ public function handle(): void

// Does the author have a valid ORCID connection?
$author = $this->authorEmployment->author;
if(!$author->hasValidOrcidCredentials()){
if (! $author->hasValidOrcidCredentials()) {
Log::error('SyncAuthor: Author does not have valid ORCID credentials');

return;
}

Expand Down Expand Up @@ -81,20 +84,20 @@ private function createEmploymentRecordInOrcid(OrcidMemberAPIConnector $connecto
$request = new PostEmploymentRequest($employmentData);
$response = $connector->send($request);

if($response->failed() || $response->status() !== 201){
if ($response->failed() || $response->status() !== 201) {
Log::error('SyncAuthor: Error creating employment record in ORCID', [
'status' => $response->status(),
'headers' => $response->headers()->all(),
]);
$response->throw();
}

if(!$response->header('location')){
if (! $response->header('location')) {
throw new \Exception('No location header in response - cannot get putcode');
}

$location = $response->header('location');
$putcode = (int)Str::afterLast($location, '/');
$putcode = (int) Str::afterLast($location, '/');

$this->authorEmployment->orcid_putcode = $putcode;
$this->authorEmployment->orcid_updated_at = now();
Expand All @@ -112,13 +115,14 @@ private function updateEmploymentRecordInOrcid(OrcidMemberAPIConnector $connecto
$request = new PutEmploymentRequest($employmentData);
$response = $connector->send($request);

if($response->failed() || $response->status() !== 200){
if ($response->failed() || $response->status() !== 200) {

if($response->status() === 404){
if ($response->status() === 404) {
Log::error('SyncAuthor: Employment record not found in ORCID - Likely Deleted', [
'author_employment_id' => $this->authorEmployment->id,
]);
$this->createEmploymentRecordInOrcid($connector);

return;
}

Expand All @@ -145,7 +149,7 @@ private function deleteEmploymentRecordInOrcid(OrcidMemberAPIConnector $connecto
$request = new DeleteEmploymentRequest($putcode);
$response = $connector->send($request);

if($response->failed() || $response->status() !== 204 || $response->status() !== 404){
if ($response->failed() || $response->status() !== 204 || $response->status() !== 404) {
Log::error('SyncAuthor: Error deleting employment record in ORCID', [
'status' => $response->status(),
'headers' => $response->headers()->all(),
Expand Down
14 changes: 10 additions & 4 deletions app/Models/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,17 @@ public function clearOrcidToken(): void
*/
public function hasValidOrcidCredentials(): bool
{
if(!$this->orcid_verified) return false;
if(!$this->orcid_access_token) return false;
if($this->orcid_expires_at < now()) return false;
if (! $this->orcid_verified) {
return false;
}
if (! $this->orcid_access_token) {
return false;
}
if ($this->orcid_expires_at < now()) {
return false;
}

return true;
return true;
}

// Relationships
Expand Down
1 change: 1 addition & 0 deletions app/Models/AuthorEmployment.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class AuthorEmployment extends Model
{
/** @use HasFactory<\Database\Factories\AuthorEmploymentFactory> */
use HasFactory;

use LogsActivity;
use SoftDeletes;

Expand Down
7 changes: 4 additions & 3 deletions app/Policies/AuthorEmploymentPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\Models\Author;
use App\Models\AuthorEmployment;
use App\Models\User;
use Illuminate\Auth\Access\Response;

class AuthorEmploymentPolicy
{
Expand All @@ -30,7 +29,10 @@ public function view(User $user, AuthorEmployment $authorEmployment): bool
*/
public function create(User $user, Author $author): bool
{
if ($user->author->id !== $author->id) return false;
if ($user->author->id !== $author->id) {
return false;
}

return $user->can('create_author_employments');
}

Expand All @@ -49,5 +51,4 @@ public function delete(User $user, AuthorEmployment $authorEmployment): bool
{
return $user->author->id === $authorEmployment->author_id;
}

}
6 changes: 3 additions & 3 deletions tests/Feature/Models/AuthorEmployementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

});

test('a user can create a new author employment record', function (){
test('a user can create a new author employment record', function () {

// mock queue to ensure job dispatched
Queue::fake();
Expand Down Expand Up @@ -70,7 +70,7 @@

});

test('a user can update an author employment record', function (){
test('a user can update an author employment record', function () {

Queue::fake();

Expand Down Expand Up @@ -102,7 +102,7 @@

});

test('a user can delete an author employment record', function (){
test('a user can delete an author employment record', function () {

Queue::fake();
$user = User::factory()->create();
Expand Down

0 comments on commit ffdada0

Please sign in to comment.