1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Revert for scheduler storatge

This commit is contained in:
David Bomba 2023-12-17 07:40:45 +11:00
parent f58018c8e8
commit 4edb123d42
2 changed files with 11 additions and 76 deletions

View File

@ -11,18 +11,13 @@
namespace App\Http\Requests\TaskScheduler; namespace App\Http\Requests\TaskScheduler;
use App\Utils\Ninja;
use App\Http\Requests\Request; use App\Http\Requests\Request;
use App\Utils\Traits\MakesHash;
use Illuminate\Auth\Access\AuthorizationException;
use App\Http\ValidationRules\Scheduler\ValidClientIds; use App\Http\ValidationRules\Scheduler\ValidClientIds;
use App\Utils\Traits\MakesHash;
class StoreSchedulerRequest extends Request class StoreSchedulerRequest extends Request
{ {
use MakesHash; use MakesHash;
private string $error_message = '';
/** /**
* Determine if the user is authorized to make this request. * Determine if the user is authorized to make this request.
* *
@ -30,13 +25,10 @@ class StoreSchedulerRequest extends Request
*/ */
public function authorize(): bool public function authorize(): bool
{ {
// /** @var \App\Models\User $user */ /** @var \App\Models\User $user */
// $user = auth()->user(); $user = auth()->user();
// return $user->isAdmin();
return $this->checkUserAbleToSave();
return $user->isAdmin();
} }
public function rules() public function rules()
@ -82,39 +74,11 @@ class StoreSchedulerRequest extends Request
if(isset($input['parameters']['status'])) { if(isset($input['parameters']['status'])) {
$input['parameters']['status'] = collect(explode(",", $input['parameters']['status'])) $input['parameters']['status'] = collect(explode(",", $input['parameters']['status']))
->filter(function($status) { ->filter(function ($status) {
return in_array($status, ['all','draft','paid','unpaid','overdue']); return in_array($status, ['all','draft','paid','unpaid','overdue']);
})->implode(",") ?? ''; })->implode(",") ?? '';
} }
$this->replace($input); $this->replace($input);
} }
private function checkUserAbleToSave()
{
$this->error_message = ctrans('texts.authorization_failure');
/** @var \App\Models\User $user */
$user = auth()->user();
if(Ninja::isSelfHost() && $user->isAdmin())
return true;
if(Ninja::isHosted() && $user->account->isPaid() && $user->isAdmin()) {
return true;
}
if(Ninja::isHosted() && !$user->account->isPaid())
$this->error_message = ctrans('texts.upgrade_to_paid_plan');
return false;
}
protected function failedAuthorization()
{
throw new AuthorizationException($this->error_message);
}
} }

View File

@ -10,16 +10,11 @@
*/ */
namespace App\Http\Requests\TaskScheduler; namespace App\Http\Requests\TaskScheduler;
use App\Utils\Ninja;
use App\Http\Requests\Request; use App\Http\Requests\Request;
use Illuminate\Auth\Access\AuthorizationException;
use App\Http\ValidationRules\Scheduler\ValidClientIds; use App\Http\ValidationRules\Scheduler\ValidClientIds;
class UpdateSchedulerRequest extends Request class UpdateSchedulerRequest extends Request
{ {
private string $error_message = '';
/** /**
* Determine if the user is authorized to make this request. * Determine if the user is authorized to make this request.
* *
@ -27,9 +22,10 @@ class UpdateSchedulerRequest extends Request
*/ */
public function authorize(): bool public function authorize(): bool
{ {
/** @var \App\Models\User $user */
$user = auth()->user();
return $this->checkUserAbleToSave(); return $user->isAdmin() && $this->task_scheduler->company_id == $user->company()->id;
} }
public function rules(): array public function rules(): array
@ -82,32 +78,7 @@ class UpdateSchedulerRequest extends Request
$this->replace($input); $this->replace($input);
} }
private function checkUserAbleToSave()
{
$this->error_message = ctrans('texts.authorization_failure');
/** @var \App\Models\User $user */
$user = auth()->user();
if(Ninja::isSelfHost() && $user->isAdmin() && $this->task_scheduler->company_id == $user->company()->id)
return true;
if(Ninja::isHosted() && $user->account->isPaid() && $user->isAdmin() && $this->task_scheduler->company_id == $user->company()->id) {
return true;
}
if(Ninja::isHosted() && !$user->account->isPaid())
$this->error_message = ctrans('texts.upgrade_to_paid_plan');
return false;
}
protected function failedAuthorization()
{
throw new AuthorizationException($this->error_message);
}
} }