ChangeSet ID: 30437 CVSROOT: /opt/cvs-commit Module name: appdb Changes by: wineowner@winehq.org 2006/12/08 23:07:25
Modified files: include : application.php maintainer.php unit_test : test_maintainer.php
Log message: Alexander Nicolaysen Sørnes alex@thehandofagony.com Allow the user to tick a checkbox upon application submission, indication whether he would like to become a super maintainer of the application. The request is processed along with the application. Also add a unit test that tests maintainer requests submitted along with an application.
Patch: http://cvs.winehq.org/patch.py?id=30437
Old revision New revision Changes Path 1.78 1.79 +38 -1 appdb/include/application.php 1.20 1.21 +6 -3 appdb/include/maintainer.php 1.2 1.3 +52 -0 appdb/unit_test/test_maintainer.php
Index: appdb/include/application.php diff -u -p appdb/include/application.php:1.78 appdb/include/application.php:1.79 --- appdb/include/application.php:1.78 9 Dec 2006 5: 7:25 -0000 +++ appdb/include/application.php 9 Dec 2006 5: 7:25 -0000 @@ -9,6 +9,7 @@ require_once(BASE."include/category.php" require_once(BASE."include/url.php"); require_once(BASE."include/util.php"); require_once(BASE."include/mail.php"); +require_once(BASE."include/maintainer.php");
define("PLATINUM_RATING", "Platinum"); define("GOLD_RATING", "Gold"); @@ -33,6 +34,8 @@ class Application { var $sSubmitTime; var $iSubmitterId; var $aVersionsIds; // an array that contains the versionId of every version linked to this app. + var $bSuperMaintainerRequest; // Temporary variable used in application submission. + // If the user wants to become a super maintainer for the application
/** * constructor, fetches the data. @@ -128,6 +131,18 @@ class Application { $this->iAppId = mysql_insert_id(); $this->application($this->iAppId); $this->SendNotificationMail(); // Only administrators will be mailed as no supermaintainers exist for this app. + + /* Submit super maintainer request if asked to */ + if($this->bSuperMaintainerRequest) + { + $oMaintainer = new Maintainer(); + $oMaintainer->iAppId = $this->iAppId; + $oMaintainer->iUserId = $_SESSION['current']->iUserId; + $oMaintainer->sMaintainReason = "This user submitted the application; auto-queued."; + $oMaintainer->bSuperMaintainer = 1; + $oMaintainer->create(); + } + return true; } else { @@ -291,6 +306,15 @@ class Application { // we send an e-mail to intersted people $this->mailSubmitter(); $this->SendNotificationMail(); + + /* Unqueue matching super maintainer request */ + $hResultMaint = query_parameters("SELECT maintainerId FROM appMaintainers WHERE userId = '?' AND appId = '?'", $this->iSubmitterId, $this->iAppId); + if($hResultMaint) + { + $oMaintainerRow = mysql_fetch_object($hResultMaint); + $oMaintainer = new Maintainer($oMaintainerRow->maintainerId); + $oMaintainer->unQueue("OK"); + } } }
@@ -336,7 +360,10 @@ class Application { { $aClean = array(); //array of filtered user input
- $aClean['sReplyText'] = makeSafe($_REQUEST['sReplyText']); + if(isset($_REQUEST['sReplyText'])) + $aClean['sReplyText'] = makeSafe($_REQUEST['sReplyText']); + else + $aClean['sReplyText'] = "";
if($this->iSubmitterId) { @@ -517,6 +544,15 @@ class Application {
echo $this->sDescription.'</textarea></p></td></tr>',"\n";
+ // Allow user to apply as super maintainer if this is a new app + if(!$this->iAppId) + { + if($this->bSuperMaintainerRequest) + $sRequestSuperMaintainerChecked = 'checked="checked"'; + echo '<tr valign="top"><td class="color0"><b>Become super maintainer?</b></td>',"\n"; + echo '<td><input type="checkbox" '.$sRequestSuperMaintainerChecked.' name="bSuperMaintainerRequest" /> Check this to request being a super maintainer for the application</td></tr>',"\n"; + } + echo "</table>\n";
echo html_frame_end(); @@ -556,6 +592,7 @@ class Application { $this->iVendorId = $aValues['iAppVendorId']; $this->sWebpage = $aValues['sAppWebpage']; $this->sKeywords = $aValues['sAppKeywords']; + $this->bSuperMaintainerRequest = $aValues['bSuperMaintainerRequest']; }
/* display this application */ Index: appdb/include/maintainer.php diff -u -p appdb/include/maintainer.php:1.20 appdb/include/maintainer.php:1.21 --- appdb/include/maintainer.php:1.20 9 Dec 2006 5: 7:25 -0000 +++ appdb/include/maintainer.php 9 Dec 2006 5: 7:25 -0000 @@ -185,9 +185,11 @@ class maintainer
function ObjectGetEntries($bQueued) { + /* Excluding requests for queued apps, as these will be handled automatically */ if($bQueued) - $sQuery = "SELECT maintainerId FROM appMaintainers, user_list WHERE appMaintainers.userid = user_list.userid ". - "AND queued = '?' ORDER by submitTime"; + $sQuery = "SELECT maintainerId FROM appMaintainers, user_list, appFamily WHERE appMaintainers.userid = user_list.userid ". + "AND appMaintainers.queued = '?' AND appMaintainers.appId = ". + "appFamily.appId AND appFamily.queued = 'false' ORDER by ". "appMaintainers.submitTime"; else $sQuery = "SELECT maintainerId FROM appMaintainers, user_list WHERE appMaintainers.userid = user_list.userid ". "AND queued = '?' ORDER by realname"; @@ -248,7 +250,8 @@ class maintainer
function getQueuedMaintainerCount() { - $sQuery = "SELECT count(*) as queued_maintainers FROM appMaintainers where queued='true'"; + /* Excluding requests for queued apps, as these are handled automatically */ + $sQuery = "SELECT COUNT(*) as queued_maintainers FROM appMaintainers, appFamily WHERE appMaintainers.queued='true' AND appFamily.appId = appMaintainers.appId AND appFamily.queued = 'false'"; $hResult = query_parameters($sQuery); $oRow = mysql_fetch_object($hResult); return $oRow->queued_maintainers; Index: appdb/unit_test/test_maintainer.php diff -u -p appdb/unit_test/test_maintainer.php:1.2 appdb/unit_test/test_maintainer.php:1.3 --- appdb/unit_test/test_maintainer.php:1.2 9 Dec 2006 5: 7:25 -0000 +++ appdb/unit_test/test_maintainer.php 9 Dec 2006 5: 7:25 -0000 @@ -257,6 +257,53 @@ function test_maintainer_unQueue() return true; }
+/* Test whether a super maintainer request submitted along with an application is also accepted when the application is accepted */ +function test_superMaintainerOnAppSubmit() +{ + test_start(__FUNCTION__); + + global $test_email, $test_password; + + /* Log in */ + $oUser = new User(); + if($retval = $oUser->login($test_email, $test_password) != SUCCESS) + { + echo "Received '$retval' instead of SUCCESS('".SUCCESS."')."; + return FALSE; + } + + $iAppId = 655000; + $iVersionId = 655200; + + $oApp = new Application($iAppId); + + /* The user wants to be a super maintainer */ + $oApp->bSuperMaintainerRequest = 1; + + /* Make sure the user is not an admin, so the app will be queued */ + $oUser->delPriv("admin"); + + $oApp->create(); + + /* Make the user an admin so the app can be unqueued */ + $oUser->addPriv("admin"); + + $oApp->unQueue(); + + /* The user should now be a super maintainer */ + $iExpected = 1; + $iGot = Maintainer::getMaintainerCountForUser($oUser, TRUE); + + if($iGot != $iExpected) + { + echo "Got maintainer count of '$iGot' instead of '$iExpected'"; + return false; + } + + Maintainer::deleteMaintainer($oUser, $iAppId); + + return true; +}
if(!test_maintainer_getMaintainerCountForUser()) echo "test_maintainer_getMaintainerCountForUser() failed!\n"; @@ -275,4 +322,9 @@ if(!test_maintainer_unQueue()) else echo "test_maintainer_unQueue() passed\n";
+if(!test_superMaintainerOnAppSubmit()) + echo "test_superMaintainerOnAppSubmit() failed!\n"; +else + echo "test_superMaintainerOnAppSubmit() passed\n"; + ?>