Created
October 28, 2013 19:20
-
-
Save mjrider/7202903 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit e97ef4947f56deab4cfcec839b64644c2857e53d | |
Author: Robbert Müller <muller@muze.nl> | |
Date: Mon Oct 28 20:11:31 2013 +0100 | |
Rework import user and group grants now also use auth config to find the user and groups | |
diff --git a/lib/templates/pgroup/system.import.groupgrants.phtml b/lib/templates/pgroup/system.import.groupgrants.phtml | |
deleted file mode 100644 | |
index cb9292d..0000000 | |
--- a/lib/templates/pgroup/system.import.groupgrants.phtml | |
+++ /dev/null | |
@@ -1,26 +0,0 @@ | |
-<?php | |
- if ($this->CheckLogin("config") && $this->CheckConfig()) { | |
- display("importing grants for group ".$this->data->login."\n"); | |
- $paths=$ARCurrent->grants_list["pgroup"][$this->data->login]; | |
- while (list($path, $grants)=each($paths)) { | |
- $newpath=$importDestPath.substr($path, strlen($importRootPath)); | |
- display(" $newpath\n"); | |
- | |
- $result=current($this->get($newpath, "system.import.grants.phtml", | |
- Array( | |
- "importDestPath" => $importDestPath, | |
- "importRootPath" => $importRootPath, | |
- "grants" => &$grants, | |
- "type" => "pgroup" , | |
- "id" => $this->data->login | |
- ))); | |
- if ($result) { | |
- @reset($grants); | |
- while (list($grant, $value)=each($grants)) { | |
- $this->data->config->usergrants[$newpath][$grant]=$value; | |
- } | |
- } | |
- } | |
- $this->save(); | |
- } | |
-?> | |
\ No newline at end of file | |
diff --git a/lib/templates/pobject/system.export.phtml b/lib/templates/pobject/system.export.phtml | |
index ee87050..d6e0166 100644 | |
--- a/lib/templates/pobject/system.export.phtml | |
+++ b/lib/templates/pobject/system.export.phtml | |
@@ -300,20 +300,56 @@ | |
$offset+=$stepsize; | |
} | |
if (!$ARCurrent->options["without_grants"]) { | |
+ // reset config | |
+ $destobj = current($ARCurrent->importStore->call("system.get.phtml", $arguments, | |
+ $ARCurrent->importStore->get($destpath))); | |
+ $destobj->resetConfig(); | |
+ | |
+ $userConfig = $destobj->loadUserConfig(); | |
+ $authconfig = $userConfig['authentication']; | |
+ | |
display("updating grants (groups)\n"); | |
@reset($ARCurrent->grants_list); | |
while (list($type, $type_logins)=@each($ARCurrent->grants_list)) { | |
- while (list($login, )=each($type_logins)) { | |
+ while (list($login, $paths)=each($type_logins)) { | |
if ($type=="pgroup") { | |
- unset($criteria); | |
- $criteria["login"]["value"]["="]="'$login'"; | |
- $criteria["object"]["type"]["="]="'pgroup'"; | |
- $arguments = $arCallArgs; | |
- $arguments["importDestPath"] = $destpath; | |
- $arguments["importRootPath"] = $rootpath; | |
- $ARCurrent->importStore->call("system.import.groupgrants.phtml", | |
- $arguments, | |
- $ARCurrent->importStore->find("/system/groups/", $criteria)); | |
+ foreach ( $paths as $path => $grants ) { | |
+ $newpath=$destpath.substr($path, strlen($rootpath)); | |
+ $dataobj = current($ARCurrent->importStore->call("system.get.phtml", array(), | |
+ $ARCurrent->importStore->get($newpath))); | |
+ $dataobj->resetConfig(); | |
+ | |
+ $userConfig = $dataobj->loadUserConfig(); | |
+ $authconfig = $userConfig['authentication']; | |
+ unset($user); | |
+ unset($criteria); | |
+ $criteria["login"]["value"]["="]="'$login'"; | |
+ $criteria["object"]["type"]["="]="'pgroup'"; | |
+ foreach ($authconfig['groupdirs'] as $groupdirpath) { | |
+ $result=$destobj->find($groupdirpath,$criteria,"system.get.phtml"); | |
+ if (count($result)) { | |
+ $group = current($result); | |
+ break; | |
+ } | |
+ } | |
+ if( ! is_null($group) ) { | |
+ display(" $newpath\n"); | |
+ $result=current($group->get($newpath, "system.import.grants.phtml", | |
+ Array( | |
+ "importDestPath" => $destpath, | |
+ "importRootPath" => $rootpath, | |
+ "grants" => &$grants, | |
+ "type" => "pgroup" , | |
+ "id" => $group->data->login | |
+ ))); | |
+ if ($result) { | |
+ foreach( $grants as $grant => $grantValue) { | |
+ $this->data->config->usergrants[$newpath][$grant]=$grantValue; | |
+ } | |
+ } | |
+ $group->save(); | |
+ } | |
+ } | |
} | |
} | |
} | |
@@ -321,16 +357,44 @@ | |
display("updating grants (users)\n"); | |
@reset($ARCurrent->grants_list); | |
while (list($type, $type_logins)=@each($ARCurrent->grants_list)) { | |
- while (list($login, )=each($type_logins)) { | |
+ while (list($login, $paths )=each($type_logins)) { | |
if ($type=="puser") { | |
- unset($criteria); | |
- $criteria["login"]["value"]["="]="'$login'"; | |
- $criteria["object"]["type"]["="]="'puser'"; | |
- $arguments = $arCallArgs; | |
- $arguments["importDestPath"] = $destpath; | |
- $arguments["importRootPath"] = $rootpath; | |
- $ARCurrent->importStore->call("system.import.usergrants.phtml", $arguments, | |
- $ARCurrent->importStore->find("/system/users/", $criteria)); | |
+ foreach ( $paths as $path => $grants ) { | |
+ $newpath=$destpath.substr($path, strlen($rootpath)); | |
+ $dataobj = current($ARCurrent->importStore->call("system.get.phtml", array(), | |
+ $ARCurrent->importStore->get($newpath))); | |
+ $dataobj->resetConfig(); | |
+ | |
+ $userConfig = $dataobj->loadUserConfig(); | |
+ $authconfig = $userConfig['authentication']; | |
+ unset($crit); | |
+ unset($user); | |
+ $crit["login"]["value"]["="]="'".AddSlashes($login)."'"; | |
+ foreach ($authconfig['userdirs'] as $userdirpath) { | |
+ $result=$destobj->find($userdirpath,$crit,"system.get.phtml"); | |
+ if (count($result)) { | |
+ $user = current($result); | |
+ break; | |
+ } | |
+ } | |
+ if( ! is_null($user) ) { | |
+ display(" $newpath\n"); | |
+ $result=current($user->get($newpath, "system.import.grants.phtml", | |
+ Array( | |
+ "importDestPath" => $destpath, | |
+ "importRootPath" => $rootpath, | |
+ "grants" => &$grants, | |
+ "type" => "puser" , | |
+ "id" => $user->data->login | |
+ ))); | |
+ if ($result) { | |
+ foreach( $grants as $grant => $grantValue) { | |
+ $this->data->config->usergrants[$newpath][$grant]=$grantValue; | |
+ } | |
+ } | |
+ $user->save(); | |
+ } | |
+ } | |
} | |
} | |
} | |
diff --git a/lib/templates/puser/system.import.usergrants.phtml b/lib/templates/puser/system.import.usergrants.phtml | |
deleted file mode 100644 | |
index ad7c709..0000000 | |
--- a/lib/templates/puser/system.import.usergrants.phtml | |
+++ /dev/null | |
@@ -1,26 +0,0 @@ | |
-<?php | |
- if ($this->CheckLogin("config") && $this->CheckConfig()) { | |
- display("importing grants for user ".$this->data->login."\n"); | |
- $paths=$ARCurrent->grants_list["puser"][$this->data->login]; | |
- while (list($path, $grants)=each($paths)) { | |
- $newpath=$importDestPath.substr($path, strlen($importRootPath)); | |
- display(" $newpath\n"); | |
- | |
- $result=current($this->get($newpath, "system.import.grants.phtml", | |
- Array( | |
- "importDestPath" => $importDestPath, | |
- "importRootPath" => $importRootPath, | |
- "grants" => &$grants, | |
- "type" => "puser" , | |
- "id" => $this->data->login | |
- ))); | |
- if ($result) { | |
- @reset($grants); | |
- while (list($grant, $value)=each($grants)) { | |
- $this->data->config->usergrants[$newpath][$grant]=$value; | |
- } | |
- } | |
- } | |
- $this->save(); | |
- } | |
-?> | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment