Selaa lähdekoodia

Merge pull request #139 from andrewdwallo/development-3.x

Development 3.x
3.x
Andrew Wallo 5 kuukautta sitten
vanhempi
commit
746bffdf84
No account linked to committer's email address

+ 27
- 0
app/Filament/Company/Pages/Service/ConnectedAccount.php Näytä tiedosto

@@ -2,7 +2,9 @@
2 2
 
3 3
 namespace App\Filament\Company\Pages\Service;
4 4
 
5
+use App\Services\PlaidService;
5 6
 use Filament\Actions\Action;
7
+use Filament\Navigation\NavigationItem;
6 8
 use Filament\Pages\Page;
7 9
 use Filament\Support\Enums\MaxWidth;
8 10
 use Illuminate\Contracts\Support\Htmlable;
@@ -15,6 +17,11 @@ class ConnectedAccount extends Page
15 17
 
16 18
     protected static string $view = 'filament.company.pages.service.connected-account';
17 19
 
20
+    public static function canAccess(): bool
21
+    {
22
+        return app(PlaidService::class)->isEnabled();
23
+    }
24
+
18 25
     public function getTitle(): string | Htmlable
19 26
     {
20 27
         return translate(static::$title);
@@ -34,6 +41,26 @@ class ConnectedAccount extends Page
34 41
         ];
35 42
     }
36 43
 
44
+    /**
45
+     * @return array<NavigationItem>
46
+     */
47
+    public static function getNavigationItems(): array
48
+    {
49
+        return [
50
+            NavigationItem::make(static::getNavigationLabel())
51
+                ->visible(static::canAccess())
52
+                ->group(static::getNavigationGroup())
53
+                ->parentItem(static::getNavigationParentItem())
54
+                ->icon(static::getNavigationIcon())
55
+                ->activeIcon(static::getActiveNavigationIcon())
56
+                ->isActiveWhen(fn (): bool => request()->routeIs(static::getNavigationItemActiveRoutePattern()))
57
+                ->sort(static::getNavigationSort())
58
+                ->badge(static::getNavigationBadge(), color: static::getNavigationBadgeColor())
59
+                ->badgeTooltip(static::getNavigationBadgeTooltip())
60
+                ->url(static::getNavigationUrl()),
61
+        ];
62
+    }
63
+
37 64
     public function getMaxContentWidth(): MaxWidth | string | null
38 65
     {
39 66
         return MaxWidth::ScreenLarge;

+ 26
- 6
app/Filament/Company/Pages/Service/LiveCurrency.php Näytä tiedosto

@@ -5,6 +5,7 @@ namespace App\Filament\Company\Pages\Service;
5 5
 use App\Facades\Forex;
6 6
 use App\Models\Service\CurrencyList;
7 7
 use App\Models\Setting\Currency;
8
+use Filament\Navigation\NavigationItem;
8 9
 use Filament\Pages\Page;
9 10
 use Illuminate\Contracts\Support\Htmlable;
10 11
 use Livewire\Attributes\Url;
@@ -20,25 +21,24 @@ class LiveCurrency extends Page
20 21
     #[Url]
21 22
     public ?string $activeTab = null;
22 23
 
23
-    public function getTitle(): string | Htmlable
24
+    public static function canAccess(): bool
24 25
     {
25
-        return translate(static::$title);
26
+        return Forex::isEnabled();
26 27
     }
27 28
 
28
-    public static function getNavigationLabel(): string
29
+    public function getTitle(): string | Htmlable
29 30
     {
30 31
         return translate(static::$title);
31 32
     }
32 33
 
33
-    public static function shouldRegisterNavigation(): bool
34
+    public static function getNavigationLabel(): string
34 35
     {
35
-        return Forex::isEnabled();
36
+        return translate(static::$title);
36 37
     }
37 38
 
38 39
     public function mount(): void
39 40
     {
40 41
         $this->loadDefaultActiveTab();
41
-        abort_unless(Forex::isEnabled(), 403);
42 42
     }
43 43
 
44 44
     protected function loadDefaultActiveTab(): void
@@ -62,4 +62,24 @@ class LiveCurrency extends Page
62 62
             'companyCurrenciesQuery' => Currency::query()->count(),
63 63
         ];
