You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vcl.apache.org by jf...@apache.org on 2014/10/02 21:39:21 UTC

svn commit: r1629055 - in /vcl/trunk/web: .ht-inc/requests.php .ht-inc/utils.php .ht-inc/xmlrpcWrappers.php js/requests.js

Author: jfthomps
Date: Thu Oct  2 19:39:21 2014
New Revision: 1629055

URL: http://svn.apache.org/r1629055
Log:
VCL-178 - enable checkuser flag for per reservation instead of image only

used method of having a special user group named "Allow No User Check" to determine who gets to see the checkbox that disables timeouts for disconnected users

requests.php:
-modified newReservationHTML and AJeditRequest: added $nousercheck and related HTML content
-modified AJnewRequest: added checkuser argument when calling addRequest
-modified AJsubmitEditRequest: handle newnousercheck; reworked how updates are done for serverrequest and request tables
-modified AJconfirmDeleteRequestProduction: changed preg_replace wrap character count from 60 to 48
-modified processRequestInput: added nousercheck


utils.php:
-modified addRequest: added $checkuser as argument and insert to request table
-modified getRequestInfo: added checkuser to returned data

xmlrpcWrappers.php: modified XMLRPCaddRequest and XMLRPCaddRequestWithEnding: added $nousercheck argument

requests.js:
-modified resetNewResDlg: added reset for nousercheck
-modified selectResType: hide/unhide nousercheckspan at proper times
-modified getDeployData and submitEditReservation: added nousercheck to submitted data
-modified hideEditResDlg: destroy newnousercheck

Modified:
    vcl/trunk/web/.ht-inc/requests.php
    vcl/trunk/web/.ht-inc/utils.php
    vcl/trunk/web/.ht-inc/xmlrpcWrappers.php
    vcl/trunk/web/js/requests.js

Modified: vcl/trunk/web/.ht-inc/requests.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/requests.php?rev=1629055&r1=1629054&r2=1629055&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/requests.php (original)
+++ vcl/trunk/web/.ht-inc/requests.php Thu Oct  2 19:39:21 2014
@@ -1241,6 +1241,7 @@ function newReservationHTML() {
 	}
 
 	uasort($images, "sortKeepIndex");
+
 	$groupid = getUserGroupID('Specify End Time', 1);
 	$members = getUserGroupMembers($groupid);
 	if(array_key_exists($user['id'], $members))
@@ -1248,10 +1249,18 @@ function newReservationHTML() {
 	else
 		$openend = 0;
 
+	$groupid = getUserGroupID('Allow No User Check', 1);
+	$members = getUserGroupMembers($groupid);
+	if(array_key_exists($user['id'], $members))
+		$nousercheck = 1;
+	else
+		$nousercheck = 0;
+
 	$cdata = array('baseaccess' => $baseaccess,
 	               'imagingaccess' => $imagingaccess,
 	               'serveraccess' => $serveraccess,
 	               'openend' => $openend,
+	               'nousercheck' => $nousercheck,
 	               'imaging' => $forimaging);
 	$debug = processInputVar('debug', ARG_NUMERIC, 0);
 	if($debug && checkUserHasPerm('View Debug Information'))
@@ -1515,11 +1524,19 @@ function newReservationHTML() {
 	$h .= "dojoType=\"dijit.form.ValidationTextBox\" ";
 	$h .= "regExp=\"($regip4)(,$regip4){0,2}\" disabled></span><br>\n";
 	$h .= "</div>\n"; # nrfixedipdiv
-	$h .= "<br>";
+	$h .= "<br><br>";
 	$h .= "</div>\n"; # nrfixedipdiv2
 
 	$h .= "</div>\n"; # newreslabelfields
 
+	$h .= "<span id=\"nousercheckspan\"";
+	if(! $nousercheck)
+		$h .= " class=\"hidden\"";
+	$h .= ">\n";
+	if($nousercheck)
+		$h .= labeledFormItem('nousercheck', 'Disable timeout for disconnected users', 'check', '', '', '1');
+	$h .= "<br></span>";
+
 	$h .= "<span id=\"whentitlebasic\">";
 	$h .= _("When would you like to use the environment?");
 	$h .= "</span>\n";
@@ -1906,7 +1923,7 @@ function printImageDescription($imageid)
 		$desc = preg_replace("/(.{1,60}([ \n]|$))/", '\1<br>', $desc);
 		print "dojo.byId('imgdesc').innerHTML = '<strong>";
 		print _("Image Description") . "</strong>:<br>";
-		print "$desc<br><br>'; ";
+		print "$desc<br>'; ";
 	}
 }
 
