Merge branch 'action_log' into dev
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Enumerations;
|
||||||
|
|
||||||
|
use App\Models\ActionLogType;
|
||||||
|
|
||||||
|
class ActionLogTypes extends BaseEnumeration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Init list of all action log types
|
||||||
|
*
|
||||||
|
* @throws Exceptions\EnumerationExistsException
|
||||||
|
*/
|
||||||
|
protected static function init()
|
||||||
|
{
|
||||||
|
$types = ActionLogType::all(['id', 'name']);
|
||||||
|
|
||||||
|
foreach ($types as $type) {
|
||||||
|
self::push($type->id, $type->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Enumerations;
|
||||||
|
|
||||||
|
use App\Models\ActionLogType;
|
||||||
|
|
||||||
|
class ActionLogTypesForLogger extends BaseEnumeration
|
||||||
|
{
|
||||||
|
protected static function init()
|
||||||
|
{
|
||||||
|
$types = ActionLogType::all(['string_id', 'id']);
|
||||||
|
|
||||||
|
foreach ($types as $type) {
|
||||||
|
self::push($type->string_id, $type->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use App\Events\Event;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||||
|
|
||||||
|
class ChangeSettings extends Event
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use App\Events\Event;
|
||||||
|
use App\Models\CustomField;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||||
|
|
||||||
|
class CreateNewCustomField extends Event
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
/**
|
||||||
|
* @var CustomField
|
||||||
|
*/
|
||||||
|
public $customField;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @param CustomField $customField
|
||||||
|
*/
|
||||||
|
public function __construct(CustomField $customField)
|
||||||
|
{
|
||||||
|
$this->customField = $customField;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use App\Events\Event;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||||
|
|
||||||
|
class CreateNewUser extends Event
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
/**
|
||||||
|
* @var User
|
||||||
|
*/
|
||||||
|
public $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @param User $user
|
||||||
|
*/
|
||||||
|
public function __construct(User $user)
|
||||||
|
{
|
||||||
|
$this->user = $user;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use App\Events\Event;
|
||||||
|
use App\Models\CustomField;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||||
|
|
||||||
|
class DeleteCustomField extends Event
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
/**
|
||||||
|
* @var CustomField
|
||||||
|
*/
|
||||||
|
public $customField;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @param CustomField $customField
|
||||||
|
*/
|
||||||
|
public function __construct(CustomField $customField)
|
||||||
|
{
|
||||||
|
$this->customField = $customField;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use App\Events\Event;
|
||||||
|
use App\Models\CustomField;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||||
|
|
||||||
|
class EditCustomField extends Event
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
/**
|
||||||
|
* @var CustomField
|
||||||
|
*/
|
||||||
|
public $customField;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @param CustomField $customField
|
||||||
|
*/
|
||||||
|
public function __construct(CustomField $customField)
|
||||||
|
{
|
||||||
|
$this->customField = $customField;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class EditUser extends Event
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
/**
|
||||||
|
* @var User
|
||||||
|
*/
|
||||||
|
public $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @param User $user
|
||||||
|
*/
|
||||||
|
public function __construct(User $user)
|
||||||
|
{
|
||||||
|
$this->user = $user;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,8 +4,10 @@ namespace App\Http\Controllers\Admin;
|
|||||||
|
|
||||||
use App\Enumerations\CustomFieldResources;
|
use App\Enumerations\CustomFieldResources;
|
||||||
use App\Enumerations\CustomFieldTypes;
|
use App\Enumerations\CustomFieldTypes;
|
||||||
|
use App\Events\CreateNewCustomField as CreateNewCustomFieldEvent;
|
||||||
use App\Http\Requests\NewCustomFieldRequest;
|
use App\Http\Requests\NewCustomFieldRequest;
|
||||||
use App\Models\CustomField;
|
use App\Models\CustomField;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
|
|
||||||
class CreateNewCustomField extends Controller
|
class CreateNewCustomField extends Controller
|
||||||
{
|
{
|
||||||
@@ -59,6 +61,9 @@ class CreateNewCustomField extends Controller
|
|||||||
|
|
||||||
$customField->save();
|
$customField->save();
|
||||||
|
|
||||||
|
// fire event about creating new custom field
|
||||||
|
Event::fire(new CreateNewCustomFieldEvent($customField));
|
||||||
|
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('customfields.new')
|
->route('customfields.new')
|
||||||
->with('success', trans('admin/customFields.successfullyCreated'));
|
->with('success', trans('admin/customFields.successfullyCreated'));
|
||||||
|
|||||||
@@ -3,11 +3,12 @@
|
|||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Enumerations\UserRoles;
|
use App\Enumerations\UserRoles;
|
||||||
|
use App\Events\CreateNewUser as CreateNewUserEvent;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests;
|
use App\Http\Requests;
|
||||||
use App\Http\Requests\CreateNewUserRequest;
|
use App\Http\Requests\CreateNewUserRequest;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Support\Facades\Event;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|
||||||
class CreateNewUser extends Controller
|
class CreateNewUser extends Controller
|
||||||
@@ -51,6 +52,9 @@ class CreateNewUser extends Controller
|
|||||||
// store user into database
|
// store user into database
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
|
// fire event
|
||||||
|
Event::fire(new CreateNewUserEvent($user));
|
||||||
|
|
||||||
// refresh page with information about successfull registration
|
// refresh page with information about successfull registration
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('users.new')
|
->route('users.new')
|
||||||
|
|||||||
@@ -4,10 +4,13 @@ namespace App\Http\Controllers\Admin;
|
|||||||
|
|
||||||
use App\Enumerations\CustomFieldResources;
|
use App\Enumerations\CustomFieldResources;
|
||||||
use App\Enumerations\CustomFieldTypes;
|
use App\Enumerations\CustomFieldTypes;
|
||||||
|
use App\Events\DeleteCustomField;
|
||||||
|
use App\Events\EditCustomField as EditCustomFieldEvent;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests;
|
use App\Http\Requests;
|
||||||
use App\Http\Requests\EditCustomFieldRequest;
|
use App\Http\Requests\EditCustomFieldRequest;
|
||||||
use App\Models\CustomField;
|
use App\Models\CustomField;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
|
|
||||||
class EditCustomField extends Controller
|
class EditCustomField extends Controller
|
||||||
{
|
{
|
||||||
@@ -60,6 +63,9 @@ class EditCustomField extends Controller
|
|||||||
// save changes into database
|
// save changes into database
|
||||||
$customField->save();
|
$customField->save();
|
||||||
|
|
||||||
|
// fire event about editing custom field
|
||||||
|
Event::fire(new EditCustomFieldEvent($customField));
|
||||||
|
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('customfields.edit', ['id' => $id])
|
->route('customfields.edit', ['id' => $id])
|
||||||
->with('success', trans('admin/customFields.successfullyEdited'));
|
->with('success', trans('admin/customFields.successfullyEdited'));
|
||||||
@@ -89,6 +95,9 @@ class EditCustomField extends Controller
|
|||||||
// delete item
|
// delete item
|
||||||
$field->delete();
|
$field->delete();
|
||||||
|
|
||||||
|
// fire event about editing custom field
|
||||||
|
Event::fire(new DeleteCustomField($field));
|
||||||
|
|
||||||
// redirect back to overview
|
// redirect back to overview
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('customfields.overview')
|
->route('customfields.overview')
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ namespace App\Http\Controllers\Admin;
|
|||||||
|
|
||||||
use App\Enumerations\UserRoles;
|
use App\Enumerations\UserRoles;
|
||||||
use App\Enumerations\UserStates;
|
use App\Enumerations\UserStates;
|
||||||
|
use App\Events\EditUser as EditUserEvent;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests;
|
use App\Http\Requests;
|
||||||
use App\Http\Requests\EditUserRequest;
|
use App\Http\Requests\EditUserRequest;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|
||||||
class EditUser extends Controller
|
class EditUser extends Controller
|
||||||
@@ -74,6 +76,9 @@ class EditUser extends Controller
|
|||||||
|
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
|
// fire event about editing user
|
||||||
|
Event::fire(new EditUserEvent($user));
|
||||||
|
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('users.detail', ['id' => $id])
|
->route('users.detail', ['id' => $id])
|
||||||
->with('success', trans('admin/userManagement.userSuccessfullyEdited'));
|
->with('success', trans('admin/userManagement.userSuccessfullyEdited'));
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use App\Events\ChangeSettings;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
|
class LogChangeSettings extends Logger
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param ChangeSettings $event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(ChangeSettings $event)
|
||||||
|
{
|
||||||
|
$parameters = [];
|
||||||
|
|
||||||
|
$this->saveLog($parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for action name. Used only internally
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function getName()
|
||||||
|
{
|
||||||
|
return 'changeSettings';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use App\Events\CreateNewCustomField;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
|
class LogCreateCustomField extends Logger
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param CreateNewCustomField $event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(CreateNewCustomField $event)
|
||||||
|
{
|
||||||
|
$parameters = [
|
||||||
|
'id' => $event->customField->id,
|
||||||
|
'name' => $event->customField->name
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->saveLog($parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for action name. Used only internally
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function getName()
|
||||||
|
{
|
||||||
|
return 'newCustomField';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use App\Events\CreateNewUser;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
|
class LogCreatedUser extends Logger
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param CreateNewUser $event
|
||||||
|
*/
|
||||||
|
public function handle(CreateNewUser $event)
|
||||||
|
{
|
||||||
|
$parameters = [
|
||||||
|
'id' => $event->user->id,
|
||||||
|
'name' => $event->user->name,
|
||||||
|
'email' => $event->user->email
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->saveLog($parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for action name. Used only internally
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function getName()
|
||||||
|
{
|
||||||
|
return 'createUser';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use App\Events\DeleteCustomField;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
|
class LogDeleteField extends Logger
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param DeleteCustomField $event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(DeleteCustomField $event)
|
||||||
|
{
|
||||||
|
$parameters = [
|
||||||
|
'id' => $event->customField->id,
|
||||||
|
'name' => $event->customField->name
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->saveLog($parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for action name. Used only internally
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function getName()
|
||||||
|
{
|
||||||
|
return 'deleteCustomField';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use App\Events\EditCustomField;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
|
class LogEditCustomField extends Logger
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param EditCustomField $event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(EditCustomField $event)
|
||||||
|
{
|
||||||
|
$parameters = [
|
||||||
|
'id' => $event->customField->id,
|
||||||
|
'name' => $event->customField->name
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->saveLog($parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for action name. Used only internally
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function getName()
|
||||||
|
{
|
||||||
|
return 'editCustomField';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use App\Events\EditUser;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
|
class LogEditUser extends Logger
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param EditUser $event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(EditUser $event)
|
||||||
|
{
|
||||||
|
$parameters = [
|
||||||
|
'id' => $event->user->id,
|
||||||
|
'name' => $event->user->name,
|
||||||
|
'email' => $event->user->email
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->saveLog($parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for action name. Used only internally
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function getName()
|
||||||
|
{
|
||||||
|
return 'userEdit';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use Illuminate\Auth\Events\Login;
|
||||||
|
|
||||||
|
class LogLogin extends Logger
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param Login $event
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(Login $event)
|
||||||
|
{
|
||||||
|
$parameters = [
|
||||||
|
'id' => $event->user->id,
|
||||||
|
'name' => $event->user->name,
|
||||||
|
'email' => $event->user->email
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->saveLog($parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for action name. Used only internally
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function getName()
|
||||||
|
{
|
||||||
|
return 'login';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use Illuminate\Auth\Events\Logout;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
|
class LogLogout extends Logger
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param Logout $event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(Logout $event)
|
||||||
|
{
|
||||||
|
$parameters = [
|
||||||
|
'id' => $event->user->id,
|
||||||
|
'name' => $event->user->name,
|
||||||
|
'email' => $event->user->email
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->saveLog($parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for action name. Used only internally
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function getName()
|
||||||
|
{
|
||||||
|
return 'logout';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use App\Enumerations\ActionLogTypesForLogger;
|
||||||
|
use App\Events\Event;
|
||||||
|
use App\Models\ActionLog;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
abstract class Logger
|
||||||
|
{
|
||||||
|
private $actionTypes = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the event listener.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->actionTypes = ActionLogTypesForLogger::getWithTranslations();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shortcut for loging events
|
||||||
|
*
|
||||||
|
* @param array $parameters
|
||||||
|
*/
|
||||||
|
protected function saveLog($parameters = [])
|
||||||
|
{
|
||||||
|
// try to translate string id into integer id
|
||||||
|
$typeId = $this->getTypeId();
|
||||||
|
|
||||||
|
// is user logged in and exists given type?
|
||||||
|
if (!Auth::check() || is_null($typeId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get user id
|
||||||
|
$userId = Auth::user()->id;
|
||||||
|
|
||||||
|
// setup object for insertion
|
||||||
|
$data = [
|
||||||
|
'user_id' => $userId,
|
||||||
|
'type_id' => $typeId,
|
||||||
|
'parameters' => json_encode((array)$parameters)
|
||||||
|
];
|
||||||
|
|
||||||
|
// create new logged event
|
||||||
|
ActionLog::create($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translate string id to integer id
|
||||||
|
*
|
||||||
|
* @return int|null ID of action type when exists, null otherwise
|
||||||
|
*/
|
||||||
|
private function getTypeId()
|
||||||
|
{
|
||||||
|
$name = $this->getName();
|
||||||
|
if (!isset($this->actionTypes[$name])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->actionTypes[$name];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for action name. Used only internally
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
abstract protected function getName();
|
||||||
|
}
|
||||||
@@ -9,8 +9,9 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
*/
|
*/
|
||||||
class ActionLog extends Model
|
class ActionLog extends Model
|
||||||
{
|
{
|
||||||
|
protected $table = 'action_log';
|
||||||
|
|
||||||
public $timestamps = true;
|
public $timestamps = false;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'type_id',
|
'type_id',
|
||||||
|
|||||||
@@ -13,8 +13,30 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $listen = [
|
protected $listen = [
|
||||||
'App\Events\SomeEvent' => [
|
'App\Events\CreateNewUser' => [
|
||||||
'App\Listeners\EventListener',
|
'App\Listeners\LogCreatedUser',
|
||||||
|
],
|
||||||
|
'App\Events\EditUser' => [
|
||||||
|
'App\Listeners\LogEditUser',
|
||||||
|
],
|
||||||
|
'App\Events\CreateNewCustomField' => [
|
||||||
|
'App\Listeners\LogCreateCustomField',
|
||||||
|
],
|
||||||
|
'App\Events\EditCustomField' => [
|
||||||
|
'App\Listeners\LogEditCustomField',
|
||||||
|
],
|
||||||
|
'App\Events\DeleteCustomField' => [
|
||||||
|
'App\Listeners\LogDeleteField',
|
||||||
|
],
|
||||||
|
'App\Events\ChangeSettings' => [
|
||||||
|
'App\Listeners\LogChangeSettings',
|
||||||
|
],
|
||||||
|
// internal Laravel events - should work as auth.login and auth.logout, however it doesn't...
|
||||||
|
'Illuminate\Auth\Events\Login' => [
|
||||||
|
'App\Listeners\LogLogin'
|
||||||
|
],
|
||||||
|
'Illuminate\Auth\Events\Logout' => [
|
||||||
|
'App\Listeners\LogLogout'
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
|
||||||
|
class AddStringIdForActionTypes extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('action_log_types', function (Blueprint $table) {
|
||||||
|
$table->string('string_id', 64)
|
||||||
|
->after('id')
|
||||||
|
->unique()->comment = 'String ID used for better readability in loggers';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('action_log_types', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('string_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,5 +14,6 @@ class DatabaseSeeder extends Seeder
|
|||||||
// fill up custom field types
|
// fill up custom field types
|
||||||
$this->call(SeedCustomFieldTypes::class);
|
$this->call(SeedCustomFieldTypes::class);
|
||||||
$this->call(SeedCustomFieldResources::class);
|
$this->call(SeedCustomFieldResources::class);
|
||||||
|
$this->call(SeedActionLogTypes::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
class SeedActionLogTypes extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
$types = [
|
||||||
|
'login',
|
||||||
|
'logout',
|
||||||
|
'userEdit',
|
||||||
|
'createUser',
|
||||||
|
'newCustomField',
|
||||||
|
'editCustomField',
|
||||||
|
'deleteCustomField',
|
||||||
|
'changeSettings'
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($types as $type) {
|
||||||
|
\DB::table('action_log_types')
|
||||||
|
->insert([
|
||||||
|
'string_id' => $type,
|
||||||
|
'name' => 'admin/actionLog.name' . ucfirst($type),
|
||||||
|
'value' => 'admin/actionLog.' . $type
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
return [
|
||||||
|
'login' => 'Logged in',
|
||||||
|
'logout' => 'Logged out',
|
||||||
|
'selfUserEdit' => 'Updated self user',
|
||||||
|
'userEdit' => 'Updated someone\'s profile',
|
||||||
|
'changePassword' => 'Changed password',
|
||||||
|
'newCustomField' => 'Added new custom field',
|
||||||
|
'editCustomField' => 'Edited custom field',
|
||||||
|
'deleteCustomField' => 'Deleted custom field',
|
||||||
|
'changeSettings' => 'Changes settings',
|
||||||
|
|
||||||
|
// list of names
|
||||||
|
'nameLogin' => 'Logged in',
|
||||||
|
'nameLogout' => 'Logged out',
|
||||||
|
'nameSelfUserEdit' => 'Updated self user',
|
||||||
|
'nameUserEdit' => 'Updated someone\'s profile',
|
||||||
|
'nameChangePassword' => 'Changed password',
|
||||||
|
'nameNewCustomField' => 'Added new custom field',
|
||||||
|
'nameEditCustomField' => 'Edited custom field',
|
||||||
|
'nameDeleteCustomField' => 'Deleted custom field',
|
||||||
|
'nameChangeSettings' => 'Changes settings',
|
||||||
|
];
|
||||||
Reference in New Issue
Block a user