Add actions
This commit is contained in:
@@ -9,11 +9,13 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Laravel\Nova\Actions\Actionable;
|
||||
|
||||
class LoanOrder extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use SoftDeletes;
|
||||
use Actionable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
|
||||
@@ -10,13 +10,17 @@ 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\Nova\Actions\Actionable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
use Actionable;
|
||||
use HasApiTokens;
|
||||
use HasFactory;
|
||||
use HasRoles;
|
||||
use Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
|
||||
@@ -16,6 +16,7 @@ use Laravel\Nova\Fields\Date;
|
||||
use Laravel\Nova\Fields\Email;
|
||||
use Laravel\Nova\Fields\ID;
|
||||
use Laravel\Nova\Fields\Image;
|
||||
use Laravel\Nova\Fields\MorphMany;
|
||||
use Laravel\Nova\Fields\Select;
|
||||
use Laravel\Nova\Fields\Text;
|
||||
use Laravel\Nova\Panel;
|
||||
@@ -158,6 +159,9 @@ class LoanOrderFieldsForDetail
|
||||
Image::make(__('Passport (page 32)'), 'passport_four')
|
||||
->size('w-1/2'),
|
||||
]),
|
||||
|
||||
MorphMany::make(__('Actions'), 'actions', config('nova.actions.resource'))
|
||||
->canSeeWhen('isAdmin', $this)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,11 +24,13 @@ use App\Rules\OnlyLetters;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Laravel\Nova\Actions\Action;
|
||||
use Laravel\Nova\Fields\BelongsTo;
|
||||
use Laravel\Nova\Fields\Date;
|
||||
use Laravel\Nova\Fields\Email;
|
||||
use Laravel\Nova\Fields\ID;
|
||||
use Laravel\Nova\Fields\Image;
|
||||
use Laravel\Nova\Fields\MorphMany;
|
||||
use Laravel\Nova\Fields\Number;
|
||||
use Laravel\Nova\Fields\Select;
|
||||
use Laravel\Nova\Fields\Text;
|
||||
@@ -180,9 +182,11 @@ class LoanOrder extends Resource
|
||||
->canSeeWhen('systemUser', $this),
|
||||
|
||||
BelongsTo::make(__('Created by').': ', 'user', User::class)
|
||||
->fullWidth()
|
||||
->canSeeWhen('isMe', $this),
|
||||
|
||||
|
||||
BelongsTo::make(__('Updated by').': ', 'filledBy', User::class)
|
||||
->fullWidth()
|
||||
->canSeeWhen('isMe', $this),
|
||||
|
||||
new Panel(__('Loan'), [
|
||||
|
||||
@@ -13,6 +13,10 @@ class LoanOrderPolicy
|
||||
*/
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
if ($user->isOperator() && $user->cannot('viewLoanOrders')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -25,7 +29,7 @@ class LoanOrderPolicy
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->isOperator()) {
|
||||
if ($user->isOperator() && $user->can('viewLoanOrders')) {
|
||||
return $user->branches()->where('branches.id', $loanOrder->branch_id)->exists();
|
||||
}
|
||||
|
||||
@@ -41,6 +45,10 @@ class LoanOrderPolicy
|
||||
*/
|
||||
public function create(User $user): bool
|
||||
{
|
||||
if ($user->isOperator() && $user->cannot('viewLoanOrders')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -53,7 +61,7 @@ class LoanOrderPolicy
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->isOperator()) {
|
||||
if ($user->isOperator() && $user->can('viewLoanOrders')) {
|
||||
return $user->branches()->where('branches.id', $loanOrder->branch_id)->exists();
|
||||
}
|
||||
|
||||
@@ -75,7 +83,7 @@ class LoanOrderPolicy
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->isOperator()) {
|
||||
if ($user->isOperator() && $user->can('viewLoanOrders')) {
|
||||
return $user->branches()->where('branches.id', $loanOrder->branch_id)->exists();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,10 +43,15 @@ class AuthServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
// General permissions...
|
||||
Gate::define('isMe', fn ($user) => $user->isMe());
|
||||
Gate::define('isAdmin', fn ($user) => $user->isAdmin());
|
||||
Gate::define('systemUser', fn ($user) => $user->isSystemUser());
|
||||
|
||||
// Tooling permissions...
|
||||
Gate::define('viewPulse', fn ($user) => $user->isMe());
|
||||
|
||||
// LoanOrder permissions...
|
||||
Gate::define('viewLoanOrders', fn ($user) => $user->isSystemUser());
|
||||
}
|
||||
}
|
||||
|
||||
12
lang/vendor/nova/tk.json
vendored
12
lang/vendor/nova/tk.json
vendored
@@ -8,8 +8,8 @@
|
||||
":resource Details": "Giňişleýin :Resource",
|
||||
":resource Details: :title": ":Resource giňişleýin: :title",
|
||||
"Action": "Hereket",
|
||||
"Action Happened At": "Boldy",
|
||||
"Action Initiated By": "Başlady",
|
||||
"Action Happened At": "Sene",
|
||||
"Action Initiated By": "Kim tarapyndan",
|
||||
"Action Name": "Amalyň ady",
|
||||
"Action Status": "Amalyň statusy",
|
||||
"Action Target": "Amalyň nyşany (targedi)",
|
||||
@@ -111,7 +111,7 @@
|
||||
"Copy to clipboard": "Paneli göçüriň",
|
||||
"Costa Rica": "Kosta Rika",
|
||||
"Cote D'Ivoire": "Kot d'Iwuar",
|
||||
"Create": "Dörediň",
|
||||
"Create": "Goşmak",
|
||||
"Create & Add Another": "Başga birini dörediň we goşuň",
|
||||
"Create :resource": ":Resource dörediň",
|
||||
"Croatia": "Horwatiýa",
|
||||
@@ -125,7 +125,7 @@
|
||||
"Dashboard": "Dolandyryş paneli",
|
||||
"December": "Dekabr",
|
||||
"Decrease": "Pese gaçmak",
|
||||
"Delete": "Poz",
|
||||
"Delete": "Pozmak",
|
||||
"Delete all notifications": "Noteshli bildirişleri pozuň",
|
||||
"Delete File": "Faýly poz",
|
||||
"Delete Resource": "Resursy poz",
|
||||
@@ -333,7 +333,7 @@
|
||||
"Resource Row Dropdown": "Resurslaryň hatary",
|
||||
"Resources": "Resurslar",
|
||||
"resources": "resurslar",
|
||||
"Restore": "Dikelt",
|
||||
"Restore": "Arhiwden çykar",
|
||||
"Restore Resource": "Resursy dikeltmek",
|
||||
"Restore Selected": "Saýlananlary dikelt",
|
||||
"Reunion": "Reunion",
|
||||
@@ -439,7 +439,7 @@
|
||||
"United Kingdom": "Angliýa",
|
||||
"United States": "Birleşen Ştatlar",
|
||||
"United States Outlying Islands": "ABŞ-nyň daşarky adalary",
|
||||
"Update": "Täzelen",
|
||||
"Update": "Üýtgetmek",
|
||||
"Update & Continue Editing": "Tassykla we üýtgetmäge dowam et",
|
||||
"Update :resource": ":Resource täzeläň",
|
||||
"Update :resource: :title": ":Resource: :title täzeläň",
|
||||
|
||||
Reference in New Issue
Block a user