69 lines
2.0 KiB
PHP
69 lines
2.0 KiB
PHP
<?php
|
|
|
|
// Run with: php artisan tinker --execute="require base_path('fix_content_manager_permissions.php');"
|
|
|
|
$canonicalPermissions = [
|
|
'create posts',
|
|
'update posts',
|
|
'delete posts',
|
|
'publish posts',
|
|
'unpublish posts',
|
|
'manage posts',
|
|
'create tags',
|
|
'update tags',
|
|
'delete tags',
|
|
'manage tags',
|
|
'create mailings',
|
|
'update mailings',
|
|
'manage calls',
|
|
'create calls',
|
|
'update calls',
|
|
'delete calls',
|
|
'view posts',
|
|
'view tags',
|
|
'view calls',
|
|
'view mailings',
|
|
'publish calls',
|
|
'unpublish calls',
|
|
'view search-metrics',
|
|
'admin contacts',
|
|
'admin change-password',
|
|
];
|
|
|
|
$roles = \Spatie\Permission\Models\Role::where('name', 'like', '%content-manager')->get();
|
|
|
|
if ($roles->isEmpty()) {
|
|
echo "No content-manager roles found." . PHP_EOL;
|
|
return;
|
|
}
|
|
|
|
foreach ($roles as $role) {
|
|
echo "Processing role: {$role->name}" . PHP_EOL;
|
|
|
|
$currentPermissions = $role->permissions->pluck('name')->toArray();
|
|
echo " Current permissions (" . count($currentPermissions) . "):" . PHP_EOL;
|
|
foreach ($currentPermissions as $p) {
|
|
$flag = in_array($p, $canonicalPermissions) ? ' OK' : ' REMOVE';
|
|
echo " [{$flag}] {$p}" . PHP_EOL;
|
|
}
|
|
|
|
$toAdd = array_diff($canonicalPermissions, $currentPermissions);
|
|
$toRemove = array_diff($currentPermissions, $canonicalPermissions);
|
|
|
|
echo " To add (" . count($toAdd) . "): " . implode(', ', $toAdd) . PHP_EOL;
|
|
echo " To remove (" . count($toRemove) . "): " . implode(', ', $toRemove) . PHP_EOL;
|
|
|
|
// Sync to exactly the canonical set
|
|
$role->syncPermissions($canonicalPermissions);
|
|
|
|
$after = $role->fresh()->permissions->pluck('name')->sort()->values();
|
|
echo " Done. Final permissions (" . count($after) . "):" . PHP_EOL;
|
|
foreach ($after as $p) {
|
|
echo " - {$p}" . PHP_EOL;
|
|
}
|
|
}
|
|
|
|
// Clear permission cache
|
|
app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();
|
|
echo PHP_EOL . "Permission cache cleared." . PHP_EOL;
|