WIp
This commit is contained in:
@@ -16,7 +16,6 @@ use Spatie\Permission\Traits\HasRoles;
|
|||||||
|
|
||||||
class User extends Authenticatable
|
class User extends Authenticatable
|
||||||
{
|
{
|
||||||
use Actionable;
|
|
||||||
use HasApiTokens;
|
use HasApiTokens;
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
use HasRoles;
|
use HasRoles;
|
||||||
@@ -75,6 +74,14 @@ class User extends Authenticatable
|
|||||||
return $this->hasMany(LoanOrder::class);
|
return $this->hasMany(LoanOrder::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if user has role.
|
||||||
|
*/
|
||||||
|
public function withoutRole(): bool
|
||||||
|
{
|
||||||
|
return $this->roles->count() === 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if user is me.
|
* Check if user is me.
|
||||||
*/
|
*/
|
||||||
@@ -138,4 +145,12 @@ class User extends Authenticatable
|
|||||||
{
|
{
|
||||||
return ! is_null($this->phone_verified_at);
|
return ! is_null($this->phone_verified_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Profile page of user
|
||||||
|
*/
|
||||||
|
public function profilePage(): string
|
||||||
|
{
|
||||||
|
return '/resources/users/'. $this->id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,13 +32,6 @@ class Permission extends Resource
|
|||||||
'id', 'name',
|
'id', 'name',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates if the resource should be displayed in the sidebar.
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
public static $displayInNavigation = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the fields displayed by the resource.
|
* Get the fields displayed by the resource.
|
||||||
*/
|
*/
|
||||||
|
|||||||
119
app/Policies/Order/Card/CardOrderPolicy.php
Normal file
119
app/Policies/Order/Card/CardOrderPolicy.php
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Policies\Order\Card;
|
||||||
|
|
||||||
|
use App\Models\CardOrder;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
class CardOrderPolicy
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine whether the user can view any models.
|
||||||
|
*/
|
||||||
|
public function viewAny(User $user): bool
|
||||||
|
{
|
||||||
|
if ($user->isOperator() && $user->cannot('viewCardOrders')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can view the model.
|
||||||
|
*/
|
||||||
|
public function view(User $user, CardOrder $cardOrder): bool
|
||||||
|
{
|
||||||
|
if ($user->isAdmin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($user->isOperator() && $user->can('viewCardOrders')) {
|
||||||
|
return $user->branches()->where('branches.id', $loanOrder->branch_id)->exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($user->ownsLoanOrder($loanOrder)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can create models.
|
||||||
|
*/
|
||||||
|
public function create(User $user): bool
|
||||||
|
{
|
||||||
|
if ($user->isOperator() && $user->cannot('viewCardOrders')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can update the model.
|
||||||
|
*/
|
||||||
|
public function update(User $user, CardOrder $cardOrder): bool
|
||||||
|
{
|
||||||
|
if ($user->isAdmin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($user->isOperator() && $user->can('viewCardOrders')) {
|
||||||
|
return $user->branches()->where('branches.id', $loanOrder->branch_id)->exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($user->ownsLoanOrder($loanOrder) && in_array($loanOrder->status, [
|
||||||
|
OrderRepo::PENDING,
|
||||||
|
])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can delete the model.
|
||||||
|
*/
|
||||||
|
public function delete(User $user, CardOrder $cardOrder): bool
|
||||||
|
{
|
||||||
|
if ($user->isAdmin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($user->isOperator() && $user->can('viewLoanOrders')) {
|
||||||
|
return $user->branches()->where('branches.id', $loanOrder->branch_id)->exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($user->ownsLoanOrder($loanOrder)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can restore the model.
|
||||||
|
*/
|
||||||
|
public function restore(User $user, CardOrder $cardOrder): bool
|
||||||
|
{
|
||||||
|
if ($user->isMe()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can permanently delete the model.
|
||||||
|
*/
|
||||||
|
public function forceDelete(User $user, CardOrder $cardOrder): bool
|
||||||
|
{
|
||||||
|
if ($user->isMe()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
93
app/Policies/Order/Card/CardStatePolicy.php
Normal file
93
app/Policies/Order/Card/CardStatePolicy.php
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Policies\Order\Card;
|
||||||
|
|
||||||
|
use App\Models\CardState;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
class CardStatePolicy
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine whether the user can view any models.
|
||||||
|
*/
|
||||||
|
public function viewAny(User $user): bool
|
||||||
|
{
|
||||||
|
if ($user->isAdmin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can view the model.
|
||||||
|
*/
|
||||||
|
public function view(User $user, CardState $cardState): bool
|
||||||
|
{
|
||||||
|
if ($user->isAdmin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can create models.
|
||||||
|
*/
|
||||||
|
public function create(User $user): bool
|
||||||
|
{
|
||||||
|
if ($user->isAdmin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can update the model.
|
||||||
|
*/
|
||||||
|
public function update(User $user, CardState $cardState): bool
|
||||||
|
{
|
||||||
|
if ($user->isAdmin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can delete the model.
|
||||||
|
*/
|
||||||
|
public function delete(User $user, CardState $cardState): bool
|
||||||
|
{
|
||||||
|
if ($user->isAdmin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can restore the model.
|
||||||
|
*/
|
||||||
|
public function restore(User $user, CardState $cardState): bool
|
||||||
|
{
|
||||||
|
if ($user->isAdmin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can permanently delete the model.
|
||||||
|
*/
|
||||||
|
public function forceDelete(User $user, CardState $cardState): bool
|
||||||
|
{
|
||||||
|
if ($user->isAdmin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
93
app/Policies/Order/Card/CardTypePolicy.php
Normal file
93
app/Policies/Order/Card/CardTypePolicy.php
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Policies\Order\Card;
|
||||||
|
|
||||||
|
use App\Models\Order\Card\CardType;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
class CardTypePolicy
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine whether the user can view any models.
|
||||||
|
*/
|
||||||
|
public function viewAny(User $user): bool
|
||||||
|
{
|
||||||
|
if ($user->isAdmin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can view the model.
|
||||||
|
*/
|
||||||
|
public function view(User $user, CardType $cardType): bool
|
||||||
|
{
|
||||||
|
if ($user->isAdmin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can create models.
|
||||||
|
*/
|
||||||
|
public function create(User $user): bool
|
||||||
|
{
|
||||||
|
if ($user->isAdmin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can update the model.
|
||||||
|
*/
|
||||||
|
public function update(User $user, CardType $cardType): bool
|
||||||
|
{
|
||||||
|
if ($user->isAdmin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can delete the model.
|
||||||
|
*/
|
||||||
|
public function delete(User $user, CardType $cardType): bool
|
||||||
|
{
|
||||||
|
if ($user->isAdmin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can restore the model.
|
||||||
|
*/
|
||||||
|
public function restore(User $user, CardType $cardType): bool
|
||||||
|
{
|
||||||
|
if ($user->isAdmin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can permanently delete the model.
|
||||||
|
*/
|
||||||
|
public function forceDelete(User $user, CardType $cardType): bool
|
||||||
|
{
|
||||||
|
if ($user->isAdmin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -99,7 +99,7 @@ class LoanOrderPolicy
|
|||||||
*/
|
*/
|
||||||
public function restore(User $user, LoanOrder $loanOrder): bool
|
public function restore(User $user, LoanOrder $loanOrder): bool
|
||||||
{
|
{
|
||||||
if ($user->isAdmin()) {
|
if ($user->isMe()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +111,7 @@ class LoanOrderPolicy
|
|||||||
*/
|
*/
|
||||||
public function forceDelete(User $user, LoanOrder $loanOrder): bool
|
public function forceDelete(User $user, LoanOrder $loanOrder): bool
|
||||||
{
|
{
|
||||||
if ($user->isAdmin()) {
|
if ($user->isMe()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,8 +61,5 @@ class AuthServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
// Tooling permissions...
|
// Tooling permissions...
|
||||||
Gate::define('viewPulse', fn ($user) => $user->isMe());
|
Gate::define('viewPulse', fn ($user) => $user->isMe());
|
||||||
|
|
||||||
// LoanOrder permissions...
|
|
||||||
Gate::define('viewLoanOrders', fn ($user) => $user->isSystemUser());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,14 @@ use Stepanenko3\LogsTool\LogsTool;
|
|||||||
|
|
||||||
class NovaServiceProvider extends NovaApplicationServiceProvider
|
class NovaServiceProvider extends NovaApplicationServiceProvider
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Register any application services.
|
||||||
|
*/
|
||||||
|
public function register(): void
|
||||||
|
{
|
||||||
|
Nova::initialPath(NovaRepo::initialPath());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bootstrap any application services.
|
* Bootstrap any application services.
|
||||||
*/
|
*/
|
||||||
@@ -39,7 +47,7 @@ class NovaServiceProvider extends NovaApplicationServiceProvider
|
|||||||
parent::boot();
|
parent::boot();
|
||||||
|
|
||||||
Nova::withBreadcrumbs();
|
Nova::withBreadcrumbs();
|
||||||
Nova::footer(fn () => view('vendor.nova.partials.footer')->render());
|
Nova::footer(NovaRepo::footer());
|
||||||
|
|
||||||
$this->setupNavigation();
|
$this->setupNavigation();
|
||||||
$this->setupUserNavigation();
|
$this->setupUserNavigation();
|
||||||
@@ -66,9 +74,7 @@ class NovaServiceProvider extends NovaApplicationServiceProvider
|
|||||||
*/
|
*/
|
||||||
protected function gate(): void
|
protected function gate(): void
|
||||||
{
|
{
|
||||||
Gate::define('viewNova', function ($user) {
|
Gate::define('viewNova', NovaRepo::viewNova());
|
||||||
return $user->isSystemUser() || $user->phoneIsVerified();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,23 +98,15 @@ class NovaServiceProvider extends NovaApplicationServiceProvider
|
|||||||
->onSwitchLocale(NovaRepo::localeSwitcherSave()),
|
->onSwitchLocale(NovaRepo::localeSwitcherSave()),
|
||||||
|
|
||||||
BackupTool::make()
|
BackupTool::make()
|
||||||
->canSee(fn () => auth()->user()->isMe()),
|
->canSee(NovaRepo::isMe()),
|
||||||
|
|
||||||
LogsTool::make()
|
LogsTool::make()
|
||||||
->canSee(fn () => Gate::allows('isMe', auth()->user()))
|
->canSee(NovaRepo::isMe())
|
||||||
->canDownload(fn () => Gate::allows('isMe', auth()->user()))
|
->canDownload(NovaRepo::isMe())
|
||||||
->canDelete(fn () => Gate::allows('isMe', auth()->user())),
|
->canDelete(NovaRepo::isMe()),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Register any application services.
|
|
||||||
*/
|
|
||||||
public function register(): void
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup navigation
|
* Setup navigation
|
||||||
*/
|
*/
|
||||||
@@ -165,7 +163,7 @@ class NovaServiceProvider extends NovaApplicationServiceProvider
|
|||||||
public function setupUserNavigation(): void
|
public function setupUserNavigation(): void
|
||||||
{
|
{
|
||||||
Nova::userMenu(function (Request $request, Menu $menu) {
|
Nova::userMenu(function (Request $request, Menu $menu) {
|
||||||
$menu->prepend(MenuItem::make(__('My Profile'), sprintf('/resources/users/%s', $request->user()->id)));
|
$menu->prepend(MenuItem::make(__('My Profile'), $request->user()->profilePage()));
|
||||||
|
|
||||||
return $menu;
|
return $menu;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Repos\Order\Loan;
|
namespace App\Repos\Order\Loan;
|
||||||
|
|
||||||
use App\Models\Branch\Branch;
|
use App\Models\Branch\Branch;
|
||||||
|
use App\Repos\Order\OrderRepo;
|
||||||
use Closure;
|
use Closure;
|
||||||
|
|
||||||
class LoanOrderRepo
|
class LoanOrderRepo
|
||||||
|
|||||||
@@ -5,10 +5,17 @@ namespace App\Repos\System\Nova;
|
|||||||
use App\Models\System\Location\Province;
|
use App\Models\System\Location\Province;
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Gate;
|
||||||
use Laravel\Nova\Events\ServingNova;
|
use Laravel\Nova\Events\ServingNova;
|
||||||
|
|
||||||
class NovaRepo
|
class NovaRepo
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Initial path
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected static string $initialPath = '/dashboards/main';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serving nova application
|
* Serving nova application
|
||||||
*/
|
*/
|
||||||
@@ -17,6 +24,24 @@ class NovaRepo
|
|||||||
static::setLocale($event);
|
static::setLocale($event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initial path for nova
|
||||||
|
*/
|
||||||
|
public static function initialPath(): string
|
||||||
|
{
|
||||||
|
return request()->user() && request()->user()->withoutRole()
|
||||||
|
? request()->user()->profilePage()
|
||||||
|
: static::$initialPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This gate determines who can access Nova in non-local environments.
|
||||||
|
*/
|
||||||
|
public static function viewNova(): Closure
|
||||||
|
{
|
||||||
|
return fn ($user) => $user->isSystemUser() || $user->phoneIsVerified();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set locales
|
* Set locales
|
||||||
*/
|
*/
|
||||||
@@ -43,6 +68,22 @@ class NovaRepo
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nova Footer
|
||||||
|
*/
|
||||||
|
public static function footer(): Closure
|
||||||
|
{
|
||||||
|
return fn () => view('vendor.nova.partials.footer')->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if user is me
|
||||||
|
*/
|
||||||
|
public static function isMe(): Closure
|
||||||
|
{
|
||||||
|
return fn () => Gate::allows('isMe', auth()->user());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Depends on region
|
* Depends on region
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class DatabaseSeeder extends Seeder
|
|||||||
ProvinceTableSeeder::class,
|
ProvinceTableSeeder::class,
|
||||||
BranchTableSeeder::class,
|
BranchTableSeeder::class,
|
||||||
LoanTypeSeeder::class,
|
LoanTypeSeeder::class,
|
||||||
|
PermissionTableSeeder::class,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
23
database/seeders/PermissionTableSeeder.php
Normal file
23
database/seeders/PermissionTableSeeder.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Models\System\Roles\Permission;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
class PermissionTableSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
collect([
|
||||||
|
'ViewCardOrders',
|
||||||
|
'ViewLoanOrders',
|
||||||
|
])->each(fn ($name) => Permission::create([
|
||||||
|
'name' => $name,
|
||||||
|
'guard_name' => 'web',
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user