wip
This commit is contained in:
@@ -9,7 +9,6 @@ use App\Modules\Card\Filament\Actions\CheckCardBalanceAction;
|
|||||||
use App\Modules\Card\Filament\Actions\DownloadCardRequisteAction;
|
use App\Modules\Card\Filament\Actions\DownloadCardRequisteAction;
|
||||||
use App\Modules\Card\Filament\Actions\DownloadCardTransactionAction;
|
use App\Modules\Card\Filament\Actions\DownloadCardTransactionAction;
|
||||||
use App\Modules\Card\Models\Card;
|
use App\Modules\Card\Models\Card;
|
||||||
use App\Modules\DefaultQueryForResourceIndex\Repositories\DefaultQueryForResourceIndexRepository;
|
|
||||||
use BackedEnum;
|
use BackedEnum;
|
||||||
use Filament\Actions\BulkActionGroup;
|
use Filament\Actions\BulkActionGroup;
|
||||||
use Filament\Actions\DeleteAction;
|
use Filament\Actions\DeleteAction;
|
||||||
@@ -91,7 +90,11 @@ class CardResource extends Resource
|
|||||||
{
|
{
|
||||||
return $table
|
return $table
|
||||||
->modifyQueryUsing(function (Builder $query) {
|
->modifyQueryUsing(function (Builder $query) {
|
||||||
DefaultQueryForResourceIndexRepository::make($query);
|
if (user()->isAdmin()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query->where('user_id', user()->id);
|
||||||
})
|
})
|
||||||
->columns([
|
->columns([
|
||||||
TextColumn::make('number')
|
TextColumn::make('number')
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace App\Filament\Resources\Users\Schemas;
|
|||||||
use Filament\Forms\Components\Select;
|
use Filament\Forms\Components\Select;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
use Filament\Schemas\Schema;
|
use Filament\Schemas\Schema;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|
||||||
class UserForm
|
class UserForm
|
||||||
@@ -29,7 +30,6 @@ class UserForm
|
|||||||
|
|
||||||
TextInput::make('phone')
|
TextInput::make('phone')
|
||||||
->label(__('Phone number'))
|
->label(__('Phone number'))
|
||||||
->required()
|
|
||||||
->unique(ignoreRecord: true),
|
->unique(ignoreRecord: true),
|
||||||
|
|
||||||
TextInput::make('email')
|
TextInput::make('email')
|
||||||
@@ -51,6 +51,14 @@ class UserForm
|
|||||||
->preload()
|
->preload()
|
||||||
->native(false)
|
->native(false)
|
||||||
->required(),
|
->required(),
|
||||||
|
|
||||||
|
Select::make('branches')
|
||||||
|
->label(__('Branches'))
|
||||||
|
->relationship('branches', 'name', fn (Builder $query) => $query->distinct('id')->orderBy('id'))
|
||||||
|
->multiple()
|
||||||
|
->preload()
|
||||||
|
->native(false)
|
||||||
|
->required(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,10 @@ class UsersTable
|
|||||||
public static function configure(Table $table): Table
|
public static function configure(Table $table): Table
|
||||||
{
|
{
|
||||||
return $table
|
return $table
|
||||||
|
->defaultSort('created_at', direction: 'desc')
|
||||||
->columns([
|
->columns([
|
||||||
|
TextColumn::make('id'),
|
||||||
|
|
||||||
TextColumn::make('first_name')
|
TextColumn::make('first_name')
|
||||||
->label(__('First name'))
|
->label(__('First name'))
|
||||||
->searchable()
|
->searchable()
|
||||||
|
|||||||
@@ -16,12 +16,31 @@ use Filament\Tables\Table;
|
|||||||
|
|
||||||
class UserResource extends Resource
|
class UserResource extends Resource
|
||||||
{
|
{
|
||||||
|
protected static ?int $navigationSort = 2;
|
||||||
|
|
||||||
protected static ?string $model = User::class;
|
protected static ?string $model = User::class;
|
||||||
|
|
||||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedUsers;
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedUsers;
|
||||||
|
|
||||||
|
protected static string|BackedEnum|null $activeNavigationIcon = Heroicon::Users;
|
||||||
|
|
||||||
protected static ?string $recordTitleAttribute = 'first_name';
|
protected static ?string $recordTitleAttribute = 'first_name';
|
||||||
|
|
||||||
|
public static function getNavigationLabel(): string
|
||||||
|
{
|
||||||
|
return __('Users');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getModelLabel(): string
|
||||||
|
{
|
||||||
|
return __('User');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPluralModelLabel(): string
|
||||||
|
{
|
||||||
|
return __('Users');
|
||||||
|
}
|
||||||
|
|
||||||
public static function form(Schema $schema): Schema
|
public static function form(Schema $schema): Schema
|
||||||
{
|
{
|
||||||
return UserForm::configure($schema);
|
return UserForm::configure($schema);
|
||||||
|
|||||||
@@ -20,6 +20,11 @@ class EnsureProfileIsFilled
|
|||||||
/** @var \App\Models\User */
|
/** @var \App\Models\User */
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
|
|
||||||
|
// Skip if user is system user...
|
||||||
|
if ($user->isSystemUser()) {
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
|
||||||
// 1. If user is not logged in, or profile is already complete, do nothing.
|
// 1. If user is not logged in, or profile is already complete, do nothing.
|
||||||
// (Based on your logic: must_fill_profile == true means complete)
|
// (Based on your logic: must_fill_profile == true means complete)
|
||||||
if (! $user->must_fill_profile) {
|
if (! $user->must_fill_profile) {
|
||||||
|
|||||||
@@ -16,8 +16,18 @@ class RedirectIfUserPhoneIsUnVerfied
|
|||||||
*/
|
*/
|
||||||
public function handle(Request $request, Closure $next): Response
|
public function handle(Request $request, Closure $next): Response
|
||||||
{
|
{
|
||||||
if (Auth::check() && is_null($request->user()?->phone_verified_at)) {
|
if (Auth::check()) {
|
||||||
return redirect()->route('sms-verification');
|
/** @var \App\Models\User */
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
// Skip if user is system user...
|
||||||
|
if ($user->isSystemUser()) {
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_null($user->phone_verified_at)) {
|
||||||
|
return redirect()->route('sms-verification');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
|
|||||||
24
app/Modules/Branch/Models/UserBranch.php
Normal file
24
app/Modules/Branch/Models/UserBranch.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\Branch\Models;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||||
|
|
||||||
|
class UserBranch extends Pivot
|
||||||
|
{
|
||||||
|
public $incrementing = true;
|
||||||
|
|
||||||
|
protected $table = 'branch_user';
|
||||||
|
|
||||||
|
public function branch(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Branch::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function user(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,9 @@
|
|||||||
namespace App\Modules\UserAdjustments\Traits;
|
namespace App\Modules\UserAdjustments\Traits;
|
||||||
|
|
||||||
use App\Modules\Branch\Models\Branch;
|
use App\Modules\Branch\Models\Branch;
|
||||||
|
use App\Modules\Branch\Models\UserBranch;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Spatie\Permission\Traits\HasRoles;
|
use Spatie\Permission\Traits\HasRoles;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,4 +73,12 @@ trait UserAdjustments
|
|||||||
{
|
{
|
||||||
return $this->belongsToMany(Branch::class);
|
return $this->belongsToMany(Branch::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User branches
|
||||||
|
*/
|
||||||
|
public function userBranches(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(UserBranch::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,5 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
return $builder;
|
return $builder;
|
||||||
});
|
});
|
||||||
|
|
||||||
logDB();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
36
app/Providers/AuthServiceProvider.php
Normal file
36
app/Providers/AuthServiceProvider.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Gate;
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
|
class AuthServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Register services.
|
||||||
|
*/
|
||||||
|
public function register(): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bootstrap services.
|
||||||
|
*/
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
// General permissions...
|
||||||
|
Gate::define('isMe', fn (User $user) => $user->isMe());
|
||||||
|
Gate::define('isSuperAdmin', fn (User $user) => $user->isSuperAdmin());
|
||||||
|
Gate::define('isAdmin', fn (User $user) => $user->isAdmin());
|
||||||
|
Gate::define('isCurrencyMaintainer', fn (User $user) => $user->isCurrencyMaintainer());
|
||||||
|
Gate::define('systemUser', fn (User $user) => $user->isSystemUser());
|
||||||
|
Gate::define('notSystemUser', fn (User $user) => ! $user->isSystemUser());
|
||||||
|
|
||||||
|
// Tooling permissions...
|
||||||
|
// Gate::define('viewPulse', fn ($user) => $user->isAdmin());
|
||||||
|
// Gate::define('viewApiDocs', fn ($user) => $user->canAccessApiDocs());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -85,7 +85,6 @@ class WorkPanelProvider extends PanelProvider
|
|||||||
])
|
])
|
||||||
->spa()
|
->spa()
|
||||||
->databaseTransactions()
|
->databaseTransactions()
|
||||||
->breadcrumbs(false)
|
|
||||||
->colors([
|
->colors([
|
||||||
'danger' => Color::Rose,
|
'danger' => Color::Rose,
|
||||||
'gray' => Color::Gray,
|
'gray' => Color::Gray,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
App\Providers\AppServiceProvider::class,
|
App\Providers\AppServiceProvider::class,
|
||||||
|
App\Providers\AuthServiceProvider::class,
|
||||||
App\Modules\ModuleServiceProvider::class,
|
App\Modules\ModuleServiceProvider::class,
|
||||||
App\Providers\Filament\WorkPanelProvider::class,
|
App\Providers\Filament\WorkPanelProvider::class,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -3,11 +3,6 @@
|
|||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Support\Facades\File;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use LazyJson\JsonElement;
|
|
||||||
use SplFileObject;
|
|
||||||
|
|
||||||
class FillJsonData extends Seeder
|
class FillJsonData extends Seeder
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
<form wire:submit="save" class="fi-sc-form">
|
<div>
|
||||||
{{ $this->form }}
|
@if(! user()->isSystemUser())
|
||||||
|
<form wire:submit="save" class="fi-sc-form">
|
||||||
|
{{ $this->form }}
|
||||||
|
|
||||||
<div class="fi-ac fi-align-end">
|
<div class="fi-ac fi-align-end">
|
||||||
<x-filament::button type="submit">
|
<x-filament::button type="submit">
|
||||||
{{ __('filament-edit-profile::default.save') }}
|
{{ __('filament-edit-profile::default.save') }}
|
||||||
</x-filament::button>
|
</x-filament::button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
@else
|
||||||
|
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user