2021-11-06 00:28:48 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2021-11-06 00:28:48 +01:00
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Requests\User;
|
|
|
|
|
|
|
|
use App\Http\Requests\Request;
|
|
|
|
use App\Http\ValidationRules\Ninja\CanRestoreUserRule;
|
2023-10-26 04:57:44 +02:00
|
|
|
use App\Utils\Ninja;
|
|
|
|
use Illuminate\Auth\Access\AuthorizationException;
|
2021-11-06 00:28:48 +01:00
|
|
|
|
|
|
|
class BulkUserRequest extends Request
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function authorize() : bool
|
2023-05-09 05:37:53 +02:00
|
|
|
{
|
2023-10-26 04:57:44 +02:00
|
|
|
if($this->action == 'delete' && in_array(auth()->user()->hashed_id, $this->ids)) {
|
2023-05-09 05:01:27 +02:00
|
|
|
return false;
|
2023-10-26 04:57:44 +02:00
|
|
|
}
|
2023-05-09 05:01:27 +02:00
|
|
|
|
2021-11-06 00:28:48 +01:00
|
|
|
return auth()->user()->isAdmin();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
$rules = [];
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if (Ninja::isHosted() && $this->action && $this->action == 'restore') {
|
2021-11-06 00:28:48 +01:00
|
|
|
$rules['ids'] = new CanRestoreUserRule();
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-11-06 00:28:48 +01:00
|
|
|
|
|
|
|
return $rules;
|
|
|
|
}
|
|
|
|
|
2022-06-24 03:55:41 +02:00
|
|
|
public function prepareForValidation()
|
2021-11-06 00:28:48 +01:00
|
|
|
{
|
|
|
|
$input = $this->all();
|
|
|
|
|
|
|
|
$this->replace($input);
|
|
|
|
}
|
2023-05-09 05:01:27 +02:00
|
|
|
|
|
|
|
protected function failedAuthorization()
|
|
|
|
{
|
|
|
|
throw new AuthorizationException("This Action is unauthorized.");
|
|
|
|
}
|
2021-11-06 00:28:48 +01:00
|
|
|
}
|