Skip to content
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

1879 edit operation #2253

Merged
merged 24 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
31c6f94
chore: read only widget support array values
marcellmueller Sep 19, 2024
4d8a953
chore: create administration operation information schema
marcellmueller Sep 19, 2024
bf6b688
chore: add registration_purpose fixtures
marcellmueller Sep 20, 2024
c091143
chore: add operation update api route
marcellmueller Sep 20, 2024
dc0ece6
chore: add get operation with documents route
marcellmueller Sep 20, 2024
d7a8e96
chore: add get operation with documents shared action
marcellmueller Sep 20, 2024
c2593f2
chore: save operation details on edit
marcellmueller Sep 20, 2024
d2c8da5
chore: add new operation_id endpoints tests
marcellmueller Sep 20, 2024
9403854
chore: allow industry users to edit operation details
marcellmueller Sep 23, 2024
f9c398a
chore: fix typescript enumnames error
marcellmueller Sep 23, 2024
30ff06f
chore: fix build error
marcellmueller Sep 23, 2024
b579c01
chore: update operation information tests
marcellmueller Sep 23, 2024
917727d
chore: add operation information form tests
marcellmueller Sep 23, 2024
b1a4cf7
chore: update registration_purpose fixtures
marcellmueller Sep 24, 2024
fc61c7c
chore: add more purpose fixtures
marcellmueller Sep 24, 2024
8b46e19
chore: fix regulated_products required bug
marcellmueller Sep 24, 2024
4a871e4
chore: add operation out schema fields after rebase
marcellmueller Sep 24, 2024
b400a9c
chore: save regulated_products field
marcellmueller Sep 24, 2024
454e4c8
chore: add multiple operator out schema
marcellmueller Sep 25, 2024
8876960
chore: fix cra business number
marcellmueller Sep 25, 2024
8dd850a
chore: update test
marcellmueller Sep 25, 2024
49782dd
chore: add file preview
marcellmueller Sep 25, 2024
c9a7771
chore: fix read only file widget error
marcellmueller Sep 25, 2024
e73346b
chore: add operation service comment
marcellmueller Sep 25, 2024
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
1 change: 1 addition & 0 deletions bc_obps/common/management/commands/load_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def handle(self, *args, **options):
f'{fixture_base_dir}/transfer_event.json',
f'{fixture_base_dir}/parent_operator.json',
f'{fixture_base_dir}/partner_operator.json',
f'{fixture_base_dir}/registration_purpose.json',
]

for fixture in fixtures:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
OperationInformationIn,
OperationUpdateOut,
OperationRegistrationSubmissionIn,
OperationStatutoryDeclarationIn,
)
from service.operation_service_v2 import OperationServiceV2
from registration.constants import OPERATION_TAGS, V2
from registration.constants import V2
from common.permissions import authorize
from registration.api.utils.current_user_utils import get_current_user_guid
from service.error_service.custom_codes_4xx import custom_codes_4xx
from registration.models import Operation
from registration.decorators import handle_http_errors
from registration.api.router import router
from registration.schema.generic import Message
from ninja.responses import codes_4xx


