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

Lruzicki/draft #7

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Lruzicki/draft #7

wants to merge 5 commits into from

Conversation

lruzicki
Copy link
Collaborator

This is draft branch that will be deleted. It was created to show flow for implementing one endpoint.

Description:

  • middleware that checks Information-Mediator-Client is added
  • views: serialize data, execute controller, edit response
  • controller: takes validated data and executes services
  • services: implement business logic

@lruzicki lruzicki marked this pull request as draft July 13, 2023 09:23
Copy link

@dborowiecki dborowiecki left a comment

Choose a reason for hiding this comment

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

I left some general comments but I think that we need to put more focus in designing general use mapper as well as it's specific variation for the digital registries bb. it should make our work easier in future as well as avoid code repetition in the future.

@@ -4,3 +4,21 @@
class TestHarnessApiConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'govstack_test_harness_api'

IM_CLIENT = 'eGovStack/GOV/90000009/digitalregistries'

Choose a reason for hiding this comment

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

Ideally this shouldn't be hardcoded in apps.py, but rather pulled from env. Leaviing this piece of code seems to be a security risk.


IM_CLIENT = 'eGovStack/GOV/90000009/digitalregistries'

digital_registry = {

Choose a reason for hiding this comment

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

Yo can consider adding some schema for the BB definition (e.g. as Pydantic dataclass). Different BBs could have different requirements. For the digital registries it's valid to have registryname and versionnumber but for other it could be different.

Comment on lines +16 to +23
"registryname": {
"111": {
'ID': 'chfId',
'FirstName': 'otherNames',
'LastName': 'lastName',
'BirthCertificateID': 'json_ext'
}
}

Choose a reason for hiding this comment

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

As for the mapping - have you considered classes that would be loaded instead of JSON definition? Classes could be determined through config (e.g. mapper class "govvstack_test_harness_api.mappers.DigitalRegistry") could be added as a config and then this actual piece of code would be loaded. It does make sense as plenty of entries will not be simple key-value and should be determined throguh some logic (as in the Post Partum we have mother-child-father relation, adressed in IMIS through the family relations with the head of family).

Comment on lines +1 to +2
from ..services.record_exists_service import RecordExistsService
from ..services.services import get_query_content_values, login_with_env_variables

Choose a reason for hiding this comment

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

Change imports to absolute

Comment on lines +12 to +16
def __init__(self, jwt_token, context, validated_data):
self.context = context
self.validated_data = validated_data
# self.headers = {"Authorization": "Bearer " + jwt_token}
self.client = GrapheneClient()

Choose a reason for hiding this comment

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

I don't see jwt_token argument to be used anywhere. Also jwt_token is a specific attribute that wouldn't be used inside of application oftern (it is generated/stored/used mostly during the in the django auth, and shouldn't be mixed in business logic.

Comment on lines +71 to +78
def get_update_fields(write_values) -> str:
field_mapping = {
"LastName": "lastName",
"FirstName": "otherNames"
}
return "".join(f'{field_mapping[key]}: "{value}" '
for key, value in write_values.items()
if value and key in field_mapping)

Choose a reason for hiding this comment

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

This function also seems to be quite specific for the insuree and I don't fully understand what's it's purpose. Can you add some inline explanation and also wrap everything related to the digital-registry fetching under single class (or module if class would be hundred lines long).

if value and key in field_mapping)


def login_with_env_variables(request):

Choose a reason for hiding this comment

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

I think that this functionality should be under graphql client.

Comment on lines +3 to +8
from ..serializers.record_exists_serializer import RecordExistsSerializer
from drf_yasg.utils import swagger_auto_schema
from .swaggers_schema import exists_request_body, exists_response_body
from ..swaggers_schema import info_mediator_client
from ..services.services import login_with_env_variables
from ..controllers.record_exists_controller import check_if_record_exists

Choose a reason for hiding this comment

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

Please replace relative imports with absolute ones.
If you're using PyCharm IDE it can be set as an default in settings.

)
return JsonResponse(response_data)
else:
return JsonResponse(serializer.errors, status=400)

Choose a reason for hiding this comment

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

You can consider raising request execptions in the validator. It will give more flexibility 400 is quite general and perhaps we could be more specific with 401, 403, 404 and so on.



urlpatterns = [
path('data/<str:registryname>/<str:versionnumber>/exists', check_if_record_exists_in_registry)

Choose a reason for hiding this comment

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

can you also add name to the url? (django doc)

@sonarcloud
Copy link

sonarcloud bot commented Jul 28, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot E 1 Security Hotspot
Code Smell A 6 Code Smells

No Coverage information No Coverage information
55.2% 55.2% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants