Exemple #1
0
def confirm_edit_user_email(service_id, user_id):
    user = current_service.get_team_member(user_id)
    session_key = 'team_member_email_change-{}'.format(user_id)
    if session_key in session:
        new_email = session[session_key]
    else:
        return redirect(
            url_for('.edit_user_email', service_id=service_id,
                    user_id=user_id))
    if request.method == 'POST':
        try:
            user.update(email_address=new_email, updated_by=current_user.id)
        except HTTPError as e:
            abort(500, e)
        else:
            create_email_change_event(user.id, current_user.id,
                                      user.email_address, new_email)
        finally:
            session.pop(session_key, None)

        return redirect(url_for('.manage_users', service_id=service_id))
    return render_template('views/manage-users/confirm-edit-user-email.html',
                           user=user,
                           service_id=service_id,
                           new_email=new_email)
def confirm_edit_user_email(service_id, user_id):
    user = current_service.get_team_member(user_id)
    if "team_member_email_change" in session:
        new_email = session["team_member_email_change"]
    else:
        return redirect(
            url_for(".edit_user_email", service_id=service_id,
                    user_id=user_id))
    if request.method == "POST":
        try:
            user.update(email_address=new_email, updated_by=current_user.id)
        except HTTPError as e:
            abort(500, e)
        else:
            create_email_change_event(user.id, current_user.id,
                                      user.email_address, new_email)
        finally:
            session.pop("team_member_email_change", None)

        return redirect(url_for(".manage_users", service_id=service_id))
    return render_template(
        "views/manage-users/confirm-edit-user-email.html",
        user=user,
        service_id=service_id,
        new_email=new_email,
    )
def test_create_email_change_event_calls_events_api(app_, mock_events):
    user_id = str(uuid.uuid4())
    updated_by_id = str(uuid.uuid4())

    with app_.test_request_context():
        create_email_change_event(user_id, updated_by_id, '*****@*****.**', '*****@*****.**')

        mock_events.assert_called_with('update_user_email',
                                       {'browser_fingerprint':
                                        {'browser': ANY, 'version': ANY, 'platform': ANY, 'user_agent_string': ''},
                                        'ip_address': ANY,
                                        'user_id': user_id,
                                        'updated_by_id': updated_by_id,
                                        'original_email_address': '*****@*****.**',
                                        'new_email_address': '*****@*****.**'})
def test_create_email_change_event_calls_events_api(app_, mock_events):
    user_id = str(uuid.uuid4())
    updated_by_id = str(uuid.uuid4())

    with app_.test_request_context(environ_base={"REMOTE_ADDR": "1.2.3.4"}):
        create_email_change_event(user_id, updated_by_id,
                                  "*****@*****.**", "*****@*****.**")

        mock_events.assert_called_with(
            "update_user_email",
            {
                "browser_fingerprint": {
                    "browser": ANY,
                    "version": ANY,
                    "platform": ANY,
                    "user_agent_string": "",
                },
                "ip_address": "1.2.3.4",
                "user_id": user_id,
                "updated_by_id": updated_by_id,
                "original_email_address": "*****@*****.**",
                "new_email_address": "*****@*****.**",
            },
        )