Currency rate

This commit is contained in:
2024-11-09 13:57:22 +05:00
parent 914e54859c
commit 56f42848f5
5 changed files with 88 additions and 29 deletions

View File

@@ -1 +1,2 @@
# Online tbbank dashboard # Online tbbank dashboard

View File

@@ -4,6 +4,8 @@ namespace App\Nova\Resources;
use App\Models\CurrencyRate as ModelsCurrencyRate; use App\Models\CurrencyRate as ModelsCurrencyRate;
use App\Nova\Resource; use App\Nova\Resource;
use App\Nova\Resources\CurrencyRate\CurrencyRateAuth;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Gate;
use Laravel\Nova\Fields\ID; use Laravel\Nova\Fields\ID;
@@ -13,6 +15,8 @@ use Laravel\Nova\Http\Requests\NovaRequest;
class CurrencyRate extends Resource class CurrencyRate extends Resource
{ {
use CurrencyRateAuth;
/** /**
* The model the resource corresponds to. * The model the resource corresponds to.
* *
@@ -37,33 +41,11 @@ class CurrencyRate extends Resource
]; ];
/** /**
* Determine if the given resource is authorizable. * Get the displayable label of the resource.
*
* @return bool
*/ */
public static function authorizable() public static function label(): string
{ {
if (auth()->user()->isSystemUser()) { return __('Currency rate');
return false;
}
// disables
return true;
}
/**
* Determine if the resource should be available for the given request.
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
public static function authorizedToViewAny(Request $request)
{
if (auth()->user()->isSystemUser()) {
return true;
}
return false;
} }
/** /**

View File

@@ -0,0 +1,79 @@
<?php
namespace App\Nova\Resources\CurrencyRate;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Http\Request;
trait CurrencyRateAuth
{
/** View */
public function authorizeToView(Request $request)
{
$user = auth()->user();
if ($user->isSystemUser()) {
return;
}
throw new AuthorizationException();
}
/** Edit button */
public function authorizedToUpdate(Request $request): bool
{
$user = auth()->user();
if ($user->isSystemUser()) {
return true;
}
return false;
}
/** Update */
public function authorizeToUpdate(Request $request): void
{
$user = auth()->user();
if ($user->isSystemUser()) {
return;
}
if ($this->resource->user_id == auth()->id()) {
return;
}
throw new AuthorizationException();
}
/** Delete button */
public function authorizedToDelete(Request $request)
{
$user = auth()->user();
if ($user->isMe()) {
return true;
}
return false;
}
/** Delete */
public function authorizeToDelete(Request $request)
{
$user = auth()->user();
if ($user->isMe()) {
return;
}
throw new AuthorizationException();
}
/** Force delete */
public function authorizedToForceDelete(Request $request)
{
throw_unless(auth()->user()->isMe(), AuthorizationException::class);
}
}

View File

@@ -132,10 +132,6 @@ class User extends Resource
BelongsToMany::make(__('Branches'), 'branches', Branch::class) BelongsToMany::make(__('Branches'), 'branches', Branch::class)
->canSeeWhen('isAdmin', $this), ->canSeeWhen('isAdmin', $this),
HasMany::make(__('Loan order'), 'loanOrders', LoanOrder::class),
HasMany::make(__('Card order'), 'cardOrders', CardOrder::class),
]; ];
} }

View File

@@ -322,6 +322,7 @@
"Loan Card": "Karz karty", "Loan Card": "Karz karty",
"Send payment": "Tölegi geçir", "Send payment": "Tölegi geçir",
"Currencies": "Walýutalar", "Currencies": "Walýutalar",
"Currency rate": "Walýuta kursy",
"Passport number": "Pasport nomeri", "Passport number": "Pasport nomeri",
"Fetch loan history": "Karz taryhyny görmek", "Fetch loan history": "Karz taryhyny görmek",
"Online payment": "Onlaýn töleg", "Online payment": "Onlaýn töleg",