Add role-based access control to various settings pages: implement canAccess method in AboutPageSettings, ContactPageSettings, HomePageSettings, ManageCtaSettings, ManagePortfolio, ManageSite, ManageSiteSocialSettings, ManageSolutions, ManageSuccess, and update User model to include canManageSettings method for enhanced security and user experience.
This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Filament\Pages;
|
namespace App\Filament\Pages;
|
||||||
|
|
||||||
use App\Settings\AboutSettings;
|
|
||||||
use App\Models\UserRole;
|
use App\Models\UserRole;
|
||||||
|
use App\Settings\AboutSettings;
|
||||||
use Filament\Forms\Components\FileUpload;
|
use Filament\Forms\Components\FileUpload;
|
||||||
use Filament\Forms\Components\Grid;
|
use Filament\Forms\Components\Grid;
|
||||||
use Filament\Forms\Components\Repeater;
|
use Filament\Forms\Components\Repeater;
|
||||||
@@ -247,6 +247,11 @@ class AboutPageSettings extends SettingsPage
|
|||||||
return 'Manage the content sections of the About Us page.';
|
return 'Manage the content sections of the About Us page.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function canAccess(): bool
|
||||||
|
{
|
||||||
|
return auth()->user()->canManageSettings();
|
||||||
|
}
|
||||||
|
|
||||||
public static function canView(): bool
|
public static function canView(): bool
|
||||||
{
|
{
|
||||||
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
|
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Filament\Pages;
|
namespace App\Filament\Pages;
|
||||||
|
|
||||||
use App\Settings\ContactSettings;
|
|
||||||
use App\Models\UserRole;
|
use App\Models\UserRole;
|
||||||
|
use App\Settings\ContactSettings;
|
||||||
use Filament\Forms\Components\Section;
|
use Filament\Forms\Components\Section;
|
||||||
use Filament\Forms\Components\Textarea;
|
use Filament\Forms\Components\Textarea;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
@@ -86,6 +86,11 @@ class ContactPageSettings extends SettingsPage
|
|||||||
return 'Manage the contact form details, contact information, and map embed.';
|
return 'Manage the contact form details, contact information, and map embed.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function canAccess(): bool
|
||||||
|
{
|
||||||
|
return auth()->user()->canManageSettings();
|
||||||
|
}
|
||||||
|
|
||||||
public static function canView(): bool
|
public static function canView(): bool
|
||||||
{
|
{
|
||||||
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
|
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Filament\Pages;
|
namespace App\Filament\Pages;
|
||||||
|
|
||||||
use App\Settings\HomeSettings;
|
|
||||||
use App\Models\UserRole;
|
use App\Models\UserRole;
|
||||||
|
use App\Settings\HomeSettings;
|
||||||
use Filament\Forms\Components\FileUpload;
|
use Filament\Forms\Components\FileUpload;
|
||||||
use Filament\Forms\Components\Grid;
|
use Filament\Forms\Components\Grid;
|
||||||
use Filament\Forms\Components\Repeater;
|
use Filament\Forms\Components\Repeater;
|
||||||
@@ -294,6 +294,11 @@ class HomePageSettings extends SettingsPage
|
|||||||
return 'Manage the homepage hero section, background video, and call-to-action content.';
|
return 'Manage the homepage hero section, background video, and call-to-action content.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function canAccess(): bool
|
||||||
|
{
|
||||||
|
return auth()->user()->canManageSettings();
|
||||||
|
}
|
||||||
|
|
||||||
public static function canView(): bool
|
public static function canView(): bool
|
||||||
{
|
{
|
||||||
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
|
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
|
||||||
|
|||||||
@@ -2,13 +2,12 @@
|
|||||||
|
|
||||||
namespace App\Filament\Pages;
|
namespace App\Filament\Pages;
|
||||||
|
|
||||||
use App\Settings\CtaSettings;
|
|
||||||
use App\Models\UserRole;
|
use App\Models\UserRole;
|
||||||
|
use App\Settings\CtaSettings;
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
use Filament\Forms\Components\FileUpload;
|
use Filament\Forms\Components\FileUpload;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
use Filament\Pages\SettingsPage;
|
use Filament\Pages\SettingsPage;
|
||||||
use Illuminate\Contracts\Support\Htmlable;
|
|
||||||
|
|
||||||
class ManageCtaSettings extends SettingsPage
|
class ManageCtaSettings extends SettingsPage
|
||||||
{
|
{
|
||||||
@@ -45,6 +44,11 @@ class ManageCtaSettings extends SettingsPage
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function canAccess(): bool
|
||||||
|
{
|
||||||
|
return auth()->user()->canManageSettings();
|
||||||
|
}
|
||||||
|
|
||||||
public static function canView(): bool
|
public static function canView(): bool
|
||||||
{
|
{
|
||||||
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
|
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Filament\Pages;
|
namespace App\Filament\Pages;
|
||||||
|
|
||||||
use App\Settings\PortfolioSettings;
|
|
||||||
use App\Models\UserRole;
|
use App\Models\UserRole;
|
||||||
|
use App\Settings\PortfolioSettings;
|
||||||
use Filament\Forms\Components\FileUpload;
|
use Filament\Forms\Components\FileUpload;
|
||||||
use Filament\Forms\Components\Grid;
|
use Filament\Forms\Components\Grid;
|
||||||
use Filament\Forms\Components\Repeater;
|
use Filament\Forms\Components\Repeater;
|
||||||
@@ -110,6 +110,11 @@ class ManagePortfolio extends SettingsPage
|
|||||||
return 'Manage the portfolio section content, including items, categories, and titles.';
|
return 'Manage the portfolio section content, including items, categories, and titles.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function canAccess(): bool
|
||||||
|
{
|
||||||
|
return auth()->user()->canManageSettings();
|
||||||
|
}
|
||||||
|
|
||||||
public static function canView(): bool
|
public static function canView(): bool
|
||||||
{
|
{
|
||||||
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
|
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Filament\Pages;
|
namespace App\Filament\Pages;
|
||||||
|
|
||||||
use App\Settings\SiteSettings;
|
|
||||||
use App\Models\UserRole;
|
use App\Models\UserRole;
|
||||||
|
use App\Settings\SiteSettings;
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
use Filament\Pages\SettingsPage;
|
use Filament\Pages\SettingsPage;
|
||||||
@@ -170,6 +170,11 @@ class ManageSite extends SettingsPage
|
|||||||
return 'Manage your website\'s general configuration';
|
return 'Manage your website\'s general configuration';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function canAccess(): bool
|
||||||
|
{
|
||||||
|
return auth()->user()->canManageSettings();
|
||||||
|
}
|
||||||
|
|
||||||
public static function canView(): bool
|
public static function canView(): bool
|
||||||
{
|
{
|
||||||
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
|
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Filament\Pages;
|
namespace App\Filament\Pages;
|
||||||
|
|
||||||
use App\Settings\SiteSocialSettings;
|
|
||||||
use App\Models\UserRole;
|
use App\Models\UserRole;
|
||||||
|
use App\Settings\SiteSocialSettings;
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
use Filament\Pages\SettingsPage;
|
use Filament\Pages\SettingsPage;
|
||||||
@@ -79,6 +79,11 @@ class ManageSiteSocialSettings extends SettingsPage
|
|||||||
return 'Manage your social media profiles and sharing options';
|
return 'Manage your social media profiles and sharing options';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function canAccess(): bool
|
||||||
|
{
|
||||||
|
return auth()->user()->canManageSettings();
|
||||||
|
}
|
||||||
|
|
||||||
public static function canView(): bool
|
public static function canView(): bool
|
||||||
{
|
{
|
||||||
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
|
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Filament\Pages;
|
namespace App\Filament\Pages;
|
||||||
|
|
||||||
use App\Settings\SolutionSettings;
|
|
||||||
use App\Models\UserRole;
|
use App\Models\UserRole;
|
||||||
|
use App\Settings\SolutionSettings;
|
||||||
use Filament\Forms\Components\FileUpload;
|
use Filament\Forms\Components\FileUpload;
|
||||||
use Filament\Forms\Components\Grid;
|
use Filament\Forms\Components\Grid;
|
||||||
use Filament\Forms\Components\Repeater;
|
use Filament\Forms\Components\Repeater;
|
||||||
@@ -378,6 +378,11 @@ class ManageSolutions extends SettingsPage
|
|||||||
return 'Manage the solutions section content, including individual solution items.';
|
return 'Manage the solutions section content, including individual solution items.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function canAccess(): bool
|
||||||
|
{
|
||||||
|
return auth()->user()->canManageSettings();
|
||||||
|
}
|
||||||
|
|
||||||
public static function canView(): bool
|
public static function canView(): bool
|
||||||
{
|
{
|
||||||
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
|
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Filament\Pages;
|
namespace App\Filament\Pages;
|
||||||
|
|
||||||
use App\Settings\SuccessSettings;
|
|
||||||
use App\Models\UserRole;
|
use App\Models\UserRole;
|
||||||
|
use App\Settings\SuccessSettings;
|
||||||
use Filament\Forms\Components\FileUpload;
|
use Filament\Forms\Components\FileUpload;
|
||||||
use Filament\Forms\Components\Grid;
|
use Filament\Forms\Components\Grid;
|
||||||
use Filament\Forms\Components\Repeater;
|
use Filament\Forms\Components\Repeater;
|
||||||
@@ -115,6 +115,11 @@ class ManageSuccess extends SettingsPage
|
|||||||
return 'Manage the success section content, including text, button, and skill bars.';
|
return 'Manage the success section content, including text, button, and skill bars.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function canAccess(): bool
|
||||||
|
{
|
||||||
|
return auth()->user()->canManageSettings();
|
||||||
|
}
|
||||||
|
|
||||||
public static function canView(): bool
|
public static function canView(): bool
|
||||||
{
|
{
|
||||||
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
|
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
|
||||||
|
|||||||
@@ -16,9 +16,8 @@ use Filament\Resources\Resource;
|
|||||||
use Filament\Tables;
|
use Filament\Tables;
|
||||||
use Filament\Tables\Columns\ImageColumn;
|
use Filament\Tables\Columns\ImageColumn;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class NewsResource extends Resource
|
class NewsResource extends Resource
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ use Filament\Resources\Resource;
|
|||||||
use Filament\Tables;
|
use Filament\Tables;
|
||||||
use Filament\Tables\Columns\ImageColumn;
|
use Filament\Tables\Columns\ImageColumn;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class SuccessResource extends Resource
|
class SuccessResource extends Resource
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
namespace App\Filament\Resources;
|
namespace App\Filament\Resources;
|
||||||
|
|
||||||
use App\Filament\Resources\TeamMemberResource\Pages;
|
use App\Filament\Resources\TeamMemberResource\Pages;
|
||||||
use App\Filament\Resources\TeamMemberResource\RelationManagers;
|
|
||||||
use App\Models\TeamMember;
|
use App\Models\TeamMember;
|
||||||
use App\Models\UserRole;
|
use App\Models\UserRole;
|
||||||
use Filament\Forms\Components\FileUpload;
|
use Filament\Forms\Components\FileUpload;
|
||||||
@@ -12,14 +11,9 @@ use Filament\Forms\Components\TextInput;
|
|||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
use Filament\Resources\Resource;
|
use Filament\Resources\Resource;
|
||||||
use Filament\Tables;
|
use Filament\Tables;
|
||||||
use Filament\Tables\Actions\ActionGroup;
|
|
||||||
use Filament\Tables\Actions\DeleteAction;
|
|
||||||
use Filament\Tables\Actions\EditAction;
|
|
||||||
use Filament\Tables\Columns\ImageColumn;
|
use Filament\Tables\Columns\ImageColumn;
|
||||||
use Filament\Tables\Columns\TextColumn;
|
use Filament\Tables\Columns\TextColumn;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
||||||
|
|
||||||
class TeamMemberResource extends Resource
|
class TeamMemberResource extends Resource
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
namespace App\Filament\Resources\TeamMemberResource\Pages;
|
namespace App\Filament\Resources\TeamMemberResource\Pages;
|
||||||
|
|
||||||
use App\Filament\Resources\TeamMemberResource;
|
use App\Filament\Resources\TeamMemberResource;
|
||||||
use Filament\Actions;
|
|
||||||
use Filament\Resources\Pages\CreateRecord;
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
class CreateTeamMember extends CreateRecord
|
class CreateTeamMember extends CreateRecord
|
||||||
|
|||||||
@@ -54,4 +54,9 @@ class User extends Authenticatable
|
|||||||
'role' => UserRole::class,
|
'role' => UserRole::class,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function canManageSettings(): bool
|
||||||
|
{
|
||||||
|
return $this->role === UserRole::ADMIN || $this->role === UserRole::MANAGER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ namespace App\Providers\Filament;
|
|||||||
use App\Filament\Pages\HomePageSettings;
|
use App\Filament\Pages\HomePageSettings;
|
||||||
use App\Filament\Pages\ManageCtaSettings;
|
use App\Filament\Pages\ManageCtaSettings;
|
||||||
use App\Filament\Resources\ApplicationResource;
|
use App\Filament\Resources\ApplicationResource;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Models\UserRole;
|
||||||
use Filament\Http\Middleware\Authenticate;
|
use Filament\Http\Middleware\Authenticate;
|
||||||
use Filament\Http\Middleware\DisableBladeIconComponents;
|
use Filament\Http\Middleware\DisableBladeIconComponents;
|
||||||
use Filament\Http\Middleware\DispatchServingFilamentEvent;
|
use Filament\Http\Middleware\DispatchServingFilamentEvent;
|
||||||
@@ -19,10 +21,8 @@ use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
|
|||||||
use Illuminate\Routing\Middleware\SubstituteBindings;
|
use Illuminate\Routing\Middleware\SubstituteBindings;
|
||||||
use Illuminate\Session\Middleware\AuthenticateSession;
|
use Illuminate\Session\Middleware\AuthenticateSession;
|
||||||
use Illuminate\Session\Middleware\StartSession;
|
use Illuminate\Session\Middleware\StartSession;
|
||||||
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Models\UserRole;
|
|
||||||
use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
|
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||||||
|
|
||||||
class PanelPanelProvider extends PanelProvider
|
class PanelPanelProvider extends PanelProvider
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,32 +8,47 @@ class AboutSettings extends Settings
|
|||||||
{
|
{
|
||||||
// Our Story Section
|
// Our Story Section
|
||||||
public string $our_story_title;
|
public string $our_story_title;
|
||||||
|
|
||||||
public string $our_story_subtitle;
|
public string $our_story_subtitle;
|
||||||
|
|
||||||
public string $our_story_paragraph_one;
|
public string $our_story_paragraph_one;
|
||||||
|
|
||||||
public string $our_story_paragraph_two;
|
public string $our_story_paragraph_two;
|
||||||
|
|
||||||
public string $our_story_paragraph_three;
|
public string $our_story_paragraph_three;
|
||||||
|
|
||||||
public string $our_story_button_text;
|
public string $our_story_button_text;
|
||||||
|
|
||||||
public string $our_story_button_url;
|
public string $our_story_button_url;
|
||||||
|
|
||||||
public string $our_story_video_poster;
|
public string $our_story_video_poster;
|
||||||
|
|
||||||
public string $our_story_video_source;
|
public string $our_story_video_source;
|
||||||
|
|
||||||
// Our Journey Section
|
// Our Journey Section
|
||||||
public string $our_journey_title;
|
public string $our_journey_title;
|
||||||
|
|
||||||
public string $our_journey_subtitle;
|
public string $our_journey_subtitle;
|
||||||
|
|
||||||
public array $our_journey_milestones; // [{year: 2010, title: "Start Company", description: "...", image: "..."}]
|
public array $our_journey_milestones; // [{year: 2010, title: "Start Company", description: "...", image: "..."}]
|
||||||
|
|
||||||
// Company Structure Section
|
// Company Structure Section
|
||||||
public string $company_structure_title;
|
public string $company_structure_title;
|
||||||
|
|
||||||
public string $company_structure_subtitle;
|
public string $company_structure_subtitle;
|
||||||
|
|
||||||
public string $company_structure_director_name;
|
public string $company_structure_director_name;
|
||||||
|
|
||||||
public string $company_structure_advisor_name;
|
public string $company_structure_advisor_name;
|
||||||
|
|
||||||
public array $company_structure_departments; // [{name: "HSE", person: "Michael Brown"}]
|
public array $company_structure_departments; // [{name: "HSE", person: "Michael Brown"}]
|
||||||
|
|
||||||
// Our Facilities Section
|
// Our Facilities Section
|
||||||
public string $our_facilities_title;
|
public string $our_facilities_title;
|
||||||
public string $our_facilities_subtitle;
|
|
||||||
public array $our_facilities_locations; // [{name: "Headquarters", location: "...", description: "...", image: "...", tags: ["R&D Labs"]}]
|
|
||||||
|
|
||||||
|
public string $our_facilities_subtitle;
|
||||||
|
|
||||||
|
public array $our_facilities_locations; // [{name: "Headquarters", location: "...", description: "...", image: "...", tags: ["R&D Labs"]}]
|
||||||
|
|
||||||
public static function group(): string
|
public static function group(): string
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user