def get_board_email_data(meeting: MeetingData, archive: ArchiveData) -> MailData:
    raw_msg = get_config_value("mail_to_board_message")
    board_name = get_config_value("board_display_name")
    secretary_email = get_config_value("secretary_email")
    msg = raw_msg.format(
        board_name=board_name,
        meeting_number=meeting.meeting_no,
        meeting_lp=meeting.lp,
        meeting_archive_url=archive.get_archive_location(),
        secretary_email=secretary_email
    )
    to = get_config_value("board_email")

    raw_subject = get_config_value("mail_to_board_subject")
    subject = raw_subject.format(
        board_name=board_name,
        meeting_number=meeting.meeting_no,
        meeting_lp=meeting.lp,
        meeting_archive_url=archive.get_archive_location(),
        secretary_email=secretary_email
    )

    return MailData(
        mail_to=to,
        subject=subject,
        msg=msg
    )
def send_email(email_data: MailData) -> bool:
    gotify_auth_key = environ.get("gotify_auth_key", "123abc")

    auth = "pre-shared: " + str(gotify_auth_key)
    url = get_config_value("gotify_url")
    header = {"Authorization": auth, "Accept": "*/*"}
    mail_from = get_config_value("from_email_address")
    data = {
        "to": email_data.mail_to,
        "from": mail_from,
        "subject": email_data.subject,
        "body": email_data.msg
    }
    try:
        r = requests.post(url=url, json=data, headers=header)
        print(
            f"Sent email to {email_data.mail_to}, status code {r.status_code}, reason {r.reason}"
        )
        return True
    except Exception as e:
        print(f"Encountered an error while contacting gotify: {e}")
        return False
def get_archive_url(id_str: str) -> HttpResponse:
    id_res = validate_meeting_id_from_str(id_str)
    if id_res.is_error:
        return get_with_error(400, id_res.message)
    id = id_res.data

    archive_code_res = create_archive(id)
    if archive_code_res.is_error:
        return get_with_error(500, archive_code_res.message)
    archive_code = archive_code_res.data

    base_url = get_config_value("archive_base_url")
    redirect_url = f"{base_url}/{archive_code}"
    print("Should be redirected to {0}".format(redirect_url))
    return get_with_data({"redirect_url": redirect_url})
Beispiel #4
0
def handle_code_request(code_str: str) -> HttpResponse:
    code_res = validate_code(code_str)
    if code_res.is_error:
        return get_with_error(400, code_res.message)

    code_last_upload = get_last_upload_for_code(code_res.data)

    current_date = datetime.utcnow()
    if code_last_upload < current_date:
        secretary_email = get_config_value("secretary_email")
        return get_with_error(401, "Code expired, please contact the secretary at {0}".format(secretary_email))

    data_res = get_data_for_code(code_res.data)
    if data_res.is_error:
        return get_with_error(401, data_res.message)

    return get_with_data({
        "code": code_str,
        "data": data_res.data
    })
Beispiel #5
0
def handle_file_request(code_str: str, files: Dict) -> HttpResponse:
    code_res = validate_code(code_str)
    if code_res.is_error:
        return get_with_error(401, code_res.message)

    code = code_res.data
    group_meeting = get_group_meeting_by_code(code)
    if group_meeting is None:
        secretary_email = get_config_value("secretary_email")
        return get_with_error(
            400, "Code not found! Please contact the secretary at {0}".format(
                secretary_email))

    overwrite = False
    for task in files:
        file_res = handle_file(code, task, files[task])
        if file_res.is_error:
            return get_with_error(400, file_res.message)

        overwrite = file_res.data

    return get_with_data({"overwrite": overwrite})
Beispiel #6
0
 def get_archive_location(self):
     base_path = get_config_value("archive_base_url")
     return f"{base_path}/{self.code}"