Fixes for permissions

This commit is contained in:
David Bomba 2024-02-12 20:16:35 +11:00
parent 91e23ee189
commit 909db91184
8 changed files with 25 additions and 25 deletions

View File

@ -225,22 +225,6 @@ class ClientExport extends BaseExport
$entity['client.assigned_user'] = $client->assigned_user ? $client->user->present()->name() : ''; $entity['client.assigned_user'] = $client->assigned_user ? $client->user->present()->name() : '';
} }
// if (in_array('client.country_id', $this->input['report_keys'])) {
// $entity['client.country_id'] = $client->country ? ctrans("texts.country_{$client->country->name}") : '';
// }
// if (in_array('client.shipping_country_id', $this->input['report_keys'])) {
// $entity['client.shipping_country_id'] = $client->shipping_country ? ctrans("texts.country_{$client->shipping_country->name}") : '';
// }
// if (in_array('client.currency_id', $this->input['report_keys'])) {
// $entity['client.currency_id'] = $client->currency() ? $client->currency()->code : $client->company->currency()->code;
// }
// if (in_array('client.industry_id', $this->input['report_keys'])) {
// $entity['industry_id'] = $client->industry ? ctrans("texts.industry_{$client->industry->name}") : '';
// }
if (in_array('client.classification', $this->input['report_keys']) && isset($client->classification)) { if (in_array('client.classification', $this->input['report_keys']) && isset($client->classification)) {
$entity['client.classification'] = ctrans("texts.{$client->classification}") ?? ''; $entity['client.classification'] = ctrans("texts.{$client->classification}") ?? '';
} }

View File

@ -93,7 +93,7 @@ class StoreClientRequest extends Request
$rules['number'] = ['bail', 'nullable', Rule::unique('clients')->where('company_id', $user->company()->id)]; $rules['number'] = ['bail', 'nullable', Rule::unique('clients')->where('company_id', $user->company()->id)];
$rules['id_number'] = ['bail', 'nullable', Rule::unique('clients')->where('company_id', $user->company()->id)]; $rules['id_number'] = ['bail', 'nullable', Rule::unique('clients')->where('company_id', $user->company()->id)];
$rules['classification'] = 'bail|sometimes|nullable|in:individual,business,partnership,trust,charity,government,other'; $rules['classification'] = 'bail|sometimes|nullable|in:individual,business,company,partnership,trust,charity,government,other';
return $rules; return $rules;
} }

View File

@ -60,7 +60,7 @@ class UpdateClientRequest extends Request
$rules['size_id'] = 'integer|nullable'; $rules['size_id'] = 'integer|nullable';
$rules['country_id'] = 'integer|nullable'; $rules['country_id'] = 'integer|nullable';
$rules['shipping_country_id'] = 'integer|nullable'; $rules['shipping_country_id'] = 'integer|nullable';
$rules['classification'] = 'bail|sometimes|nullable|in:individual,business,partnership,trust,charity,government,other'; $rules['classification'] = 'bail|sometimes|nullable|in:individual,business,company,partnership,trust,charity,government,other';
if ($this->id_number) { if ($this->id_number) {
$rules['id_number'] = Rule::unique('clients')->where('company_id', $user->company()->id)->ignore($this->client->id); $rules['id_number'] = Rule::unique('clients')->where('company_id', $user->company()->id)->ignore($this->client->id);

View File

@ -11,6 +11,7 @@
namespace App\Http\Requests\ExpenseCategory; namespace App\Http\Requests\ExpenseCategory;
use App\Models\Expense;
use App\Http\Requests\Request; use App\Http\Requests\Request;
use App\Models\ExpenseCategory; use App\Models\ExpenseCategory;
@ -23,14 +24,21 @@ class StoreExpenseCategoryRequest extends Request
*/ */
public function authorize(): bool public function authorize(): bool
{ {
return auth()->user()->can('create', ExpenseCategory::class); /** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('create', ExpenseCategory::class) || $user->can('create', Expense::class);
} }
public function rules() public function rules()
{ {
/** @var \App\Models\User $user */
$user = auth()->user();
$rules = []; $rules = [];
$rules['name'] = 'required|unique:expense_categories,name,null,null,company_id,'.auth()->user()->companyId(); $rules['name'] = 'required|unique:expense_categories,name,null,null,company_id,'.$user->companyId();
return $this->globalRules($rules); return $this->globalRules($rules);
} }

View File

@ -26,16 +26,24 @@ class UpdateExpenseCategoryRequest extends Request
*/ */
public function authorize(): bool public function authorize(): bool
{ {
return auth()->user()->can('edit', $this->expense_category);
/** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('edit', $this->expense_category);
} }
public function rules() public function rules()
{ {
/** @var \App\Models\User $user */
$user = auth()->user();
$rules = []; $rules = [];
if ($this->input('name')) { if ($this->input('name')) {
// $rules['name'] = 'unique:expense_categories,name,'.$this->id.',id,company_id,'.$this->expense_category->company_id; // $rules['name'] = 'unique:expense_categories,name,'.$this->id.',id,company_id,'.$this->expense_category->company_id;
$rules['name'] = Rule::unique('expense_categories')->where('company_id', auth()->user()->company()->id)->ignore($this->expense_category->id); $rules['name'] = Rule::unique('expense_categories')->where('company_id', $user->company()->id)->ignore($this->expense_category->id);
} }
return $rules; return $rules;

View File

@ -73,7 +73,7 @@ class StoreVendorRequest extends Request
} }
$rules['language_id'] = 'bail|nullable|sometimes|exists:languages,id'; $rules['language_id'] = 'bail|nullable|sometimes|exists:languages,id';
$rules['classification'] = 'bail|sometimes|nullable|in:individual,company,partnership,trust,charity,government,other'; $rules['classification'] = 'bail|sometimes|nullable|in:individual,business,company,partnership,trust,charity,government,other';
return $rules; return $rules;
} }

View File

@ -74,7 +74,7 @@ class UpdateVendorRequest extends Request
} }
$rules['language_id'] = 'bail|nullable|sometimes|exists:languages,id'; $rules['language_id'] = 'bail|nullable|sometimes|exists:languages,id';
$rules['classification'] = 'bail|sometimes|nullable|in:individual,company,partnership,trust,charity,government,other'; $rules['classification'] = 'bail|sometimes|nullable|in:individual,business,company,partnership,trust,charity,government,other';
return $rules; return $rules;
} }

View File

@ -5120,7 +5120,7 @@ $lang = array(
'set_private' => 'Set private', 'set_private' => 'Set private',
'individual' => 'Individual', 'individual' => 'Individual',
'business' => 'Business', 'business' => 'Business',
'partnership' => 'partnership', 'partnership' => 'Partnership',
'trust' => 'Trust', 'trust' => 'Trust',
'charity' => 'Charity', 'charity' => 'Charity',
'government' => 'Government', 'government' => 'Government',