@@ -2213,7 +2230,7 @@ function AJnewRequest() {
 		sendJSON($data);
 		return;
 	}
-	$requestid = addRequest($imaging, $data['revisionids']);
+	$requestid = addRequest($imaging, $data['revisionids'], (1 - $data['nousercheck']));
 	if($data['type'] == 'server') {
 		if($data['ipaddr'] != '') {
 			# save additional network info in variable table
@@ -2933,6 +2950,12 @@ function AJeditRequest() {
 		$openend = 1;
 	else
 		$openend = 0;
+	$groupid = getUserGroupID('Allow No User Check', 1);
+	$members = getUserGroupMembers($groupid);
+	if(array_key_exists($user['id'], $members))
+		$nousercheck = 1;
+	else
+		$nousercheck = 0;
 	$h = '';
 
 	# determine the current total length of the reservation
@@ -2942,8 +2965,10 @@ function AJeditRequest() {
 		$reslen -= 15;
 	$cdata = array('requestid' => $requestid,
 	               'openend' => $openend,
+	               'nousercheck' => $nousercheck,
 	               'modifystart' => 0,
 	               'allowindefiniteend' => 0);
+	# generate HTML
 	if($request['serverrequest']) {
 		if(empty($request['servername']))
 			$request['servername'] = $request['reservations'][0]['prettyimage'];
@@ -3000,6 +3025,13 @@ function AJeditRequest() {
 		}
 		$h .= "</select><br><br>";
 	}
+	elseif($nousercheck) {
+		$extra = array();
+		if($request['checkuser'] == 0)
+			$extra['checked'] = 'checked';
+		$h .= labeledFormItem('newnousercheck', 'Disable timeout for disconnected users', 'check', '', '', '1', '', '', $extra);
+		$h .= "<br>\n";
+	}
 	// if future, allow start to be modified
 	if($unixstart > $now) {
 		$cdata['modifystart'] = 1;
@@ -3149,7 +3181,7 @@ function AJeditRequest() {
 	else
 		$maxcheck = $maxtimes['total'];
 	if(! $openend && ($reslen >= $maxcheck)) {
-		$h .= _("You are only allowed to extend your reservation such that it ");
+		$h  = _("You are only allowed to extend your reservation such that it ");
 		$h .= _("has a total length of ") . minToHourMin($maxcheck);
 		$h .= _(". This reservation<br>already meets that length. Therefore, ");
 		$h .= _("you are not allowed to extend your reservation any further.<br><br>");
@@ -3187,7 +3219,7 @@ function AJeditRequest() {
 		cleanSemaphore();
 		if(! $request['serverrequest'] && (! $movedall || ! $lockedall)) {
 			$msg = _("The computer you are using has another reservation immediately following yours. Therefore, you cannot extend your reservation because it would overlap with the next one.<br>");
-			$h .= preg_replace("/(.{1,60}( |$))/", '\1<br>', $msg);
+			$h  = preg_replace("/(.{1,60}( |$))/", '\1<br>', $msg);
 			sendJSON(array('status' => 'nomodify', 'html' => $h));
 			return;
 		}
@@ -3368,6 +3400,7 @@ function AJsubmitEditRequest() {
 	global $user;
 	$requestid = getContinuationVar('requestid');
 	$openend = getContinuationVar('openend');
+	$allownousercheck = getContinuationVar('nousercheck');
 	$modifystart = getContinuationVar('modifystart');
 	$startdays = getContinuationVar('startdays');
 	$lengths = getContinuationVar('lengths');
@@ -3605,27 +3638,43 @@ function AJsubmitEditRequest() {
 	}
 	elseif($rc > 0) {
 		updateRequest($requestid);
+		$serversets = array();
+		$reqsets = array();
 		if($updategroups && $request['laststateid'] != 24) {
 			if($admingroupid == 0)
 				$admingroupid = 'NULL';
 			if($logingroupid == 0)
 				$logingroupid = 'NULL';
-			$query = "UPDATE serverrequest "
-			       . "SET admingroupid = $admingroupid, "
-			       .     "logingroupid = $logingroupid "
-			       . "WHERE requestid = $requestid";
-			doQuery($query, 101);
+			$serversets[] = "admingroupid = $admingroupid";
+			$serversets[] = "logingroupid = $logingroupid";
 			addChangeLogEntryOther($request['logid'], "event:usergroups|admingroupid:$admingroupid|logingroupid:$logingroupid");
-			$query = "UPDATE request "
-			       . "SET stateid = 29 "
-			       . "WHERE id = $requestid";
-			doQuery($query, 101);
+			$reqsets[] = "stateid = 29";
+		}
+
+		if($updateservername)
+			$reqsets = "name = '$servername'";
+
+		if($allownousercheck) {
+			$newnousercheck = processInputVar('newnousercheck', ARG_NUMERIC);
+			if(($newnousercheck == 1 || $newnousercheck == 0) &&
+				($newnousercheck == $request['checkuser'])) {
+				$reqsets[] = "checkuser = (1 - checkuser)";
+			}
 		}
-		if($updateservername) {
+
+		if(count($serversets)) {
+			$sets = implode(',', $serversets);
 			$query = "UPDATE serverrequest "
-			       . "SET name = '$servername' "
+			       . "SET $sets "
 			       . "WHERE requestid = $requestid";
-			doQuery($query, 101);
+			doQuery($query);
+		}
+		if(count($reqsets)) {
+			$sets = implode(',', $reqsets);
+			$query = "UPDATE request "
+			       . "SET $sets "
+			       . "WHERE id = $requestid";
+			doQuery($query);
 		}
 		sendJSON(array('status' => 'success'));
 		cleanSemaphore();
@@ -3761,7 +3810,7 @@ function AJconfirmDeleteRequestProductio
 	$radios .= "&nbsp;&nbsp;&nbsp;<INPUT type=radio name=continuation ";
 	$radios .= "value=\"$cont\" id=\"radioend\"><label for=\"radioend\">";
 	$radios .= _("Just end the reservation</label><br><br>");
-	$text = preg_replace("/(.{1,60}([ \n]|$))/", '\1<br>', $text);
+	$text = preg_replace("/(.{1,48}([ \n]|$))/", '\1<br>', $text);
 	$data = array('content' => $title . $text . $radios,
 	              'cont' => $cont,
 	              'btntxt' => _('Submit'));
@@ -4270,6 +4319,7 @@ function processRequestInput() {
 	$imagingaccess = getContinuationVar('imagingaccess', 0);
 	$serveraccess = getContinuationVar('serveraccess', 0);
 	$openend = getContinuationVar('openend', 0);
+	$nousercheck = getContinuationVar('nousercheck', 0);
 	$return['imaging'] = getContinuationVar('imaging', 0);
 	$maxinitial = getContinuationVar('maxinitial', 0);
 
@@ -4321,6 +4371,11 @@ function processRequestInput() {
 		return $return;
 	}
 
+	# nousercheck
+	$return['nousercheck'] = processInputVar('nousercheck', ARG_NUMERIC);
+	if(! $nousercheck || $return['nousercheck'] != 1)
+		$return['nousercheck'] = 0;
+
 	# revisionid
 	$revids = processInputVar("revisionid", ARG_STRING);
 	$revids = explode(':', $revids);

Modified: vcl/trunk/web/.ht-inc/utils.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/utils.php?rev=1629055&r1=1629054&r2=1629055&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/utils.php (original)
+++ vcl/trunk/web/.ht-inc/utils.php Thu Oct  2 19:39:21 2014
@@ -5093,18 +5093,20 @@ function getMaxOverlap($userid) {
 
 ////////////////////////////////////////////////////////////////////////////////
 ///
-/// \fn addRequest($forimaging, $revisionid)
+/// \fn addRequest($forimaging, $revisionid, $nousercheck)
 ///
 /// \param $forimaging - (optional) 0 if a normal request, 1 if a request for
 /// creating a new image
 /// \param $revisionid - (optional) desired revision id of the image
+/// \param $checkuser - (optional, default=1) 0 or 1 - value to set for
+/// request.checkuser
 ///
 /// \return id from request table that corresponds to the added entry
 ///
 /// \brief adds an entry to the request and reservation tables
 ///
 ////////////////////////////////////////////////////////////////////////////////
-function addRequest($forimaging=0, $revisionid=array()) {
+function addRequest($forimaging=0, $revisionid=array(), $checkuser=1) {
 	global $requestInfo, $user, $uniqid, $mysql_link_vcl;
 	$startstamp = unixToDatetime($requestInfo["start"]);
 	$endstamp = unixToDatetime($requestInfo["end"]);
@@ -5136,7 +5138,8 @@ function addRequest($forimaging=0, $revi
 	       .        "forimaging, "
 	       .        "start, "
 	       .        "end, "
-	       .        "daterequested) "
+	       .        "daterequested, "
+	       .        "checkuser) "
 	       . "VALUES "
 	       .       "(13, "
 	       .       "{$user['id']}, "
@@ -5145,7 +5148,8 @@ function addRequest($forimaging=0, $revi
 	       .       "$forimaging, "
 	       .       "'$startstamp', "
 	       .       "'$endstamp', "
-	       .       "NOW())";
+	       .       "NOW(), "
+	       .       "$checkuser)";
 	$qh = doQuery($query, 136);
 
 	$qh = doQuery("SELECT LAST_INSERT_ID() FROM request", 134);
@@ -5359,6 +5363,7 @@ function findManagementNode($compid, $st
 /// \b logid - id from log table\n
 /// \b test - test flag\n
 /// \b forimaging - 0 if request is normal, 1 if it is for imaging\n
+/// \b checkuser - 1 if connected user timeout checks are enabled, 0 if not\n
 /// \b serverrequest - 0 if request is normal, 1 if it is a server request\n
 /// \b servername - name of server if server request\n
 /// \b admingroupid - id of admin user group if server request\n
@@ -5402,7 +5407,8 @@ function getRequestInfo($id, $returnNULL
 	       .        "datemodified, "
 	       .        "logid, "
 	       .        "test, "
-	       .        "forimaging "
+	       .        "forimaging, "
+	       .        "checkuser "
 	       . "FROM request "
 	       . "WHERE id = $id";
 	$qh = doQuery($query, 165);

Modified: vcl/trunk/web/.ht-inc/xmlrpcWrappers.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/xmlrpcWrappers.php?rev=1629055&r1=1629054&r2=1629055&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/xmlrpcWrappers.php (original)
+++ vcl/trunk/web/.ht-inc/xmlrpcWrappers.php Thu Oct  2 19:39:21 2014
@@ -134,7 +134,7 @@ function XMLRPCgetImages() {
 
 ////////////////////////////////////////////////////////////////////////////////
 ///
-/// \fn XMLRPCaddRequest($imageid, $start, $length, $foruser)
+/// \fn XMLRPCaddRequest($imageid, $start, $length, $foruser, $nousercheck)
 ///
 /// \param $imageid - id of an image
 /// \param $start - "now" or unix timestamp for start of reservation; will
@@ -144,6 +144,8 @@ function XMLRPCgetImages() {
 /// increments)
 /// \param $foruser - (optional) login to be used when setting up the account
 /// on the reserved machine - CURRENTLY, THIS IS UNSUPPORTED
+/// \param $nousercheck - (optional, default=0) set to 1 to disable timeout
+/// when user is disconnected for too long
 ///
 /// \return an array with at least one index named '\b status' which will have
 /// one of these values:\n
@@ -159,7 +161,8 @@ function XMLRPCgetImages() {
 /// \brief tries to make a request
 ///
 ////////////////////////////////////////////////////////////////////////////////
-function XMLRPCaddRequest($imageid, $start, $length, $foruser='') {
+function XMLRPCaddRequest($imageid, $start, $length, $foruser='',
+                          $nousercheck=0) {
 	global $user;
 	$imageid = processInputData($imageid, ARG_NUMERIC);
 	$start = processInputData($start, ARG_STRING, 1);
@@ -214,6 +217,8 @@ function XMLRPCaddRequest($imageid, $sta
 		                         . "have, and you are allowed $max "
 		                         . "overlapping reservations at a time");
 	}
+	if($nousercheck != 0 && $nousercheck != 1)
+		$nousercheck = 0;
 
 	$images = getImages();
 	$revisionid = getProductionRevisionid($imageid);
@@ -223,14 +228,15 @@ function XMLRPCaddRequest($imageid, $sta
 		            unixToDatetime($end), 0, $imageid);
 		return array('status' => 'notavailable');
 	}
-	$return['requestid']= addRequest();
+	$return['requestid']= addRequest(0, array(), (1 - $nousercheck));
 	$return['status'] = 'success';
 	return $return;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 ///
-/// \fn XMLRPCaddRequestWithEnding($imageid, $start, $end, $foruser)
+/// \fn XMLRPCaddRequestWithEnding($imageid, $start, $end, $foruser,
+//                                 $nousercheck)
 ///
 /// \param $imageid - id of an image
 /// \param $start - "now" or unix timestamp for start of reservation; will
@@ -240,6 +246,8 @@ function XMLRPCaddRequest($imageid, $sta
 /// the nearest 15 minute increment
 /// \param $foruser - (optional) login to be used when setting up the account
 /// on the reserved machine - CURRENTLY, THIS IS UNSUPPORTED
+/// \param $nousercheck - (optional, default=0) set to 1 to disable timeout
+/// when user is disconnected for too long
 ///
 /// \return an array with at least one index named '\b status' which will have
 /// one of these values:\n
@@ -255,7 +263,8 @@ function XMLRPCaddRequest($imageid, $sta
 /// \brief tries to make a request with the specified ending time
 ///
 ////////////////////////////////////////////////////////////////////////////////
-function XMLRPCaddRequestWithEnding($imageid, $start, $end, $foruser='') {
+function XMLRPCaddRequestWithEnding($imageid, $start, $end, $foruser='',
+                                    $nousercheck=0) {
 	global $user;
 	$imageid = processInputData($imageid, ARG_NUMERIC);
 	$start = processInputData($start, ARG_STRING, 1);
@@ -322,6 +331,8 @@ function XMLRPCaddRequestWithEnding($ima
 		                         . "have, and you are allowed $max "
 		                         . "overlapping reservations at a time");
 	}
+	if($nousercheck != 0 && $nousercheck != 1)
+		$nousercheck = 0;
 
 	$images = getImages();
 	$revisionid = getProductionRevisionid($imageid);
@@ -331,7 +342,7 @@ function XMLRPCaddRequestWithEnding($ima
 		            unixToDatetime($end), 0, $imageid);
 		return array('status' => 'notavailable');
 	}
-	$return['requestid']= addRequest();
+	$return['requestid']= addRequest(0, array(), (1 - $nousercheck));
 	$return['status'] = 'success';
 	return $return;
 }

Modified: vcl/trunk/web/js/requests.js
URL: http://svn.apache.org/viewvc/vcl/trunk/web/js/requests.js?rev=1629055&r1=1629054&r2=1629055&view=diff
==============================================================================
--- vcl/trunk/web/js/requests.js (original)
+++ vcl/trunk/web/js/requests.js Thu Oct  2 19:39:21 2014
@@ -89,6 +89,8 @@ function resetNewResDlg() {
 	dojo.byId('basicrdo').checked = true;
 	selectResType();
 	dijit.byId('deployprofileid').reset();
+	if(dijit.byId('nousercheck'))
+		dijit.byId('nousercheck').reset();
 	dijit.byId('deployname').reset();
 	resetSelect('deployadmingroup');
 	resetSelect('deploylogingroup');
@@ -147,6 +149,8 @@ function selectResType() {
 		//dojo.addClass('nrmacaddrspan', 'hidden');
 		//dojo.addClass('nrmonitoredspan', 'hidden');
 		dojo.addClass('nrfixedipdiv2', 'hidden');
+		if(dijit.byId('nousercheck'))
+			dojo.removeClass('nousercheckspan', 'hidden');
 		dojo.addClass('anystart', 'hidden');
 		dojo.addClass('indefinteend', 'hidden');
 		//hideDijitButton('newResDlgShowConfigBtn'); // finishconfigs
@@ -191,6 +195,8 @@ function selectResType() {
 	if(dojo.byId('serverrdo').checked) {
 		dijit.byId('deployimage').set('query', {server: 1, checkout: 1});
 		checkSelectedInList();
+		if(dijit.byId('nousercheck'))
+			dojo.addClass('nousercheckspan', 'hidden');
 		dijit.byId('deploystarttime').set('required', true);
 		dijit.byId('deploystartdate').set('required', true);
 		dojo.addClass('waittime', 'hidden');
@@ -469,6 +475,10 @@ function getDeployData(waitonly) {
 	// finishconfigs
 	/*if(dojo.byId('serverrdo').checked)
 		data.configdata = getConfigData();*/
+	if(dijit.byId('nousercheck') && dijit.byId('nousercheck').get('value') == 1)
+		data.nousercheck = 1;
+	else
+		data.nousercheck = 0;
 	data.profileid = dojo.byId('appliedprofileid').value;
 	data.name = dijit.byId('deployname').get('value');
 	data.admingroupid = getSelectValue('deployadmingroup');
@@ -1436,6 +1446,8 @@ function hideEditResDlg() {
 		dijit.byId('admingrpsel').destroy();
 	if(dijit.byId('logingrpsel'))
 		dijit.byId('logingrpsel').destroy();
+	if(dijit.byId('newnousercheck'))
+		dijit.byId('newnousercheck').destroy();
 	dojo.byId('editResDlgErrMsg').innerHTML = '';
 	dojo.byId('editrescont').value = '';
 	dojo.byId('editresid').value = '';
@@ -1487,6 +1499,10 @@ function submitEditReservation() {
 		var tmp = dijit.byId('day').value.match(/([0-9]{4})([0-9]{2})([0-9]{2})/);
 		var teststart = new Date(tmp[1], tmp[2] - 1, tmp[3], t.getHours(), t.getMinutes(), 0, 0);
 	}
+	if(dijit.byId('newnousercheck') && dijit.byId('newnousercheck').get('value') == 1)
+		data.newnousercheck = 1;
+	else
+		data.newnousercheck = 0;
 	if(dijit.byId('servername'))
 		data.servername = dijit.byId('servername').get('value');
 	if(dijit.byId('admingrpsel')) {