Skip to content
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"php": ">=7.1.3",
"illuminate/config": "5.6.*",
"illuminate/database": "5.6.*",
"illuminate/support": "5.6.*"
"illuminate/support": "5.6.*",
"illuminate/translation": "5.6.*"
},
"autoload": {
"psr-4": {
Expand Down
21 changes: 21 additions & 0 deletions resources/lang/en/enums.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

return [

// activity types
'activity_type_failed_login' => 'Failed Login',
'activity_type_logout' => 'Logout',
'activity_type_logged_in' => 'Logged In',
'activity_type_locked_out' => 'Locked Out',
'activity_type_password_change' => 'Password Change',
'activity_type_get_data' => 'Get Data',
'activity_type_modify_data' => 'Modify Data',

// verbs
'verb_get' => 'GET',
'verb_post' => 'POST',
'verb_patch' => 'PATCH',
'verb_put' => 'PUT',
'verb_delete' => 'DELETE',
'verb_unknown' => 'UNKNOWN',
];
1 change: 1 addition & 0 deletions src/LoggerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function boot()
$this->commands([AuditModelResolver::class]);
}

$this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'logger');
$this->mergeConfigFrom(__DIR__ . '/../config/logger.php', 'logger');
$this->publishes([
__DIR__ . '/../config/logger.php' => config_path('logger.php')
Expand Down
58 changes: 58 additions & 0 deletions src/Models/AuditActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

use App\User;
use Carbon\Carbon;
use Sourcetoad\Logger\Enums\ActivityType;
use Sourcetoad\Logger\Enums\HttpVerb;
use Sourcetoad\Logger\Traits\Immutable;

/**
Expand All @@ -18,10 +20,13 @@
* @property int|null $entity_id
* @property int $type
* @property string $ip_address
* @property int $verb
* @property Carbon $created_at
* @property-read AuditRoute $route
* @property-read AuditKey $key
* @property-read User $user
* @property-read string $human_verb
* @property-read string $human_activity
*/
class AuditActivity extends BaseModel
{
Expand Down Expand Up @@ -60,6 +65,59 @@ public function setUpdatedAtAttribute($value)
{
// Nothing
}

public function getHumanVerbAttribute(): string
{
switch ($this->verb) {
case HttpVerb::GET:
return trans('logger::enums.verb_get');

case HttpVerb::POST:
return trans('logger::enums.verb_post');

case HttpVerb::PATCH:
return trans('logger::enums.verb_patch');

case HttpVerb::PUT:
return trans('logger::enums.verb_patch');

case HttpVerb::DELETE:
return trans('logger::enums.verb_delete');

case HttpVerb::UNKNOWN:
default:
return trans('logger::enums.verb_unknown');
}
}

public function getHumanActivityAttribute(): string
{
switch ($this->type) {
case ActivityType::FAILED_LOGIN:
return trans('logger::enums.activity_type_failed_login');

case ActivityType::LOGOUT:
return trans('logger::enums.activity_type_logout');

case ActivityType::SUCCESSFUL_LOGIN:
return trans('logger::enums.activity_type_logged_in');

case ActivityType::LOCKED_OUT:
return trans('logger::enums.activity_type_locked_out');

case ActivityType::PASSWORD_CHANGE:
return trans('logger::enums.activity_type_password_change');

case ActivityType::GET_DATA:
return trans('logger::enums.activity_type_get_data');

case ActivityType::MODIFY_DATA:
return trans('logger::enums.activity_type_modify_data');

default:
throw new \Exception('Unknown enum type: ' . $this->type);
}
}

//--------------------------------------------------------------------------------------------------------------
// Relations
Expand Down
2 changes: 1 addition & 1 deletion src/Models/AuditRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function setRouteAttribute($value)

public static function createOrFind(string $route): AuditRoute
{
$routeHash = md5(strtolower($route));
$routeHash = md5(strtolower(trim($route)));

/** @var AuditRoute $route */
$route = AuditRoute::query()->firstOrCreate([
Expand Down