diff --git a/README.md b/README.md index 1aa7022..b4edd11 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ # Online tbbank dashboard + diff --git a/app/Nova/Resources/CurrencyRate.php b/app/Nova/Resources/CurrencyRate.php index 78ec659..a0b987a 100644 --- a/app/Nova/Resources/CurrencyRate.php +++ b/app/Nova/Resources/CurrencyRate.php @@ -4,6 +4,8 @@ namespace App\Nova\Resources; use App\Models\CurrencyRate as ModelsCurrencyRate; use App\Nova\Resource; +use App\Nova\Resources\CurrencyRate\CurrencyRateAuth; +use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Http\Request; use Illuminate\Support\Facades\Gate; use Laravel\Nova\Fields\ID; @@ -13,6 +15,8 @@ use Laravel\Nova\Http\Requests\NovaRequest; class CurrencyRate extends Resource { + use CurrencyRateAuth; + /** * The model the resource corresponds to. * @@ -37,33 +41,11 @@ class CurrencyRate extends Resource ]; /** - * Determine if the given resource is authorizable. - * - * @return bool + * Get the displayable label of the resource. */ - public static function authorizable() + public static function label(): string { - if (auth()->user()->isSystemUser()) { - 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; + return __('Currency rate'); } /** diff --git a/app/Nova/Resources/CurrencyRate/CurrencyRateAuth.php b/app/Nova/Resources/CurrencyRate/CurrencyRateAuth.php new file mode 100644 index 0000000..f626ef3 --- /dev/null +++ b/app/Nova/Resources/CurrencyRate/CurrencyRateAuth.php @@ -0,0 +1,79 @@ +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); + } +} diff --git a/app/Nova/User.php b/app/Nova/User.php index 7e4a67d..6a2e1ff 100644 --- a/app/Nova/User.php +++ b/app/Nova/User.php @@ -132,10 +132,6 @@ class User extends Resource BelongsToMany::make(__('Branches'), 'branches', Branch::class) ->canSeeWhen('isAdmin', $this), - - HasMany::make(__('Loan order'), 'loanOrders', LoanOrder::class), - - HasMany::make(__('Card order'), 'cardOrders', CardOrder::class), ]; } diff --git a/lang/tk.json b/lang/tk.json index 814e373..6ea4567 100644 --- a/lang/tk.json +++ b/lang/tk.json @@ -322,6 +322,7 @@ "Loan Card": "Karz karty", "Send payment": "Tölegi geçir", "Currencies": "Walýutalar", + "Currency rate": "Walýuta kursy", "Passport number": "Pasport nomeri", "Fetch loan history": "Karz taryhyny görmek", "Online payment": "Onlaýn töleg",