mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Updates a user
This commit is contained in:
parent
d9c216433a
commit
26f2bf71d5
@ -13,7 +13,6 @@ namespace App\Http\Requests\User;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Http\ValidationRules\UniqueUserRule;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class UpdateUserRequest extends Request
|
||||
{
|
||||
@ -25,7 +24,6 @@ class UpdateUserRequest extends Request
|
||||
|
||||
public function authorize() : bool
|
||||
{
|
||||
Log::error($this->user);
|
||||
return auth()->user()->can('edit', $this->user);
|
||||
|
||||
}
|
||||
@ -33,6 +31,7 @@ Log::error($this->user);
|
||||
|
||||
public function rules()
|
||||
{
|
||||
$this->sanitize();
|
||||
|
||||
$input = $this->all();
|
||||
|
||||
@ -43,4 +42,18 @@ Log::error($this->user);
|
||||
];
|
||||
}
|
||||
|
||||
public function sanitize()
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
|
||||
if(!isset($input['email']))
|
||||
{
|
||||
$input['email'] = null;
|
||||
}
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -12,6 +12,7 @@
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\CompanyUser;
|
||||
use App\Models\User;
|
||||
|
||||
/**
|
||||
@ -30,15 +31,21 @@ class UserPolicy extends EntityPolicy
|
||||
{
|
||||
|
||||
return $user->isAdmin() || $user->hasPermission('create_user');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//we need to override as User does not have the company_id property!!!!!
|
||||
/*
|
||||
*
|
||||
* We need to override as User does not have the company_id property!!!!!
|
||||
*
|
||||
* We use the CompanyUser table as a proxy
|
||||
*/
|
||||
public function edit(User $user, $user_entity) : bool
|
||||
{
|
||||
$company_user = CompanyUser::whereUserId($user_entity->id)->whereCompanyId($user->companyId())->first();
|
||||
|
||||
return ($user->isAdmin() && $user_entity->companyId() == $user->companyId());;
|
||||
return ($user->isAdmin() && $company_user);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user