Example #1
0
def test_email_template(template_id):
    email_template = EmailTemplate.get_template(template_id)
    if email_template:
        course = SisSection.get_course(term_id=app.config['CURRENT_TERM_ID'],
                                       section_id='12597')
        template = EmailTemplate.get_template(template_id)
        subject_line = interpolate_email_content(
            course=course,
            recipient_name=current_user.name,
            templated_string=template.subject_line,
        )
        message = interpolate_email_content(
            course=course,
            recipient_name=current_user.name,
            templated_string=template.message,
        )
        BConnected().send(
            recipients=[
                {
                    'email': current_user.email_address,
                    'name': current_user.name,
                    'uid': current_user.uid,
                },
            ],
            message=message,
            subject_line=subject_line,
        )
        return tolerant_jsonify(
            {'message': f'Email sent to {current_user.email_address}'}), 200
    else:
        raise ResourceNotFoundError('No such email_template')
def test_email_template(template_id):
    email_template = EmailTemplate.get_template(template_id)
    if email_template:
        course = SisSection.get_random_co_taught_course(app.config['CURRENT_TERM_ID'])
        template = EmailTemplate.get_template(template_id)
        publish_types = get_all_publish_types()
        recording_types = get_all_recording_types()

        def _get_interpolated_content(templated_string):
            return interpolate_content(
                course=course,
                pending_instructors=course['instructors'],
                previous_publish_type_name=NAMES_PER_PUBLISH_TYPE[publish_types[0]],
                previous_recording_type_name=NAMES_PER_RECORDING_TYPE[recording_types[0]],
                publish_type_name=NAMES_PER_PUBLISH_TYPE[publish_types[1]],
                recording_type_name=NAMES_PER_RECORDING_TYPE[recording_types[1]],
                recipient_name=current_user.name,
                templated_string=templated_string,
            )
        BConnected().send(
            recipient={
                'email': current_user.email_address,
                'name': current_user.name,
                'uid': current_user.uid,
            },
            message=_get_interpolated_content(template.message),
            subject_line=_get_interpolated_content(template.subject_line),
        )
        return tolerant_jsonify({'message': f'Email sent to {current_user.email_address}'}), 200
    else:
        raise ResourceNotFoundError('No such email_template')
Example #3
0
 def test_authorized(self, client, admin_session):
     """Admin user has access."""
     email_template_id = 1
     email_template = EmailTemplate.get_template(email_template_id)
     name = f'{email_template.name} (modified)'
     email_template = self._api_update_email_template(
         client,
         email_template_id=email_template.id,
         template_type=email_template.template_type,
         name=name,
         subject_line=email_template.subject_line,
         message=email_template.message,
     )
     assert len(email_template)
     assert email_template['name'] == name
def update_template():
    params = request.get_json()
    template_id = params.get('templateId')
    email_template = EmailTemplate.get_template(template_id) if template_id else None
    if email_template:
        template_type = params.get('templateType')
        name = params.get('name')
        subject_line = params.get('subjectLine')
        message = params.get('message')

        if None in [template_type, name, subject_line, message]:
            raise BadRequestError('Required parameters are missing.')

        email_template = EmailTemplate.update(
            template_id=template_id,
            template_type=template_type,
            name=name,
            subject_line=subject_line,
            message=message,
        )
        return tolerant_jsonify(email_template.to_api_json())
    else:
        raise ResourceNotFoundError('No such email template')
Example #5
0
def get_email_template(template_id):
    email_template = EmailTemplate.get_template(template_id)
    if email_template:
        return tolerant_jsonify(email_template.to_api_json())
    else:
        raise ResourceNotFoundError('No such email_template')