Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Make sure we don't have false positive for old user migrations, other…
Browse files Browse the repository at this point in the history
…wise it can end up overriding the role
  • Loading branch information
cdujeu committed Nov 14, 2013
1 parent e380e20 commit 8ec38d1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
8 changes: 5 additions & 3 deletions core/src/plugins/conf.serial/class.AJXP_SerialUser.php
Expand Up @@ -158,9 +158,11 @@ public function load()
$this->roles["AJXP_USR_"."/".$this->id] = $personalRole;
} else {
// MIGRATE NOW !
$this->migrateRightsToPersonalRole();
AJXP_Utils::saveSerialFile($this->getStoragePath()."/role.ser", $this->personalRole, true);
AJXP_Utils::saveSerialFile($this->getStoragePath()."/rights.ser", $this->rights, true);
$changes = $this->migrateRightsToPersonalRole();
if ($changes) {
AJXP_Utils::saveSerialFile($this->getStoragePath()."/role.ser", $this->personalRole, true);
AJXP_Utils::saveSerialFile($this->getStoragePath()."/rights.ser", $this->rights, true);
}
}

$this->recomputeMergedRole();
Expand Down
20 changes: 13 additions & 7 deletions core/src/plugins/conf.sql/class.AJXP_SqlUser.php
Expand Up @@ -427,15 +427,21 @@ public function load()
} else {
// MIGRATE NOW !
$originalRights = $this->rights;
$this->migrateRightsToPersonalRole();
$removedRights = array_keys(array_diff($originalRights, $this->rights));
$this->roles["AJXP_USR_"."/".$this->id] = $this->personalRole;
$changes = $this->migrateRightsToPersonalRole();
// SAVE RIGHT AND ROLE
if (count($removedRights)) {
// We use (%s) instead of %in to pass everyting as string ('1' instead of 1)
dibi::query("DELETE FROM [ajxp_user_rights] WHERE [login] = %s AND [repo_uuid] IN (%s)", $this->getId(), $removedRights);
if ($changes > 0) {
// There was an actual migration, let's save the changes now.
$removedRights = array_keys(array_diff($originalRights, $this->rights));
if (count($removedRights)) {
// We use (%s) instead of %in to pass everything as string ('1' instead of 1)
dibi::query("DELETE FROM [ajxp_user_rights] WHERE [login] = %s AND [repo_uuid] IN (%s)", $this->getId(), $removedRights);
}
AuthService::updateRole($this->personalRole);
} else {
$this->personalRole = new AJXP_Role("AJXP_USR_"."/".$this->id);
}
AuthService::updateRole($this->personalRole);
$this->roles["AJXP_USR_"."/".$this->id] = $this->personalRole;

}
$this->recomputeMergedRole();
}
Expand Down
5 changes: 4 additions & 1 deletion core/src/plugins/core.conf/class.AbstractAjxpUser.php
Expand Up @@ -413,19 +413,22 @@ public function recomputeMergedRole()

protected function migrateRightsToPersonalRole()
{
$changes = 0;
$this->personalRole = new AJXP_Role("AJXP_USR_"."/".$this->id);
$this->roles["AJXP_USR_"."/".$this->id] = $this->personalRole;
foreach ($this->rights as $rightKey => $rightValue) {
if ($rightKey == "ajxp.actions" && is_array($rightValue)) {
foreach ($rightValue as $repoId => $repoData) {
foreach ($repoData as $actionName => $actionState) {
$this->personalRole->setActionState("plugin.all", $actionName, $repoId, $actionState);
$changes++;
}
}
unset($this->rights[$rightKey]);
}
if(strpos($rightKey, "ajxp.") === 0) continue;
$this->personalRole->setAcl($rightKey, $rightValue);
$changes++;
unset($this->rights[$rightKey]);
}
// Move old CUSTOM_DATA values to personal role parameter
Expand All @@ -451,7 +454,7 @@ protected function migrateRightsToPersonalRole()
}
}
}

return $changes;
}

protected function orderRoles($r1, $r2)
Expand Down

0 comments on commit 8ec38d1

Please sign in to comment.