Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions app/core/checkout/endpoints_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ async def webhook(
):
# We may receive the webhook multiple times, we only want to save a CheckoutPayment
# in the database the first time
existing_checkout_payment_model = await cruds_checkout.get_checkout_payment_by_hello_asso_payment_id(
hello_asso_payment_id=content.data.id, # ty:ignore[unresolved-attribute]
db=db,
existing_checkout_payment_model = (
await cruds_checkout.get_checkout_payment_by_hello_asso_payment_id(
hello_asso_payment_id=content.data.id, # ty:ignore[unresolved-attribute]
db=db,
)
)
if existing_checkout_payment_model is not None:
hyperion_error_logger.debug(
Expand Down
2 changes: 1 addition & 1 deletion app/core/checkout/payment_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ async def init_checkout(
self._helloasso_slug,
init_checkout_body,
)
except (UnauthorizedException, BadRequestException):
except UnauthorizedException, BadRequestException:
# We know that HelloAsso may refuse some payer infos, like using the firstname "test"
# Even when prefilling the payer infos,the user will be able to edit them on the payment page,
# so we can safely retry without the payer infos
Expand Down
4 changes: 2 additions & 2 deletions app/core/feed/types_feed.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from enum import StrEnum


class NewsStatus(str, Enum):
class NewsStatus(StrEnum):
WAITING_APPROVAL = "waiting_approval"
REJECTED = "rejected"
PUBLISHED = "published"
3 changes: 2 additions & 1 deletion app/core/google_api/google_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from types import TracebackType
from typing import Self

from fastapi import HTTPException, Request
from google.auth.transport import requests
Expand Down Expand Up @@ -217,7 +218,7 @@ def __init__(self, db: AsyncSession, settings: Settings):
self._db = db
self._settings = settings

async def __aenter__(self) -> "DriveGoogleAPI":
async def __aenter__(self) -> Self:
google_api = GoogleAPI()
creds = await google_api.get_credentials(self._db, self._settings)
self._drive: Resource = build("drive", "v3", credentials=creds)
Expand Down
6 changes: 1 addition & 5 deletions app/core/permissions/endpoints_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
is_user,
is_user_super_admin,
)
from app.module import full_name_permissions_list, permissions_list
from app.types.module import CoreModule
from app.utils.tools import is_group_id_valid

Expand Down Expand Up @@ -45,7 +46,6 @@ async def read_permissions_list(
"""
Return all permissions from database
"""
from app.module import full_name_permissions_list

return full_name_permissions_list

Expand All @@ -62,7 +62,6 @@ async def read_permissions(
"""
Return all permissions from database
"""
from app.module import permissions_list

return await cruds_permissions.get_permissions(permissions_list, db)

Expand All @@ -80,7 +79,6 @@ async def read_permission(
"""
Return permission with name from database
"""
from app.module import permissions_list

if permission_name not in permissions_list:
raise HTTPException(
Expand Down Expand Up @@ -111,7 +109,6 @@ async def create_permission(
"""
Create a new permission in database
"""
from app.module import permissions_list

if permission.permission_name not in permissions_list:
raise HTTPException(
Expand Down Expand Up @@ -143,7 +140,6 @@ async def delete_permission(
"""
Delete a permission from database by name
"""
from app.module import permissions_list

if permission.permission_name not in permissions_list:
raise HTTPException(
Expand Down
4 changes: 2 additions & 2 deletions app/core/permissions/type_permissions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum
from enum import StrEnum


class ModulePermissions(str, Enum):
class ModulePermissions(StrEnum):
pass
4 changes: 2 additions & 2 deletions app/core/tickets/types_tickets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from enum import StrEnum


class AnswerType(str, Enum):
class AnswerType(StrEnum):
TEXT = "text"
NUMBER = "number"
BOOLEAN = "boolean"
36 changes: 16 additions & 20 deletions app/core/users/factory_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,22 @@ class CoreUsersFactory(Factory):

@classmethod
def init_demo_users(cls, settings: Settings) -> None:
cls.demo_users = (
settings.FACTORIES_DEMO_USERS
if settings.FACTORIES_DEMO_USERS
else [
UserDemoFactoryConfig(
firstname="Alice",
name="Dupont",
nickname="alice",
email="demo1@test.fr",
password=Faker().password(16, True, True, True, True),
),
UserDemoFactoryConfig(
firstname="Bob",
name="Martin",
nickname="bob",
email="demo2@test.fr",
password=Faker().password(16, True, True, True, True),
),
]
)
cls.demo_users = settings.FACTORIES_DEMO_USERS or [
UserDemoFactoryConfig(
firstname="Alice",
name="Dupont",
nickname="alice",
email="demo1@test.fr",
password=Faker().password(16, True, True, True, True),
),
UserDemoFactoryConfig(
firstname="Bob",
name="Martin",
nickname="bob",
email="demo2@test.fr",
password=Faker().password(16, True, True, True, True),
),
]
cls.demo_users_id = [str(uuid.uuid4()) for _ in cls.demo_users]

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion app/core/utils/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import pathlib
import tomllib
from functools import cached_property
from re import Pattern
from typing import Any, ClassVar

import jwt
import tomllib
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives.serialization import load_pem_private_key
from pydantic import BaseModel, computed_field, model_validator
Expand Down
4 changes: 2 additions & 2 deletions app/core/utils/log.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import logging.config
import queue
from enum import Enum
from enum import StrEnum
from logging.handlers import QueueHandler, QueueListener
from pathlib import Path
from typing import Any
Expand All @@ -12,7 +12,7 @@


class ColoredConsoleFormatter(uvicorn.logging.DefaultFormatter):
class ConsoleColors(str, Enum):
class ConsoleColors(StrEnum):
"""Colors can be found here: https://talyian.github.io/ansicolors/"""

DEBUG = "\033[38;5;12m"
Expand Down
7 changes: 3 additions & 4 deletions app/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
core_module_list: list[CoreModule] = []
all_modules: list[CoreModule] = []

permissions_list: list[str] = []
full_name_permissions_list: list[str] = []

for endpoints_file in Path().glob("app/modules/*/endpoints_*.py"):
endpoint_module = importlib.import_module(
".".join(endpoints_file.with_suffix("").parts),
Expand Down Expand Up @@ -39,10 +42,6 @@
)


permissions_list: list[str] = []
full_name_permissions_list: list[str] = []


class DuplicatePermissionsError(Exception):
def __init__(self, permissions: list[list[str]]):
arranged_permissions = [
Expand Down
6 changes: 3 additions & 3 deletions app/modules/amap/types_amap.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from enum import Enum
from enum import StrEnum


class AmapSlotType(str, Enum):
class AmapSlotType(StrEnum):
midi = "midi"
soir = "soir"

def __str__(self) -> str:
return f"{self.name}<{self.value}"


class DeliveryStatusType(str, Enum):
class DeliveryStatusType(StrEnum):
creation = "creation" # Can edit date, add and remove products, no order possible
orderable = "orderable" # Ordering is possible, no edition possible
locked = "locked" # Can't order
Expand Down
4 changes: 2 additions & 2 deletions app/modules/booking/endpoints_booking.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging
import uuid
from datetime import UTC, datetime
from zoneinfo import ZoneInfo

from fastapi import Depends, HTTPException
from sqlalchemy.ext.asyncio import AsyncSession
from zoneinfo import ZoneInfo

from app.core.groups import cruds_groups
from app.core.groups.groups_type import AccountType
Expand Down Expand Up @@ -302,7 +302,7 @@ async def create_booking(
group = await cruds_groups.get_group_by_id(group_id=manager.group_id, db=db)

local_start = result.start.astimezone(ZoneInfo("Europe/Paris"))
applicant_nickname = user.nickname if user.nickname else user.firstname
applicant_nickname = user.nickname or user.firstname
content = f"{applicant_nickname} - {result.room.name} {local_start.strftime('%m/%d/%Y, %H:%M')} - {result.reason}"
# Setting time to Paris timezone in order to have the correct time in the notification

Expand Down
4 changes: 2 additions & 2 deletions app/modules/booking/types_booking.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from enum import StrEnum


class Decision(str, Enum):
class Decision(StrEnum):
approved = "approved"
declined = "declined"
pending = "pending"
Expand Down
8 changes: 2 additions & 6 deletions app/modules/calendar/endpoints_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,7 @@ async def add_event(

if decision == Decision.approved:
feed_module = "tickets" if event.ticket_event_id else utils_calendar.root
feed_module_object_id = (
event.ticket_event_id if event.ticket_event_id else event_id
)
feed_module_object_id = event.ticket_event_id or event_id

await utils_calendar.add_event_to_feed(
event=created_event,
Expand Down Expand Up @@ -524,9 +522,7 @@ async def confirm_event(

if decision == Decision.approved:
feed_module = "tickets" if event.ticket_event_id else utils_calendar.root
feed_module_object_id = (
event.ticket_event_id if event.ticket_event_id else event.id
)
feed_module_object_id = event.ticket_event_id or event.id

await utils_calendar.add_event_to_feed(
event=event,
Expand Down
4 changes: 2 additions & 2 deletions app/modules/calendar/types_calendar.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from enum import StrEnum


class Decision(str, Enum):
class Decision(StrEnum):
approved = "approved"
declined = "declined"
pending = "pending"
Expand Down
6 changes: 3 additions & 3 deletions app/modules/campaign/types_campaign.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from enum import StrEnum


class ListType(str, Enum):
class ListType(StrEnum):
"""
A list can be "Serios" or "Pipo". There will also be one "Blank" list by section that will be automatically added when the vote is open.
"""
Expand All @@ -11,7 +11,7 @@ class ListType(str, Enum):
blank = "Blank"


class StatusType(str, Enum):
class StatusType(StrEnum):
"""
Status of the voting
"""
Expand Down
10 changes: 5 additions & 5 deletions app/modules/cdr/types_cdr.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
from enum import Enum
from enum import StrEnum


class DocumentSignatureType(str, Enum):
class DocumentSignatureType(StrEnum):
material = "material"
numeric = "numeric"


class PaymentType(str, Enum):
class PaymentType(StrEnum):
cash = "cash"
check = "check"
helloasso = "HelloAsso"
card = "card"
archived = "archived"


class CdrStatus(str, Enum):
class CdrStatus(StrEnum):
pending = "pending"
online = "online"
onsite = "onsite"
closed = "closed"


class CdrLogActionType(str, Enum):
class CdrLogActionType(StrEnum):
purchase_add = "purchase_add"
purchase_delete = "purchase_delete"
payment_add = "payment_add"
Expand Down
4 changes: 2 additions & 2 deletions app/modules/raffle/types_raffle.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from enum import StrEnum


class RaffleStatusType(str, Enum):
class RaffleStatusType(StrEnum):
creation = "creation" # Can edit every parameter
open = "open" # Ordering is possible, no edition possible
lock = "lock" # Can't order
8 changes: 5 additions & 3 deletions app/modules/raid/cruds_raid.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,11 @@ async def get_number_of_team_by_difficulty(
team_numbers = [
team.number if team.number is not None and team.number >= 0 else 0
for team in filter(
lambda team: team.validation_progress == 100
and team.number is not None
and team.number >= 0,
lambda team: (
team.validation_progress == 100
and team.number is not None
and team.number >= 0
),
teams_found,
)
]
Expand Down
Loading
Loading