-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
Cs/sc 3360 support road network algorithm #34024
Conversation
Add api key to GeoConfig model and form Add test api key button Store api_token encrypted
Add model tests
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.
Looks good, just a few minor comments.
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.
Quick question @Charl1996,
why are we putting this behind a new feature flag? Can't we simply include it in the feature itself.
If its new, can we simply add "(unstable)" or something similar in the name in the dropdown when user is selecting it to let them know it is still in development.
Since we already have a feature flag for GEOSPATIAL, this is anyway being used by known projects.
The reason is simply because there's additional costs and considerations involved when using this algorithm. I suppose we don't have to. Let met check with Mary. |
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.
Thanks for all the effort on this @Charl1996, looks good!
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.
Thanks for the follow up on using the plaintext property @Charl1996
Appreciate the flexibility.
I assume this has not been deployed on any environment so can we simply club the migrations to keep only one final migration.
corehq/apps/geospatial/models.py
Outdated
else: | ||
self._api_token = None | ||
self.api_token = None |
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 am thinking that this else block is implicitly resetting the api_token.
I would think that this function would encrypt and store the value and if it is not able to should it
- do nothing
- raise an error
I would prefer 2. More specifically:
if value is None:
self.api_token = None
elif value and not value.startswith(f'${ALGO_AES}$'):
# encrypt and store
else:
raise Exception("Unexpected value received for plaintext api token")
Let me know what you think.
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 see what you're meaning and I concur. I'll update!
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.
The setter now also handles the case where you set a non-string value, say, 1234
. You also can't set an empty api_token. The token can only ever be either
- A string value (not empty)
- null
corehq/apps/geospatial/forms.py
Outdated
choices = self.fields['selected_disbursement_algorithm'].choices | ||
choices.append(self.ROAD_NETWORK_ALGORITHM_OPTION) | ||
self.fields['selected_disbursement_algorithm'].choices = choices | ||
|
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.
Nice!
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.
looks like the PR description is still referring to this and needs to be updated.
corehq/apps/geospatial/models.py
Outdated
self.api_token = f'${ALGO_AES}${ciphertext}' | ||
else: | ||
raise Exception("Unexpected value set for plaintext api token") | ||
except AttributeError: |
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.
Thanks for the improvement @Charl1996
Can you share what will raise the exception AttributeError
?
Additionally, possible to keep the two messages different? If one gets an error, it wont be clear where it came from.
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.
When raising exceptions its nice to be explicit what code would raise the exception. It's not clear to me here what will raise the exception AttributeError
, though if only the necessary code is kept in the try block, its easier to locate.
Closing in favour of #34081 (cleaned up the commits a bit). |
Product Description
Demo video
The disbursement algorithm, "Road Network Algorithm", makes use of the Mapbox Matrix API. This PR adds the ability for a project to add their own mapbox token on the Geospatial Settings page.
Once the FF is enabled for a project, the new disbursement algorithm will appear on the Geospatial Settings page. Once the algorithm is selected, two new HTML elements will appear on the screen:
Note that the user don't have to click the "Test API Key" button in order to save the token; the button exists purely to test the token.
Technical Summary
Ticket
Noteworthy items:
Feature Flag
New FF:
SUPPORT_ROAD_NETWORK_DISBURSEMENT_ALGORITHM
Safety Assurance
Safety story
Tested this feature on my local machine.
Automated test coverage
QA Plan
QA planned
Migrations
Rollback instructions
Labels & Review