[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] conga/luci/site/luci/Extensions homebase_adapt ...



CVSROOT:	/cvs/cluster
Module name:	conga
Branch: 	EXPERIMENTAL
Changes by:	rmccabe sourceware org	2007-06-06 15:14:12

Modified files:
	luci/site/luci/Extensions: homebase_adapters.py 

Log message:
	Fix bz241727 (can't set user permissions in luci)

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/homebase_adapters.py.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.50.2.8&r2=1.50.2.9

--- conga/luci/site/luci/Extensions/homebase_adapters.py	2007/05/30 05:54:02	1.50.2.8
+++ conga/luci/site/luci/Extensions/homebase_adapters.py	2007/06/06 15:14:12	1.50.2.9
@@ -758,7 +758,7 @@
 	if not request.form.has_key('__CLUSTER'):
 		for i in clusters:
 			try:
-				if user.has_permission('View', i[1]):
+				if user.has_role('View', i[1]):
 					roles = list(i[1].get_local_roles_for_userid(user_id))
 					roles.remove('View')
 
@@ -776,7 +776,7 @@
 		for i in clusters:
 			if i[0] in request.form['__CLUSTER']:
 				try:
-					if not user.has_permission('View', i[1]):
+					if not user.has_role('View', i[1]):
 						roles = list(i[1].get_local_roles_for_userid(user_id))
 						roles.append('View')
 						i[1].manage_setLocalRoles(user_id, roles)
@@ -788,7 +788,7 @@
 					errors.append('Failed to add permission for user "%s" for cluster "%s"' % (user_id, i[0]))
 			else:
 				try:
-					if user.has_permission('View', i[1]):
+					if user.has_role('View', i[1]):
 						roles = list(i[1].get_local_roles_for_userid(user_id))
 						roles.remove('View')
 
@@ -809,7 +809,7 @@
 	if not request.form.has_key('__SYSTEM'):
 		for i in storage:
 			try:
-				if user.has_permission('View', i[1]):
+				if user.has_role('View', i[1]):
 					roles = list(i[1].get_local_roles_for_userid(user_id))
 					roles.remove('View')
 
@@ -824,7 +824,7 @@
 		for i in storage:
 			if i[0] in request.form['__SYSTEM']:
 				try:
-					if not user.has_permission('View', i[1]):
+					if not user.has_role('View', i[1]):
 						roles = list(i[1].get_local_roles_for_userid(user_id))
 						roles.append('View')
 						i[1].manage_setLocalRoles(user_id, roles)
@@ -833,7 +833,7 @@
 					errors.append('Failed to add permission for user "%s" for system "%s"' % (user_id, i[0]))
 			else:
 				try:
-					if user.has_permission('View', i[1]):
+					if user.has_role('View', i[1]):
 						roles = list(i[1].get_local_roles_for_userid(user_id))
 						roles.remove('View')
 
@@ -998,12 +998,12 @@
 	except:
 		pass
 
-	if 'ACTUAL_URL' in request:
+	if request.has_key('ACTUAL_URL'):
 		url = request['ACTUAL_URL']
 	else:
 		url = '.'
 
-	if 'pagetype' in request:
+	if request.has_key('pagetype'):
 		pagetype = request['pagetype']
 	else:
 		pagetype = '0'
@@ -1016,110 +1016,105 @@
 	index = 0
 	cur = None
 
-	pagetype = str(pagetype)
+	if pagetype is None:
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('HBP0: pagetype is None')
 
-#
-# The Add System page
-#
+	pagetype = str(pagetype)
 
+	# The Add System page
 	try:
 		if havePermAddStorage(self):
 			addSystem = {}
 			addSystem['Title'] = 'Add a System'
-			addSystem['absolute_url'] = '%s?pagetype=%s' % (url, HOMEBASE_ADD_SYSTEM)
+			addSystem['absolute_url'] = '%s?pagetype=%s' \
+				% (url, HOMEBASE_ADD_SYSTEM)
 			addSystem['Description'] = 'Add a system to the Luci storage management interface.'
+
 			if pagetype == HOMEBASE_ADD_SYSTEM:
-				cur = addSystem
 				addSystem['currentItem'] = True
 				ret['curIndex'] = index
-			else:
-				addSystem['currentItem'] = False
+				cur = addSystem
 			index += 1
 			temp.append(addSystem)
-	except: pass
+	except Exception, e:
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('HBP1: %r %s' % (e, str(e)))
 
 	# Initial add cluster page
 	try:
 		if havePermAddCluster(self):
 			addCluster = {}
 			addCluster['Title'] = 'Add an Existing Cluster'
-			addCluster['absolute_url'] = '%s?pagetype=%s' % (url, HOMEBASE_ADD_CLUSTER_INITIAL)
+			addCluster['absolute_url'] = '%s?pagetype=%s' \
+				% (url, HOMEBASE_ADD_CLUSTER_INITIAL)
 			addCluster['Description'] = 'Add an existing cluster to the Luci cluster management interface.'
+
 			if pagetype == HOMEBASE_ADD_CLUSTER_INITIAL or pagetype == HOMEBASE_ADD_CLUSTER:
 				addCluster['currentItem'] = True
 				ret['curIndex'] = index
 				cur = addCluster
-			else:
-				addCluster['currentItem'] = False
 			index += 1
 			temp.append(addCluster)
-	except: pass
-
-#
-# The Remove Storage System page
-#
+	except Exception, e:
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('HBP2: %r %s' % (e, str(e)))
 
+	# The Remove Storage System page
 	try:
 		if (havePermRemStorage(self) and havePermRemCluster(self) and (getStorage(self) or getClusters(self))):
 			remSystem = {}
 			remSystem['Title'] = 'Manage Systems'
-			remSystem['absolute_url'] = '%s?pagetype=%s' % (url, HOMEBASE_DEL_SYSTEM)
+			remSystem['absolute_url'] = '%s?pagetype=%s' \
+				% (url, HOMEBASE_DEL_SYSTEM)
 			remSystem['Description'] = 'Update or remove storage systems and clusters.'
 			if pagetype == HOMEBASE_DEL_SYSTEM:
 				remSystem['currentItem'] = True
 				ret['curIndex'] = index
 				cur = remSystem
-			else:
-				remSystem['currentItem'] = False
 			index += 1
 			temp.append(remSystem)
-	except:
-		pass
-
-#
-# Add a Luci user.
-#
+	except Exception, e:
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('HBP3: %r %s' % (e, str(e)))
 
+	# Add a Luci user.
 	try:
 		if havePermAddUser(self):
 			addUser = {}
 			addUser['Title'] = 'Add a User'
-			addUser['absolute_url'] = '%s?pagetype=%s' % (url, HOMEBASE_ADD_USER)
+			addUser['absolute_url'] = '%s?pagetype=%s' \
+				% (url, HOMEBASE_ADD_USER)
 			addUser['Description'] = 'Add a user to the Luci interface.'
 			if pagetype == HOMEBASE_ADD_USER:
 				addUser['currentItem'] = True
 				ret['curIndex'] = index
 				cur = addUser
-			else:
-				addUser['currentItem'] = False
 			index += 1
 			temp.append(addUser)
-	except:
-		pass
-
-#
-# Delete a Luci user
-#
+	except Exception, e:
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('HBP4: %r %s' % (e, str(e)))
 
+	# Delete a Luci user
 	try:
 		if (self.portal_membership.listMembers() and havePermDelUser(self)):
 			delUser = {}
 			delUser['Title'] = 'Delete a User'
-			delUser['absolute_url'] = '%s?pagetype=%s' % (url, HOMEBASE_DEL_USER)
+			delUser['absolute_url'] = '%s?pagetype=%s' \
+				% (url, HOMEBASE_DEL_USER)
 			delUser['Description'] = 'Delete a Luci user.'
 			if pagetype == HOMEBASE_DEL_USER:
 				delUser['currentItem'] = True
 				ret['curIndex'] = index
 				cur = delUser
-			else:
-				delUser['currentItem'] = False
 			index += 1
 			temp.append(delUser)
-	except: pass
+	except Exception, e:
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('HBP5: %r %s' % (e, str(e)))
 
-#
-# The User Permissions Page
-#
+	# The User Permissions Page
 	try:
 		if (havePermEditPerms(self) and self.portal_membership.listMembers() and (getStorage(self) or getClusters(self))):
 			userPerm = {}
@@ -1130,35 +1125,34 @@
 				userPerm['currentItem'] = True
 				ret['curIndex'] = index
 				cur = userPerm
-			else:
-				userPerm['currentItem'] = False
 			index += 1
 			temp.append(userPerm)
-	except: pass
+	except Exception, e:
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('HBP6: %r %s' % (e, str(e)))
 
-	if not 'curIndex' in ret:
+	if not ret.has_key('curIndex'):
 		ret['curIndex'] = 0
 
-	if cur and 'absolute_url' in cur and params:
-		import cgi
+	if cur is not None and cur.has_key('absolute_url'):
 		cur['base_url'] = cur['absolute_url']
-		param_list = list()
-		for i in params:
-			param_list.append('&%s=%s' % (cgi.escape(i), cgi.escape(params[i])))
-		temp = '%s%s' % (cur['absolute_url'], ''.join(param_list))
-		cur['absolute_url'] = temp
-	elif cur and 'absolute_url' in cur:
-		cur['base_url'] = cur['absolute_url']
-	else:
-		cur = {}
-		cur['base_url'] = '#'
+
+		if params:
+			import cgi
+			param_list = list()
+			for i in params:
+				param_list.append('&%s=%s' \
+					% (cgi.escape(i), cgi.escape(params[i])))
+			temp = '%s%s' % (cur['absolute_url'], ''.join(param_list))
+			cur['absolute_url'] = temp
 
 	ret['children'] = temp
 	return ret
 
 def createSystem(self, host, passwd):
 	try:
-		dummy = self.restrictedTraverse('%s%s' % (STORAGE_FOLDER_PATH, host)).objectItems()
+		dummy = self.restrictedTraverse('%s%s' \
+			% (STORAGE_FOLDER_PATH, host)).objectItems()
 		if LUCI_DEBUG_MODE is True:
 			luci_log.debug_verbose('CS0: %s already exists' % host)
 		return 'Storage system %s is already managed' % host
@@ -1171,7 +1165,7 @@
 			raise Exception, 'rc is None'
 	except Exception, e:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('CS1: %s: %s' % (host, e))
+			luci_log.debug_verbose('CS2: %s: %r %s' % (host, e, str(e)))
 		return 'Unable to establish a secure connection to the ricci agent on %s: %s' % (host, str(e))
 
 	try:
@@ -1179,14 +1173,14 @@
 			rc.auth(passwd)
 	except Exception, e:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('CS2: %s: %s' % (host, e))
+			luci_log.debug_verbose('CS3: %s: %r %s' % (host, e, str(e)))
 		return 'Unable to communicate with the ricci agent on %s for authentication' % host
 
 	try:
 		i = rc.authed()
 	except Exception, e:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('CS3 %s: %r %s' % (host, e, str(e)))
+			luci_log.debug_verbose('CS4 %s: %r %s' % (host, e, str(e)))
 		return 'Unable to authenticate to the ricci agent on %s' % host
 
 	if i is not True:
@@ -1233,10 +1227,9 @@
 			user = request['user']
 		except:
 			try:
-				members = list()
-				members.extend(self.portal_membership.listMembers())
+				members = map(lambda x: x.getUserName(), self.portal_membership.listMembers())
 				members.sort()
-				user = members[0].getUserName()
+				user = members[0]
 			except Exception, e:
 				if LUCI_DEBUG_MODE is True:
 					luci_log.debug_verbose('getDefaultUser0: %r %s' \
@@ -1280,14 +1273,14 @@
 
 		for c in clusters:
 			try:
-				perms[userName]['cluster'][c[0]] = i.has_permission('View', c[1])
+				perms[userName]['cluster'][c[0]] = i.has_role('View', c[1])
 			except Exception, e:
 				if LUCI_DEBUG_MODE is True:
 					luci_log.debug_verbose('getUserPerms2: user %s, obj %s: %r %s' % (userName, c[0], e, str(e)))
 
 		for s in storage:
 			try:
-				perms[userName]['storage'][s[0]] = i.has_permission('View', s[1])
+				perms[userName]['storage'][s[0]] = i.has_role('View', s[1])
 			except Exception, e:
 				if LUCI_DEBUG_MODE is True:
 					luci_log.debug_verbose('getUserPerms2: user %s, obj %s: %r %s' % (userName, s[0], e, str(e)))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]