Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last login feature #740

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Some helper libraries of note here:
All changes must be done via a PR to the `main` branch. PR should be descriptive and provide
reference to any issues as required.

For commits, messages, use [Coventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)
For commits, messages, use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)

The commit message should be structured as follows:

Expand Down
49 changes: 30 additions & 19 deletions _ide_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/**
* A helper file for Laravel, to provide autocomplete information to your IDE
* Generated for Laravel 11.21.0.
* Generated for Laravel 11.22.0.
*
* This file should not be included in your code, only analyzed by your IDE!
*
Expand Down Expand Up @@ -6984,7 +6984,7 @@
*
* @param string $path
* @param string $algorithm
* @return string
* @return string|false
* @static
*/ public static function hash($path, $algorithm = 'md5')
{
Expand Down Expand Up @@ -8040,7 +8040,7 @@
* @method static \Illuminate\Http\Client\PendingRequest beforeSending(callable $callback)
* @method static \Illuminate\Http\Client\PendingRequest throw(callable|null $callback = null)
* @method static \Illuminate\Http\Client\PendingRequest throwIf(callable|bool $condition)
* @method static \Illuminate\Http\Client\PendingRequest throwUnless(bool $condition)
* @method static \Illuminate\Http\Client\PendingRequest throwUnless(callable|bool $condition)
* @method static \Illuminate\Http\Client\PendingRequest dump()
* @method static \Illuminate\Http\Client\PendingRequest dd()
* @method static \Illuminate\Http\Client\Response get(string $url, array|string|null $query = null)
Expand Down Expand Up @@ -10840,7 +10840,7 @@
/**
* Create a new redirect response to a named route.
*
* @param string $route
* @param \BackedEnum|string $route
* @param mixed $parameters
* @param int $status
* @param array $headers
Expand All @@ -10854,7 +10854,7 @@
/**
* Create a new redirect response to a signed named route.
*
* @param string $route
* @param \BackedEnum|string $route
* @param mixed $parameters
* @param \DateTimeInterface|\DateInterval|int|null $expiration
* @param int $status
Expand All @@ -10869,7 +10869,7 @@
/**
* Create a new redirect response to a signed named route.
*
* @param string $route
* @param \BackedEnum|string $route
* @param \DateTimeInterface|\DateInterval|int|null $expiration
* @param mixed $parameters
* @param int $status
Expand Down Expand Up @@ -13314,10 +13314,10 @@
* @method static \Illuminate\Routing\RouteRegistrar whereIn(array|string $parameters, array $values)
* @method static \Illuminate\Routing\RouteRegistrar as(string $value)
* @method static \Illuminate\Routing\RouteRegistrar controller(string $controller)
* @method static \Illuminate\Routing\RouteRegistrar domain(string $value)
* @method static \Illuminate\Routing\RouteRegistrar domain(\BackedEnum|string $value)
* @method static \Illuminate\Routing\RouteRegistrar middleware(array|string|null $middleware)
* @method static \Illuminate\Routing\RouteRegistrar missing(\Closure $missing)
* @method static \Illuminate\Routing\RouteRegistrar name(string $value)
* @method static \Illuminate\Routing\RouteRegistrar name(\BackedEnum|string $value)
* @method static \Illuminate\Routing\RouteRegistrar namespace(string|null $value)
* @method static \Illuminate\Routing\RouteRegistrar prefix(string $prefix)
* @method static \Illuminate\Routing\RouteRegistrar scopeBindings()
Expand Down Expand Up @@ -16476,7 +16476,7 @@
/**
* Create a signed route URL for a named route.
*
* @param string $name
* @param \BackedEnum|string $name
* @param mixed $parameters
* @param \DateTimeInterface|\DateInterval|int|null $expiration
* @param bool $absolute
Expand All @@ -16491,7 +16491,7 @@
/**
* Create a temporary signed route URL for a named route.
*
* @param string $name
* @param \BackedEnum|string $name
* @param \DateTimeInterface|\DateInterval|int $expiration
* @param array $parameters
* @param bool $absolute
Expand Down Expand Up @@ -16554,11 +16554,11 @@
/**
* Get the URL to a named route.
*
* @param string $name
* @param \BackedEnum|string $name
* @param mixed $parameters
* @param bool $absolute
* @return string
* @throws \Symfony\Component\Routing\Exception\RouteNotFoundException
* @throws \Symfony\Component\Routing\Exception\RouteNotFoundException|\InvalidArgumentException
* @static
*/ public static function route($name, $parameters = [], $absolute = true)
{
Expand Down Expand Up @@ -18037,9 +18037,20 @@
return $instance->usePreloadTagAttributes($attributes);
}
/**
* Use the "waterfall" prefetching strategy.
* Eagerly prefetch assets.
*
* @param int|null $concurrency
* @param string $event
* @return \Illuminate\Foundation\Vite
* @static
*/ public static function prefetch($concurrency = null, $event = 'load')
{
/** @var \Illuminate\Foundation\Vite $instance */
return $instance->prefetch($concurrency, $event);
}
/**
* Use the "waterfall" prefetching strategy.
*
* @return \Illuminate\Foundation\Vite
* @static
*/ public static function useWaterfallPrefetching($concurrency = null)
Expand Down Expand Up @@ -22592,7 +22603,7 @@ class Eloquent extends \Illuminate\Database\Eloquent\Model {
/**
* Add a "where" clause to the query for multiple columns with "and" conditions between them.
*
* @param \Illuminate\Contracts\Database\Query\Expression[]|string[] $columns
* @param \Illuminate\Contracts\Database\Query\Expression[]|\Closure[]|string[] $columns
* @param mixed $operator
* @param mixed $value
* @param string $boolean
Expand All @@ -22606,7 +22617,7 @@ class Eloquent extends \Illuminate\Database\Eloquent\Model {
/**
* Add an "or where" clause to the query for multiple columns with "and" conditions between them.
*
* @param \Illuminate\Contracts\Database\Query\Expression[]|string[] $columns
* @param \Illuminate\Contracts\Database\Query\Expression[]|\Closure[]|string[] $columns
* @param mixed $operator
* @param mixed $value
* @return \Illuminate\Database\Query\Builder
Expand All @@ -22619,7 +22630,7 @@ class Eloquent extends \Illuminate\Database\Eloquent\Model {
/**
* Add a "where" clause to the query for multiple columns with "or" conditions between them.
*
* @param \Illuminate\Contracts\Database\Query\Expression[]|string[] $columns
* @param \Illuminate\Contracts\Database\Query\Expression[]|\Closure[]|string[] $columns
* @param mixed $operator
* @param mixed $value
* @param string $boolean
Expand All @@ -22633,7 +22644,7 @@ class Eloquent extends \Illuminate\Database\Eloquent\Model {
/**
* Add an "or where" clause to the query for multiple columns with "or" conditions between them.
*
* @param \Illuminate\Contracts\Database\Query\Expression[]|string[] $columns
* @param \Illuminate\Contracts\Database\Query\Expression[]|\Closure[]|string[] $columns
* @param mixed $operator
* @param mixed $value
* @return \Illuminate\Database\Query\Builder
Expand All @@ -22646,7 +22657,7 @@ class Eloquent extends \Illuminate\Database\Eloquent\Model {
/**
* Add a "where not" clause to the query for multiple columns where none of the conditions should be true.
*
* @param \Illuminate\Contracts\Database\Query\Expression[]|string[] $columns
* @param \Illuminate\Contracts\Database\Query\Expression[]|\Closure[]|string[] $columns
* @param mixed $operator
* @param mixed $value
* @param string $boolean
Expand All @@ -22660,7 +22671,7 @@ class Eloquent extends \Illuminate\Database\Eloquent\Model {
/**
* Add an "or where not" clause to the query for multiple columns where none of the conditions should be true.
*
* @param \Illuminate\Contracts\Database\Query\Expression[]|string[] $columns
* @param \Illuminate\Contracts\Database\Query\Expression[]|\Closure[]|string[] $columns
* @param mixed $operator
* @param mixed $value
* @return \Illuminate\Database\Query\Builder
Expand Down
22 changes: 13 additions & 9 deletions app/Actions/CreatePublicationFromManuscript.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,42 @@
use App\Models\Journal;
use App\Models\ManuscriptRecord;
use App\Models\Publication;
use Illuminate\Support\Facades\DB;

class CreatePublicationFromManuscript
{
public static function handle(ManuscriptRecord $manuscriptRecord, Journal $journal): Publication
{

// create a new publication record
$publication = $manuscriptRecord->publication()->create([
return DB::transaction(function () use ($manuscriptRecord, $journal) {
$publication = $manuscriptRecord->publication()->create([
'title' => $manuscriptRecord->title,
'journal_id' => $journal->id,
'status' => PublicationStatus::ACCEPTED,
'accepted_on' => $manuscriptRecord->accepted_on,
'user_id' => $manuscriptRecord->user_id,
]);
]);

// attach the manuscript's authors to the publication
$manuscriptRecord->manuscriptAuthors()->each(function ($manuscriptAuthor) use ($publication) {
// attach the manuscript's authors to the publication
$manuscriptRecord->manuscriptAuthors()->each(function ($manuscriptAuthor) use ($publication) {
$publication->publicationAuthors()->create([
'author_id' => $manuscriptAuthor->author_id,
'organization_id' => $manuscriptAuthor->organization_id,
'is_corresponding_author' => $manuscriptAuthor->is_corresponding_author,
]);
});
});

// attach the manuscript's fundingSources to the publication
$manuscriptRecord->fundingSources()->each(function ($fundingSource) use ($publication) {
// attach the manuscript's fundingSources to the publication
$manuscriptRecord->fundingSources()->each(function ($fundingSource) use ($publication) {
$publication->fundingSources()->create([
'funder_id' => $fundingSource->funder_id,
'title' => $fundingSource->title,
'description' => $fundingSource->description,
]);
});
});

return $publication;
return $publication;
});
}
}
18 changes: 11 additions & 7 deletions app/Actions/DeleteManuscriptRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@

namespace App\Actions;

use Illuminate\Support\Facades\DB;

class DeleteManuscriptRecord
{
public static function handle($manuscriptRecord): bool
{
// delete manuscript authors;
$manuscriptRecord->manuscriptAuthors()->delete();
return DB::transaction(function () use ($manuscriptRecord) {
// delete manuscript authors;
$manuscriptRecord->manuscriptAuthors()->delete();

// delete funding sources
$manuscriptRecord->fundingSources()->delete();
// delete funding sources
$manuscriptRecord->fundingSources()->delete();

// files/manuscript will be handled by media library
// files/manuscript will be handled by media library

// delete manuscript record
return $manuscriptRecord->delete();
// delete manuscript record
return $manuscriptRecord->delete();
});
}
}
1 change: 1 addition & 0 deletions app/Http/Resources/AuthenticatedUserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function toArray($request)
'new_password_required' => $this->new_password_required,
'author' => AuthorResource::make($this->author),
'roles' => $this->getRoleNames(),
'last_login_at' => $this->previousSuccessfulLoginAt(),
'permissions' => $this->getAllPermissions()->pluck('name'),
];
}
Expand Down
5 changes: 5 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,9 @@ public function sendPasswordResetNotification($token): void

$this->notify(new PasswordResetNotification($this, $token));
}

public function previousSuccessfulLoginAt()
{
return $this->authentications()->whereLoginSuccessful(true)->skip(1)->first()?->login_at;
}
}
Loading
Loading