Skip to content

Commit

Permalink
Merge pull request #12 from KingSit3/master
Browse files Browse the repository at this point in the history
Feature for Superman 🤜
  • Loading branch information
AaEzha authored Oct 27, 2024
2 parents ef05ffa + cd8b583 commit f146a4a
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 41 deletions.
36 changes: 26 additions & 10 deletions app/Filament/Superman/Resources/JamaahResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Filters;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
Expand All @@ -19,31 +20,46 @@ class JamaahResource extends Resource

protected static ?string $navigationIcon = 'heroicon-o-users';
protected static ?string $navigationLabel = 'Jamaah';
protected static ?string $pluralLabel = 'Jamaah';

public static function form(Form $form): Form
{
return $form
->schema([
//
]);
Forms\Components\TextInput::make('name')->required(),
Forms\Components\TextInput::make('website')
->suffix('.jamaah.com')
->prefixIcon('heroicon-m-globe-alt')
->required()
->alphaDash()
->unique(table: Jamaah::class, column: "website", ignoreRecord: true),
Forms\Components\Select::make("type")->options([
'masjid' => 'Masjid',
'majelis' => 'Majelis',
])
->selectablePlaceholder(false)
->required()

])->columns(1);
}

public static function table(Table $table): Table
{
return $table
->columns([
//
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('website'),
Tables\Columns\TextColumn::make('type'),
])
->filters([
//
Filters\SelectFilter::make('type')
->options([
'masjid' => 'Masjid',
'majelis' => 'Majelis',
])
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
Tables\Actions\DeleteAction::make(),
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
class CreateJamaah extends CreateRecord
{
protected static string $resource = JamaahResource::class;
protected static bool $canCreateAnother = false;
}
20 changes: 10 additions & 10 deletions app/Filament/Superman/Resources/UsersResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use App\Filament\Superman\Resources\UsersResource\RelationManagers;
use App\Models\User;
use Filament\Forms;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
Expand All @@ -24,26 +23,27 @@ public static function form(Form $form): Form
{
return $form
->schema([
Select::make('roles')->multiple()->relationship('roles', 'name')
]);
Forms\Components\TextInput::make('name')->required(),
Forms\Components\Select::make('roles')
->relationship('roles', 'name')
->selectablePlaceholder(false)
->required()
])->columns(1);
}

public static function table(Table $table): Table
{
return $table
->columns([
//
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('email'),
Tables\Columns\TextColumn::make('created_at')->label("Register date"),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
Tables\Actions\DeleteAction::make(),
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
class CreateUsers extends CreateRecord
{
protected static string $resource = UsersResource::class;
protected static bool $canCreateAnother = false;
}
21 changes: 21 additions & 0 deletions app/Http/Middleware/SupermanMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;

class SupermanMiddleware
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
return (Auth::user()->is_superman) ? $next($request) : redirect(to: route("filament.jamaah.auth.login"));
}
}
21 changes: 21 additions & 0 deletions app/Http/Middleware/UserMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;

class UserMiddleware
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
return (Auth::user()?->is_superman) ? redirect(to: route("filament.superman.pages.dashboard")) : $next($request);
}
}
11 changes: 1 addition & 10 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,10 @@ protected function casts(): array
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'is_superman' => 'boolean',
];
}

public function canAccessPanel(Panel $panel): bool
{
// Only Superman can go to Krypton 🫳🫳
if ($panel->getId() === 'superman') {
return $this->hasRole("superman");
}

return true;
}

public function jamaah(): BelongsToMany
{
return $this->belongsToMany(Jamaah::class);
Expand Down
2 changes: 1 addition & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function boot(): void
Model::unguard();

Gate::before(function (User $user, string $ability) {
return $user->hasRole("superman") ? true : null;
return $user->is_superman ? true : null;
});
}
}
2 changes: 2 additions & 0 deletions app/Providers/Filament/JamaahPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Filament\Jamaah\Pages\Dashboard;
use App\Filament\Jamaah\Pages\JamaahProfile;
use App\Filament\Jamaah\Pages\JamaahRegistration;
use App\Http\Middleware\UserMiddleware;
use App\Models\Jamaah;
use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin;
use DutchCodingCompany\FilamentSocialite\Provider;
Expand Down Expand Up @@ -69,6 +70,7 @@ public function panel(Panel $panel): Panel
SubstituteBindings::class,
DisableBladeIconComponents::class,
DispatchServingFilamentEvent::class,
UserMiddleware::class
])
->tenantMiddleware([
SyncSpatiePermissionsWithFilamentTenants::class,
Expand Down
2 changes: 2 additions & 0 deletions app/Providers/Filament/SupermanPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Althinect\FilamentSpatieRolesPermissions\FilamentSpatieRolesPermissionsPlugin;
use Althinect\FilamentSpatieRolesPermissions\Middleware\SyncSpatiePermissionsWithFilamentTenants;
use App\Filament\Superman\Pages\Dashboard;
use App\Http\Middleware\SupermanMiddleware;
use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin;
use DutchCodingCompany\FilamentSocialite\Provider;
use Filament\Http\Middleware\Authenticate;
Expand Down Expand Up @@ -62,6 +63,7 @@ public function panel(Panel $panel): Panel
SubstituteBindings::class,
DisableBladeIconComponents::class,
DispatchServingFilamentEvent::class,
SupermanMiddleware::class
])
->authMiddleware([
Authenticate::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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::table('users', function (Blueprint $table) {
$table->boolean("is_superman")->after("password")->default(false);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn("is_superman");
});
}
};
11 changes: 1 addition & 10 deletions database/seeders/RoleSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,10 @@ class RoleSeeder extends Seeder
*/
public function run(): void
{
// superman will get special treatment from kripton's Gate
$superman = Role::create(
['name' => 'superman', "guard_name" => 'web']
);
$superman->givePermissionTo(
Permission::where("guard_name", "web")->get()
);

// Admin Permissions
$admin = Role::create(
Role::create(
['name' => 'admin', "guard_name" => 'web'],
);

// $admin->givePermissionTo(
// ['create jamaah', 'unpublish jamaah']
// );
Expand Down

0 comments on commit f146a4a

Please sign in to comment.