From b3784b77b1497312aae93f6b8b8ef42620ea2aff Mon Sep 17 00:00:00 2001 From: Nicholas Ciechanowski Date: Tue, 10 Oct 2023 20:46:03 +1100 Subject: [PATCH 01/11] feat: remove old code --- .../profile/delete-user-form.blade.php | 77 ----------------- .../update-profile-information-form.blade.php | 82 ------------------- resources/views/profile.blade.php | 12 --- 3 files changed, 171 deletions(-) delete mode 100644 resources/views/livewire/profile/delete-user-form.blade.php delete mode 100644 resources/views/livewire/profile/update-profile-information-form.blade.php diff --git a/resources/views/livewire/profile/delete-user-form.blade.php b/resources/views/livewire/profile/delete-user-form.blade.php deleted file mode 100644 index 7537eb1..0000000 --- a/resources/views/livewire/profile/delete-user-form.blade.php +++ /dev/null @@ -1,77 +0,0 @@ -validate(); - - tap(auth()->user(), fn () => auth()->logout())->delete(); - - session()->invalidate(); - session()->regenerateToken(); - - $this->redirect('/', navigate: true); - } -}; ?> - -
-
-

- {{ __('Delete Account') }} -

- -

- {{ __('Once your account is deleted, all of its resources and data will be permanently deleted. Before deleting your account, please download any data or information that you wish to retain.') }} -

-
- - {{ __('Delete Account') }} - - -
- -

- {{ __('Are you sure you want to delete your account?') }} -

- -

- {{ __('Once your account is deleted, all of its resources and data will be permanently deleted. Please enter your password to confirm you would like to permanently delete your account.') }} -

- -
- - - - - -
- -
- - {{ __('Cancel') }} - - - - {{ __('Delete Account') }} - -
-
-
-
diff --git a/resources/views/livewire/profile/update-profile-information-form.blade.php b/resources/views/livewire/profile/update-profile-information-form.blade.php deleted file mode 100644 index 4764e78..0000000 --- a/resources/views/livewire/profile/update-profile-information-form.blade.php +++ /dev/null @@ -1,82 +0,0 @@ -firstname = auth()->user()->firstname; - $this->lastname = auth()->user()->lastname; - $this->email = auth()->user()->email; - } - - public function updateProfileInformation(): void - { - $user = auth()->user(); - - $validated = $this->validate([ - 'firstname' => ['required', 'string', 'max:255'], - 'lastname' => ['required', 'string', 'max:255'], - 'email' => ['required', 'email', 'max:255', Rule::unique(User::class)->ignore($user->id)], - ]); - - $user->fill($validated); - - if ($user->isDirty('email')) { - $user->email_verified_at = null; - } - - $user->save(); - - $this->dispatch('profile-updated', name: $user->name); - } -}; ?> - -
-
-

- {{ __('Profile Information') }} -

- -

- {{ __("Update your account's profile information and email address.") }} -

