-
Notifications
You must be signed in to change notification settings - Fork 1
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
Replace operation rep #2679
Replace operation rep #2679
Conversation
@@ -198,6 +199,22 @@ def create_or_update_operation_v2( | |||
|
|||
# set m2m relationships | |||
operation.activities.set(payload.activities) | |||
if isinstance(payload, OperationInformationInUpdate): |
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 (vs if payload.operation_representatives) was to make mypy happy
@@ -330,12 +347,6 @@ def update_operation( | |||
payload, | |||
operation_id, | |||
) | |||
|
|||
if payload.regulated_products: |
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 is already handled in create_or_update_operation_v2
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.
Also, good catch, Thanks! 🙏
At some point, we might need to refactor create_or_update_operation_v2
service because it has many responsibilities.
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.
I was thinking this too--in other places in the app we have separate create and update functions
fb07630
to
8583b84
Compare
@@ -162,7 +190,7 @@ const formData = { | |||
naics_code_id: 1, | |||
secondary_naics_code_id: 2, | |||
operation_has_multiple_operators: true, | |||
activities: [1, 2, 3, 4, 5], | |||
activities: [1, 2], |
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.
We only mocked two activities
8583b84
to
444fbe4
Compare
5af0462
to
5bda3dc
Compare
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 is dope! 🔥 I’ve left a few small suggestions, but nothing major.
class PlacesAssigned(Schema): | ||
role_name: str | ||
operation_name: str | ||
operation_id: UUID | ||
|
||
|
||
class ContactWithPlacesAssigned(ContactOut): | ||
places_assigned: Optional[list[PlacesAssigned]] |
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.
Can we move these schemas into the schema file?
@classmethod | ||
def get_if_authorized_v2(cls, user_guid: UUID, contact_id: int) -> Optional[Contact]: | ||
user = UserDataAccessService.get_by_guid(user_guid) | ||
user_contacts = ContactDataAccessService.get_all_contacts_for_user(user) | ||
contact = user_contacts.filter(id=contact_id).first() | ||
if user.is_industry_user() and not contact: | ||
raise Exception(UNAUTHORIZED_MESSAGE) | ||
return contact |
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.
I know this is the second version of a method I wrote earlier (which was never used lol). However, I'm struggling to grasp its purpose. Since we’re already retrieving all the contacts associated with the user’s operator, why do we need to check if the user is an industry user and if there’s no associated contact, why do we raise UNAUTHORIZED_MESSAGE
? 🤔
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.
Uh... good question. Maybe it was something about how reg1 had senior officers as part of the operator approval? I'll nix it for v2
@@ -23,7 +24,7 @@ | |||
) | |||
@handle_http_errors() | |||
def get_contact(request: HttpRequest, contact_id: int) -> Tuple[Literal[200], Optional[ContactWithPlacesAssigned]]: | |||
return 200, ContactService.get_with_places_assigned(get_current_user_guid(request), contact_id) | |||
return 200, ContactServiceV2.get_with_places_assigned_v2(get_current_user_guid(request), contact_id) |
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 use ContactWithPlacesAssigned
as the schema for the response? (line 18)
( | ||
Q(bc_obps_regulated_operation__id__icontains=bc_obps_regulated_operation) | ||
if bc_obps_regulated_operation | ||
else Q() | ||
), |
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.
Is this just a formatting change? 🤔
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.
Yes, prettier put it in
<Note variant="important"> | ||
To remove the current operation representative, please select a new | ||
contact to replace them. | ||
</Note> |
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.
Do we need to show this message to internal users too?
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.
Nope, thanks for catching
if (response.error.includes("Please return to Contacts")) { | ||
const splitError = response.error.split("Contacts"); | ||
response.error = ( | ||
<> | ||
{splitError[0]} <Link href={"/contacts"}>Contacts</Link> | ||
{splitError[1]} | ||
</> | ||
); | ||
} |
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.
nit: I think adding a comment here could be helpful.
const regulatedProducts: { id: number; name: string }[] = | ||
await getRegulatedProducts(); | ||
|
||
const contacts: { | ||
items: [{ id: number; first_name: string; last_name: string }]; | ||
} = await getContacts(); |
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.
We could use error-handling logic here! Just in case fetching data fails for regulatedProducts
or contacts
.
vi.mock("libs/actions/src/api/getContacts", () => ({ | ||
default: getContacts, | ||
})); |
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.
nit: Would it be better to move this to the contacts/mocks
folder?
return ( | ||
<div className="flex min-w-full flex-col"> | ||
{items?.map((item) => { | ||
const formData = item.children.props.formData; |
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.
nit: const { role_name, operation_name, operation_id } = item.children.props.formData;
'status', | ||
'activities', | ||
'opted_in_operation', | ||
'contacts', |
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.
Do we need contacts
here?!
5bda3dc
to
d017894
Compare
@@ -194,7 +194,7 @@ class Meta: | |||
'status', | |||
'activities', | |||
'opted_in_operation', | |||
'contacts', | |||
# 'contacts', |
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.
leftover!
def get_by_id(cls, contact_id: int) -> Contact: | ||
return Contact.objects.get(id=contact_id) |
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.
We already have this in ContactDataAccessService
.
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.
🤦
41e2957
to
5d79839
Compare
https://github.com/orgs/bcgov/projects/123/views/16?pane=issue&itemId=88758186&issue=bcgov%7Ccas-registration%7C2524
Notes: