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

2427 internal users can transfer a facility or operation #2557

Merged
merged 53 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
c2cb573
chore: add new user role to permissions
Sepehr-Sobhani Dec 6, 2024
6e62445
chore: admin panel tweaks
Sepehr-Sobhani Dec 6, 2024
a8361b5
chore: fix type hints
Sepehr-Sobhani Dec 6, 2024
c443150
chore: add new api endpoint tag
Sepehr-Sobhani Dec 6, 2024
3d59799
chore: exclude `all` key from generic errors
Sepehr-Sobhani Dec 6, 2024
ad4ced0
chore: operation and designated operator fixture tweaks
Sepehr-Sobhani Dec 6, 2024
d62b410
chore: new fixture for cas analyst user
Sepehr-Sobhani Dec 6, 2024
b4a908d
chore: one more approved industry user admin
Sepehr-Sobhani Dec 6, 2024
6b99ddc
chore: more data model methods
Sepehr-Sobhani Dec 6, 2024
6db5193
chore: remove unused jsonschema file
Sepehr-Sobhani Dec 6, 2024
d1b51f7
chore: tweak endpoint, schema and types to fetch non paginated data a…
Sepehr-Sobhani Dec 6, 2024
e11ba88
chore: fix dashboard tile href
Sepehr-Sobhani Dec 6, 2024
e584d84
chore: renaming - using ts instead of tsx
Sepehr-Sobhani Dec 6, 2024
4599f90
chore: update transfer event fixtures
Sepehr-Sobhani Dec 6, 2024
58ce5fa
chore: update transfer event data model
Sepehr-Sobhani Dec 6, 2024
062942a
chore: add status to operation designated operator timeline table
Sepehr-Sobhani Dec 6, 2024
2816b5d
feat: add transfer event feature
Sepehr-Sobhani Dec 6, 2024
afd6221
chore: add transfer event endpoint and schema
Sepehr-Sobhani Dec 6, 2024
49a8a56
chore: handle server errors when rows is undefined
Sepehr-Sobhani Dec 6, 2024
47c7222
chore: resolve a new uuid when we have similar transfer events - caus…
Sepehr-Sobhani Dec 6, 2024
0e9fb44
chore: add the new fetch api to the index file
Sepehr-Sobhani Dec 6, 2024
e9474f4
chore: fix import
Sepehr-Sobhani Dec 6, 2024
5196f68
chore: post-rebase migration fix
Sepehr-Sobhani Dec 6, 2024
dc7d1e0
chore: fix tests after latest transfer event modifications
Sepehr-Sobhani Dec 8, 2024
f0b06bb
chore: remove v2 ref after endpoint refactor
Sepehr-Sobhani Dec 8, 2024
43b2aae
chore: transfer event is a v2 feature
Sepehr-Sobhani Dec 8, 2024
5e854ad
chore: post-rebase fix
Sepehr-Sobhani Dec 8, 2024
8ef2f99
chore: add cas analyst to endpoint tests
Sepehr-Sobhani Dec 8, 2024
aba9f4f
chore: add extra check to prevent creating wrong transfer event
Sepehr-Sobhani Dec 8, 2024
35bc6df
chore: make eslint happy
Sepehr-Sobhani Dec 8, 2024
0780dce
chore: add more baker recipes
Sepehr-Sobhani Dec 11, 2024
93826a2
chore: make test name singular
Sepehr-Sobhani Dec 11, 2024
29f4edc
chore: fix schema name
Sepehr-Sobhani Dec 11, 2024
0f2b1c4
chore: renaming tweaks
Sepehr-Sobhani Dec 11, 2024
2f22c75
test: add backend tests
Sepehr-Sobhani Dec 11, 2024
72de680
test: add frontend tests
Sepehr-Sobhani Dec 11, 2024
2d15e58
test: raise error if response is undefined
Sepehr-Sobhani Dec 11, 2024
f1ad03d
chore: renaming tweaks and cover edge cases
Sepehr-Sobhani Dec 11, 2024
ddf8676
chore: return undefined if pageData is undefined
Sepehr-Sobhani Dec 11, 2024
8c95f93
chore: fix dashboard tile allowedRules issue
Sepehr-Sobhani Dec 12, 2024
4134e7f
chore: remove leftover
Sepehr-Sobhani Dec 12, 2024
b0ee873
chore: fix vitest tests after using the session util
Sepehr-Sobhani Dec 12, 2024
2668fbf
docs: add docs about transfer events
Sepehr-Sobhani Dec 12, 2024
acbf3dd
chore: make pre-commit happy
Sepehr-Sobhani Dec 12, 2024
1f9a07a
chore: make reg1 e2e tests happy
Sepehr-Sobhani Dec 12, 2024
8c20d4d
chore: make sonarcloud happy
Sepehr-Sobhani Dec 12, 2024
20306cd
chore: remove transfer sub-dashboard for internal users
Sepehr-Sobhani Dec 13, 2024
fa1a690
chore: remove transfer sub-dashboard for internal users
Sepehr-Sobhani Dec 13, 2024
21bc2e9
chore: implement review suggestions, remove redundant endpoints and u…
Sepehr-Sobhani Dec 13, 2024
f59d3f2
chore: using ts instead of tsx
Sepehr-Sobhani Dec 13, 2024
eabb344
chore: remove unused mock
Sepehr-Sobhani Dec 13, 2024
2439d76
chore: fix post-rebase migration issue
Sepehr-Sobhani Dec 13, 2024
0a49409
chore: fix vitest
Sepehr-Sobhani Dec 14, 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
10 changes: 2 additions & 8 deletions bc_obps/common/fixtures/dashboard/bciers/internal.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
},
{
"title": "Transfers",
"href": "/registration",
"icon": "Layers",
"content": "Transfer operations and facilities between Operators and view transfers.",
"links": [
Expand All @@ -48,13 +47,8 @@
},
{
"title": "Transfer an operation or facility",
"href": "/registration/transfer",
"conditions": [
{
"allowedRoles": ["cas_analyst"],
"value": true
}
]
"href": "/registration/transfers/transfer-entity",
"allowedRoles": ["cas_analyst"]
}
]
},
Expand Down
25 changes: 0 additions & 25 deletions bc_obps/common/fixtures/dashboard/registration/internal.json

