first commit

This commit is contained in:
salam committed 2025-09-04 16:06:17 +02:00
commit c9b36775da
180 files changed
+18476

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
<?php
namespace App\Http\Controllers;
abstract class Controller
{
//
}
@@ -0,0 +1,24 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class AppUserVerifiedMiddleware
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if (is_null($request->user()->app_verified_at)) {
abort(Response::HTTP_FORBIDDEN, 'Ihr Konto muss von einem Administrator verifiziert werden.');
}
return $next($request);
}
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace App\Livewire;
use App\Models\User;
use Livewire\Component;
class TenancySwitch extends Component
{
public function render()
{
return view('livewire.tenancy-switch');
}
public function swop($kammer_id)
{
User::find(auth()->user()->id)->update(['kammer_id' => $kammer_id]);
$this->js('window.location.reload()');
}
}
+97
View File
@@ -0,0 +1,97 @@
<?php
namespace App\Models;
use Filament\Models\Contracts\FilamentUser;
use Filament\Panel;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Log;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable implements FilamentUser, MustVerifyEmail
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, HasRoles, Notifiable, SoftDeletes;
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'name',
'email',
'password',
'super_admin',
'app_verified_at',
'first_name',
'last_name',
'gender',
'company',
'uid',
'address',
'place',
'postcode',
'phone',
];
/**
* The attributes that should be hidden for serialization.
*
* @var list<string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'app_verified_at' => 'datetime',
];
}
public function canAccessPanel(Panel $panel): bool
{
Log::info('canAccessPanel');
return true;
}
public function canAccessAdminPanel(Panel $panel): bool
{
Log::info('canAccessAdminPanel');
if ($panel->getId() === 'admin') {
return (
str_ends_with($this->email, '@webwerkstatt.tirol') ||
str_ends_with($this->email, '@kammerwest.at')
)
&& $this->hasVerifiedEmail();
}
return false;
}
public function kammer()
{
return $this->belongsTo(Kammer::class);
}
public function bundesland()
{
return $this->belongsTo(Bundesland::class);
}
}
+108
View File
@@ -0,0 +1,108 @@
<?php
namespace App\Policies;
use App\Models\User;
use Spatie\Permission\Models\Role;
use Illuminate\Auth\Access\HandlesAuthorization;
class RolePolicy
{
use HandlesAuthorization;
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return $user->can('view_any_role');
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, Role $role): bool
{
return $user->can('view_role');
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return $user->can('create_role');
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, Role $role): bool
{
return $user->can('update_role');
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, Role $role): bool
{
return $user->can('delete_role');
}
/**
* Determine whether the user can bulk delete.
*/
public function deleteAny(User $user): bool
{
return $user->can('delete_any_role');
}
/**
* Determine whether the user can permanently delete.
*/
public function forceDelete(User $user, Role $role): bool
{
return $user->can('{{ ForceDelete }}');
}
/**
* Determine whether the user can permanently bulk delete.
*/
public function forceDeleteAny(User $user): bool
{
return $user->can('{{ ForceDeleteAny }}');
}
/**
* Determine whether the user can restore.
*/
public function restore(User $user, Role $role): bool
{
return $user->can('{{ Restore }}');
}
/**
* Determine whether the user can bulk restore.
*/
public function restoreAny(User $user): bool
{
return $user->can('{{ RestoreAny }}');
}
/**
* Determine whether the user can replicate.
*/
public function replicate(User $user, Role $role): bool
{
return $user->can('{{ Replicate }}');
}
/**
* Determine whether the user can reorder.
*/
public function reorder(User $user): bool
{
return $user->can('{{ Reorder }}');
}
}
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace App\Providers;
use Filament\Support\Facades\FilamentView;
use Filament\View\PanelsRenderHook;
use Illuminate\Support\ServiceProvider;
use Illuminate\View\View;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
FilamentView::registerRenderHook(
PanelsRenderHook::FOOTER, fn (): View => view('footer'),
);
}
}
@@ -0,0 +1,87 @@
<?php
namespace App\Providers\Filament;
use App\Http\Middleware\AppUserVerifiedMiddleware;
use Awcodes\LightSwitch\Enums\Alignment;
use Awcodes\LightSwitch\LightSwitchPlugin;
use BezhanSalleh\FilamentShield\FilamentShieldPlugin;
use Filament\Http\Middleware\Authenticate;
use Filament\Http\Middleware\AuthenticateSession;
use Filament\Http\Middleware\DisableBladeIconComponents;
use Filament\Http\Middleware\DispatchServingFilamentEvent;
use Filament\Pages\Dashboard;
use Filament\Panel;
use Filament\PanelProvider;
use Filament\Support\Colors\Color;
use Filament\Support\Enums\Width;
use Filament\View\PanelsRenderHook;
use Filament\Widgets\AccountWidget;
use Filament\Widgets\FilamentInfoWidget;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\Support\Facades\Blade;
use Illuminate\View\Middleware\ShareErrorsFromSession;
use Swis\Filament\Backgrounds\FilamentBackgroundsPlugin;
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->id('admin')
->path('')
->login()
->default()
->colors([
'primary' => Color::Blue,
'secondary' => Color::Amber,
])->renderHook(
PanelsRenderHook::GLOBAL_SEARCH_BEFORE,
fn (): string => auth()->user()->hasRole('tenancy_switch') ? Blade::render('@livewire(\'tenancy-switch\')') : false
)
->maxContentWidth(Width::ScreenExtraLarge)
->sidebarCollapsibleOnDesktop()
->font('Poppins')
->favicon(asset('images/building.svg'))
->brandLogo(asset('images/logo-light.svg'))
->darkModeBrandLogo(asset('images/logo-dark.svg'))
->brandLogoHeight('2rem')
->unsavedChangesAlerts()
->databaseTransactions()
->discoverResources(in: app_path('Filament/Resources'), for: 'App\Filament\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\Filament\Pages')
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\Filament\Widgets')
->viteTheme('resources/css/filament/admin/theme.css')
->pages([
Dashboard::class,
])
->widgets([
AccountWidget::class,
FilamentInfoWidget::class,
])
->middleware([
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
StartSession::class,
AuthenticateSession::class,
ShareErrorsFromSession::class,
VerifyCsrfToken::class,
SubstituteBindings::class,
DisableBladeIconComponents::class,
DispatchServingFilamentEvent::class,
])
->authMiddleware([
AppUserVerifiedMiddleware::class,
Authenticate::class,
])->plugins([
FilamentShieldPlugin::make(),
FilamentBackgroundsPlugin::make(),
LightSwitchPlugin::make()->position(Alignment::TopCenter),
]);
}
}