diff --git a/admin/adminMaintainerQueue.php b/admin/adminMaintainerQueue.php
index 75f1ee7..cd0919c 100644
--- a/admin/adminMaintainerQueue.php
+++ b/admin/adminMaintainerQueue.php
@@ -113,7 +113,8 @@ if ($aClean['sSub'])
echo '
| This user also maintains these apps: | ',"\n";
$firstDisplay = true;
- $other_apps = getAppsFromUserId($oRow->userId);
+ $oUser = new User($oRow->userId);
+ $other_apps = $oUser->getAppsMaintained();
if($other_apps)
{
while(list($index, list($appIdOther, $versionIdOther, $superMaintainerOther)) = each($other_apps))
diff --git a/include/application.php b/include/application.php
index 6013f81..de8e232 100644
--- a/include/application.php
+++ b/include/application.php
@@ -7,6 +7,7 @@ require_once(BASE."include/version.php");
require_once(BASE."include/vendor.php");
require_once(BASE."include/url.php");
require_once(BASE."include/util.php");
+require_once(BASE."include/mail.php");
/**
* Application class for handling applications.
diff --git a/include/maintainer.php b/include/maintainer.php
index 06345d1..c2c7a70 100644
--- a/include/maintainer.php
+++ b/include/maintainer.php
@@ -3,29 +3,6 @@
/* functions for maintainers */
/*****************************/
-/**
- * get the applications and versions that this userId maintains
- */
-function getAppsFromUserId($userId)
-{
- /* retrieve the list of application and order them by application name */
- $hResult = query_parameters("SELECT appMaintainers.appId, versionId, superMaintainer, appName FROM ".
- "appFamily, appMaintainers WHERE appFamily.appId = appMaintainers.appId ".
- "AND userId = '?' ORDER BY appName", $userId);
- if(!$hResult || mysql_num_rows($hResult) == 0)
- return;
-
- $retval = array();
- $c = 0;
- while($oRow = mysql_fetch_object($hResult))
- {
- $retval[$c] = array($oRow->appId, $oRow->versionId, $oRow->superMaintainer);
- $c++;
- }
-
- return $retval;
-}
-
/*
* get the userIds of maintainers for a versionId
*/
diff --git a/include/sidebar_login.php b/include/sidebar_login.php
index 0987a23..9fbb456 100644
--- a/include/sidebar_login.php
+++ b/include/sidebar_login.php
@@ -19,7 +19,7 @@ function global_sidebar_login() {
/* if this user maintains any applications list them */
/* in their sidebar */
- $apps_user_maintains = getAppsFromUserId($_SESSION['current']->iUserId);
+ $apps_user_maintains = $_SESSION['current']->getAppsMaintained();
if($apps_user_maintains)
{
$g->addmisc("");
diff --git a/include/user.php b/include/user.php
index 4329985..e8367aa 100644
--- a/include/user.php
+++ b/include/user.php
@@ -296,6 +296,29 @@ class User {
return mysql_num_rows($hResult);
}
+ /**
+ * get the applications and versions that this user maintains
+ */
+ function getAppsMaintained()
+ {
+ /* retrieve the list of application and order them by application name */
+ $hResult = query_parameters("SELECT appMaintainers.appId, versionId, superMaintainer, appName FROM ".
+ "appFamily, appMaintainers WHERE appFamily.appId = appMaintainers.appId ".
+ "AND userId = '?' ORDER BY appName", $this->iUserId);
+ if(!$hResult || mysql_num_rows($hResult) == 0)
+ return NULL;
+
+ $aAppsMaintained = array();
+ $c = 0;
+ while($oRow = mysql_fetch_object($hResult))
+ {
+ $aAppsMaintained[$c] = array($oRow->appId, $oRow->versionId, $oRow->superMaintainer);
+ $c++;
+ }
+
+ return $aAppsMaintained;
+ }
+
function getMaintainerCount($bSuperMaintainer)
{
if(!$this->isLoggedIn()) return 0;
diff --git a/unit_test/test_user.php b/unit_test/test_user.php
index a6b96d2..0d7b576 100644
--- a/unit_test/test_user.php
+++ b/unit_test/test_user.php
@@ -353,6 +353,83 @@ function test_user_getMaintainerCount()
return true;
}
+function test_user_getAppsMaintained()
+{
+ test_start(__FUNCTION__);
+
+ global $test_email, $test_password;
+
+ /* login the user */
+ $oUser = new User();
+ $retval = $oUser->login($test_email, $test_password);
+ if($retval != SUCCESS)
+ {
+ echo "Got '".$retval."' instead of SUCCESS(".SUCCESS.")\n";
+ return false;
+ }
+
+ /* make this user an admin so we can create applications without having them queued */
+ $hResult = query_parameters("INSERT into user_privs values ('?', '?')",
+ $oUser->iUserId, "admin");
+
+ /* create a application so we have a valid appFamily for the call to user::getAppsMaintained() */
+ $oApp = new Application();
+ $oApp->sName = "Some application";
+ $oApp->sDescription = "some description";
+ $oApp->submitterId = $oUser->iUserId;
+ if(!$oApp->create())
+ {
+ echo "Failed to create application!\n";
+ return false;
+ }
+
+ /**
+ * make the user a super maintatiner
+ */
+ $iAppId = $oApp->iAppId; /* use the iAppId of the application we just created */
+ $iVersionId = 655200;
+ $iQueueId = 655300;
+ $bSuperMaintainer = TRUE;
+ $statusMessage = $oUser->addAsMaintainer($iAppId, $iVersionId, $bSuperMaintainer, $iQueueId);
+
+ /* get an array of the apps maintained */
+ $aAppsMaintained = $oUser->getAppsMaintained();
+
+ if(!$aAppsMaintained)
+ {
+ echo "aAppsMaintained is null, we expected a non-null return value!\n";
+ return false;
+ }
+
+ /* get only the first entry from the array of applications maintained */
+ /* we only added the user as a maintainer of a single application */
+ list($iAppId1, $iVersionId1, $bSuperMaintainer1) = $aAppsMaintained[0];
+
+ /* make sure all parameters match what we added as maintainer information */
+ if($iAppId1 != $iAppId)
+ {
+ echo "Expected iAppid of ".$iAppId." but got ".$iAppId1."\n";
+ return false;
+ }
+
+ if($iVersionId1 != $iVersionId)
+ {
+ echo "Expected iVersionId of ".$iVersionId." but got ".$iVersionId1."\n";
+ return false;
+ }
+
+ if($bSuperMaintainer1 != $bSuperMaintainer)
+ {
+ echo "Expected bSuperMaintainer of ".$bSuperMaintainer." but got ".$bSuperMaintainer1."\n";
+ return false;
+ }
+
+ /* remove maintainership for this user */
+ $oUser->deleteMaintainer($iAppId);
+
+ return true;
+}
+
/*************************/
/* Main testing routines */
@@ -392,6 +469,11 @@ if(!test_user_getMaintainerCount())
else
echo "test_user_getMaintainerCount() passed\n";
+if(!test_user_getAppsMaintained())
+ echo "test_user_getAppsMaintained() failed!\n";
+else
+ echo "test_user_getAppsMaintained() passed\n";
+
/* TODO: the rest of the user member functions we don't currently test */