This file was deleted.

1 change: 0 additions & 1 deletion bc_obps/common/migrations/0010_dashboarddata.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def load_dashboard_fixtures(apps, schema_editor):
# Below file does not exist in the repository but I'm keeping it here for reference
# 'common/fixtures/dashboard/registration/operation/external.json',
'common/fixtures/dashboard/registration/external.json',
'common/fixtures/dashboard/registration/internal.json',
'common/fixtures/dashboard/reporting/external.json',
'common/fixtures/dashboard/reporting/internal.json',
]
Expand Down
1 change: 0 additions & 1 deletion bc_obps/common/migrations/0012_update_dashboard_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def load_dashboard_fixtures(apps, schema_editor):
'common/fixtures/dashboard/administration/external.json',
'common/fixtures/dashboard/administration/internal.json',
'common/fixtures/dashboard/registration/external.json',
'common/fixtures/dashboard/registration/internal.json',
'common/fixtures/dashboard/reporting/external.json',
'common/fixtures/dashboard/reporting/internal.json',
'common/fixtures/dashboard/coam/external.json',
Expand Down
1 change: 0 additions & 1 deletion bc_obps/common/migrations/0016_update_dashboard_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def load_dashboard_fixtures(apps, schema_editor):
'common/fixtures/dashboard/administration/external.json',
'common/fixtures/dashboard/administration/internal.json',
'common/fixtures/dashboard/registration/external.json',
'common/fixtures/dashboard/registration/internal.json',
'common/fixtures/dashboard/reporting/external.json',
'common/fixtures/dashboard/reporting/internal.json',
'common/fixtures/dashboard/coam/external.json',
Expand Down
1 change: 0 additions & 1 deletion bc_obps/common/migrations/0017_update_dashboard_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def load_dashboard_fixtures(apps, schema_editor):
'common/fixtures/dashboard/administration/external.json',
'common/fixtures/dashboard/administration/internal.json',
'common/fixtures/dashboard/registration/external.json',
'common/fixtures/dashboard/registration/internal.json',
'common/fixtures/dashboard/reporting/external.json',
'common/fixtures/dashboard/reporting/internal.json',
'common/fixtures/dashboard/coam/external.json',
Expand Down
1 change: 0 additions & 1 deletion bc_obps/common/migrations/0020_update_dashboard_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def load_dashboard_fixtures(apps, schema_editor):
'common/fixtures/dashboard/administration/external.json',
'common/fixtures/dashboard/administration/internal.json',
'common/fixtures/dashboard/registration/external.json',
'common/fixtures/dashboard/registration/internal.json',
'common/fixtures/dashboard/reporting/external.json',
'common/fixtures/dashboard/reporting/internal.json',
'common/fixtures/dashboard/coam/external.json',
Expand Down
1 change: 0 additions & 1 deletion bc_obps/common/migrations/0022_update_dashboard_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def load_dashboard_fixtures(apps, schema_editor):
'common/fixtures/dashboard/administration/internal.json',
'common/fixtures/dashboard/operators/internal.json',
'common/fixtures/dashboard/registration/external.json',
'common/fixtures/dashboard/registration/internal.json',
'common/fixtures/dashboard/reporting/external.json',
'common/fixtures/dashboard/reporting/internal.json',
'common/fixtures/dashboard/coam/external.json',
Expand Down
6 changes: 6 additions & 0 deletions bc_obps/common/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ def get_permission_configs(permission: str) -> Optional[Union[Dict[str, List[str
'authorized_app_roles': ["cas_admin", "cas_analyst", "industry_user"],
'authorized_user_operator_roles': ["admin"],
},
"cas_analyst": {
'authorized_app_roles': list(
AppRole.objects.filter(role_name="cas_analyst").values_list("role_name", flat=True)
),
},
}
cache.set(PERMISSION_CONFIGS_CACHE_KEY, permission_configs, timeout=3600) # 1 hour
return permission_configs.get(permission)
Expand Down Expand Up @@ -155,6 +160,7 @@ def authorize(
"authorized_irc_user_and_industry_admin_user",
"v1_authorized_irc_user_write",
"v1_authorized_irc_user_and_industry_admin_user_write",
"cas_analyst",
]
) -> Callable[[HttpRequest], bool]:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ class TestEndpointPermissions(TestCase):
"kwargs": {"user_operator_id": mock_uuid},
},
],
"cas_analyst": [
{"method": "post", "endpoint_name": "create_transfer_event"},
],
}

