loan order permissions
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models\Branch;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Spatie\Translatable\HasTranslations;
|
||||
@@ -44,4 +45,12 @@ class Branch extends Model
|
||||
'name',
|
||||
'address',
|
||||
];
|
||||
|
||||
/**
|
||||
* Branches associated with user
|
||||
*/
|
||||
public function users(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use App\Models\Branch\Branch;
|
||||
use App\Models\Order\Loan\LoanOrder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
@@ -47,7 +51,23 @@ class User extends Authenticatable
|
||||
];
|
||||
|
||||
/**
|
||||
* User is me?
|
||||
* Branches associated with user
|
||||
*/
|
||||
public function branches(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Branch::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loan orders user created
|
||||
*/
|
||||
public function loanOrders(): HasMany
|
||||
{
|
||||
return $this->hasMany(LoanOrder::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is me.
|
||||
*/
|
||||
public function isMe(): bool
|
||||
{
|
||||
@@ -55,7 +75,7 @@ class User extends Authenticatable
|
||||
}
|
||||
|
||||
/**
|
||||
* Is user admin?
|
||||
* Check if user is admin.
|
||||
*/
|
||||
public function isAdmin(): bool
|
||||
{
|
||||
@@ -65,4 +85,20 @@ class User extends Authenticatable
|
||||
|
||||
return $this->hasRole(['king', 'superadmin', 'admin']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is operator.
|
||||
*/
|
||||
public function isOperator(): bool
|
||||
{
|
||||
return $this->hasRole('operator');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user owns loan order.
|
||||
*/
|
||||
public function ownsLoanOrder(LoanOrder $loanOrder): bool
|
||||
{
|
||||
return $this->id === $loanOrder->user_id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Nova;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||
use Laravel\Nova\Resource as NovaResource;
|
||||
|
||||
@@ -14,6 +15,14 @@ abstract class Resource extends NovaResource
|
||||
*/
|
||||
public static $trafficCop = false;
|
||||
|
||||
/**
|
||||
* Determine if the current user can replicate the given resource.
|
||||
*/
|
||||
public function authorizedToReplicate(Request $request): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an "index" query for the given resource.
|
||||
*
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace App\Nova;
|
||||
|
||||
use App\Nova\Resources\Branch\Branch;
|
||||
use App\Nova\Resources\System\Roles\Role;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Laravel\Nova\Fields\BelongsToMany;
|
||||
use Laravel\Nova\Fields\ID;
|
||||
use Laravel\Nova\Fields\MorphToMany;
|
||||
use Laravel\Nova\Fields\Password;
|
||||
@@ -90,6 +92,8 @@ class User extends Resource
|
||||
->updateRules('nullable', Rules\Password::defaults()),
|
||||
|
||||
MorphToMany::make(__('Roles'), 'roles', Role::class),
|
||||
|
||||
BelongsToMany::make(__('Branches'), 'branches', Branch::class),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -12,13 +12,9 @@ class LoanOrderPolicy
|
||||
*/
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
if ($user->isAdmin()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
@@ -28,6 +24,14 @@ class LoanOrderPolicy
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->isOperator()) {
|
||||
return $user->branches()->where('id', $loanOrder->branch_id)->exists();
|
||||
}
|
||||
|
||||
if ($user->ownsLoanOrder($loanOrder)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -36,13 +40,9 @@ class LoanOrderPolicy
|
||||
*/
|
||||
public function create(User $user): bool
|
||||
{
|
||||
if ($user->isAdmin()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
@@ -52,6 +52,14 @@ class LoanOrderPolicy
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->isOperator()) {
|
||||
return $user->branches()->where('id', $loanOrder->branch_id)->exists();
|
||||
}
|
||||
|
||||
if ($user->ownsLoanOrder($loanOrder)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -64,6 +72,14 @@ class LoanOrderPolicy
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->isOperator()) {
|
||||
return $user->branches()->where('id', $loanOrder->branch_id)->exists();
|
||||
}
|
||||
|
||||
if ($user->ownsLoanOrder($loanOrder)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('branch_user', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('branch_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('branch_user');
|
||||
}
|
||||
};
|
||||
68
lang/vendor/nova/tk.json
vendored
68
lang/vendor/nova/tk.json
vendored
@@ -20,38 +20,38 @@
|
||||
"Aland Islands": "Åland adalary",
|
||||
"Albania": "Albaniýa",
|
||||
"Algeria": "Al Algerir",
|
||||
"All resources loaded.": "Resourceshli çeşmeler ýüklendi.",
|
||||
"All resources loaded.": "Ähli resurslar ýüklendi.",
|
||||
"American Samoa": "Amerikan Samoasy",
|
||||
"An error occurred while uploading the file.": "Faýl ýüklenende säwlik ýüze çykdy.",
|
||||
"An error occurred while uploading the file: :error": "Faýl ýüklenende säwlik ýüze çykdy: :error",
|
||||
"Andorra": "Andorra",
|
||||
"Angola": "Angola",
|
||||
"Anguilla": "Anguilla",
|
||||
"Another user has updated this resource since this page was loaded. Please refresh the page and try again.": "Başga bir ulanyjy bu sahypa ýükleneninden bäri bu çeşmäni täzeledi. Sahypany täzeläň we gaýtadan synanyşyň.",
|
||||
"Another user has updated this resource since this page was loaded. Please refresh the page and try again.": "Başga bir ulanyjy bu sahypa ýükleneninden bäri bu resursy täzeledi. Sahypany täzeläň we gaýtadan synanyşyň.",
|
||||
"Antarctica": "Antarktida",
|
||||
"Antigua And Barbuda": "Antigua we Barbuda",
|
||||
"April": "Aprel",
|
||||
"Are you sure you want to delete all the notifications?": "Allhli bildirişleri pozmak isleýändigiňize ynanýarsyňyzmy?",
|
||||
"Are you sure you want to delete the selected resources?": "Saýlanan çeşmeleri ýok etmek isleýändigiňize ynanýarsyňyzmy?",
|
||||
"Are you sure you want to delete the selected resources?": "Hakykatdanam saýlanan resurslary pozmak isleýärsiňizmi?",
|
||||
"Are you sure you want to delete this file?": "Bu faýly pozmak isleýändigiňize ynanýarsyňyzmy?",
|
||||
"Are you sure you want to delete this notification?": "Bu habarnamany öçürmek isleýändigiňize ynanýarsyňyzmy?",
|
||||
"Are you sure you want to delete this resource?": "Bu çeşmäni pozmak isleýändigiňize ynanýarsyňyzmy?",
|
||||
"Are you sure you want to detach the selected resources?": "Saýlanan çeşmeleri bölmek isleýändigiňize ynanýarsyňyzmy?",
|
||||
"Are you sure you want to detach this resource?": "Bu çeşmäni bölmek isleýändigiňize ynanýarsyňyzmy?",
|
||||
"Are you sure you want to force delete the selected resources?": "Saýlanan çeşmeleri pozmaga mejbur edýändigiňize ynanýarsyňyzmy?",
|
||||
"Are you sure you want to force delete this resource?": "Bu çeşmäni pozmaga mejbur edýändigiňize ynanýarsyňyzmy?",
|
||||
"Are you sure you want to delete this notification?": "Bu habarnamany pozmak isleýändigiňize ynanýarsyňyzmy?",
|
||||
"Are you sure you want to delete this resource?": "Bu resursy pozmak isleýändigiňize ynanýarsyňyzmy?",
|
||||
"Are you sure you want to detach the selected resources?": "Saýlanan resurslary bölmek isleýändigiňize ynanýarsyňyzmy?",
|
||||
"Are you sure you want to detach this resource?": "Bu resursy bölmek isleýändigiňize ynanýarsyňyzmy?",
|
||||
"Are you sure you want to force delete the selected resources?": "Saýlanan resurslary pozmaga mejbur edýändigiňize ynanýarsyňyzmy?",
|
||||
"Are you sure you want to force delete this resource?": "Bu resursy pozmaga mejbur edýändigiňize ynanýarsyňyzmy?",
|
||||
"Are you sure you want to log out?": "Çykmak isleýändigiňize ynanýarsyňyzmy?",
|
||||
"Are you sure you want to remove this item?": "Bu elementi aýyrmak isleýändigiňize ynanýarsyňyzmy?",
|
||||
"Are you sure you want to restore the selected resources?": "Saýlanan çeşmeleri dikeltmek isleýändigiňize ynanýarsyňyzmy?",
|
||||
"Are you sure you want to restore this resource?": "Bu çeşmäni dikeltmek isleýändigiňize ynanýarsyňyzmy?",
|
||||
"Are you sure you want to restore this resource?": "Bu resursy dikeltmek isleýändigiňize ynanýarsyňyzmy?",
|
||||
"Are you sure you want to run this action?": "Bu çäräni geçirmek isleýändigiňize ynanýarsyňyzmy?",
|
||||
"Are you sure you want to stop impersonating?": "Özüňi görkezmekden ýüz öwürmek isleýärsiňmi?",
|
||||
"Argentina": "Argentina",
|
||||
"Armenia": "Ermenistan",
|
||||
"Aruba": "Aruba",
|
||||
"Attach": "Berkidiň",
|
||||
"Attach & Attach Another": "Başga birini dakyň we dakyň",
|
||||
"Attach :resource": ":Resource-e dakyň",
|
||||
"Attach": "Birikdir",
|
||||
"Attach & Attach Another": "Birikidirip başga birini hem birikdiriň",
|
||||
"Attach :resource": ":Resource birikdiriň",
|
||||
"Attach files by dragging & dropping, selecting or pasting them.": "Faýllary süýräp we taşlap, saýlap ýa-da dadyp görüň.",
|
||||
"August": "Awgust",
|
||||
"Australia": "Awstraliýa",
|
||||
@@ -81,7 +81,7 @@
|
||||
"Cambodia": "Kamboja",
|
||||
"Cameroon": "Kamerun",
|
||||
"Canada": "Kanada",
|
||||
"Cancel": "Elatyr",
|
||||
"Cancel": "Ýatyr",
|
||||
"Cape Verde": "Cape Verde",
|
||||
"Cayman Islands": "Kaýman adalary",
|
||||
"Central African Republic": "Merkezi Afrika Respublikasy",
|
||||
@@ -125,13 +125,13 @@
|
||||
"Dashboard": "Dolandyryş paneli",
|
||||
"December": "Dekabr",
|
||||
"Decrease": "Pese gaçmak",
|
||||
"Delete": "Öçür",
|
||||
"Delete": "Poz",
|
||||
"Delete all notifications": "Noteshli bildirişleri pozuň",
|
||||
"Delete File": "Faýly poz",
|
||||
"Delete Resource": "Çeşmäni poz",
|
||||
"Delete Resource": "Resursy poz",
|
||||
"Delete Selected": "Saýlananlary poz",
|
||||
"Denmark": "Daniýa",
|
||||
"Detach": "Aýralyk",
|
||||
"Detach": "Aýyr",
|
||||
"Detach Resource": "Resurslary bölüň",
|
||||
"Detach Selected": "Saýlananlary bölüň",
|
||||
"Details": "Jikme-jiklikler",
|
||||
@@ -143,9 +143,9 @@
|
||||
"Drop file or click to choose": "Faýly taşlaň ýa-da saýlamak üçin basyň",
|
||||
"Drop files or click to choose": "Faýllary taşlaň ýa-da saýlamak üçin basyň",
|
||||
"Ecuador": "Ekwador",
|
||||
"Edit": "Redaktirläň",
|
||||
"Edit :resource": ":Resource redaktirläň",
|
||||
"Edit Attached": "Birikdirilen redaktirleme",
|
||||
"Edit": "Üýtget",
|
||||
"Edit :resource": ":Resource üýtget",
|
||||
"Edit Attached": "Üýtget",
|
||||
"Egypt": "Müsür",
|
||||
"El Salvador": "El Salwador",
|
||||
"Email Address": "Email adres",
|
||||
@@ -162,9 +162,9 @@
|
||||
"Fiji": "Fiji",
|
||||
"Filename": "Faýlyň ady",
|
||||
"Finland": "Finlýandiýa",
|
||||
"Force Delete": "Güýç öçürmek",
|
||||
"Force Delete Resource": "Resurslary öçürmek",
|
||||
"Force Delete Selected": "Saýlananlary öçürmek",
|
||||
"Force Delete": "Doly poz",
|
||||
"Force Delete Resource": "Resurslary doly poz",
|
||||
"Force Delete Selected": "Saýlananlary poz",
|
||||
"Forgot Password": "Paroly ýatdan çykardy",
|
||||
"Forgot your password?": "Parolyňyzy ýatdan çykardyňyzmy?",
|
||||
"France": "Fransiýa",
|
||||
@@ -325,16 +325,16 @@
|
||||
"Reload": "Gaýtadan ýükläň",
|
||||
"Remember me": "Meni ýatla",
|
||||
"Remove": "Aýyr",
|
||||
"Replicate": "Gaýtalama",
|
||||
"Replicate": "Şeýle resurs goş",
|
||||
"Reset Filters": "Süzgüçleri täzeden düzmek",
|
||||
"Reset Password": "Paroly täzeden düzmek",
|
||||
"Reset Password Notification": "Parol habarnamasyny täzeden düzmek",
|
||||
"resource": "çeşmesi",
|
||||
"Resource Row Dropdown": "Çeşmeleriň hatary",
|
||||
"resource": "resurs",
|
||||
"Resource Row Dropdown": "Resurslaryň hatary",
|
||||
"Resources": "Resurslar",
|
||||
"resources": "resurslar",
|
||||
"Restore": "Dikelt",
|
||||
"Restore Resource": "Çeşmäni dikeltmek",
|
||||
"Restore Resource": "Resursy dikeltmek",
|
||||
"Restore Selected": "Saýlananlary dikelt",
|
||||
"Reunion": "Reunion",
|
||||
"Romania": "Rumyniýa",
|
||||
@@ -369,8 +369,8 @@
|
||||
"Sint Maarten (Dutch part)": "Sint Maarten",
|
||||
"Slovakia": "Slowakiýa",
|
||||
"Slovenia": "Sloweniýa",
|
||||
"Soft Deleted": "Softumşak öçürildi",
|
||||
"Solomon Islands": "Süleýman adalary",
|
||||
"Soft Deleted": "Arhiwlendi",
|
||||
"Solomon Islands": "Solomon adalary",
|
||||
"Somalia": "Somali",
|
||||
"Something went wrong.": "Bir zat nädogry boldy.",
|
||||
"Sorry! You are not authorized to perform this action.": "Bagyşlaň! Bu hereketi ýerine ýetirmäge ygtyýaryňyz ýok.",
|
||||
@@ -397,11 +397,11 @@
|
||||
"Tanzania": "Tanzaniýa",
|
||||
"Thailand": "Taýland",
|
||||
"The :resource was created!": ":Resource döredildi!",
|
||||
"The :resource was deleted!": ":Resource öçürildi!",
|
||||
"The :resource was deleted!": ":Resource pozuldy!",
|
||||
"The :resource was restored!": ":Resource dikeldildi!",
|
||||
"The :resource was updated!": ":Resource täzelendi!",
|
||||
"The action was executed successfully.": "Hereket üstünlikli ýerine ýetirildi.",
|
||||
"The file was deleted!": "Faýl öçürildi!",
|
||||
"The file was deleted!": "Faýl pozuldy!",
|
||||
"The government won't let us show you what's behind these doors": "Rugsat ýok",
|
||||
"The HasOne relationship has already been filled.": "HasOne gatnaşyklary eýýäm dolduryldy.",
|
||||
"The image could not be loaded": "Suraty ýükläp bolmady",
|
||||
@@ -409,7 +409,7 @@
|
||||
"The resource was attached!": "Resurs goşuldy!",
|
||||
"The resource was prevented from being saved!": "Resursyň tygşytlanmagynyň öňüni aldy!",
|
||||
"The resource was updated!": "Resurs täzelendi!",
|
||||
"There are no available options for this resource.": "Bu çeşme üçin elýeterli wariant ýok.",
|
||||
"There are no available options for this resource.": "Bu resurs üçin elýeterli wariant ýok.",
|
||||
"There are no fields to display.": "Görkezjek meýdan ýok.",
|
||||
"There are no new notifications.": "Täze bildiriş ýok.",
|
||||
"There was a problem executing the action.": "Hereketi ýerine ýetirmekde kynçylyk ýüze çykdy.",
|
||||
@@ -417,7 +417,7 @@
|
||||
"There was a problem submitting the form.": "Anketany tabşyrmakda kynçylyk ýüze çykdy.",
|
||||
"This copy of Nova is unlicensed.": "Nowanyň bu nusgasy ygtyýarnamasyz.",
|
||||
"This file field is read-only.": "Bu faýl meýdany diňe okalýar.",
|
||||
"This resource no longer exists": "Bu çeşme indi ýok",
|
||||
"This resource no longer exists": "Bu resurs indi ýok",
|
||||
"Timor-Leste": "Timor-Leste",
|
||||
"To": "To",
|
||||
"Today": "Bu gün",
|
||||
@@ -440,7 +440,7 @@
|
||||
"United States": "Birleşen Ştatlar",
|
||||
"United States Outlying Islands": "ABŞ-nyň daşarky adalary",
|
||||
"Update": "Täzelen",
|
||||
"Update & Continue Editing": "Redaktirlemegi täzeläň we dowam etdiriň",
|
||||
"Update & Continue Editing": "Tassykla we üýtgetmäge dowam et",
|
||||
"Update :resource": ":Resource täzeläň",
|
||||
"Update :resource: :title": ":Resource: :title täzeläň",
|
||||
"Update attached :resource: :title": "Täzelenme :resource: :title",
|
||||
|
||||
Reference in New Issue
Block a user