Users API reference
Users
User module for user account management and authentication.
This module provides comprehensive user management including account creation, profile updates, authentication, MFA support, email verification, and admin approval workflows.
Exports
- CRUD: get_all_users, get_users_number, get_users_with_pagination, get_user_by_username, get_user_by_email, get_user_by_id, get_users_admin, create_user, create_signup_user, edit_user, approve_user, verify_user_email, update_user_photo, delete_user
- Schemas: UsersBase, Users, UsersRead, UsersMe, UsersSignup, UsersCreate, UsersEditPassword, UsersListResponse
- Enums: Gender, Language, WeekDay, UserAccessType
- Utils: get_user_by_id_or_404, get_admin_users_or_404, check_user_is_active, create_user_default_data, save_user_image_file, delete_user_photo_filesystem
Gender
Bases: Enum
User gender enumeration.
Attributes:
| Name | Type | Description |
|---|---|---|
MALE |
Male gender. |
|
FEMALE |
Female gender. |
|
UNSPECIFIED |
Unspecified or undisclosed gender. |
Source code in backend/app/modules/users/users/schema.py
21 22 23 24 25 26 27 28 29 30 31 32 33 | |
Language
Bases: Enum
Supported application languages.
Attributes:
| Name | Type | Description |
|---|---|---|
CATALAN |
Catalan (ca). |
|
CHINESE_SIMPLIFIED |
Simplified Chinese (zh-Hans). |
|
CHINESE_TRADITIONAL |
Traditional Chinese (zh-Hant). |
|
GERMAN |
German (de). |
|
FRENCH |
French (fr). |
|
GALICIAN |
Galician (gl). |
|
ITALIAN |
Italian (it). |
|
DUTCH |
Dutch (nl). |
|
PORTUGUESE |
Portuguese (pt-PT). |
|
SLOVENIAN |
Slovenian (sl). |
|
SWEDISH |
Swedish (sv). |
|
SPANISH |
Spanish (es). |
|
ENGLISH |
English (en). |
|
POLISH |
Polish (pl). |
|
TURKISH |
Turkish (tr). |
|
UKRAINIAN |
Ukrainian (uk). |
|
ROMANIAN |
Romanian (ro). |
|
NORWEGIAN |
Norwegian Bokmål (nb). |
|
DANISH |
Danish (da). |
|
FINNISH |
Finnish (fi). |
|
CZECH |
Czech (cs). |
|
GREEK |
Greek (el). |
|
HUNGARIAN |
Hungarian (hu). |
|
BULGARIAN |
Bulgarian (bg). |
|
CROATIAN |
Croatian (hr). |
|
SERBIAN |
Serbian (sr). |
|
SLOVAK |
Slovak (sk). |
|
LITHUANIAN |
Lithuanian (lt). |
|
LATVIAN |
Latvian (lv). |
|
ESTONIAN |
Estonian (et). |
Source code in backend/app/modules/users/users/schema.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
UserAccessType
Bases: Enum
User access level enumeration.
Attributes:
| Name | Type | Description |
|---|---|---|
REGULAR |
Standard user access. |
|
ADMIN |
Administrative access. |
Source code in backend/app/modules/users/users/schema.py
128 129 130 131 132 133 134 135 136 137 138 | |
Users
Bases: UsersBase
Complete users schema with administrative fields.
Note
mfa_secret is intentionally NOT part of any API-facing
schema. It lives only on the SQLAlchemy model and is
accessed directly by MFA verification utilities. Including
it in a Pydantic schema would risk leaking the encrypted
seed through responses, exports, logs, or future
model_dump callers.
Attributes:
| Name | Type | Description |
|---|---|---|
access_type |
UserAccessType
|
User access level. |
photo_path |
StrictStr | None
|
Servable URL of the user's photo, resolved from the stored storage key. Read-only: writes are ignored. |
active |
StrictBool
|
Whether the user is active. |
mfa_enabled |
StrictBool
|
Whether MFA is enabled. |
email_verified |
StrictBool
|
Whether email is verified. |
pending_admin_approval |
StrictBool
|
Whether pending admin approval. |
Source code in backend/app/modules/users/users/schema.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
UsersBase
Bases: BaseModel
Base users schema with common fields.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
StrictStr
|
User's full name (1-250 chars). |
username |
StrictStr
|
Unique username (1-250 chars, alphanumeric and dots). |
email |
EmailStr
|
User's email address (max 250 chars). |
city |
StrictStr | None
|
User's city (max 250 chars). |
birthdate |
date | None
|
User's birthdate. |
preferred_language |
Language
|
Preferred language. |
gender |
Gender
|
User's gender. |
units |
Units
|
User units (metric, imperial). |
height |
StrictInt | None
|
User's height in centimeters (1-300). |
max_heart_rate |
StrictInt | None
|
Maximum heart rate in bpm (30-250). |
first_day_of_week |
WeekDay
|
First day of the week. |
currency |
Currency
|
User currency (euro, dollar, pound). |
timezone |
StrictStr | None
|
IANA timezone the athlete lives in. |
Source code in backend/app/modules/users/users/schema.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
validate_birthdate
classmethod
validate_birthdate(value)
Convert birthdate to ISO format string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
date | str | None
|
Birthdate as date object, string, or None. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
ISO format date string or None. |
Source code in backend/app/modules/users/users/schema.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
UsersCreate
Bases: Users
Users schema for admin user creation.
Attributes:
| Name | Type | Description |
|---|---|---|
password |
StrictStr
|
User's password (min 8 chars). |
Source code in backend/app/modules/users/users/schema.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
UsersEditPassword
Bases: BaseModel
Schema for password update operations (self-service).
Requires the caller to prove possession of the current password — and an MFA code when MFA is enabled — before the new password is accepted. This prevents a stolen in-memory access token from being parlayed into permanent account takeover.
Attributes:
| Name | Type | Description |
|---|---|---|
current_password |
StrictStr
|
Caller's existing password. |
password |
StrictStr
|
New password (min 8 chars). |
mfa_code |
StrictStr | None
|
TOTP or backup code, required when MFA is enabled on the account. |
Source code in backend/app/modules/users/users/schema.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 | |
UsersListResponse
Bases: BaseModel
Response model for paginated user listing.
Attributes:
| Name | Type | Description |
|---|---|---|
total |
StrictInt
|
Total number of user records. |
num_records |
StrictInt | None
|
Number of records in this response. |
page_number |
StrictInt | None
|
Current page number. |
records |
list[UsersRead]
|
List of user records. |
Source code in backend/app/modules/users/users/schema.py
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 | |
UsersMe
Bases: UsersRead
Extended users schema for current user profile.
Includes privacy settings and integration status.
Attributes:
| Name | Type | Description |
|---|---|---|
is_strava_linked |
StrictInt | None
|
Strava integration status. |
is_garminconnect_linked |
StrictInt | None
|
Garmin Connect status. |
default_activity_visibility |
StrictStr | None
|
Default visibility level. |
hide_activity_start_time |
StrictBool | None
|
Hide start time setting. |
hide_activity_location |
StrictBool | None
|
Hide location setting. |
hide_activity_map |
StrictBool | None
|
Hide map setting. |
hide_activity_hr |
StrictBool | None
|
Hide heart rate setting. |
hide_activity_power |
StrictBool | None
|
Hide power setting. |
hide_activity_cadence |
StrictBool | None
|
Hide cadence setting. |
hide_activity_elevation |
StrictBool | None
|
Hide elevation setting. |
hide_activity_speed |
StrictBool | None
|
Hide speed setting. |
hide_activity_pace |
StrictBool | None
|
Hide pace setting. |
hide_activity_laps |
StrictBool | None
|
Hide laps setting. |
hide_activity_workout_sets_steps |
StrictBool | None
|
Hide workout sets/steps. |
hide_activity_gear |
StrictBool | None
|
Hide gear setting. |
has_local_password |
StrictBool | None
|
Whether the account has a local password (False for SSO-only accounts). |
Source code in backend/app/modules/users/users/schema.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
UsersRead
Bases: Users
Users schema for read operations.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
StrictInt
|
User ID. |
external_auth_count |
StrictInt
|
Number of external auth providers. |
Source code in backend/app/modules/users/users/schema.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |
UsersSignup
Bases: UsersBase
Users schema for signup operations.
Attributes:
| Name | Type | Description |
|---|---|---|
password |
StrictStr
|
User's password (min 8 chars). |
Source code in backend/app/modules/users/users/schema.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 | |
WeekDay
Bases: Enum
Days of the week enumeration.
Attributes:
| Name | Type | Description |
|---|---|---|
SUNDAY |
Sunday. |
|
MONDAY |
Monday. |
|
TUESDAY |
Tuesday. |
|
WEDNESDAY |
Wednesday. |
|
THURSDAY |
Thursday. |
|
FRIDAY |
Friday. |
|
SATURDAY |
Saturday. |
Source code in backend/app/modules/users/users/schema.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
approve_user
approve_user(user_id, db)
Approve a user by marking them as active.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
ID of user to approve. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if user not found. |
HTTPException
|
400 if user email not verified. |
HTTPException
|
500 if database error occurs. |
Source code in backend/app/modules/users/users/crud.py
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 | |
check_user_is_active
check_user_is_active(user)
Check if user is active and raise 403 if inactive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
UsersRead
|
User object to check (UsersRead schema). |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
403 if user is not active. |
Source code in backend/app/modules/users/users/utils.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
create_signup_user
create_signup_user(user, server_settings, identity_service, db, persist_credential=True)
Create a new user during signup process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
UsersSignup
|
User signup data. |
required |
server_settings
|
ServerSettingsRead
|
Server config for signup requirements. |
required |
identity_service
|
IdentityService
|
Identity service dependency. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
persist_credential
|
bool
|
When |
True
|
Returns:
| Type | Description |
|---|---|
UsersRead
|
Created user schema. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
409 if email/username already exists. Abstract message to reduce information leakage. |
HTTPException
|
500 if database error occurs. |
Source code in backend/app/modules/users/users/crud.py
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 | |
create_user
create_user(user, identity_service, db)
Create a new user with hashed password.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
UsersCreate
|
User creation data with plain text password. |
required |
identity_service
|
IdentityService
|
Identity service dependency. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
UsersRead
|
Created user schema with hashed password. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
409 if email/username already exists. |
HTTPException
|
500 if database error occurs. |
Source code in backend/app/modules/users/users/crud.py
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 | |
create_user_default_data
create_user_default_data(user_id, identity_service, db)
Create default data for newly created user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
ID of user to create default data for. |
required |
identity_service
|
IdentityService
|
Identity service used to initialise the auth-owned MFA row through the auth boundary. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in backend/app/modules/users/users/utils.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
delete_user
async
delete_user(user_id, db)
Delete a user from the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
ID of user to delete. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if user not found. |
HTTPException
|
500 if database error occurs. |
Source code in backend/app/modules/users/users/crud.py
908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 | |
delete_user_photo_filesystem
async
delete_user_photo_filesystem(user_id)
Delete a user's stored photo blobs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
ID of user whose photo files to delete. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in backend/app/modules/users/users/utils.py
191 192 193 194 195 196 197 198 199 200 201 202 203 | |
edit_user
async
edit_user(user_id, user, db)
Update an existing user's information.
Note
This dynamic-assignment helper is intended for admin
endpoints that legitimately need to set fields like
access_type, active, or pending_admin_approval.
Self-service profile updates MUST NOT call this — use
:func:edit_profile_user instead, which enforces an
explicit allow-list and prevents privilege escalation
through mass assignment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
ID of user to update. |
required |
user
|
UsersRead
|
User data to update with. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
UsersRead
|
users_schema.UsersRead |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if user not found. |
HTTPException
|
409 if email/username conflict. |
HTTPException
|
500 if database error occurs. |
Source code in backend/app/modules/users/users/crud.py
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 | |
get_admin_users_or_404
get_admin_users_or_404(db)
Retrieve all admin users from database or raise 404 error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
list[UsersRead]
|
List of all admin User schemas. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if no admin users found. |
Source code in backend/app/modules/users/users/utils.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
get_all_users
get_all_users(db)
Retrieve all users from the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
list[UsersRead]
|
List of all user schemas. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database query fails. |
Source code in backend/app/modules/users/users/crud.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
get_user_by_email
get_user_by_email(email, db)
Retrieve user by email address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email
|
str
|
Email address to search for (case-insensitive). |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
UsersRead | None
|
User schema if found, None otherwise. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database query fails. |
Source code in backend/app/modules/users/users/crud.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | |
get_user_by_id
get_user_by_id(user_id, db, public_check=False)
Retrieve user by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID to search for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
public_check
|
bool
|
If True, only returns user when public sharing is enabled in server settings. |
False
|
Returns:
| Type | Description |
|---|---|
UsersRead | None
|
User schema if found (and public sharing enabled if |
UsersRead | None
|
public_check=True), None otherwise. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database query fails. |
Source code in backend/app/modules/users/users/crud.py
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
get_user_by_id_or_404
get_user_by_id_or_404(user_id, db)
Retrieve user by ID or raise 404 error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID to search for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
UsersRead
|
Users schema (guaranteed non-None). |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if user not found. |
Source code in backend/app/modules/users/users/utils.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
get_user_by_username
get_user_by_username(username: str, db: Session, contains: Literal[False] = False) -> users_schema.UsersRead | None
get_user_by_username(username: str, db: Session, contains: Literal[True]) -> list[users_schema.UsersRead]
get_user_by_username(username, db, contains=False)
Retrieve user by username.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
username
|
str
|
Username to search for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
contains
|
bool
|
If True, performs partial match search and returns list of matching users. If False, performs exact match and returns single user or None. |
False
|
Returns:
| Type | Description |
|---|---|
list[UsersRead] | UsersRead | None
|
If contains=False: User schema if found, None otherwise. |
list[UsersRead] | UsersRead | None
|
If contains=True: List of user schemas matching the search. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database query fails. |
Source code in backend/app/modules/users/users/crud.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
get_users_admin
get_users_admin(db)
Retrieve all admin users from the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
list[UsersRead]
|
List of admin user schemas. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database query fails. |
Source code in backend/app/modules/users/users/crud.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
get_users_number
get_users_number(db, show_inactive=True, show_email_unverified=True, show_pending_approval=True)
Count users matching the optional list filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
Session
|
SQLAlchemy database session. |
required |
show_inactive
|
bool | None
|
If False, excludes inactive users. Defaults to True. |
True
|
show_email_unverified
|
bool | None
|
If False, excludes users with unverified emails. Defaults to True. |
True
|
show_pending_approval
|
bool | None
|
If False, excludes users pending admin approval. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
int
|
Number of users matching the filters. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database query fails. |
Source code in backend/app/modules/users/users/crud.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
get_users_with_pagination
get_users_with_pagination(db, page_number=None, num_records=None, show_inactive=True, show_email_unverified=True, show_pending_approval=True)
Retrieve a paginated list of users with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
Session
|
Database session for executing queries. |
required |
page_number
|
int | None
|
The page number for pagination (1-indexed). If None, pagination is not applied. Defaults to None. |
None
|
num_records
|
int | None
|
The number of records per page. If None, pagination is not applied. Defaults to None. |
None
|
show_inactive
|
bool | None
|
If False, excludes inactive users. Defaults to True (includes inactive users). |
True
|
show_email_unverified
|
bool | None
|
If False, excludes users with unverified emails. Defaults to True (includes email unverified users). |
True
|
show_pending_approval
|
bool | None
|
If False, excludes users pending admin approval. Defaults to True (includes pending approval users). |
True
|
Returns:
| Type | Description |
|---|---|
list[UsersRead]
|
list[users_schema.UsersRead]: A list of User schemas matching the specified criteria, ordered by username. Returns an empty list if no users match the filters. |
Source code in backend/app/modules/users/users/crud.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
save_user_image_file
async
save_user_image_file(user_id, file, db)
Save user image file with security validation and update DB.
Uses centralized file upload handler for validation and async I/O, then updates user photo path in database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
ID of user whose image is being saved. |
required |
file
|
UploadFile
|
Uploaded image file (UploadFile). |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Path to saved image file. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
400 if filename or extension is invalid, 413 if too large, 500 if upload fails. |
Source code in backend/app/modules/users/users/utils.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
update_user_photo
async
update_user_photo(user_id, db, photo_path=None)
Update a user's photo path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
ID of user to update photo for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
photo_path
|
str | None
|
New photo path. If None, removes photo. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
The updated photo path, or None if removed. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if user not found. |
HTTPException
|
500 if database error occurs. |
Source code in backend/app/modules/users/users/crud.py
877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 | |
verify_user_email
verify_user_email(user_id, server_settings, db)
Verify user email and conditionally activate account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
ID of user to verify. |
required |
server_settings
|
ServerSettingsRead
|
Server config determining activation policy. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if user not found. |
HTTPException
|
500 if database error occurs. |
Source code in backend/app/modules/users/users/crud.py
843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 | |
Users profile
Profile module for user profile management and operations.
This module provides functionality for: - User profile retrieval and updates - MFA (Multi-Factor Authentication) setup and management - Profile data export and import (ZIP archives) - Identity provider linking and management - Session management
Exports
- Services: ExportService, ImportService
- Exceptions: ProfileOperationError, ExportError, ProfileImportError, and related exception classes
ActivityLimitError
Bases: ProfileImportError
Raised when import contains too many activities.
Source code in backend/app/modules/users/users_profile/exceptions.py
136 137 138 139 140 141 | |
DataCollectionError
Bases: ExportError
Raised when data collection from database fails.
Source code in backend/app/modules/users/users_profile/exceptions.py
71 72 73 74 75 76 | |
DataIntegrityError
Bases: ProfileImportError
Raised when imported data has integrity issues.
Source code in backend/app/modules/users/users_profile/exceptions.py
104 105 106 107 108 109 | |
DatabaseConnectionError
Bases: ExportError
Raised when database connection fails during export.
Source code in backend/app/modules/users/users_profile/exceptions.py
39 40 41 42 43 44 | |
DiskSpaceError
Bases: ProfileImportError
Raised when insufficient disk space is available.
Source code in backend/app/modules/users/users_profile/exceptions.py
120 121 122 123 124 125 | |
ExportError
Bases: ProfileOperationError
Base exception for export operations.
Source code in backend/app/modules/users/users_profile/exceptions.py
22 23 24 25 26 27 | |
ExportService
Service for exporting user profile data to ZIP archive.
Attributes:
| Name | Type | Description |
|---|---|---|
user_id |
ID of user to export data for. |
|
db |
Database session. |
|
counts |
Dictionary tracking exported item counts. |
|
performance_config |
ExportPerformanceConfig
|
Performance configuration. |
Source code in backend/app/modules/users/users_profile/export_service.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 | |
add_activity_files_to_zip
add_activity_files_to_zip(zipf, user_activities)
Add activity files to ZIP archive.
Reads each activity's retained source file through the platform
StorageProvider (local disk or object storage) and writes it into the
archive under activity_files/{id}{ext}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zipf
|
ZipFile
|
ZipFile instance to write to. |
required |
user_activities
|
list[Any]
|
List of activity objects. |
required |
Source code in backend/app/modules/users/users_profile/export_service.py
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 | |
add_activity_media_to_zip
add_activity_media_to_zip(zipf, user_activities)
Add activity media files to ZIP archive.
Read through the platform StorageProvider rather than by walking a
local directory, so an export is complete regardless of which storage
backend is configured. Keys are {activity_id}_{uuid}{ext}, so each
activity's blobs are listed by its own prefix instead of scanning every
stored file and filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zipf
|
ZipFile
|
ZipFile instance to write to. |
required |
user_activities
|
list[Any]
|
List of activity objects. |
required |
Source code in backend/app/modules/users/users_profile/export_service.py
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 | |
add_user_images_to_zip
add_user_images_to_zip(zipf)
Add the user's profile image to the ZIP archive.
Read through the platform StorageProvider rather than by walking a
local directory, so an export is complete regardless of which storage
backend is configured. Keys are {user_id}{ext}, so the caller's
blobs are listed by their own prefix instead of scanning every stored
image and filtering by filename.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zipf
|
ZipFile
|
ZipFile instance to write to. |
required |
Source code in backend/app/modules/users/users_profile/export_service.py
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 | |
collect_gear_data
collect_gear_data(zipf)
Collect and write gear data to ZIP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zipf
|
ZipFile
|
ZipFile instance to write to. |
required |
Raises:
| Type | Description |
|---|---|
DatabaseConnectionError
|
If database error occurs. |
Source code in backend/app/modules/users/users_profile/export_service.py
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |
collect_health_weight
collect_health_weight(zipf)
Collect and write health data to ZIP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zipf
|
ZipFile
|
ZipFile instance to write to. |
required |
Raises:
| Type | Description |
|---|---|
DatabaseConnectionError
|
If database error occurs. |
Source code in backend/app/modules/users/users_profile/export_service.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 | |
collect_user_activities_data
collect_user_activities_data(zipf)
Collect and write user activities to ZIP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zipf
|
ZipFile
|
ZipFile instance to write to. |
required |
Returns:
| Type | Description |
|---|---|
list[Any]
|
List of collected activity objects. |
Raises:
| Type | Description |
|---|---|
DatabaseConnectionError
|
If database error occurs. |
MemoryAllocationError
|
If memory limit exceeded. |
DataCollectionError
|
If collection fails. |
Source code in backend/app/modules/users/users_profile/export_service.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
collect_user_settings_data
collect_user_settings_data(zipf)
Collect and write user settings to ZIP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zipf
|
ZipFile
|
ZipFile instance to write to. |
required |
Raises:
| Type | Description |
|---|---|
DatabaseConnectionError
|
If database error occurs. |
Source code in backend/app/modules/users/users_profile/export_service.py
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 | |
generate_export_archive
generate_export_archive(user_dict, timeout_seconds=300)
Generate and stream export archive as bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_dict
|
dict[str, Any]
|
User data dictionary to export. |
required |
timeout_seconds
|
int | None
|
Optional timeout in seconds. |
300
|
Yields:
| Type | Description |
|---|---|
Generator[bytes]
|
Chunks of ZIP archive as bytes. |
Raises:
| Type | Description |
|---|---|
ExportTimeoutError
|
If operation times out. |
ZipCreationError
|
If ZIP creation fails. |
MemoryAllocationError
|
If memory limit exceeded. |
FileSystemError
|
If file system error occurs. |
Source code in backend/app/modules/users/users_profile/export_service.py
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 | |
ExportTimeoutError
Bases: ExportError
Raised when export operation exceeds time limit.
Source code in backend/app/modules/users/users_profile/exceptions.py
79 80 81 82 83 84 | |
FileFormatError
Bases: ProfileImportError
Raised when imported file format is invalid or corrupted.
Source code in backend/app/modules/users/users_profile/exceptions.py
96 97 98 99 100 101 | |
FileSizeError
Bases: ProfileImportError
Raised when imported file exceeds size limits.
Source code in backend/app/modules/users/users_profile/exceptions.py
128 129 130 131 132 133 | |
FileSystemError
Bases: ProfileOperationError
Raised when file system operations fail.
Source code in backend/app/modules/users/users_profile/exceptions.py
47 48 49 50 51 52 | |
ImportService
Service for importing user profile data from ZIP archive.
Attributes:
| Name | Type | Description |
|---|---|---|
user_id |
ID of user to import data for. |
|
db |
Database session. |
|
websocket_manager |
WebSocket manager for updates. |
|
counts |
Dictionary tracking imported item counts. |
|
performance_config |
ImportPerformanceConfig
|
Performance configuration. |
Source code in backend/app/modules/users/users_profile/import_service.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | |
add_activity_files_from_zip
async
add_activity_files_from_zip(zipf, file_list, activities_id_mapping)
Extract and import activity files from ZIP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zipf
|
ZipFile
|
ZipFile instance to read from. |
required |
file_list
|
set
|
Set of file paths in ZIP. |
required |
activities_id_mapping
|
dict[int, int]
|
Mapping of old to new IDs. |
required |
Source code in backend/app/modules/users/users_profile/import_service.py
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 | |
add_activity_media_from_zip
async
add_activity_media_from_zip(zipf, file_list, activities_id_mapping)
Extract and import activity media from ZIP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zipf
|
ZipFile
|
ZipFile instance to read from. |
required |
file_list
|
set
|
Set of file paths in ZIP. |
required |
activities_id_mapping
|
dict[int, int]
|
Mapping of old to new IDs. |
required |
Source code in backend/app/modules/users/users_profile/import_service.py
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 | |
add_user_images_from_zip
async
add_user_images_from_zip(zipf, file_list)
Extract and import user images from ZIP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zipf
|
ZipFile
|
ZipFile instance to read from. |
required |
file_list
|
set
|
Set of file paths in ZIP. |
required |
Source code in backend/app/modules/users/users_profile/import_service.py
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | |
collect_and_import_activities_data_batched
async
collect_and_import_activities_data_batched(zipf, file_list, gears_id_mapping, start_time, timeout_seconds)
Import activities in batches to manage memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zipf
|
ZipFile
|
ZipFile instance to read from. |
required |
file_list
|
set[str]
|
Set of file paths in ZIP. |
required |
gears_id_mapping
|
dict[int, int]
|
Mapping of old to new gear IDs. |
required |
start_time
|
float
|
Import operation start time. |
required |
timeout_seconds
|
int
|
Timeout limit in seconds. |
required |
Returns:
| Type | Description |
|---|---|
dict[int, int]
|
Dictionary mapping old activity IDs to new IDs. |
Raises:
| Type | Description |
|---|---|
ActivityLimitError
|
If too many activities. |
ImportTimeoutError
|
If operation times out. |
Source code in backend/app/modules/users/users_profile/import_service.py
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 | |
collect_and_import_activity_components
async
collect_and_import_activity_components(component_data, original_activity_id, new_activity)
Import contributed components for a single restored activity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component_data
|
dict[str, list[dict[str, Any]]]
|
Records keyed by profile contributor key. |
required |
original_activity_id
|
int
|
Old activity ID. |
required |
new_activity
|
ActivityRead
|
New activity object. |
required |
Source code in backend/app/modules/users/users_profile/import_service.py
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 | |
collect_and_import_gear_components_data
async
collect_and_import_gear_components_data(gear_components_data, gears_id_mapping)
Import gear components data with ID remapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gear_components_data
|
list[Any]
|
List of component dicts. |
required |
gears_id_mapping
|
dict[int, int]
|
Mapping of old to new gear IDs. |
required |
Source code in backend/app/modules/users/users_profile/import_service.py
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |
collect_and_import_gears_data
async
collect_and_import_gears_data(gears_data)
Import gear data and create ID mappings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gears_data
|
list[Any]
|
List of gear data dictionaries. |
required |
Returns:
| Type | Description |
|---|---|
dict[int, int]
|
Dictionary mapping old gear IDs to new IDs. |
Source code in backend/app/modules/users/users_profile/import_service.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | |
collect_and_import_health_weight
async
collect_and_import_health_weight(health_weight_data, health_targets_data)
Import health data and targets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
health_weight_data
|
list[Any]
|
List of health data records. |
required |
health_targets_data
|
list[Any]
|
List of health target records. |
required |
Source code in backend/app/modules/users/users_profile/import_service.py
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 | |
collect_and_import_user_data
async
collect_and_import_user_data(user_data, user_default_gear_data, user_goals_data, user_integrations_data, user_privacy_settings_data, gears_id_mapping)
Import user profile and related settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_data
|
list[Any]
|
User profile data. |
required |
user_default_gear_data
|
list[Any]
|
Default gear settings. |
required |
user_goals_data
|
list[Any]
|
User goals data. |
required |
user_integrations_data
|
list[Any]
|
Integration settings. |
required |
user_privacy_settings_data
|
list[Any]
|
Privacy settings. |
required |
gears_id_mapping
|
dict[int, int]
|
Mapping of old to new gear IDs. |
required |
Source code in backend/app/modules/users/users_profile/import_service.py
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | |
collect_and_import_user_default_gear
async
collect_and_import_user_default_gear(user_default_gear_data, gears_id_mapping)
Import user default gear settings with ID remapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_default_gear_data
|
list[Any]
|
Default gear data. |
required |
gears_id_mapping
|
dict[int, int]
|
Mapping of old to new gear IDs. |
required |
Source code in backend/app/modules/users/users_profile/import_service.py
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | |
collect_and_import_user_goals
async
collect_and_import_user_goals(user_goals_data)
Import user goals data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_goals_data
|
list[Any]
|
List of user goal dictionaries. |
required |
Source code in backend/app/modules/users/users_profile/import_service.py
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 | |
collect_and_import_user_integrations
async
collect_and_import_user_integrations(user_integrations_data)
Import user integration settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_integrations_data
|
list[Any]
|
Integration data. |
required |
Source code in backend/app/modules/users/users_profile/import_service.py
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 | |
collect_and_import_user_privacy_settings
async
collect_and_import_user_privacy_settings(user_privacy_settings_data)
Import user privacy settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_privacy_settings_data
|
list[Any]
|
Privacy settings data. |
required |
Source code in backend/app/modules/users/users_profile/import_service.py
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 | |
import_from_zip_data
async
import_from_zip_data(zip_data)
Import profile data from ZIP file bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zip_data
|
bytes
|
ZIP file content as bytes. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with import results and counts. |
Raises:
| Type | Description |
|---|---|
FileSizeError
|
If file exceeds size limit. |
FileFormatError
|
If ZIP format is invalid. |
FileSystemError
|
If file system error occurs. |
ImportTimeoutError
|
If operation times out. |
Source code in backend/app/modules/users/users_profile/import_service.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
ImportTimeoutError
Bases: ProfileImportError
Raised when import operation exceeds time limit.
Source code in backend/app/modules/users/users_profile/exceptions.py
112 113 114 115 116 117 | |
ImportValidationError
Bases: ProfileImportError
Raised when import data fails validation checks.
Source code in backend/app/modules/users/users_profile/exceptions.py
88 89 90 91 92 93 | |
JSONParseError
Bases: ProfileImportError
Raised when JSON data cannot be parsed.
Source code in backend/app/modules/users/users_profile/exceptions.py
152 153 154 155 156 157 | |
MemoryAllocationError
Bases: ProfileOperationError
Raised when memory allocation fails.
Source code in backend/app/modules/users/users_profile/exceptions.py
63 64 65 66 67 68 | |
ProfileImportError
Bases: ProfileOperationError
Base exception for import operations.
Source code in backend/app/modules/users/users_profile/exceptions.py
30 31 32 33 34 35 | |
ProfileOperationError
Bases: Exception
Base exception for all profile operations.
Source code in backend/app/modules/users/users_profile/exceptions.py
14 15 16 17 18 19 | |
SchemaValidationError
Bases: ProfileImportError
Raised when imported data doesn't match expected schema.
Source code in backend/app/modules/users/users_profile/exceptions.py
160 161 162 163 164 165 | |
ZipCreationError
Bases: ExportError
Raised when ZIP file creation or writing fails.
Source code in backend/app/modules/users/users_profile/exceptions.py
55 56 57 58 59 60 | |
ZipStructureError
Bases: ProfileImportError
Raised when ZIP file structure is invalid.
Source code in backend/app/modules/users/users_profile/exceptions.py
144 145 146 147 148 149 | |
Users goals
User goals module for managing user fitness goals.
This module provides CRUD operations and data models for user goal tracking including activity type goals, intervals, and progress calculation.
Exports
- CRUD: get_user_goals_by_user_id, get_user_goal_by_user_and_goal_id, create_user_goal, update_user_goal, delete_user_goal
- Schemas: UsersGoalBase, UsersGoalCreate, UsersGoalUpdate, UsersGoalRead, UsersGoalProgress
- Enums: Interval, ActivityType, GoalType
- Utils: calculate_user_goals
ActivityType
Bases: StrEnum
Supported activity types for user goals.
Attributes:
| Name | Type | Description |
|---|---|---|
RUN |
Running activities. |
|
BIKE |
Cycling activities. |
|
SWIM |
Swimming activities. |
|
WALK |
Walking or hiking activities. |
|
STRENGTH |
Strength or resistance training. |
|
CARDIO |
Cardiovascular training. |
Source code in backend/app/modules/users/users_goals/schema.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
GoalType
Bases: StrEnum
Types of measurable user goals.
Attributes:
| Name | Type | Description |
|---|---|---|
CALORIES |
Target calories burned. |
|
ACTIVITIES |
Target count of completed activities. |
|
DISTANCE |
Target distance traveled. |
|
ELEVATION |
Target elevation gain. |
|
DURATION |
Target total duration. |
Source code in backend/app/modules/users/users_goals/schema.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
Interval
Bases: StrEnum
Recurrence intervals for user goals.
Attributes:
| Name | Type | Description |
|---|---|---|
DAILY |
Daily recurrence interval. |
|
WEEKLY |
Weekly recurrence interval. |
|
MONTHLY |
Monthly recurrence interval. |
|
YEARLY |
Yearly recurrence interval. |
Source code in backend/app/modules/users/users_goals/schema.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
UsersGoalBase
Bases: BaseModel
Base schema for users fitness goals.
Attributes:
| Name | Type | Description |
|---|---|---|
interval |
Interval
|
Goal time interval (daily, weekly, monthly, yearly). |
activity_type |
ActivityType
|
Type of activity for the goal. |
goal_type |
GoalType
|
Type of goal metric being tracked. |
goal_calories |
StrictInt | None
|
Target calories in kcal. |
goal_activities_number |
StrictInt | None
|
Target number of activities. |
goal_distance |
StrictInt | None
|
Target distance in meters. |
goal_elevation |
StrictInt | None
|
Target elevation gain in meters. |
goal_duration |
StrictInt | None
|
Target duration in seconds. |
Source code in backend/app/modules/users/users_goals/schema.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
ensure_correct_goal_field
ensure_correct_goal_field()
Validate exactly one goal field matches goal_type.
Returns:
| Type | Description |
|---|---|
UsersGoalBase
|
Self with validated goal field. |
Raises:
| Type | Description |
|---|---|
PydanticCustomError
|
If required field missing or extra fields set. |
Source code in backend/app/modules/users/users_goals/schema.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
UsersGoalCreate
Bases: UsersGoalBase
Schema for creating a new users goal.
Inherits all validation from UsersGoalBase.
Source code in backend/app/modules/users/users_goals/schema.py
156 157 158 159 160 161 | |
UsersGoalProgress
Bases: BaseModel
Schema for user goal progress tracking.
Attributes:
| Name | Type | Description |
|---|---|---|
goal_id |
StrictInt
|
Goal identifier. |
interval |
Interval
|
Goal time interval. |
activity_type |
ActivityType
|
Activity type for this goal. |
goal_type |
GoalType
|
Type of goal metric. |
start_date |
StrictStr
|
Period start date. |
end_date |
StrictStr
|
Period end date. |
percentage_completed |
StrictInt | None
|
Completion percentage. |
total_calories |
StrictInt | None
|
Total calories achieved. |
total_activities_number |
StrictInt | None
|
Total activities completed. |
total_distance |
StrictInt | None
|
Total distance achieved. |
total_elevation |
StrictInt | None
|
Total elevation gained. |
total_duration |
StrictInt | None
|
Total duration achieved. |
goal_calories |
StrictInt | None
|
Target calories. |
goal_activities_number |
StrictInt | None
|
Target activities count. |
goal_distance |
StrictInt | None
|
Target distance. |
goal_elevation |
StrictInt | None
|
Target elevation. |
goal_duration |
StrictInt | None
|
Target duration. |
Source code in backend/app/modules/users/users_goals/schema.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
UsersGoalRead
Bases: UsersGoalBase
Schema for reading a user goal.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
StrictInt
|
Unique identifier for the goal. |
user_id |
StrictInt
|
User who owns this goal. |
Source code in backend/app/modules/users/users_goals/schema.py
164 165 166 167 168 169 170 171 172 173 174 | |
UsersGoalUpdate
Bases: UsersGoalRead
Schema for updating an existing users goal.
Supports partial updates. Omitted fields remain unchanged.
Source code in backend/app/modules/users/users_goals/schema.py
177 178 179 180 181 182 | |
calculate_user_goals
calculate_user_goals(user_id, date, db, first_day_of_week)
Calculate progress for all user goals on a specified date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user. |
required |
date
|
str | None
|
Date in YYYY-MM-DD format. If None, uses current date. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
first_day_of_week
|
WeekdayValue
|
User's configured first weekday. |
required |
Returns:
| Type | Description |
|---|---|
list[UsersGoalProgress] | None
|
List of UsersGoalProgress objects, or None if no goals found. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If database error occurs. |
Source code in backend/app/modules/users/users_goals/utils.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
create_user_goal
create_user_goal(user_id, user_goal, db)
Create a new user goal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user. |
required |
user_goal
|
UsersGoalCreate
|
Goal data to create. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
UsersGoalRead
|
The created UsersGoal schema. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If goal already exists (409) or database error occurs (500). |
Source code in backend/app/modules/users/users_goals/crud.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
delete_user_goal
delete_user_goal(user_id, goal_id, db)
Delete a user's goal from the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
ID of the user who owns the goal. |
required |
goal_id
|
int
|
ID of the goal to delete. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If goal not found (404) or database error occurs (500). |
Source code in backend/app/modules/users/users_goals/crud.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
get_user_goal_by_user_and_goal_id
get_user_goal_by_user_and_goal_id(user_id, goal_id, db)
Retrieve a specific goal by user ID and goal ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user. |
required |
goal_id
|
int
|
The ID of the goal. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
UsersGoalRead | None
|
UsersGoal schema if found, None otherwise. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If database error occurs. |
Source code in backend/app/modules/users/users_goals/crud.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
get_user_goals_by_user_id
get_user_goals_by_user_id(user_id, db, interval=None, activity_type=None, goal_type=None)
Retrieve goals for a specific user with optional filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
interval
|
Interval | None
|
Optional filter by goal interval. |
None
|
activity_type
|
ActivityType | None
|
Optional filter by activity type. |
None
|
goal_type
|
GoalType | None
|
Optional filter by goal type. |
None
|
Returns:
| Type | Description |
|---|---|
list[UsersGoalRead]
|
List of UsersGoal schemas matching the filters. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If database error occurs. |
Source code in backend/app/modules/users/users_goals/crud.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
update_user_goal
update_user_goal(user_id, user_goal, db)
Update a user's goal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
ID of the user. |
required |
user_goal
|
UsersGoalUpdate
|
Schema with fields to update. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
UsersGoalRead
|
The updated UsersGoal schema. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If goal not found (404) or database error occurs (500). |
Source code in backend/app/modules/users/users_goals/crud.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
Users default gear
User default gear module for activity type gear assignments.
This module provides CRUD operations and data models for managing user default gear settings per activity type (run, ride, swim, etc.).
Exports
- CRUD: get_user_default_gear_by_user_id, create_user_default_gear, edit_user_default_gear
- Schemas: UsersDefaultGearBase, UsersDefaultGearUpdate, UsersDefaultGearRead
- Utils: get_user_default_gear_by_activity_type
- Constants: ACTIVITY_TYPE_TO_GEAR_ATTR
UsersDefaultGearBase
Bases: BaseModel
Base schema for users default gear assignments.
Attributes:
| Name | Type | Description |
|---|---|---|
run_gear_id |
StrictInt | None
|
Default gear for run activities. |
trail_run_gear_id |
StrictInt | None
|
Default gear for trail run activities. |
virtual_run_gear_id |
StrictInt | None
|
Default gear for virtual run activities. |
ride_gear_id |
StrictInt | None
|
Default gear for ride activities. |
gravel_ride_gear_id |
StrictInt | None
|
Default gear for gravel ride activities. |
mtb_ride_gear_id |
StrictInt | None
|
Default gear for MTB ride activities. |
virtual_ride_gear_id |
StrictInt | None
|
Default gear for virtual ride activities. |
ows_gear_id |
StrictInt | None
|
Default gear for open water swim activities. |
walk_gear_id |
StrictInt | None
|
Default gear for walk activities. |
hike_gear_id |
StrictInt | None
|
Default gear for hike activities. |
tennis_gear_id |
StrictInt | None
|
Default gear for tennis activities. |
alpine_ski_gear_id |
StrictInt | None
|
Default gear for alpine ski activities. |
nordic_ski_gear_id |
StrictInt | None
|
Default gear for nordic ski activities. |
snowboard_gear_id |
StrictInt | None
|
Default gear for snowboard activities. |
windsurf_gear_id |
StrictInt | None
|
Default gear for windsurf activities. |
Source code in backend/app/modules/users/users_default_gear/schema.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
UsersDefaultGearRead
Bases: UsersDefaultGearBase
Schema for reading user default gear settings.
Extends base with identifier fields.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
StrictInt
|
Unique identifier for the record. |
user_id |
StrictInt
|
User ID reference. |
Source code in backend/app/modules/users/users_default_gear/schema.py
124 125 126 127 128 129 130 131 132 133 134 135 136 | |
UsersDefaultGearUpdate
Bases: UsersDefaultGearRead
Schema for updating user default gear settings.
Inherits all gear assignment fields from read schema. All fields are optional for partial updates.
Source code in backend/app/modules/users/users_default_gear/schema.py
139 140 141 142 143 144 145 | |
create_user_default_gear
create_user_default_gear(user_id, db)
Create default gear settings for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user to create settings for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
UsersDefaultGearRead
|
The created UsersDefaultGear schema. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
409 error if settings already exist. |
HTTPException
|
500 error if database operation fails. |
Source code in backend/app/modules/users/users_default_gear/crud.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
edit_user_default_gear
edit_user_default_gear(user_default_gear, user_id, db)
Update default gear settings for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_default_gear
|
UsersDefaultGearUpdate
|
Schema with gear fields to update. |
required |
user_id
|
int
|
The ID of the user. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
UsersDefaultGearRead
|
The updated UsersDefaultGear schema. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 error if settings not found. |
HTTPException
|
500 error if database operation fails. |
Source code in backend/app/modules/users/users_default_gear/crud.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
get_user_default_gear_by_activity_type
get_user_default_gear_by_activity_type(user_id, activity_type, db)
Get default gear ID for a specific activity type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user. |
required |
activity_type
|
int
|
The activity type code. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
The gear ID for the activity type, or None if not set |
int | None
|
or activity type is unknown. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If user default gear not found or database error occurs. |
Source code in backend/app/modules/users/users_default_gear/utils.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
get_user_default_gear_by_user_id
get_user_default_gear_by_user_id(user_id, db)
Retrieve default gear settings for a specific user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user to fetch settings for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
UsersDefaultGearRead | None
|
The UsersDefaultGear model for the user or None if not found. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 error if settings not found. |
HTTPException
|
500 error if database query fails. |
Source code in backend/app/modules/users/users_default_gear/crud.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
Users integrations
User integrations module for third-party service OAuth management.
This module provides CRUD operations and data models for user integration settings including Strava and Garmin Connect OAuth tokens and synchronization preferences.
Exports
- CRUD: get_user_integrations_by_user_id, create_user_integrations, edit_user_integrations, link_strava_account, unlink_strava_account, set_user_strava_client, set_user_strava_state, set_user_strava_sync_gear, link_garminconnect_account, unlink_garminconnect_account, set_user_garminconnect_sync_gear, get_user_integrations_by_strava_state
- Schemas: UsersIntegrationsBase, UsersIntegrationsCreate, UsersIntegrationsRead, UsersIntegrationsUpdate
UsersIntegrationsBase
Bases: BaseModel
Base schema for user integrations.
Attributes:
| Name | Type | Description |
|---|---|---|
strava_client_id |
StrictStr | None
|
Encrypted Strava client ID. |
strava_client_secret |
StrictStr | None
|
Encrypted Strava client secret. |
strava_state |
StrictStr | None
|
Temporary state for Strava OAuth flow. |
strava_token |
StrictStr | None
|
Encrypted Strava access token. |
strava_refresh_token |
StrictStr | None
|
Encrypted Strava refresh token. |
strava_token_expires_at |
datetime | None
|
Strava token expiration time. |
strava_sync_gear |
StrictBool
|
Enable Strava gear synchronization. |
garminconnect_token |
dict[str, Any] | None
|
Garmin Connect token data. |
garminconnect_sync_gear |
StrictBool
|
Enable Garmin Connect gear synchronization. |
Source code in backend/app/modules/users/users_integrations/schema.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
UsersIntegrationsCreate
Bases: UsersIntegrationsBase
Pydantic model for creating user integrations.
Inherits all attributes from UsersIntegrationsBase.
Source code in backend/app/modules/users/users_integrations/schema.py
73 74 75 76 77 78 | |
UsersIntegrationsRead
Bases: UsersIntegrationsBase
Schema for reading user integrations.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
StrictInt
|
Unique identifier for the integrations record. |
user_id |
StrictInt
|
Foreign key reference to the user. |
Source code in backend/app/modules/users/users_integrations/schema.py
90 91 92 93 94 95 96 97 98 99 100 | |
UsersIntegrationsUpdate
Bases: UsersIntegrationsBase
Schema for updating user integrations.
Inherits all validation from UsersIntegrationsBase. All fields are optional for partial updates.
Source code in backend/app/modules/users/users_integrations/schema.py
81 82 83 84 85 86 87 | |
create_user_integrations
create_user_integrations(user_id, db)
Create integration settings for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user to create integrations for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
UsersIntegrationsRead
|
The created UsersIntegrationsRead schema. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
409 error if integrations already exist. |
HTTPException
|
500 error if database operation fails. |
Source code in backend/app/modules/users/users_integrations/crud.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
edit_user_integrations
edit_user_integrations(user_integrations, user_id, db)
Update user integration settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_integrations
|
UsersIntegrationsUpdate
|
Schema with fields to update. |
required |
user_id
|
int
|
The ID of the user to update. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
UsersIntegrationsRead
|
The updated UsersIntegrations model. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 error if integrations not found. |
HTTPException
|
500 error if database operation fails. |
Source code in backend/app/modules/users/users_integrations/crud.py
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |
get_user_integrations_by_strava_state
get_user_integrations_by_strava_state(strava_state, db)
Retrieve integrations by Strava OAuth state token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strava_state
|
str
|
The Strava OAuth state to search for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
UsersIntegrationsRead | None
|
The UsersIntegrationsRead schema if found, None otherwise. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database query fails. |
Source code in backend/app/modules/users/users_integrations/crud.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
get_user_integrations_by_user_id
get_user_integrations_by_user_id(user_id, db)
Retrieve integrations for a specific user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user to fetch integrations for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
UsersIntegrationsRead | None
|
The UsersIntegrationsRead schema for the user. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 error if integrations not found. |
HTTPException
|
500 error if database query fails. |
Source code in backend/app/modules/users/users_integrations/crud.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
link_garminconnect_account
link_garminconnect_account(user_id, token, db)
Link a Garmin Connect account by storing token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user. |
required |
token
|
dict
|
Garmin Connect token data. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 error if integrations not found. |
HTTPException
|
500 error if database operation fails. |
Source code in backend/app/modules/users/users_integrations/crud.py
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 | |
link_strava_account
link_strava_account(user_id, tokens, db)
Link a Strava account by storing OAuth tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user to update. |
required |
tokens
|
dict
|
Dictionary containing access_token, refresh_token, and expires_at. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database operation fails. |
Source code in backend/app/modules/users/users_integrations/crud.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
set_user_garminconnect_sync_gear
set_user_garminconnect_sync_gear(user_id, garminconnect_sync_gear, db)
Set Garmin Connect gear synchronization preference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user. |
required |
garminconnect_sync_gear
|
bool
|
Whether to sync gear from Garmin Connect. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 error if integrations not found. |
HTTPException
|
500 error if database operation fails. |
Source code in backend/app/modules/users/users_integrations/crud.py
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | |
set_user_strava_client
set_user_strava_client(user_id, client_id, client_secret, db)
Set Strava client credentials for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user. |
required |
client_id
|
str
|
Strava client ID to encrypt and store. |
required |
client_secret
|
str
|
Strava client secret to encrypt and store. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 error if integrations not found. |
HTTPException
|
500 error if database operation fails. |
Source code in backend/app/modules/users/users_integrations/crud.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
set_user_strava_state
set_user_strava_state(user_id, state, db)
Set or clear Strava OAuth state for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user. |
required |
state
|
str | None
|
Strava OAuth state to set, or None to clear. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 error if integrations not found. |
HTTPException
|
500 error if database operation fails. |
Source code in backend/app/modules/users/users_integrations/crud.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |
set_user_strava_sync_gear
set_user_strava_sync_gear(user_id, strava_sync_gear, db)
Set Strava gear synchronization preference for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user. |
required |
strava_sync_gear
|
bool
|
Whether to sync gear from Strava. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 error if integrations not found. |
HTTPException
|
500 error if database operation fails. |
Source code in backend/app/modules/users/users_integrations/crud.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
unlink_garminconnect_account
unlink_garminconnect_account(user_id, db)
Unlink a Garmin Connect account by clearing OAuth tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user to unlink. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 error if integrations not found. |
HTTPException
|
500 error if database operation fails. |
Source code in backend/app/modules/users/users_integrations/crud.py
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
unlink_strava_account
unlink_strava_account(user_id, db)
Unlink a Strava account by clearing OAuth tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user to unlink. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 error if integrations not found. |
HTTPException
|
500 error if database operation fails. |
Source code in backend/app/modules/users/users_integrations/crud.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
Users privacy settings
User privacy settings module for activity visibility control.
This module provides CRUD operations and data models for user privacy settings including activity visibility levels and various data hiding options for activities.
Exports
- CRUD: get_user_privacy_settings_by_user_id, create_user_privacy_settings, edit_user_privacy_settings
- Schemas: UsersPrivacySettingsBase, UsersPrivacySettingsCreate, UsersPrivacySettingsRead, UsersPrivacySettingsUpdate
- Models: UsersPrivacySettings (ORM model)
- Enums: ActivityVisibility
ActivityVisibility
Bases: Enum
Activity visibility levels.
Attributes:
| Name | Type | Description |
|---|---|---|
PUBLIC |
Visible to everyone. |
|
FOLLOWERS |
Visible only to followers. |
|
PRIVATE |
Visible only to the user. |
Source code in backend/app/modules/users/users_privacy_settings/schema.py
14 15 16 17 18 19 20 21 22 23 24 25 26 | |
UsersPrivacySettingsBase
Bases: BaseModel
Base schema for user privacy settings.
Attributes:
| Name | Type | Description |
|---|---|---|
default_activity_visibility |
ActivityVisibility | None
|
Default activity visibility level. |
hide_activity_start_time |
StrictBool | None
|
Hide start time from activities. |
hide_activity_location |
StrictBool | None
|
Hide location data from activities. |
hide_activity_map |
StrictBool | None
|
Hide map visualization from activities. |
hide_activity_hr |
StrictBool | None
|
Hide heart rate data from activities. |
hide_activity_power |
StrictBool | None
|
Hide power data from activities. |
hide_activity_cadence |
StrictBool | None
|
Hide cadence data from activities. |
hide_activity_elevation |
StrictBool | None
|
Hide elevation data from activities. |
hide_activity_speed |
StrictBool | None
|
Hide speed data from activities. |
hide_activity_pace |
StrictBool | None
|
Hide pace data from activities. |
hide_activity_laps |
StrictBool | None
|
Hide lap data from activities. |
hide_activity_workout_sets_steps |
StrictBool | None
|
Hide workout sets and steps from activities. |
hide_activity_gear |
StrictBool | None
|
Hide gear information from activities. |
Source code in backend/app/modules/users/users_privacy_settings/schema.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
UsersPrivacySettingsCreate
Bases: UsersPrivacySettingsBase
Pydantic model for creating user privacy settings.
Inherits all attributes from UsersPrivacySettingsBase.
Source code in backend/app/modules/users/users_privacy_settings/schema.py
84 85 86 87 88 89 | |
UsersPrivacySettingsRead
Bases: UsersPrivacySettingsBase
Schema for reading user privacy settings.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
StrictInt
|
Unique identifier for the privacy settings record. |
user_id |
StrictInt
|
Foreign key reference to the user. |
Source code in backend/app/modules/users/users_privacy_settings/schema.py
101 102 103 104 105 106 107 108 109 110 111 | |
UsersPrivacySettingsUpdate
Bases: UsersPrivacySettingsBase
Schema for updating user privacy settings.
Inherits all validation from UsersPrivacySettingsBase. All fields are optional for partial updates.
Source code in backend/app/modules/users/users_privacy_settings/schema.py
92 93 94 95 96 97 98 | |
create_user_privacy_settings
create_user_privacy_settings(user_id, db)
Create privacy settings for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user to create settings for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
UsersPrivacySettingsRead
|
The created UsersPrivacySettingsRead schema. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
409 error if settings already exist. |
HTTPException
|
500 error if database operation fails. |
Source code in backend/app/modules/users/users_privacy_settings/crud.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
edit_user_privacy_settings
edit_user_privacy_settings(user_id, user_privacy_settings_data, db)
Update privacy settings for a specific user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user to update settings for. |
required |
user_privacy_settings_data
|
UsersPrivacySettingsUpdate
|
Schema with fields to update. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
UsersPrivacySettingsRead
|
The updated UsersPrivacySettingsRead schema. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 error if settings not found. |
HTTPException
|
500 error if database operation fails. |
Source code in backend/app/modules/users/users_privacy_settings/crud.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
get_user_privacy_settings_by_user_id
get_user_privacy_settings_by_user_id(user_id, db)
Retrieve privacy settings for a specific user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user to fetch settings for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
UsersPrivacySettingsRead | None
|
The UsersPrivacySettingsRead schema if found, None otherwise. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database query fails. |
Source code in backend/app/modules/users/users_privacy_settings/crud.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |