Пример #1
0
 def _process_notification(self, users, scheduler):
     for username in users:
         logger.info(f"Sending due deletion {scheduler} to user",
                     username=obfuscate_email(username))
         NotifyService().request_to_notify(template_name=scheduler,
                                           email=username)
         logger.info(f"Due deletion {scheduler} sent to user",
                     username=obfuscate_email(username))
         self._update_user(username, scheduler)
Пример #2
0
def patch_account(username):
    """
    Patch endpoint for user resource.
    Currently only marked_for_deletion, first_notification, second_notification and third_notification
     attribute can be patched
    @param: username
    """
    logger.info("Starting patch operation on user",
                username=obfuscate_email(username))
    req = request.form
    try:
        patch_data = patch_account_schema.load(req)
    except ValidationError as ex:
        logger.exception("Patch data validation error", exc_info=ex)
        return make_response(
            jsonify({
                "title": "Bad Request error in Auth service",
                "detail": "Patch data validation failed"
            }), 400)
    try:
        with transactional_session() as session:
            user = session.query(User).filter(
                func.lower(User.username) == username.lower()).one()
            user.patch_user(patch_data)

    except NoResultFound:
        logger.error("User does not exist", username=obfuscate_email(username))
        return make_response(
            jsonify({
                "title": "Auth service undo delete user error",
                "detail": "This user does not exist on the Auth server",
            }),
            404,
        )
    except SQLAlchemyError:
        logger.exception("Unable to commit undo delete operation",
                         username=obfuscate_email(username))
        return make_response(
            jsonify({
                "title": "Auth service undo delete user error",
                "detail": "Unable to commit undo delete operation"
            }),
            500,
        )

    logger.info("Successfully completed patch operation on user",
                username=obfuscate_email(username))
    return "", 204
Пример #3
0
def delete_account():
    """
    Updates user data to be marked for deletion.
    """
    params = request.form
    try:
        username = params["username"]
        logger.info("Deleting user", username=obfuscate_email(username))
        with transactional_session() as session:
            user = session.query(User).filter(
                func.lower(User.username) == username.lower()).one()
            user.mark_for_deletion = True
            if "force_delete" in params.keys():
                user.force_delete = strtobool(params["force_delete"])
            session.commit()
    except KeyError:
        logger.exception("Missing request parameter")
        return make_response(
            jsonify({
                "title": "Auth service delete user error",
                "detail": "Missing 'username'"
            }), 400)
    except NoResultFound:
        logger.error("User does not exist", username=obfuscate_email(username))
        return make_response(
            jsonify({
                "title": "Auth service delete user error",
                "detail": "This user does not exist on the Auth server"
            }),
            404,
        )

    except SQLAlchemyError:
        logger.exception("Unable to commit delete operation",
                         username=obfuscate_email(username))
        return make_response(
            jsonify({
                "title": "Auth service delete user error",
                "detail": "Unable to commit delete operation"
            }), 500)

    logger.info("Successfully deleted user",
                username=obfuscate_email(username))
    return "", 204
Пример #4
0
 def _update_user(self, user, scheduler_column):
     logger.info('Updating user data with notification sent date',
                 notification=scheduler_column)
     form_data = {scheduler_column: datetime.utcnow()}
     try:
         requests.patch(f'{self.patch_url}/{user}',
                        data=form_data,
                        headers=self.headers)
     except requests.exceptions.HTTPError as error:
         logger.exception("Unable to update user notification date",
                          username=obfuscate_email(user),
                          error=error)
         raise error
     logger.info('user data with notification sent date updated',
                 notification=scheduler_column)
Пример #5
0
def get_account_by_user_name(username):
    """
    Get user data.
    """
    try:
        with transactional_session() as session:
            user = session.query(User).filter(
                func.lower(User.username) == username.lower()).one()
    except NoResultFound:
        logger.info("User does not exist", username=obfuscate_email(username))
        return make_response(
            jsonify({
                "title": "Auth service get user error",
                "detail": "This user does not exist on the Auth server"
            }), 404)
    return jsonify(user.to_user_dict())
def delete_party_respondents_and_auth_user(users, session):
    for user in users:
        try:
            url = f'{app.config["PARTY_URL"]}/party-api/v1/respondents/{user.username}'
            response = requests.delete(url, auth=app.config["BASIC_AUTH"])
            if response.status_code != 500:
                logger.info(
                    "Successfully sent request to party service for user deletion",
                    status_code=response.status_code)
                session.delete(user)
                logger.info("user successfully deleted",
                            email=obfuscate_email(user.username))
            else:
                logger.error(
                    "party returned error can't proceed with user deletion",
                    status_code=response.status_code)
        except (SQLAlchemyError, Exception):
            logger.exception(
                "Unexpected error can't proceed with user deletion.")
Пример #7
0
    def test_obfuscate_email(self):
        """Test obfuscate email correctly changes inputted emails"""

        # TODO fix function for bottom scenario
        test_scenarios = [
            ["*****@*****.**", "e*****e@e*********m"],
            ["*****@*****.**", "p****x@d**********k"],
            ["*****@*****.**", "f********e@p**********k"],
            ["*****@*****.**", "m*********n@g*******m"],
            ["*****@*****.**", "a***********e@e*********m"],
            [
                "*****@*****.**",
                "j**************6@l****************k"
            ],
            ["[email protected]", "m**?@e*********m"],
            ["*****@*****.**", "m@m***m"],
        ]

        for scenario in test_scenarios:
            self.assertEqual(obfuscate_email(scenario[0]), scenario[1])
Пример #8
0
 def test_obfuscate_email(email, obfuscated_email):
     """Test obfuscate email correctly changes inputted emails"""
     assert obfuscate_email(email) == obfuscated_email