Exemplo n.º 1
0
def add_resource(resource, request_body, current_user_id = None):
	fields = request_body.form
	if "extension" in resource:
		return request_extension(int(fields['request_id']), fields.getlist('extend_reason'), current_user_id)
	if "note" in resource:
		return add_note(int(fields['request_id']), fields['note_text'], current_user_id)
	elif "record" in resource:
		if fields['record_description'] == "":
			return "When uploading a record, please fill out the 'summary' field."
		if 'record_access' in fields and fields['record_access'] != "":
			return add_offline_record(int(fields['request_id']), fields['record_description'], fields['record_access'], current_user_id)
		elif 'link_url' in fields and fields['link_url'] != "":
			return add_link(int(fields['request_id']), fields['link_url'], fields['record_description'], current_user_id)
		else:
			return upload_record(int(fields['request_id']), request.files['record'], fields['record_description'], current_user_id)
	elif "qa" in resource:
		return ask_a_question(int(fields['request_id']), current_user_id, fields['question_text'])
	elif "owner" in resource:
		participant_id, new = add_staff_participant(request_id = fields['request_id'], email = fields['owner_email'], reason = fields['owner_reason'])
		if new:
			generate_prr_emails(request_id = fields['request_id'], notification_type = "Staff participant added", user_id = get_attribute("user_id", obj_id = participant_id, obj_type = "Owner"))
		return participant_id
	elif "subscriber" in resource:
		return add_subscriber(request_id=fields['request_id'], email = fields['follow_email'])
	else:
		return False
Exemplo n.º 2
0
def close_request(request_id, reason = "", user_id = None):
	req = get_obj("Request", request_id)
	change_request_status(request_id, "Closed")
	# Create a note to capture closed information:
	create_note(request_id, reason, user_id)
	generate_prr_emails(request_id = request_id, notification_type = "Request closed")
	add_staff_participant(request_id = request_id, user_id = user_id)
Exemplo n.º 3
0
def make_request(text, email = None, user_id = None, phone = None, alias = None, department = None, passed_recaptcha = False):
	""" Make the request. At minimum you need to communicate which record(s) you want, probably with some text."""
	if (app.config['ENVIRONMENT'] == 'PRODUCTION') and (not passed_recaptcha) and is_spam(text): 
		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:
		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:
			print "%s is not a valid department" %(department)
			department = None
	request_id = create_request(text = text, user_id = user_id, department = department) # 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 phone or alias: # If the user provided an e-mail address, add them as a subscriber to the request.
		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
Exemplo n.º 4
0
def add_resource(resource, request_body, current_user_id = None):
	fields = request_body.form
	if "extension" in resource:
		return request_extension(int(fields['request_id']), fields.getlist('extend_reason'), current_user_id)
	if "note" in resource:
		return add_note(int(fields['request_id']), fields['note_text'], current_user_id)
	elif "record" in resource:
		if fields['record_description'] == "":
			return "When uploading a record, please fill out the 'summary' field."
		if 'record_access' in fields and fields['record_access'] != "":
			return add_offline_record(int(fields['request_id']), fields['record_description'], fields['record_access'], current_user_id)
		elif 'link_url' in fields and fields['link_url'] != "":
			return add_link(int(fields['request_id']), fields['link_url'], fields['record_description'], current_user_id)
		else:
			return upload_record(int(fields['request_id']), request.files['record'], fields['record_description'], current_user_id)
	elif "qa" in resource:
		return ask_a_question(int(fields['request_id']), current_user_id, fields['question_text'])
	elif "owner" in resource:
		participant_id, new = add_staff_participant(request_id = fields['request_id'], email = fields['owner_email'], reason = fields['owner_reason'])
		if new:
			generate_prr_emails(request_id = fields['request_id'], notification_type = "Staff participant added", user_id = get_attribute("user_id", obj_id = participant_id, obj_type = "Owner"))
		return participant_id
	elif "subscriber" in resource:
		return add_subscriber(request_id=fields['request_id'], email = fields['follow_email'])
	else:
		return False
Exemplo n.º 5
0
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
Exemplo n.º 6
0
def make_request(
    text,
    email=None,
    assigned_to_name=None,
    assigned_to_email=None,
    assigned_to_reason=None,
    user_id=None,
    phone=None,
    alias=None,
    department=None,
):
    """ Make the request. At minimum you need to communicate which record(s) you want, probably with some text."""
    if is_spam(text):
        return None, False
    request_id = find_request(text)
    if request_id:  # Same request already exists
        return request_id, False
    request_id = create_request(text=text, user_id=user_id, department=department)  # 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 phone or alias:  # If the user provided an e-mail address, add them as a subscriber to the request.
        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