64 64
     }
65
+
66
+    /**
67
+     * @return array<NavigationItem>
68
+     */
69
+    public static function getNavigationItems(): array
70
+    {
71
+        return [
72
+            NavigationItem::make(static::getNavigationLabel())
73
+                ->visible(static::canAccess())
74
+                ->group(static::getNavigationGroup())
75
+                ->parentItem(static::getNavigationParentItem())
76
+                ->icon(static::getNavigationIcon())
77
+                ->activeIcon(static::getActiveNavigationIcon())
78
+                ->isActiveWhen(fn (): bool => request()->routeIs(static::getNavigationItemActiveRoutePattern()))
79
+                ->sort(static::getNavigationSort())
80
+                ->badge(static::getNavigationBadge(), color: static::getNavigationBadgeColor())
81
+                ->badgeTooltip(static::getNavigationBadgeTooltip())
82
+                ->url(static::getNavigationUrl()),
83
+        ];
84
+    }
65 85
 }

+ 26
- 0
app/Filament/User/Clusters/Account.php Näytä tiedosto

@@ -3,6 +3,7 @@
3 3
 namespace App\Filament\User\Clusters;
4 4
 
5 5
 use Filament\Clusters\Cluster;
6
+use Filament\Navigation\NavigationItem;
6 7
 
7 8
 class Account extends Cluster
8 9
 {
@@ -16,4 +17,29 @@ class Account extends Cluster
16 17
     {
17 18
         return static::getUrl(panel: 'user');
18 19
     }
20
+
21
+    public static function canAccess(): bool
22
+    {
23
+        return ! app()->environment('demo');
24
+    }
25
+
26
+    /**
27
+     * @return array<NavigationItem>
28
+     */
29
+    public static function getNavigationItems(): array
30
+    {
31
+        return [
32
+            NavigationItem::make(static::getNavigationLabel())
33
+                ->visible(static::canAccess())
34
+                ->group(static::getNavigationGroup())
35
+                ->parentItem(static::getNavigationParentItem())
36
+                ->icon(static::getNavigationIcon())
37
+                ->activeIcon(static::getActiveNavigationIcon())
38
+                ->isActiveWhen(fn (): bool => request()->routeIs(static::getNavigationItemActiveRoutePattern()))
39
+                ->sort(static::getNavigationSort())
40
+                ->badge(static::getNavigationBadge(), color: static::getNavigationBadgeColor())
41
+                ->badgeTooltip(static::getNavigationBadgeTooltip())
42
+                ->url(static::getNavigationUrl()),
43
+        ];
44
+    }
19 45
 }

+ 4
- 0
app/Models/User.php Näytä tiedosto

@@ -71,6 +71,10 @@ class User extends Authenticatable implements FilamentUser, HasAvatar, HasDefaul
71 71
 
72 72
     public function canAccessPanel(Panel $panel): bool
73 73
     {
74
+        if ($panel->getId() === 'user' && app()->environment('demo')) {
75
+            return false;
76
+        }
77
+
74 78
         return true;
75 79
     }
76 80
 

+ 24
- 0
app/Policies/CompanyPolicy.php Näytä tiedosto

@@ -31,6 +31,10 @@ class CompanyPolicy
31 31
      */
32 32
     public function create(User $user): bool
33 33
     {
34
+        if (app()->environment('demo')) {
35
+            return false;
36
+        }
37
+
34 38
         return true;
35 39
     }
36 40
 
@@ -39,6 +43,10 @@ class CompanyPolicy
39 43
      */
40 44
     public function update(User $user, Company $company): bool
