From b6fcf51309a96fbc5c2362293f693bcfb11d0d51 Mon Sep 17 00:00:00 2001 From: Philipp Schmied Date: Wed, 28 Feb 2018 09:19:27 +0100 Subject: [PATCH] Flask_terms.py: Fixed mapping of notifcation e-mails to terms with uppercase letters --- var/www/modules/terms/Flask_terms.py | 55 ++++++++++++++-------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/var/www/modules/terms/Flask_terms.py b/var/www/modules/terms/Flask_terms.py index ce2fa4a7..0811a4c0 100644 --- a/var/www/modules/terms/Flask_terms.py +++ b/var/www/modules/terms/Flask_terms.py @@ -3,7 +3,7 @@ ''' Flask functions and routes for the trending modules page - + note: The matching of credential against supplied credential is done using Levenshtein distance ''' import redis @@ -128,7 +128,7 @@ def mixUserName(supplied, extensive=False): if len(usr) > 2: filtered_usernames.append(usr) return filtered_usernames - + # ============ ROUTES ============ @@ -148,7 +148,7 @@ def terms_management(): # Map tracking if notifications are enabled for a specific term notificationEnabledDict = {} - + # Maps a specific term to the associated email addresses notificationEMailTermMapping = {} @@ -157,12 +157,12 @@ def terms_management(): trackReg_list_values = [] trackReg_list_num_of_paste = [] for tracked_regex in r_serv_term.smembers(TrackedRegexSet_Name): - + notificationEMailTermMapping[tracked_regex] = "\n".join(r_serv_term.smembers(TrackedTermsNotificationEmailsPrefix_Name + tracked_regex)) - + if tracked_regex not in notificationEnabledDict: notificationEnabledDict[tracked_regex] = False - + trackReg_list.append(tracked_regex) value_range = Term_getValueOverRange(tracked_regex, today_timestamp, [1, 7, 31], per_paste=per_paste_text) @@ -182,13 +182,13 @@ def terms_management(): trackSet_list_values = [] trackSet_list_num_of_paste = [] for tracked_set in r_serv_term.smembers(TrackedSetSet_Name): - + notificationEMailTermMapping[tracked_set] = "\n".join(r_serv_term.smembers(TrackedTermsNotificationEmailsPrefix_Name + tracked_set)) - + if tracked_set not in notificationEnabledDict: notificationEnabledDict[tracked_set] = False - + trackSet_list.append(tracked_set) value_range = Term_getValueOverRange(tracked_set, today_timestamp, [1, 7, 31], per_paste=per_paste_text) @@ -208,12 +208,12 @@ def terms_management(): track_list_values = [] track_list_num_of_paste = [] for tracked_term in r_serv_term.smembers(TrackedTermsSet_Name): - + notificationEMailTermMapping[tracked_term] = "\n".join(r_serv_term.smembers(TrackedTermsNotificationEmailsPrefix_Name + tracked_term)) - + if tracked_term not in notificationEnabledDict: notificationEnabledDict[tracked_term] = False - + track_list.append(tracked_term) value_range = Term_getValueOverRange(tracked_term, today_timestamp, [1, 7, 31], per_paste=per_paste_text) @@ -235,9 +235,9 @@ def terms_management(): term_date = datetime.datetime.utcfromtimestamp(int(term_date)) if term_date is not None else "No date recorded" black_list.append([blacked_term, term_date]) - return render_template("terms_management.html", + return render_template("terms_management.html", black_list=black_list, track_list=track_list, trackReg_list=trackReg_list, trackSet_list=trackSet_list, - track_list_values=track_list_values, track_list_num_of_paste=track_list_num_of_paste, + track_list_values=track_list_values, track_list_num_of_paste=track_list_num_of_paste, trackReg_list_values=trackReg_list_values, trackReg_list_num_of_paste=trackReg_list_num_of_paste, trackSet_list_values=trackSet_list_values, trackSet_list_num_of_paste=trackSet_list_num_of_paste, per_paste=per_paste, notificationEnabledDict=notificationEnabledDict, notificationEMailTermMapping=notificationEMailTermMapping) @@ -309,19 +309,19 @@ def terms_management_action(): action = request.args.get('action') term = request.args.get('term') notificationEmailsParam = request.args.get('emailAddresses') - + if action is None or term is None: return "None" else: if section == "followTerm": if action == "add": - + # Strip all whitespace notificationEmailsParam = "".join(notificationEmailsParam.split()) - + # Make a list of all passed email addresses notificationEmails = notificationEmailsParam.split(",") - + validNotificationEmails = [] # check for valid email addresses for email in notificationEmails: @@ -329,15 +329,14 @@ def terms_management_action(): # has exactly one @ sign, and at least one . in the part after the @ if re.match(r"[^@]+@[^@]+\.[^@]+", email): validNotificationEmails.append(email) - + # add all valid emails to the set for email in validNotificationEmails: - r_serv_term.sadd(TrackedTermsNotificationEmailsPrefix_Name + term, email) - print "added " + email + " for " + TrackedTermsNotificationEmailsPrefix_Name + term - + r_serv_term.sadd(TrackedTermsNotificationEmailsPrefix_Name + term.lower(), email) + # enable notifications by default r_serv_term.sadd(TrackedTermsNotificationEnabled_Name, term.lower()) - + # check if regex/set or simple term #regex if term.startswith('/') and term.endswith('/'): @@ -361,7 +360,7 @@ def terms_management_action(): else: r_serv_term.sadd(TrackedTermsSet_Name, term.lower()) r_serv_term.hset(TrackedTermsDate_Name, term.lower(), today_timestamp) - + elif action == "toggleEMailNotification": # get the current state if term in r_serv_term.smembers(TrackedTermsNotificationEnabled_Name): @@ -370,7 +369,7 @@ def terms_management_action(): else: # add it r_serv_term.sadd(TrackedTermsNotificationEnabled_Name, term.lower()) - + #del action else: if term.startswith('/') and term.endswith('/'): @@ -490,9 +489,9 @@ def terms_plot_top_data(): value = r_serv_term.hget(per_paste+str(timestamp), term) curr_value_range = int(value) if value is not None else 0 value_range.append([timestamp, curr_value_range]) - + to_return.append([term, value_range, tot_value, position]) - + return jsonify(to_return) @@ -567,7 +566,7 @@ def cred_management_action(): for Unum in uniq_num_set: levenRatio = 2.0 username = r_serv_cred.hget(REDIS_KEY_ALL_CRED_SET_REV, Unum) - + # Calculate Levenshtein distance, ignore negative ratio supp_splitted = supplied.split() supp_mixed = supplied.replace(' ','')