Exemplo n.º 7
0
def assign_owner(request_id, reason, email=None):
    """ Called any time a new owner is assigned. This will overwrite the current owner."""
    req = get_obj("Request", request_id)
    past_owner_id = None
    # If there is already an owner, unassign them:
    if req.point_person():
        past_owner_id = req.point_person().id
        past_owner = get_obj("Owner", req.point_person().id)
        update_obj(attribute="is_point_person", val=False, obj=past_owner)
    owner_id, is_new_owner = add_staff_participant(request_id=request_id,
                                                   reason=reason,
                                                   email=email,
                                                   is_point_person=True)
    if (past_owner_id == owner_id
        ):  # Already the current owner, so don't send any e-mails
        return owner_id

    app.logger.info("\n\nA new owner has been assigned: Owner: %s" % owner_id)
    new_owner = get_obj("Owner", owner_id)
    # Update the associated department on request
    update_obj(attribute="department_id",
               val=new_owner.user.department,
               obj=req)
    user_id = get_attribute(attribute="user_id",
                            obj_id=owner_id,
                            obj_type="Owner")
    # Send notifications
    if is_new_owner:
        generate_prr_emails(request_id=request_id,
                            notification_type="Request assigned",
                            user_id=user_id)
    return owner_id
Exemplo n.º 8
0
def add_resource(resource, request_body, current_user_id = None):
	fields = request_body
	if "extension" in resource:
		if not fields.getlist('extend_reason') and not fields.getlist('extend_reasons'):
			return "You must select a reason for the extension."
		return request_extension(int(fields['request_id']), fields.getlist('extend_reason'), current_user_id)
	if "note" in resource:
		return add_note(request_id = int(fields['request_id']), text = fields['note_text'], user_id = current_user_id, passed_spam_filter = True) # Bypass spam filter because they are logged in.
	elif "record" in resource:
		if fields['record_description'] == "":
			return "When uploading a record, please fill out the 'summary' field."
		if 'record_access' in fields and fields['record_access'] != "":
			return add_offline_record(int(fields['request_id']), fields['record_description'], fields['record_access'], current_user_id)
		elif 'link_url' in fields and fields['link_url'] != "":
			return add_link(request_id = int(fields['request_id']), url = fields['link_url'], description = fields['record_description'], user_id = current_user_id)
		# else:
		# 	document = None
		# 	try:
		# 		document = request.files['record']
		# 	except:
		# 		app.logger.info("\n\nNo file passed in")
		# 	return upload_record(request_id = int(fields['request_id']), document = document, description = fields['record_description'], user_id = current_user_id)
	elif "qa" in resource:
		return ask_a_question(request_id = int(fields['request_id']), user_id = current_user_id, question = fields['question_text'])
	elif "owner" in resource:
		participant_id, new = add_staff_participant(request_id = fields['request_id'], email = fields['owner_email'], reason = fields['owner_reason'])
		if new:
			generate_prr_emails(request_id = fields['request_id'], notification_type = "Staff participant added", user_id = get_attribute("user_id", obj_id = participant_id, obj_type = "Owner"))
		return participant_id
	elif "subscriber" in resource:
		return add_subscriber(request_id=fields['request_id'], email = fields['follow_email'])
	else:
		return False
Exemplo n.º 9
0
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
Exemplo n.º 10
0
def ask_a_question(request_id, owner_id, question):
	""" City staff can ask a question about a request they are confused about."""
	qa_id = create_QA(request_id = request_id, question = question, owner_id = owner_id)
	if qa_id:
		change_request_status(request_id, "Pending")
		generate_prr_emails(request_id, notification_type = "Question asked", user_id = get_requester(request_id))
		add_staff_participant(request_id = request_id, user_id = get_attribute(attribute = "user_id", obj_id = owner_id, obj_type = "Owner"))
		return qa_id
	return False
Exemplo n.º 11
0
def ask_a_question(request_id, owner_id, question):
	""" City staff can ask a question about a request they are confused about."""
	qa_id = create_QA(request_id = request_id, question = question, owner_id = owner_id)
	if qa_id:
		change_request_status(request_id, "Pending")
		generate_prr_emails(request_id, notification_type = "Question asked", user_id = get_requester(request_id))
		add_staff_participant(request_id = request_id, user_id = get_attribute(attribute = "user_id", obj_id = owner_id, obj_type = "Owner"))
		return qa_id
	return False
