| 1 |
<?php |
| 2 |
|
| 3 |
namespace VisualComposer\Modules\Migrations; |
| 4 |
|
| 5 |
if (!defined('ABSPATH')) { |
| 6 |
header('Status: 403 Forbidden'); |
| 7 |
header('HTTP/1.1 403 Forbidden'); |
| 8 |
exit; |
| 9 |
} |
| 10 |
|
| 11 |
use VisualComposer\Framework\Illuminate\Support\Module; |
| 12 |
|
| 13 |
class NewDefaultCapabilitiesMigration extends MigrationsController implements Module |
| 14 |
{ |
| 15 |
protected $migrationId = 'defaultCapabilitiesMigration46'; |
| 16 |
|
| 17 |
protected $migrationPriority = 1; |
| 18 |
|
| 19 |
protected function run() |
| 20 |
{ |
| 21 |
// Run migration only if role Manager addon is available and is enabled |
| 22 |
if (!vcvenv('VCV_ADDON_ROLE_MANAGER_PARTS')) { |
| 23 |
return false; |
| 24 |
} |
| 25 |
|
| 26 |
$roleHelper = vchelper('AccessRole'); |
| 27 |
$userCapabilitiesHelper = vchelper('AccessUserCapabilities'); |
| 28 |
$defaultCapabilities = $userCapabilitiesHelper->getDefaultCapabilities(); |
| 29 |
|
| 30 |
// for a security reason we decided to remove all default caps in some user roles. |
| 31 |
$roleWithoutDefaultCaps = ['author', 'contributor']; |
| 32 |
|
| 33 |
foreach ($defaultCapabilities as $roleName => $roleParts) { |
| 34 |
if (in_array($roleName, $roleWithoutDefaultCaps)) { |
| 35 |
continue; |
| 36 |
} |
| 37 |
|
| 38 |
foreach ($roleParts as $capPart => $capabilities) { |
| 39 |
foreach ($capabilities as $cap) { |
| 40 |
if (!is_object($roleHelper->who($roleName)->part($capPart)->getRole())) { |
| 41 |
continue; |
| 42 |
} |
| 43 |
|
| 44 |
if (! $roleHelper->who($roleName)->part($capPart)->issetCapRule($cap)) { |
| 45 |
$roleHelper->who($roleName)->part($capPart)->setCapRule($cap); |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
return true; |
| 52 |
} |
| 53 |
} |
| 54 |
|