Beispiel #1
0
def token():
    """Generate an authorization token."""
    # Currently, we only support a single user.
    with database() as conn:
        if usr := user.from_id(1, conn):
            token = user.new_token(usr, conn)
        else:
Beispiel #2
0
async def test_update_user(db, graphql_query, snapshot):
    query = """
        mutation {
            updateUser(nickname: "not admin") {
                ...UserFields
            }
        }
    """

    success, data = await graphql_query(query)
    assert success is True
    snapshot.assert_match(data)
    assert user.from_id(1, db).nickname == "not admin"
Beispiel #3
0
def _check_session_auth(csrf: bool) -> bool:
    """
    Check to see if the current request has valid session authentication. If ``csrf`` is
    set, validate the CSRF header as well.

    If it is valid, set `quart.g.user` and return ``True``, otherwise return ``False``.

    :param csrf: Whether to validate the CSRF header.
    :return: Whether current request has valid session authentication.
    """
    try:
        quart.g.user = user.from_id(  # type: ignore
            quart.session["user_id"],
            quart.g.db,
        )
    except KeyError:
        return False

    if quart.g.user and csrf and not _check_csrf():
        quart.abort(400)

    return bool(quart.g.user)
Beispiel #4
0
    async def executor(query):
        used_fragments = "\n".join(v for k, v in FRAGMENTS.items()
                                   if k in query)
        query = f"{query}\n{used_fragments}"

        async with quart_app.test_request_context("/testing", method="GET"):
            with database() as conn:
                return await graphql(
                    schema=schema,
                    data={
                        "operationName": None,
                        "variables": {},
                        "query": query
                    },
                    context_value=GraphQLContext(
                        user=user.from_id(1, conn),  # type: ignore
                        db=conn,
                        request=quart.request,
                    ),
                    error_formatter=error_formatter,
                    debug=False,
                )
Beispiel #5
0
def resolve_used_by(obj: invite.T, info: GraphQLResolveInfo) -> Optional[user.T]:
    return user.from_id(obj.used_by, info.context.db) if obj.used_by else None
Beispiel #6
0
def resolve_created_by(obj: invite.T, info: GraphQLResolveInfo) -> user.T:
    usr = user.from_id(obj.created_by, info.context.db)
    assert usr is not None
    return usr
Beispiel #7
0
def resolve_user(obj: playlist.T,
                 info: GraphQLResolveInfo) -> Optional[libuser.T]:
    if obj.user_id is None:
        return None

    return libuser.from_id(obj.user_id, info.context.db)