Exemplo n.º 12
0
def add_offline_record(request_id, description, access, user_id):
	""" Creates a record with offline attributes """
	record_id = create_record(request_id = request_id, user_id = user_id, access = access, description = description) # To create an offline record, we need to know the request ID to which it will be added, the user ID for the person adding the record, how it can be accessed, and a description/title of the record.
	if record_id:
		change_request_status(request_id, "A response has been added.")
		generate_prr_emails(request_id = request_id, notification_type = "City response added")
		add_staff_participant(request_id = request_id, user_id = user_id)
		return record_id
	return False
Exemplo n.º 13
0
def add_link(request_id, url, description, user_id):
	""" Creates a record with link attributes """
	record_id = create_record(url = url, request_id = request_id, user_id = user_id, description = description)
	if record_id:
		change_request_status(request_id, "A response has been added.")
		generate_prr_emails(request_id = request_id, notification_type = "City response added")
		add_staff_participant(request_id = request_id, user_id = user_id)
		return record_id
	return False
Exemplo n.º 14
0
def answer_a_question(qa_id, answer, subscriber_id = None, passed_spam_filter = False):
	""" A requester can answer a question city staff asked them about their request."""
	if (not answer) or (answer == "") or (not passed_spam_filter):
		return False
	else:
		request_id = create_answer(qa_id, subscriber_id, answer)
		# We aren't changing the request status if someone's answered a question anymore, but we could change_request_status(request_id, "Pending")
		generate_prr_emails(request_id = request_id, notification_type = "Question answered")
		return True
Exemplo n.º 15
0
def assign_owner(request_id, reason, email = None): 
	""" Called any time a new owner is assigned. This will overwrite the current owner."""
	owner_id, is_new_owner = add_staff_participant(request_id = request_id, reason = reason, email = email)
	req = get_obj("Request", request_id)
	if req.current_owner == owner_id: # Already the current owner
		return owner_id
	update_obj(attribute = "current_owner", val = owner_id, obj = req)
	user_id = get_attribute(attribute = "user_id", obj_id = owner_id, obj_type = "Owner")
	if is_new_owner:
		generate_prr_emails(request_id = request_id, notification_type = "Request assigned", user_id = user_id)
	return owner_id
Exemplo n.º 16
0
def assign_owner(request_id, reason, email = None): 
	""" Called any time a new owner is assigned. This will overwrite the current owner."""
	owner_id, is_new_owner = add_staff_participant(request_id = request_id, reason = reason, email = email)
	req = get_obj("Request", request_id)
	if req.current_owner == owner_id: # Already the current owner
		return owner_id
	update_obj(attribute = "current_owner", val = owner_id, obj = req)
	user_id = get_attribute(attribute = "user_id", obj_id = owner_id, obj_type = "Owner")
	if is_new_owner:
		generate_prr_emails(request_id = request_id, notification_type = "Request assigned", user_id = user_id)
	return owner_id
Exemplo n.º 17
0
def ask_a_question(request_id, user_id, question):
	""" City staff can ask a question about a request they are confused about."""
	req = get_obj("Request", request_id)
	qa_id = create_QA(request_id = request_id, question = question, user_id = user_id)
	if qa_id:
		change_request_status(request_id, "Pending")
		requester = req.requester()
		if requester:
			generate_prr_emails(request_id, notification_type = "Question asked", user_id = requester.user_id)
		add_staff_participant(request_id = request_id, user_id = user_id)
		return qa_id
	return False
Exemplo n.º 18
0
def add_note(request_id, text, user_id = None, passed_spam_filter = False):
	if not text or text == "" or (not passed_spam_filter):
		return False
	note_id = create_note(request_id = request_id, text = text, user_id = user_id)
	if note_id:
		change_request_status(request_id, "A response has been added.")
		if user_id:
			add_staff_participant(request_id = request_id, user_id = user_id)
			generate_prr_emails(request_id = request_id, notification_type = "City response added")
		else:
			generate_prr_emails(request_id = request_id, notification_type = "Public note added")
		return note_id
	return False
Exemplo n.º 19
0
def upload_record(request_id, file, description, user_id):
	""" Creates a record with upload/download attributes """
	try:
		doc_id, filename = scribd_helpers.upload_file(file)
	except:
		return "The upload timed out, please try again."
	if doc_id == False:
		return "Extension type '%s' is not allowed." % filename
	else:
		if str(doc_id).isdigit():
			record_id = create_record(doc_id = doc_id, request_id = request_id, user_id = user_id, description = description, filename = filename, url = app.config['HOST_URL'] + doc_id)
			change_request_status(request_id, "A response has been added.")
			generate_prr_emails(request_id = request_id, notification_type = "City response added")
			add_staff_participant(request_id = request_id, user_id = user_id)
			return record_id
	return "There was an issue with your upload."