41 45
     {
46
+        if (app()->environment('demo')) {
47
+            return false;
48
+        }
49
+
42 50
         return $user->ownsCompany($company);
43 51
     }
44 52
 
@@ -47,6 +55,10 @@ class CompanyPolicy
47 55
      */
48 56
     public function addCompanyEmployee(User $user, Company $company): bool
49 57
     {
58
+        if (app()->environment('demo')) {
59
+            return false;
60
+        }
61
+
50 62
         return $user->ownsCompany($company);
51 63
     }
52 64
 
@@ -55,6 +67,10 @@ class CompanyPolicy
55 67
      */
56 68
     public function updateCompanyEmployee(User $user, Company $company): bool
57 69
     {
70
+        if (app()->environment('demo')) {
71
+            return false;
72
+        }
73
+
58 74
         return $user->ownsCompany($company);
59 75
     }
60 76
 
@@ -63,6 +79,10 @@ class CompanyPolicy
63 79
      */
64 80
     public function removeCompanyEmployee(User $user, Company $company): bool
65 81
     {
82
+        if (app()->environment('demo')) {
83
+            return false;
84
+        }
85
+
66 86
         return $user->ownsCompany($company);
67 87
     }
68 88
 
@@ -71,6 +91,10 @@ class CompanyPolicy
71 91
      */
72 92
     public function delete(User $user, Company $company): bool
73 93
     {
94
+        if (app()->environment('demo')) {
95
+            return false;
96
+        }
97
+
74 98
         return $user->ownsCompany($company);
75 99
     }
76 100
 }

+ 0
- 60
app/Providers/Filament/AdminPanelProvider.php Näytä tiedosto

@@ -1,60 +0,0 @@
1
-<?php
2
-
3
-namespace App\Providers\Filament;
4
-
5
-use App\Http\Middleware\Authenticate;
6
-use Exception;
7
-use Filament\Http\Middleware\DisableBladeIconComponents;
8
-use Filament\Http\Middleware\DispatchServingFilamentEvent;
9
-use Filament\Pages;
10
-use Filament\Panel;
11
-use Filament\PanelProvider;
12
-use Filament\Support\Colors\Color;
13
-use Filament\Widgets;
14
-use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
15
-use Illuminate\Cookie\Middleware\EncryptCookies;
16
-use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
17
-use Illuminate\Routing\Middleware\SubstituteBindings;
18
-use Illuminate\Session\Middleware\AuthenticateSession;
19
-use Illuminate\Session\Middleware\StartSession;
20
-use Illuminate\View\Middleware\ShareErrorsFromSession;
21
-
22
-class AdminPanelProvider extends PanelProvider
23
-{
24
-    /**
25
-     * @throws Exception
26
-     */
27
-    public function panel(Panel $panel): Panel
28
-    {
29
-        return $panel
30
-            ->id('admin')
31
-            ->path('admin')
32
-            ->colors([
33
-                'primary' => Color::Amber,
34
-            ])
35
-            ->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
36
-            ->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
37
-            ->pages([
38
-                Pages\Dashboard::class,
39
-            ])
40
-            ->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
41
-            ->widgets([
42
-                Widgets\AccountWidget::class,
43
-                Widgets\FilamentInfoWidget::class,
44
-            ])
45
-            ->middleware([
46
-                EncryptCookies::class,
47
-                AddQueuedCookiesToResponse::class,
48
-                StartSession::class,
49
-                AuthenticateSession::class,
50
-                ShareErrorsFromSession::class,
51
-                VerifyCsrfToken::class,
52
-                SubstituteBindings::class,
53
-                DisableBladeIconComponents::class,
54
-                DispatchServingFilamentEvent::class,
55
-            ])
56
-            ->authMiddleware([
57
-                Authenticate::class,
58
-            ]);
59
-    }
60
-}

+ 11
- 10
app/Providers/Filament/CompanyPanelProvider.php Näytä tiedosto

