mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
User event-listener pairs
This commit is contained in:
parent
6326a3c840
commit
e0da0c14a8
@ -5,7 +5,6 @@ namespace App\DataMapper;
|
||||
use App\DataMapper\ClientSettings;
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\Utils\TranslationHelper;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* ClientSettings
|
||||
@ -118,7 +117,6 @@ class ClientSettings extends BaseSettings
|
||||
{
|
||||
|
||||
if(!isset($client_settings->{$key}) && property_exists($company_settings, $key)) {
|
||||
Log::error('settings ' . $key .' to '. $company_settings->{$key});
|
||||
$client_settings->{$key} = $company_settings->{$key};
|
||||
}
|
||||
|
||||
|
51
app/Events/User/UserWasArchived.php
Normal file
51
app/Events/User/UserWasArchived.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\User;
|
||||
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
/**
|
||||
* Class UserWasArchived
|
||||
* @package App\Events\User
|
||||
*/
|
||||
class UserWasArchived
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @var $user
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* @var $company
|
||||
*/
|
||||
|
||||
public $company;
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($user, $company)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->company = $company;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return \Illuminate\Broadcasting\Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
51
app/Events/User/UserWasDeleted.php
Normal file
51
app/Events/User/UserWasDeleted.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\User;
|
||||
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
/**
|
||||
* Class UserWasDeleted
|
||||
* @package App\Events\User
|
||||
*/
|
||||
class UserWasDeleted
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @var $user
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* @var $company
|
||||
*/
|
||||
|
||||
public $company;
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($user, $company)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->company = $company;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return \Illuminate\Broadcasting\Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
51
app/Events/User/UserWasRestored.php
Normal file
51
app/Events/User/UserWasRestored.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\User;
|
||||
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
/**
|
||||
* Class UserWasRestored
|
||||
* @package App\Events\User
|
||||
*/
|
||||
class UserWasRestored
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @var $user
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* @var $company
|
||||
*/
|
||||
|
||||
public $company;
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($user, $company)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->company = $company;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return \Illuminate\Broadcasting\Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
51
app/Events/User/UserWasUpdated.php
Normal file
51
app/Events/User/UserWasUpdated.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\User;
|
||||
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
/**
|
||||
* Class UserWasUpdated
|
||||
* @package App\Events\User
|
||||
*/
|
||||
class UserWasUpdated
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @var $user
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* @var $company
|
||||
*/
|
||||
|
||||
public $company;
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($user, $company)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->company = $company;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return \Illuminate\Broadcasting\Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
44
app/Listeners/User/ArchivedUserActivity.php
Normal file
44
app/Listeners/User/ArchivedUserActivity.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\User;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Repositories\ActivityRepository;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
|
||||
class ArchivedUserActivity
|
||||
{
|
||||
protected $activityRepo;
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ActivityRepository $activityRepo)
|
||||
{
|
||||
$this->activityRepo = $activityRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param object $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle($event)
|
||||
{
|
||||
|
||||
$fields = new \stdClass;
|
||||
|
||||
if(auth()->user()->id)
|
||||
$fields->user_id = auth()->user()->id;
|
||||
else
|
||||
$fields->user_id = $event->user->id;
|
||||
|
||||
$fields->company_id = $event->user->company_id;
|
||||
$fields->activity_type_id = Activity::ARCHIVE_USER;
|
||||
|
||||
$this->activityRepo->save($fields, $event->user);
|
||||
}
|
||||
}
|
@ -31,7 +31,11 @@ class CreatedUserActivity
|
||||
|
||||
$fields = new \stdClass;
|
||||
|
||||
$fields->user_id = auth()->user()->id;
|
||||
if(auth()->user()->id)
|
||||
$fields->user_id = auth()->user()->id;
|
||||
else
|
||||
$fields->user_id = $event->user->id;
|
||||
|
||||
$fields->company_id = $event->user->company_id;
|
||||
$fields->activity_type_id = Activity::CREATE_USER;
|
||||
|
||||
|
44
app/Listeners/User/DeletedUserActivity.php
Normal file
44
app/Listeners/User/DeletedUserActivity.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\User;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Repositories\ActivityRepository;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
|
||||
class DeletedUserActivity
|
||||
{
|
||||
protected $activityRepo;
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ActivityRepository $activityRepo)
|
||||
{
|
||||
$this->activityRepo = $activityRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param object $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle($event)
|
||||
{
|
||||
|
||||
$fields = new \stdClass;
|
||||
|
||||
if(auth()->user()->id)
|
||||
$fields->user_id = auth()->user()->id;
|
||||
else
|
||||
$fields->user_id = $event->user->id;
|
||||
|
||||
$fields->company_id = $event->user->company_id;
|
||||
$fields->activity_type_id = Activity::DELETE_USER;
|
||||
|
||||
$this->activityRepo->save($fields, $event->user);
|
||||
}
|
||||
}
|
44
app/Listeners/User/RestoredUserActivity.php
Normal file
44
app/Listeners/User/RestoredUserActivity.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\User;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Repositories\ActivityRepository;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
|
||||
class RestoredUserActivity
|
||||
{
|
||||
protected $activityRepo;
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ActivityRepository $activityRepo)
|
||||
{
|
||||
$this->activityRepo = $activityRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param object $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle($event)
|
||||
{
|
||||
|
||||
$fields = new \stdClass;
|
||||
|
||||
if(auth()->user()->id)
|
||||
$fields->user_id = auth()->user()->id;
|
||||
else
|
||||
$fields->user_id = $event->user->id;
|
||||
|
||||
$fields->company_id = $event->user->company_id;
|
||||
$fields->activity_type_id = Activity::RESTORE_USER;
|
||||
|
||||
$this->activityRepo->save($fields, $event->user);
|
||||
}
|
||||
}
|
44
app/Listeners/User/UpdatedUserActivity.php
Normal file
44
app/Listeners/User/UpdatedUserActivity.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\User;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Repositories\ActivityRepository;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
|
||||
class UpdatedUserActivity
|
||||
{
|
||||
protected $activityRepo;
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ActivityRepository $activityRepo)
|
||||
{
|
||||
$this->activityRepo = $activityRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param object $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle($event)
|
||||
{
|
||||
|
||||
$fields = new \stdClass;
|
||||
|
||||
if(auth()->user()->id)
|
||||
$fields->user_id = auth()->user()->id;
|
||||
else
|
||||
$fields->user_id = $event->user->id;
|
||||
|
||||
$fields->company_id = $event->user->company_id;
|
||||
$fields->activity_type_id = Activity::UPDATE_USER;
|
||||
|
||||
$this->activityRepo->save($fields, $event->user);
|
||||
}
|
||||
}
|
@ -15,6 +15,11 @@ class CompanyToken extends BaseModel
|
||||
'id',
|
||||
];
|
||||
|
||||
protected $with = [
|
||||
// 'user',
|
||||
// 'company',
|
||||
];
|
||||
|
||||
public function account()
|
||||
{
|
||||
return $this->belongsTo(Account::class);
|
||||
|
Loading…
Reference in New Issue
Block a user