[evolvis-commits] r18693: [#3259] begin all-about-the-current-user JSON export file

mirabilos at evolvis.org mirabilos at evolvis.org
Thu Oct 4 18:00:00 CEST 2012


Author: mirabilos
Date: 2012-10-04 17:59:59 +0200 (Thu, 04 Oct 2012)
New Revision: 18693

Added:
   trunk/gforge_base/evolvisforge-5.1/src/www/account/jsonact.php
Log:
[#3259] begin all-about-the-current-user JSON export file

for now: user info, all groups (explicit or not template),
all roles in these groups with their home projects listed

Added: trunk/gforge_base/evolvisforge-5.1/src/www/account/jsonact.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/www/account/jsonact.php	                        (rev 0)
+++ trunk/gforge_base/evolvisforge-5.1/src/www/account/jsonact.php	2012-10-04 15:59:59 UTC (rev 18693)
@@ -0,0 +1,166 @@
+<?php
+/*-
+ * JSON export for information about the currently logged-in Forge user
+ *
+ * Copyright © 2012
+ *	Thorsten “mirabilos” Glaser <t.glaser at tarent.de>
+ * All rights reserved.
+ *
+ * This file is part of FusionForge. FusionForge is free software;
+ * you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the Licence, or (at your option)
+ * any later version.
+ *
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *-
+ * Short description of the module or comments or whatever
+ */
+
+require_once('../env.inc.php');
+require_once $gfcommon.'include/pre.php';
+require_once $gfcommon.'include/minijson.php';
+require_once $gfcommon.'pm/ProjectTask.class.php';
+require_once $gfwww.'tracker/include/ArtifactHtml.class.php';
+
+session_require_login();
+if (!session_issecure()) {
+	exit_error(_('Session is not secure'), 'my');
+}
+
+if (!($u =& user_get_object(user_getid())) || !is_object($u)) {
+	exit_error(_('Could Not Get User'), 'my');
+} elseif ($u->isError()) {
+	exit_error($u->getErrorMessage(), 'my');
+}
+
+//        $ah =& artifact_get_object($aid);
+//$pt = projecttask_get_object($tid)))
+
+$i = array(
+	'user_id' => (int)$u->getID(),
+	'user_name' => $u->getUnixName(),
+	'email' => $u->getEmail(),
+	'realname' => $u->getRealName(),
+	'add_date' => (int)$u->getAddDate(),
+	'timezone' => $u->getTimeZone(),
+	'ccode' => $u->getCountryCode(),
+	'shell' => $u->getShell(),
+	'language' => $u->getLanguage(),
+	'language_name' => lang_id_to_language_name($u->getLanguage()),
+	'language_code' => language_name_to_locale_code(lang_id_to_language_name($u->getLanguage())),
+	'_forge-admin' => !!forge_check_global_perm('forge_admin'),
+	'~groups' => array(),
+    );
+
+$roles = $u->getRoles();
+$groups = array();
+$groles = array();
+foreach ($roles as $r) {
+	foreach ($r->getLinkedProjects() as $p) {
+		if (!isset($groups[$p->getID()])) {
+			$groups[$p->getID()] = array($p, 1);
+		}
+		$groles[$p->getID()][$r->getID()] = $r;
+	}
+	if ($r instanceof RoleExplicit &&
+	    ($p = $r->getHomeProject()) != NULL) {
+		$groups[$p->getID()] = array($p, 2);
+		$groles[$p->getID()][$r->getID()] = $r;
+	}
+}
+
+foreach ($groups as $gid => $gtype) {
+	$g = $gtype[0];
+	$j = array('_explicit' => $gtype[1] == 2);
+	if ($g->isTemplate() && !$j['_explicit']) {
+		/* skip implicit template groups */
+		continue;
+	}
+
+	foreach ($g->data_array as $k => $v) {
+		/* skip numeric fields */
+		if (!preg_match('/^[a-z]/', $k)) {
+			continue;
+		}
+
+		/* skip use_* fields */
+		if (preg_match('/^use_/', $k)) {
+			continue;
+		}
+
+		/* distinguish actions for specific fields */
+		switch ($k) {
+		/* skip these */
+		case 'built_from_template':
+		case 'enable_anonscm':
+		case 'enable_pserver':
+		case 'force_docman_reindex':
+		case 'is_public':
+		case 'is_template':
+		case 'license':
+		case 'license_other':
+		case 'new_doc_address':
+		case 'rand_hash':
+		case 'send_all_docs':
+		case 'type_id':
+		/* these are not really used */
+		case 'scm_box':
+		case 'unix_box':
+			break;
+
+		case 'group_name':
+		case 'short_description':
+		case 'register_purpose':
+			/* fix mistake of how stuff is stored in the DB */
+			$v = util_unconvert_htmlspecialchars($v);
+			/* fix issue with how stuff may be stored in the DB */
+			$v = util_sanitise_multiline_submission($v);
+			/* but export using logical newlines */
+			$v = str_replace("\r\n", "\n", $v);
+			/* now we’ve got something we can use */
+			$j[$k] = $v;
+			break;
+
+		case 'register_time':
+			$j[$k] = (int)$v;
+			break;
+
+		default:
+			$j[$k] = $v;
+			break;
+		}
+	}
+	$j['_project-admin'] = !!forge_check_perm('project_admin', $gid);
+	$j['~roles'] = array();
+	foreach ($groles[$gid] as $rid => $r) {
+		$j['~roles'][(int)$rid] = array(
+			'role_id' => (int)$r->getID(),
+			'role_name' => $r->getName(),
+			'home_project_id' => $r->getHomeProject() ?
+			    (int)$r->getHomeProject()->getID() : NULL,
+			'home_project_name' => $r->getHomeProject() ?
+			    $r->getHomeProject()->getPublicName() : NULL,
+		    );
+	}
+	$i['~groups'][(int)$gid] = $j;
+}
+
+if (getIntFromRequest('text')) {
+	$asformat = "text/plain; charset=\"UTF-8\"";
+	$jsonindent = "";
+} else {
+	$asformat = "application/json; charset=\"UTF-8\"";
+	$jsonindent = false;
+}
+
+sysdebug_off("Content-type: " . $asformat);
+echo minijson_encode($i, $jsonindent) . "\n";
+exit;



More information about the evolvis-commits mailing list