-
- -
-
- - - -
- -
- - - -
- -
- - - -
- -
- {{ __('Save') }} - - - {{ __('Saved.') }} - -
-
-
diff --git a/resources/views/profile.blade.php b/resources/views/profile.blade.php index 314e5f1..a822c85 100644 --- a/resources/views/profile.blade.php +++ b/resources/views/profile.blade.php @@ -7,23 +7,11 @@
-{{--
--}} -{{--
--}} -{{-- --}} -{{--
--}} -{{--
--}} -
- -{{--
--}} -{{--
--}} -{{-- --}} -{{--
--}} -{{--
--}}
From faaed8fa1b20a2f2ba5a3ae53038920c9b789615 Mon Sep 17 00:00:00 2001 From: Nicholas Ciechanowski Date: Tue, 10 Oct 2023 20:49:51 +1100 Subject: [PATCH 02/11] feat: logging --- app/Http/Controllers/Api/UserController.php | 25 +++++++--------- .../Controllers/Api/WebHookController.php | 19 ++++++++++-- app/Models/Log.php | 18 +++++++++++ app/Models/Quote.php | 30 +++++++++++++++++-- app/Models/RequestedQuote.php | 13 ++++++-- app/Models/User.php | 27 +++++++++++++++++ .../2023_10_10_200426_create_logs_table.php | 28 +++++++++++++++++ .../views/livewire/pages/admin/send.blade.php | 12 ++++++-- .../views/livewire/pages/auth/login.blade.php | 6 ++++ .../pages/auth/reset-password.blade.php | 6 ++++ .../profile/update-password-form.blade.php | 6 ++++ routes/api.php | 3 +- 12 files changed, 169 insertions(+), 24 deletions(-) create mode 100644 app/Models/Log.php create mode 100644 database/migrations/2023_10_10_200426_create_logs_table.php diff --git a/app/Http/Controllers/Api/UserController.php b/app/Http/Controllers/Api/UserController.php index 6eb4768..73ac070 100644 --- a/app/Http/Controllers/Api/UserController.php +++ b/app/Http/Controllers/Api/UserController.php @@ -3,36 +3,33 @@ namespace App\Http\Controllers\Api; use App\Http\Controllers\Controller; -use App\Models\User; -use Illuminate\Support\Str; -use Illuminate\Http\Request; use App\Http\Requests\StoreUserRequest; -use Illuminate\Support\Facades\Validator; +use App\Models\User; +use Illuminate\Http\Request; +use Illuminate\Support\Str; +use Throwable; class UserController extends Controller { public function registerUser(StoreUserRequest $request) { + $data = $request->validated(); + $data['password'] = Str::random(8); - $validated = $request->validated(); - $validated['is_admin'] = false; - $validated['password'] = Str::random(8); - $validated['status'] = true; try { - $user = User::create($validated); - }catch (Throwable $exception){ + $user = User::create($data); + } catch (Throwable $exception) { return response() - ->json($exception); + ->json($exception); } - return response() - ->json(['message' => 'Successfully created user ' . $user->firstname]); + ->json(['message' => 'Successfully created user ' . $user->firstname]); } public function getUser(Request $request, User $user) { return response() - ->json(["status" => true]); + ->json(['status' => true]); } } diff --git a/app/Http/Controllers/Api/WebHookController.php b/app/Http/Controllers/Api/WebHookController.php index 1f81d9b..fd5761d 100644 --- a/app/Http/Controllers/Api/WebHookController.php +++ b/app/Http/Controllers/Api/WebHookController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Api; use App\Http\Controllers\Controller; +use App\Models\Log; use App\Models\Quote; use Illuminate\Http\Request; use Illuminate\Support\Facades\Http; @@ -12,6 +13,7 @@ class WebHookController extends Controller { public function webHookSend(string $payload) { + // TODO: move this to a helper class so we can reuse code between API and FE $data = ['text' => $payload]; $response = Http::post(config('bot.webhook'), $data); } @@ -19,17 +21,30 @@ class WebHookController extends Controller public function sendQuote(Request $request) { $quote = $request->input('quote'); + if (empty($quote)) { return; } + Log::create([ + 'user_id' => auth()?->user()?->id, + 'content' => "Quote sent. {$quote}", + ]); + $this->webHookSend($quote); } public function sendRandomQuote() { - $quote = Quote::inRandomOrder()->first()->quote; - $this->webHookSend($quote); + $quote = Quote::inRandomOrder()->first(); + + Log::create([ + 'user_id' => auth()?->user()?->id, + 'quote_id' => $quote->id, + 'content' => 'Quote sent.', + ]); + + $this->webHookSend($quote->quote); } public function test() diff --git a/app/Models/Log.php b/app/Models/Log.php new file mode 100644 index 0000000..e0bfb0c --- /dev/null +++ b/app/Models/Log.php @@ -0,0 +1,18 @@ + auth()?->user()?->id, + 'quote_id' => $this->id, + 'content' => 'Quote requested.' + ]); + } protected $fillable = [ 'quote', ]; + + public static function boot(): void + { + parent::boot(); + + self::created(function ($model) { + Log::create([ + 'user_id' => auth()?->user()?->id, + 'quote_id' => $model->id, + 'content' => 'Quote created.' + ]); + }); + + self::deleted(function ($model) { + Log::create([ + 'user_id' => auth()?->user()?->id, + 'quote_id' => $model->id, + 'content' => 'Quote deleted.' + ]); + }); + } } diff --git a/app/Models/RequestedQuote.php b/app/Models/RequestedQuote.php index e1da899..9b758c0 100644 --- a/app/Models/RequestedQuote.php +++ b/app/Models/RequestedQuote.php @@ -19,7 +19,12 @@ class RequestedQuote extends Model public function approve(): void { - // TODO: we'll probs want to log who approved this quote + Log::create([ + 'user_id' => auth()?->user()?->id, + 'requested_quote_id' => $this->id, + 'content' => 'Quote approved.' + ]); + Quote::create([ 'quote' => $this->quote, ]); @@ -29,7 +34,11 @@ class RequestedQuote extends Model public function reject(): void { - // TODO: we'll probs want to log who reject this quote + Log::create([ + 'user_id' => auth()?->user()?->id, + 'requested_quote_id' => $this->id, + 'content' => 'Quote rejected.' + ]); $this->delete(); } diff --git a/app/Models/User.php b/app/Models/User.php index c3f3b03..7af6c1e 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -14,6 +14,16 @@ class User extends Authenticatable { use HasApiTokens, HasFactory, Notifiable; + /** + * The model's default values for attributes. + * + * @var array + */ + protected $attributes = [ + 'is_admin' => false, + 'status' => true, + ]; + /** * The attributes that are mass assignable. * @@ -46,6 +56,23 @@ class User extends Authenticatable * @var array */ protected $casts = [ + 'is_admin' => 'boolean', + 'status' => 'boolean', 'password' => 'hashed', ]; + + public static function boot(): void + { + parent::boot(); + + // These will only ever get created by the api/bot. + // If we want to add something like by whom later on, + // we can just append it to the content e.g auth()?->user()?->id ?? 'API'. + self::created(function ($model) { + Log::create([ + 'user_id' => $model->id, + 'content' => 'User created.' + ]); + }); + } } diff --git a/database/migrations/2023_10_10_200426_create_logs_table.php b/database/migrations/2023_10_10_200426_create_logs_table.php new file mode 100644 index 0000000..d5292b6 --- /dev/null +++ b/database/migrations/2023_10_10_200426_create_logs_table.php @@ -0,0 +1,28 @@ +id(); + $table->foreignIdFor(User::class)->nullable(); + $table->foreignIdFor(Quote::class)->nullable(); + $table->foreignIdFor(RequestedQuote::class)->nullable(); + $table->string('content'); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('logs'); + } +}; diff --git a/resources/views/livewire/pages/admin/send.blade.php b/resources/views/livewire/pages/admin/send.blade.php index 1f71114..7decace 100644 --- a/resources/views/livewire/pages/admin/send.blade.php +++ b/resources/views/livewire/pages/admin/send.blade.php @@ -1,5 +1,6 @@ validate(); + // TODO: move this to a helper class so we can reuse code between API and FE $response = Http::post(config('bot.webhook'), ['text' => $validated['quote']]); + Log::create([ + 'user_id' => auth()?->user()?->id, + 'content' => "Quote sent. {$validated['quote']}" + ]); + $this->quote = ''; } }; ?> -
{{ __('Send') }} + class="mt-4"> + {{ __('Send') }} +
diff --git a/resources/views/livewire/pages/auth/login.blade.php b/resources/views/livewire/pages/auth/login.blade.php index b16c133..be02104 100644 --- a/resources/views/livewire/pages/auth/login.blade.php +++ b/resources/views/livewire/pages/auth/login.blade.php @@ -1,5 +1,6 @@ regenerate(); + Log::create([ + 'user_id' => auth()?->user()?->id, + 'content' => "Quote sent. {$quote}" + ]); + $this->redirect( session('url.intended', RouteServiceProvider::HOME), navigate: true diff --git a/resources/views/livewire/pages/auth/reset-password.blade.php b/resources/views/livewire/pages/auth/reset-password.blade.php index 3ac0b57..3f397d2 100644 --- a/resources/views/livewire/pages/auth/reset-password.blade.php +++ b/resources/views/livewire/pages/auth/reset-password.blade.php @@ -1,5 +1,6 @@ flash('status', __($status)); + Log::create([ + 'user_id' => auth()?->user()?->id, + 'content' => "Quote sent. {$quote}" + ]); + $this->redirectRoute('login', navigate: true); } }; ?> diff --git a/resources/views/livewire/profile/update-password-form.blade.php b/resources/views/livewire/profile/update-password-form.blade.php index 480fcd2..04eee07 100644 --- a/resources/views/livewire/profile/update-password-form.blade.php +++ b/resources/views/livewire/profile/update-password-form.blade.php @@ -1,5 +1,6 @@ Hash::make($validated['password']), ]); + Log::create([ + 'user_id' => auth()?->user()?->id, + 'content' => "Quote sent. {$quote}" + ]); + $this->reset('current_password', 'password', 'password_confirmation'); $this->dispatch('password-updated'); diff --git a/routes/api.php b/routes/api.php index a73824e..c520243 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,9 +1,8 @@ Date: Tue, 10 Oct 2023 23:48:05 +1100 Subject: [PATCH 03/11] feat: basic log page --- app/Models/Log.php | 16 +++++ app/Models/Quote.php | 13 +++- app/Models/RequestedQuote.php | 10 ++- app/Models/User.php | 13 +++- resources/views/admin/logs.blade.php | 9 +++ resources/views/components/sidebar.blade.php | 7 +- .../views/livewire/pages/admin/logs.blade.php | 67 +++++++++++++++++++ .../views/livewire/pages/admin/send.blade.php | 2 +- .../views/livewire/pages/auth/login.blade.php | 2 +- .../pages/auth/reset-password.blade.php | 2 +- .../profile/update-password-form.blade.php | 2 +- routes/web.php | 4 ++ 12 files changed, 131 insertions(+), 16 deletions(-) create mode 100644 resources/views/admin/logs.blade.php create mode 100644 resources/views/livewire/pages/admin/logs.blade.php diff --git a/app/Models/Log.php b/app/Models/Log.php index e0bfb0c..f359360 100644 --- a/app/Models/Log.php +++ b/app/Models/Log.php @@ -3,6 +3,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; /** * @mixin IdeHelperLog @@ -15,4 +16,19 @@ class Log extends Model 'requested_quote_id', 'content', ]; + + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } + + public function quote(): BelongsTo + { + return $this->belongsTo(Quote::class); + } + + public function requestedQuote(): BelongsTo + { + return $this->belongsTo(RequestedQuote::class); + } } diff --git a/app/Models/Quote.php b/app/Models/Quote.php index 51d041e..57649fb 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -3,6 +3,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; /** @@ -20,13 +21,19 @@ class Quote extends Model Log::create([ 'user_id' => auth()?->user()?->id, 'quote_id' => $this->id, - 'content' => 'Quote requested.' + 'content' => 'Quote requested.', ]); } + protected $fillable = [ 'quote', ]; + public function logs(): hasMany + { + return $this->hasMany(Log::class); + } + public static function boot(): void { parent::boot(); @@ -35,7 +42,7 @@ class Quote extends Model Log::create([ 'user_id' => auth()?->user()?->id, 'quote_id' => $model->id, - 'content' => 'Quote created.' + 'content' => 'Quote created.', ]); }); @@ -43,7 +50,7 @@ class Quote extends Model Log::create([ 'user_id' => auth()?->user()?->id, 'quote_id' => $model->id, - 'content' => 'Quote deleted.' + 'content' => 'Quote deleted.', ]); }); } diff --git a/app/Models/RequestedQuote.php b/app/Models/RequestedQuote.php index 9b758c0..8ab0190 100644 --- a/app/Models/RequestedQuote.php +++ b/app/Models/RequestedQuote.php @@ -3,6 +3,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; /** @@ -17,12 +18,17 @@ class RequestedQuote extends Model 'user_id', ]; + public function logs(): hasMany + { + return $this->hasMany(Log::class); + } + public function approve(): void { Log::create([ 'user_id' => auth()?->user()?->id, 'requested_quote_id' => $this->id, - 'content' => 'Quote approved.' + 'content' => 'Quote approved.', ]); Quote::create([ @@ -37,7 +43,7 @@ class RequestedQuote extends Model Log::create([ 'user_id' => auth()?->user()?->id, 'requested_quote_id' => $this->id, - 'content' => 'Quote rejected.' + 'content' => 'Quote rejected.', ]); $this->delete(); diff --git a/app/Models/User.php b/app/Models/User.php index 7af6c1e..7d2f868 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -3,6 +3,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; @@ -61,6 +62,16 @@ class User extends Authenticatable 'password' => 'hashed', ]; + public function logs(): hasMany + { + return $this->hasMany(Log::class); + } + + public function fullName(): string + { + return "{$this->firstname} {$this->lastname}"; + } + public static function boot(): void { parent::boot(); @@ -71,7 +82,7 @@ class User extends Authenticatable self::created(function ($model) { Log::create([ 'user_id' => $model->id, - 'content' => 'User created.' + 'content' => 'User created.', ]); }); } diff --git a/resources/views/admin/logs.blade.php b/resources/views/admin/logs.blade.php new file mode 100644 index 0000000..181274e --- /dev/null +++ b/resources/views/admin/logs.blade.php @@ -0,0 +1,9 @@ + +
+
+
+ +
+
+
+
diff --git a/resources/views/components/sidebar.blade.php b/resources/views/components/sidebar.blade.php index 9f0f255..d67a92a 100644 --- a/resources/views/components/sidebar.blade.php +++ b/resources/views/components/sidebar.blade.php @@ -38,12 +38,7 @@ Send Quote
  • - {{-- TODO: fill with SVG icons to make it pretty --}} - {{-- Second Page--}} -
  • -
  • - {{-- TODO: fill with SVG icons to make it pretty --}} - {{-- Third Page--}} + Logs
  • diff --git a/resources/views/livewire/pages/admin/logs.blade.php b/resources/views/livewire/pages/admin/logs.blade.php new file mode 100644 index 0000000..557d4d2 --- /dev/null +++ b/resources/views/livewire/pages/admin/logs.blade.php @@ -0,0 +1,67 @@ +getLogs(); + } + + public function getLogs(): void + { + // TODO: look into pagination for this. + $this->logs = Log::with(['user', 'quote', 'requestedQuote'])->get()->sortByDesc('created_at'); + } +}; ?> + +
    +
    + + + + + + + + + + @foreach ($logs as $log) + + + + + + @endforeach + +
    + User + + Logs + + Type +
    + {{ $log?->user->fullName() ?? 'N/A' }} + + {{ $log->content }} + + @if (!empty($log->quote_id)) + Quote - {{ $log->quote_id }} + @elseif (!empty($log->requested_quote_id)) + Requsted Quote - ID: {{ $log->requested_quote_id }} + @else + N/A + @endif +
    +
    +
    + diff --git a/resources/views/livewire/pages/admin/send.blade.php b/resources/views/livewire/pages/admin/send.blade.php index 7decace..7b8f526 100644 --- a/resources/views/livewire/pages/admin/send.blade.php +++ b/resources/views/livewire/pages/admin/send.blade.php @@ -20,7 +20,7 @@ new #[Layout('layouts.app')] class extends Component Log::create([ 'user_id' => auth()?->user()?->id, - 'content' => "Quote sent. {$validated['quote']}" + 'content' => "Quote sent. {$validated['quote']}", ]); $this->quote = ''; diff --git a/resources/views/livewire/pages/auth/login.blade.php b/resources/views/livewire/pages/auth/login.blade.php index be02104..b9851f8 100644 --- a/resources/views/livewire/pages/auth/login.blade.php +++ b/resources/views/livewire/pages/auth/login.blade.php @@ -42,7 +42,7 @@ new #[Layout('layouts.guest')] class extends Component Log::create([ 'user_id' => auth()?->user()?->id, - 'content' => "Quote sent. {$quote}" + 'content' => "Quote sent. {$quote}", ]); $this->redirect( diff --git a/resources/views/livewire/pages/auth/reset-password.blade.php b/resources/views/livewire/pages/auth/reset-password.blade.php index 3f397d2..0d2b932 100644 --- a/resources/views/livewire/pages/auth/reset-password.blade.php +++ b/resources/views/livewire/pages/auth/reset-password.blade.php @@ -61,7 +61,7 @@ new #[Layout('layouts.guest')] class extends Component Log::create([ 'user_id' => auth()?->user()?->id, - 'content' => "Quote sent. {$quote}" + 'content' => "Quote sent. {$quote}", ]); $this->redirectRoute('login', navigate: true); diff --git a/resources/views/livewire/profile/update-password-form.blade.php b/resources/views/livewire/profile/update-password-form.blade.php index 04eee07..90b9a68 100644 --- a/resources/views/livewire/profile/update-password-form.blade.php +++ b/resources/views/livewire/profile/update-password-form.blade.php @@ -31,7 +31,7 @@ new class extends Component Log::create([ 'user_id' => auth()?->user()?->id, - 'content' => "Quote sent. {$quote}" + 'content' => "Quote sent. {$quote}", ]); $this->reset('current_password', 'password', 'password_confirmation'); diff --git a/routes/web.php b/routes/web.php index 6825f2c..81f11f7 100644 --- a/routes/web.php +++ b/routes/web.php @@ -29,6 +29,10 @@ Route::view('send', 'admin.send') ->middleware(['auth']) ->name('admin.send'); +Route::view('/admin/logs', 'admin.logs') + ->middleware(['auth']) + ->name('admin.logs'); + Route::middleware('guest')->group(function () { Volt::route('login', 'pages.auth.login') ->name('login'); From 13c5cafa9f9b2a13863c30eac22a400ead48ec9a Mon Sep 17 00:00:00 2001 From: Nicholas Ciechanowski Date: Wed, 11 Oct 2023 00:29:16 +1100 Subject: [PATCH 04/11] fix: route name --- resources/views/components/sidebar.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/components/sidebar.blade.php b/resources/views/components/sidebar.blade.php index d67a92a..10ec7f1 100644 --- a/resources/views/components/sidebar.blade.php +++ b/resources/views/components/sidebar.blade.php @@ -38,7 +38,7 @@ Send Quote
  • - Logs + Logs
  • From 2d5991988d8326637a37df37f595091fb5e9977a Mon Sep 17 00:00:00 2001 From: Nicholas Ciechanowski Date: Wed, 11 Oct 2023 22:28:14 +1100 Subject: [PATCH 05/11] feat: rework logging --- app/Enums/LogAction.php | 22 +++++++ .../Controllers/Api/WebHookController.php | 19 ++++-- app/Models/Log.php | 19 +++--- app/Models/Quote.php | 33 ++++++---- app/Models/RequestedQuote.php | 22 ++++--- app/Models/User.php | 28 +++++---- .../2023_10_10_200426_create_logs_table.php | 8 ++- database/seeders/DatabaseSeeder.php | 2 +- resources/views/admin/logs.blade.php | 8 +-- .../views/livewire/pages/admin/logs.blade.php | 60 ++++++++++++------- .../views/livewire/pages/admin/send.blade.php | 9 ++- .../views/livewire/pages/auth/login.blade.php | 10 +++- .../pages/auth/reset-password.blade.php | 10 +++- .../profile/update-password-form.blade.php | 46 ++++++++++---- vite.config.js | 3 +- 15 files changed, 204 insertions(+), 95 deletions(-) create mode 100644 app/Enums/LogAction.php diff --git a/app/Enums/LogAction.php b/app/Enums/LogAction.php new file mode 100644 index 0000000..73d0968 --- /dev/null +++ b/app/Enums/LogAction.php @@ -0,0 +1,22 @@ + auth()?->user()?->id, - 'content' => "Quote sent. {$quote}", + 'user_id' => auth()?->user()?->id ?? 1, + 'loggable_type' => Quote::class, + 'loggable_id' => null, + 'action' => LogAction::SEND, + 'content' => $quote, + 'ip' => request()->ip(), ]); $this->webHookSend($quote); @@ -39,9 +43,12 @@ class WebHookController extends Controller $quote = Quote::inRandomOrder()->first(); Log::create([ - 'user_id' => auth()?->user()?->id, - 'quote_id' => $quote->id, - 'content' => 'Quote sent.', + 'user_id' => auth()?->user()?->id ?? 1, + 'loggable_type' => Quote::class, + 'loggable_id' => $quote->id, + 'action' => LogAction::REQUEST, + 'content' => 'Random quote requested', + 'ip' => request()->ip(), ]); $this->webHookSend($quote->quote); diff --git a/app/Models/Log.php b/app/Models/Log.php index f359360..3e1be21 100644 --- a/app/Models/Log.php +++ b/app/Models/Log.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\MorphTo; /** * @mixin IdeHelperLog @@ -12,9 +13,11 @@ class Log extends Model { protected $fillable = [ 'user_id', - 'quote_id', - 'requested_quote_id', + 'loggable_type', + 'loggable_id', + 'action', 'content', + 'ip', ]; public function user(): BelongsTo @@ -22,13 +25,11 @@ class Log extends Model return $this->belongsTo(User::class); } - public function quote(): BelongsTo + /** + * Get the parent loggable model (user, quote or requested quote). + */ + public function loggable(): MorphTo { - return $this->belongsTo(Quote::class); - } - - public function requestedQuote(): BelongsTo - { - return $this->belongsTo(RequestedQuote::class); + return $this->morphTo(); } } diff --git a/app/Models/Quote.php b/app/Models/Quote.php index 57649fb..e904578 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -2,8 +2,9 @@ namespace App\Models; +use App\Enums\LogAction; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\SoftDeletes; /** @@ -20,37 +21,47 @@ class Quote extends Model Log::create([ 'user_id' => auth()?->user()?->id, - 'quote_id' => $this->id, - 'content' => 'Quote requested.', + 'loggable_type' => self::class, + 'loggable_id' => $this->id, + 'action' => LogAction::REQUEST, + 'content' => $this->quote, + 'ip' => request()->ip(), ]); } protected $fillable = [ + 'user_id', 'quote', ]; - public function logs(): hasMany + public function logs(): MorphOne { - return $this->hasMany(Log::class); + return $this->morphOne(Log::class, 'loggable'); } public static function boot(): void { parent::boot(); - self::created(function ($model) { + self::created(function (Quote $model) { Log::create([ 'user_id' => auth()?->user()?->id, - 'quote_id' => $model->id, - 'content' => 'Quote created.', + 'loggable_type' => self::class, + 'loggable_id' => $model->id, + 'action' => LogAction::CREATE, + 'content' => $model->quote, + 'ip' => request()->ip(), ]); }); - self::deleted(function ($model) { + self::deleted(function (Quote $model) { Log::create([ 'user_id' => auth()?->user()?->id, - 'quote_id' => $model->id, - 'content' => 'Quote deleted.', + 'loggable_type' => self::class, + 'loggable_id' => $model->id, + 'action' => LogAction::DELETE, + 'content' => $model->quote, + 'ip' => request()->ip(), ]); }); } diff --git a/app/Models/RequestedQuote.php b/app/Models/RequestedQuote.php index 8ab0190..e9fa709 100644 --- a/app/Models/RequestedQuote.php +++ b/app/Models/RequestedQuote.php @@ -2,8 +2,9 @@ namespace App\Models; +use App\Enums\LogAction; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\SoftDeletes; /** @@ -15,20 +16,22 @@ class RequestedQuote extends Model protected $fillable = [ 'quote', - 'user_id', ]; - public function logs(): hasMany + public function logs(): MorphOne { - return $this->hasMany(Log::class); + return $this->morphOne(Log::class, 'loggable'); } public function approve(): void { Log::create([ 'user_id' => auth()?->user()?->id, - 'requested_quote_id' => $this->id, - 'content' => 'Quote approved.', + 'loggable_type' => self::class, + 'loggable_id' => $this->id, + 'action' => LogAction::APPROVE, + 'content' => $this->quote, + 'ip' => request()->ip(), ]); Quote::create([ @@ -42,8 +45,11 @@ class RequestedQuote extends Model { Log::create([ 'user_id' => auth()?->user()?->id, - 'requested_quote_id' => $this->id, - 'content' => 'Quote rejected.', + 'loggable_type' => self::class, + 'loggable_id' => $this->id, + 'action' => LogAction::REJECT, + 'content' => $this->quote, + 'ip' => request()->ip(), ]); $this->delete(); diff --git a/app/Models/User.php b/app/Models/User.php index 7d2f868..49ba7d0 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,18 +2,20 @@ namespace App\Models; +use App\Enums\LogAction; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; -use Laravel\Sanctum\HasApiTokens; /** * @mixin IdeHelperUser */ class User extends Authenticatable { - use HasApiTokens, HasFactory, Notifiable; + use HasFactory, Notifiable; /** * The model's default values for attributes. @@ -62,27 +64,33 @@ class User extends Authenticatable 'password' => 'hashed', ]; - public function logs(): hasMany + public function logAction(): HasMany { return $this->hasMany(Log::class); } - public function fullName(): string + public function logs(): MorphOne { - return "{$this->firstname} {$this->lastname}"; + return $this->morphOne(Log::class, 'loggable'); + } + + public function getFullNameAttribute(): string + { + return "$this->firstname $this->lastname"; } public static function boot(): void { parent::boot(); - // These will only ever get created by the api/bot. - // If we want to add something like by whom later on, - // we can just append it to the content e.g auth()?->user()?->id ?? 'API'. self::created(function ($model) { Log::create([ - 'user_id' => $model->id, - 'content' => 'User created.', + 'user_id' => auth()?->user()?->id ?? 1, + 'loggable_type' => self::class, + 'loggable_id' => $model->id, + 'action' => LogAction::CREATE, + 'content' => $model->full_name, + 'ip' => request()->ip(), ]); }); } diff --git a/database/migrations/2023_10_10_200426_create_logs_table.php b/database/migrations/2023_10_10_200426_create_logs_table.php index d5292b6..a804593 100644 --- a/database/migrations/2023_10_10_200426_create_logs_table.php +++ b/database/migrations/2023_10_10_200426_create_logs_table.php @@ -14,9 +14,11 @@ return new class extends Migration Schema::create('logs', function (Blueprint $table) { $table->id(); $table->foreignIdFor(User::class)->nullable(); - $table->foreignIdFor(Quote::class)->nullable(); - $table->foreignIdFor(RequestedQuote::class)->nullable(); - $table->string('content'); + $table->string('loggable_type'); + $table->integer('loggable_id'); + $table->string('action'); + $table->text('content'); + $table->string('ip'); $table->timestamps(); }); } diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index bee7ef0..8090ebe 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -12,7 +12,7 @@ class DatabaseSeeder extends Seeder */ public function run(): void { - $this->call(BaseQuotesSeeder::class); $this->call(PriceyBotSeeder::class); + $this->call(BaseQuotesSeeder::class); } } diff --git a/resources/views/admin/logs.blade.php b/resources/views/admin/logs.blade.php index 181274e..dca138b 100644 --- a/resources/views/admin/logs.blade.php +++ b/resources/views/admin/logs.blade.php @@ -1,9 +1,5 @@ -
    -
    -
    - -
    -
    +
    +
    diff --git a/resources/views/livewire/pages/admin/logs.blade.php b/resources/views/livewire/pages/admin/logs.blade.php index 557d4d2..26a8c81 100644 --- a/resources/views/livewire/pages/admin/logs.blade.php +++ b/resources/views/livewire/pages/admin/logs.blade.php @@ -1,23 +1,23 @@ getLogs(); - } + $logs = Log::with(['user', 'loggable']) + ->orderByDesc('created_at') + ->paginate(15); - public function getLogs(): void - { - // TODO: look into pagination for this. - $this->logs = Log::with(['user', 'quote', 'requestedQuote'])->get()->sortByDesc('created_at'); + return [ + 'logs' => $logs, + ]; } }; ?> @@ -30,38 +30,56 @@ new #[Layout('layouts.app')] class extends Component class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-nexi-black dark:text-gray-200 sm:pl-6"> User + + Type + + + Entity ID + + + Action + Logs - Type + IP @foreach ($logs as $log) - - {{ $log?->user->fullName() ?? 'N/A' }} + + {{ $log?->user?->full_name ?? 'Anonymous' }} - + + {{ str_replace('App\Models\\', '', $log->loggable_type) }} + + + {{ $log->loggable_id }} + + + {{ $log->action }} + + {{ $log->content }} - - @if (!empty($log->quote_id)) - Quote - {{ $log->quote_id }} - @elseif (!empty($log->requested_quote_id)) - Requsted Quote - ID: {{ $log->requested_quote_id }} - @else - N/A - @endif + + {{ $log->ip }} @endforeach
    +
    + {{ $logs->links() }} +
    diff --git a/resources/views/livewire/pages/admin/send.blade.php b/resources/views/livewire/pages/admin/send.blade.php index 7b8f526..67603a0 100644 --- a/resources/views/livewire/pages/admin/send.blade.php +++ b/resources/views/livewire/pages/admin/send.blade.php @@ -1,5 +1,6 @@ $validated['quote']]); Log::create([ - 'user_id' => auth()?->user()?->id, - 'content' => "Quote sent. {$validated['quote']}", + 'user_id' => auth()->user()->id, + 'loggable_type' => Log::class, + 'loggable_id' => null, + 'action' => LogAction::SEND, + 'content' => $validated['quote'], + 'ip' => request()->ip(), ]); $this->quote = ''; diff --git a/resources/views/livewire/pages/auth/login.blade.php b/resources/views/livewire/pages/auth/login.blade.php index b9851f8..9e788c2 100644 --- a/resources/views/livewire/pages/auth/login.blade.php +++ b/resources/views/livewire/pages/auth/login.blade.php @@ -1,6 +1,8 @@ regenerate(); Log::create([ - 'user_id' => auth()?->user()?->id, - 'content' => "Quote sent. {$quote}", + 'user_id' => auth()->user()->id, + 'loggable_type' => User::class, + 'loggable_id' => auth()->user()->id, + 'action' => LogAction::ACCESS, + 'content' => 'User logged in', + 'ip' => request()->ip(), ]); $this->redirect( diff --git a/resources/views/livewire/pages/auth/reset-password.blade.php b/resources/views/livewire/pages/auth/reset-password.blade.php index 0d2b932..4603b51 100644 --- a/resources/views/livewire/pages/auth/reset-password.blade.php +++ b/resources/views/livewire/pages/auth/reset-password.blade.php @@ -1,5 +1,7 @@ flash('status', __($status)); Log::create([ - 'user_id' => auth()?->user()?->id, - 'content' => "Quote sent. {$quote}", + 'user_id' => auth()->user()->id, + 'loggable_type' => User::class, + 'loggable_id' => auth()?->user()?->id, + 'action' => LogAction::UPDATE, + 'content' => 'User reset password via reset', + 'ip' => request()->ip(), ]); $this->redirectRoute('login', navigate: true); diff --git a/resources/views/livewire/profile/update-password-form.blade.php b/resources/views/livewire/profile/update-password-form.blade.php index 90b9a68..c9c03bb 100644 --- a/resources/views/livewire/profile/update-password-form.blade.php +++ b/resources/views/livewire/profile/update-password-form.blade.php @@ -1,6 +1,8 @@ auth()?->user()?->id, - 'content' => "Quote sent. {$quote}", + 'user_id' => auth()->user()->id, + 'loggable_type' => User::class, + 'loggable_id' => auth()?->user()?->id, + 'action' => LogAction::UPDATE, + 'content' => 'User updated password', + 'ip' => request()->ip(), ]); $this->reset('current_password', 'password', 'password_confirmation'); @@ -53,25 +59,41 @@ new class extends Component
    - - - + + +
    - - - + + +
    - - - + + +
    - {{ __('Save') }} + {{ __('Save') }} {{ __('Saved.') }} diff --git a/vite.config.js b/vite.config.js index 89f26f5..3344198 100644 --- a/vite.config.js +++ b/vite.config.js @@ -7,8 +7,7 @@ export default defineConfig({ input: [ 'resources/css/app.css', 'resources/js/app.js', - ], - refresh: true, + ] }), ], }); From 7d94630fd68e037fcc1bd3710be2c73a5534655f Mon Sep 17 00:00:00 2001 From: Nicholas Ciechanowski Date: Thu, 12 Oct 2023 22:51:26 +1100 Subject: [PATCH 06/11] feat: swap over to spatie logger --- app/Enums/LogAction.php | 22 --- .../Controllers/Api/WebHookController.php | 25 +-- app/Models/Log.php | 35 ---- app/Models/Quote.php | 58 ++----- app/Models/RequestedQuote.php | 38 ++--- app/Models/User.php | 34 +--- app/Providers/AppServiceProvider.php | 6 +- composer.json | 3 +- composer.lock | 155 +++++++++++++++++- config/activitylog.php | 52 ++++++ .../2023_10_10_200426_create_logs_table.php | 30 ---- ...10_12_080056_create_activity_log_table.php | 27 +++ ...add_event_column_to_activity_log_table.php | 22 +++ ...atch_uuid_column_to_activity_log_table.php | 22 +++ .../views/components/paginator.blade.php | 106 ++++++++++++ .../views/livewire/guest/navigation.blade.php | 2 +- .../livewire/layout/navigation.blade.php | 2 +- .../views/livewire/pages/admin/logs.blade.php | 30 ++-- .../views/livewire/pages/admin/send.blade.php | 14 +- .../views/livewire/pages/auth/login.blade.php | 13 +- .../pages/auth/reset-password.blade.php | 37 ++--- .../profile/update-password-form.blade.php | 21 +-- 22 files changed, 485 insertions(+), 269 deletions(-) delete mode 100644 app/Enums/LogAction.php delete mode 100644 app/Models/Log.php create mode 100644 config/activitylog.php delete mode 100644 database/migrations/2023_10_10_200426_create_logs_table.php create mode 100644 database/migrations/2023_10_12_080056_create_activity_log_table.php create mode 100644 database/migrations/2023_10_12_080057_add_event_column_to_activity_log_table.php create mode 100644 database/migrations/2023_10_12_080058_add_batch_uuid_column_to_activity_log_table.php create mode 100644 resources/views/components/paginator.blade.php diff --git a/app/Enums/LogAction.php b/app/Enums/LogAction.php deleted file mode 100644 index 73d0968..0000000 --- a/app/Enums/LogAction.php +++ /dev/null @@ -1,22 +0,0 @@ - auth()?->user()?->id ?? 1, - 'loggable_type' => Quote::class, - 'loggable_id' => null, - 'action' => LogAction::SEND, - 'content' => $quote, - 'ip' => request()->ip(), - ]); + activity() + ->event('send') + ->log("Manually sent quote: $quote"); $this->webHookSend($quote); } @@ -42,14 +35,10 @@ class WebHookController extends Controller { $quote = Quote::inRandomOrder()->first(); - Log::create([ - 'user_id' => auth()?->user()?->id ?? 1, - 'loggable_type' => Quote::class, - 'loggable_id' => $quote->id, - 'action' => LogAction::REQUEST, - 'content' => 'Random quote requested', - 'ip' => request()->ip(), - ]); + activity() + ->performedOn($quote) + ->event('send') + ->log("Requested quote: $quote->quote"); $this->webHookSend($quote->quote); } diff --git a/app/Models/Log.php b/app/Models/Log.php deleted file mode 100644 index 3e1be21..0000000 --- a/app/Models/Log.php +++ /dev/null @@ -1,35 +0,0 @@ -belongsTo(User::class); - } - - /** - * Get the parent loggable model (user, quote or requested quote). - */ - public function loggable(): MorphTo - { - return $this->morphTo(); - } -} diff --git a/app/Models/Quote.php b/app/Models/Quote.php index e904578..5387dea 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -2,67 +2,37 @@ namespace App\Models; -use App\Enums\LogAction; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\SoftDeletes; +use Spatie\Activitylog\LogOptions; +use Spatie\Activitylog\Traits\LogsActivity; /** * @mixin IdeHelperQuote */ class Quote extends Model { - use SoftDeletes; - - public function request(): void - { - // Send the quote - // If success, add it to the transactions - - Log::create([ - 'user_id' => auth()?->user()?->id, - 'loggable_type' => self::class, - 'loggable_id' => $this->id, - 'action' => LogAction::REQUEST, - 'content' => $this->quote, - 'ip' => request()->ip(), - ]); - } + use LogsActivity, SoftDeletes; protected $fillable = [ 'user_id', 'quote', ]; - public function logs(): MorphOne + public function request(): void { - return $this->morphOne(Log::class, 'loggable'); + // Send the quote + // If success, add it to the transactions + + activity() + ->performedOn($this) + ->event('send') + ->log("Requested quote: $this->quote"); } - public static function boot(): void + public function getActivityLogOptions(): LogOptions { - parent::boot(); - - self::created(function (Quote $model) { - Log::create([ - 'user_id' => auth()?->user()?->id, - 'loggable_type' => self::class, - 'loggable_id' => $model->id, - 'action' => LogAction::CREATE, - 'content' => $model->quote, - 'ip' => request()->ip(), - ]); - }); - - self::deleted(function (Quote $model) { - Log::create([ - 'user_id' => auth()?->user()?->id, - 'loggable_type' => self::class, - 'loggable_id' => $model->id, - 'action' => LogAction::DELETE, - 'content' => $model->quote, - 'ip' => request()->ip(), - ]); - }); + return LogOptions::defaults() + ->logOnly(['quote']); } } diff --git a/app/Models/RequestedQuote.php b/app/Models/RequestedQuote.php index e9fa709..4a3b2cc 100644 --- a/app/Models/RequestedQuote.php +++ b/app/Models/RequestedQuote.php @@ -2,56 +2,44 @@ namespace App\Models; -use App\Enums\LogAction; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\SoftDeletes; +use Spatie\Activitylog\Facades\LogBatch; +use Spatie\Activitylog\LogOptions; +use Spatie\Activitylog\Traits\LogsActivity; /** * @mixin IdeHelperRequestedQuote */ class RequestedQuote extends Model { - use SoftDeletes; + use LogsActivity, SoftDeletes; protected $fillable = [ 'quote', ]; - public function logs(): MorphOne - { - return $this->morphOne(Log::class, 'loggable'); - } - public function approve(): void { - Log::create([ - 'user_id' => auth()?->user()?->id, - 'loggable_type' => self::class, - 'loggable_id' => $this->id, - 'action' => LogAction::APPROVE, - 'content' => $this->quote, - 'ip' => request()->ip(), - ]); + LogBatch::startBatch(); Quote::create([ 'quote' => $this->quote, ]); $this->delete(); + + LogBatch::endBatch(); } public function reject(): void { - Log::create([ - 'user_id' => auth()?->user()?->id, - 'loggable_type' => self::class, - 'loggable_id' => $this->id, - 'action' => LogAction::REJECT, - 'content' => $this->quote, - 'ip' => request()->ip(), - ]); - $this->delete(); } + + public function getActivityLogOptions(): LogOptions + { + return LogOptions::defaults() + ->logOnly(['quote']); + } } diff --git a/app/Models/User.php b/app/Models/User.php index 49ba7d0..54c6a75 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,20 +2,18 @@ namespace App\Models; -use App\Enums\LogAction; use Illuminate\Database\Eloquent\Factories\HasFactory; -use Illuminate\Database\Eloquent\Relations\BelongsTo; -use Illuminate\Database\Eloquent\Relations\HasMany; -use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; +use Spatie\Activitylog\LogOptions; +use Spatie\Activitylog\Traits\LogsActivity; /** * @mixin IdeHelperUser */ class User extends Authenticatable { - use HasFactory, Notifiable; + use LogsActivity, HasFactory, Notifiable; /** * The model's default values for attributes. @@ -64,34 +62,14 @@ class User extends Authenticatable 'password' => 'hashed', ]; - public function logAction(): HasMany - { - return $this->hasMany(Log::class); - } - - public function logs(): MorphOne - { - return $this->morphOne(Log::class, 'loggable'); - } - public function getFullNameAttribute(): string { return "$this->firstname $this->lastname"; } - public static function boot(): void + public function getActivityLogOptions(): LogOptions { - parent::boot(); - - self::created(function ($model) { - Log::create([ - 'user_id' => auth()?->user()?->id ?? 1, - 'loggable_type' => self::class, - 'loggable_id' => $model->id, - 'action' => LogAction::CREATE, - 'content' => $model->full_name, - 'ip' => request()->ip(), - ]); - }); + return LogOptions::defaults() + ->logExcept(['password']); } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index a8daa55..fc7759b 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -3,6 +3,7 @@ namespace App\Providers; use Illuminate\Support\ServiceProvider; +use Spatie\Activitylog\Models\Activity; class AppServiceProvider extends ServiceProvider { @@ -15,6 +16,7 @@ class AppServiceProvider extends ServiceProvider $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class); } + // This is so we can access alpine without livewire on the page. \Livewire\Livewire::forceAssetInjection(); } @@ -23,6 +25,8 @@ class AppServiceProvider extends ServiceProvider */ public function boot(): void { - // + Activity::saving(function (Activity $activity) { + $activity->properties = $activity->properties->put('ip', request()->ip()); + }); } } diff --git a/composer.json b/composer.json index ba0c6a7..e84244c 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ "laravel/sanctum": "^3.2", "laravel/tinker": "^2.8", "livewire/livewire": "^3.0", - "livewire/volt": "^1.0" + "livewire/volt": "^1.0", + "spatie/laravel-activitylog": "^4.7" }, "require-dev": { "barryvdh/laravel-ide-helper": "^2.13", diff --git a/composer.lock b/composer.lock index 9dfa19f..388f2da 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "feae295eec753591e7cf70bf21f57924", + "content-hash": "da777baec27a8032a972c70cc19d114a", "packages": [ { "name": "brick/math", @@ -3251,6 +3251,157 @@ ], "time": "2023-04-15T23:01:58+00:00" }, + { + "name": "spatie/laravel-activitylog", + "version": "4.7.3", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-activitylog.git", + "reference": "ec65a478a909b8df1b4f0c3c45de2592ca7639e5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-activitylog/zipball/ec65a478a909b8df1b4f0c3c45de2592ca7639e5", + "reference": "ec65a478a909b8df1b4f0c3c45de2592ca7639e5", + "shasum": "" + }, + "require": { + "illuminate/config": "^8.0 || ^9.0 || ^10.0", + "illuminate/database": "^8.69 || ^9.27 || ^10.0", + "illuminate/support": "^8.0 || ^9.0 || ^10.0", + "php": "^8.0", + "spatie/laravel-package-tools": "^1.6.3" + }, + "require-dev": { + "ext-json": "*", + "orchestra/testbench": "^6.23 || ^7.0 || ^8.0", + "pestphp/pest": "^1.20" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Spatie\\Activitylog\\ActivitylogServiceProvider" + ] + } + }, + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Spatie\\Activitylog\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + }, + { + "name": "Sebastian De Deyne", + "email": "sebastian@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + }, + { + "name": "Tom Witkowski", + "email": "dev.gummibeer@gmail.com", + "homepage": "https://gummibeer.de", + "role": "Developer" + } + ], + "description": "A very simple activity logger to monitor the users of your website or application", + "homepage": "https://github.com/spatie/activitylog", + "keywords": [ + "activity", + "laravel", + "log", + "spatie", + "user" + ], + "support": { + "issues": "https://github.com/spatie/laravel-activitylog/issues", + "source": "https://github.com/spatie/laravel-activitylog/tree/4.7.3" + }, + "funding": [ + { + "url": "https://spatie.be/open-source/support-us", + "type": "custom" + }, + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2023-01-25T17:04:51+00:00" + }, + { + "name": "spatie/laravel-package-tools", + "version": "1.16.1", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-package-tools.git", + "reference": "cc7c991555a37f9fa6b814aa03af73f88026a83d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-package-tools/zipball/cc7c991555a37f9fa6b814aa03af73f88026a83d", + "reference": "cc7c991555a37f9fa6b814aa03af73f88026a83d", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^9.28|^10.0", + "php": "^8.0" + }, + "require-dev": { + "mockery/mockery": "^1.5", + "orchestra/testbench": "^7.7|^8.0", + "pestphp/pest": "^1.22", + "phpunit/phpunit": "^9.5.24", + "spatie/pest-plugin-test-time": "^1.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\LaravelPackageTools\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "role": "Developer" + } + ], + "description": "Tools for creating Laravel packages", + "homepage": "https://github.com/spatie/laravel-package-tools", + "keywords": [ + "laravel-package-tools", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/laravel-package-tools/issues", + "source": "https://github.com/spatie/laravel-package-tools/tree/1.16.1" + }, + "funding": [ + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2023-08-23T09:04:39+00:00" + }, { "name": "symfony/console", "version": "v6.3.4", @@ -9758,5 +9909,5 @@ "php": "^8.1" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/config/activitylog.php b/config/activitylog.php new file mode 100644 index 0000000..29d6f1a --- /dev/null +++ b/config/activitylog.php @@ -0,0 +1,52 @@ + env('ACTIVITY_LOGGER_ENABLED', true), + + /* + * When the clean-command is executed, all recording activities older than + * the number of days specified here will be deleted. + */ + 'delete_records_older_than_days' => 365, + + /* + * If no log name is passed to the activity() helper + * we use this default log name. + */ + 'default_log_name' => 'default', + + /* + * You can specify an auth driver here that gets user models. + * If this is null we'll use the current Laravel auth driver. + */ + 'default_auth_driver' => null, + + /* + * If set to true, the subject returns soft deleted models. + */ + 'subject_returns_soft_deleted_models' => true, + + /* + * This model will be used to log activity. + * It should implement the Spatie\Activitylog\Contracts\Activity interface + * and extend Illuminate\Database\Eloquent\Model. + */ + 'activity_model' => \Spatie\Activitylog\Models\Activity::class, + + /* + * This is the name of the table that will be created by the migration and + * used by the Activity model shipped with this package. + */ + 'table_name' => 'activity_log', + + /* + * This is the database connection that will be used by the migration and + * the Activity model shipped with this package. In case it's not set + * Laravel's database.default will be used instead. + */ + 'database_connection' => env('ACTIVITY_LOGGER_DB_CONNECTION'), +]; diff --git a/database/migrations/2023_10_10_200426_create_logs_table.php b/database/migrations/2023_10_10_200426_create_logs_table.php deleted file mode 100644 index a804593..0000000 --- a/database/migrations/2023_10_10_200426_create_logs_table.php +++ /dev/null @@ -1,30 +0,0 @@ -id(); - $table->foreignIdFor(User::class)->nullable(); - $table->string('loggable_type'); - $table->integer('loggable_id'); - $table->string('action'); - $table->text('content'); - $table->string('ip'); - $table->timestamps(); - }); - } - - public function down(): void - { - Schema::dropIfExists('logs'); - } -}; diff --git a/database/migrations/2023_10_12_080056_create_activity_log_table.php b/database/migrations/2023_10_12_080056_create_activity_log_table.php new file mode 100644 index 0000000..7c05bc8 --- /dev/null +++ b/database/migrations/2023_10_12_080056_create_activity_log_table.php @@ -0,0 +1,27 @@ +create(config('activitylog.table_name'), function (Blueprint $table) { + $table->bigIncrements('id'); + $table->string('log_name')->nullable(); + $table->text('description'); + $table->nullableMorphs('subject', 'subject'); + $table->nullableMorphs('causer', 'causer'); + $table->json('properties')->nullable(); + $table->timestamps(); + $table->index('log_name'); + }); + } + + public function down() + { + Schema::connection(config('activitylog.database_connection'))->dropIfExists(config('activitylog.table_name')); + } +} diff --git a/database/migrations/2023_10_12_080057_add_event_column_to_activity_log_table.php b/database/migrations/2023_10_12_080057_add_event_column_to_activity_log_table.php new file mode 100644 index 0000000..7b797fd --- /dev/null +++ b/database/migrations/2023_10_12_080057_add_event_column_to_activity_log_table.php @@ -0,0 +1,22 @@ +table(config('activitylog.table_name'), function (Blueprint $table) { + $table->string('event')->nullable()->after('subject_type'); + }); + } + + public function down() + { + Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) { + $table->dropColumn('event'); + }); + } +} diff --git a/database/migrations/2023_10_12_080058_add_batch_uuid_column_to_activity_log_table.php b/database/migrations/2023_10_12_080058_add_batch_uuid_column_to_activity_log_table.php new file mode 100644 index 0000000..8f7db66 --- /dev/null +++ b/database/migrations/2023_10_12_080058_add_batch_uuid_column_to_activity_log_table.php @@ -0,0 +1,22 @@ +table(config('activitylog.table_name'), function (Blueprint $table) { + $table->uuid('batch_uuid')->nullable()->after('properties'); + }); + } + + public function down() + { + Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) { + $table->dropColumn('batch_uuid'); + }); + } +} diff --git a/resources/views/components/paginator.blade.php b/resources/views/components/paginator.blade.php new file mode 100644 index 0000000..2fb0392 --- /dev/null +++ b/resources/views/components/paginator.blade.php @@ -0,0 +1,106 @@ +@if ($paginator->hasPages()) + +@endif diff --git a/resources/views/livewire/guest/navigation.blade.php b/resources/views/livewire/guest/navigation.blade.php index 6de4550..240c1e1 100644 --- a/resources/views/livewire/guest/navigation.blade.php +++ b/resources/views/livewire/guest/navigation.blade.php @@ -1,4 +1,4 @@ -
    +
    @auth diff --git a/resources/views/livewire/pages/admin/send.blade.php b/resources/views/livewire/pages/admin/send.blade.php index 67603a0..337def7 100644 --- a/resources/views/livewire/pages/admin/send.blade.php +++ b/resources/views/livewire/pages/admin/send.blade.php @@ -1,6 +1,5 @@ $validated['quote']]); - Log::create([ - 'user_id' => auth()->user()->id, - 'loggable_type' => Log::class, - 'loggable_id' => null, - 'action' => LogAction::SEND, - 'content' => $validated['quote'], - 'ip' => request()->ip(), - ]); + activity() + ->event('send') + ->log("Manually sent quote: {$validated['quote']}"); $this->quote = ''; } @@ -37,7 +31,7 @@ new #[Layout('layouts.app')] class extends Component diff --git a/resources/views/livewire/pages/auth/login.blade.php b/resources/views/livewire/pages/auth/login.blade.php index 9e788c2..74d5354 100644 --- a/resources/views/livewire/pages/auth/login.blade.php +++ b/resources/views/livewire/pages/auth/login.blade.php @@ -1,6 +1,5 @@ regenerate(); - Log::create([ - 'user_id' => auth()->user()->id, - 'loggable_type' => User::class, - 'loggable_id' => auth()->user()->id, - 'action' => LogAction::ACCESS, - 'content' => 'User logged in', - 'ip' => request()->ip(), - ]); + activity() + ->performedOn(auth()->user()) + ->event('access') + ->log('login'); $this->redirect( session('url.intended', RouteServiceProvider::HOME), diff --git a/resources/views/livewire/pages/auth/reset-password.blade.php b/resources/views/livewire/pages/auth/reset-password.blade.php index 4603b51..8ccb2cf 100644 --- a/resources/views/livewire/pages/auth/reset-password.blade.php +++ b/resources/views/livewire/pages/auth/reset-password.blade.php @@ -1,6 +1,5 @@ only('email', 'password', 'password_confirmation', 'token'), - function ($user) { - $user->forceFill([ - 'password' => Hash::make($this->password), - 'remember_token' => Str::random(60), - ])->save(); - event(new PasswordReset($user)); - } - ); + auth()->user()->update([ + $status = Password::reset( + $this->only('email', 'password', 'password_confirmation', 'token'), + function ($user) { + $user->forceFill([ + 'password' => Hash::make($this->password), + 'remember_token' => Str::random(60), + ])->save(); + + event(new PasswordReset($user)); + } + ); + ]); // If the password was successfully reset, we will redirect the user back to // the application's home authenticated view. If there is an error we can @@ -59,16 +61,11 @@ new #[Layout('layouts.guest')] class extends Component return; } - session()->flash('status', __($status)); + activity() + ->event('updated') + ->log('password reset'); - Log::create([ - 'user_id' => auth()->user()->id, - 'loggable_type' => User::class, - 'loggable_id' => auth()?->user()?->id, - 'action' => LogAction::UPDATE, - 'content' => 'User reset password via reset', - 'ip' => request()->ip(), - ]); + session()->flash('status', __($status)); $this->redirectRoute('login', navigate: true); } diff --git a/resources/views/livewire/profile/update-password-form.blade.php b/resources/views/livewire/profile/update-password-form.blade.php index c9c03bb..185e3b7 100644 --- a/resources/views/livewire/profile/update-password-form.blade.php +++ b/resources/views/livewire/profile/update-password-form.blade.php @@ -1,6 +1,5 @@ user()->update([ - 'password' => Hash::make($validated['password']), - ]); + // We don't want to have a complete log, just something for updating password + activity()->withoutLogs(function () { + auth()->user()->update([ + 'password' => Hash::make($validated['password']), + ]); + }); - Log::create([ - 'user_id' => auth()->user()->id, - 'loggable_type' => User::class, - 'loggable_id' => auth()?->user()?->id, - 'action' => LogAction::UPDATE, - 'content' => 'User updated password', - 'ip' => request()->ip(), - ]); + activity() + ->event('updated') + ->log('password updated'); $this->reset('current_password', 'password', 'password_confirmation'); From 60f191c3c1e78bcbff514050c02ce5bc7503278d Mon Sep 17 00:00:00 2001 From: Nicholas Ciechanowski Date: Thu, 12 Oct 2023 22:55:39 +1100 Subject: [PATCH 07/11] style: fix light mode hover --- resources/views/components/sidebar-nav.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/components/sidebar-nav.blade.php b/resources/views/components/sidebar-nav.blade.php index 63f05db..bb56c17 100644 --- a/resources/views/components/sidebar-nav.blade.php +++ b/resources/views/components/sidebar-nav.blade.php @@ -3,7 +3,7 @@ {{ $svg ?? '' }} From 12893399c84f18a15314d28a389c9e3eae36c9d0 Mon Sep 17 00:00:00 2001 From: Nicholas Ciechanowski Date: Thu, 12 Oct 2023 22:58:39 +1100 Subject: [PATCH 08/11] feat: backmerge --- .github/workflows/deploy.yml | 33 +++++++++++++++++++++++++ composer.json | 1 + deploy.php | 48 ++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 .github/workflows/deploy.yml create mode 100644 deploy.php diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..e69a83b --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,33 @@ +name: deploy + +on: + push: + tags: + - 'v*' + +concurrency: production_environment + +jobs: + production: + runs-on: ubuntu-latest + environment: Production + + steps: + - uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + tools: composer + extensions: bcmath, ctype, fileinfo, json, odbc, mbstring, openssl, pdo, pdo_mysql, pdo_odbc tokenizer, xml, soap, redis, igbinary + php-version: "8.2" + + - name: Install dependencies + run: composer install --no-interaction --no-scripts --prefer-dist + + + - name: Deploy + uses: deployphp/action@v1 + with: + private-key: ${{ secrets.DEPLOY_KEY }} + dep: deploy production diff --git a/composer.json b/composer.json index e84244c..71fec1b 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ }, "require-dev": { "barryvdh/laravel-ide-helper": "^2.13", + "deployer/deployer": "^7.3", "fakerphp/faker": "^1.9.1", "laravel/breeze": "^1.24", "laravel/pint": "^1.0", diff --git a/deploy.php b/deploy.php new file mode 100644 index 0000000..b2201c2 --- /dev/null +++ b/deploy.php @@ -0,0 +1,48 @@ +set('hostname', 'vps.benjamyn.love') + ->set('port', '22') + ->set('remote_user', 'root') + ->set('deploy_path', '/opt/PriceyBotPanel'); + + +// Tasks +task('npm:build', function () { + $command = match (get('alias')) { + 'production' => 'production', + 'staging' => 'development', + default => 'production' +}; +run("cd {{release_path}} && {{bin/npm}} run {$command}"); +}); + +task('perm:fix', function () { + run("chown -R nginx:nginx /opt/PriceyBotPanel"); +}); + + +// Hooks +after('deploy:vendors', 'npm:install'); +after('npm:install', 'npm:build'); +after('npm:build', 'perm:fix'); +after('deploy:failed', 'deploy:unlock'); From 6b6010ccc0a5e289eb0aa73583be842065444451 Mon Sep 17 00:00:00 2001 From: Nicholas Ciechanowski Date: Thu, 12 Oct 2023 23:10:02 +1100 Subject: [PATCH 09/11] chore: bump composer --- composer.lock | 252 +++++++++++++++++++++++++++++--------------------- 1 file changed, 149 insertions(+), 103 deletions(-) diff --git a/composer.lock b/composer.lock index 388f2da..0ad11a7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "da777baec27a8032a972c70cc19d114a", + "content-hash": "e30e72a75870b7f76938f6dd2adff20c", "packages": [ { "name": "brick/math", @@ -434,21 +434,21 @@ }, { "name": "fruitcake/php-cors", - "version": "v1.2.0", + "version": "v1.3.0", "source": { "type": "git", "url": "https://github.com/fruitcake/php-cors.git", - "reference": "58571acbaa5f9f462c9c77e911700ac66f446d4e" + "reference": "3d158f36e7875e2f040f37bc0573956240a5a38b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fruitcake/php-cors/zipball/58571acbaa5f9f462c9c77e911700ac66f446d4e", - "reference": "58571acbaa5f9f462c9c77e911700ac66f446d4e", + "url": "https://api.github.com/repos/fruitcake/php-cors/zipball/3d158f36e7875e2f040f37bc0573956240a5a38b", + "reference": "3d158f36e7875e2f040f37bc0573956240a5a38b", "shasum": "" }, "require": { "php": "^7.4|^8.0", - "symfony/http-foundation": "^4.4|^5.4|^6" + "symfony/http-foundation": "^4.4|^5.4|^6|^7" }, "require-dev": { "phpstan/phpstan": "^1.4", @@ -458,7 +458,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.1-dev" + "dev-master": "1.2-dev" } }, "autoload": { @@ -489,7 +489,7 @@ ], "support": { "issues": "https://github.com/fruitcake/php-cors/issues", - "source": "https://github.com/fruitcake/php-cors/tree/v1.2.0" + "source": "https://github.com/fruitcake/php-cors/tree/v1.3.0" }, "funding": [ { @@ -501,7 +501,7 @@ "type": "github" } ], - "time": "2022-02-20T15:07:15+00:00" + "time": "2023-10-12T05:21:21+00:00" }, { "name": "graham-campbell/result-type", @@ -972,16 +972,16 @@ }, { "name": "laravel/framework", - "version": "v10.26.2", + "version": "v10.28.0", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "6e5440f7c518f26b4495e5d7e4796ec239e26df9" + "reference": "09137f50f715c1efc649788a26092dcb1ec4ab6e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/6e5440f7c518f26b4495e5d7e4796ec239e26df9", - "reference": "6e5440f7c518f26b4495e5d7e4796ec239e26df9", + "url": "https://api.github.com/repos/laravel/framework/zipball/09137f50f715c1efc649788a26092dcb1ec4ab6e", + "reference": "09137f50f715c1efc649788a26092dcb1ec4ab6e", "shasum": "" }, "require": { @@ -1168,7 +1168,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2023-10-03T14:24:20+00:00" + "time": "2023-10-10T13:01:37+00:00" }, { "name": "laravel/prompts", @@ -1818,16 +1818,16 @@ }, { "name": "livewire/livewire", - "version": "v3.0.5", + "version": "v3.0.8", "source": { "type": "git", "url": "https://github.com/livewire/livewire.git", - "reference": "37f11583c61a75d51b2146c2fe38f506ad36014b" + "reference": "6f62019a0e821894f701ca463210c01d7369c929" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/livewire/livewire/zipball/37f11583c61a75d51b2146c2fe38f506ad36014b", - "reference": "37f11583c61a75d51b2146c2fe38f506ad36014b", + "url": "https://api.github.com/repos/livewire/livewire/zipball/6f62019a0e821894f701ca463210c01d7369c929", + "reference": "6f62019a0e821894f701ca463210c01d7369c929", "shasum": "" }, "require": { @@ -1836,15 +1836,15 @@ "illuminate/validation": "^10.0", "league/mime-type-detection": "^1.9", "php": "^8.1", - "symfony/http-kernel": "^5.0|^6.0" + "symfony/http-kernel": "^6.2" }, "require-dev": { "calebporzio/sushi": "^2.1", "laravel/framework": "^10.0", "laravel/prompts": "^0.1.6", "mockery/mockery": "^1.3.1", - "orchestra/testbench": "^7.0|^8.0", - "orchestra/testbench-dusk": "^7.0|^8.0", + "orchestra/testbench": "^8.0", + "orchestra/testbench-dusk": "^8.0", "phpunit/phpunit": "^9.0", "psy/psysh": "@stable" }, @@ -1880,7 +1880,7 @@ "description": "A front-end framework for Laravel.", "support": { "issues": "https://github.com/livewire/livewire/issues", - "source": "https://github.com/livewire/livewire/tree/v3.0.5" + "source": "https://github.com/livewire/livewire/tree/v3.0.8" }, "funding": [ { @@ -1888,7 +1888,7 @@ "type": "github" } ], - "time": "2023-09-16T11:51:32+00:00" + "time": "2023-10-10T20:44:46+00:00" }, { "name": "livewire/volt", @@ -6072,16 +6072,16 @@ }, { "name": "brianium/paratest", - "version": "v7.2.9", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/paratestphp/paratest.git", - "reference": "1f9e41c0779be4540654d92a9314016713f5e62c" + "reference": "2951d3f773ea91451c7440f48122287778634b0d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paratestphp/paratest/zipball/1f9e41c0779be4540654d92a9314016713f5e62c", - "reference": "1f9e41c0779be4540654d92a9314016713f5e62c", + "url": "https://api.github.com/repos/paratestphp/paratest/zipball/2951d3f773ea91451c7440f48122287778634b0d", + "reference": "2951d3f773ea91451c7440f48122287778634b0d", "shasum": "" }, "require": { @@ -6095,22 +6095,22 @@ "phpunit/php-code-coverage": "^10.1.7", "phpunit/php-file-iterator": "^4.1.0", "phpunit/php-timer": "^6.0", - "phpunit/phpunit": "^10.4.0", + "phpunit/phpunit": "^10.4.1", "sebastian/environment": "^6.0.1", - "symfony/console": "^6.3.4", - "symfony/process": "^6.3.4" + "symfony/console": "^6.3.4 || ^7.0.0", + "symfony/process": "^6.3.4 || ^7.0.0" }, "require-dev": { "doctrine/coding-standard": "^12.0.0", "ext-pcov": "*", "ext-posix": "*", - "infection/infection": "^0.27.3", - "phpstan/phpstan": "^1.10.37", + "infection/infection": "^0.27.4", + "phpstan/phpstan": "^1.10.38", "phpstan/phpstan-deprecation-rules": "^1.1.4", - "phpstan/phpstan-phpunit": "^1.3.14", + "phpstan/phpstan-phpunit": "^1.3.15", "phpstan/phpstan-strict-rules": "^1.5.1", "squizlabs/php_codesniffer": "^3.7.2", - "symfony/filesystem": "^6.3.1" + "symfony/filesystem": "^6.3.1 || ^7.0.0" }, "bin": [ "bin/paratest", @@ -6151,7 +6151,7 @@ ], "support": { "issues": "https://github.com/paratestphp/paratest/issues", - "source": "https://github.com/paratestphp/paratest/tree/v7.2.9" + "source": "https://github.com/paratestphp/paratest/tree/v7.3.0" }, "funding": [ { @@ -6163,7 +6163,7 @@ "type": "paypal" } ], - "time": "2023-10-06T07:53:04+00:00" + "time": "2023-10-10T15:11:25+00:00" }, { "name": "composer/class-map-generator", @@ -6240,16 +6240,16 @@ }, { "name": "composer/pcre", - "version": "3.1.0", + "version": "3.1.1", "source": { "type": "git", "url": "https://github.com/composer/pcre.git", - "reference": "4bff79ddd77851fe3cdd11616ed3f92841ba5bd2" + "reference": "00104306927c7a0919b4ced2aaa6782c1e61a3c9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/pcre/zipball/4bff79ddd77851fe3cdd11616ed3f92841ba5bd2", - "reference": "4bff79ddd77851fe3cdd11616ed3f92841ba5bd2", + "url": "https://api.github.com/repos/composer/pcre/zipball/00104306927c7a0919b4ced2aaa6782c1e61a3c9", + "reference": "00104306927c7a0919b4ced2aaa6782c1e61a3c9", "shasum": "" }, "require": { @@ -6291,7 +6291,7 @@ ], "support": { "issues": "https://github.com/composer/pcre/issues", - "source": "https://github.com/composer/pcre/tree/3.1.0" + "source": "https://github.com/composer/pcre/tree/3.1.1" }, "funding": [ { @@ -6307,7 +6307,50 @@ "type": "tidelift" } ], - "time": "2022-11-17T09:50:14+00:00" + "time": "2023-10-11T07:11:09+00:00" + }, + { + "name": "deployer/deployer", + "version": "v7.3.1", + "source": { + "type": "git", + "url": "https://github.com/deployphp/deployer.git", + "reference": "c5c5e79d4e57445918ed24a9cdd3d85b0f261de3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/deployphp/deployer/zipball/c5c5e79d4e57445918ed24a9cdd3d85b0f261de3", + "reference": "c5c5e79d4e57445918ed24a9cdd3d85b0f261de3", + "shasum": "" + }, + "bin": [ + "dep" + ], + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Anton Medvedev", + "email": "anton@medv.io" + } + ], + "description": "Deployment Tool", + "homepage": "https://deployer.org", + "support": { + "docs": "https://deployer.org/docs", + "issues": "https://github.com/deployphp/deployer/issues", + "source": "https://github.com/deployphp/deployer" + }, + "funding": [ + { + "url": "https://github.com/sponsors/antonmedv", + "type": "github" + } + ], + "time": "2023-04-05T09:24:30+00:00" }, { "name": "doctrine/cache", @@ -6404,16 +6447,16 @@ }, { "name": "doctrine/dbal", - "version": "3.7.0", + "version": "3.7.1", "source": { "type": "git", "url": "https://github.com/doctrine/dbal.git", - "reference": "00d03067f07482f025d41ab55e4ba0db5eca2cdf" + "reference": "5b7bd66c9ff58c04c5474ab85edce442f8081cb2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/dbal/zipball/00d03067f07482f025d41ab55e4ba0db5eca2cdf", - "reference": "00d03067f07482f025d41ab55e4ba0db5eca2cdf", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/5b7bd66c9ff58c04c5474ab85edce442f8081cb2", + "reference": "5b7bd66c9ff58c04c5474ab85edce442f8081cb2", "shasum": "" }, "require": { @@ -6497,7 +6540,7 @@ ], "support": { "issues": "https://github.com/doctrine/dbal/issues", - "source": "https://github.com/doctrine/dbal/tree/3.7.0" + "source": "https://github.com/doctrine/dbal/tree/3.7.1" }, "funding": [ { @@ -6513,7 +6556,7 @@ "type": "tidelift" } ], - "time": "2023-09-26T20:56:55+00:00" + "time": "2023-10-06T05:06:20+00:00" }, { "name": "doctrine/deprecations", @@ -6965,16 +7008,16 @@ }, { "name": "laravel/breeze", - "version": "v1.24.1", + "version": "v1.25.0", "source": { "type": "git", "url": "https://github.com/laravel/breeze.git", - "reference": "15c8866a19a5469c34748586162a238efa27fa51" + "reference": "d62371252246d45417d077ca8019b6abd679343c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/breeze/zipball/15c8866a19a5469c34748586162a238efa27fa51", - "reference": "15c8866a19a5469c34748586162a238efa27fa51", + "url": "https://api.github.com/repos/laravel/breeze/zipball/d62371252246d45417d077ca8019b6abd679343c", + "reference": "d62371252246d45417d077ca8019b6abd679343c", "shasum": "" }, "require": { @@ -7023,20 +7066,20 @@ "issues": "https://github.com/laravel/breeze/issues", "source": "https://github.com/laravel/breeze" }, - "time": "2023-10-04T01:03:14+00:00" + "time": "2023-10-06T13:24:19+00:00" }, { "name": "laravel/pint", - "version": "v1.13.2", + "version": "v1.13.3", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "bbb13460d7f8c5c0cd9a58109beedd79cd7331ff" + "reference": "93b2d0d49719bc6e444ba21cd4dbbccec935413d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/bbb13460d7f8c5c0cd9a58109beedd79cd7331ff", - "reference": "bbb13460d7f8c5c0cd9a58109beedd79cd7331ff", + "url": "https://api.github.com/repos/laravel/pint/zipball/93b2d0d49719bc6e444ba21cd4dbbccec935413d", + "reference": "93b2d0d49719bc6e444ba21cd4dbbccec935413d", "shasum": "" }, "require": { @@ -7047,7 +7090,7 @@ "php": "^8.1.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.26.1", + "friendsofphp/php-cs-fixer": "^3.34.1", "illuminate/view": "^10.23.1", "laravel-zero/framework": "^10.1.2", "mockery/mockery": "^1.6.6", @@ -7089,7 +7132,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2023-09-19T15:55:02+00:00" + "time": "2023-10-10T15:39:09+00:00" }, { "name": "laravel/sail", @@ -7302,16 +7345,16 @@ }, { "name": "nunomaduro/collision", - "version": "v7.9.0", + "version": "v7.10.0", "source": { "type": "git", "url": "https://github.com/nunomaduro/collision.git", - "reference": "296d0cf9fe462837ac0da8a568b56fc026b132da" + "reference": "49ec67fa7b002712da8526678abd651c09f375b2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nunomaduro/collision/zipball/296d0cf9fe462837ac0da8a568b56fc026b132da", - "reference": "296d0cf9fe462837ac0da8a568b56fc026b132da", + "url": "https://api.github.com/repos/nunomaduro/collision/zipball/49ec67fa7b002712da8526678abd651c09f375b2", + "reference": "49ec67fa7b002712da8526678abd651c09f375b2", "shasum": "" }, "require": { @@ -7320,19 +7363,22 @@ "php": "^8.1.0", "symfony/console": "^6.3.4" }, + "conflict": { + "laravel/framework": ">=11.0.0" + }, "require-dev": { - "brianium/paratest": "^7.2.7", - "laravel/framework": "^10.23.1", - "laravel/pint": "^1.13.1", + "brianium/paratest": "^7.3.0", + "laravel/framework": "^10.28.0", + "laravel/pint": "^1.13.3", "laravel/sail": "^1.25.0", "laravel/sanctum": "^3.3.1", "laravel/tinker": "^2.8.2", "nunomaduro/larastan": "^2.6.4", - "orchestra/testbench-core": "^8.11.0", - "pestphp/pest": "^2.19.1", - "phpunit/phpunit": "^10.3.5", + "orchestra/testbench-core": "^8.13.0", + "pestphp/pest": "^2.23.2", + "phpunit/phpunit": "^10.4.1", "sebastian/environment": "^6.0.1", - "spatie/laravel-ignition": "^2.3.0" + "spatie/laravel-ignition": "^2.3.1" }, "type": "library", "extra": { @@ -7391,33 +7437,33 @@ "type": "patreon" } ], - "time": "2023-09-19T10:45:09+00:00" + "time": "2023-10-11T15:45:01+00:00" }, { "name": "pestphp/pest", - "version": "v2.21.0", + "version": "v2.23.2", "source": { "type": "git", "url": "https://github.com/pestphp/pest.git", - "reference": "2ffafd445d42c8b7b7e1874bde1c29945767a49d" + "reference": "b126e8e6e4afd6562e80c5dafcc2a973f17a09b3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pestphp/pest/zipball/2ffafd445d42c8b7b7e1874bde1c29945767a49d", - "reference": "2ffafd445d42c8b7b7e1874bde1c29945767a49d", + "url": "https://api.github.com/repos/pestphp/pest/zipball/b126e8e6e4afd6562e80c5dafcc2a973f17a09b3", + "reference": "b126e8e6e4afd6562e80c5dafcc2a973f17a09b3", "shasum": "" }, "require": { - "brianium/paratest": "^7.2.9", - "nunomaduro/collision": "^7.9.0", - "nunomaduro/termwind": "^1.15.1", + "brianium/paratest": "^7.3.0", + "nunomaduro/collision": "^7.9.0|^8.0.0", + "nunomaduro/termwind": "^1.15.1|^2.0.0", "pestphp/pest-plugin": "^2.1.1", - "pestphp/pest-plugin-arch": "^2.3.3", + "pestphp/pest-plugin-arch": "^2.4.0", "php": "^8.1.0", - "phpunit/phpunit": "^10.4.0" + "phpunit/phpunit": "^10.4.1" }, "conflict": { - "phpunit/phpunit": ">10.4.0", + "phpunit/phpunit": ">10.4.1", "sebastian/exporter": "<5.1.0", "webmozart/assert": "<1.11.0" }, @@ -7482,7 +7528,7 @@ ], "support": { "issues": "https://github.com/pestphp/pest/issues", - "source": "https://github.com/pestphp/pest/tree/v2.21.0" + "source": "https://github.com/pestphp/pest/tree/v2.23.2" }, "funding": [ { @@ -7494,7 +7540,7 @@ "type": "github" } ], - "time": "2023-10-06T12:33:39+00:00" + "time": "2023-10-10T15:40:34+00:00" }, { "name": "pestphp/pest-plugin", @@ -7568,26 +7614,26 @@ }, { "name": "pestphp/pest-plugin-arch", - "version": "v2.3.3", + "version": "v2.4.0", "source": { "type": "git", "url": "https://github.com/pestphp/pest-plugin-arch.git", - "reference": "b758990e83f89daba3c45672398579cf8692213f" + "reference": "b315c03bbb7e620d7b57a670816e9bf5f3dbc7f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pestphp/pest-plugin-arch/zipball/b758990e83f89daba3c45672398579cf8692213f", - "reference": "b758990e83f89daba3c45672398579cf8692213f", + "url": "https://api.github.com/repos/pestphp/pest-plugin-arch/zipball/b315c03bbb7e620d7b57a670816e9bf5f3dbc7f7", + "reference": "b315c03bbb7e620d7b57a670816e9bf5f3dbc7f7", "shasum": "" }, "require": { - "nunomaduro/collision": "^7.8.1", - "pestphp/pest-plugin": "^2.0.1", + "nunomaduro/collision": "^7.9.0|^8.0.0", + "pestphp/pest-plugin": "^2.1.1", "php": "^8.1", "ta-tikoma/phpunit-architecture-test": "^0.7.4" }, "require-dev": { - "pestphp/pest": "^2.16.0", + "pestphp/pest": "^2.22.0", "pestphp/pest-dev-tools": "^2.16.0" }, "type": "library", @@ -7616,7 +7662,7 @@ "unit" ], "support": { - "source": "https://github.com/pestphp/pest-plugin-arch/tree/v2.3.3" + "source": "https://github.com/pestphp/pest-plugin-arch/tree/v2.4.0" }, "funding": [ { @@ -7628,7 +7674,7 @@ "type": "github" } ], - "time": "2023-08-21T16:06:30+00:00" + "time": "2023-10-10T14:44:21+00:00" }, { "name": "pestphp/pest-plugin-laravel", @@ -8348,16 +8394,16 @@ }, { "name": "phpunit/phpunit", - "version": "10.4.0", + "version": "10.4.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "9784e877e3700de37475545bdbdce8383ff53d25" + "reference": "62bd7af13d282deeb95650077d28ba3600ca321c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9784e877e3700de37475545bdbdce8383ff53d25", - "reference": "9784e877e3700de37475545bdbdce8383ff53d25", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/62bd7af13d282deeb95650077d28ba3600ca321c", + "reference": "62bd7af13d282deeb95650077d28ba3600ca321c", "shasum": "" }, "require": { @@ -8429,7 +8475,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/10.4.0" + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.4.1" }, "funding": [ { @@ -8445,7 +8491,7 @@ "type": "tidelift" } ], - "time": "2023-10-06T03:41:22+00:00" + "time": "2023-10-08T05:01:11+00:00" }, { "name": "psr/cache", @@ -9628,16 +9674,16 @@ }, { "name": "spatie/laravel-ignition", - "version": "2.3.0", + "version": "2.3.1", "source": { "type": "git", "url": "https://github.com/spatie/laravel-ignition.git", - "reference": "4ed813d16edb5a1ab0d7f4b1d116c37ee8cdf3c0" + "reference": "bf21cd15aa47fa4ec5d73bbc932005c70261efc8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/laravel-ignition/zipball/4ed813d16edb5a1ab0d7f4b1d116c37ee8cdf3c0", - "reference": "4ed813d16edb5a1ab0d7f4b1d116c37ee8cdf3c0", + "url": "https://api.github.com/repos/spatie/laravel-ignition/zipball/bf21cd15aa47fa4ec5d73bbc932005c70261efc8", + "reference": "bf21cd15aa47fa4ec5d73bbc932005c70261efc8", "shasum": "" }, "require": { @@ -9716,7 +9762,7 @@ "type": "github" } ], - "time": "2023-08-23T06:24:34+00:00" + "time": "2023-10-09T12:55:26+00:00" }, { "name": "symfony/yaml", From aace075321724e2dfe41659e9f742e7dd22d29fc Mon Sep 17 00:00:00 2001 From: Nicholas Ciechanowski Date: Mon, 16 Oct 2023 18:02:19 +1100 Subject: [PATCH 10/11] chore: bump composer --- composer.lock | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/composer.lock b/composer.lock index 0ad11a7..437fd0f 100644 --- a/composer.lock +++ b/composer.lock @@ -2948,16 +2948,16 @@ }, { "name": "psy/psysh", - "version": "v0.11.21", + "version": "v0.11.22", "source": { "type": "git", "url": "https://github.com/bobthecow/psysh.git", - "reference": "bcb22101107f3bf770523b65630c9d547f60c540" + "reference": "128fa1b608be651999ed9789c95e6e2a31b5802b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/bobthecow/psysh/zipball/bcb22101107f3bf770523b65630c9d547f60c540", - "reference": "bcb22101107f3bf770523b65630c9d547f60c540", + "url": "https://api.github.com/repos/bobthecow/psysh/zipball/128fa1b608be651999ed9789c95e6e2a31b5802b", + "reference": "128fa1b608be651999ed9789c95e6e2a31b5802b", "shasum": "" }, "require": { @@ -2986,7 +2986,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "0.11.x-dev" + "dev-0.11": "0.11.x-dev" }, "bamarni-bin": { "bin-links": false, @@ -3022,9 +3022,9 @@ ], "support": { "issues": "https://github.com/bobthecow/psysh/issues", - "source": "https://github.com/bobthecow/psysh/tree/v0.11.21" + "source": "https://github.com/bobthecow/psysh/tree/v0.11.22" }, - "time": "2023-09-17T21:15:54+00:00" + "time": "2023-10-14T21:56:36+00:00" }, { "name": "ralouphie/getallheaders", @@ -7614,26 +7614,26 @@ }, { "name": "pestphp/pest-plugin-arch", - "version": "v2.4.0", + "version": "v2.4.1", "source": { "type": "git", "url": "https://github.com/pestphp/pest-plugin-arch.git", - "reference": "b315c03bbb7e620d7b57a670816e9bf5f3dbc7f7" + "reference": "59698f0a381c5bc4fa2cd5b6ed331067c4501fdb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pestphp/pest-plugin-arch/zipball/b315c03bbb7e620d7b57a670816e9bf5f3dbc7f7", - "reference": "b315c03bbb7e620d7b57a670816e9bf5f3dbc7f7", + "url": "https://api.github.com/repos/pestphp/pest-plugin-arch/zipball/59698f0a381c5bc4fa2cd5b6ed331067c4501fdb", + "reference": "59698f0a381c5bc4fa2cd5b6ed331067c4501fdb", "shasum": "" }, "require": { - "nunomaduro/collision": "^7.9.0|^8.0.0", + "nunomaduro/collision": "^7.10.0|^8.0.0", "pestphp/pest-plugin": "^2.1.1", "php": "^8.1", - "ta-tikoma/phpunit-architecture-test": "^0.7.4" + "ta-tikoma/phpunit-architecture-test": "^0.7.5" }, "require-dev": { - "pestphp/pest": "^2.22.0", + "pestphp/pest": "^2.23.2", "pestphp/pest-dev-tools": "^2.16.0" }, "type": "library", @@ -7662,7 +7662,7 @@ "unit" ], "support": { - "source": "https://github.com/pestphp/pest-plugin-arch/tree/v2.4.0" + "source": "https://github.com/pestphp/pest-plugin-arch/tree/v2.4.1" }, "funding": [ { @@ -7674,7 +7674,7 @@ "type": "github" } ], - "time": "2023-10-10T14:44:21+00:00" + "time": "2023-10-12T15:35:38+00:00" }, { "name": "pestphp/pest-plugin-laravel", @@ -9838,16 +9838,16 @@ }, { "name": "ta-tikoma/phpunit-architecture-test", - "version": "0.7.4", + "version": "0.7.5", "source": { "type": "git", "url": "https://github.com/ta-tikoma/phpunit-architecture-test.git", - "reference": "abe1f8a5f4635e7cbe0a8a37d6b8d20c687af0f2" + "reference": "9eb08437e8f0c0c75cc947a373cf49672c335827" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ta-tikoma/phpunit-architecture-test/zipball/abe1f8a5f4635e7cbe0a8a37d6b8d20c687af0f2", - "reference": "abe1f8a5f4635e7cbe0a8a37d6b8d20c687af0f2", + "url": "https://api.github.com/repos/ta-tikoma/phpunit-architecture-test/zipball/9eb08437e8f0c0c75cc947a373cf49672c335827", + "reference": "9eb08437e8f0c0c75cc947a373cf49672c335827", "shasum": "" }, "require": { @@ -9855,7 +9855,7 @@ "php": "^8.1.0", "phpdocumentor/reflection-docblock": "^5.3.0", "phpunit/phpunit": "^10.1.1", - "symfony/finder": "^6.2.7" + "symfony/finder": "^6.2.7 || ^7.0.0" }, "require-dev": { "laravel/pint": "^1.9.0", @@ -9891,9 +9891,9 @@ ], "support": { "issues": "https://github.com/ta-tikoma/phpunit-architecture-test/issues", - "source": "https://github.com/ta-tikoma/phpunit-architecture-test/tree/0.7.4" + "source": "https://github.com/ta-tikoma/phpunit-architecture-test/tree/0.7.5" }, - "time": "2023-08-03T06:50:14+00:00" + "time": "2023-10-12T15:31:50+00:00" }, { "name": "theseer/tokenizer", From 2adff37550bea17395a6a05b38d19dcf2f0bb903 Mon Sep 17 00:00:00 2001 From: Nicholas Ciechanowski Date: Mon, 16 Oct 2023 18:22:18 +1100 Subject: [PATCH 11/11] feat: better automatic descriptions --- app/Models/Quote.php | 15 +++++++++++++++ app/Models/RequestedQuote.php | 15 +++++++++++++++ app/Models/User.php | 15 +++++++++++++++ .../views/livewire/pages/admin/logs.blade.php | 9 +-------- .../views/livewire/pages/auth/login.blade.php | 2 +- .../livewire/pages/auth/reset-password.blade.php | 2 +- .../profile/update-password-form.blade.php | 2 +- 7 files changed, 49 insertions(+), 11 deletions(-) diff --git a/app/Models/Quote.php b/app/Models/Quote.php index 5387dea..0c0bf07 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -5,6 +5,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Spatie\Activitylog\LogOptions; +use Spatie\Activitylog\Models\Activity; use Spatie\Activitylog\Traits\LogsActivity; /** @@ -30,6 +31,20 @@ class Quote extends Model ->log("Requested quote: $this->quote"); } + public function tapActivity(Activity $activity, string $eventName) + { + switch ($eventName) { + case 'created': + $activity->description = "Quote created: {$this->quote}"; + return; + case 'deleted': + $activity->description = "Quote deleted: {$this->quote}"; + return; + default; + return; + } + } + public function getActivityLogOptions(): LogOptions { return LogOptions::defaults() diff --git a/app/Models/RequestedQuote.php b/app/Models/RequestedQuote.php index 4a3b2cc..53e29dc 100644 --- a/app/Models/RequestedQuote.php +++ b/app/Models/RequestedQuote.php @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Spatie\Activitylog\Facades\LogBatch; use Spatie\Activitylog\LogOptions; +use Spatie\Activitylog\Models\Activity; use Spatie\Activitylog\Traits\LogsActivity; /** @@ -37,6 +38,20 @@ class RequestedQuote extends Model $this->delete(); } + public function tapActivity(Activity $activity, string $eventName) + { + switch ($eventName) { + case 'created': + $activity->description = "Quote created: {$this->quote}"; + return; + case 'deleted': + $activity->description = "Quote deleted: {$this->quote}"; + return; + default; + return; + } + } + public function getActivityLogOptions(): LogOptions { return LogOptions::defaults() diff --git a/app/Models/User.php b/app/Models/User.php index 54c6a75..cdc39e7 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Spatie\Activitylog\LogOptions; +use Spatie\Activitylog\Models\Activity; use Spatie\Activitylog\Traits\LogsActivity; /** @@ -67,6 +68,20 @@ class User extends Authenticatable return "$this->firstname $this->lastname"; } + public function tapActivity(Activity $activity, string $eventName) + { + switch ($eventName) { + case 'created': + $activity->description = "User created: {$this->full_name}"; + return; + case 'deleted': + $activity->description = "User deleted: {$this->full_name}"; + return; + default; + return; + } + } + public function getActivityLogOptions(): LogOptions { return LogOptions::defaults() diff --git a/resources/views/livewire/pages/admin/logs.blade.php b/resources/views/livewire/pages/admin/logs.blade.php index 1947160..d0e9703 100644 --- a/resources/views/livewire/pages/admin/logs.blade.php +++ b/resources/views/livewire/pages/admin/logs.blade.php @@ -71,14 +71,7 @@ new #[Layout('layouts.app')] class extends Component {{ \Illuminate\Support\Str::headline($log->event) }} - @switch($log->subject_type) - @case(Quote::class) - @case(RequestedQuote::class) - {{ $log?->subject?->quote }} - @break - @default - {{ $log->description }} - @endswitch + {{ $log->description }} {{ $log->getExtraProperty('ip') }} diff --git a/resources/views/livewire/pages/auth/login.blade.php b/resources/views/livewire/pages/auth/login.blade.php index 74d5354..6236ee5 100644 --- a/resources/views/livewire/pages/auth/login.blade.php +++ b/resources/views/livewire/pages/auth/login.blade.php @@ -44,7 +44,7 @@ new #[Layout('layouts.guest')] class extends Component activity() ->performedOn(auth()->user()) ->event('access') - ->log('login'); + ->log('User logged in'); $this->redirect( session('url.intended', RouteServiceProvider::HOME), diff --git a/resources/views/livewire/pages/auth/reset-password.blade.php b/resources/views/livewire/pages/auth/reset-password.blade.php index 8ccb2cf..7746ffb 100644 --- a/resources/views/livewire/pages/auth/reset-password.blade.php +++ b/resources/views/livewire/pages/auth/reset-password.blade.php @@ -63,7 +63,7 @@ new #[Layout('layouts.guest')] class extends Component activity() ->event('updated') - ->log('password reset'); + ->log('Password reset'); session()->flash('status', __($status)); diff --git a/resources/views/livewire/profile/update-password-form.blade.php b/resources/views/livewire/profile/update-password-form.blade.php index 185e3b7..9df9c4f 100644 --- a/resources/views/livewire/profile/update-password-form.blade.php +++ b/resources/views/livewire/profile/update-password-form.blade.php @@ -35,7 +35,7 @@ new class extends Component activity() ->event('updated') - ->log('password updated'); + ->log('Password updated'); $this->reset('current_password', 'password', 'password_confirmation');