Skip to content

Commit

Permalink
Fix: migration and user declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
Rotheem committed Nov 19, 2024
1 parent 06f01a1 commit 2d30254
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 33 deletions.
2 changes: 1 addition & 1 deletion app/core/groups/groups_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_ecl_account_types() -> list[AccountType]:
]


def get_account_types_except_external() -> list[AccountType]:
def get_account_types_except_externals() -> list[AccountType]:
return [
AccountType.student,
AccountType.former_student,
Expand Down
1 change: 1 addition & 0 deletions app/modules/cdr/endpoints_cdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2484,6 +2484,7 @@ async def get_payment_url(
)
user_schema = schemas_core.CoreUser(
account_type=user.account_type,
school_id=user.school_id,
email=user.email,
birthday=user.birthday,
promo=user.promo,
Expand Down
4 changes: 3 additions & 1 deletion app/modules/raid/endpoints_raid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,13 +1087,15 @@ async def get_payment_url(
if not participant.payment:
checkout_name += " + "
checkout_name += "T Shirt taille" + participant.t_shirt_size.value
user_dict = user.__dict__
user_dict.pop("school", None)
checkout = await payment_tool.init_checkout(
module=module.root,
helloasso_slug="AEECL",
checkout_amount=price,
checkout_name=checkout_name,
redirection_uri=settings.RAID_PAYMENT_REDIRECTION_URL or "",
payer_user=schemas_core.CoreUser(**user.__dict__),
payer_user=schemas_core.CoreUser(**user_dict),
db=db,
)
hyperion_error_logger.info(f"RAID: Logging Checkout id {checkout.id}")
Expand Down
4 changes: 2 additions & 2 deletions app/utils/auth/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from app.core.groups.groups_type import (
AccountType,
GroupType,
get_account_types_except_external,
get_account_types_except_externals,
get_ecl_account_types,
)
from app.types.floors_type import FloorsType
Expand Down Expand Up @@ -39,7 +39,7 @@ class BaseAuthClient:
# Restrict the authentication to this client to specific Hyperion account types.
# When set to `None`, users from any account type can use the auth client
allowed_account_types: list[AccountType] | None = (
get_account_types_except_external()
get_account_types_except_externals()
)
# redirect_uri should alway match the one provided by the client
redirect_uri: list[str]
Expand Down
49 changes: 23 additions & 26 deletions migrations/versions/27-schools.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,19 @@ def upgrade() -> None:
sa.Enum(AccountType, name="accounttype").drop(
conn,
)
sa.Enum(AccountType2, name="accounttype").create(
conn,

op.create_table(
"module_account_type_visibility",
sa.Column("root", sa.String(), nullable=False),
sa.Column(
"allowed_account_type",
sa.Enum(
AccountType2,
name="accounttype",
),
nullable=False,
),
sa.PrimaryKeyConstraint("root", "allowed_account_type"),
)

with op.batch_alter_table("core_user") as batch_op:
Expand All @@ -140,17 +151,6 @@ def upgrade() -> None:
),
)

op.create_table(
"module_account_type_visibility",
sa.Column("root", sa.String(), nullable=False),
sa.Column(
"allowed_account_type",
sa.Enum(AccountType2, name="accounttype"),
nullable=False,
),
sa.PrimaryKeyConstraint("root", "allowed_account_type"),
)

with op.batch_alter_table("core_user_unconfirmed") as batch_op:
batch_op.add_column(
sa.Column(
Expand Down Expand Up @@ -227,19 +227,6 @@ def downgrade() -> None:
sa.Enum(AccountType2, name="accounttype").drop(
op.get_bind(),
)
sa.Enum(AccountType, name="accounttype").create(
op.get_bind(),
)

with op.batch_alter_table("core_user") as batch_op:
batch_op.add_column(
sa.Column(
"account_type",
sa.Enum(AccountType, name="accounttype"),
nullable=False,
server_default="external",
),
)

op.create_table(
"module_account_type_visibility",
Expand All @@ -252,6 +239,16 @@ def downgrade() -> None:
sa.PrimaryKeyConstraint("root", "allowed_account_type"),
)

with op.batch_alter_table("core_user") as batch_op:
batch_op.add_column(
sa.Column(
"account_type",
sa.Enum(AccountType, name="accounttype"),
nullable=False,
server_default="external",
),
)

op.drop_index(op.f("ix_core_school_name"), table_name="core_school")
op.drop_index(op.f("ix_core_school_id"), table_name="core_school")
op.drop_table("core_school")
Expand Down
9 changes: 6 additions & 3 deletions tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from app.core import models_core
from app.core.groups.groups_type import AccountType, GroupType
from app.core.schools.schools_type import SchoolType
from tests.commons import (
create_api_access_token,
create_user_with_groups,
Expand Down Expand Up @@ -140,6 +141,7 @@ def test_create_user_by_user_with_email(
"/users/create",
json={
"email": email,
"school_id": SchoolType.centrale_lyon.value,
},
)
assert response.status_code == expected_code
Expand All @@ -157,6 +159,7 @@ def test_create_and_activate_user(mocker: MockerFixture, client: TestClient) ->
"/users/create",
json={
"email": "[email protected]",
"school_id": SchoolType.centrale_lyon.value,
},
)
assert response.status_code == 201
Expand Down Expand Up @@ -210,9 +213,9 @@ def test_update_batch_create_users(client: TestClient) -> None:
response = client.post(
"/users/batch-creation",
json=[
{"email": "[email protected]"},
{"email": "[email protected]"},
{"email": "[email protected]"},
{"email": "[email protected]", "school_id": SchoolType.centrale_lyon.value},
{"email": "[email protected]", "school_id": SchoolType.centrale_lyon.value},
{"email": "[email protected]", "school_id": SchoolType.centrale_lyon.value},
],
headers={"Authorization": f"Bearer {token_admin_user}"},
)
Expand Down

0 comments on commit 2d30254

Please sign in to comment.