-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
533 filing status prototype #540
base: main
Are you sure you want to change the base?
Changes from 3 commits
bba5e5e
77a6362
b192c02
4684694
09d35db
7588b68
46fb9c7
0988c40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
"""Add filing state | ||
|
||
Revision ID: 7fe49d38726b | ||
Revises: 6ec12afa5b37 | ||
Create Date: 2024-12-30 13:05:01.303998 | ||
|
||
""" | ||
|
||
from typing import Sequence, Union | ||
|
||
from alembic import op, context | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "7fe49d38726b" | ||
down_revision: Union[str, None] = "6ec12afa5b37" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
filing_state_enum = postgresql.ENUM( | ||
"OPEN", | ||
"CLOSED", | ||
name="filingstate", | ||
create_type=False, | ||
) | ||
|
||
old_user_action = postgresql.ENUM( | ||
"SUBMIT", | ||
"ACCEPT", | ||
"SIGNED", | ||
"CREATE", | ||
name="useractiontype", | ||
create_type=False, | ||
) | ||
|
||
new_user_action = postgresql.ENUM( | ||
"SUBMIT", | ||
"ACCEPT", | ||
"SIGNED", | ||
"CREATE", | ||
"REOPEN", | ||
name="useractiontype", | ||
create_type=False, | ||
) | ||
|
||
|
||
def upgrade() -> None: | ||
filing_state_enum.create(op.get_bind(), checkfirst=True) | ||
op.add_column( | ||
"filing", | ||
sa.Column("state", filing_state_enum), | ||
) | ||
|
||
if "sqlite" not in context.get_context().dialect.name: | ||
op.execute("ALTER TYPE useractiontype RENAME TO useractiontype_old") | ||
new_user_action.create(op.get_bind(), checkfirst=True) | ||
op.execute( | ||
"ALTER TABLE user_action ALTER COLUMN action_type TYPE useractiontype USING user_action::text::useractiontype" | ||
) | ||
op.execute("DROP TYPE useractiontype_old") | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_column("filing", "state") | ||
if "sqlite" not in context.get_context().dialect.name: | ||
op.execute(sa.DDL("DROP TYPE filingstate")) | ||
|
||
op.execute("ALTER TYPE useractiontype RENAME TO useractiontype_old") | ||
old_user_action.create(op.get_bind(), checkfirst=True) | ||
op.execute( | ||
"ALTER TABLE user_action ALTER COLUMN action_type TYPE useractiontype USING user_action::text::useractiontype" | ||
) | ||
op.execute("DROP TYPE useractiontype_old") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
from regtech_api_commons.models.auth import AuthenticatedUser | ||
|
||
from sbl_filing_api.entities.models.dao import FilingDAO | ||
from sbl_filing_api.entities.models.model_enums import UserActionType | ||
from sbl_filing_api.entities.models.model_enums import UserActionType, FilingState | ||
from sbl_filing_api.services import submission_processor | ||
from sbl_filing_api.services.multithread_handler import handle_submission | ||
from sbl_filing_api.config import request_action_validations | ||
|
@@ -139,6 +139,7 @@ async def sign_filing(request: Request, lei: str, period_code: str): | |
sig_timestamp = int(sig.timestamp.timestamp()) | ||
filing.confirmation_id = lei + "-" + period_code + "-" + str(latest_sub.counter) + "-" + str(sig_timestamp) | ||
filing.signatures.append(sig) | ||
filing.state = FilingState.CLOSED | ||
send_confirmation_email( | ||
request.user.name, request.user.email, filing.contact_info.email, filing.confirmation_id, sig_timestamp | ||
) | ||
|
@@ -411,3 +412,28 @@ async def update_is_voluntary(request: Request, lei: str, period_code: str, upda | |
name="Filing Not Found", | ||
detail=f"A Filing for the LEI ({lei}) and period ({period_code}) that was attempted to be updated does not exist.", | ||
) | ||
|
||
|
||
@router.put( | ||
"/institutions/{lei}/filings/{period_code}/reopen", | ||
response_model=FilingDTO, | ||
dependencies=[ | ||
Depends(set_context({UserActionContext.FILING})), | ||
Depends(validate_user_action(request_action_validations.filing_reopen, "Filing Reopen Forbidden")), | ||
], | ||
) | ||
@requires("authenticated") | ||
async def reopen_filing(request: Request, lei: str, period_code: str): | ||
await repo.add_user_action( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The user action needs to be added to the Filing object as a relationship (like signature, submitter is added to the Submission, etc). Otherwise there's not relationship to tell who reopened a filing. You just have a user action created in the table but nothing that it refers back to. |
||
request.state.db_session, | ||
UserActionDTO( | ||
user_id=request.user.id, | ||
user_name=request.user.name, | ||
user_email=request.user.email, | ||
action_type=UserActionType.REOPEN, | ||
), | ||
) | ||
filing = await repo.get_filing(request.state.db_session, lei, period_code) | ||
filing.state = FilingState.OPEN | ||
res = await repo.upsert_filing(request.state.db_session, filing) | ||
return res |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,12 +72,21 @@ async def setup( | |
action_type=UserActionType.SIGN, | ||
timestamp=dt.now(), | ||
) | ||
user_action6 = UserActionDAO( | ||
id=6, | ||
user_id="[email protected]", | ||
user_name="signer name", | ||
user_email="[email protected]", | ||
action_type=UserActionType.REOPEN, | ||
timestamp=dt.now(), | ||
) | ||
|
||
transaction_session.add(user_action1) | ||
transaction_session.add(user_action2) | ||
transaction_session.add(user_action3) | ||
transaction_session.add(user_action4) | ||
transaction_session.add(user_action5) | ||
transaction_session.add(user_action6) | ||
|
||
filing_task_1 = FilingTaskDAO(name="Task-1", task_order=1) | ||
filing_task_2 = FilingTaskDAO(name="Task-2", task_order=2) | ||
|
@@ -262,6 +271,7 @@ async def test_add_filing(self, transaction_session: AsyncSession): | |
assert res.creator.user_name == "test creator" | ||
assert res.creator.user_email == "[email protected]" | ||
assert res.creator.action_type == UserActionType.CREATE | ||
assert res.state == "OPEN" | ||
|
||
async def test_modify_filing(self, transaction_session: AsyncSession): | ||
user_action_create = await repo.add_user_action( | ||
|
@@ -606,7 +616,7 @@ async def test_get_user_action(self, query_session: AsyncSession): | |
async def test_get_user_actions(self, query_session: AsyncSession): | ||
res = await repo.get_user_actions(session=query_session) | ||
|
||
assert len(res) == 5 | ||
assert len(res) == 6 | ||
assert res[0].id == 1 | ||
assert res[0].user_name == "signer name" | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if we should add a check to ensure the Filing is in an OPEN state on signing. @lchen-2101 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we prevent signing altogether if the state is not set to open?
And add a validator check to look at the state before proceeding?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I am thinking, yeah.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This validation has been added.