##### PUT #####
Expand All @@ -38,22 +36,6 @@ def register_edit_operation_information(
return 200, OperationServiceV2.register_operation_information(get_current_user_guid(request), operation_id, payload)


@router.put(
"/v2/operations/{operation_id}/registration/statutory-declaration",
response={200: OperationUpdateOut, codes_4xx: Message},
tags=OPERATION_TAGS,
description="Creates or replaces a statutory declaration document for an Operation",
auth=authorize("approved_industry_user"),
)
@handle_http_errors()
def create_or_replace_statutory_declarations(
request: HttpRequest, operation_id: UUID, payload: OperationStatutoryDeclarationIn
) -> Tuple[Literal[200], Operation]:
return 200, OperationServiceV2.create_or_replace_statutory_declaration(
get_current_user_guid(request), operation_id, payload
)


@router.patch(
"/v2/operations/{uuid:operation_id}/registration/submission",
response={200: OperationUpdateStatusOut, custom_codes_4xx: Message},
Expand Down
33 changes: 32 additions & 1 deletion bc_obps/registration/api/v2/_operations/operation_id.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from typing import Literal, Tuple
from uuid import UUID
from registration.schema.v2.operation import OperationOutV2
from registration.schema.v2.operation import OperationOutV2, OperationInformationIn, OperationOutWithDocuments
from common.permissions import authorize
from django.http import HttpRequest
from registration.constants import OPERATION_TAGS
from service.operation_service import OperationService
from service.operation_service_v2 import OperationServiceV2
from registration.api.utils.current_user_utils import get_current_user_guid
from registration.decorators import handle_http_errors
from registration.api.router import router
Expand All @@ -29,3 +30,33 @@
@handle_http_errors()
def get_operation_v2(request: HttpRequest, operation_id: UUID) -> Tuple[Literal[200], Operation]:
return 200, OperationService.get_if_authorized(get_current_user_guid(request), operation_id)


@router.get(
"/v2/operations/{uuid:operation_id}/with-documents",
response={200: OperationOutWithDocuments, codes_4xx: Message},
tags=OPERATION_TAGS,
description="""Retrieves the details of a specific operation by its ID along with it's documents""",
exclude_none=True,
auth=authorize("approved_authorized_roles"),
)
@handle_http_errors()
def get_operation_with_documents(request: HttpRequest, operation_id: UUID) -> Tuple[Literal[200], Operation]:
return 200, OperationService.get_if_authorized(get_current_user_guid(request), operation_id)
Comment on lines +35 to +45
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new API route, though I was split on if I should add a query param like documents and return the documents if it was true. Can we have conditional Django Ninja schemas? Is a separate route fine?



##### PUT ######


@router.put(
"/v2/operations/{uuid:operation_id}",
response={200: OperationOutV2, codes_4xx: Message},
tags=OPERATION_TAGS,
description="Updates the details of a specific operation by its ID.",
auth=authorize("approved_industry_user"),
)
@handle_http_errors()
def update_operation_v2(
request: HttpRequest, operation_id: UUID, payload: OperationInformationIn
) -> Tuple[Literal[200], Operation]:
return 200, OperationServiceV2.update_operation(get_current_user_guid(request), payload, operation_id)
11 changes: 11 additions & 0 deletions bc_obps/registration/fixtures/mock/operation.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
},
{
"model": "registration.operation",
"pk": "df62d793-8cfe-4272-a93e-ea9c9139ff82",
"fields": {
"operator": "4242ea9d-b917-4129-93c2-db00b7451051",
"documents": [],
Expand All @@ -260,6 +261,7 @@
},
{
"model": "registration.operation",
"pk": "c5b3643b-c143-42f3-8a2b-03ccc7319cd9",
"fields": {
"operator": "4242ea9d-b917-4129-93c2-db00b7451051",
"documents": [],
Expand All @@ -278,6 +280,7 @@
},
{
"model": "registration.operation",
"pk": "954c0382-ff61-4e87-a8a0-873586534b54",
"fields": {
"operator": "4242ea9d-b917-4129-93c2-db00b7451051",
"documents": [],
Expand All @@ -296,6 +299,7 @@
},
{
"model": "registration.operation",
"pk": "6d07d02a-1ad2-46ed-ad56-2f84313e98bf",
"fields": {
"operator": "4242ea9d-b917-4129-93c2-db00b7451051",
"documents": [],
Expand All @@ -314,6 +318,7 @@
},
{
"model": "registration.operation",
"pk": "59d95661-c752-489b-9fd1-0c3fa3454dda",
"fields": {
"operator": "4242ea9d-b917-4129-93c2-db00b7451051",
"documents": [],
Expand All @@ -332,6 +337,7 @@
},
{
"model": "registration.operation",
"pk": "1bd04128-d070-4d3a-940a-0874c4956181",
"fields": {
"operator": "4242ea9d-b917-4129-93c2-db00b7451051",
"documents": [],
Expand All @@ -350,6 +356,7 @@
},
{
"model": "registration.operation",
"pk": "17f13f4d-29b4-45f4-b025-b21f2e126771",
"fields": {
"operator": "4242ea9d-b917-4129-93c2-db00b7451051",
"documents": [],
Expand All @@ -367,6 +374,7 @@
},
{
"model": "registration.operation",
"pk": "ef9044dd-2a27-4d26-86fe-02e51e0755f7",
"fields": {
"operator": "4242ea9d-b917-4129-93c2-db00b7451051",
"documents": [],
Expand All @@ -383,6 +391,7 @@
},
{
"model": "registration.operation",
"pk": "aeeb781e-a97b-4ab2-9a6e-02e4522add1a",
"fields": {
"operator": "4242ea9d-b917-4129-93c2-db00b7451051",
"documents": [],
Expand All @@ -399,6 +408,7 @@
},
{
"model": "registration.operation",
"pk": "02a3ab84-26c6-4a79-bf89-72f877ceef8e",
"fields": {
"operator": "4242ea9d-b917-4129-93c2-db00b7451051",
"documents": [],
Expand Down Expand Up @@ -431,6 +441,7 @@
},
{
"model": "registration.operation",
"pk": "0ac72fa9-2636-4f54-b378-af6b1a070787",
"fields": {
"operator": "4242ea9d-b917-4129-93c2-db00b7451051",
"documents": [],
Expand Down
170 changes: 170 additions & 0 deletions bc_obps/registration/fixtures/mock/registration_purpose.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
[
{
"model": "registration.registrationpurpose",
"pk": 1,
"fields": {
"registration_purpose": "OBPS Regulated Operation",
"operation_id": "c0743c09-82fa-4186-91aa-4b5412e3415c"
}
},
{
"model": "registration.registrationpurpose",
"pk": 2,
"fields": {
"registration_purpose": "Potential Reporting Operation",
"operation_id": "c0743c09-82fa-4186-91aa-4b5412e3415c"
}
},
{
"model": "registration.registrationpurpose",
"pk": 3,
"fields": {
"registration_purpose": "OBPS Regulated Operation",
"operation_id": "1bd04128-d070-4d3a-940a-0874c4956181"
}
},
{
"model": "registration.registrationpurpose",
"pk": 4,
"fields": {
"registration_purpose": "Reporting Operation",
"operation_id": "1bd04128-d070-4d3a-940a-0874c4956181"
}
},
{
"model": "registration.registrationpurpose",
"pk": 5,
"fields": {
"registration_purpose": "New Entrant Operation",
"operation_id": "1bd04128-d070-4d3a-940a-0874c4956181"
}
},
{
"model": "registration.registrationpurpose",
"pk": 6,
"fields": {
"registration_purpose": "OBPS Regulated Operation",
"operation_id": "3b5b95ea-2a1a-450d-8e2e-2e15feed96c9"
}
},
{
"model": "registration.registrationpurpose",
"pk": 7,
"fields": {
"registration_purpose": "Reporting Operation",
"operation_id": "3b5b95ea-2a1a-450d-8e2e-2e15feed96c9"
}
},
{
"model": "registration.registrationpurpose",
"pk": 8,
"fields": {
"registration_purpose": "Electricity Import Operation",
"operation_id": "3b5b95ea-2a1a-450d-8e2e-2e15feed96c9"
}
},
{
"model": "registration.registrationpurpose",
"pk": 9,
"fields": {
"registration_purpose": "OBPS Regulated Operation",
"operation_id": "17f13f4d-29b4-45f4-b025-b21f2e126771"
}
},
{
"model": "registration.registrationpurpose",
"pk": 10,
"fields": {
"registration_purpose": "Reporting Operation",
"operation_id": "1bd04128-d070-4d3a-940a-0874c4956181"
}
},
{
"model": "registration.registrationpurpose",
"pk": 11,
"fields": {
"registration_purpose": "OBPS Regulated Operation",
"operation_id": "aeeb781e-a97b-4ab2-9a6e-02e4522add1a"
}
},
{
"model": "registration.registrationpurpose",
"pk": 12,
"fields": {
"registration_purpose": "Reporting Operation",
"operation_id": "02a3ab84-26c6-4a79-bf89-72f877ceef8e"
}
},
{
"model": "registration.registrationpurpose",
"pk": 13,
"fields": {
"registration_purpose": "OBPS Regulated Operation",
"operation_id": "0ac72fa9-2636-4f54-b378-af6b1a070787"
}
},
{
"model": "registration.registrationpurpose",
"pk": 14,
"fields": {
"registration_purpose": "Reporting Operation",
"operation_id": "df62d793-8cfe-4272-a93e-ea9c9139ff82"
}
},
{
"model": "registration.registrationpurpose",
"pk": 15,
"fields": {
"registration_purpose": "OBPS Regulated Operation",
"operation_id": "c5b3643b-c143-42f3-8a2b-03ccc7319cd9"
}
},
{
"model": "registration.registrationpurpose",
"pk": 16,
"fields": {
"registration_purpose": "OBPS Regulated Operation",
"operation_id": "954c0382-ff61-4e87-a8a0-873586534b54"
}
},
{
"model": "registration.registrationpurpose",
"pk": 14,
"fields": {
"registration_purpose": "Reporting Operation",
"operation_id": "ef9044dd-2a27-4d26-86fe-02e51e0755f7"
}
},
{
"model": "registration.registrationpurpose",
"pk": 15,
"fields": {
"registration_purpose": "Reporting Operation",
"operation_id": "59d95661-c752-489b-9fd1-0c3fa3454dda"
}
},
{
"model": "registration.registrationpurpose",
"pk": 14,
"fields": {
"registration_purpose": "Reporting Operation",
"operation_id": "6d07d02a-1ad2-46ed-ad56-2f84313e98bf"
}
},
{
"model": "registration.registrationpurpose",
"pk": 15,
"fields": {
"registration_purpose": "Potential Reporting Operation",
"operation_id": "df62d793-8cfe-4272-a93e-ea9c9139ff82"
}
},
{
"model": "registration.registrationpurpose",
"pk": 16,
"fields": {
"registration_purpose": "Electricity Import Operation",
"operation_id": "c5b3643b-c143-42f3-8a2b-03ccc7319cd9"
}
}
]
21 changes: 21 additions & 0 deletions bc_obps/registration/models/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,27 @@ def get_statutory_declaration(self) -> Optional[Document]:
.first()
) # filter returns a queryset, so we use .first() to get the single record (there will only ever be one statutory declaration per operation)

def get_boundary_map(self) -> Optional[Document]:
"""
Returns the boundary map document associated with the operation.
"""

return self.documents.filter(type=DocumentType.objects.get(name="boundary_map")).only('file').first()

def get_process_flow_diagram(self) -> Optional[Document]:
"""
Returns the process flow diagram document associated with the operation.
"""

return self.documents.filter(type=DocumentType.objects.get(name="process_flow_diagram")).only('file').first()

def get_equipment_list(self) -> Optional[Document]:
"""
Returns the equipment list document associated with the operation.
"""

return self.documents.filter(type=DocumentType.objects.get(name="equipment_list")).only('file').first()

def user_has_access(self, user_guid: UUID) -> bool:
"""
Returns whether a user has access to the operation.
Expand Down
Loading