1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00

Add flag when permissions change

This commit is contained in:
David Bomba 2021-01-29 23:29:42 +11:00
parent af472b21c1
commit 6d278a9c05
4 changed files with 43 additions and 1 deletions

View File

@ -370,14 +370,25 @@ class UserController extends BaseController
public function update(UpdateUserRequest $request, User $user)
{
$old_email = $user->email;
$old_company_user = $user->company_user;
$old_user = $user;
$new_email = $request->input('email');
$user = $this->user_repo->save($request->all(), $user);
$user = $user->fresh();
if ($old_email != $new_email) {
UserEmailChanged::dispatch($new_email, $old_email, auth()->user()->company());
}
if(
strcasecmp($old_company_user->permissions, $user->company_user->permissions) != 0 ||
$old_company_user->is_admin != $user->company_user->is_admin
){
$user->company_user()->update(["permissions_updated_at" => now()]);
}
event(new UserWasUpdated($user, auth()->user(), auth()->user()->company, Ninja::eventVars()));
return $this->itemResponse($user);

View File

@ -28,6 +28,7 @@ class CompanyUser extends Pivot
* @var array
*/
protected $casts = [
'permissions_updated_at' => 'timestamp',
'updated_at' => 'timestamp',
'created_at' => 'timestamp',
'deleted_at' => 'timestamp',

View File

@ -48,7 +48,7 @@ class CompanyUserTransformer extends EntityTransformer
'updated_at' => (int) $company_user->updated_at,
'archived_at' => (int) $company_user->deleted_at,
'created_at' => (int) $company_user->created_at,
'permissions_updated_at' => (int) $company_user->permissions_updated_at,
];
}

View File

@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddPermissionChangedTimestamp extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('company_user', function (Blueprint $table) {
$table->timestamp('permissions_updated_at')->useCurrent();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}