@classmethod
Expand Down
1 change: 0 additions & 1 deletion bc_obps/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def reset_dashboard_data() -> None:
'common/fixtures/dashboard/administration/internal.json',
'common/fixtures/dashboard/operators/internal.json',
'common/fixtures/dashboard/registration/external.json',
'common/fixtures/dashboard/registration/internal.json',
'common/fixtures/dashboard/reporting/external.json',
'common/fixtures/dashboard/reporting/internal.json',
'common/fixtures/dashboard/coam/external.json',
Expand Down
36 changes: 35 additions & 1 deletion bc_obps/registration/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
admin.site.register(BcObpsRegulatedOperation)
admin.site.register(ClosureEvent)
admin.site.register(TemporaryShutdownEvent)
admin.site.register(TransferEvent)
admin.site.register(RestartEvent)


Expand Down Expand Up @@ -87,6 +86,7 @@ class FacilityDesignatedOperationTimelineAdmin(admin.ModelAdmin):
class OperationDesignatedOperatorTimelineAdmin(admin.ModelAdmin):
list_display = (
'id',
'status',
'operation',
'operator',
'start_date',
Expand Down Expand Up @@ -125,3 +125,37 @@ def user_full_name(obj: UserOperator) -> str:
@staticmethod
def operator_legal_name(obj: UserOperator) -> str:
return obj.operator.legal_name


@admin.register(TransferEvent)
class TransferEventAdmin(admin.ModelAdmin):
list_display = (
'id',
'status',
'from_operator_name',
'to_operation_name',
'operation_name',
'from_operation_name',
'to_operator_name',
'effective_date',
)

@staticmethod
def to_operator_name(obj: TransferEvent) -> str:
return obj.to_operator.legal_name

@staticmethod
def from_operator_name(obj: TransferEvent) -> str:
return obj.from_operator.legal_name

@staticmethod
def operation_name(obj: TransferEvent) -> str:
return obj.operation.name if obj.operation else 'N/A'

@staticmethod
def from_operation_name(obj: TransferEvent) -> str:
return obj.from_operation.name if obj.from_operation else 'N/A'

@staticmethod
def to_operation_name(obj: TransferEvent) -> str:
return obj.to_operation.name if obj.to_operation else 'N/A'
8 changes: 3 additions & 5 deletions bc_obps/registration/api/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
facilities,
)
from ._operations import current as operations_current
from ._operations._operation_id import boro_id, bcghg_id as operation_bcghg_id
from ._operations._operation_id import boro_id, bcghg_id as operation_bcghg_id, operation_representatives
from ._operations._operation_id.facilities import list_facilities_by_operation_id
from ._facilities._facility_id import bcghg_id as facility_bcghg_id
from ._facilities import facility_id
from ._operators import search
from ._operators import search, operator_id
from .transfer_events import list_transfer_events
from ._operators._operator_id import has_admin, request_access, request_admin_access, access_declined, confirm
from ._operators import operator_id
from ._user_operators._current import (
operator,
access_requests,
Expand All @@ -38,9 +37,8 @@
operator_users,
)
from ._user_operators._user_operator_id import update_status