@@ -85,27 +85,28 @@ class CompanyPanelProvider extends PanelProvider
85 85
             ->id('company')
86 86
             ->path('company')
87 87
             ->login(Login::class)
88
-            ->registration(Register::class)
89
-            ->passwordReset()
88
+            ->registration(action: app()->environment('demo') ? null : Register::class)
89
+            ->passwordReset(requestAction: app()->environment('demo') ? null : Pages\Auth\PasswordReset\RequestPasswordReset::class)
90 90
             ->tenantMenu(false)
91 91
             ->plugin(
92 92
                 FilamentCompanies::make()
93 93
                     ->userPanel('user')
94 94
                     ->switchCurrentCompany()
95
-                    ->updateProfileInformation(component: UpdateProfileInformation::class)
96
-                    ->updatePasswords(component: UpdatePassword::class)
97
-                    ->setPasswords()
98
-                    ->connectedAccounts()
99
-                    ->manageBrowserSessions()
100
-                    ->accountDeletion()
101
-                    ->profilePhotos()
102
-                    ->api()
95
+                    ->updateProfileInformation(condition: ! app()->environment('demo'), component: UpdateProfileInformation::class)
96
+                    ->updatePasswords(condition: ! app()->environment('demo'), component: UpdatePassword::class)
97
+                    ->setPasswords(condition: ! app()->environment('demo'))
98
+                    ->connectedAccounts(condition: ! app()->environment('demo'))
99
+                    ->manageBrowserSessions(condition: ! app()->environment('demo'))
100
+                    ->accountDeletion(condition: ! app()->environment('demo'))
101
+                    ->profilePhotos(condition: ! app()->environment('demo'))
102
+                    ->api(condition: ! app()->environment('demo'))
103 103
                     ->companies(invitations: true)
104 104
                     ->autoAcceptInvitations()
105 105
                     ->termsAndPrivacyPolicy()
106 106
                     ->notifications()
107 107
                     ->modals()
108 108
                     ->socialite(
109
+                        condition: ! app()->environment('demo'),
109 110
                         providers: [Provider::Github],
110 111
                         features: [Feature::RememberSession, Feature::ProviderAvatars],
111 112
                     ),

+ 4
- 0
app/Services/CurrencyService.php Näytä tiedosto

@@ -21,6 +21,10 @@ class CurrencyService implements CurrencyHandler
21 21
      */
22 22
     public function isEnabled(): bool
23 23
     {
24
+        if (app()->environment('demo')) {
25
+            return false;
26
+        }
27
+
24 28
         return filled($this->apiKey) && filled($this->baseUrl);
25 29
     }
26 30
 

+ 12
- 0
app/Services/PlaidService.php Näytä tiedosto

@@ -58,6 +58,18 @@ class PlaidService
58 58
         $this->setBaseUrl($this->environment);
59 59
     }
60 60
 
61
+    /**
62
+     * Determine if the Plaid service is enabled and properly configured.
63
+     */
64
+    public function isEnabled(): bool
65
+    {
66
+        if (app()->environment('demo') || empty($this->clientId) || empty($this->clientSecret)) {
67
+            return false;
68
+        }
69
+
70
+        return true;
71
+    }
72
+
61 73
     public function setClientCredentials(?string $clientId, ?string $clientSecret): self
62 74
     {
63 75
         $this->clientId = $clientId ?? $this->clientId;

+ 0
- 1
bootstrap/app.php Näytä tiedosto

@@ -9,7 +9,6 @@ return Application::configure(basePath: dirname(__DIR__))
9 9
         web: __DIR__ . '/../routes/web.php',
10 10
         api: __DIR__ . '/../routes/api.php',
11 11
         commands: __DIR__ . '/../routes/console.php',
12
-        health: '/up',
13 12
     )
14 13
     ->withMiddleware(function (Middleware $middleware) {
15 14
         //

Loading…
Peruuta
Tallenna