Skip to content

Commit 39eb4fc

Browse files
committed
Add should_change_password column
1 parent 513a563 commit 39eb4fc

File tree

6 files changed

+70
-0
lines changed

6 files changed

+70
-0
lines changed

app/core/users/cruds_users.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,18 @@ async def update_user_password_by_id(
283283
await db.flush()
284284

285285

286+
async def update_should_user_change_password_by_id(
287+
db: AsyncSession,
288+
user_id: str,
289+
should_change_password: bool = True,
290+
):
291+
await db.execute(
292+
update(models_users.CoreUser)
293+
.where(models_users.CoreUser.id == user_id)
294+
.values(should_change_password=should_change_password),
295+
)
296+
297+
286298
async def remove_users_from_school(
287299
db: AsyncSession,
288300
school_id: UUID,

app/core/users/endpoints_users.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ async def activate_user(
406406
school_id=school_id,
407407
account_type=account_type,
408408
password_hash=password_hash,
409+
should_change_password=False,
409410
name=user.name,
410411
firstname=user.firstname,
411412
nickname=user.nickname,

app/core/users/factory_users.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ async def create_core_users(cls, db: AsyncSession):
9393
user = CoreUser(
9494
id=cls.other_users_id[i],
9595
password_hash=password[i],
96+
should_change_password=False,
9697
firstname=firstname[i],
9798
nickname=nickname[i],
9899
name=name[i],
@@ -113,6 +114,7 @@ async def create_core_users(cls, db: AsyncSession):
113114
password_hash=security.get_password_hash(
114115
user_info.password or faker.password(16, True, True, True, True),
115116
),
117+
should_change_password=False,
116118
firstname=user_info.firstname,
117119
nickname=user_info.nickname,
118120
name=user_info.name,

app/core/users/models_users.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class CoreUser(Base):
2424
email: Mapped[str] = mapped_column(unique=True, index=True)
2525
school_id: Mapped[UUID] = mapped_column(ForeignKey("core_school.id"))
2626
password_hash: Mapped[str]
27+
should_change_password: Mapped[bool]
2728
# Depending on the account type, the user may have different rights and access to different features
2829
# External users may exist for:
2930
# - accounts meant to be used by external services based on Hyperion SSO or Hyperion backend
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""password-invalidation
2+
3+
Create Date: 2025-10-03 11:24:35.720759
4+
"""
5+
6+
from collections.abc import Sequence
7+
from typing import TYPE_CHECKING
8+
9+
if TYPE_CHECKING:
10+
from pytest_alembic import MigrationContext
11+
12+
import sqlalchemy as sa
13+
from alembic import op
14+
15+
# revision identifiers, used by Alembic.
16+
revision: str = "cfba514689ed"
17+
down_revision: str | None = "c4812e1ab108"
18+
branch_labels: str | Sequence[str] | None = None
19+
depends_on: str | Sequence[str] | None = None
20+
21+
22+
def upgrade() -> None:
23+
# ### commands auto generated by Alembic - please adjust! ###
24+
op.add_column(
25+
"core_user",
26+
sa.Column(
27+
"should_change_password",
28+
sa.Boolean(),
29+
nullable=False,
30+
server_default=sa.sql.false(),
31+
),
32+
)
33+
# ### end Alembic commands ###
34+
35+
36+
def downgrade() -> None:
37+
# ### commands auto generated by Alembic - please adjust! ###
38+
op.drop_column("core_user", "should_change_password")
39+
# ### end Alembic commands ###
40+
41+
42+
def pre_test_upgrade(
43+
alembic_runner: "MigrationContext",
44+
alembic_connection: sa.Connection,
45+
) -> None:
46+
pass
47+
48+
49+
def test_upgrade(
50+
alembic_runner: "MigrationContext",
51+
alembic_connection: sa.Connection,
52+
) -> None:
53+
pass

tests/commons.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ async def create_user_with_groups(
193193
email=email or (get_random_string() + "@etu.ec-lyon.fr"),
194194
school_id=school_id,
195195
password_hash=password_hash,
196+
should_change_password=False,
196197
name=name or get_random_string(),
197198
firstname=firstname or get_random_string(),
198199
nickname=nickname,

0 commit comments

Comments
 (0)