-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(PC-32565)[BO] feat: add page for ds account update requests
- Loading branch information
1 parent
53a6e25
commit 6e7df43
Showing
19 changed files
with
574 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
025aaed1c957 (pre) (head) | ||
9bca134a0476 (post) (head) | ||
cb98ffb241da (pre) (head) | ||
ddb791b7e221 (post) (head) |
71 changes: 71 additions & 0 deletions
71
...alembic/versions/20241119T161430_cb98ffb241da_create_table_user_account_update_request.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"""Create table UserAccountUpdateRequest | ||
""" | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
from pcapi.connectors.dms.models import GraphQLApplicationStates | ||
from pcapi.utils.db import MagicEnum | ||
|
||
|
||
# pre/post deployment: pre | ||
# revision identifiers, used by Alembic. | ||
revision = "cb98ffb241da" | ||
down_revision = "025aaed1c957" | ||
branch_labels: tuple[str] | None = None | ||
depends_on: list[str] | None = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.create_table( | ||
"user_account_update_request", | ||
sa.Column("id", sa.BigInteger(), autoincrement=True, nullable=False), | ||
sa.Column("dsApplicationId", sa.BigInteger(), nullable=False), | ||
sa.Column("status", MagicEnum(GraphQLApplicationStates), nullable=False), | ||
sa.Column("dateCreated", sa.DateTime(), server_default=sa.text("now()"), nullable=False), | ||
sa.Column("dateLastStatusUpdate", sa.DateTime(), server_default=sa.text("now()"), nullable=True), | ||
sa.Column("firstName", sa.Text(), nullable=True), | ||
sa.Column("lastName", sa.Text(), nullable=True), | ||
sa.Column("email", sa.Text(), nullable=False), | ||
sa.Column("birthDate", sa.Date(), nullable=True), | ||
sa.Column("userId", sa.BigInteger(), nullable=True), | ||
sa.Column("newEmail", sa.Text(), nullable=True), | ||
sa.Column("newPhoneNumber", sa.Text(), nullable=True), | ||
sa.Column("newFirstName", sa.Text(), nullable=True), | ||
sa.Column("newLastName", sa.Text(), nullable=True), | ||
sa.Column("allConditionsChecked", sa.Boolean(), nullable=False), | ||
sa.Column("lastInstructorId", sa.BigInteger(), nullable=True), | ||
sa.Column("dateLastUserMessage", sa.DateTime(), nullable=True), | ||
sa.Column("dateLastInstructorMessage", sa.DateTime(), nullable=True), | ||
sa.ForeignKeyConstraint( | ||
["lastInstructorId"], | ||
["user.id"], | ||
postgresql_not_valid=True, | ||
), | ||
sa.ForeignKeyConstraint( | ||
["userId"], | ||
["user.id"], | ||
postgresql_not_valid=True, | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
op.create_index( | ||
op.f("ix_user_account_update_request_dsApplicationId"), | ||
"user_account_update_request", | ||
["dsApplicationId"], | ||
unique=True, | ||
) | ||
op.create_index( | ||
op.f("ix_user_account_update_request_userId"), | ||
"user_account_update_request", | ||
["userId"], | ||
) | ||
op.create_index( | ||
op.f("ix_user_account_update_request_lastInstructorId"), | ||
"user_account_update_request", | ||
["lastInstructorId"], | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_table("user_account_update_request") |
29 changes: 29 additions & 0 deletions
29
.../alembic/versions/20241122T135331_ddb791b7e221_validate_user_account_update_request_fk.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""Validate constraint on user_account_update_request.userId and user_account_update_request.lastInstructorId | ||
""" | ||
|
||
from alembic import op | ||
|
||
from pcapi import settings | ||
|
||
|
||
# pre/post deployment: post | ||
# revision identifiers, used by Alembic. | ||
revision = "ddb791b7e221" | ||
down_revision = "9bca134a0476" | ||
branch_labels: tuple[str] | None = None | ||
depends_on: list[str] | None = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.execute("SET SESSION statement_timeout = '300s'") | ||
op.execute( | ||
"""ALTER TABLE user_account_update_request VALIDATE CONSTRAINT "user_account_update_request_userId_fkey" """ | ||
) | ||
op.execute( | ||
"""ALTER TABLE user_account_update_request VALIDATE CONSTRAINT "user_account_update_request_lastInstructorId_fkey" """ | ||
) | ||
op.execute(f"SET SESSION statement_timeout={settings.DATABASE_STATEMENT_TIMEOUT}") | ||
|
||
|
||
def downgrade() -> None: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
api/src/pcapi/routes/backoffice/accounts/update_request_blueprint.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from functools import partial | ||
|
||
from flask import render_template | ||
from flask import url_for | ||
import sqlalchemy as sa | ||
|
||
from pcapi.core.permissions import models as perm_models | ||
from pcapi.core.users import models as users_models | ||
from pcapi.repository import atomic | ||
from pcapi.routes.backoffice import search_utils | ||
from pcapi.routes.backoffice import utils | ||
|
||
from . import forms as account_forms | ||
|
||
|
||
account_update_blueprint = utils.child_backoffice_blueprint( | ||
"account_update", | ||
__name__, | ||
url_prefix="/account-update-requests", | ||
permission=perm_models.Permissions.MANAGE_ACCOUNT_UPDATE_REQUEST, | ||
) | ||
|
||
|
||
@account_update_blueprint.route("", methods=["GET"]) | ||
@atomic() | ||
def list_account_update_requests() -> utils.BackofficeResponse: | ||
form = account_forms.AccountUpdateRequestSearchForm(formdata=utils.get_query_params()) | ||
if not form.validate(): | ||
return render_template("accounts/update_requests_list.html", rows=[], form=form), 400 | ||
|
||
query = users_models.UserAccountUpdateRequest.query.options( | ||
sa.orm.joinedload(users_models.UserAccountUpdateRequest.user).load_only( | ||
users_models.User.id, | ||
users_models.User.email, | ||
users_models.User.firstName, | ||
users_models.User.lastName, | ||
users_models.User.civility, | ||
users_models.User.phoneNumber, | ||
users_models.User.dateOfBirth, | ||
users_models.User.validatedBirthDate, | ||
), | ||
sa.orm.joinedload(users_models.UserAccountUpdateRequest.lastInstructor).load_only( | ||
users_models.User.id, | ||
users_models.User.email, | ||
users_models.User.firstName, | ||
users_models.User.lastName, | ||
), | ||
).order_by(users_models.UserAccountUpdateRequest.id.desc()) | ||
|
||
paginated_rows = query.paginate(page=int(form.page.data), per_page=int(form.per_page.data)) | ||
next_page = partial(url_for, ".list_account_update_requests", **form.raw_data) | ||
next_pages_urls = search_utils.pagination_links(next_page, int(form.page.data), paginated_rows.pages) | ||
form.page.data = 1 # Reset to first page when form is submitted ("Chercher" clicked) | ||
|
||
return render_template( | ||
"accounts/update_requests_list.html", | ||
rows=paginated_rows, | ||
form=form, | ||
next_pages_urls=next_pages_urls, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.