Exemplo n.º 20
0
def make_request(text, email = None, assigned_to_name = None, assigned_to_email = None, assigned_to_reason = None, user_id = None, phone = None, alias = None, department = None, passed_recaptcha = False):
	""" Make the request. At minimum you need to communicate which record(s) you want, probably with some text."""
	if (not passed_recaptcha) and is_spam(text): 
		return None, False
	request_id = find_request(text)
	if request_id: # Same request already exists
		return request_id, False
	request_id = create_request(text = text, user_id = user_id, department = department) # 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 phone or alias: # If the user provided an e-mail address, add them as a subscriber to the request.
		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
Exemplo n.º 21
0
def upload_record(request_id, file, description, user_id):
	""" Creates a record with upload/download attributes """
	try:
		doc_id, filename = scribd_helpers.upload_file(file = file, request_id = request_id)
	except:
		return "The upload timed out, please try again."
	if doc_id == False:
		return "Extension type '%s' is not allowed." % filename
	else:
		if str(doc_id).isdigit():
			record_id = create_record(doc_id = doc_id, request_id = request_id, user_id = user_id, description = description, filename = filename, url = app.config['HOST_URL'] + doc_id)
			change_request_status(request_id, "A response has been added.")
			generate_prr_emails(request_id = request_id, notification_type = "City response added")
			add_staff_participant(request_id = request_id, user_id = user_id)
			return record_id
	return "There was an issue with your upload."
Exemplo n.º 22
0
def make_request(text,
                 email=None,
                 user_id=None,
                 phone=None,
                 alias=None,
                 department=None,
                 passed_recaptcha=False):
    """ Make the request. At minimum you need to communicate which record(s) you want, probably with some text."""
    if (app.config['ENVIRONMENT']
            == 'PRODUCTION') and (not passed_recaptcha) and is_spam(text):
        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:
        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:
            print "%s is not a valid department" % (department)
            department = None
    request_id = create_request(
        text=text, user_id=user_id,
        department=department)  # 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 phone or alias:  # If the user provided an e-mail address, add them as a subscriber to the request.
        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
Exemplo n.º 23
0
def assign_owner(request_id, reason, email = None):
	""" Called any time a new owner is assigned. This will overwrite the current owner."""
	req = get_obj("Request", request_id)
	past_owner_id = None
	# If there is already an owner, unassign them:
	if req.point_person():
		past_owner_id = req.point_person().id
		past_owner = get_obj("Owner", req.point_person().id)
		update_obj(attribute = "is_point_person", val = False, obj = past_owner)
	owner_id, is_new_owner = add_staff_participant(request_id = request_id, reason = reason, email = email, is_point_person = True)
	if (past_owner_id == owner_id): # Already the current owner, so don't send any e-mails
		return owner_id

	app.logger.info("\n\nA new owner has been assigned: Owner: %s" % owner_id)
	new_owner = get_obj("Owner", owner_id)
	# Update the associated department on request
	update_obj(attribute = "department_id", val = new_owner.user.department_id, obj = req)
	user_id = get_attribute(attribute = "user_id", obj_id = owner_id, obj_type = "Owner")
	# Send notifications
	if is_new_owner:
		generate_prr_emails(request_id = request_id, notification_type = "Request assigned", user_id = user_id)
	return owner_id
Exemplo n.º 24
0
def answer_a_question(qa_id, answer, subscriber_id = None):
	""" A requester can answer a question city staff asked them about their request."""
	request_id = create_answer(qa_id, subscriber_id, answer)
	change_request_status(request_id, "Pending")
	generate_prr_emails(request_id = request_id, notification_type = "Question answered")
Exemplo n.º 25
0
def answer_a_question(qa_id, answer, subscriber_id = None):
	""" A requester can answer a question city staff asked them about their request."""
	request_id = create_answer(qa_id, subscriber_id, answer)
	change_request_status(request_id, "Pending")
	generate_prr_emails(request_id = request_id, notification_type = "Question answered")
Exemplo n.º 26
0
def answer_a_question(qa_id, answer, subscriber_id = None):
	""" A requester can answer a question city staff asked them about their request."""
	request_id = create_answer(qa_id, subscriber_id, answer)
	# We aren't changing the request status if someone's answered a question anymore, but we could
	# change_request_status(request_id, "Pending")
	generate_prr_emails(request_id = request_id, notification_type = "Question answered")