Permalink
Browse files

Add dedicated serializers for user and repository.

  • Loading branch information...
1 parent 27155e1 commit 644c542f6c4ea97c59de647274002e62a219188f @cdujeu cdujeu committed Jun 20, 2016
@@ -26,6 +26,7 @@
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Model\RepositoryInterface;
use Pydio\Core\Model\UserInterface;
+use Pydio\Core\Serializer\RepositoryXML;
use Pydio\Core\Services\LocaleService;
use Pydio\Core\Services\UsersService;
use Pydio\Core\Utils\Utils;
@@ -500,214 +501,7 @@ public static function sendMessage($logMessage, $errorMessage, $print = true)
}
return XMLWriter::write("<message type=\"$messageType\">".$message."</message>", $print);
}
-
- /**
- * Extract all the user data and put it in XML
- * @static
- * @param ContextInterface $ctx
- * @param AbstractAjxpUser|null $userObject
- * @return string
- */
- public static function getUserXML(ContextInterface $ctx, $userObject = null)
- {
- $buffer = "";
- $loggedUser = $ctx->getUser();
- $currentRepoId = $ctx->getRepositoryId();
- $confDriver = ConfService::getConfStorageImpl();
- if($userObject != null) $loggedUser = $userObject;
- if (!UsersService::usersEnabled()) {
- $buffer.="<user id=\"shared\">";
- $buffer.="<active_repo id=\"".$currentRepoId."\" write=\"1\" read=\"1\"/>";
- $buffer.= XMLWriter::writeRepositoriesData($ctx);
- $buffer.="</user>";
- } else if ($loggedUser != null) {
- $lock = $loggedUser->getLock();
- $buffer.="<user id=\"".$loggedUser->id."\">";
- $buffer.="<active_repo id=\"".$currentRepoId."\" write=\"".($loggedUser->canWrite($currentRepoId)?"1":"0")."\" read=\"".($loggedUser->canRead($currentRepoId)?"1":"0")."\"/>";
- $buffer.= XMLWriter::writeRepositoriesData($ctx);
- $buffer.="<preferences>";
- $preferences = $confDriver->getExposedPreferences($loggedUser);
- foreach ($preferences as $prefName => $prefData) {
- $atts = "";
- if (isSet($prefData["exposed"]) && $prefData["exposed"] == true) {
- foreach ($prefData as $k => $v) {
- if($k=="name") continue;
- if($k == "value") $k = "default";
- $atts .= "$k='$v' ";
- }
- }
- if (isset($prefData["pluginId"])) {
- $atts .= "pluginId='".$prefData["pluginId"]."' ";
- }
- if ($prefData["type"] == "string") {
- $buffer.="<pref name=\"$prefName\" value=\"".$prefData["value"]."\" $atts/>";
- } else if ($prefData["type"] == "json") {
- $buffer.="<pref name=\"$prefName\" $atts><![CDATA[".$prefData["value"]."]]></pref>";
- }
- }
- $buffer.="</preferences>";
- $buffer.="<special_rights is_admin=\"".($loggedUser->isAdmin()?"1":"0")."\" ".($lock!==false?"lock=\"$lock\"":"")."/>";
- /*
- $bMarks = $loggedUser->getBookmarks();
- if (count($bMarks)) {
- $buffer.= "<bookmarks>".AJXP_XMLWriter::writeBookmarks($bMarks, false)."</bookmarks>";
- }
- */
- $buffer.="</user>";
- }
- return $buffer;
- }
-
- /**
- * Write the repositories access rights in XML format
- * @static
- * @param ContextInterface $ctx
- * @return string
- */
- public static function writeRepositoriesData(ContextInterface $ctx)
- {
- $loggedUser = $ctx->getUser();
- $accessible = UsersService::getRepositoriesForUser($loggedUser);
- $streams = PluginsService::detectRepositoriesStreams($accessible);
-
- $st = "<repositories>";
-
- $exposed = PluginsService::searchManifestsWithCache("//server_settings/param[contains(@scope,'repository') and @expose='true']", function($nodes){
- $exposedNodes = [];
- foreach($nodes as $exposed_prop){
- $pluginId = $exposed_prop->parentNode->parentNode->getAttribute("id");
- $paramName = $exposed_prop->getAttribute("name");
- $paramDefault = $exposed_prop->getAttribute("default");
- $exposedNodes[] = array("PLUGIN_ID" => $pluginId, "NAME" => $paramName, "DEFAULT" => $paramDefault);
- }
- return $exposedNodes;
- });
-
- $inboxStatus = 0;
- foreach($accessible as $repoId => $repoObject){
- if(!$repoObject->hasContentFilter()) {
- continue;
- }
- $accessStatus = $repoObject->getAccessStatus();
- if(empty($accessStatus) && $loggedUser != null){
- $lastConnected = $loggedUser->getArrayPref("repository_last_connected", $repoId);
- if(empty($lastConnected)){
- $accessStatus = 1;
- }
- }
- if(!empty($accessStatus)){
- $inboxStatus ++;
- }
- }
-
- foreach ($accessible as $repoId => $repoObject) {
- if(!isSet($_SESSION["CURRENT_MINISITE"]) && $repoObject->hasContentFilter()){
- continue;
- }
- $accessStatus = '';
- if($repoObject->getAccessType() == "inbox"){
- $accessStatus = $inboxStatus;
- }
- $xmlString = self::repositoryToXML($repoId, $repoObject, $exposed, $streams, $loggedUser, $accessStatus);
- $st .= $xmlString;
- }
-
- $st .= "</repositories>";
- return $st;
- }
-
- /**
- * @param string $repoId
- * @param RepositoryInterface $repoObject
- * @param array $exposed
- * @param array $streams
- * @param UserInterface $loggedUser
- * @param string $accessStatus
- * @return string
- * @throws \Exception
- */
- public static function repositoryToXML($repoId, $repoObject, $exposed, $streams, $loggedUser, $accessStatus = ""){
-
-
- $statusString = " repository_type=\"".$repoObject->getRepositoryType()."\"";
- if(empty($accessStatus)){
- $accessStatus = $repoObject->getAccessStatus();
- }
- if(!empty($accessStatus)){
- $statusString .= " access_status=\"$accessStatus\" ";
- }else if($loggedUser != null){
- $lastConnected = $loggedUser->getArrayPref("repository_last_connected", $repoId);
- if(!empty($lastConnected)) $statusString .= " last_connection=\"$lastConnected\" ";
- }
-
- $streamString = "";
- if (in_array($repoObject->getAccessType(), $streams)) {
- $streamString = "allowCrossRepositoryCopy=\"true\"";
- }
- if ($repoObject->getUniqueUser()) {
- $streamString .= " user_editable_repository=\"true\" ";
- }
- if ($repoObject->hasContentFilter()){
- $streamString .= " hasContentFilter=\"true\"";
- }
- $slugString = "";
- $slug = $repoObject->getSlug();
- if (!empty($slug)) {
- $slugString = "repositorySlug=\"$slug\"";
- }
- $isSharedString = "";
- $currentUserIsOwner = false;
- $ownerLabel = null;
- if ($repoObject->hasOwner()) {
- $uId = $repoObject->getOwner();
- if($loggedUser != null && $loggedUser->getId() == $uId){
- $currentUserIsOwner = true;
- }
- $label = UsersService::getUserPersonalParameter("USER_DISPLAY_NAME", $uId, "core.conf", $uId);
- $ownerLabel = $label;
- $isSharedString = 'owner="'.Utils::xmlEntities($label).'"';
- }
- if ($repoObject->securityScope() == "USER" || $currentUserIsOwner){
- $streamString .= " userScope=\"true\"";
- }
-
- $descTag = "";
- $public = false;
- if(!empty($_SESSION["CURRENT_MINISITE"])) $public = true;
- $description = $repoObject->getDescription($public, $ownerLabel);
- if (!empty($description)) {
- $descTag = '<description>'.Utils::xmlEntities($description, true).'</description>';
- }
- $ctx = Context::contextWithObjects($loggedUser, $repoObject);
- $roleString="";
- if($loggedUser != null){
- $merged = $loggedUser->getMergedRole();
- $params = array();
- foreach($exposed as $exposed_prop){
- $metaOptions = $repoObject->getContextOption($ctx, "META_SOURCES");
- if(!isSet($metaOptions[$exposed_prop["PLUGIN_ID"]])){
- continue;
- }
- $value = $exposed_prop["DEFAULT"];
- if(isSet($metaOptions[$exposed_prop["PLUGIN_ID"]][$exposed_prop["NAME"]])){
- $value = $metaOptions[$exposed_prop["PLUGIN_ID"]][$exposed_prop["NAME"]];
- }
- $value = $merged->filterParameterValue($exposed_prop["PLUGIN_ID"], $exposed_prop["NAME"], $repoId, $value);
- if($value !== null){
- if($value === true || $value === false) $value = ($value === true ?"true":"false");
- $params[] = '<repository_plugin_param plugin_id="'.$exposed_prop["PLUGIN_ID"].'" name="'.$exposed_prop["NAME"].'" value="'.Utils::xmlEntities($value).'"/>';
- $roleString .= str_replace(".", "_",$exposed_prop["PLUGIN_ID"])."_".$exposed_prop["NAME"].'="'.Utils::xmlEntities($value).'" ';
- }
- }
- $roleString.='acl="'.$merged->getAcl($repoId).'"';
- if($merged->hasMask($repoId)){
- $roleString.= ' hasMask="true" ';
- }
- }
- return "<repo access_type=\"".$repoObject->getAccessType()."\" id=\"".$repoId."\"$statusString $streamString $slugString $isSharedString $roleString><label>".TextEncoder::toUTF8(Utils::xmlEntities($repoObject->getDisplay()))."</label>".$descTag.$repoObject->getClientSettings($ctx)."</repo>";
-
- }
-
+
/**
* Create plain PHP associative array from XML.
*
@@ -110,13 +110,6 @@ public function getSlug();
public function setSlug($slug = null);
/**
- * Get the <client_settings> content of the manifest.xml
- * @param ContextInterface $ctx
- * @return \DOMElement|\DOMNodeList|string
- */
- public function getClientSettings(ContextInterface $ctx);
-
- /**
* Add options
* @param $oName
* @param $oValue
@@ -226,6 +219,11 @@ public function getOwner();
public function getParentId();
/**
+ * @return null|RepositoryInterface
+ */
+ public function getParentRepository();
+
+ /**
* @return string|null
*/
public function getUniqueUser();
@@ -241,6 +239,11 @@ public function hasOwner();
public function hasParent();
/**
+ * @return bool
+ */
+ public function isTemplate();
+
+ /**
* @param $bool
*/
public function setInferOptionsFromParent($bool);
Oops, something went wrong.

0 comments on commit 644c542

Please sign in to comment.