Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Fix #1150: Changing Role name breaks permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
mwhitneysdsu committed Aug 3, 2015
1 parent 6a5d987 commit fcbd33d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
1 change: 1 addition & 0 deletions bonfire/docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#### Closes Issues:
* #1151: [BF_Router] Call to undefined method `_set_404override_controller()`
* #1150: Changing Role name breaks permissions
* #1149: Blog Tutorial defined `$modified_field` without default value.
* #1147: Unique validation fails on existing role.
* #1144: Emailer lang entries missing when sending mail from users module.
Expand Down
5 changes: 3 additions & 2 deletions bonfire/docs/upgrade/076.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
1. Update `/bonfire/core/BF_Router.php`
2. Update `/bonfire/modules/builder/libraries/Modulebuilder.php`
3. Update `/bonfire/modules/emailer/libraries/Emailer.php`
4. Update `/bonfire/modules/roles/views/settings/role_form.php`
5. Update `/bonfire/modules/users/libraries/PasswordHash.php`
4. Update `/bonfire/modules/roles/controllers/Settings.php`
5. Update `/bonfire/modules/roles/views/settings/role_form.php`
6. Update `/bonfire/modules/users/libraries/PasswordHash.php`
30 changes: 12 additions & 18 deletions bonfire/modules/roles/controllers/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ private function saveRole($type = 'insert', $id = 0)
$id = $this->role_model->insert($data);
$return = is_numeric($id);
} elseif ($type == 'update') {
// Grab the name of the role being updated.
$current_name = $this->role_model->find($id)->role_name;
$return = $this->role_model->update($id, $data);
}

Expand All @@ -276,15 +278,13 @@ private function saveRole($type = 'insert', $id = 0)
}

// Add a new management permission for the role.
$new_perm_name = 'Permissions.' . ucwords($roleName) . '.Manage';
$add_perm = array(
'name' => 'Permissions.' . ucwords($roleName) . '.Manage',
'description' => "To manage the access control permissions for the {$roleName} role.",
'status' => 'active'
);

if ($type == 'insert') {
$add_perm = array(
'name' => $new_perm_name,
'description' => "To manage the access control permissions for the {$roleName} role.",
'status' => 'active'
);

$permissionId = $this->permission_model->insert($add_perm);

if (! $permissionId) {
Expand Down Expand Up @@ -314,18 +314,12 @@ private function saveRole($type = 'insert', $id = 0)
$this->form_validation->reset_validation();
$this->role_permission_model->insert_batch($rolePermissions);
}
} else {
// Update
//
// Grab the name of the role being updated.
$current_name = $this->role_model->find($id)->role_name;

} elseif ($type == 'update') {
// Update the permission name.
$this->permission_model->update_where(
'name',
'Permissions.' . ucwords($current_name) . '.Manage',
array('name' => $new_perm_name)
);
$currentPermission = $this->permission_model->find_by('name', 'Permissions.' . ucwords($current_name) . '.Manage');
$permissionKey = $this->permission_model->get_key();
$add_perm['status'] = $currentPermission->status;
$this->permission_model->update($currentPermission->{$permissionKey}, $add_perm);
}

// Reset validation so the role_permissions model can use it.
Expand Down

0 comments on commit fcbd33d

Please sign in to comment.