示例#1
0
def get_workshop_emails(workshop_id):
    # Well, I could use aggregation, but it is not implemented in mongomock :(
    data = get_db().workshops.find_one({"workshopId": workshop_id}, {"emails.emailId": 0})

    if data is None:
        return error_response("Workshop %s not found" % workshop_id), 404

    emails = [EmailMessage.from_db_dict(email).as_response() for email in data['emails']]
    json_data = jsonify(emails=emails)
    return json_data
示例#2
0
def accept_incoming_emails():
    email_address = request.form['recipient']
    email = EmailMessage(
        email_id=generate_email_id(),
        sender=request.form['from'],
        subject=request.form['subject'],
        text=request.form.get('body-plain'),
        html=request.form.get('body-html')
    )
    workshop_secret = get_workshop_secret_from_email_address(email_address)
    workshop = get_db().workshops.find_and_modify(
        query={"emailSecret": workshop_secret},
        update={"$push": {"emails": email.as_db_dict()}}
    )
    if workshop is None:
        return error_response("Workshop not found"), 404  # TODO send reply that invalid email was sent?

    ensure_mails_were_sent_to_users([email], workshop['users'], workshop)
    ensure_mail_were_sent_to_mentors(email, workshop['mentors'], workshop)
    return success_response("Email processed.")
示例#3
0
def accept_incoming_emails():
    email_address = request.form['recipient']
    email = EmailMessage(email_id=generate_email_id(),
                         sender=request.form['from'],
                         subject=request.form['subject'],
                         text=request.form.get('body-plain'),
                         html=request.form.get('body-html'))
    workshop_secret = get_workshop_secret_from_email_address(email_address)
    workshop = get_db().workshops.find_and_modify(
        query={"emailSecret": workshop_secret},
        update={"$push": {
            "emails": email.as_db_dict()
        }})
    if workshop is None:
        return error_response(
            "Workshop not found"
        ), 404  # TODO send reply that invalid email was sent?

    ensure_mails_were_sent_to_users([email], workshop['users'], workshop)
    ensure_mail_were_sent_to_mentors(email, workshop['mentors'], workshop)
    return success_response("Email processed.")
示例#4
0
def get_workshop_emails(workshop_id):
    # Well, I could use aggregation, but it is not implemented in mongomock :(
    data = get_db().workshops.find_one({"workshopId": workshop_id},
                                       {"emails.emailId": 0})

    if data is None:
        return error_response("Workshop %s not found" % workshop_id), 404

    emails = [
        EmailMessage.from_db_dict(email).as_response()
        for email in data['emails']
    ]
    json_data = jsonify(emails=emails)
    return json_data
示例#5
0
def register_new_user_for_workshop(workshop_id, attender_email):
    user = get_db().users.find_one({"email": attender_email})
    if user is None:
        return error_response("User %s not found" % attender_email), 412
    elif user['isConfirmed'] is not True:
        return error_response("User %s not confirmed" % attender_email), 412

    workshop = get_db().workshops.find_and_modify(
        query={"workshopId": workshop_id},
        update={"$addToSet": {"users": attender_email}}
    )
    if workshop is None:
        return error_response("Workshop %s not found" % workshop_id), 404
    if attender_email in workshop['users']:
        return error_response("User %s is already registered for %s" % (attender_email, workshop_id)), 304
    workshop['emails'] = [EmailMessage.from_db_dict(e) for e in workshop['emails']]
    ensure_mails_were_sent_to_users(workshop['emails'], [attender_email], workshop)
    return success_response("User %s registered for %s" % (attender_email, workshop_id)), 200
示例#6
0
def register_new_user_for_workshop(workshop_id, attender_email):
    user = get_db().users.find_one({"email": attender_email})
    if user is None:
        return error_response("User %s not found" % attender_email), 412
    elif user['isConfirmed'] is not True:
        return error_response("User %s not confirmed" % attender_email), 412

    workshop = get_db().workshops.find_and_modify(
        query={"workshopId": workshop_id},
        update={"$addToSet": {
            "users": attender_email
        }})
    if workshop is None:
        return error_response("Workshop %s not found" % workshop_id), 404
    if attender_email in workshop['users']:
        return error_response("User %s is already registered for %s" %
                              (attender_email, workshop_id)), 304
    workshop['emails'] = [
        EmailMessage.from_db_dict(e) for e in workshop['emails']
    ]
    ensure_mails_were_sent_to_users(workshop['emails'], [attender_email],
                                    workshop)
    return success_response("User %s registered for %s" %
                            (attender_email, workshop_id)), 200
示例#7
0
 def send_email(self):
     "Send email"
     email = EmailMessage(self)
     if self.stream and self.stream.outgoing_server_name:
         email.send_email()
import mongomock
from emails import EmailMessage

import flaskr

NAME = "Jan Kowalski"
EMAIL_ADDRESS = "*****@*****.**"
TEST_KEY = "TEST_KEY"
FIRST_MAIL_SUBJECT = "Introduction to test workshop"
SECOND_MAIL_SUBJECT = "Link to repository"
WORKSHOP_ID = "test_workshop"
WORKSHOP_EMAIL_SECRET = "tajny-kod"
CURRENT_DATE = datetime.datetime(2007, 12, 6, 16, 29, 43, 79043)
EMAIL_MESSAGE = EmailMessage(FIRST_MAIL_SUBJECT,
                             "text",
                             sender="*****@*****.**",
                             date=CURRENT_DATE,
                             email_id=1)


def user_in_db(confirmed=False):
    return {
        "email": EMAIL_ADDRESS,
        "name": NAME,
        "key": TEST_KEY,
        "isConfirmed": confirmed,
        "emails": []
    }


def workshop_in_db(with_user, with_mail):