def get(self):
        """Return a single user with id `user_id`."""
        parser = reqparse.RequestParser()
        parser.add_argument("Authorization", location="headers")
        parser.add_argument("nextPage", type=str)
        parser.add_argument("primaryEmail", type=str)
        parser.add_argument("filterDisplay", type=str)
        args = parser.parse_args()

        filter_display = args.get("filterDisplay", None)
        primary_email = args.get("primaryEmail", None)
        next_page = args.get("nextPage", None)
        scopes = get_scopes(args.get("Authorization"))

        if next_page is not None:
            nextPage = load_dirty_json(next_page)
        else:
            nextPage = None

        if transactions == "false":
            identity_vault = user.Profile(dynamodb_table, dynamodb_client, transactions=False)

        if transactions == "true":
            identity_vault = user.Profile(dynamodb_table, dynamodb_client, transactions=True)

        next_page_token = None
        if primary_email is None:
            result = identity_vault.all_by_page(next_page=nextPage, limit=25)
            next_page_token = result.get("LastEvaluatedKey")
        else:
            result = identity_vault.find_by_email(primary_email)
        v2_profiles = []

        for profile in result.get("Items"):
            vault_profile = json.loads(profile.get("profile"))
            v2_profile = User(user_structure_json=vault_profile)
            if "read:fullprofile" in scopes:
                # Assume someone has asked for all the data.
                logger.info(
                    "The provided token has access to all of the data.", extra={"query_args": args, "scopes": scopes}
                )
                pass
            else:
                # Assume the we are filtering falls back to public with no scopes
                logger.info("This is a limited scoped query.", extra={"query_args": args, "scopes": scopes})
                v2_profile.filter_scopes(scope_to_mozilla_data_classification(scopes))

            if "display:all" in scopes:
                logger.info("display:all in token not filtering profile.", extra={"query_args": args, "scopes": scopes})
            else:
                logger.info("display filtering engaged for query.", extra={"query_args": args, "scopes": scopes})
                v2_profile.filter_display(scope_to_display_level(scopes))

            if filter_display is not None:
                v2_profile.filter_display(DisplayLevelParms.map(filter_display))

            v2_profiles.append(v2_profile.as_dict())

        response = {"Items": v2_profiles, "nextPage": next_page_token}
        return jsonify(response)
Esempio n. 2
0
def getUser(id, find_by):
    """Return a single user with identifier using find_by."""
    id = urllib.parse.unquote(id)
    parser = reqparse.RequestParser()
    parser.add_argument("Authorization", location="headers")
    parser.add_argument("filterDisplay", type=str)
    parser.add_argument("active", type=str)
    args = parser.parse_args()
    scopes = get_scopes(args.get("Authorization"))
    filter_display = args.get("filterDisplay", None)

    if args.get("active") is not None and args.get("active").lower() == "false":
        active = False
    elif args.get("active") is not None and args.get("active").lower() == "any":
        active = None
    else:
        active = True

    if transactions == "false":
        identity_vault = user.Profile(dynamodb_table, dynamodb_client, transactions=False)

    if transactions == "true":
        identity_vault = user.Profile(dynamodb_table, dynamodb_client, transactions=True)

    result = find_by(identity_vault, id)

    if len(result["Items"]) > 0:
        vault_profile = result["Items"][0]["profile"]
        v2_profile = User(user_structure_json=json.loads(vault_profile))

        if v2_profile.active.value == active or active is None:
            if "read:fullprofile" in scopes:
                logger.debug(
                    "read:fullprofile in token not filtering based on scopes.",
                    extra={"query_args": args, "scopes": scopes},
                )
            else:
                v2_profile.filter_scopes(scope_to_mozilla_data_classification(scopes))

            if "display:all" in scopes:
                logger.debug(
                    "display:all in token not filtering profile based on display.",
                    extra={"query_args": args, "scopes": scopes},
                )
            else:
                v2_profile.filter_display(scope_to_display_level(scopes))

            if filter_display is not None:
                logger.debug(
                    "filter_display argument is passed, applying display level filter.", extra={"query_args": args}
                )
                v2_profile.filter_display(DisplayLevelParms.map(filter_display))

            return jsonify(v2_profile.as_dict())

    logger.debug("No user was found for the query", extra={"query_args": args, "scopes": scopes})
    return jsonify({})
