[SUCS Devel] [Git][sucs/accountmanager][master] 2 commits: Fix bugs so the program actually runs

Imran Hussain imranh at sucs.org
Tue Mar 12 18:26:43 GMT 2019


Imran Hussain pushed to branch master at sucs / accountmanager


Commits:
ac7c4d77 by Imran Hussain at 2019-03-12T18:00:54Z
Fix bugs so the program actually runs

- - - - -
4859cccc by Imran Hussain at 2019-03-12T18:25:55Z
Add the ability to mark a cohort from a specific year for deletion

- - - - -


1 changed file:

- sucsam.py


Changes:

=====================================
sucsam.py
=====================================
@@ -1,4 +1,4 @@
-debugmode = 1
+debugmode = 0
 
 import os
 import pwd
@@ -11,6 +11,7 @@ import smtplib
 from email.mime.multipart import MIMEMultipart
 from email.mime.text import MIMEText
 import ldap
+import subprocess
 
 
 def correctPaidUntilStr():
@@ -257,29 +258,30 @@ def deleteUser(peopleList):
 	subprocess.call(['sudo', 'mkdir', "-m", "700", basedir])
 
 	for person in peopleList:
+
 		# get all their info from the db
 		cur = DBconn.cursor()
-		cur.execute("SELECT * from members WHERE username=%(user)s",{"user" : person[0]})
+		cur.execute("SELECT * from members WHERE username=%(user)s",{"user" : person})
 		userDBinfo = cur.fetchall()
 		cur.close()
 
 		# fail safe, if the DB username we just got isn't the one we are
 		# messing with, die
-		if str(person[0]) != userDBinfo[0][1]:
+		if str(person) != userDBinfo[0][1]:
 			print("Something went wrong getting info from DB, quitting! NO CHNAGES MADE")
 			sys.exit(9)
 
 		# get all their info from the ldap
-		userLDAPinfo = ldapconn.search_s(ldap_base,ldap.SCOPE_SUBTREE,"uid="+str(person[0]))
+		userLDAPinfo = ldapconn.search_s(ldap_base,ldap.SCOPE_SUBTREE,"uid="+str(person))
 
 		# fail safe, if the ldap username we just got isn't the one we
 		# are messing with, die
-		if str(person[0]) != userLDAPinfo[0][1]["uid"][0]:
+		if str(person) != userLDAPinfo[0][1]["uid"][0]:
 			print("Something went wrong getting info from LDAP, quitting! NO CHNAGES MADE")
 			sys.exit(9)
 
 		# declare some easy to use vars
-		username = str(person[0])
+		username = str(person)
 		persondir = basedir+"/"+username
 
 		# make the dir to store their stuff
@@ -331,17 +333,17 @@ def deleteUser(peopleList):
 		# /usr/lib/mailman/bin/remove_members users imranh at sucs.org
 		subprocess.call(['sudo', '/usr/lib/mailman/bin/remove_members', "members", userLDAPinfo[0][1]["mail"][0]])  # sucs email
 		subprocess.call(['sudo', '/usr/lib/mailman/bin/remove_members', "members", userDBinfo[0][3]])  # main email
-		subprocess.call(['sudo', '/usr/lib/mailman/bin/remove_members', "members", userDBinfo[0][6]+"@swan.ac.uk"])  # iss email
+		subprocess.call(['sudo', '/usr/lib/mailman/bin/remove_members', "members", str(userDBinfo[0][6])+"@swan.ac.uk"])  # iss email
 		subprocess.call(['sudo', '/usr/lib/mailman/bin/remove_members', "users", userLDAPinfo[0][1]["mail"][0]])  # sucs email
 		subprocess.call(['sudo', '/usr/lib/mailman/bin/remove_members', "users", userDBinfo[0][3]])  # main email
-		subprocess.call(['sudo', '/usr/lib/mailman/bin/remove_members', "users", userDBinfo[0][6]+"@swan.ac.uk"])  # iss email
+		subprocess.call(['sudo', '/usr/lib/mailman/bin/remove_members', "users", str(userDBinfo[0][6])+"@swan.ac.uk"])  # iss email
 
 		# time to delete them from the db :(
 		cur = DBconn.cursor()
 		# delete from doorcards first
-		cur.execute("DELETE FROM doorcards WHERE uid=%(uid)s",{"uid" : userDBinfo[0][0]})
+		cur.execute("DELETE FROM doorcards WHERE uid=%(uid)s",{"uid" : str(userDBinfo[0][0])})
 		# delete from members table
-		cur.execute("DELETE FROM members WHERE username=%(user)s",{"user" : person[0]})
+		cur.execute("DELETE FROM members WHERE username=%(user)s",{"user" : username})
 		# add their some details to the oldmembers table
 		cur.execute("INSERT into oldmembers (username,realname) VALUES (%(user)s,%(realname)s)",{"user" : username,"realname" : userDBinfo[0][2]})
 		DBconn.commit()
@@ -353,7 +355,7 @@ def deleteUser(peopleList):
 		# them
 		emailDeletedUser(userDBinfo)
 		# logs@
-		emailAdminDeleteUser(person[0])
+		emailAdminDeleteUser(person)
 		
 		# remove the entry from the list
 		peopleList.remove(person)
@@ -403,6 +405,7 @@ def deleteMenu(deleteArray):
 	print("2. Add/delete users from delete list")
 	print("3. Auto populate list of users to be deleted")
 	print("3.1 Just add student accounts")
+	print("3.2 Just add student accounts from a specific year")
 	print("3.5 Just add accounts marked as 'delete' in the DB")
 	print("9. Do the delete")
 	print("0. Go back to main menu")
@@ -449,6 +452,16 @@ def deleteMenu(deleteArray):
 				deleteArray.append(student[0])
 		print("No students look like the need deleting.")
 		deleteMenu(deleteArray)
+	elif option == "3.2":
+		year = input("Please enter the year you wish to target: ")
+		if len(studentsBad) > 0:
+			targetedPeople = []
+			for student in studentsBad:
+				paidyeararray = student[1].split(' ')
+				if year == paidyeararray[1]:
+					targetedPeople.append(student[0])
+					print("Adding " + student[0] + " to the list because the DB says: " + str(student[1]))
+			deleteMenu(targetedPeople)
 	elif option == "3.5":
 		if len(studentsBad) > 0:
 			for student in studentsBad:



View it on GitLab: https://projects.sucs.org/sucs/accountmanager/compare/8b380201461273cc2345a531e89d11682c2977c8...4859cccc6a5ca6aec9db0d792ebe7c91eea49244

-- 
View it on GitLab: https://projects.sucs.org/sucs/accountmanager/compare/8b380201461273cc2345a531e89d11682c2977c8...4859cccc6a5ca6aec9db0d792ebe7c91eea49244
You're receiving this email because of your account on projects.sucs.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/devel/attachments/20190312/d74fc01a/attachment-0001.html>


More information about the Devel mailing list