API Reference
sharkservers_api.
sharkservers-api
(C) 2023-present Adrian Ciołek (Qwizi)
apps
¶
sharkservers_api.
sharkservers-api
(C) 2023-present Adrian Ciołek (Qwizi)
dependencies
¶
get_app_service() -> AppService
async
¶
Get app service :return AppService:
Source code in sharkservers/apps/dependencies.py
8 9 10 11 12 13 | |
get_valid_apps(apps_id: int, apps_service: AppService = Depends(get_app_service)) -> ormar.Model
async
¶
Get valid apps :param app_service: :param apps_id: :return Apps:
Source code in sharkservers/apps/dependencies.py
16 17 18 19 20 21 22 23 24 25 26 | |
enums
¶
AppsEventsEnum
¶
RApps events enum.
Source code in sharkservers/apps/enums.py
9 10 11 12 13 14 15 16 17 18 19 20 21 | |
models
¶
services
¶
auth
¶
sharkservers_api.
sharkservers-api
(C) 2023-present Adrian Ciołek (Qwizi)
dependencies
¶
Dependencies for auth.
get_access_token_service: Get access token service
get_refresh_token_service: Get refresh token service
get_auth_service: Get auth service
get_current_user: Get current user
get_current_active_user: Get current active user
get_admin_user: Get admin user
get_application: Get application
get_activation_account_code_service: Get activation account code service
get_change_account_email_code_service: Get change account email code service
get_reset_account_password_code_service: Get reset account password code service
get_steam_auth_service: Get steam auth service
get_access_token_service(settings: Settings = Depends(get_settings)) -> JWTService
async
¶
Get the access token service.
settings (Settings): The application settings.
JWTService: The access token service.
Source code in sharkservers/auth/dependencies.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
get_refresh_token_service(settings: Settings = Depends(get_settings)) -> JWTService
async
¶
Retrieve the JWTService instance for handling refresh tokens.¶
settings (Settings): The application settings.
JWTService: The JWTService instance for handling refresh tokens.
Source code in sharkservers/auth/dependencies.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
get_auth_service(users_service: UserService = Depends(get_users_service), roles_service: RoleService = Depends(get_roles_service), scopes_service: ScopeService = Depends(get_scopes_service)) -> AuthService
async
¶
Get the authentication service with the required dependencies.
users_service (UserService): The user service dependency.
roles_service (RoleService): The role service dependency.
scopes_service (ScopeService): The scope service dependency.
users_sessions_service (UserSessionService): The user session service dependency.
AuthService: The authentication service instance.
Source code in sharkservers/auth/dependencies.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
get_current_user(security_scopes: SecurityScopes, token: str = Depends(AuthService.oauth2_scheme), access_token_service: JWTService = Depends(get_access_token_service), users_service: UserService = Depends(get_users_service)) -> User
async
¶
Retrieve the current user based on the provided security scopes and token.
security_scopes (SecurityScopes): The security scopes required for the user.
token (str): The access token used for authentication.
access_token_service (JWTService): The service used for decoding the access token.
users_service (UserService): The service used for retrieving user information.
users_sessions_service (UserSessionService): The service used for retrieving user session information.
User: The current user.
InvalidCredentialsException: If the credentials are invalid.
NoPermissionsException: If the user does not have the required permissions.
Source code in sharkservers/auth/dependencies.py
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 | |
get_current_active_user(current_user: User = Depends(get_current_user)) -> User
async
¶
Retrieve the current active user.
This function checks if the current user is activated. If not, it raises an exception.
current_user (User): The current user.
User: The current active user.
inactivate_user_exception: If the current user is not activated.
Source code in sharkservers/auth/dependencies.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
get_admin_user(user: User = Depends(get_current_active_user)) -> User
async
¶
Retrieve the admin user.
user (User): The current user.
User: The admin user.
NotAdminUserException: If the user is not a superuser.
Source code in sharkservers/auth/dependencies.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
get_activation_account_code_service(redis: Redis = Depends(get_redis)) -> CodeService
async
¶
Get the activation account code service.
This function returns an instance of the CodeService class that is used for generating and validating activation codes for user accounts.
redis: The Redis connection object.
The CodeService instance.
Source code in sharkservers/auth/dependencies.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
get_change_account_email_code_service(redis: Redis = Depends(get_redis)) -> CodeService
async
¶
Retrieves the CodeService instance for changing the account email.
redis (Redis): The Redis instance.
CodeService: The CodeService instance for changing the account email.
Source code in sharkservers/auth/dependencies.py
232 233 234 235 236 237 238 239 240 241 242 243 244 | |
get_reset_account_password_code_service(redis: Redis = Depends(get_redis)) -> CodeService
async
¶
Retrieve the CodeService instance for resetting account password.
redis (Redis): The Redis instance used for storing the reset password code.
CodeService: The CodeService instance for resetting account password.
Source code in sharkservers/auth/dependencies.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
get_steam_auth_service(users_service: UserService = Depends(get_users_service), players_service: PlayerService = Depends(get_players_service)) -> SteamAuthService
async
¶
Get the SteamAuthService instance with the provided dependencies.
users_service (UserService): The UserService instance.
players_service (PlayerService): The PlayerSer>
SteamAuthService: The SteamAuthService instance.
Source code in sharkservers/auth/dependencies.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
enums
¶
Enums for auth module.
Enums: - RedisAuthKeyEnum: The keys for the redis auth codes. - AuthExceptionsDetailEnum: The detail messages for the auth exceptions. - AuthEventsEnum: The events for the auth module.
RedisAuthKeyEnum
¶
Enum class representing the keys used in Redis for authentication purposes.
Source code in sharkservers/auth/enums.py
12 13 14 15 16 17 | |
AuthExceptionsDetailEnum
¶
Enum class that defines the detail messages for various authentication exceptions.
Source code in sharkservers/auth/enums.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
AuthEventsEnum
¶
Enum class that defines the events for the auth module.
Source code in sharkservers/auth/enums.py
36 37 38 39 40 41 42 43 44 45 46 | |
exceptions
¶
Exceptions for the auth module.
Exceptions:¶
- username_taken_exception: Raised when a username is taken.
- email_taken_exception: Raised when an email is taken.
- invalid_activation_code_exception: Raised when an activation code is invalid.
- user_activated_exception: Raised when a user is already activated.
- not_admin_user_exception: Raised when a user is not an admin.
- incorrect_username_password_exception: Raised when the username or password is incorrect.
- no_permissions_exception: Raised when a user has no permissions.
- invalid_credentials_exception: Raised when the credentials are invalid.
- inactivate_user_exception: Raised when a user is inactive.
- user_exists_exception: Raised when a user exists.
- invalid_activation_code_exception: Raised when an activation code is invalid.
- token_expired_exception: Raised when a token is expired.
schemas
¶
Schemas for the auth module.
Schemas: - UsernameRegex: The schema for the username regex. - PasswordSchema: The schema for the password. - RegisterUserSchema: The schema for registering a user. - TokenDetailsSchema: The schema for the token details. - TokenSchema: The schema for the tokens. - TokenDataSchema: The schema for the token data. - RefreshTokenSchema: The schema for the refresh token. - ActivateUserCodeSchema: The schema for the activation code. - ResendActivationCodeSchema: The schema for resending the activation code. - UserActivatedSchema: The schema for the user activated. - EmailConfirmSchema: The schema for the email confirmation. - ResetPasswordSchema: The schema for resetting the password. - SteamAuthSchema: The schema for the steam auth.
UsernameRegex
¶
Bases: BaseModel
Schema for the username regex.
Source code in sharkservers/auth/schemas.py
26 27 28 29 30 31 32 33 34 35 | |
PasswordSchema
¶
Bases: BaseModel
Schema for validating password fields.
Source code in sharkservers/auth/schemas.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
passwords_match(value, values, **kwargs) -> None
¶
Check if the 'password2' field matches the 'password' field.
Raises¶
ValueError: If the passwords do not match.
Source code in sharkservers/auth/schemas.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
RegisterUserSchema
¶
Bases: UsernameRegex, PasswordSchema
Schema for registering a user.
Source code in sharkservers/auth/schemas.py
63 64 65 66 | |
TokenDetailsSchema
¶
Bases: BaseModel
Schema for the token details.
Source code in sharkservers/auth/schemas.py
69 70 71 72 73 74 | |
TokenSchema
¶
Bases: BaseModel
Schema for the tokens.
Source code in sharkservers/auth/schemas.py
77 78 79 80 81 | |
TokenDataSchema
¶
Bases: BaseModel
Schema for the token data.
Source code in sharkservers/auth/schemas.py
84 85 86 87 88 89 90 | |
RefreshTokenSchema
¶
Bases: BaseModel
Schema for the refresh token.
Source code in sharkservers/auth/schemas.py
93 94 95 96 | |
ActivateUserCodeSchema
¶
Bases: BaseModel
Schema for the activation code.
Source code in sharkservers/auth/schemas.py
99 100 101 102 | |
ResendActivationCodeSchema
¶
Bases: BaseModel
Schema for resending the activation code.
Source code in sharkservers/auth/schemas.py
105 106 107 108 | |
UserActivatedSchema
¶
Bases: BaseModel
Schema for the user activated.
Source code in sharkservers/auth/schemas.py
111 112 113 114 115 | |
EmailConfirmSchema
¶
Bases: BaseModel
Schema for the email confirmation.
Source code in sharkservers/auth/schemas.py
118 119 120 121 122 123 | |
ResetPasswordSchema
¶
Bases: ActivateUserCodeSchema, PasswordSchema
Schema for resetting the password.
Source code in sharkservers/auth/schemas.py
126 127 | |
SteamAuthSchema
¶
Bases: BaseModel
Schema for the steam auth.
Source code in sharkservers/auth/schemas.py
130 131 132 133 134 135 136 137 138 139 140 141 142 | |
services
¶
sharkservers_api.
sharkservers-api
(C) 2023-present Adrian Ciołek (Qwizi)
auth
¶
Auth service.
Module responsible for authentication and authorization.
Classes: - OAuth2ClientSecretRequestForm: Represents a form for requesting OAuth2 client secret. - AuthService: Represents the service responsible for authentication and authorization operations.
OAuth2ClientSecretRequestForm
¶
Represents a form for requesting OAuth2 client secret.
client_id (str, optional): The client ID. Defaults to None.
client_secret (str, optional): The client secret. Defaults to None.
Source code in sharkservers/auth/services/auth.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
__init__(client_id: str | None = Form(default=None), client_secret: str | None = Form(default=None)) -> None
¶
Initializes an instance of the Auth class.
Source code in sharkservers/auth/services/auth.py
64 65 66 67 68 69 70 71 | |
AuthService
¶
Service class for authentication-related operations.
Attributes¶
users_service (UserService): The service for managing user-related operations.
roles_service (RoleService): The service for managing role-related operations.
scopes_service (ScopeService): The service for managing scope-related operations.
users_sessions_service (UserSessionService): The service for managing user session-related operations.
Methods¶
authenticate_user: Authenticates a user based on the provided username and password.
register: Register a new user.
login: Authenticate a user and generates access and refresh tokens.
create_access_token_from_refresh_token: Create an access token from a refresh token.
logout: Log out the specified user by generating a new secret salt and updating it in the user's record.
generate_code: Generate a random code consisting of digits.
generate_secret_salt: Generate a secret salt consisting of random alphanumeric characters.
resend_activation_code: Resend the activation code to the specified email address.
activate_user: Activate a user based on the provided activation code.
confirm_change_email: Confirm the change of email for a user.
reset_password: Reset the password for a user.
get_user_agent: Get the User-Agent header from the request.
Source code in sharkservers/auth/services/auth.py
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 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 | |
__init__(users_service: UserService, roles_service: RoleService, scopes_service: ScopeService) -> None
¶
Initialize the Auth service.
users_service (UserService): The service for managing users.
roles_service (RoleService): The service for managing roles.
scopes_service (ScopeService): The service for managing scopes.
users_sessions_service (UserSessionService): The service for managing user sessions.
Source code in sharkservers/auth/services/auth.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
authenticate_user(username: str, password: str, user_ip: str | None, user_agent: str | None) -> User | bool
async
¶
Authenticates a user based on the provided username and password.
username (str): The username of the user.
password (str): The password of the user.
user_ip (str): The IP address of the user.
user_agent (str): The user agent string of the user's browser.
Union[User, bool]: The authenticated user object if successful, False otherwise.
Source code in sharkservers/auth/services/auth.py
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 | |
register(user_data: RegisterUserSchema, is_activated: bool = False, is_superuser: bool = False, request: Request = None, settings: Settings = None) -> User
async
¶
Register a new user.
user_data (RegisterUserSchema): The user data for registration.
is_activated (bool, optional): Whether the user is activated. Defaults to False.
is_superuser (bool, optional): Whether the user is a superuser. Defaults to False.
request (Request, optional): The request object. Defaults to None.
settings (Settings, optional): The settings object. Defaults to None.
User: The registered user.
user_exists_exception: If the user already exists.
Source code in sharkservers/auth/services/auth.py
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 | |
login(form_data: OAuth2PasswordRequestForm, jwt_access_token_service: JWTService, jwt_refresh_token_service: JWTService, user_ip: str | None = None, user_agent: str | None = None) -> tuple[TokenSchema, User]
async
¶
Authenticate a user and generates access and refresh tokens.
form_data (OAuth2PasswordRequestForm): The form data containing the username and password.
jwt_access_token_service (JWTService): The service used to encode the access token.
jwt_refresh_token_service (JWTService): The service used to encode the refresh token.
user_ip (str): The IP address of the user.
user_agent (str): The user agent string.
tuple[TokenSchema, User]: A tuple containing the access and refresh tokens, and the authenticated user.
Source code in sharkservers/auth/services/auth.py
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 | |
create_access_token_from_refresh_token(token_data: RefreshTokenSchema, jwt_access_token_service: JWTService, jwt_refresh_token_service: JWTService) -> tuple[TokenSchema, User]
async
¶
Create an access token from a refresh token.
token_data (RefreshTokenSchema): The refresh token data.
jwt_access_token_service (JWTService): The JWT service for access tokens.
jwt_refresh_token_service (JWTService): The JWT service for refresh tokens.
tuple[TokenSchema, User]: A tuple containing the access token schema and the user object.
Source code in sharkservers/auth/services/auth.py
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 | |
logout(user: User) -> User
async
¶
Log out the specified user by generating a new secret salt and updating it in the user's record.
user (User): The user to log out.
User: The updated user object.
Source code in sharkservers/auth/services/auth.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
generate_code(number: int = 8) -> str
staticmethod
¶
Generate a random code consisting of digits.
number (int): The length of the generated code. Default is 8.
str: The generated code.
Source code in sharkservers/auth/services/auth.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
generate_secret_salt() -> str
staticmethod
¶
Generate a secret salt consisting of random alphanumeric characters.
Returns¶
str: The generated secret salt.
Source code in sharkservers/auth/services/auth.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
resend_activation_code(email: EmailStr, code_service: CodeService, email_service: EmailService) -> dict[str, str]
async
¶
Resend the activation code to the specified email address.
email (EmailStr): The email address to send the activation code to.
code_service (CodeService): The code service used to create the activation code.
email_service (EmailService): The email service used to send the activation email.
dict: A dictionary with a message indicating that the activation code will be sent if the email is correct.
Source code in sharkservers/auth/services/auth.py
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 | |
activate_user(code: str, code_service: CodeService) -> tuple[bool, User]
async
¶
Activate a user based on the provided activation code.
code (str): The activation code.
code_service (CodeService): The code service used to retrieve the user ID.
Tuple[bool, Union[bool, User]]: A tuple containing a boolean indicating the success of the activation,
and either a boolean indicating if the user was already activated or the activated user object.
Source code in sharkservers/auth/services/auth.py
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 | |
confirm_change_email(code_service: CodeService, code: str) -> User
async
¶
Confirm the change of email for a user.
code_service (CodeService): The code service used to retrieve the user data.
code (str): The activation code.
User: The updated user object.
InvalidActivationCodeException: If the activation code is invalid.
Source code in sharkservers/auth/services/auth.py
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 | |
reset_password(reset_password_data: ResetPasswordSchema, code_service: CodeService) -> bool
async
¶
Reset the password for a user.
reset_password_data (ResetPasswordSchema): The data required to reset the password.
code_service (CodeService): The service used to validate the activation code.
bool: True if the password was successfully reset, False otherwise.
Source code in sharkservers/auth/services/auth.py
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 | |
get_user_agent(request: Request) -> str
async
¶
Get the User-Agent header from the request.
request (Request): The incoming request.
str: The User-Agent header value, or None if not found.
Source code in sharkservers/auth/services/auth.py
520 521 522 523 524 525 526 527 528 529 530 531 532 | |
code
¶
Code service.
Code service is a service that allows you to create a code and store it in redis. It is used for example to create a code for email confirmation.
CodeService
¶
Service class for generating and managing codes using Redis.
Attributes¶
redis (aioredis.Redis): Redis instance for code storage.
key (str): Key prefix for Redis storage.
Methods¶
generate: Generate a random code.
get_redis_key: Get the Redis key for a given code.
create: Create a code and store it in Redis.
get: Get the data associated with a code from Redis.
delete: Delete a code and its associated data from Redis.
Source code in sharkservers/auth/services/code.py
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 122 123 | |
__init__(redis: aioredis.Redis, key: str) -> None
¶
Initialize the CodeService.
Source code in sharkservers/auth/services/code.py
34 35 36 37 | |
generate(number: int = 8) -> str
staticmethod
¶
Generate a random string of digits.
number (int): The length of the generated string. Default is 8.
str: A random string of digits.
Source code in sharkservers/auth/services/code.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
get_redis_key(code: str) -> str
¶
Return the Redis key for the given code.
code (str): The code to generate the Redis key for.
str: The Redis key.
Source code in sharkservers/auth/services/code.py
56 57 58 59 60 61 62 63 64 65 66 67 68 | |
create(data: any, code_len: int = 8, expire: int = 60 * 60) -> (str, str)
async
¶
Create a code and stores it in Redis with the provided data.
data (any): The data to be stored along with the code.
code_len (int, optional): The length of the generated code. Defaults to 8.
expire (int, optional): The expiration time of the code in seconds. Defaults to 3600.
Tuple[str, str]: A tuple containing the code key and the stored data.
Source code in sharkservers/auth/services/code.py
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 | |
get(code: str) -> str
async
¶
Retrieves the value associated with the given code from Redis.
code (str): The code to retrieve the value for.
str: The value associated with the code.
Source code in sharkservers/auth/services/code.py
97 98 99 100 101 102 103 104 105 106 107 108 109 | |
delete(code: str) -> bool
async
¶
Delete a code from the Redis cache.
code (str): The code to be deleted.
bool: True if the code was successfully deleted, False otherwise.
Source code in sharkservers/auth/services/code.py
111 112 113 114 115 116 117 118 119 120 121 122 123 | |
jwt
¶
JWT Service.
This module contains JWTService class which is responsible for encoding and decoding JWT tokens.
JWTService
¶
Service class for encoding and decoding JSON Web Tokens (JWT).
Attributes¶
secret_key (str): The secret key used to encode and decode the JWT.
algorithm (str): The algorithm used to encode and decode the JWT.
expires_delta (timedelta): The expiration delta for the JWT.
Methods¶
encode: Encodes the given data into a JWT.
decode: Decodes the given JWT.
decode_token: Decodes the given JWT and returns the token data schema.
Source code in sharkservers/auth/services/jwt.py
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 | |
__init__(secret_key: str, algorithm: str = 'HS512', expires_delta: timedelta = timedelta(minutes=15)) -> None
¶
Initialize the JWTService.
Source code in sharkservers/auth/services/jwt.py
34 35 36 37 38 39 40 41 42 43 | |
encode(data: dict) -> (str, datetime)
¶
Encodes the given data into a JWT.
data (dict): The data to be encoded.
tuple: A tuple containing the encoded JWT and the expiration datetime.
Source code in sharkservers/auth/services/jwt.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
decode(token: str) -> dict
¶
Decodes the given JWT.
token (str): The JWT to be decoded.
dict: The decoded JWT payload.
Source code in sharkservers/auth/services/jwt.py
64 65 66 67 68 69 70 71 72 73 74 75 76 | |
decode_token(token: str) -> TokenDataSchema
¶
Decodes the given JWT and returns the token data schema.
token (str): The JWT to be decoded.
TokenDataSchema: The decoded token data schema.
invalid_credentials_exception: If the JWT is invalid or missing required data.
Source code in sharkservers/auth/services/jwt.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 | |
steam
¶
Steam auth service.
Steam auth service is a service that allows you to authenticate a user using Steam OpenID.
SteamAuthService: Service class for authenticating users using Steam OpenID.
SteamAuthService
¶
Service class for handling Steam authentication.
Attributes¶
users_service (UserService): The user service.
players_service (PlayerService): The player service.
auth_url (str): The Steam authentication URL.
Methods¶
get_steamid_from_url: Get the Steam ID from a Steam profile URL.
format_params: Format the Steam authentication parameters into a dict.
is_valid_params: Check if the provided Steam authentication parameters are valid.
authenticate: Authenticate a user using Steam authentication.
Source code in sharkservers/auth/services/steam.py
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 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 | |
__init__(users_service: UserService, players_service: PlayerService) -> None
¶
Initialize the SteamAuthService.
Source code in sharkservers/auth/services/steam.py
40 41 42 43 44 45 46 47 48 | |
get_steamid_from_url(url: str) -> str
staticmethod
¶
Extracts the SteamID from a given Steam profile URL.
url (str): The Steam profile URL.
str: The extracted SteamID.
Source code in sharkservers/auth/services/steam.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
format_params(params: SteamAuthSchema) -> dict
¶
Format the Steam authentication parameters into a dict.
params (SteamAuthSchema): The Steam authentication parameters.
dict: The formatted parameters.
Source code in sharkservers/auth/services/steam.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
is_valid_params(params: SteamAuthSchema) -> bool
async
¶
Check if the provided Steam authentication parameters are valid.
params (SteamAuthSchema): The Steam authentication parameters.
bool: True if the parameters are valid, False otherwise.
Source code in sharkservers/auth/services/steam.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
authenticate(user: User, params: SteamAuthSchema) -> Player
async
¶
Authenticate a user using Steam authentication.
user (User): The user to authenticate.
params (SteamAuthSchema): The Steam authentication parameters.
Player: The authenticated player.
HTTPException: If the Steam profile cannot be authenticated or if the user is already connected to a profile.
Source code in sharkservers/auth/services/steam.py
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 | |
utils
¶
Utils for auth module.
Functions: - verify_password: Verifies a password. - get_password_hash: Hashes a password. - now_datetime: Returns the current datetime.
verify_password(plain_password: str, hashed_password: str) -> bool
¶
Verify if a plain password matches a hashed password.
plain_password (str): The plain password to verify.
hashed_password (str): The hashed password to compare against.
bool: True if the plain password matches the hashed password, False otherwise.
Source code in sharkservers/auth/utils.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
get_password_hash(plain_password: str) -> str
¶
Hashes the given plain password using the pwd_context.
plain_password (str): The plain password to be hashed.
str: The hashed password.
Source code in sharkservers/auth/utils.py
39 40 41 42 43 44 45 46 47 48 49 50 51 | |
now_datetime() -> datetime
¶
Return the current datetime in the timezone "Europe/Warsaw".
Returns¶
datetime: The current datetime without timezone information.
Source code in sharkservers/auth/utils.py
54 55 56 57 58 59 60 61 62 | |
views
¶
Module contains the API endpoints related to authentication.
register(user_data: RegisterUserSchema, background_tasks: BackgroundTasks, request: Request, auth_service: AuthService = Depends(get_auth_service), code_service: CodeService = Depends(get_activation_account_code_service), email_service: EmailService = Depends(get_email_service), settings: Settings = Depends(get_settings)) -> UserOut
async
¶
Register a new user.
user_data (RegisterUserSchema): The user data to register.
background_tasks (BackgroundTasks): The background tasks object.
request (Request): The request object.
auth_service (AuthService, optional): The authentication service. Defaults to Depends(get_auth_service).
code_service (CodeService, optional): The code service. Defaults to Depends(get_activation_account_code_service).
email_service (EmailService, optional): The email service. Defaults to Depends(get_email_service).
settings (Settings, optional): The settings object. Defaults to Depends(get_settings).
UserOut: The registered user.
Source code in sharkservers/auth/views.py
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 | |
login_user(request: Request, form_data: OAuth2PasswordRequestForm = Depends(), access_token_service: JWTService = Depends(get_access_token_service), refresh_token_service: JWTService = Depends(get_refresh_token_service), auth_service: AuthService = Depends(get_auth_service)) -> TokenSchema
async
¶
Log in a user and returns a token.
request (Request): The incoming request object.
form_data (OAuth2PasswordRequestForm, optional): The form data containing the user's credentials. Defaults to Depends().
access_token_service (JWTService, optional): The service for generating access tokens. Defaults to Depends(get_access_token_service).
refresh_token_service (JWTService, optional): The service for generating refresh tokens. Defaults to Depends(get_refresh_token_service).
auth_service (AuthService, optional): The service for handling authentication. Defaults to Depends(get_auth_service).
TokenSchema: The token schema containing the access token.
Source code in sharkservers/auth/views.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 129 130 131 132 | |
get_access_token_from_refresh_token(token_data: RefreshTokenSchema, access_token_service: JWTService = Depends(get_access_token_service), refresh_token_service: JWTService = Depends(get_refresh_token_service), auth_service: AuthService = Depends(get_auth_service)) -> TokenSchema
async
¶
Retrieve an access token from a refresh token.
token_data (RefreshTokenSchema): The refresh token data.
access_token_service (JWTService, optional): The access token service. Defaults to Depends(get_access_token_service).
refresh_token_service (JWTService, optional): The refresh token service. Defaults to Depends(get_refresh_token_service).
auth_service (AuthService, optional): The authentication service. Defaults to Depends(get_auth_service).
TokenSchema: The access token.
Source code in sharkservers/auth/views.py
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 | |
logout_user(user: User = Depends(get_current_active_user), auth_service: AuthService = Depends(get_auth_service)) -> UserOut
async
¶
Log out the user.
user (User): The user to be logged out.
auth_service (AuthService): The authentication service.
UserOut: The logged out user.
Source code in sharkservers/auth/views.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
activate_user(activate_code_data: ActivateUserCodeSchema, auth_service: AuthService = Depends(get_auth_service), activate_code_service: CodeService = Depends(get_activation_account_code_service)) -> UserActivatedSchema
async
¶
Activate a user account using the provided activation code.
activate_code_data (ActivateUserCodeSchema): The activation code data.
auth_service (AuthService): The authentication service.
activate_code_service (CodeService): The activation code service.
UserActivatedSchema: The activated user data.
invalid_activation_code_exception: If the activation code is invalid.
Source code in sharkservers/auth/views.py
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 | |
resend_activate_code(data: ResendActivationCodeSchema, background_tasks: BackgroundTasks, auth_service: AuthService = Depends(get_auth_service), code_service: CodeService = Depends(get_activation_account_code_service), email_service: EmailService = Depends(get_email_service)) -> dict[str, str]
async
¶
Resends the activation code to the specified email address.
data (ResendActivationCodeSchema): The data containing the email address.
background_tasks (BackgroundTasks): The background tasks manager.
auth_service (AuthService): The authentication service.
code_service (CodeService): The activation code service.
email_service (EmailService): The email service.
dict[str, str]: A dictionary with a message indicating if the email is correct and an email with the activation code will be sent.
Source code in sharkservers/auth/views.py
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 | |
forgot_password_request(data: ResendActivationCodeSchema, background_tasks: BackgroundTasks, email_service: EmailService = Depends(get_email_service), code_service: CodeService = Depends(get_reset_account_password_code_service)) -> dict[str, str]
async
¶
Send a request to reset the account password.
data (ResendActivationCodeSchema): The data containing the email address.
background_tasks (BackgroundTasks): The background tasks manager.
auth_service (AuthService): The authentication service.
email_service (EmailService): The email service.
code_service (CodeService): The code service for resetting the account password.
dict[str, str]: A dictionary with a message indicating that an email with the reset code will be sent if the email is correct.
Source code in sharkservers/auth/views.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 287 | |
reset_password(data: ResetPasswordSchema, auth_service: AuthService = Depends(get_auth_service), code_service: CodeService = Depends(get_reset_account_password_code_service)) -> dict
async
¶
Reset the password for a user account.
data (ResetPasswordSchema): The data containing the password reset information.
auth_service (AuthService): The authentication service.
code_service (CodeService): The code service for resetting the account password.
dict: A dictionary with a message indicating that the password has been reset.
Source code in sharkservers/auth/views.py
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 | |
chat
¶
sharkservers_api.
sharkservers-api
(C) 2023-present Adrian Ciołek (Qwizi)
bot
¶
dependencies
¶
enums
¶
ChatEventsEnum
¶
RChat events enum.
Source code in sharkservers/chat/enums.py
9 10 11 12 13 14 15 16 17 18 19 20 21 | |
models
¶
services
¶
websocket
¶
db
¶
Module contains database-related functionality for the SharkServers API.
It defines the database connection, models, and base service class.
BaseMeta
¶
Bases: ModelMeta
Meta class for the BaseMeta class.
This class defines the metadata and database attributes for ormar models.
Source code in sharkservers/db.py
61 62 63 64 65 66 67 68 69 | |
DateFieldsMixins
¶
Mixin class that provides date fields for created_at and updated_at.
Source code in sharkservers/db.py
72 73 74 75 76 77 78 79 80 81 82 | |
BaseService
¶
Base service class for ormar models.
Source code in sharkservers/db.py
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 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 | |
Meta
¶
Meta class for the BaseService class.
Source code in sharkservers/db.py
88 89 90 91 92 | |
get_one(**kwargs) -> ormar.Model
async
¶
Get a single model instance based on the provided filters.
**kwargs: The filters to apply.
ormar.Model: The retrieved model instance.
HTTPException: If no matching model instance is found.
Source code in sharkservers/db.py
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 | |
get_all(params: Params = None, related=None, order_by=None, **kwargs)
async
¶
Get all model instances based on the provided filters.
params (Params, optional): The pagination parameters.
related (str, optional): The related model to include.
order_by (str, optional): The field to order the results by.
**kwargs: The filters to apply.
QuerySet: The retrieved model instances.
Source code in sharkservers/db.py
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 | |
delete(_id: int)
async
¶
Delete a model instance by its ID.
_id (int): The ID of the model instance to delete.
ormar.Model: The deleted model instance.
HTTPException: If no matching model instance is found.
Source code in sharkservers/db.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
create(*args, **kwargs)
async
¶
Create a new model instance.
*args: The positional arguments.
**kwargs: The keyword arguments.
ormar.Model: The created model instance.
HTTPException: If a unique constraint is violated.
Source code in sharkservers/db.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
update(updated_data: dict, **kwargs) -> ormar.Model
async
¶
Update a model instance.
updated_data (dict): The updated data.
**kwargs: The filters to apply.
ormar.Model: The updated model instance.
HTTPException: If a unique constraint is violated.
Source code in sharkservers/db.py
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 | |
create_redis_pool() -> aioredis.Redis
async
¶
Create a Redis connection pool.
Returns¶
aioredis.Redis: The Redis connection pool.
Source code in sharkservers/db.py
33 34 35 36 37 38 39 40 41 42 43 | |
get_redis(request: Request) -> aioredis.Redis
async
¶
Get the Redis connection from the request.
request (Request): The incoming request.
aioredis.Redis: The Redis connection.
Source code in sharkservers/db.py
46 47 48 49 50 51 52 53 54 55 56 57 58 | |
dependencies
¶
Dependencies for the application.
get_email_checker() -> DefaultChecker
async
¶
Retrieve the default email checker.
Returns¶
DefaultChecker: The default email checker.
Source code in sharkservers/dependencies.py
26 27 28 29 30 31 32 33 34 35 36 37 38 | |
get_email_service(settings: Settings = Depends(get_settings), checker: DefaultChecker = Depends(get_email_checker)) -> EmailService
async
¶
Retrieve the email service.
settings (Settings, optional): The application settings. Defaults to Depends(get_settings).
checker (DefaultChecker, optional): The default email checker. Defaults to Depends(get_email_checker).
EmailService: The email service.
Source code in sharkservers/dependencies.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
get_upload_service(settings: Settings = Depends(get_settings)) -> UploadService
async
¶
Retrieve the upload service.
settings (Settings, optional): The application settings. Defaults to Depends(get_settings).
UploadService: The upload service.
Source code in sharkservers/dependencies.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
enums
¶
Module contains all the enums used in the project.
MainEventEnum
¶
Enum class representing main events.
Attributes¶
STARTUP (str): Represents the startup event.
SHUTDOWN (str): Represents the shutdown event.
INSTALL (str): Represents the install event.
Source code in sharkservers/enums.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
ActivationEmailTypeEnum
¶
Enum class representing activation email types.
Attributes¶
ACCOUNT (str): Represents the account activation email type.
EMAIL (str): Represents the email activation email type.
PASSWORD (str): Represents the password activation email type.
Source code in sharkservers/enums.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
OrderEnum
¶
Enum class representing order types.
Attributes¶
ID_DESC (str): Represents the descending order by ID.
ID_ASC (str): Represents the ascending order by ID.
Source code in sharkservers/enums.py
37 38 39 40 41 42 43 44 45 46 47 48 | |
exception_handlers
¶
Exception handlers for FastAPI.
request_validation_exception_handler(request: Request, exc: RequestValidationError) -> JSONResponse
async
¶
Middleware will log all RequestValidationErrors.
request: The request object.
exc: The RequestValidationError exception.
A JSONResponse with the errors and the request body.
Source code in sharkservers/exception_handlers.py
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 | |
http_exception_handler(request: Request, exc: HTTPException) -> Union[JSONResponse, Response]
async
¶
HTTPException handler.
request: The request object.
exc: The HTTPException exception.
A JSONResponse with the error.
Source code in sharkservers/exception_handlers.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
unhandled_exception_handler(request: Request, exc: Exception) -> PlainTextResponse
async
¶
Unhandled exception handler.
request: The request object.
exc: The exception.
A PlainTextResponse with the error.
Source code in sharkservers/exception_handlers.py
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 | |
forum
¶
sharkservers_api.
sharkservers-api
(C) 2023-present Adrian Ciołek (Qwizi)
dependencies
¶
Forum dependencies.
get_categories_service() -> CategoryService
async
¶
Get categories service.
Source code in sharkservers/forum/dependencies.py
23 24 25 | |
get_threads_service() -> ThreadService
async
¶
Get threads service.
Source code in sharkservers/forum/dependencies.py
28 29 30 | |
get_posts_service() -> PostService
async
¶
Get posts service.
Source code in sharkservers/forum/dependencies.py
33 34 35 | |
get_valid_category(category_id: int, categories_service: CategoryService = Depends(get_categories_service)) -> Category
async
¶
Get valid category.
category_id (int): The category id.
categories_service (CategoryService, optional): The categories service. Defaults to Depends(get_categories_service).
Category: The category.
Source code in sharkservers/forum/dependencies.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
get_valid_thread(thread_id: int, threads_service: ThreadService = Depends(get_threads_service)) -> Thread
async
¶
Get valid thread.
thread_id (int): The thread id.
threads_service (ThreadService, optional): The threads service. Defaults to Depends(get_threads_service).
Thread: The thread.
Source code in sharkservers/forum/dependencies.py
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 | |
get_valid_open_thread(thread: Thread = Depends(get_valid_thread)) -> Thread
async
¶
Get valid open thread.
thread (Thread, optional): The thread. Defaults to Depends(get_valid_thread).
Thread: The thread.
Source code in sharkservers/forum/dependencies.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
get_valid_thread_with_author(thread: Thread = Depends(get_valid_open_thread), user: User = Security(get_current_active_user, scopes=['threads:update'])) -> Thread
async
¶
Get valid thread with author.
thread (Thread, optional): The thread. Defaults to Depends(get_valid_open_thread).
user (User, optional): The current active user. Defaults to Security(get_current_active_user, scopes=["threads:update"]).
Thread: The thread.
Source code in sharkservers/forum/dependencies.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
get_valid_post(post_id: int, posts_service: PostService = Depends(get_posts_service)) -> Post
async
¶
Get valid post.
post_id (int): The post id.
posts_service (PostService, optional): The posts service. Defaults to Depends(get_posts_service).
Post: The post.
Source code in sharkservers/forum/dependencies.py
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 | |
get_valid_post_author(post: Post = Depends(get_valid_post), user: User = Security(get_current_active_user, scopes=['posts:update'])) -> Post
async
¶
Get valid post author.
post (Post, optional): The post. Defaults to Depends(get_valid_post).
user (User, optional): The current active user. Defaults to Security(get_current_active_user, scopes=["posts:update"]).
Post: The post.
Source code in sharkservers/forum/dependencies.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
get_likes_service() -> LikeService
async
¶
Get likes service.
Source code in sharkservers/forum/dependencies.py
176 177 178 | |
get_thread_meta_service() -> ThreadMetaService
async
¶
Get thread meta service.
Source code in sharkservers/forum/dependencies.py
181 182 183 | |
enums
¶
Enums for forum app.
CategoryExceptionEnum
¶
Enum for categories exceptions.
Source code in sharkservers/forum/enums.py
5 6 7 8 9 10 | |
TagExceptionEnum
¶
ThreadExceptionEnum
¶
Enum for thread exceptions.
Source code in sharkservers/forum/enums.py
19 20 21 22 23 24 25 | |
PostExceptionsEnum
¶
Enum for post exceptions.
Source code in sharkservers/forum/enums.py
28 29 30 31 32 33 | |
LikeExceptionsEnum
¶
CategoryEventEnum
¶
Enum for categories events.
Source code in sharkservers/forum/enums.py
43 44 45 46 47 48 49 | |
CategoryAdminEventEnum
¶
Enum for categories admin events.
Source code in sharkservers/forum/enums.py
52 53 54 55 56 57 58 59 60 61 62 63 64 | |
TagEventsEnum
¶
TagAdminEventsEnum
¶
Enum for tags admin events.
Source code in sharkservers/forum/enums.py
76 77 78 79 80 81 82 83 84 85 86 87 88 | |
ThreadEventEnum
¶
Enum for threads events.
Source code in sharkservers/forum/enums.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
ThreadAdminEventEnum
¶
Enum for threads admin events.
Source code in sharkservers/forum/enums.py
110 111 112 113 114 115 116 117 118 119 120 121 122 | |
PostEventEnum
¶
Enum for posts events.
Source code in sharkservers/forum/enums.py
125 126 127 128 129 130 131 132 133 134 135 136 137 | |
PostAdminEventEnum
¶
Enum for posts admin events.
Source code in sharkservers/forum/enums.py
141 142 143 144 145 146 147 148 149 150 151 152 153 | |
CategoryTypeEnum
¶
ThreadTypeEnum
¶
ThreadStatusEnum
¶
ThreadOrderEnum
¶
ThreadActionEnum
¶
exceptions
¶
Forum exceptions.
models
¶
Forum models.
Category
¶
Bases: Model, DateFieldsMixins
Category model.
Attributes¶
id (int): Category ID
name (str): Category name
description (str): Category description
type (str): Category type
threads_count (int): Category threads count
Source code in sharkservers/forum/models.py
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 | |
Like
¶
Bases: Model, DateFieldsMixins
Like model.
Attributes¶
id (int): Like ID
author (User): Like author
Source code in sharkservers/forum/models.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
Post
¶
Bases: Model, DateFieldsMixins
Post model.
Attributes¶
id (int): Post ID
author (User): Post author
content (str): Post content
likes (List[Like]): Post likes
likes_count (int): Post likes count
Source code in sharkservers/forum/models.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
ThreadMeta
¶
Bases: Model, DateFieldsMixins
Thread meta model.
Attributes¶
id (str): Thread meta ID
name (str): Thread meta name
value (str): Thread meta value
description (str): Thread meta description
Source code in sharkservers/forum/models.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
Thread
¶
Bases: Model, DateFieldsMixins
Thread model.
Attributes¶
id (int): Thread ID
title (str): Thread title
content (str): Thread content
is_closed (bool): Is thread closed
is_pinned (bool): Is thread pinned
status (str): Thread status
category (Category): Thread category
author (User): Thread author
posts (List[Post]): Thread posts
meta_fields (List[ThreadMeta]): Thread meta fields
post_count (int): Thread post count
Source code in sharkservers/forum/models.py
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 | |
Meta
¶
Bases: BaseMeta
Meta class for Thread model.
Source code in sharkservers/forum/models.py
135 136 137 138 | |
close() -> None
async
¶
Close thread.
Source code in sharkservers/forum/models.py
161 162 163 | |
open() -> None
async
¶
Open thread.
Source code in sharkservers/forum/models.py
165 166 167 | |
approve() -> None
async
¶
Approve thread.
Source code in sharkservers/forum/models.py
169 170 171 172 | |
reject() -> None
async
¶
Reject thread.
Source code in sharkservers/forum/models.py
174 175 176 177 | |
pin() -> None
async
¶
Pin thread.
Source code in sharkservers/forum/models.py
179 180 181 | |
unpin() -> None
async
¶
Unpin thread.
Source code in sharkservers/forum/models.py
183 184 185 | |
change_category(new_category: Category) -> None
async
¶
Change thread category.
Source code in sharkservers/forum/models.py
187 188 189 | |
run_action(action: ThreadActionEnum, new_category: Category = None) -> None
async
¶
Run thread action.
Source code in sharkservers/forum/models.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
on_thread_save(sender, instance, **kwargs) -> None
async
¶
On thread save event.
sender (Thread): Thread model
instance (Thread): Thread instance
**kwargs: Additional arguments
None
Source code in sharkservers/forum/models.py
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 | |
update_category_thread_counter_after_delete(sender: Thread, instance: Thread, **kwargs) -> None
async
¶
Update category thread counter after thread delete.
sender (Thread): Thread model
instance (Thread): Thread instance
**kwargs: Additional arguments
Source code in sharkservers/forum/models.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
update_thread_post_counter_after_relation_add(sender: Thread, instance: Thread, child: Post, **kwargs) -> None
async
¶
Update thread post counter after relation add.
Source code in sharkservers/forum/models.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
update_thread_post_counter_after_relation_remove(sender: Thread, instance: Thread, child: Post, **kwargs) -> None
async
¶
Update thread post counter after relation remove.
Source code in sharkservers/forum/models.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
schemas
¶
Forum schemas.
CategoryOut
¶
Bases: category_out
Category output schema.
Source code in sharkservers/forum/schemas.py
41 42 43 44 45 46 47 | |
Config
¶
Category output schema config.
Source code in sharkservers/forum/schemas.py
44 45 46 47 | |
ThreadMetaOut
¶
Bases: BaseModel
Thread meta output schema.
Source code in sharkservers/forum/schemas.py
50 51 52 53 54 55 56 | |
Config
¶
Thread meta output schema config.
Source code in sharkservers/forum/schemas.py
53 54 55 56 | |
ThreadOut
¶
Bases: thread_out
Thread output schema.
Source code in sharkservers/forum/schemas.py
59 60 61 62 63 64 65 | |
Config
¶
Thread output schema config.
Source code in sharkservers/forum/schemas.py
62 63 64 65 | |
PostOut
¶
Bases: post_out
Post output schema.
Source code in sharkservers/forum/schemas.py
68 69 70 71 72 73 74 | |
Config
¶
Post output schema config.
Source code in sharkservers/forum/schemas.py
71 72 73 74 | |
LikeOut
¶
Bases: like_out
Like output schema.
Source code in sharkservers/forum/schemas.py
77 78 79 80 81 82 83 | |
Config
¶
Like output schema config.
Source code in sharkservers/forum/schemas.py
80 81 82 83 | |
ThreadTag
¶
Bases: BaseModel
Thread tag schema.
Source code in sharkservers/forum/schemas.py
86 87 88 89 90 | |
ThreadCategory
¶
Bases: BaseModel
Thread category schema.
Source code in sharkservers/forum/schemas.py
93 94 95 96 97 | |
ThreadAuthor
¶
Bases: BaseModel
Thread author schema.
Source code in sharkservers/forum/schemas.py
100 101 102 103 104 105 106 | |
ThreadPostSchema
¶
Bases: BaseModel
Thread post schema.
Source code in sharkservers/forum/schemas.py
109 110 111 112 113 114 | |
AdminCreateCategorySchema
¶
Bases: BaseModel
Admin create category schema.
Source code in sharkservers/forum/schemas.py
117 118 119 120 121 122 | |
AdminCreateThreadSchema
¶
Bases: AdminCreateCategorySchema
Admin create thread schema.
Source code in sharkservers/forum/schemas.py
126 127 128 129 | |
UpdateThreadSchema
¶
Bases: BaseModel
Update thread schema.
Source code in sharkservers/forum/schemas.py
132 133 134 135 136 | |
AdminUpdateThreadSchema
¶
Bases: UpdateThreadSchema
Admin update thread schema.
Source code in sharkservers/forum/schemas.py
140 141 142 143 144 | |
CreatePostSchema
¶
Bases: BaseModel
Create post schema.
Source code in sharkservers/forum/schemas.py
147 148 149 150 151 | |
UpdatePostSchema
¶
Bases: BaseModel
Update post schema.
Source code in sharkservers/forum/schemas.py
154 155 156 157 | |
CreateCategorySchema
¶
Bases: BaseModel
Create category schema.
Source code in sharkservers/forum/schemas.py
160 161 162 163 164 165 | |
CreateThreadSchema
¶
Bases: BaseModel
Create thread schema.
Source code in sharkservers/forum/schemas.py
168 169 170 171 172 173 174 175 176 177 | |
AdminCreatePostSchema
¶
Bases: CreatePostSchema
Admin create post schema.
Source code in sharkservers/forum/schemas.py
180 181 182 183 | |
AdminUpdatePostSchema
¶
Bases: UpdatePostSchema
Admin update post schema.
Source code in sharkservers/forum/schemas.py
186 187 188 189 190 | |
ThreadQuery
¶
Bases: OrderQuery
Thread query schema.
Source code in sharkservers/forum/schemas.py
193 194 195 196 197 198 199 200 201 202 203 | |
PostQuery
¶
Bases: OrderQuery
Post query schema.
Source code in sharkservers/forum/schemas.py
206 207 | |
AdminThreadActionSchema
¶
Bases: BaseModel
Admin thread action schema.
Source code in sharkservers/forum/schemas.py
210 211 212 213 214 | |
services
¶
Forum services.
CategoryService
¶
Bases: BaseService
Category service.
Source code in sharkservers/forum/services.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
Meta
¶
Category service meta.
Source code in sharkservers/forum/services.py
31 32 33 34 35 | |
sync_counters() -> None
async
¶
Sync category threads counters.
Source code in sharkservers/forum/services.py
37 38 39 40 41 42 43 44 45 46 47 48 | |
ThreadMetaService
¶
Bases: BaseService
Thread meta service.
Source code in sharkservers/forum/services.py
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 | |
Meta
¶
Thread meta service meta.
Source code in sharkservers/forum/services.py
54 55 56 57 58 | |
fill_meta(thread_id: int, data: dict) -> ThreadMeta
async
¶
Fill thread meta.
thread_id (int): The thread id.
data (dict): The data.
ThreadMeta: The thread meta.
Source code in sharkservers/forum/services.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
ThreadService
¶
Bases: BaseService
Thread service.
Source code in sharkservers/forum/services.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 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 | |
Meta
¶
Thread service meta.
Source code in sharkservers/forum/services.py
81 82 83 84 85 | |
create_thread(data: CreateThreadSchema, author: User, category: Category, status: ThreadStatusEnum = ThreadStatusEnum.PENDING.value, thread_meta_service: ThreadMetaService = None, servers_service: ServerService = None, **kwargs) -> ThreadOut
async
¶
Create thread.
data (CreateThreadSchema): The data.
author (User): The author.
category (Category): The category.
status (ThreadStatusEnum, optional): The status. Defaults to ThreadStatusEnum.PENDING.value.
thread_meta_service (ThreadMetaService, optional): The thread meta service. Defaults to None.
servers_service (ServerService, optional): The servers service. Defaults to None.
**kwargs: The kwargs.
HTTPException: The HTTP exception.
ThreadOut: The thread.
Source code in sharkservers/forum/services.py
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 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 | |
sync_counters() -> None
async
¶
Sync thread posts counters.
Source code in sharkservers/forum/services.py
181 182 183 184 185 186 187 188 189 190 | |
set_author_role(thread: Thread) -> None
async
¶
Set author role.
thread (Thread): The thread.
None: None.
Source code in sharkservers/forum/services.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
PostService
¶
Bases: BaseService
Post service.
Source code in sharkservers/forum/services.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
Meta
¶
Post service meta.
Source code in sharkservers/forum/services.py
216 217 218 219 220 | |
sync_counters() -> None
async
¶
Sync post likes counters.
Source code in sharkservers/forum/services.py
222 223 224 225 226 227 228 229 230 231 | |
LikeService
¶
Bases: BaseService
Like service.
Source code in sharkservers/forum/services.py
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 | |
Meta
¶
Like service meta.
Source code in sharkservers/forum/services.py
237 238 239 240 241 | |
add_like_to_post(post: Post, author: User) -> tuple[LikeOut, int]
async
¶
Add like to post.
post (Post): The post.
author (User): The author.
like_already_exists_exception: The like already exists exception.
tuple[LikeOut, int]: The like and likes count.
Source code in sharkservers/forum/services.py
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 | |
remove_like_from_post(post: Post, author: User) -> dict
async
¶
Remove like from post.
post (Post): The post.
author (User): The author.
like_not_found_exception: The like not found exception.
dict: The dict.
Source code in sharkservers/forum/services.py
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 | |
views
¶
sharkservers_api.
sharkservers-api
(C) 2023-present Adrian Ciołek (Qwizi)
admin
¶
sharkservers_api.
sharkservers-api
(C) 2023-present Adrian Ciołek (Qwizi)
categories
¶
Admin categories views.
admin_create_category(category_data: CreateCategorySchema, categories_service: CategoryService = Depends(get_categories_service)) -> CategoryOut
async
¶
Admin create category.
category_data (CreateCategorySchema): The category data.
categories_service (CategoryService, optional): The categories service. Defaults to Depends(get_categories_service).
Category: The category.
Source code in sharkservers/forum/views/admin/categories.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
admin_delete_category(category: Category = Depends(get_valid_category)) -> CategoryOut
async
¶
Delete category.
category (Category, optional): The category. Defaults to Depends(get_valid_category).
Category: The category.
Source code in sharkservers/forum/views/admin/categories.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
posts
¶
Admin posts views.
admin_delete_post(post: Post = Depends(get_valid_post)) -> PostOut
async
¶
Admin delete post.
post (Post, optional): The post. Defaults to Depends(get_valid_post).
Post: The post.
Source code in sharkservers/forum/views/admin/posts.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
admin_update_post(post_data: AdminUpdatePostSchema, posts_service: PostService = Depends(get_posts_service), threads_service: ThreadService = Depends(get_threads_service), users_service: UserService = Depends(get_users_service)) -> PostOut
async
¶
Admin update post.
post_data (AdminUpdatePostSchema): The post data.
posts_service (PostService, optional): The posts service. Defaults to Depends(get_posts_service).
threads_service (ThreadService, optional): The threads service. Defaults to Depends(get_threads_service).
users_service (UserService, optional): The users service. Defaults to Depends(get_users_service).
PostOut: The post.
Source code in sharkservers/forum/views/admin/posts.py
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 | |
threads
¶
Admin threads views.
router = APIRouter()
module-attribute
¶
admin_delete_thread(thread: Thread = Depends(get_valid_thread)) -> ThreadOut
async
¶
Delete thread.
thread (Thread, optional): The thread. Defaults to Depends(get_valid_thread).
Thread: The thread.
Source code in sharkservers/forum/views/admin/threads.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
admin_update_thread(update_thread_data: AdminUpdateThreadSchema, thread: Thread = Depends(get_valid_thread), threads_service: ThreadService = Depends(get_threads_service), users_service: UserService = Depends(get_users_service), categories_service: CategoryService = Depends(get_categories_service)) -> ThreadOut
async
¶
Update thread.
update_thread_data (AdminUpdateThreadSchema): The update thread data.
thread (Thread, optional): The thread. Defaults to Depends(get_valid_thread).
threads_service (ThreadService, optional): The threads service. Defaults to Depends(get_threads_service).
users_service (UserService, optional): The users service. Defaults to Depends(get_users_service).
categories_service (CategoryService, optional): The categories service. Defaults to Depends(get_categories_service).
Thread: The thread.
Source code in sharkservers/forum/views/admin/threads.py
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 | |
run_thread_action(data: AdminThreadActionSchema, thread: Thread = Depends(get_valid_thread), categories_service: CategoryService = Depends(get_categories_service)) -> ThreadOut
async
¶
Run thread action.
data (AdminThreadActionSchema): The data.
thread (Thread, optional): The thread. Defaults to Depends(get_valid_thread).
threads_service (ThreadService, optional): The threads service. Defaults to Depends(get_threads_service).
categories_service (CategoryService, optional): The categories service. Defaults to Depends(get_categories_service).
HTTPException: The HTTP exception.
ThreadOut: The thread.
Source code in sharkservers/forum/views/admin/threads.py
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 | |
categories
¶
Category views.
get_categories(params: Params = Depends(), queries: OrderQuery = Depends(), categories_service: CategoryService = Depends(get_categories_service)) -> Page[CategoryOut]
async
¶
Get all categories.
params (Params, optional): The params. Defaults to Depends().
queries (OrderQuery, optional): The queries. Defaults to Depends().
categories_service (CategoryService, optional): The categories service. Defaults to Depends(get_categories_service).
Page[CategoryOut]: The categories.
Source code in sharkservers/forum/views/categories.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
get_category(category: Category = Depends(get_valid_category)) -> CategoryOut
async
¶
Get a category.
category (Category, optional): The category. Defaults to Depends(get_valid_category).
CategoryOut: The category.
Source code in sharkservers/forum/views/categories.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
posts
¶
Posts views.
get_posts(thread_id: int | None = None, params: Params = Depends(), queries: PostQuery = Depends(), posts_service: PostService = Depends(get_posts_service)) -> Page[PostOut]
async
¶
Get all posts.
thread_id (int, optional): The thread ID. Defaults to None.
params (Params, optional): The params. Defaults to Depends().
queries (PostQuery, optional): The queries. Defaults to Depends().
posts_service (PostService, optional): The posts service. Defaults to Depends(get_posts_service).
Page[PostOut]: The posts.
Source code in sharkservers/forum/views/posts.py
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 | |
get_post_by_id(post: Post = Depends(get_valid_post)) -> PostOut
async
¶
Get post by ID.
post (Post): The post. Defaults to Depends(get_valid_post).
Post: The post.
Source code in sharkservers/forum/views/posts.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
create_post(post_data: CreatePostSchema, user: User = Security(get_current_active_user, scopes=['posts:create']), posts_service: PostService = Depends(get_posts_service), threads_service: ThreadService = Depends(get_threads_service)) -> PostOut
async
¶
Create post.
post_data (CreatePostSchema): The post data.
user (User, optional): The user. Defaults to Security(get_current_active_user, scopes=["posts:create"]).
posts_service (PostService, optional): The posts service. Defaults to Depends(get_posts_service).
threads_service (ThreadService, optional): The threads service. Defaults to Depends(get_threads_service).
thread_is_closed_exception: The thread is closed exception.
PostOut: The post.
Source code in sharkservers/forum/views/posts.py
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 | |
update_post(post_data: UpdatePostSchema, post: Post = Depends(get_valid_post_author)) -> PostOut
async
¶
Update post.
post_data (UpdatePostSchema): The post data.
post (Post, optional): The post. Defaults to Depends(get_valid_post_author).
Post: The post.
Source code in sharkservers/forum/views/posts.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
get_post_likes(post: Post = Depends(get_valid_post), likes_service: LikeService = Depends(get_likes_service), params: Params = Depends()) -> Page[LikeOut]
async
¶
Get post likes.
post (Post, optional): The post. Defaults to Depends(get_valid_post).
likes_service (LikeService, optional): The likes service. Defaults to Depends(get_likes_service).
params (Params, optional): The params. Defaults to Depends().
Page[LikeOut]: The likes.
Source code in sharkservers/forum/views/posts.py
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 | |
like_post(post: Post = Depends(get_valid_post), user: User = Security(get_current_active_user, scopes=['posts:create']), likes_service: LikeService = Depends(get_likes_service)) -> LikeOut
async
¶
Like post.
post (Post, optional): The post. Defaults to Depends(get_valid_post).
user (User, optional): The user. Defaults to Security(get_current_active_user, scopes=["posts:create"]).
likes_service (LikeService, optional): The likes service. Defaults to Depends(get_likes_service).
LikeOut: The like.
Source code in sharkservers/forum/views/posts.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
dislike_post(post: Post = Depends(get_valid_post), user: User = Security(get_current_active_user, scopes=['posts:create']), likes_service: LikeService = Depends(get_likes_service)) -> dict
async
¶
Dislike post.
post (Post, optional): The post. Defaults to Depends(get_valid_post).
user (User, optional): The user. Defaults to Security(get_current_active_user, scopes=["posts:create"]).
likes_service (LikeService, optional): The likes service. Defaults to Depends(get_likes_service).
dict: The response.
Source code in sharkservers/forum/views/posts.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
threads
¶
Threads views.
get_threads(params: Params = Depends(), queries: ThreadQuery = Depends(), threads_service: ThreadService = Depends(get_threads_service)) -> Page[ThreadOut]
async
¶
Get all threads.
params (Params, optional): The params. Defaults to Depends().
queries (ThreadQuery, optional): The queries. Defaults to Depends().
threads_service (ThreadService, optional): The threads service. Defaults to Depends(get_threads_service).
Page[ThreadOut]: The threads.
Source code in sharkservers/forum/views/threads.py
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 | |
create_thread(thread_data: CreateThreadSchema, user: User = Security(get_current_active_user, scopes=['threads:create']), threads_service: ThreadService = Depends(get_threads_service), categories_service: CategoryService = Depends(get_categories_service), thread_meta_service: ThreadMetaService = Depends(get_thread_meta_service), servers_service: ServerService = Depends(get_servers_service)) -> ThreadOut
async
¶
Create thread.
thread_data (CreateThreadSchema): The thread data.
user (User, optional): The user. Defaults to Security(get_current_active_user, scopes=["threads:create"]).
threads_service (ThreadService, optional): The threads service. Defaults to Depends(get_threads_service).
categories_service (CategoryService, optional): The categories service. Defaults to Depends(get_categories_service).
thread_meta_service (ThreadMetaService, optional): The thread meta service. Defaults to Depends(get_thread_meta_service).
servers_service (ServerService, optional): The servers service. Defaults to Depends(get_servers_service).
ThreadOut: The thread.
Source code in sharkservers/forum/views/threads.py
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 | |
get_thread(thread: Thread = Depends(get_valid_thread)) -> ThreadOut
async
¶
Get thread by id.
thread (Thread, optional): The thread. Defaults to Depends(get_valid_thread).
ThreadOut: The thread.
Source code in sharkservers/forum/views/threads.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
update_thread(thread_data: UpdateThreadSchema, thread: Thread = Depends(get_valid_thread_with_author)) -> ThreadOut
async
¶
Update thread by id.
thread_data (UpdateThreadSchema): The thread data.
thread (Thread, optional): The thread. Defaults to Depends(get_valid_thread_with_author).
ThreadOut: The thread.
Source code in sharkservers/forum/views/threads.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
logger
¶
Logging configuration for the server.
logger_with_filename(filename: str, data: str) -> None
¶
Log a message with the filename and data.
filename (str): The filename to log.
data (str): The data to log.
None
Source code in sharkservers/logger.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
main
¶
Main moduke of the SharkServers API.
It contains the FastAPI application setup, including routes, middlewares, and WebSocket endpoints.
init_routes(_app: FastAPI) -> FastAPI
¶
Initialize the routes for the FastAPI application.
_app (FastAPI): The FastAPI application instance.
FastAPI: The FastAPI application instance with the routes initialized.
Source code in sharkservers/main.py
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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
update_tables_counters() -> None
async
¶
Cron job function to update the counters in the database tables.
Source code in sharkservers/main.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
add_middlewares(_app: FastAPI) -> FastAPI
¶
Add middlewares to the FastAPI application.
_app (FastAPI): The FastAPI application instance.
FastAPI: The FastAPI application instance with the middlewares added.
Source code in sharkservers/main.py
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 | |
create_app() -> FastAPI
¶
Create the FastAPI application.
Returns¶
FastAPI: The FastAPI application instance.
Source code in sharkservers/main.py
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 | |
manager
¶
Module contains the ConnectionManager class, which manages WebSocket connections and provides methods for sending messages.
ConnectionManager
¶
Manages WebSocket connections and provides methods for sending messages.
Source code in sharkservers/manager.py
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 | |
__init__() -> None
¶
Initialize the ConnectionManager class.
Source code in sharkservers/manager.py
17 18 19 | |
connect(websocket: WebSocket) -> None
async
¶
Accepts a WebSocket connection and adds it to the list of active connections.
websocket (WebSocket): The WebSocket connection to be added.
Source code in sharkservers/manager.py
21 22 23 24 25 26 27 28 29 30 31 | |
disconnect(websocket: WebSocket) -> None
¶
Removes a WebSocket connection from the list of active connections.
websocket (WebSocket): The WebSocket connection to be removed.
None
Source code in sharkservers/manager.py
33 34 35 36 37 38 39 40 41 42 43 44 45 | |
send_personal_message(chat_schema: ChatEventSchema, websocket: WebSocket) -> None
async
¶
Send a personal message to a specific WebSocket connection.
chat_schema (ChatEventSchema): The chat event schema to be sent.
websocket (WebSocket): The WebSocket connection to send the message to.
None
Source code in sharkservers/manager.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
broadcast(chat_schema: ChatEventSchema) -> None
async
¶
Send a message to all active WebSocket connections.
chat_schema (ChatEventSchema): The chat event schema to be sent.
None
Source code in sharkservers/manager.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
middleware
¶
log_request_middleware(request: Request, call_next)
async
¶
This middleware will log all requests and their processing time. E.g. log: 0.0.0.0:1234 - GET /ping 200 OK 1.00ms
Source code in sharkservers/middleware.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
players
¶
sharkservers_api.
sharkservers-api
(C) 2023-present Adrian Ciołek (Qwizi)
dependencies
¶
Players dependencies.
get_steamrep_service() -> SteamRepService
async
¶
Retrieve an instance of the SteamRepService class.
Returns¶
SteamRepService: An instance of the SteamRepService class.
Source code in sharkservers/players/dependencies.py
13 14 15 16 17 18 19 20 21 | |
get_players_service(steamrep_service: SteamRepService = Depends(get_steamrep_service), settings: Settings = Depends(get_settings)) -> PlayerService
async
¶
Retrieve the PlayerService instance with the specified dependencies.
steamrep_service (SteamRepService): The SteamRepService instance.
settings (Settings): The Settings instance.
PlayerService: The PlayerService instance.
Source code in sharkservers/players/dependencies.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
get_valid_player(player_id: int, player_service: PlayerService = Depends(get_players_service)) -> Player
async
¶
Retrieve a valid player by their ID.
player_id (int): The ID of the player.
player_service (PlayerService, optional): The player service dependency. Defaults to Depends(get_players_service).
Player: The valid player object.
Source code in sharkservers/players/dependencies.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
get_valid_player_by_steamid(steamid64: str, player_service: PlayerService = Depends(get_players_service)) -> Player
async
¶
Retrieve a valid player by their SteamID.
steamid64 (str): The SteamID of the player.
player_service (PlayerService, optional): The player service dependency. Defaults to Depends(get_players_service).
Player: The player object.
Source code in sharkservers/players/dependencies.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
enums
¶
Players enums.
exceptions
¶
Players exceptions.
models
¶
Players models.
SteamRepProfile
¶
Bases: Model, DateFieldsMixins
Represents a SteamRep profile.
Attributes¶
id (int): The unique identifier of the profile.
profile_url (str): The URL of the profile.
is_scammer (bool): Indicates if the profile is a scammer.
steamid64 (str): The 64-bit Steam ID of the profile.
Source code in sharkservers/players/models.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
Player
¶
Bases: Model, DateFieldsMixins
Represents a player in the game.
Attributes¶
id (int): The unique identifier of the player.
steamrep_profile (Optional[SteamRepProfile]): The player's SteamRep profile.
username (str): The username of the player.
steamid3 (str): The player's SteamID3.
steamid32 (str): The player's SteamID32.
steamid64 (str): The player's SteamID64.
profile_url (str): The URL to the player's profile.
avatar (str): The URL to the player's avatar.
country_code (str): The country code of the player.
reputation (int): The reputation score of the player.
Source code in sharkservers/players/models.py
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 | |
schemas
¶
Schemas for the players module.
PlayerOut
¶
Bases: player_out
Player out schema.
Source code in sharkservers/players/schemas.py
11 12 | |
SteamPlayer
¶
Bases: BaseModel
Steam player schema.
Source code in sharkservers/players/schemas.py
15 16 17 18 19 20 21 22 23 24 25 | |
CreatePlayerSchema
¶
Bases: BaseModel
Create player schema.
Source code in sharkservers/players/schemas.py
28 29 30 31 | |
services
¶
Player services.
SteamRepService
¶
Bases: BaseService
Service for interacting with SteamRep API.
Attributes¶
api_url (str): The URL to the SteamRep API.
Methods¶
get_data(steamid64: str) -> tuple[str, bool]: Get data from SteamRep API for a given steamid64.
create_profile(steamid64: str) -> SteamRepProfile: Create a SteamRep profile for a given steamid64.
Source code in sharkservers/players/services.py
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 | |
Meta
¶
SteamRep service metadata.
Source code in sharkservers/players/services.py
39 40 41 42 43 | |
get_data(steamid64: str) -> tuple[str, bool]
async
¶
Get data from SteamRep API for a given steamid64.
steamid64 (str): The steamid64 of the player.
tuple: A tuple containing the profile URL and a boolean indicating if the player is a scammer.
Source code in sharkservers/players/services.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
create_profile(steamid64: str) -> SteamRepProfile
async
¶
Create a SteamRep profile for a given steamid64.
steamid64 (str): The steamid64 of the player.
SteamRepProfile: The created SteamRep profile.
Source code in sharkservers/players/services.py
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 | |
PlayerService
¶
Bases: BaseService
Service for interacting with Player data.
Attributes¶
steam_api_key (str): The Steam API key.
steam_api (WebAPI): The Steam API.
steamrep_service (SteamRepService): The SteamRep service.
Methods¶
get_steam_player_info(steamid64: str) -> SteamPlayer: Get Steam player information for a given steamid64.
create_player(steamid64: str) -> Player: Create a player with the given steamid64.
Source code in sharkservers/players/services.py
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 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 | |
Meta
¶
Player service metadata.
Source code in sharkservers/players/services.py
115 116 117 118 119 | |
__init__(steam_api_key: str, steamrep_service: SteamRepService) -> None
¶
Initialize the PlayerService.
Source code in sharkservers/players/services.py
121 122 123 124 | |
get_steam_player_info(steamid64: str) -> SteamPlayer
¶
Get Steam player information for a given steamid64.
steamid64 (str): The steamid64 of the player.
SteamPlayer: The Steam player information.
Source code in sharkservers/players/services.py
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 | |
create_player(steamid64: str) -> Player
async
¶
Create a player with the given steamid64.
steamid64 (str): The steamid64 of the player.
Player: The created player.
Source code in sharkservers/players/services.py
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 | |
views
¶
Players views.
get_players(params: Params = Depends(), players_service: PlayerService = Depends(get_players_service)) -> Page[PlayerOut]
async
¶
Retrieve a list of players based on the provided parameters.
params (Params): The parameters for filtering and pagination.
players_service (PlayerService): The service for retrieving player data.
Page[PlayerOut]: A paginated list of player data.
Source code in sharkservers/players/views.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
create_player(player_data: CreatePlayerSchema, players_service: PlayerService = Depends(get_players_service)) -> PlayerOut
async
¶
Create a new player.
player_data (CreatePlayerSchema): The data for creating a player.
players_service (PlayerService): The service for managing players.
PlayerOut: The created player.
Source code in sharkservers/players/views.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
get_player(player: Player = Depends(get_valid_player_by_steamid)) -> PlayerOut
async
¶
Retrieve a player by their Steam ID.
player (Player): The player object obtained from the `get_valid_player_by_steamid` dependency.
Player: The retrieved player object.
Source code in sharkservers/players/views.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
views_admin
¶
Admin views for players.
admin_get_steam_profiles(params: Params = Depends(), players_service: PlayerService = Depends(get_players_service)) -> Page[PlayerOut]
async
¶
Retrieve all player profiles with their associated SteamRep profiles.
params (Params): The parameters for filtering and pagination.
players_service (PlayerService): The service for retrieving player profiles.
Page[PlayerOut]: A paginated list of player profiles with their associated SteamRep profiles.
Source code in sharkservers/players/views_admin.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
admin_get_steam_profile(profile_id: int) -> PlayerOut
async
¶
Retrieve the Steam profile of a player with the given profile ID.
profile_id (int): The ID of the player's Steam profile.
PlayerOut: The player's Steam profile.
player_not_found_exception: If the player's profile is not found.
Source code in sharkservers/players/views_admin.py
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 | |
admin_create_player(profile_data: CreatePlayerSchema, background_tasks: BackgroundTasks, players_service: PlayerService = Depends(get_players_service)) -> dict
async
¶
Admin endpoint to create a player.
profile_data (CreatePlayerSchema): The data for creating a player.
background_tasks (BackgroundTasks): The background tasks object.
players_service (PlayerService, optional): The player service dependency. Defaults to Depends(get_players_service).
dict: A dictionary with a message indicating that the player was created.
Source code in sharkservers/players/views_admin.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
admin_delete_steam_profile(profile_id: int) -> PlayerOut
async
¶
Delete a Steam profile with the given profile ID.
profile_id (int): The ID of the profile to delete.
PlayerOut: The deleted player profile.
player_not_found_exception: If the player profile with the given ID is not found.
Source code in sharkservers/players/views_admin.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 | |
roles
¶
sharkservers_api.
sharkservers-api
(C) 2023-present Adrian Ciołek (Qwizi)
dependencies
¶
Dependencies for roles module.
get_roles_service() -> RoleService
async
¶
Get the RoleService instance.
Source code in sharkservers/roles/dependencies.py
9 10 11 | |
get_valid_role(role_id: int, roles_service: RoleService = Depends(get_roles_service)) -> Model
async
¶
Get a valid role by its ID.
role_id (int): The ID of the role.
roles_service (RoleService, optional): The RoleService instance to use. Defaults to Depends(get_roles_service).
Model: The valid role model.
Source code in sharkservers/roles/dependencies.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
enums
¶
Enum classes for roles module.
ProtectedDefaultRolesEnum
¶
Enumeration class for protected default roles.
Source code in sharkservers/roles/enums.py
5 6 7 8 9 10 11 12 13 14 15 16 | |
has_value(value) -> bool
classmethod
¶
Check if the given value is a valid member of the enumeration.
Source code in sharkservers/roles/enums.py
13 14 15 16 | |
ProtectedDefaultRolesTagEnum
¶
Enumeration class for protected default role tags.
Source code in sharkservers/roles/enums.py
19 20 21 22 23 24 25 26 27 28 29 30 | |
has_value(value) -> bool
classmethod
¶
Check if the given value is a valid member of the enumeration.
Source code in sharkservers/roles/enums.py
27 28 29 30 | |
RolesExceptionsDetailEnum
¶
Enumeration class for roles exceptions detail.
Source code in sharkservers/roles/enums.py
33 34 35 36 37 38 | |
RolesEventsEnum
¶
Enumeration class for roles events.
Source code in sharkservers/roles/enums.py
41 42 43 44 45 46 47 | |
RolesAdminEventsEnum
¶
Enumeration class for roles admin events.
Source code in sharkservers/roles/enums.py
50 51 52 53 54 55 56 57 58 59 60 61 62 | |
exceptions
¶
Exceptions for roles module.
models
¶
Roles models.
Role
¶
Bases: Model, DateFieldsMixins
Represent a role in the system.
Attributes¶
id (int): The unique identifier of the role.
tag (str, optional): The tag associated with the role.
name (str, optional): The name of the role.
color (str, optional): The color associated with the role.
scopes (List[Scope], optional): The list of scopes associated with the role.
is_staff (bool, optional): Indicates if the role is a staff role.
Source code in sharkservers/roles/models.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
schemas
¶
Schemas for the roles module.
RoleOut
¶
Bases: role_out
RoleOut schema.
Source code in sharkservers/roles/schemas.py
13 14 | |
RoleOutWithScopes
¶
Bases: role_out_with_scopes
RoleOutWithScopes schema.
Source code in sharkservers/roles/schemas.py
17 18 | |
RoleOutWithoutScopesAndUserRoles
¶
Bases: role_out_without_scopes_and_user_roles
RoleOutWithoutScopesAndUserRoles schema.
Source code in sharkservers/roles/schemas.py
21 22 | |
StaffUserInRolesSchema
¶
Bases: BaseModel
StaffUserInRolesSchema schema.
Source code in sharkservers/roles/schemas.py
25 26 27 28 29 30 | |
StaffRolesSchema
¶
Bases: BaseModel
StaffRolesSchema schema.
Source code in sharkservers/roles/schemas.py
33 34 35 36 37 38 39 | |
CreateRoleSchema
¶
Bases: BaseModel
CreateRoleSchema schema.
Source code in sharkservers/roles/schemas.py
42 43 44 45 46 47 48 49 | |
UpdateRoleSchema
¶
Bases: BaseModel
UpdateRoleSchema schema.
Source code in sharkservers/roles/schemas.py
52 53 54 55 56 57 58 59 | |
services
¶
Services for roles.
RoleService
¶
Bases: BaseService
Service class for managing roles.
Attributes¶
create_default_roles (Callable): Creates default roles with specified scopes.
get_staff_roles (Callable): Retrieves staff roles.
admin_create_role (Callable): Creates a role with specified scopes.
Source code in sharkservers/roles/services.py
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 | |
Meta
¶
RoleService metadata.
Source code in sharkservers/roles/services.py
31 32 33 34 35 | |
create_default_roles(scopes_service: ScopeService) -> None
async
¶
Creates default roles with specified scopes.
scopes_service (ScopeService): The service for managing scopes.
Source code in sharkservers/roles/services.py
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 | |
get_staff_roles(params: Params) -> Page[Role]
async
¶
Retrieves staff roles.
params: Additional parameters for filtering or pagination.
List: A list of staff roles.
Source code in sharkservers/roles/services.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
admin_create_role(role_data: CreateRoleSchema, scopes_service: ScopeService) -> Role
async
¶
Create a role with specified scopes.
role_data (CreateRoleSchema): The data for creating the role.
scopes_service (ScopeService): The service for managing scopes.
Role: The created role.
Source code in sharkservers/roles/services.py
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 | |
views
¶
Views for roles.
get_roles(params: Params = Depends(), roles_service: RoleService = Depends(get_roles_service)) -> Page[RoleOut]
async
¶
Retrieve all roles based on the provided parameters.
params (Params): The parameters for filtering and pagination.
roles_service (RoleService): The service for retrieving roles.
Page[RoleOut]: A paginated list of RoleOut objects.
Source code in sharkservers/roles/views.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
get_role(role: Role = Depends(get_valid_role)) -> RoleOutWithScopes
async
¶
Retrieve a role by its ID.
role (Role): The role object.
RoleOutWithScopes: The role object with associated scopes.
Source code in sharkservers/roles/views.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
views_admin
¶
Views for admin roles.
admin_get_roles(params: Params = Depends(), roles_service: RoleService = Depends(get_roles_service)) -> Page[RoleOut]
async
¶
Retrieve all roles with pagination.
params (Params, optional): The query parameters for pagination. Defaults to Depends().
admin_user (User, optional): The authenticated admin user. Defaults to Security(get_admin_user, scopes=["roles:all"]).
roles_service (RoleService, optional): The service for managing roles. Defaults to Depends(get_roles_service).
Page[RoleOut]: The paginated list of roles.
Source code in sharkservers/roles/views_admin.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
admin_get_role(role: Role = Depends(get_valid_role)) -> RoleOutWithScopes
async
¶
Retrieve the details of a role.
role (Role): The role object to retrieve details for.
RoleOutWithScopes: The role object with associated scopes.
Source code in sharkservers/roles/views_admin.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
admin_create_role(role_data: CreateRoleSchema, roles_service: RoleService = Depends(get_roles_service), scopes_service: ScopeService = Depends(get_scopes_service)) -> RoleOutWithScopes
async
¶
Admin endpoint to create a new role.
role_data (CreateRoleSchema): The data for creating the role.
roles_service (RoleService, optional): The service for managing roles. Defaults to Depends(get_roles_service).
scopes_service (ScopeService, optional): The service for managing scopes. Defaults to Depends(get_scopes_service).
The newly created role.
Source code in sharkservers/roles/views_admin.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
admin_delete_role(role: Role = Depends(get_valid_role), roles_service: RoleService = Depends(get_roles_service)) -> RoleOutWithScopes
async
¶
Delete a role.
role (Role): The role to be deleted.
roles_service (RoleService): The service used to delete the role.
RoleOutWithScopes: The deleted role.
Source code in sharkservers/roles/views_admin.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
admin_update_role(update_role_data: UpdateRoleSchema, role: Role = Depends(get_valid_role), scopes_service: ScopeService = Depends(get_scopes_service)) -> RoleOutWithScopes
async
¶
Update a role with the provided data.
update_role_data (UpdateRoleSchema): The data to update the role with.
role (Role): The role to be updated.
scopes_service (ScopeService): The service to handle scopes.
Role: The updated role.
Source code in sharkservers/roles/views_admin.py
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 | |
schemas
¶
Module contains the schema definitions used in the SharkServers API.
It includes the following classes: - CreateAdmin: Represents the schema for creating an admin user. - HTTPErrorSchema: Represents the base schema for HTTP error responses. - HTTPError404Schema: Represents the schema for a 404 Not Found error response. - HTTPError400Schema: Represents the schema for a 400 Bad Request error response. - HTTPError401Schema: Represents the schema for a 401 Unauthorized error response. - OrderQuery: Represents the schema for the order query parameter.
CreateAdmin
¶
Bases: BaseModel
Represents the data required to create an admin.
Attributes¶
admin_username (str): The username of the admin.
admin_password (str): The password of the admin.
admin_email (str): The email address of the admin.
Source code in sharkservers/schemas.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
HTTPErrorSchema
¶
Bases: BaseModel
Schema for representing an HTTP error response.
Attributes¶
detail (str): The error message.
Source code in sharkservers/schemas.py
37 38 39 40 41 42 43 44 45 46 | |
HTTPError404Schema
¶
Bases: HTTPErrorSchema
Schema for representing a 404 Not Found HTTP error.
Source code in sharkservers/schemas.py
49 50 51 52 | |
HTTPError400Schema
¶
Bases: HTTPErrorSchema
Schema for HTTP 400 Bad Request error.
Source code in sharkservers/schemas.py
55 56 57 58 | |
HTTPError401Schema
¶
Bases: HTTPErrorSchema
Schema for representing a 401 Unauthorized HTTP error.
Inherits from the base HTTPErrorSchema class.
Source code in sharkservers/schemas.py
61 62 63 64 65 66 67 68 | |
OrderQuery
¶
Bases: BaseModel
Represents the query parameters for ordering data.
:param order_by: The field to order by.
Source code in sharkservers/schemas.py
71 72 73 74 75 76 77 78 79 80 81 82 | |
scopes
¶
sharkservers_api.
sharkservers-api
(C) 2023-present Adrian Ciołek (Qwizi)
dependencies
¶
Dependencies for scopes endpoints.
get_scopes_service() -> ScopeService
async
¶
Get the ScopeService instance.
Source code in sharkservers/scopes/dependencies.py
9 10 11 | |
get_valid_scope(scope_id: int, scopes_service: ScopeService = Depends(get_scopes_service)) -> Scope
async
¶
Get a valid scope by ID.
Source code in sharkservers/scopes/dependencies.py
14 15 16 17 18 19 | |
enums
¶
Enums for scopes module.
ScopeEnum
¶
Bases: Enum
Scope enum.
Source code in sharkservers/scopes/enums.py
5 6 7 8 9 10 11 12 | |
ScopesExceptionsDetailEnum
¶
ScopesEventsEnum
¶
Scopes events enum.
Source code in sharkservers/scopes/enums.py
21 22 23 24 25 26 27 | |
ScopesAdminEventsEnum
¶
Scopes events enum.
Source code in sharkservers/scopes/enums.py
30 31 32 33 34 35 36 37 38 39 40 41 42 | |
exceptions
¶
Exceptions for scopes module.
models
¶
Scopes models.
Scope
¶
Bases: Model
Represents a scope in the application.
Attributes¶
id (int): The unique identifier of the scope.
app_name (str): The name of the application.
value (str): The value of the scope.
description (str): The description of the scope.
protected (bool): Indicates if the scope is protected.
Methods¶
get_string(): Returns a string representation of the scope.
get_tuple(): Returns a tuple representation of the scope.
get_dict(): Returns a dictionary representation of the scope.
Source code in sharkservers/scopes/models.py
7 8 9 10 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 | |
Meta
¶
Bases: BaseMeta
Meta class for Scope model.
Source code in sharkservers/scopes/models.py
26 27 28 29 | |
get_string() -> str
¶
Return a string representation of the object.
Returns¶
str: The string representation of the object.
Source code in sharkservers/scopes/models.py
37 38 39 40 41 42 43 44 45 | |
get_tuple() -> tuple
¶
Return a tuple containing the formatted app name and value, along with the description.
Returns¶
tuple: A tuple containing the formatted app name and value, along with the description.
Source code in sharkservers/scopes/models.py
47 48 49 50 51 52 53 54 55 | |
get_dict() -> dict
¶
Return a dictionary representation of the object.
Returns¶
dict: A dictionary with the object's attributes.
Source code in sharkservers/scopes/models.py
57 58 59 60 61 62 63 64 65 66 67 68 | |
schemas
¶
Schemas for scopes module.
CreateScopeSchema
¶
Bases: BaseModel
Create scope schema.
Source code in sharkservers/scopes/schemas.py
11 12 13 14 15 16 17 | |
UpdateScopeSchema
¶
Bases: BaseModel
Update scope schema.
Source code in sharkservers/scopes/schemas.py
20 21 22 23 24 25 26 | |
services
¶
Scopes services.
ScopeService
¶
Bases: BaseService
Service class for managing scopes.
Attributes¶
extra_scopes : list[CreateScopeSchema] | None List of extra scopes. default_scopes : list[str] List of default scopes.
Methods¶
add_default_scopes(apps)
Add default scope.
add_extra_scope(app_name, scope_values)
Add extra scope.
get_extra_scopes()
Get extra scopes.
create_scopes_for_app(app_name, additional_scopes)
Create scopes for app.
create_default_scopes(applications, additional=None)
Create default scopes for applications.
get_scopes_list(roles)
Get list of scopes for the given roles.
get_default_scopes_for_role(role_id)
Get default scopes for the given role.
Source code in sharkservers/scopes/services.py
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 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 | |
Meta
¶
Meta class for ScopeService.
Source code in sharkservers/scopes/services.py
51 52 53 54 55 | |
add_default_scopes(apps: list[str]) -> ScopeService
¶
Add default scope.
Args:¶
apps : list[str] List of application names.
Returns:¶
ScopeService The ScopeService instance.
Source code in sharkservers/scopes/services.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
add_extra_scope(app_name: str, scope_values: list[tuple[str, str, str]]) -> ScopeService
¶
Add extra scope.
Parameters¶
app_name : str Name of the application. scope_values : list[tuple[str, str, str]] List of tuples containing scope values.
Returns¶
ScopeService The ScopeService instance.
Source code in sharkservers/scopes/services.py
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 | |
get_extra_scopes() -> list[CreateScopeSchema]
¶
Get extra scopes.
Returns¶
list[CreateScopeSchema] List of extra scopes.
Source code in sharkservers/scopes/services.py
112 113 114 115 116 117 118 119 120 121 122 | |
create_scopes_for_app(app_name: str, additional_scopes: list[tuple[str, str, str]]) -> None
async
¶
Create scopes for app.
Args:¶
app_name : str Name of the application. additional_scopes : list[tuple[str, str, str]] List of tuples containing additional scope values.
Returns:¶
None
Source code in sharkservers/scopes/services.py
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 | |
create_default_scopes(applications, additional=None) -> None
async
¶
Create default scopes for applications.
Parameters¶
applications : list List of application names. additional : list, optional List of additional scope values, by default None.
Returns¶
None
Source code in sharkservers/scopes/services.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
get_scopes_list(roles: list[Role]) -> list[str]
async
staticmethod
¶
Get list of scopes for the given roles.
Args:¶
roles : list[Role] List of roles.
Returns:¶
list List of scopes.
Source code in sharkservers/scopes/services.py
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 | |
get_default_scopes_for_role(role_id: str) -> list[Scope]
async
¶
Get default scopes for the given role.
Args:¶
role_id : str ID of the role.
Returns:¶
list List of default scopes.
Source code in sharkservers/scopes/services.py
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 | |
views
¶
Scopes views.
get_all_scopes(params: Params = Depends(), scopes_service: ScopeService = Depends(get_scopes_service), role_id: int | None = None) -> Page[ScopeOut]
async
¶
Retrieve all scopes.
params (Params, optional): The request parameters. Defaults to Depends().
scopes_service (ScopeService, optional): The scope service. Defaults to Depends(get_scopes_service).
role_id (int | None, optional): The role ID. Defaults to None.
Page[ScopeOut]: The list of scopes.
Source code in sharkservers/scopes/views.py
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 | |
views_admin
¶
Scopes admin views.
admin_get_scopes(params: Params = Depends(), scopes_service: ScopeService = Depends(get_scopes_service)) -> Page[ScopeOut]
async
¶
Retrieve all scopes for admin users.
params (Params): The parameters for filtering and pagination.
scopes_service (ScopeService): The service for retrieving scopes.
Page[ScopeOut]: A paginated list of ScopeOut objects.
Source code in sharkservers/scopes/views_admin.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
admin_get_scope(scope: Scope = Depends(get_valid_scope)) -> ScopeOut
async
¶
Retrieve a scope for admin users.
scope (Scope): The scope to retrieve.
ScopeOut: The retrieved scope.
Source code in sharkservers/scopes/views_admin.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
admin_create_scope(scope_data: CreateScopeSchema, scopes_service: ScopeService = Depends(get_scopes_service)) -> ScopeOut
async
¶
Create a new scope.
scope_data (CreateScopeSchema): The data for creating the scope.
scopes_service (ScopeService, optional): The service for managing scopes. Defaults to Depends(get_scopes_service).
ScopeOut: The created scope.
Source code in sharkservers/scopes/views_admin.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
admin_delete_scope(scope: Scope = Depends(get_valid_scope), scopes_service: ScopeService = Depends(get_scopes_service)) -> ScopeOut
async
¶
Deletes a scope from the system.
scope (Scope): The scope to be deleted.
scopes_service (ScopeService): The service responsible for managing scopes.
ScopeOut: The deleted scope.
Source code in sharkservers/scopes/views_admin.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
admin_update_scope(update_scope_data: UpdateScopeSchema, scope: Scope = Depends(get_valid_scope)) -> ScopeOut
async
¶
Update the given scope with the provided data.
update_scope_data (UpdateScopeSchema): The data to update the scope with.
scope (Scope): The scope to be updated.
ScopeOut: The updated scope.
Source code in sharkservers/scopes/views_admin.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
servers
¶
sharkservers_api.
sharkservers-api
(C) 2023-present Adrian Ciołek (Qwizi)
dependencies
¶
Dependencies for the servers module.
get_servers_service() -> ServerService
async
¶
Retrieve the server service.
Returns¶
ServerService: The server service instance.
Source code in sharkservers/servers/dependencies.py
8 9 10 11 12 13 14 15 16 | |
get_valid_server(server_id: int, servers_service: ServerService = Depends(get_servers_service)) -> Model
async
¶
Retrieve a valid server with the given server ID.
server_id (int): The ID of the server to retrieve.
servers_service (ServerService): The server service dependency.
Model: The retrieved server model.
Source code in sharkservers/servers/dependencies.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
exceptions
¶
Exceptions for the servers module.
models
¶
Servers models.
Server
¶
Bases: Model, DateFieldsMixins
Represents a server in the system.
Attributes¶
id (int): The unique identifier of the server.
name (str, optional): The name of the server.
tag (str, optional): The tag of the server.
ip (str, optional): The IP address of the server.
port (int, optional): The port number of the server.
admin_role (Role, optional): The admin role associated with the server.
api_url (str, optional): The API URL of the server.
Methods¶
get_sourcemod_api_config(): Returns the APIConfig object for the server's Sourcemod API.
get_admins_groups(params: Params) -> Page_GroupOut_: Retrieves a page of admin groups for the server.
get_admin_group(group_id: int): Retrieves an admin group by its ID.
create_admin_group(data: CreateGroupSchema): Creates a new admin group for the server.
delete_admin_group(group_id: int): Deletes an admin group by its ID.
get_admins(params: Params): Retrieves a page of admins for the server.
get_admin(identity: str): Retrieves an admin by their identity.
create_admin(data: CreateAdminSchema): Creates a new admin for the server.
update_admin(identity: str, data: UpdateAdminSchema): Updates an admin by their identity.
delete_admin(identity: str): Deletes an admin by their identity.
Source code in sharkservers/servers/models.py
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 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 | |
Meta
¶
Bases: BaseMeta
Metadata for the server model.
Source code in sharkservers/servers/models.py
67 68 69 70 | |
get_sourcemod_api_config() -> APIConfig
¶
Return the APIConfig object for the server's Sourcemod API.
Returns¶
APIConfig: The APIConfig object for the server's Sourcemod API.
Source code in sharkservers/servers/models.py
80 81 82 83 84 85 86 87 88 89 90 | |
get_admins_groups(params: Params) -> Page_GroupOut_
async
¶
Get a page of admin groups for the server.
params (Params): The pagination parameters.
Page_GroupOut_: The page of admin groups for the server.
Source code in sharkservers/servers/models.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
get_admin_group(group_id: int) -> GroupOut
async
¶
Get an admin group by its ID.
group_id (int): The ID of the admin group.
GroupOut: The admin group.
Source code in sharkservers/servers/models.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
create_admin_group(data: CreateGroupSchema) -> GroupOut
async
¶
Create a new admin group for the server.
data (CreateGroupSchema): The data for the new admin group.
GroupOut: The newly created admin group.
Source code in sharkservers/servers/models.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
delete_admin_group(group_id: int) -> GroupOut
async
¶
Delete an admin group by its ID.
group_id (int): The ID of the admin group.
GroupOut: The deleted admin group.
Source code in sharkservers/servers/models.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
get_admins(params: Params) -> Page_AdminOut_
async
¶
Get a page of admins for the server.
params (Params): The pagination parameters.
Page_AdminOut_: The page of admins for the server.
Source code in sharkservers/servers/models.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
get_admin(identity: str) -> AdminOut
async
¶
Get an admin by their identity.
identity (str): The identity of the admin.
Source code in sharkservers/servers/models.py
179 180 181 182 183 184 185 186 187 188 189 190 | |
create_admin(data: CreateAdminSchema) -> AdminOut
async
¶
Create a new admin for the server.
data (CreateAdminSchema): The data for the new admin.
AdminOut: The newly created admin.
Source code in sharkservers/servers/models.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
update_admin(identity: str, data: UpdateAdminSchema) -> AdminOut
async
¶
Update an admin by their identity.
identity (str): The identity of the admin.
data (UpdateAdminSchema): The data to update the admin with.
AdminOut: The updated admin.
Source code in sharkservers/servers/models.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
delete_admin(identity: str) -> AdminOut
async
¶
Delete an admin by their identity.
identity (str): The identity of the admin.
AdminOut: The deleted admin.
Source code in sharkservers/servers/models.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
create_admin_role(instance: Server) -> RoleOut
async
¶
Create an admin role for the server.
instance (Server): The server instance.
Role: The newly created admin role.
Source code in sharkservers/servers/models.py
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 | |
on_server_created(sender: Server, instance: Server, **kwargs) -> None
async
¶
On server created event.
sender (Server): The sender of the event.
instance (Server): The server instance.
**kwargs: The keyword arguments.
None
Source code in sharkservers/servers/models.py
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 | |
on_server_deleted(sender, instance: Server, **kwargs) -> None
async
¶
On server deleted event.
sender (Server): The sender of the event.
instance (Server): The server instance.
**kwargs: The keyword arguments.
Source code in sharkservers/servers/models.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
schemas
¶
Schemas for the servers module.
ServerOut
¶
Bases: server_out
Schema for retrieving a server.
Source code in sharkservers/servers/schemas.py
11 12 | |
CreateServerSchema
¶
Bases: BaseModel
Schema for creating a server.
Source code in sharkservers/servers/schemas.py
15 16 17 18 19 20 21 22 | |
UpdateServerSchema
¶
Bases: BaseModel
Schema for updating server information.
Source code in sharkservers/servers/schemas.py
25 26 27 28 29 30 31 32 | |
ServerStatusSchema
¶
Bases: BaseModel
Schema for retrieving a server's status.
Source code in sharkservers/servers/schemas.py
35 36 37 38 39 40 41 42 43 44 45 | |
services
¶
Services for servers app.
ServerService
¶
Bases: BaseService
Service class for managing server operations.
Methods¶
get_status(): Retrieves the status of all servers.
Source code in sharkservers/servers/services.py
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 | |
Meta
¶
Metadata for the service.
Source code in sharkservers/servers/services.py
24 25 26 27 28 | |
get_status() -> list[ServerStatusSchema]
async
¶
Retrieve the status of all servers.
Returns¶
list: A list of server status objects.
Source code in sharkservers/servers/services.py
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 | |
views
¶
sharkservers_api.
sharkservers-api
(C) 2023-present Adrian Ciołek (Qwizi)
admin
¶
sharkservers_api.
sharkservers-api
(C) 2023-present Adrian Ciołek (Qwizi)
admins
¶
Admin views for servers.
admin_get_server_admins(params: Params = Depends(), server: Server = Depends(get_valid_server)) -> Page_AdminOut_
async
¶
Retrieve the list of admins for a server.
params (Params): The query parameters for filtering and pagination.
server (Server): The server for which to retrieve the admins.
Page_AdminOut_: The paginated list of admins for the server.
Source code in sharkservers/servers/views/admin/admins.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
admin_create_server_admin(data: CreateAdminSchema, server: Server = Depends(get_valid_server)) -> AdminOut
async
¶
Create a server admin.
data (CreateAdminSchema): The data for creating the admin.
server (Server): The server instance.
AdminOut: The created admin.
Source code in sharkservers/servers/views/admin/admins.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
admin_get_server_admin(identity: str, server: Server = Depends(get_valid_server)) -> AdminOut
async
¶
Retrieve the admin information for a specific server.
identity (str): The identity of the admin.
server (Server): The server object.
AdminOut: The admin information.
Source code in sharkservers/servers/views/admin/admins.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
admin_update_server_admin(identity: str, data: UpdateAdminSchema, server: Server = Depends(get_valid_server)) -> AdminOut
async
¶
Update the server admin with the given identity using the provided data.
identity (str): The identity of the server admin to update.
data (UpdateAdminSchema): The updated admin data.
server (Server): The server instance.
AdminOut: The updated server admin.
Source code in sharkservers/servers/views/admin/admins.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
admin_delete_server_admin(identity: str, server: Server = Depends(get_valid_server)) -> AdminOut
async
¶
Delete a server admin with the given identity from the server.
identity (str): The identity of the admin to be deleted.
server (Server): The server from which the admin should be deleted.
AdminOut: The deleted admin.
Source code in sharkservers/servers/views/admin/admins.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
admins_groups
¶
Admins groups views.
admin_get_server_admins_groups(params: Params = Depends(), server: Server = Depends(get_valid_server)) -> Page_GroupOut_
async
¶
Retrieve the admins groups for a server.
params (Params): The parameters for the request.
server (Server): The server to retrieve the admins groups for.
Page_GroupOut_: The paginated list of admins groups.
Source code in sharkservers/servers/views/admin/admins_groups.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
admin_create_server_admins_groups(data: CreateGroupSchema, server: Server = Depends(get_valid_server)) -> GroupOut
async
¶
Create a new admin group for a server.
data (CreateGroupSchema): The data for creating the group.
server (Server): The server for which the group is being created.
GroupOut: The created admin group.
Source code in sharkservers/servers/views/admin/admins_groups.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
admin_get_server_admins_group(group_id: int, server: Server = Depends(get_valid_server)) -> GroupOut
async
¶
Retrieve the admins group of a server by its group ID.
group_id (int): The ID of the admins group.
server (Server): The server object.
GroupOut: The admins group information.
Source code in sharkservers/servers/views/admin/admins_groups.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
admin_delete_server_admins_group(group_id: int, server: Server = Depends(get_valid_server)) -> GroupOut
async
¶
Delete an admin group from the server.
group_id (int): The ID of the admin group to delete.
server (Server): The server object.
GroupOut: The deleted admin group.
Source code in sharkservers/servers/views/admin/admins_groups.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
servers
¶
Admin server views.
admin_get_servers(servers_service: ServerService = Depends(get_servers_service)) -> ServerOut
async
¶
Retrieve all servers with their associated admin role.
servers_service (ServerService): The server service instance.
ServerOut: The server data with the associated admin role.
Source code in sharkservers/servers/views/admin/servers.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
admin_create_server(server_data: CreateServerSchema, servers_service: ServerService = Depends(get_servers_service)) -> ServerOut
async
¶
Create a new server using the provided server data.
server_data (CreateServerSchema): The data for creating the server.
servers_service (ServerService): The server service instance.
ServerOut: The created server.
Source code in sharkservers/servers/views/admin/servers.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
admin_get_server(server: Server = Depends(get_valid_server)) -> ServerOut
async
¶
Retrieve the details of a server for admin purposes.
server (Server): The server object to retrieve details for.
ServerOut: The server details.
Source code in sharkservers/servers/views/admin/servers.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
admin_update_server(server_data: UpdateServerSchema, server: Server = Depends(get_valid_server)) -> ServerOut
async
¶
Update the server with the provided data.
server_data (UpdateServerSchema): The data to update the server with.
server (Server): The server to be updated.
ServerOut: The updated server.
Source code in sharkservers/servers/views/admin/servers.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
admin_delete_server(server: Server = Depends(get_valid_server), servers_service: ServerService = Depends(get_servers_service)) -> bool
async
¶
Delete the specified server.
server (Server): The server to be deleted.
servers_service (ServerService): The server service instance.
bool: True if the server is successfully deleted, False otherwise.
Source code in sharkservers/servers/views/admin/servers.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
servers
¶
Server views.
get_servers(params: Params = Depends(), ip: str | None = None, port: int | None = None, servers_service: ServerService = Depends(get_servers_service)) -> Page[ServerOut]
async
¶
Retrieve servers based on the provided parameters.
params (Params, optional): The query parameters for filtering and pagination. Defaults to Depends().
ip (str, optional): The IP address of the server to retrieve. Defaults to None.
port (int, optional): The port of the server to retrieve. Defaults to None.
servers_service (ServerService, optional): The server service dependency. Defaults to Depends(get_servers_service).
Page[ServerOut]: A paginated list of server objects.
Source code in sharkservers/servers/views/servers.py
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 | |
get_servers_status(servers_service: ServerService = Depends(get_servers_service)) -> list[ServerStatusSchema]
async
¶
Retrieve the status of servers.
servers_service (ServerService): The server service instance used to retrieve server status.
list[ServerStatusSchema]: A list of server status objects.
ConnectionRefusedError: If there is an error retrieving the server status.
Source code in sharkservers/servers/views/servers.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
get_server(server: Model = Depends(get_valid_server)) -> ServerOut
async
¶
Retrieve a server based on the provided server model.
server (Model): The server model to retrieve.
ServerOut: The retrieved server.
Source code in sharkservers/servers/views/servers.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
services
¶
Services module.
EmailService
¶
Email service class.
Source code in sharkservers/services.py
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 | |
__init__(resend, checker: DefaultChecker) -> None
¶
Initialize EmailService class.
Source code in sharkservers/services.py
29 30 31 32 33 34 35 | |
send_confirmation_email(activation_type: ActivationEmailTypeEnum, email: EmailStr, code: str) -> None
async
¶
Send a confirmation email.
activation_type (ActivationEmailTypeEnum): The type of the activation email.
email (EmailStr): The email address of the recipient.
code (str): The activation code.
None
Source code in sharkservers/services.py
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 | |
settings
¶
Settings module.
Settings
¶
Bases: BaseSettings
The Settings class represents the application's configuration settings.
Attributes¶
POSTGRES_HOST (str): The hostname of the PostgreSQL database server. POSTGRES_DB (str): The name of the PostgreSQL database. POSTGRES_USER (str): The username for connecting to the PostgreSQL database. POSTGRES_PASSWORD (str): The password for connecting to the PostgreSQL database. TESTING (bool): Flag indicating whether the application is running in testing mode. Default is False. SECRET_KEY (str): The secret key used for cryptographic operations. REFRESH_SECRET_KEY (str): The secret key used for refreshing access tokens. ALGORITHM (str): The algorithm used for token generation. Default is "HS256". ACCESS_TOKEN_EXPIRES (int): The expiration time (in minutes) for access tokens. Default is 5 minutes. REFRESH_TOKEN_EXPIRES (int): The expiration time (in minutes) for refresh tokens. Default is 43829 minutes. REDIS_HOST (str): The hostname of the Redis server. Default is "redis". REDIS_PORT (int): The port number of the Redis server. Default is 6379. STEAM_API_KEY (str): The API key for accessing the Steam API. DEBUG (bool): Flag indicating whether the application is running in debug mode. Default is False. MAIL_USERNAME (str): The username for the email server. MAIL_PASSWORD (str): The password for the email server. MAIL_FROM (str): The email address used as the "From" field in outgoing emails. MAIL_PORT (int): The port number of the email server. MAIL_SERVER (str): The hostname of the email server. MAIL_FROM_NAME (str): The name used as the "From" field in outgoing emails. MAIL_STARTTLS (bool): Flag indicating whether to use STARTTLS for secure email communication. Default is True. MAIL_SSL_TLS (bool): Flag indicating whether to use SSL/TLS for secure email communication. Default is False. USE_CREDENTIALS (bool): Flag indicating whether to use credentials for email communication. Default is True. VALIDATE_CERTS (bool): Flag indicating whether to validate SSL certificates for email communication. Default is True. IMAGE_ALLOWED_EXTENSIONS (list): List of allowed image file extensions. Default is [".png", ".jpg", ".jpeg"]. AVATAR_WIDTH (int): The width of user avatars. Default is 100. STRIPE_API_KEY (str): The API key for accessing the Stripe API. STRIPE_WEBHOOK_SECRET (str): The secret key for verifying Stripe webhook events. SITE_URL (str): The base URL of the site. Default is "http://localhost:8080".
Methods¶
get_database_url(): Returns the database URL based on the configuration settings. get_database_url_sync(): Returns the synchronous database URL based on the configuration settings. get_redis_url(): Returns the Redis URL based on the configuration settings.
Source code in sharkservers/settings.py
9 10 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 122 | |
Config
¶
The Config class represents the configuration settings for the Settings class.
Source code in sharkservers/settings.py
83 84 85 86 | |
get_database_url() -> str
¶
Return the database URL based on the configuration settings.
Returns¶
str: The database URL.
Source code in sharkservers/settings.py
88 89 90 91 92 93 94 95 96 97 98 | |
get_database_url_sync() -> str
¶
Return the synchronous database URL based on the configuration settings.
Returns¶
str: The synchronous database URL.
Source code in sharkservers/settings.py
100 101 102 103 104 105 106 107 108 109 110 | |
get_redis_url() -> str
¶
Return the Redis URL based on the configuration settings.
Returns¶
str: The Redis URL.
Source code in sharkservers/settings.py
112 113 114 115 116 117 118 119 120 121 122 | |
get_settings() -> Settings
cached
¶
Return an instance of the Settings class.
Returns¶
Settings: An instance of the Settings class.
Source code in sharkservers/settings.py
125 126 127 128 129 130 131 132 133 134 | |
subscryptions
¶
users
¶
sharkservers_api.
sharkservers-api
(C) 2023-present Adrian Ciołek (Qwizi)
dependencies
¶
Module contains dependency functions for user-related operations.
Dependencies are functions that are used to inject objects or services into other functions or endpoints.
These functions are used as parameters in FastAPI's Depends decorator.
Functions: - get_users_service: Returns an instance of the UserService class. - get_valid_user: Validates a user ID and returns the corresponding user model. - get_users_sessions_service: Returns an instance of the UserSessionService class. - get_valid_user_session: Validates a user session ID and returns the corresponding user session model.
get_users_service() -> UserService
async
¶
Return an instance of the UserService class.
Returns¶
UserService: An instance of the UserService class.
Source code in sharkservers/users/dependencies.py
23 24 25 26 27 28 29 30 31 | |
get_valid_user(user_id: int, users_service: UserService = Depends(get_users_service)) -> Model
async
¶
Retrieves a valid user by their ID.
user_id (int): The ID of the user.
users_service (UserService, optional): The user service dependency. Defaults to Depends(get_users_service).
Model: The user model.
user_not_found_exception: If the user is not found.
Source code in sharkservers/users/dependencies.py
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 | |
get_users_sessions_service() -> UserSessionService
async
¶
Get the UserSessionService instance.
Returns¶
UserSessionService: The UserSessionService instance.
Source code in sharkservers/users/dependencies.py
63 64 65 66 67 68 69 70 71 | |
get_valid_user_session(session_id: UUID, users_sessions_service: UserSessionService = Depends(get_users_sessions_service)) -> UserSession
async
¶
Retrieve a valid user session by session ID.
session_id (UUID): The ID of the session to retrieve.
users_sessions_service (UserSessionService, optional): The user sessions service. Defaults to the result of `get_users_sessions_service`.
UserSession: The retrieved user session.
user_not_found_exception: If the user session is not found.
Source code in sharkservers/users/dependencies.py
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 | |
enums
¶
Module contains the enum classes used in the Sharkservers API for users.
UsersExceptionsDetailEnum
¶
Represents the detail of the exceptions raised in the Sharkservers API for users.
Source code in sharkservers/users/enums.py
5 6 7 8 9 10 11 12 13 14 15 16 | |
UsersEventsEnum
¶
Represents the events raised in the Sharkservers API for users.
Source code in sharkservers/users/enums.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
UsersAdminEventsEnum
¶
Represents the events raised in the Sharkservers API for users.
Source code in sharkservers/users/enums.py
40 41 42 43 44 45 46 | |
exceptions
¶
This module contains custom exceptions related to user operations.
Exceptions:¶
- user_not_found_exception: Raised when a user is not found.
- username_not_available_exception: Raised when a username is not available.
- invalid_current_password_exception: Raised when the current password is invalid.
- cannot_change_display_role_exception: Raised when a user tries to change their display role.
- user_already_banned_exception: Raised when a user is already banned.
- user_not_banned_exception: Raised when a user is not banned.
- user_email_is_the_same_exception: Raised when a user tries to change their email to the same email.
models
¶
Module contains the models for users, user sessions, and bans in the SharkServers API.
The User model represents a user in the system and includes fields such as username, email, password, and various statistics like threads_count, posts_count, and likes_count. It also has relationships with roles, player, and sessions.
The UserSession model represents a session of a user and includes fields for user IP and user agent.
The Ban model represents a ban on a user and includes fields for the banned user, reason, ban time, and the user who issued the ban.
The module also includes a pre_update hook for the User model that updates the "updated_at" field whenever a user is updated.
UserSession
¶
Bases: Model, DateFieldsMixins
Represent a user session.
Attributes¶
id (str): The unique identifier for the user session.
user_ip (str): The IP address of the user.
user_agent (str): The user agent string of the client.
Source code in sharkservers/users/models.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
User
¶
Bases: Model, DateFieldsMixins
Represents a user in the system.
Attributes¶
id (int): The unique identifier of the user.
username (str, optional): The username of the user. Max length is 64 characters.
email (str, optional): The email address of the user. Max length is 255 characters.
password (str, optional): The password of the user. Max length is 255 characters.
is_activated (bool, optional): Indicates if the user is activated.
is_superuser (bool, optional): Indicates if the user is a superuser.
avatar (str, optional): The path to the user's avatar image.
roles (List[Role], optional): The roles assigned to the user.
display_role (Role, optional): The role to be displayed for the user.
last_login (datetime.datetime, optional): The timestamp of the user's last login.
last_online (datetime.datetime, optional): The timestamp of the user's last online activity.
secret_salt (str, optional): The secret salt used for password hashing. Max length is 255 characters.
threads_count (int): The number of threads created by the user.
posts_count (int): The number of posts created by the user.
likes_count (int): The number of likes received by the user.
player (Player, optional): The associated player for the user.
sessions (List[UserSession], optional): The sessions associated with the user.
Source code in sharkservers/users/models.py
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 | |
Ban
¶
Bases: Model, DateFieldsMixins
Represent a ban in the system.
Attributes¶
id (int): The unique identifier for the ban.
user (Optional[User]): The user who is banned.
reason (Optional[str]): The reason for the ban.
ban_time (Optional[datetime.datetime]): The time when the ban was imposed.
banned_by (Optional[User]): The user who imposed the ban.
Source code in sharkservers/users/models.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
update_user_updated_at(sender, instance: User, **kwargs) -> None
async
¶
Update the 'updated_at' field of a User instance with the current datetime.
sender: The sender of the signal.
instance: The User instance being updated.
kwargs: Additional keyword arguments.
Source code in sharkservers/users/models.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
schemas
¶
Module contains the schema definitions for the users in the SharkServers API.
It includes Pydantic models for various user-related operations such as creating a user, changing username, changing password, etc.
The module also defines query parameters for filtering and ordering user data.
UserSessionOut
¶
Bases: user_session_out
Represents the output schema for a user session.
Source code in sharkservers/users/schemas.py
37 38 | |
UserOut
¶
Bases: user_out
Represents the output schema for a user.
Source code in sharkservers/users/schemas.py
41 42 | |
UserOutWithEmail
¶
Bases: user_out_with_email
Represents the output schema for a user with email.
Source code in sharkservers/users/schemas.py
45 46 | |
ChangeUsernameSchema
¶
Bases: UsernameRegex
Schema for changing the username.
Attributes¶
new_username (str): The new username to be set.
Source code in sharkservers/users/schemas.py
49 50 51 52 53 54 55 56 57 58 | |
SuccessChangeUsernameSchema
¶
Bases: BaseModel
Schema for successful username change response.
Source code in sharkservers/users/schemas.py
61 62 63 64 65 | |
ChangePasswordSchema
¶
Bases: BaseModel
Schema for changing password.
Attributes¶
current_password (str): The current password.
new_password (str): The new password.
new_password2 (str): The confirmation of the new password.
Raises¶
ValueError: If the new_password2 does not match the new_password.
Source code in sharkservers/users/schemas.py
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 | |
passwords_match(value, values, **kwargs) -> None
¶
Validate that the new_password2 matches the new_password.
Source code in sharkservers/users/schemas.py
87 88 89 90 91 92 93 94 | |
ChangeEmailSchema
¶
Bases: BaseModel
Schema for changing email.
Attributes¶
email (str): The new email address.
Source code in sharkservers/users/schemas.py
97 98 99 100 101 102 103 104 105 106 | |
ChangeDisplayRoleSchema
¶
Bases: BaseModel
Schema for changing the display role of a user.
Source code in sharkservers/users/schemas.py
109 110 111 112 | |
SuccessChangeDisplayRoleSchema
¶
Bases: BaseModel
Schema for representing a successful change in display role.
Source code in sharkservers/users/schemas.py
115 116 117 118 119 | |
CreateUserSchema
¶
Bases: BaseModel
Schema for creating a user.
Source code in sharkservers/users/schemas.py
122 123 124 125 126 127 128 129 | |
CreateAdminUserSchema
¶
Bases: CreateUserSchema
Schema for creating an admin user.
Source code in sharkservers/users/schemas.py
132 133 134 135 | |
BanUserSchema
¶
Bases: BaseModel
Schema for banning a user.
Source code in sharkservers/users/schemas.py
138 139 140 141 142 | |
AdminUpdateUserSchema
¶
Bases: BaseModel
Schema for updating a user.
Source code in sharkservers/users/schemas.py
145 146 147 148 149 150 151 152 153 154 155 156 | |
UserQuery
¶
Bases: OrderQuery
Query parameters for filtering and ordering users.
Source code in sharkservers/users/schemas.py
159 160 161 162 | |
services
¶
Module contains the services for managing user-related operations.
It includes the following classes: - UserService: Provides methods for managing user data, such as changing username, password, and display role. - UserSessionService: Provides methods for managing user session data.
UserService
¶
Bases: BaseService
Service class for managing user-related operations.
Source code in sharkservers/users/services.py
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 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 | |
Meta
¶
Meta class for defining metadata options for the User model.
Source code in sharkservers/users/services.py
47 48 49 50 51 | |
get_last_online_users(params: Params) -> Page[UserOut]
async
¶
Get the last online users.
params (Params): Pagination parameters.
Page[UserOut]: A paginated list of UserOut objects.
Source code in sharkservers/users/services.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
change_username(user: User, change_username_data: ChangeUsernameSchema) -> User
async
staticmethod
¶
Change the username of a user.
user (User): The user object.
change_username_data (ChangeUsernameSchema): The new username.
User: The updated user object.
username_not_available_exception: If the new username is not available.
Source code in sharkservers/users/services.py
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 | |
change_password(user: User, change_password_data: ChangePasswordSchema) -> User
async
staticmethod
¶
Change the password of a user.
user (User): The user object.
change_password_data (ChangePasswordSchema): The new password.
User: The updated user object.
invalid_current_password_exception: If the current password is invalid.
Source code in sharkservers/users/services.py
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 | |
change_display_role(user: User, change_display_role_data: ChangeDisplayRoleSchema) -> (User, int)
async
staticmethod
¶
Change the display role of a user.
user (User): The user object.
change_display_role_data (ChangeDisplayRoleSchema): The new display role.
Tuple[User, int]: The updated user object and the old display role ID.
cannot_change_display_role_exception: If the new display role is not available.
Source code in sharkservers/users/services.py
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 | |
create_confirm_email_code(code_service: CodeService, user: User, new_email: EmailStr) -> (str, EmailStr)
async
staticmethod
¶
Create a confirmation code for changing the user's email.
code_service (CodeService): The code service object.
user (User): The user object.
new_email (EmailStr): The new email address.
Tuple[str, EmailStr]: The confirmation code and the new email address.
user_email_is_the_same_exception: If the new email is the same as the current email.
Source code in sharkservers/users/services.py
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 | |
confirm_change_email(code_service: CodeService, code: str) -> User
async
¶
Confirm the change of the user's email.
code_service (CodeService): The code service object.
code (str): The confirmation code.
User: The updated user object.
invalid_activation_code_exception: If the activation code is invalid.
Source code in sharkservers/users/services.py
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 | |
upload_avatar(user: User, avatar: UploadFile, request: Request, upload_service: UploadService, settings: Settings) -> dict
async
¶
Upload and update the user's avatar.
user (User): The user object.
avatar (UploadFile): The avatar file to upload.
request (Request): The request object.
upload_service (UploadService): The upload service object.
settings (Settings): The application settings.
dict: A dictionary containing the old and new avatar URLs.
HTTPException: If there is an error during the avatar upload.
Source code in sharkservers/users/services.py
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 | |
sync_counters(threads_service: ThreadService, posts_service: PostService) -> None
async
¶
Synchronize the thread and post counters for all users.
threads_service (ThreadService): The thread service object.
posts_service (PostService): The post service object.
Source code in sharkservers/users/services.py
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 | |
UserSessionService
¶
Bases: BaseService
Service class for managing user session-related operations.
Source code in sharkservers/users/services.py
318 319 320 321 322 323 324 325 | |
Meta
¶
Meta class for defining metadata options for the UserSession model.
Source code in sharkservers/users/services.py
321 322 323 324 325 | |
views
¶
sharkservers_api.
sharkservers-api
(C) 2023-present Adrian Ciołek (Qwizi)
admin
¶
Module contains the API endpoints related to admin users.
Functions: - admin_get_users: Retrieves a paginated list of users. - admin_get_user: Retrieves a specific user. - admin_create_user: Creates a user. - admin_delete_user: Deletes a user. - admin_update_user: Updates a user.
admin_get_users(params: Params = Depends(), users_service: UserService = Depends(get_users_service)) -> Page[UserOutWithEmail]
async
¶
Retrieve all users with their associated data.
params (Params, optional): The parameters for filtering and pagination. Defaults to Depends().
users_service (UserService, optional): The service for retrieving user data. Defaults to Depends(get_users_service).
Page[UserOutWithEmail]: The paginated list of users with their associated data.
Source code in sharkservers/users/views/admin.py
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 | |
admin_get_user(user: User = Depends(get_valid_user)) -> UserOutWithEmail
async
¶
Retrieve the user information for an admin user.
user (User): The admin user object.
UserOutWithEmail: The user information with email.
Source code in sharkservers/users/views/admin.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
admin_create_user(user_data: CreateUserSchema, auth_service: AuthService = Depends(get_auth_service), settings: Settings = Depends(get_settings)) -> UserOutWithEmail
async
¶
Create a new user with the provi print(roles) ded user data.
user_data (CreateUserSchema): The data for creating a new user.
auth_service (AuthService, optional): The authentication service. Defaults to Depends(get_auth_service).
settings (Settings, optional): The application settings. Defaults to Depends(get_settings).
UserOutWithEmail: The created user with email.
Source code in sharkservers/users/views/admin.py
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 | |
admin_delete_user(validate_user: User = Depends(get_valid_user), users_service: UserService = Depends(get_users_service)) -> UserOutWithEmail
async
¶
Deletes a user from the system.
validate_user (User): The user to be deleted.
users_service (UserService): The service responsible for user operations.
UserOutWithEmail: The deleted user with email.
Source code in sharkservers/users/views/admin.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
admin_update_user(update_user_data: AdminUpdateUserSchema, validate_user: User = Depends(get_valid_user), roles_service: RoleService = Depends(get_roles_service)) -> UserOutWithEmail
async
¶
Admin function to update a user's information.
update_user_data (AdminUpdateUserSchema): The updated user data.
validate_user (User): The user to be updated.
roles_service (RoleService): The service for managing roles.
UserOutWithEmail: The updated user with email.
Source code in sharkservers/users/views/admin.py
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 | |
me
¶
Module contains the API endpoints related to the currently logged-in user.
Functions: - get_logged_user: Retrieves the currently logged-in user. - get_logged_user_posts: Retrieves all posts created by the logged-in user. - get_logged_user_threads: Retrieves all threads created by the logged-in user. - change_user_username: Changes the username of the current user. - change_user_password: Changes the password of the current user. - request_change_user_email: Requests a change of user email. - confirm_change_user_email: Confirms the change of user email. - change_user_display_role: Changes the display role of the current user. - upload_user_avatar: Uploads the user's avatar. - connect_steam_profile: Connects a Steam profile to the user's account. - get_user_sessions: Retrieves the sessions of the current user. - delete_user_session: Deletes the user session.
get_logged_user(user: User = Security(get_current_active_user, scopes=['users:me'])) -> UserOutWithEmail
async
¶
Retrieve the currently logged-in user.
user (User): The currently logged-in user.
UserOutWithEmail: The logged-in user with email.
Source code in sharkservers/users/views/me.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
get_logged_user_posts(params: Params = Depends(), queries: OrderQuery = Depends(), user: User = Security(get_current_active_user, scopes=['users:me']), posts_service: PostService = Depends(get_posts_service)) -> Page[PostOut]
async
¶
Retrieves all posts created by the logged-in user.
params (Params, optional): The parameters for pagination and filtering. Defaults to Depends().
queries (OrderQuery, optional): The query parameters for ordering the posts. Defaults to Depends().
user (User, optional): The logged-in user. Defaults to Security(get_current_active_user, scopes=["users:me"]).
posts_service (PostService, optional): The service for retrieving posts. Defaults to Depends(get_posts_service).
List[Post]: The list of posts created by the logged-in user.
Source code in sharkservers/users/views/me.py
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 | |
get_logged_user_threads(params: Params = Depends(), queries: OrderQuery = Depends(), user: User = Security(get_current_active_user, scopes=['users:me']), threads_service: ThreadService = Depends(get_threads_service)) -> Page[ThreadOut]
async
¶
Retrieve all threads for the logged-in user.
params (Params): The parameters for filtering and pagination.
queries (OrderQuery): The query parameters for ordering.
user (User): The logged-in user.
threads_service (ThreadService): The service for handling threads.
List[Thread]: The list of threads for the logged-in user.
Source code in sharkservers/users/views/me.py
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 | |
change_user_username(change_username_data: ChangeUsernameSchema, user: User = Security(get_current_active_user, scopes=['users:me:username']), users_service: UserService = Depends(get_users_service)) -> SuccessChangeUsernameSchema
async
¶
Change the username of the current user.
change_username_data (ChangeUsernameSchema): The data containing the new username.
user (User): The current authenticated user.
users_service (UserService): The service responsible for handling user-related operations.
SuccessChangeUsernameSchema: The response containing the old and new usernames.
Source code in sharkservers/users/views/me.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 | |
change_user_password(change_password_data: ChangePasswordSchema, user: User = Security(get_current_active_user, scopes=['users:me:password']), users_service: UserService = Depends(get_users_service)) -> dict
async
¶
Change the password of the current user.
change_password_data (ChangePasswordSchema): The new password data.
user (User): The current user.
users_service (UserService): The service for managing users.
dict: A dictionary with a success message.
Source code in sharkservers/users/views/me.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
request_change_user_email(change_email_data: ChangeEmailSchema, background_tasks: BackgroundTasks, user: User = Security(get_current_active_user, scopes=['users:me']), email_service: EmailService = Depends(get_email_service), code_service: CodeService = Depends(get_change_account_email_code_service), users_service: UserService = Depends(get_users_service)) -> dict[str, str]
async
¶
Request a change of user email.
change_email_data (ChangeEmailSchema): The data for the email change request.
background_tasks (BackgroundTasks): The background tasks manager.
user (User): The current authenticated user.
email_service (EmailService): The email service.
code_service (CodeService): The code service for email confirmation codes.
users_service (UserService): The user service.
dict: A dictionary with a success message indicating that the request for email change was sent.
Source code in sharkservers/users/views/me.py
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 | |
confirm_change_user_email(activate_code_data: ActivateUserCodeSchema, code_service: CodeService = Depends(get_change_account_email_code_service), users_service: UserService = Depends(get_users_service)) -> UserOutWithEmail
async
¶
Confirm the change of user's email address using the activation code.
activate_code_data (ActivateUserCodeSchema): The activation code data.
code_service (CodeService, optional): The code service dependency. Defaults to Depends(get_change_account_email_code_service).
users_service (UserService, optional): The users service dependency. Defaults to Depends(get_users_service).
UserOutWithEmail: The updated user with the new email address.
Source code in sharkservers/users/views/me.py
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 | |
change_user_display_role(change_display_role_data: ChangeDisplayRoleSchema, user: User = Security(get_current_active_user, scopes=['users:me:display-role']), users_service: UserService = Depends(get_users_service)) -> UserOutWithEmail
async
¶
Change the display role of the current user.
change_display_role_data (ChangeDisplayRoleSchema): The data for changing the display role.
user (User): The current user.
users_service (UserService): The service for managing users.
UserOutWithEmail: The updated user object.
Source code in sharkservers/users/views/me.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
upload_user_avatar(request: Request, avatar: UploadFile = File(...), user: User = Security(get_current_active_user, scopes=['users:me']), users_service: UserService = Depends(get_users_service), upload_service: UploadService = Depends(get_upload_service), settings: Settings = Depends(get_settings)) -> dict[str, str]
async
¶
Upload the user's avatar. sharkservers.
Returns¶
dict: A dictionary with a success message.
Source code in sharkservers/users/views/me.py
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 | |
connect_steam_profile(params: SteamAuthSchema, user: User = Security(get_current_active_user, scopes=['users:me']), steam_auth_service: SteamAuthService = Depends(get_steam_auth_service)) -> None
async
¶
Connect a Steam profile to the user's account.
params (SteamAuthSchema): The parameters for Steam authentication.
user (User, optional): The authenticated user. Defaults to the current active user.
steam_auth_service (SteamAuthService, optional): The Steam authentication service. Defaults to the injected service.
None: Nothing.
Source code in sharkservers/users/views/me.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
get_user_sessions(user: User = Security(get_current_active_user, scopes=['users:me'])) -> list[UserSessionOut]
async
¶
Retrieve the sessions of the current user.
user (User): The current user.
list[UserSessionOut]: A list of user sessions.
Source code in sharkservers/users/views/me.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
delete_user_session(user_session: UserSession = Depends(get_valid_user_session)) -> UserSessionOut
async
¶
Delete the user session.
user_session (UserSession): The user session to be deleted.
UserSession: The deleted user session.
Source code in sharkservers/users/views/me.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | |
users
¶
Module contains the API endpoints related to users.
Endpoints: - GET /users: Retrieves a paginated list of users based on the provided parameters. - GET /users/staff: Retrieves a paginated list of staff users. - GET /users/online: Retrieves a paginated list of users who were last online. - GET /users/{user_id}: Retrieves a specific user based on the provided user ID. - GET /users/{user_id}/posts: Retrieves a paginated list of posts made by a specific user. - GET /users/{user_id}/threads: Retrieves a paginated list of threads created by a specific user.
get_users(params: Params = Depends(), queries: UserQuery = Depends(), users_service: UserService = Depends(get_users_service)) -> Page[UserOut]
async
¶
Retrieve a list of users based on the provided parameters and queries.
params (Params, optional): The parameters for pagination and filtering. Defaults to Depends().
queries (UserQuery, optional): The queries for filtering and ordering. Defaults to Depends().
users_service (UserService, optional): The service for retrieving user data. Defaults to Depends(get_users_service).
Page[UserOut]: The paginated list of users.
Source code in sharkservers/users/views/users.py
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 | |
get_staff_users(params: Params = Depends(), roles_service: RoleService = Depends(get_roles_service)) -> Page[StaffRolesSchema]
async
¶
Retrieve staff users based on the provided parameters.
params (Params): The parameters for filtering and pagination.
roles_service (RoleService): The service for retrieving staff roles.
Page[StaffRolesSchema]: A paginated list of staff roles.
Source code in sharkservers/users/views/users.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
get_last_online_users(params: Params = Depends(), users_service: UserService = Depends(get_users_service)) -> Page[UserOut]
async
¶
Retrieve the last online users based on the provided parameters.
params (Params): The parameters for filtering the users.
users_service (UserService): The service for retrieving user data.
Page[UserOut]: A paginated list of UserOut objects representing the last online users.
Source code in sharkservers/users/views/users.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
get_user(user: User = Depends(get_valid_user)) -> UserOut
async
¶
Retrieve the authenticated user.
user (User): The authenticated user.
UserOut: The user object with restricted information.
Source code in sharkservers/users/views/users.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
get_user_posts(params: Params = Depends(), queries: OrderQuery = Depends(), user: User = Depends(get_valid_user), posts_service: PostService = Depends(get_posts_service)) -> Page[PostOut]
async
¶
Retrieve all posts authored by a specific user.
params (Params, optional): The parameters for pagination and filtering. Defaults to Depends().
queries (OrderQuery, optional): The query parameters for ordering. Defaults to Depends().
user (User, optional): The authenticated user. Defaults to Depends(get_valid_user).
posts_service (PostService, optional): The service for retrieving posts. Defaults to Depends(get_posts_service).
Page[PostOut]: A paginated list of PostOut objects.
Source code in sharkservers/users/views/users.py
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 | |
get_user_threads(params: Params = Depends(), queries: OrderQuery = Depends(), user: User = Depends(get_valid_user), threads_service: ThreadService = Depends(get_threads_service)) -> Page[ThreadOut]
async
¶
Retrieves all threads belonging to a specific user.
params (Params): The parameters for pagination and filtering.
queries (OrderQuery): The query parameters for ordering.
user (User): The authenticated user.
threads_service (ThreadService): The service for managing threads.
Page[ThreadOut]: A paginated list of threads belonging to the user.
Source code in sharkservers/users/views/users.py
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 | |
utils
¶
Utility functions and context managers used in the Sharkservers API.
Functions: - custom_generate_unique_id: Generates a unique ID based on the route's tags and name. - init_limiter: Initializes the rate limiter for the FastAPI application. - close_limiter: Closes the rate limiter for the FastAPI application.
- connect_db: Connects to the database and initializes the Redis connection and rate limiter.¶
- disconnect_db: Disconnects from the database and closes the Redis connection.
- connect_broadcast: Connects to the broadcast service.
- disconnect_broadcast: Disconnects from the broadcast service.
Context Managers: - app_lifespan: Manages the lifespan of the FastAPI application.
custom_generate_unique_id(route: APIRouter) -> str
¶
Generate a unique ID based on the route's tags and name.
Args:¶
route (APIRouter): The route for which to generate the unique ID.
str: The generated unique ID.
Source code in sharkservers/utils.py
33 34 35 36 37 38 39 40 41 42 43 44 45 | |
init_limiter(_app: FastAPI) -> FastAPI
async
¶
Initialize the rate limiter for the FastAPI application.
_app (FastAPI): The FastAPI application.
FastAPI: The updated FastAPI application.
Source code in sharkservers/utils.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
close_limiter(_app: FastAPI) -> FastAPI
async
¶
Close the rate limiter for the FastAPI application.
_app (FastAPI): The FastAPI application.
FastAPI: The updated FastAPI application.
Source code in sharkservers/utils.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
connect_db(_app: FastAPI) -> FastAPI
async
¶
Connect to the database and initializes the Redis connection and rate limiter.
_app (FastAPI): The FastAPI application.
FastAPI: The updated FastAPI application.
Source code in sharkservers/utils.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
disconnect_db(_app: FastAPI) -> None
async
¶
Disconnect from the database and closes the Redis connection.
_app (FastAPI): The FastAPI application.
Source code in sharkservers/utils.py
101 102 103 104 105 106 107 108 109 110 111 112 | |
connect_broadcast(_app: FastAPI) -> FastAPI
async
¶
Connect to the broadcast service.
_app (FastAPI): The FastAPI application.
FastAPI: The updated FastAPI application.
Source code in sharkservers/utils.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
disconnect_broadcast(_app: FastAPI) -> None
async
¶
Disconnect from the broadcast service.
_app (FastAPI): The FastAPI application.
Source code in sharkservers/utils.py
132 133 134 135 136 137 138 139 140 141 | |
app_lifespan(_app: FastAPI) -> AsyncIterator[None]
async
¶
Manage the lifespan of the FastAPI application.
_app (FastAPI): The FastAPI application.
None
Source code in sharkservers/utils.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
views
¶
Module containing the API routes for the SharkServers application.
Includes routes for installation, generating OpenAPI documentation, and generating random data.
Routes: - /install: POST route for installing the application. - /generate-openapi: GET route for generating the OpenAPI documentation. - /generate-random-data: GET route for generating random data for testing purposes.
install(user_data: RegisterUserSchema, scopes_service: ScopeService = Depends(get_scopes_service), roles_service: RoleService = Depends(get_roles_service), auth_service: AuthService = Depends(get_auth_service), settings: Settings = Depends(get_settings)) -> dict
async
¶
Endpoint for installing the SharkServers application.
Args:¶
- user_data: User data for the admin user.
- scopes_service: Service for managing scopes.
- roles_service: Service for managing roles.
- auth_service: Service for authentication.
- settings: Application settings.
Returns:¶
- A dictionary with a "msg" key indicating the success of the installation.
Source code in sharkservers/views.py
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 | |
generate_openapi() -> dict[str, str]
async
¶
Endpoint for generating the OpenAPI documentation.
Returns¶
- A dictionary with a "msg" key indicating the success of the generation.
Source code in sharkservers/views.py
73 74 75 76 77 78 79 80 81 82 83 | |
generate_random_data(auth_service: AuthService = Depends(get_auth_service), roles_service: RoleService = Depends(get_roles_service), categories_service: CategoryService = Depends(get_categories_service), threads_service: ThreadService = Depends(get_threads_service), posts_service: PostService = Depends(get_posts_service), servers_service: ServerService = Depends(get_servers_service)) -> dict[str, str]
async
¶
Endpoint for generating random data for testing purposes.
Args:¶
- auth_service: Service for authentication.
- roles_service: Service for managing roles.
- categories_service: Service for managing categories.
- threads_service: Service for managing threads.
- posts_service: Service for managing posts.
- servers_service: Service for managing servers.
Returns:¶
- A dictionary with a "msg" key indicating the success of the generation.
Source code in sharkservers/views.py
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 | |