def add_subscriber(request_id, email): user_id = create_or_return_user(email = email) subscriber_id, is_new_subscriber = create_subscriber(request_id = request_id, user_id = user_id) if subscriber_id: generate_prr_emails(request_id, notification_type = "Request followed", user_id = user_id) return subscriber_id return False
def make_request(text, email = None, user_id = None, phone = None, alias = None, department = None, passed_spam_filter = False, offline_submission_type = None, date_received = None): """ Make the request. At minimum you need to communicate which record(s) you want, probably with some text.""" if not passed_spam_filter: return None, False request_id = find_request(text) if request_id: # Same request already exists return request_id, False assigned_to_email = app.config['DEFAULT_OWNER_EMAIL'] assigned_to_reason = app.config['DEFAULT_OWNER_REASON'] if department: app.logger.info("\n\nDepartment chosen: %s" %department) prr_email = db_helpers.get_contact_by_dept(department) if prr_email: assigned_to_email = prr_email assigned_to_reason = "PRR Liaison for %s" %(department) else: app.logger.info("%s is not a valid department" %(department)) department = None request_id = create_request(text = text, user_id = user_id, offline_submission_type = offline_submission_type, date_received = date_received) # Actually create the Request object new_owner_id = assign_owner(request_id = request_id, reason = assigned_to_reason, email = assigned_to_email) # Assign someone to the request open_request(request_id) # Set the status of the incoming request to "Open" if email or alias or phone: subscriber_user_id = create_or_return_user(email = email, alias = alias, phone = phone) subscriber_id, is_new_subscriber = create_subscriber(request_id = request_id, user_id = subscriber_user_id) if subscriber_id: generate_prr_emails(request_id, notification_type = "Request made", user_id = subscriber_user_id) # Send them an e-mail notification return request_id, True
def set_directory_fields(): # Set basic user data if 'STAFF_URL' in app.config: # This gets run at regular internals via db_users.py in order to keep the staff user list up to date. Before users are added/updated, ALL users get reset to 'inactive', and then only the ones in the current CSV are set to active. for user in User.query.filter(User.is_staff == True).all(): update_user(user = user, is_staff = False) csvfile = urllib.urlopen(app.config['STAFF_URL']) dictreader = csv.DictReader(csvfile, delimiter=',') for row in dictreader: create_or_return_user(email = row['email'].lower(), alias = row['name'], phone = row['phone number'], department = row['department name'], is_staff = True) # Set liaisons data (who is a PRR liaison for what department) if 'LIAISONS_URL' in app.config: csvfile = urllib.urlopen(app.config['LIAISONS_URL']) dictreader = csv.DictReader(csvfile, delimiter=',') for row in dictreader: user = create_or_return_user(email = row['PRR liaison'], contact_for = row['department name']) if row['PRR backup'] != "": user = create_or_return_user(email = row['PRR backup'], backup_for = row['department name']) else: app.logger.info("\n\n Please update the config variable LIAISONS_URL for where to find department liaison data for your agency.") else: app.logger.info("\n\n Please update the config variable STAFF_URL for where to find csv data on the users in your agency.") if 'DEFAULT_OWNER_EMAIL' in app.config and 'DEFAULT_OWNER_REASON' in app.config: create_or_return_user(email = app.config['DEFAULT_OWNER_EMAIL'].lower(), alias = app.config['DEFAULT_OWNER_EMAIL'], department = app.config['DEFAULT_OWNER_REASON'], is_staff = True) app.logger.info("\n\n Creating a single user from DEFAULT_OWNER_EMAIL and DEFAULT_OWNER_REASON for now. You may log in with %s" %(app.config['DEFAULT_OWNER_EMAIL'])) else: app.logger.info("\n\n Unable to create any users. No one will be able to log in.")