Coverage for seedboxsync/front/apis/users.py: 89%
18 statements
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-26 17:14 +0000
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-26 17:14 +0000
1#
2# Copyright (C) 2015-2026 Guillaume Kulakowski <guillaume@kulakowski.fr>
3#
4# For the full copyright and license information, please view the LICENSE
5# file that was distributed with this source code.
6#
7"""SeedboxSync api uploads view."""
9from typing import Any
10from flask_login import current_user
11from flask_restx import Namespace, fields
12from seedboxsync.front.apis import Resource
13from seedboxsync.front.login_manager import login_required
15api = Namespace("users", description="Operations related to users")
18# ==========================
19# Models
20# ==========================
21user_model = api.model(
22 "User",
23 {
24 "id": fields.Integer(
25 required=True,
26 description="Unique identifier of the user",
27 example=99,
28 ),
29 "username": fields.String(required=True, description="User username", example="me"),
30 "email": fields.String(
31 required=True,
32 description="User email",
33 example="me@domain.ltd",
34 ),
35 },
36)
37user_list_envelope = Resource.build_envelope_model(api, "UserList", nested_model=user_model)
38user_envelope = Resource.build_envelope_model(api, "User", nested_model=user_model, as_list=False)
39user_message_envelope = Resource.build_envelope_model(api, "UserMessage", as_message=True)
42# ==========================
43# Endpoints
44# ==========================
45@api.route("/me")
46class Me(Resource):
47 """API Resource for retrieving details about the authenticated user."""
49 @api.doc("list_uploads") # type: ignore[untyped-decorator]
50 @api.marshal_with(user_envelope, code=200, skip_none=True, description="List of uploaded torrents") # type: ignore[untyped-decorator]
51 @login_required # type: ignore[untyped-decorator]
52 def get(self) -> dict[str, Any]:
53 """
54 Get current authenticated user profile information.
56 Returns:
57 dict[str, int | str]: A dictionary containing the current user's ID and username.
58 """
59 user = {
60 "id": current_user.id,
61 "username": current_user.username,
62 "email": current_user.email,
63 }
65 return self.build_envelope(user, type="User")