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/21 19:18:30 UTC

svn commit: r1633417 - in /vcl/trunk/web/.ht-inc: groups.php utils.php

Author: jfthomps
Date: Tue Oct 21 17:18:30 2014
New Revision: 1633417

URL: http://svn.apache.org/r1633417
Log:
VCL-696 - Improve resource group deletion options and information

utils.php: added getNodePath

groups.php:
-modified checkForGroupUsage: looks for usage in individual places and sets a new passed in (by reference) argument to a string that can be displayed to the user as to where the group is being used
-modified confirmDeleteGroup: print message set in checkForGroupUsage when group is in use

Modified:
    vcl/trunk/web/.ht-inc/groups.php
    vcl/trunk/web/.ht-inc/utils.php

Modified: vcl/trunk/web/.ht-inc/groups.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/groups.php?rev=1633417&r1=1633416&r2=1633417&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/groups.php (original)
+++ vcl/trunk/web/.ht-inc/groups.php Tue Oct 21 17:18:30 2014
@@ -1140,44 +1140,168 @@ function addGroup($data) {
 
 ////////////////////////////////////////////////////////////////////////////////
 ///
-/// \fn checkForGroupUsage($groupid, $type)
+/// \fn checkForGroupUsage($groupid, $type, &$msg)
 ///
-/// \param $groupid - id of an group
+/// \param $groupid - id of a group
 /// \param $type - group type: "user" or "resource"
+/// \param $msg - (pass by ref, optional) reason why group is in use is placed
+/// in this variable
 ///
-/// \return 0 if group is not used, 1 if it is
+/// \return 0 if group is not used, 1 if it is used
 ///
-/// \brief checks for $groupid being in the priv table corresponding to $type
+/// \brief checks for $groupid being in the priv table corresponding to $type;
+/// if the group is in use, a reason why is placed in $msg
 ///
 ////////////////////////////////////////////////////////////////////////////////
-function checkForGroupUsage($groupid, $type) {
+function checkForGroupUsage($groupid, $type, &$msg='') {
+	global $user;
+	$msgs = array();
 	if($type == "user") {
-		$query = "SELECT id FROM resourcegroup WHERE ownerusergroupid = $groupid";
+		$name = getUserGroupName($groupid, 1);
+		if($name === 0)
+			return 0;
+		# resourcegroup.ownerusergroupid
+		$query = "SELECT CONCAT(rt.name, '/', rg.name) AS name "
+		       . "FROM resourcegroup rg, "
+		       .      "resourcetype rt "
+		       . "WHERE ownerusergroupid = $groupid AND "
+		       .       "rg.resourcetypeid = rt.id";
+		$usedby = array();
 		$qh = doQuery($query, 310);
-		if(mysql_num_rows($qh))
-			return 1;
-		$query = "SELECT id "
+		while($row = mysql_fetch_assoc($qh))
+			$usedby[] = $row['name'];
+		if(count($usedby)) {
+			$msgs[] = "<h3>Owning User Group for Resource Groups</h3>\n"
+			        . implode("<br>\n", $usedby) . "<br>\n";
+		}
+		# usergroup.editusergroupid
+		$query = "SELECT CONCAT(ug.name, '@', a.name) AS name "
+		       . "FROM usergroup ug, "
+		       .      "affiliation a "
+				 . "WHERE ug.editusergroupid = $groupid AND "
+				 .       "ug.id != $groupid AND "
+				 .       "ug.affiliationid = a.id";
+		$usedby = array();
+		$qh = doQuery($query, 313);
+		while($row = mysql_fetch_assoc($qh))
+			$usedby[] = $row['name'];
+		if(count($usedby)) {
+			$msgs[] = "<h3>'Editable by' Group for User Groups</h3>\n"
+			        . implode("<br>\n", $usedby) . "<br>\n";
+		}
+		# userpriv.usergroupid
+		$query = "SELECT DISTINCT privnodeid "
+		       . "FROM userpriv "
+		       . "WHERE usergroupid = $groupid";
+		$qh = doQuery($query);
+		$usedby = array();
+		while($row = mysql_fetch_assoc($qh))
+			$usedby[] = getNodePath($row['privnodeid']);
+		if(count($usedby)) {
+			$msgs[] = "<h3>Assigned at Privilege Nodes</h3>\n"
+			        . implode("<br>\n", $usedby) . "<br>\n";
+		}
+		# blockRequest.groupid
+		$query = "SELECT name "
 		       . "FROM blockRequest "
 		       . "WHERE (groupid = $groupid "
 		       .    "OR admingroupid = $groupid) "
 		       .   "AND status IN ('requested', 'accepted')";
 		$qh = doQuery($query, 311);
-		if(mysql_num_rows($qh))
-			return 1;
-		$query = "SELECT id "
-		       . "FROM usergroup "
-				 . "WHERE editusergroupid = $groupid "
-				 .   "AND id != $groupid";
-		$qh = doQuery($query, 313);
-		if(mysql_num_rows($qh))
+		$usedby = array();
+		while($row = mysql_fetch_assoc($qh))
+			$usedby[] = $row['name'];
+		if(count($usedby)) {
+			$msgs[] = "<h3>Assigned for Block Allocations</h3>\n"
+			        . implode("<br>\n", $usedby) . "<br>\n";
+		}
+		# serverprofile.admingroupid
+		$query = "SELECT name FROM serverprofile WHERE admingroupid = $groupid";
+		$qh = doQuery($query);
+		$usedby = array();
+		while($row = mysql_fetch_assoc($qh))
+			$usedby[] = $row['name'];
+		if(count($usedby)) {
+			$msgs[] = "<h3>Admin User Group for Server Profiles</h3>\n"
+			        . implode("<br>\n", $usedby) . "<br>\n";
+		}
+		# serverprofile.logingroupid
+		$query = "SELECT name FROM serverprofile WHERE logingroupid = $groupid";
+		$qh = doQuery($query);
+		$usedby = array();
+		while($row = mysql_fetch_assoc($qh))
+			$usedby[] = $row['name'];
+		if(count($usedby)) {
+			$msgs[] = "<h3>Access User Group for Server Profiles</h3>\n"
+			        . implode("<br>\n", $usedby) . "<br>\n";
+		}
+		# serverrequest.admingroupid
+		$query = "SELECT s.name "
+		       . "FROM serverrequest s, "
+		       .      "request rq "
+		       . "WHERE s.admingroupid = $groupid AND "
+		       .       "s.requestid = rq.id";
+		$qh = doQuery($query);
+		$usedby = array();
+		while($row = mysql_fetch_assoc($qh))
+			$usedby[] = $row['name'];
+		if(count($usedby)) {
+			$msgs[] = "<h3>Admin User Group for Server Requests</h3>\n"
+			        . implode("<br>\n", $usedby) . "<br>\n";
+		}
+		# serverrequest.logingroupid
+		$query = "SELECT s.name "
+		       . "FROM serverrequest s, "
+		       .      "request rq "
+		       . "WHERE s.logingroupid = $groupid AND "
+		       .       "s.requestid = rq.id";
+		$qh = doQuery($query);
+		$usedby = array();
+		while($row = mysql_fetch_assoc($qh))
+			$usedby[] = $row['name'];
+		if(count($usedby)) {
+			$msgs[] = "<h3>Access User Group for Server Requests</h3>\n"
+			        . implode("<br>\n", $usedby) . "<br>\n";
+		}
+		if(count($msgs)) {
+			$msg = "$name is currently in use in the following ways. It "
+			     . "cannot be deleted until it is no longer in use.<br><br>\n"
+			     . implode("<br>\n", $msgs);
 			return 1;
-		$query = "SELECT id FROM userpriv WHERE usergroupid = $groupid";
+		}
+		return 0;
 	}
-	else
-		$query = "SELECT id FROM resourcepriv WHERE resourcegroupid = $groupid";
-	$qh = doQuery($query, 314);
-	if(mysql_num_rows($qh))
+
+	$name = getResourceGroupName($groupid);
+	if(is_null($name))
+		return 0;
+
+	# managementnode.imagelibgroupid
+	$query = "SELECT hostname FROM managementnode WHERE imagelibgroupid = $groupid";
+	$qh = doQuery($query);
+	$usedby = array();
+	while($row = mysql_fetch_assoc($qh))
+		$usedby[] = $row['hostname'];
+	if(count($usedby)) {
+		$msgs[] = "<h3>Management Node Image Library Group</h3>\n"
+		        . implode("<br>\n", $usedby) . "<br>\n";
+	}
+	# resourcepriv.resourcegroupid
+	$query = "SELECT DISTINCT privnodeid FROM resourcepriv WHERE resourcegroupid = $groupid";
+	$qh = doQuery($query);
+	$usedby = array();
+	while($row = mysql_fetch_assoc($qh))
+		$usedby[] = getNodePath($row['privnodeid']);
+	if(count($usedby)) {
+		$msgs[] = "<h3>Assigned at Privilege Nodes</h3>\n"
+		        . implode("<br>\n", $usedby) . "<br>\n";
+	}
+	if(count($msgs)) {
+		$msg = "$name is currently in use in the following ways. It "
+		     . "cannot be deleted until it is no longer in use.<br><br>\n"
+		     . implode("<br>\n", $msgs);
 		return 1;
+	}
 	return 0;
 }
 
@@ -1442,7 +1566,7 @@ function confirmDeleteGroup() {
 		$target = "#resources";
 	}
 
-	if(checkForGroupUsage($groupid, $type)) {
+	if(checkForGroupUsage($groupid, $type, $usemsg)) {
 		print "<H2 align=center>$title</H2>\n";
 		print $usemsg;
 		return;

Modified: vcl/trunk/web/.ht-inc/utils.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/utils.php?rev=1633417&r1=1633416&r2=1633417&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/utils.php (original)
+++ vcl/trunk/web/.ht-inc/utils.php Tue Oct 21 17:18:30 2014
@@ -10844,6 +10844,33 @@ function getNodeInfo($nodeid) {
 
 ////////////////////////////////////////////////////////////////////////////////
 ///
+/// \fn getNodePath($nodeid)
+///
+/// \param $nodeid - an id from the privnode table
+///
+/// \return string containing node and all of its parents of the form:\n
+/// VCL > node1 > node2 > node3
+///
+/// \brief gets the full path of a node
+///
+////////////////////////////////////////////////////////////////////////////////
+function getNodePath($nodeid) {
+	global $cache;
+	getNodeInfo($nodeid);
+	$path = '';
+	do {
+		$parent = $cache['nodes'][$nodeid]['parent'];
+		if($path == '')
+			$path = $cache['nodes'][$nodeid]['name'];
+		else
+			$path = "{$cache['nodes'][$nodeid]['name']} &gt; $path";
+		$nodeid = $parent;
+	} while($parent != DEFAULT_PRIVNODE);
+	return $path;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
 /// \fn sortKeepIndex($a, $b)
 ///
 /// \param $a - first item