mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
User Activities
This commit is contained in:
parent
c49fbedcde
commit
7d46ec489a
@ -31,6 +31,8 @@ class UserWasArchived
|
||||
*/
|
||||
public $user;
|
||||
|
||||
public $creating_user;
|
||||
|
||||
public $company;
|
||||
|
||||
public $event_vars;
|
||||
@ -42,9 +44,10 @@ class UserWasArchived
|
||||
* @param Company $company
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(User $user, Company $company, array $event_vars)
|
||||
public function __construct(User $user, User $creating_user, Company $company, array $event_vars)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->creating_user = $creating_user;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ class UserWasCreated
|
||||
*/
|
||||
public $user;
|
||||
|
||||
public $creating_user;
|
||||
|
||||
public $company;
|
||||
|
||||
public $event_vars;
|
||||
@ -42,9 +44,10 @@ class UserWasCreated
|
||||
* @param Company $company
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(User $user, Company $company, array $event_vars)
|
||||
public function __construct(User $user, User $creating_user, Company $company, array $event_vars)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->creating_user = $creating_user;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ class UserWasDeleted
|
||||
*/
|
||||
public $user;
|
||||
|
||||
public $creating_user;
|
||||
|
||||
public $company;
|
||||
|
||||
public $event_vars;
|
||||
@ -42,9 +44,10 @@ class UserWasDeleted
|
||||
* @param Company $company
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(User $user, Company $company, array $event_vars)
|
||||
public function __construct(User $user, User $creating_user, Company $company, array $event_vars)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->creating_user = $creating_user;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class UserWasRestored
|
||||
|
||||
public $event_vars;
|
||||
|
||||
public $fromDeleted;
|
||||
public $creating_user;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
@ -44,12 +44,12 @@ class UserWasRestored
|
||||
* @param Company $company
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(User $user, bool $fromDeleted, Company $company, array $event_vars)
|
||||
public function __construct(User $user, User $creating_user, Company $company, array $event_vars)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
$this->fromDeleted = $fromDeleted;
|
||||
$this->creating_user = $creating_user;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,6 +31,8 @@ class UserWasUpdated
|
||||
*/
|
||||
public $user;
|
||||
|
||||
public $creating_user;
|
||||
|
||||
public $company;
|
||||
|
||||
public $event_vars;
|
||||
@ -42,9 +44,10 @@ class UserWasUpdated
|
||||
* @param Company $company
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(User $user, Company $company, array $event_vars)
|
||||
public function __construct(User $user, User $creating_user, Company $company, array $event_vars)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->creating_user = $creating_user;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\Events\User\UserWasCreated;
|
||||
use App\Events\User\UserWasDeleted;
|
||||
use App\Events\User\UserWasUpdated;
|
||||
use App\Factory\UserFactory;
|
||||
use App\Filters\UserFilters;
|
||||
use App\Http\Controllers\Traits\VerifiesUserEmail;
|
||||
@ -202,7 +204,7 @@ class UserController extends BaseController
|
||||
|
||||
$ct = CreateCompanyToken::dispatchNow($company, $user, $user_agent);
|
||||
|
||||
event(new UserWasCreated($user, $company, Ninja::eventVars()));
|
||||
event(new UserWasCreated($user, auth()->user(), $company, Ninja::eventVars()));
|
||||
|
||||
return $this->itemResponse($user->fresh());
|
||||
}
|
||||
@ -376,6 +378,8 @@ class UserController extends BaseController
|
||||
UserEmailChanged::dispatch($new_email, $old_email, auth()->user()->company());
|
||||
}
|
||||
|
||||
event(new UserWasUpdated($user, auth()->user(), auth()->user()->company, Ninja::eventVars()));
|
||||
|
||||
return $this->itemResponse($user);
|
||||
}
|
||||
|
||||
@ -444,6 +448,8 @@ class UserController extends BaseController
|
||||
/* If the user passes the company user we archive the company user */
|
||||
$user = $this->user_repo->destroy($request->all(), $user);
|
||||
|
||||
event(new UserWasDeleted($user, auth()->user(), auth()->user()->company, Ninja::eventVars()));
|
||||
|
||||
return $this->itemResponse($user->fresh());
|
||||
}
|
||||
|
||||
|
@ -43,13 +43,10 @@ class ArchivedUserActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
if (auth()->user()->id) {
|
||||
$fields->user_id = auth()->user()->id;
|
||||
} else {
|
||||
$fields->user_id = $event->user->id;
|
||||
}
|
||||
$fields->user_id = $event->user->id;
|
||||
$fields->notes = $event->creating_user->present()->name . " Archived User";
|
||||
|
||||
$fields->company_id = $event->user->company_id;
|
||||
$fields->company_id = $event->company->id;
|
||||
$fields->activity_type_id = Activity::ARCHIVE_USER;
|
||||
|
||||
$this->activityRepo->save($fields, $event->user, $event->event_vars);
|
||||
|
@ -43,13 +43,9 @@ class CreatedUserActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
if (auth()->user()) {
|
||||
$fields->user_id = auth()->user()->id;
|
||||
} else {
|
||||
$fields->user_id = $event->user->id;
|
||||
}
|
||||
|
||||
$fields->company_id = $event->user->company_id;
|
||||
$fields->user_id = $event->user->id;
|
||||
$fields->notes = $event->creating_user->present()->name() . " Created the user";
|
||||
$fields->company_id = $event->company->id;
|
||||
$fields->activity_type_id = Activity::CREATE_USER;
|
||||
|
||||
$this->activityRepo->save($fields, $event->user, $event->event_vars);
|
||||
|
@ -48,12 +48,8 @@ class DeletedUserActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
if (auth()->check()) {
|
||||
$fields->user_id = auth()->user()->id;
|
||||
} else {
|
||||
$fields->user_id = $event->user->id;
|
||||
}
|
||||
|
||||
$fields->user_id = $event->user->id;
|
||||
$fields->notes = $event->creating_user->present()->name . " Deleted User";
|
||||
$fields->company_id = $event->company->id;
|
||||
$fields->activity_type_id = Activity::DELETE_USER;
|
||||
|
||||
|
@ -43,13 +43,10 @@ class RestoredUserActivity implements ShouldQueue
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
if (auth()->user()->id) {
|
||||
$fields->user_id = auth()->user()->id;
|
||||
} else {
|
||||
$fields->user_id = $event->user->id;
|
||||
}
|
||||
$fields->user_id = $event->user->id;
|
||||
$fields->notes = $event->creating_user->present()->name() . " Restored user";
|
||||
|
||||
$fields->company_id = $event->user->company_id;
|
||||
$fields->company_id = $event->company->id;
|
||||
$fields->activity_type_id = Activity::RESTORE_USER;
|
||||
|
||||
$this->activityRepo->save($fields, $event->user, $event->event_vars);
|
||||
|
@ -42,14 +42,9 @@ class UpdatedUserActivity implements ShouldQueue
|
||||
MultiDB::setDb($event->company->db);
|
||||
|
||||
$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->user_id = $event->user->id;
|
||||
$fields->notes = $event->creating_user->present()->name . " Updated user";
|
||||
$fields->company_id = $event->company->id;
|
||||
$fields->activity_type_id = Activity::UPDATE_USER;
|
||||
|
||||
$this->activityRepo->save($fields, $event->user, $event->event_vars);
|
||||
|
@ -65,11 +65,11 @@ class Activity extends StaticModel
|
||||
const RESTORE_TASK = 46; //
|
||||
const UPDATE_EXPENSE = 47;//
|
||||
|
||||
const CREATE_USER = 48; // only used in CreateUser::job
|
||||
const UPDATE_USER = 49; // not needed?
|
||||
const ARCHIVE_USER = 50; // not needed?
|
||||
const DELETE_USER = 51; // not needed?
|
||||
const RESTORE_USER = 52; // not needed?
|
||||
const CREATE_USER = 48;
|
||||
const UPDATE_USER = 49;
|
||||
const ARCHIVE_USER = 50;
|
||||
const DELETE_USER = 51;
|
||||
const RESTORE_USER = 52;
|
||||
const MARK_SENT_INVOICE = 53; // not needed?
|
||||
const PAID_INVOICE = 54; //
|
||||
const EMAIL_INVOICE_FAILED = 57;
|
||||
|
@ -34,7 +34,8 @@ class SystemLog extends Model
|
||||
const CATEGORY_GATEWAY_RESPONSE = 1;
|
||||
const CATEGORY_MAIL = 2;
|
||||
const CATEGORY_WEBHOOK = 3;
|
||||
const CATEGORY_PDF = 3;
|
||||
const CATEGORY_PDF = 4;
|
||||
const CATEGORY_SECURITY = 5;
|
||||
|
||||
/* Event IDs*/
|
||||
const EVENT_PAYMENT_RECONCILIATION_FAILURE = 10;
|
||||
@ -50,6 +51,9 @@ class SystemLog extends Model
|
||||
const EVENT_WEBHOOK_RESPONSE = 40;
|
||||
const EVENT_PDF_RESPONSE = 50;
|
||||
|
||||
const EVENT_AUTHENTICATION_FAILURE = 60;
|
||||
const EVENT_USER = 61;
|
||||
|
||||
/*Type IDs*/
|
||||
const TYPE_PAYPAL = 300;
|
||||
const TYPE_STRIPE = 301;
|
||||
@ -62,9 +66,13 @@ class SystemLog extends Model
|
||||
const TYPE_UPSTREAM_FAILURE = 401;
|
||||
|
||||
const TYPE_WEBHOOK_RESPONSE = 500;
|
||||
|
||||
const TYPE_PDF_FAILURE = 600;
|
||||
const TYPE_PDF_SUCCESS = 601;
|
||||
|
||||
const TYPE_MODIFIED = 701;
|
||||
const TYPE_DELETED = 702;
|
||||
|
||||
protected $fillable = [
|
||||
'client_id',
|
||||
'company_id',
|
||||
|
@ -72,8 +72,11 @@ use App\Events\Task\TaskWasDeleted;
|
||||
use App\Events\Task\TaskWasRestored;
|
||||
use App\Events\Task\TaskWasUpdated;
|
||||
use App\Events\User\UserLoggedIn;
|
||||
use App\Events\User\UserWasArchived;
|
||||
use App\Events\User\UserWasCreated;
|
||||
use App\Events\User\UserWasDeleted;
|
||||
use App\Events\User\UserWasRestored;
|
||||
use App\Events\User\UserWasUpdated;
|
||||
use App\Events\Vendor\VendorWasArchived;
|
||||
use App\Events\Vendor\VendorWasCreated;
|
||||
use App\Events\Vendor\VendorWasDeleted;
|
||||
@ -123,8 +126,8 @@ use App\Listeners\Invoice\InvoiceArchivedActivity;
|
||||
use App\Listeners\Invoice\InvoiceCancelledActivity;
|
||||
use App\Listeners\Invoice\InvoiceDeletedActivity;
|
||||
use App\Listeners\Invoice\InvoiceEmailActivity;
|
||||
use App\Listeners\Invoice\InvoiceEmailedNotification;
|
||||
use App\Listeners\Invoice\InvoiceEmailFailedActivity;
|
||||
use App\Listeners\Invoice\InvoiceEmailedNotification;
|
||||
use App\Listeners\Invoice\InvoicePaidActivity;
|
||||
use App\Listeners\Invoice\InvoiceReminderEmailActivity;
|
||||
use App\Listeners\Invoice\InvoiceRestoredActivity;
|
||||
@ -132,8 +135,8 @@ use App\Listeners\Invoice\InvoiceReversedActivity;
|
||||
use App\Listeners\Invoice\InvoiceViewedActivity;
|
||||
use App\Listeners\Invoice\UpdateInvoiceActivity;
|
||||
use App\Listeners\Misc\InvitationViewedListener;
|
||||
use App\Listeners\Payment\PaymentEmailedActivity;
|
||||
use App\Listeners\Payment\PaymentEmailFailureActivity;
|
||||
use App\Listeners\Payment\PaymentEmailedActivity;
|
||||
use App\Listeners\Payment\PaymentNotification;
|
||||
use App\Listeners\Payment\PaymentRestoredActivity;
|
||||
use App\Listeners\Quote\QuoteApprovedActivity;
|
||||
@ -145,8 +148,12 @@ use App\Listeners\Quote\QuoteRestoredActivity;
|
||||
use App\Listeners\Quote\QuoteViewedActivity;
|
||||
use App\Listeners\Quote\ReachWorkflowSettings;
|
||||
use App\Listeners\SendVerificationNotification;
|
||||
use App\Listeners\User\ArchivedUserActivity;
|
||||
use App\Listeners\User\CreatedUserActivity;
|
||||
use App\Listeners\User\DeletedUserActivity;
|
||||
use App\Listeners\User\RestoredUserActivity;
|
||||
use App\Listeners\User\UpdateUserLastLogin;
|
||||
use App\Listeners\User\UpdatedUserActivity;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
@ -158,14 +165,24 @@ class EventServiceProvider extends ServiceProvider
|
||||
*/
|
||||
protected $listen = [
|
||||
UserWasCreated::class => [
|
||||
CreatedUserActivity::class,
|
||||
SendVerificationNotification::class,
|
||||
],
|
||||
UserWasDeleted::class => [
|
||||
DeletedUserActivity::class,
|
||||
],
|
||||
UserWasArchived::class => [
|
||||
ArchivedUserActivity::class,
|
||||
],
|
||||
UserLoggedIn::class => [
|
||||
UpdateUserLastLogin::class,
|
||||
],
|
||||
UserWasUpdated::class => [
|
||||
UpdatedUserActivity::class,
|
||||
],
|
||||
UserWasRestored::class => [
|
||||
RestoredUserActivity::class,
|
||||
],
|
||||
ContactLoggedIn::class => [
|
||||
UpdateContactLastLogin::class,
|
||||
],
|
||||
|
@ -19,6 +19,7 @@ use App\Models\Design;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Quote;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Models\User;
|
||||
use App\Services\PdfMaker\Design as PdfDesignModel;
|
||||
use App\Services\PdfMaker\Design as PdfMakerDesign;
|
||||
use App\Services\PdfMaker\PdfMaker as PdfMakerService;
|
||||
@ -69,7 +70,12 @@ class ActivityRepository extends BaseRepository
|
||||
*/
|
||||
public function createBackup($entity, $activity)
|
||||
{
|
||||
if ($entity->company->is_disabled) {
|
||||
nlog($entity);
|
||||
|
||||
if($entity instanceof User){
|
||||
|
||||
}
|
||||
else if ($entity->company->is_disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,9 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\Events\User\UserWasArchived;
|
||||
use App\Events\User\UserWasDeleted;
|
||||
use App\Events\User\UserWasRestored;
|
||||
use App\Models\CompanyUser;
|
||||
use App\Models\User;
|
||||
use App\Utils\Ninja;
|
||||
@ -137,7 +139,7 @@ class UserRepository extends BaseRepository
|
||||
$cu->delete();
|
||||
}
|
||||
|
||||
event(new UserWasDeleted($user, $company, Ninja::eventVars()));
|
||||
event(new UserWasDeleted($user, auth()->user(), $company, Ninja::eventVars()));
|
||||
|
||||
$user->is_deleted = true;
|
||||
$user->save();
|
||||
@ -146,4 +148,31 @@ class UserRepository extends BaseRepository
|
||||
|
||||
return $user->fresh();
|
||||
}
|
||||
|
||||
public function archive($user)
|
||||
{
|
||||
if ($user->trashed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$user->delete();
|
||||
|
||||
event(new UserWasArchived($user, auth()->user(), auth()->user()->company, Ninja::eventVars()));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $entity
|
||||
*/
|
||||
public function restore($user)
|
||||
{
|
||||
if (! $user->trashed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$user->restore();
|
||||
|
||||
event(new UserWasRestored($user, auth()->user(), auth()->user()->company, Ninja::eventVars()));
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user