from .user import user_profile, user_app_role
from ._user_operators import user_operator_id, pending, current
from ._contacts import contact_id
from ._users import user_id
from ._operations._operation_id import operation_representatives
from . import transfer_events
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from uuid import UUID
from registration.models.facility_designated_operation_timeline import FacilityDesignatedOperationTimeline
from registration.utils import CustomPagination
from service.facility_designated_operation_timeline_service import FacilityDesignatedOperationTimelineService
from registration.schema.v1.facility_designated_operation_timeline import (
FacilityDesignatedOperationTimelineFilterSchema,
Expand All @@ -13,7 +14,7 @@
from common.api.utils import get_current_user_guid
from registration.constants import FACILITY_TAGS
from registration.decorators import handle_http_errors
from ninja.pagination import paginate, PageNumberPagination
from ninja.pagination import paginate
from registration.schema.generic import Message
from service.error_service.custom_codes_4xx import custom_codes_4xx
from ninja import Query
Expand All @@ -28,13 +29,14 @@
auth=authorize("approved_authorized_roles"),
)
@handle_http_errors()
@paginate(PageNumberPagination)
@paginate(CustomPagination)
def list_facilities_by_operation_id(
request: HttpRequest,
operation_id: UUID,
filters: FacilityDesignatedOperationTimelineFilterSchema = Query(...),
sort_field: Optional[str] = "facility__created_at",
sort_order: Optional[Literal["desc", "asc"]] = "desc",
paginate_result: bool = Query(True, description="Whether to paginate the results"),
) -> QuerySet[FacilityDesignatedOperationTimeline]:
# NOTE: PageNumberPagination raises an error if we pass the response as a tuple (like 200, ...)
return FacilityDesignatedOperationTimelineService.list_timeline_by_operation_id(
Expand Down
Empty file.
21 changes: 19 additions & 2 deletions bc_obps/registration/api/v2/transfer_events.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List, Literal, Optional
from typing import List, Literal, Optional, Tuple
from registration.models.event.transfer_event import TransferEvent
from registration.schema.v1.transfer_event import TransferEventFilterSchema, TransferEventListOut
from registration.schema.v2.transfer_event import TransferEventFilterSchema, TransferEventListOut
from service.transfer_event_service import TransferEventService
from common.permissions import authorize
from django.http import HttpRequest
Expand All @@ -13,6 +13,8 @@
from ninja import Query
from registration.schema.generic import Message
from django.db.models import QuerySet
from common.api.utils import get_current_user_guid
from registration.schema.v2.transfer_event import TransferEventCreateIn, TransferEventOut


@router.get(
Expand All @@ -34,3 +36,18 @@ def list_transfer_events(
) -> QuerySet[TransferEvent]:
# NOTE: PageNumberPagination raises an error if we pass the response as a tuple (like 200, ...)
return TransferEventService.list_transfer_events(sort_field, sort_order, filters)


@router.post(
"/transfer-events",
response={201: TransferEventOut, custom_codes_4xx: Message},
tags=TRANSFER_EVENT_TAGS,
description="""Creates a new transfer event.""",
auth=authorize("cas_analyst"),
)
@handle_http_errors()
def create_transfer_event(
request: HttpRequest,
payload: TransferEventCreateIn,
) -> Tuple[Literal[201], TransferEvent]:
return 201, TransferEventService.create_transfer_event(get_current_user_guid(request), payload)
1 change: 1 addition & 0 deletions bc_obps/registration/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
CONTACT_TAGS = ["Contact V1"]
TRANSFER_EVENT_TAGS = ["Transfer Event V1"]
V2 = ["V2"]
OPERATOR_TAGS_V2 = ["Operator V2"]
7 changes: 7 additions & 0 deletions bc_obps/registration/fixtures/mock/operation.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
},
{
"model": "registration.operation",
"pk": "436dd99a-cb41-4494-91c9-98ab149b557d",
"fields": {
"operator": "685d581b-5698-411f-ae00-de1d97334a71",
"documents": [],
Expand All @@ -144,6 +145,7 @@
},
{
"model": "registration.operation",
"pk": "a47b5fb6-1e10-401a-b70e-574bd925db99",
"fields": {
"operator": "685d581b-5698-411f-ae00-de1d97334a71",
"documents": [],
Expand All @@ -163,6 +165,7 @@
},
{
"model": "registration.operation",
"pk": "21e70498-c4b0-4525-8443-86faa96206e3",
"fields": {
"operator": "685d581b-5698-411f-ae00-de1d97334a71",
"documents": [],
Expand All @@ -182,6 +185,7 @@
},
{
"model": "registration.operation",
"pk": "17550cd8-3e73-4e52-aa91-ab90cb3b62b0",
"fields": {
"operator": "685d581b-5698-411f-ae00-de1d97334a71",
"documents": [],
Expand All @@ -201,6 +205,7 @@
},
{
"model": "registration.operation",
"pk": "7d3fc7d1-0504-4ee4-a9c5-447f4b324b57",
"fields": {
"operator": "685d581b-5698-411f-ae00-de1d97334a71",
"documents": [],
Expand All @@ -220,6 +225,7 @@
},
{
"model": "registration.operation",
"pk": "acf5811e-d521-43f7-a5c7-a6d6dd47bb31",
"fields": {
"operator": "685d581b-5698-411f-ae00-de1d97334a71",
"documents": [],
Expand All @@ -239,6 +245,7 @@
},
{
"model": "registration.operation",
"pk": "8563da83-0762-4d29-9b22-da5b52ef0f24",
"fields": {
"operator": "685d581b-5698-411f-ae00-de1d97334a71",
"documents": [],
Expand Down
Loading
Loading