Skip to content

Commit

Permalink
feat: add permissions- and access- keys for migrate()
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Apr 7, 2023
1 parent 75b6ccc commit 890c242
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions RockMigrations.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -2559,9 +2559,21 @@ public function migrate($config)
}
foreach ($config->roles as $role => $data) {
// set permissions for this role
if (array_key_exists("permissions", $data)) $this->setRolePermissions($role, $data['permissions']);
if (array_key_exists("permissions", $data)) {
$this->setRolePermissions($role, $data['permissions']);
}
if (array_key_exists("permissions-", $data)) {
$this->setRolePermissions($role, $data['permissions-'], true);
}
if (array_key_exists("access", $data)) {
foreach ($data['access'] as $tpl => $access) $this->setTemplateAccess($tpl, $role, $access);
foreach ($data['access'] as $tpl => $access) {
$this->setTemplateAccess($tpl, $role, $access);
}
}
if (array_key_exists("access-", $data)) {
foreach ($data['access'] as $tpl => $access) {
$this->setTemplateAccess($tpl, $role, $access, true);
}
}
}

Expand Down Expand Up @@ -3421,6 +3433,22 @@ public function setParentChild($parent, $child, $onlyOneParent = true)
]);
}

/**
* Set permissions for given role
* By default this will not remove old permissions just like all the other
* setXXX methods behave.
* @return void
*/
public function setRolePermissions($role, $permissions, $remove = false)
{
$role = $this->getRole($role);
if ($remove) {
// remove all existing permissions from role
foreach ($role->permissions as $p) $this->removePermissionFromRole($p, $role);
}
foreach ($permissions as $perm) $this->addPermissionToRole($perm, $role);
}

/**
* Set settings of a template's access tab
*
Expand Down

0 comments on commit 890c242

Please sign in to comment.