Esempio n. 3
0
def getUser(id, find_by):
    """Return a single user with identifier using find_by."""
    id = urllib.parse.unquote(id)
    parser = reqparse.RequestParser()
    parser.add_argument("Authorization", location="headers")
    parser.add_argument("filterDisplay", type=str)
    args = parser.parse_args()
    scopes = get_scopes(args.get("Authorization"))
    filter_display = args.get("filterDisplay", None)

    if transactions == "false":
        identity_vault = user.Profile(dynamodb_table,
                                      dynamodb_client,
                                      transactions=False)

    if transactions == "true":
        identity_vault = user.Profile(dynamodb_table,
                                      dynamodb_client,
                                      transactions=True)

    result = find_by(identity_vault, id)

    if len(result["Items"]) > 0:
        vault_profile = result["Items"][0]["profile"]
        v2_profile = User(user_structure_json=json.loads(vault_profile))
        if "read:fullprofile" in scopes:
            logger.debug(
                "read:fullprofile in token returning the full user profile.")
        else:
            v2_profile.filter_scopes(
                scope_to_mozilla_data_classification(scopes))

        if "display:all" in scopes:
            logger.debug("display:all in token not filtering profile.")
        else:
            v2_profile.filter_display(scope_to_display_level(scopes))

        if filter_display is not None:
            v2_profile.filter_display(DisplayLevelParms.map(filter_display))

        return jsonify(v2_profile.as_dict())
    else:
        return jsonify({})
Esempio n. 4
0
    def get(self):
        """Return a single user with id `user_id`."""
        parser = reqparse.RequestParser()
        parser.add_argument("Authorization", location="headers")
        parser.add_argument("nextPage", type=str)
        parser.add_argument("primaryEmail", type=str)
        parser.add_argument("filterDisplay", type=str)
        parser.add_argument("active", type=str)

        args = parser.parse_args()

        filter_display = args.get("filterDisplay", None)
        primary_email = args.get("primaryEmail", None)
        next_page = args.get("nextPage", None)
        scopes = get_scopes(args.get("Authorization"))

        logger.info(
            f"Attempting to get paginated users: primary_email:{primary_email}, next_page:{next_page}, "
            "filter_display:{filter_display}, scopes:{scopes}")

        if next_page is not None:
            nextPage = load_dirty_json(next_page)
        else:
            nextPage = None

        if transactions == "false":
            identity_vault = user.Profile(dynamodb_table,
                                          dynamodb_client,
                                          transactions=False)

        if transactions == "true":
            identity_vault = user.Profile(dynamodb_table,
                                          dynamodb_client,
                                          transactions=True)

        next_page_token = None
        if primary_email is None:
            result = identity_vault.all_by_page(next_page=nextPage)
            next_page_token = result.get("LastEvaluatedKey")
        else:
            result = identity_vault.find_by_email(primary_email)
        v2_profiles = []

        if args.get("active") is not None and args.get(
                "active").lower() == "false":
            active = False
        else:
            active = True  # Support returning only active users by default.

        for profile in result.get("Items"):
            vault_profile = json.loads(profile.get("profile"))
            v2_profile = User(user_structure_json=vault_profile)

            # This must be a pre filtering check because mutation is real.
            if v2_profile.active.value == active:
                allowed_in_list = True
            else:
                allowed_in_list = False

            if "read:fullprofile" in scopes:
                # Assume someone has asked for all the data.
                logger.debug(
                    "The provided token has access to all of the data.",
                    extra={
                        "query_args": args,
                        "scopes": scopes
                    })
                pass
            else:
                # Assume the we are filtering falls back to public with no scopes
                logger.debug("This is a limited scoped query.",
                             extra={
                                 "query_args": args,
                                 "scopes": scopes
                             })
                v2_profile.filter_scopes(
                    scope_to_mozilla_data_classification(scopes))

            if "display:all" in scopes:
                logger.debug("display:all in token not filtering profile.",
                             extra={
                                 "query_args": args,
                                 "scopes": scopes
                             })
            else:
                logger.debug("display filtering engaged for query.",
                             extra={
                                 "query_args": args,
                                 "scopes": scopes
                             })
                v2_profile.filter_display(scope_to_display_level(scopes))

            if filter_display is not None:
                v2_profile.filter_display(
                    DisplayLevelParms.map(filter_display))

            if allowed_in_list:
                v2_profiles.append(v2_profile.as_dict())
            else:
                logger.debug(
                    "Skipping adding this profile to the list of profiles because it is: {}"
                    .format(active))
                pass

        response = {"Items": v2_profiles, "nextPage": next_page_token}
        return jsonify(response)