Files
ntspi-app/app/Ship/Commands/SyncDashboardPermissions.php
T
F4ilji d6c0f48d48 feat(analytics): add site analytics with grouped navigation sections
- Add Analytics container: models, tasks, jobs, controllers, routes, services
- Add analytics config with section groups (structure, institute, content, services)
- Add database tables: analytics_sessions, analytics_hits, analytics_daily_stats
- Add frontend: Analytics page, section detail, chart, overview, navigation components
- Add consent banner and JS tracking service (sendBeacon + Inertia listener)
- Add permission sync for view_analytics, view_any_analytic
- Fix trailing slash URL matching in GetNavigationSectionsTask
- Fix event propagation on expand arrows in navigation sections
- Fix RecordVisitJob to not depend on dropped analytics_geo_cache table
- Replace plain text views/visitors with badge-style icons
- Group navigation sections by category with separate blocks
- Add config-driven non-CMS sections (faculties, divisions, DPO, journals)
- Remove Events, TV, Sveden from analytics sections
2026-09-18 22:18:04 +05:00

78 lines
2.4 KiB
PHP

<?php
namespace App\Ship\Commands;
use App\Ship\Abstracts\Commands\ConsoleCommand as AbstractConsoleCommand;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
class SyncDashboardPermissions extends AbstractConsoleCommand
{
protected $signature = 'dashboard:sync-permissions {--role=super_admin,admin : Roles to sync all permissions to}';
protected $description = 'Create missing dashboard permissions and sync to roles';
private const RESOURCES = [
'post', 'category', 'department', 'faculty', 'slider',
'user', 'role', 'page', 'news', 'menu', 'widget',
'contactwidget', 'additional_education', 'admission_campaign',
'schedule', 'academic_journal', 'main_section', 'sub_section',
'direction_study', 'educational_program', 'admission_plan',
'educational_group', 'division',
];
private const EXTRA_PERMISSIONS = [
'view_analytics',
'view_any_analytic',
];
private const PREFIXES = [
'view_any', 'create', 'update', 'delete', 'restore', 'force_delete',
];
public function handle(): int
{
$created = 0;
foreach (self::RESOURCES as $resource) {
foreach (self::PREFIXES as $prefix) {
$name = "{$prefix}_{$resource}";
Permission::firstOrCreate(
['name' => $name, 'guard_name' => 'web'],
);
$created++;
}
}
// Also create view_any_contact_widget (with underscore) if menuConfig uses it
Permission::firstOrCreate(
['name' => 'view_any_contact_widget', 'guard_name' => 'web'],
);
foreach (self::EXTRA_PERMISSIONS as $name) {
Permission::firstOrCreate(
['name' => $name, 'guard_name' => 'web'],
);
$created++;
}
$roleNames = explode(',', $this->option('role'));
$allPerms = Permission::where('guard_name', 'web')->get();
foreach ($roleNames as $roleName) {
$roleName = trim($roleName);
$role = Role::firstOrCreate(
['name' => $roleName, 'guard_name' => 'web'],
);
$role->syncPermissions($allPerms);
$this->info("Role [{$roleName}] synced with {$allPerms->count()} permissions");
}
$this->info("Done. Total permissions: {$allPerms->count()}");
return static::SUCCESS;
}
}