-
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
LTD: Add endpoint for licences list #2235
base: dev
Are you sure you want to change the base?
Conversation
2b17507
to
50ee250
Compare
api/data_workspace/v2/serializers.py
Outdated
name = serializers.CharField(source="*") | ||
|
||
|
||
class SIELLicenceSerializer(serializers.ModelSerializer): |
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.
Let’s just call this Licence for now.
api/data_workspace/v2/serializers.py
Outdated
from api.licences.models import Licence | ||
|
||
|
||
class LicenceStatusSerializer(serializers.Serializer): |
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.
Let’s not include status in this first prototype.
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.
part of cherry-picked commit, will remove
Then there are no other licence statuses | ||
|
||
|
||
Scenario: Issued licence is included in the extract |
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 have this in a separate BDD scenario file? I’d like it if each endpoint had its own scenario file.
api/data_workspace/v2/views.py
Outdated
serializer_class = SIELLicenceSerializer | ||
|
||
def get_queryset(self): | ||
return Licence.objects.exclude(status=LicenceStatus.DRAFT) |
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.
It would be good to see a test for this somewhere. Possibly as a distinct scenario in the BDD file for the endpoint.
b92307d
to
ce7cbf9
Compare
def unpage_data(client): | ||
def _unpage_data(url): | ||
unpaged_results = [] | ||
while True: |
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 works fine and looks great, although I am surprised there's not a way of doing this using the existing libraries we have
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.
everything looks good to me, happy to approve
this will be a long lived branch so does not make sense to approve now
Scenario: Check that draft licences are not included in the extract | ||
Given a standard draft licence is created | ||
Then the draft licence is not included in the extract | ||
|
||
Scenario: Issued licence is included in the extract | ||
Given a standard licence is issued | ||
Then the issued licence is included in the extract |
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 feel that it might be nice to have at test that shows that a licence transitioning from draft to issued makes a difference.
api/data_workspace/v2/views.py
Outdated
# When an application with all goods as NLR is finalised then the current code | ||
# creates a licence however the goods on this licence will be empty. This | ||
# will skew licence data hence exclude them |
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.
A BDD test describing this NLR case would be nice to see.
api/data_workspace/v2/views.py
Outdated
LicenceStatus.DRAFT, | ||
LicenceStatus.CANCELLED, |
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.
Could we extract these statuses out into a named thing? For CaseStatus we have a range of named lists so I think it would be good to do the same here.
api/data_workspace/v2/views.py
Outdated
case__status__status__in=[ | ||
CaseStatusEnum.FINALISED, | ||
CaseStatusEnum.SUPERSEDED_BY_EXPORTER_EDIT, | ||
], |
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.
Could we come up with a named list for these statuses?
91490ec
to
d49fc4a
Compare
api/data_workspace/v2/views.py
Outdated
Case.objects.filter( | ||
licences__generatedcasedocument__template_id=SIEL_TEMPLATE_ID, | ||
licences__generatedcasedocument__visible_to_exporter=True, | ||
licences__generatedcasedocument__safe=True, |
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 an extra precaution? the document is generated internally so I wouldn't think this would ever not be safe=True ?
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.
safe=True
indicates no virus found
api/data_workspace/v2/views.py
Outdated
issued_qs = Case.objects.filter( | ||
licences__generatedcasedocument__template_id=SIEL_TEMPLATE_ID, | ||
licences__generatedcasedocument__visible_to_exporter=True, | ||
licences__generatedcasedocument__safe=True, | ||
) | ||
refused_qs = Case.objects.filter( | ||
id__in=GeneratedCaseDocument.objects.filter( | ||
template_id=SIEL_REFUSAL_TEMPLATE_ID, | ||
visible_to_exporter=True, | ||
safe=True, | ||
).values_list("case", flat=True) | ||
) | ||
|
||
queryset = (issued_qs | refused_qs).distinct().order_by("-reference_code") |
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.
Isn't this just a very long-winded way to do the same thing as
Case.objects.filter(
licences__generatedcasedocument__template_id__in=[SIEL_TEMPLATE_ID, SIEL_REFUSAL_TEMPLATE_ID],
licences__generatedcasedocument__visible_to_exporter=True,
licences__generatedcasedocument__safe=True,
).distinct()
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.
Actually no because there won't be a licence for refused cases.
That was the initial change and as expected refusal cases were not filtered.
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.
Are both generated documents attached to the case and we could just skip the licences__
bit entirely for both?
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.
It would also be good to have some joined up thinking based on https://github.com/uktrade/lite-api/pull/2254/files#r1819089904 as it looks like we are diverging slightly with this particular heuristic and the future implementation.
api/data_workspace/v2/serializers.py
Outdated
) | ||
|
||
def get_decision(self, case): | ||
if case.licences.count(): |
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 name this in a way that clarifies what the case.licences.count()
is doing and why it's important.
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.
You mean just by adding a comment or annotate to a field and use that?
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.
Whichever lets me know exactly why the case.licences.count
matters.
api/data_workspace/v2/serializers.py
Outdated
return LicenceDecisionType.ISSUED | ||
else: | ||
return LicenceDecisionType.REFUSED |
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 looks like it's mutually exclusive, but is it possible that something has been issued and then refused or vice versa?
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 checked that, currently there are no such cases.
Because of amendments it is not possible going forward also but there is a possibility with Appeals.
- remove licence statuses endpoint for now - make tests work
Licence document generation date is taken for this purpose.
When all products on the application are NLR then the current code allowed creation of a licence due a bug. This is not fixed yet so exclude these cases as it can skew licence data.
In some case a licence is issued but subsequently application is marked as withdrawn. Licence also should've been cancelled in this case but we are not handling this atm so filter these cases.
As there can be multiple documents in these cases
Use Case as base object and use it to filter on the licence documents. This avoids filtering of various case statuses, NLR products etc
Use the refusal letter generated date as the decision date
c6737dd
to
55c8493
Compare
Aim
LTD-