Skip to content

Commit 3663e3a

Browse files
committed
Removing unusable ldap functions
1 parent 2f7ca68 commit 3663e3a

File tree

3 files changed

+2
-296
lines changed

3 files changed

+2
-296
lines changed

packet/ldap.py

Lines changed: 0 additions & 254 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
import hashlib
2-
31
from functools import lru_cache
42

5-
import urllib.request
6-
7-
from flask import redirect
8-
93
import ldap
104

115
from packet import _ldap
@@ -167,256 +161,8 @@ def ldap_is_rd(account):
167161
return _ldap_is_member_of_directorship(account, 'research')
168162

169163

170-
# Setters
171-
172-
def ldap_set_housingpoints(account, housing_points):
173-
account.housingPoints = housing_points
174-
ldap_get_current_students.cache_clear()
175-
ldap_get_member.cache_clear()
176-
177-
178-
def ldap_set_roomnumber(account, room_number):
179-
if room_number == "":
180-
room_number = None
181-
account.roomNumber = room_number
182-
ldap_get_current_students.cache_clear()
183-
ldap_get_member.cache_clear()
184-
185-
186-
def ldap_set_active(account):
187-
_ldap_add_member_to_group(account, 'active')
188-
ldap_get_active_members.cache_clear()
189-
ldap_get_member.cache_clear()
190-
191-
192-
def ldap_set_inactive(account):
193-
_ldap_remove_member_from_group(account, 'active')
194-
ldap_get_active_members.cache_clear()
195-
ldap_get_member.cache_clear()
196-
197-
198-
def ldap_set_current_student(account):
199-
_ldap_add_member_to_group(account, 'current_student')
200-
ldap_get_current_students.cache_clear()
201-
ldap_get_member.cache_clear()
202-
203-
204-
def ldap_set_non_current_student(account):
205-
_ldap_remove_member_from_group(account, 'current_student')
206-
ldap_get_current_students.cache_clear()
207-
ldap_get_member.cache_clear()
208-
209-
def ldap_multi_update(uid, attribute, value):
210-
dn = "uid={},cn=users,cn=accounts,dc=csh,dc=rit,dc=edu".format(
211-
uid
212-
)
213-
214-
try:
215-
current = _ldap.get_member(uid, uid=True).get(attribute)
216-
except KeyError:
217-
current = []
218-
219-
remove = list(set(current) - set(value))
220-
add = list(set(value) - set(current))
221-
222-
conn = _ldap.get_con()
223-
mod_list = []
224-
225-
for entry in remove:
226-
mod = (ldap.MOD_DELETE, attribute, entry.encode('utf-8'))
227-
mod_list.append(mod)
228-
229-
for entry in add:
230-
if entry:
231-
mod = (ldap.MOD_ADD, attribute, entry.encode('utf-8'))
232-
mod_list.append(mod)
233-
234-
conn.modify_s(dn, mod_list)
235-
236-
237-
# pylint: disable=too-many-branches
238-
def ldap_update_profile(form_input, uid):
239-
account = _ldap.get_member(uid, uid=True)
240-
empty = ["None", ""]
241-
for key, value in form_input.items():
242-
if value in empty:
243-
form_input[key] = None
244-
245-
if not form_input["name"] == account.cn:
246-
account.cn = form_input["name"]
247-
248-
if not form_input["birthday"] == account.birthday:
249-
account.birthday = form_input["birthday"]
250-
251-
try:
252-
if not form_input["phone"] == account.get("mobile"):
253-
ldap_multi_update(uid, "mobile", form_input["phone"])
254-
except KeyError:
255-
ldap_multi_update(uid, "mobile", form_input["phone"])
256-
257-
258-
if not form_input["plex"] == account.plex:
259-
account.plex = form_input["plex"]
260-
261-
if "major" in form_input.keys():
262-
if not form_input["major"] == account.major:
263-
account.major = form_input["major"]
264-
265-
if "minor" in form_input.keys():
266-
if not form_input["minor"] == account.minor:
267-
account.minor = form_input["minor"]
268-
269-
if "ritYear" in form_input.keys():
270-
if not form_input["ritYear"] == account.ritYear:
271-
account.ritYear = form_input["ritYear"]
272-
273-
if not form_input["website"] == account.homepageURL:
274-
account.homepageURL = form_input["website"]
275-
276-
if not form_input["github"] == account.github:
277-
account.github = form_input["github"]
278-
279-
if not form_input["twitter"] == account.twitterName:
280-
account.twitterName = form_input["twitter"]
281-
282-
if not form_input["blog"] == account.blogURL:
283-
account.blogURL = form_input["blog"]
284-
285-
if not form_input["resume"] == account.resumeURL:
286-
account.resumeURL = form_input["resume"]
287-
288-
if not form_input["google"] == account.googleScreenName:
289-
account.googleScreenName = form_input["google"]
290-
291-
try:
292-
if not form_input["mail"] == account.mail:
293-
ldap_multi_update(uid, "mail", form_input["mail"])
294-
except KeyError:
295-
ldap_multi_update(uid, "mail", form_input["mail"])
296-
297-
try:
298-
if not form_input["nickname"] == account.nickname:
299-
ldap_multi_update(uid, "nickname", form_input["nickname"])
300-
except KeyError:
301-
ldap_multi_update(uid, "nickname", form_input["nickname"])
302-
303-
if not form_input["shell"] == account.shell:
304-
account.loginShell = form_input["shell"]
305-
306-
307164
def ldap_get_roomnumber(account):
308165
try:
309166
return account.roomNumber
310167
except AttributeError:
311168
return ""
312-
313-
314-
@lru_cache(maxsize=1024)
315-
def ldap_search_members(query):
316-
con = _ldap.get_con()
317-
filt = str("(|(description=*{0}*)"
318-
"(displayName=*{0}*)"
319-
"(mail=*{0}*)"
320-
"(nickName=*{0}*)"
321-
"(plex=*{0}*)"
322-
"(sn=*{0}*)"
323-
"(uid=*{0}*)"
324-
"(mobile=*{0}*)"
325-
"(twitterName=*{0}*)"
326-
"(github=*{0}*))").format(query)
327-
328-
res = con.search_s(
329-
"dc=csh,dc=rit,dc=edu",
330-
ldap.SCOPE_SUBTREE,
331-
filt,
332-
['uid'])
333-
334-
ret = []
335-
336-
for uid in res:
337-
try:
338-
mem = (str(uid[1]).split('\'')[3])
339-
ret.append(ldap_get_member(mem))
340-
except IndexError:
341-
continue
342-
343-
return ret
344-
345-
346-
@lru_cache(maxsize=1024)
347-
def ldap_get_year(year):
348-
con = _ldap.get_con()
349-
filt = str("(&(memberSince>={}0801010101-0400)(memberSince<={}0801010101-0400))").format(year, str(int(year) + 1))
350-
351-
res = con.search_s(
352-
"dc=csh,dc=rit,dc=edu",
353-
ldap.SCOPE_SUBTREE,
354-
filt,
355-
['uid'])
356-
357-
ret = []
358-
359-
for uid in res:
360-
try:
361-
mem = (str(uid[1]).split('\'')[3])
362-
ret.append(ldap_get_member(mem))
363-
except IndexError:
364-
continue
365-
366-
return ret
367-
368-
369-
@lru_cache(maxsize=1024)
370-
def get_image(uid):
371-
try:
372-
account = ldap_get_member(uid)
373-
image = account.jpegPhoto
374-
github = account.github
375-
twitter = account.twitterName
376-
except KeyError:
377-
return redirect(get_gravatar(), code=302)
378-
379-
# Return stored Image
380-
if image:
381-
return image
382-
383-
# Get Gravatar
384-
url = get_gravatar(uid)
385-
try:
386-
gravatar = urllib.request.urlopen(url)
387-
if gravatar.getcode() == 200:
388-
return redirect(url, code=302)
389-
except urllib.error.HTTPError:
390-
pass
391-
392-
# Get GitHub Photo
393-
if github:
394-
url = "https://github.com/" + github + ".png?size=250"
395-
try:
396-
urllib.request.urlopen(url)
397-
return redirect(url, code=302)
398-
except urllib.error.HTTPError:
399-
pass
400-
401-
# Get Twitter Photo
402-
if twitter:
403-
url = "https://twitter.com/" + twitter + "/profile_image?size=original"
404-
try:
405-
urllib.request.urlopen(url)
406-
return redirect(url, code=302)
407-
except urllib.error.HTTPError:
408-
pass
409-
410-
# Fall back to default
411-
return redirect(get_gravatar(), code=302)
412-
413-
414-
@lru_cache(maxsize=1024)
415-
def get_gravatar(uid=None):
416-
if uid:
417-
addr = uid + "@csh.rit.edu"
418-
url = "https://gravatar.com/avatar/" + hashlib.md5(addr.encode('utf8')).hexdigest() +".jpg?d=404&s=250"
419-
else:
420-
421-
url = "https://gravatar.com/avatar/" + hashlib.md5(addr.encode('utf8')).hexdigest() + ".jpg?d=mm&s=250"
422-
return url

packet/static/js/toggles.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

packet/utils.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
# Credit to Liam Middlebrook and Ram Zallan
22
# https://github.com/liam-middlebrook/gallery
3-
import subprocess
4-
import base64
53
import datetime
6-
4+
import subprocess
75
from functools import wraps
8-
from flask import session
96

107
import requests
11-
12-
import ldap
8+
from flask import session
139

1410
from packet import _ldap
1511
from packet.ldap import (ldap_get_member,
@@ -88,25 +84,3 @@ def parse_account_year(date):
8884
year = year - 1
8985
return year
9086
return None
91-
92-
93-
def process_image(photo, uid):
94-
if base64.b64decode(photo):
95-
key = 'jpegPhoto'
96-
account = ldap_get_member(uid)
97-
bin_icon = base64.b64decode(photo)
98-
con = _ldap.get_con()
99-
exists = account.jpegPhoto
100-
101-
if not exists:
102-
ldap_mod = ldap.MOD_ADD
103-
else:
104-
ldap_mod = ldap.MOD_REPLACE
105-
106-
mod = (ldap_mod, key, bin_icon)
107-
mod_attrs = [mod]
108-
con.modify_s(account.get_dn(), mod_attrs)
109-
110-
return True
111-
else:
112-
return False

0 commit comments

Comments
 (0)