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

Feature my annotations #391

Merged
merged 13 commits into from
Dec 14, 2020
Merged

Conversation

alexhuang091
Copy link
Contributor

@alexhuang091 alexhuang091 commented Nov 26, 2020

this feature requires to add a checkbox in the 'flag an issue' dialog to enable/disable notifications about this annotation. AtlasOfLivingAustralia/DataQuality#204

  • We need to get current alert settings, if any alert on for 'my annotation', check the box

  • When the user submit the issue, check the status of the checkbox, subscribe/unsubscribe to 'my annotation' alert.

Since subscribe/unsubscribe need queryid of 'my annotation' and the id is database generated and could be different on different machines. Among all returned queries, I'll check query name one by one until we find a query with the desired name (which is configurable in config file, now it's 'My Annotation') and thus use its id.

Copy link
Contributor

@ansell ansell left a comment

Choose a reason for hiding this comment

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

Some issues, including exposing an API key in Github that I have revoked. Still needs approval and review from someone else.

grails-app/conf/plugin.groovy Outdated Show resolved Hide resolved
grails-app/conf/plugin.groovy Outdated Show resolved Hide resolved
@nickdos
Copy link
Contributor

nickdos commented Nov 26, 2020

Is there a related issue on DQ project for this PR?

@nickdos nickdos self-requested a review November 26, 2020 23:44
@alexhuang091
Copy link
Contributor Author

Is there a related issue on DQ project for this PR?

Hi Nik, AtlasOfLivingAustralia/DataQuality#204

@alexhuang091 alexhuang091 marked this pull request as draft November 27, 2020 06:30
@alexhuang091 alexhuang091 marked this pull request as ready for review November 29, 2020 22:05
@alexhuang091 alexhuang091 requested a review from ansell November 29, 2020 22:18
if (orig_state !== new_state) {
// to add alerts
if (new_state) {
$.post(OCC_REC.alertsURL + "/occurrences/addAlert?queryId=" + myAnnotationQueryId);
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove this OCC_REC property and use OCC_REC.contextPath like the other AJAX calls in show.js

Copy link
Contributor

@nickdos nickdos Dec 11, 2020

Choose a reason for hiding this comment

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

From memory, isn't OCC_REC.contextPath just the /ala-hub bit? So won't it just point to the running host (https://biocache.ala.org.au in the case of prod)? But this URL is supposed to go to https://alerts.ala.org.au ??

Copy link
Contributor

@nickdos nickdos Dec 11, 2020

Choose a reason for hiding this comment

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

OK, I hadn't got down to the code below in OccurrenceController class - so it is local.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

var myAnnotationQueryId = null

$('#assertionButton').click(function (e) {
var getAlerts = OCC_REC.alertsURL + "/occurrences/alerts";
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto above comment about OCC_REC.contextPath

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -59,7 +59,9 @@
status="s">'${sds}': '${grailsApplication.config.sensitiveDatasets[sds]}'${s < (sensitiveDatasets.size() - 1) ? ',' : ''}
</g:each>
},
hasGoogleKey: ${grailsApplication.config.google.apikey as Boolean}
hasGoogleKey: ${grailsApplication.config.google.apikey as Boolean},
alertsURL: "${grailsApplication.config.grails.serverURL}",
Copy link
Contributor

Choose a reason for hiding this comment

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

As above, remove this and use OCC_REC.contextPath

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

Just FYI for next time (think I've said this before) - preferred way to write ${grailsApplication.config.google.apikey as Boolean} is use ${grailsApplication.config.getProperty('google.apikey', Boolean, false)} as it handles NPE for missing keys, type casting and default values.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed - but Alex didn't add the hasGoogleKey line, that was already here, he just added the comma to add to the JS config object

Copy link
Contributor

Choose a reason for hiding this comment

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

missed that - I stand corrected 👍


$('#assertionButton').click(function (e) {
var getAlerts = OCC_REC.alertsURL + "/occurrences/alerts";
var myAnnotationEnabled = false
Copy link
Contributor

Choose a reason for hiding this comment

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

This variable can be moved inside the .getJSON

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


def getAlerts() {
String userId = authService?.getUserId()
render ((userId == null) ? [error: 'userId must be supplied to get alerts'] : webServicesService.getAlerts(userId)) as JSON
Copy link
Contributor

Choose a reason for hiding this comment

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

Error responses should have a non 200 series HTTP status code.

These error maps aren't checked for in the JS that calls them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved.

In JS the checkbox is initially hidden now. So only when call is successful will show it.

@@ -127,6 +127,21 @@ $(document).ready(function() {
if(code!=""){
$('#assertionSubmitProgress').css({'display':'block'});

if (myAnnotationQueryId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should you add / remove alerts even if the form submit is invalid? What if the assertion add fails?

If the add / delete Alert works, shouldn't you update $('#notifyChangeCheckbox').prop('data-origstate') in case the form is resubmitted after a validation error, otherwise you might have a duplicate add / delete call?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

add/delete alert is now moved into success callback of add assertion. So only when an assertion is added successfully an add/delete will be called.


def addAlert(String userId, String queryId) {
def url = "${grailsApplication.config.alerts.baseURL}" + "/api/alerts/user/" + userId + "/subscribe/" + queryId
getJsonElements(url, "${grailsApplication.config.alerts.apiKey}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Add / delete should use POST HTTP verbs instead of GET

Copy link
Contributor

Choose a reason for hiding this comment

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

Are these calls new? May need to update the alerts side to only allow POST unless there's existing code calling them with GET

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to use POST to send the add/delete.

But I didn't create a new function for POST, just reused the postFormData with empty data supplied.

@sbearcsiro sbearcsiro merged commit df1e332 into feature/data-quality Dec 14, 2020
@sbearcsiro sbearcsiro deleted the feature_my_annotations branch December 14, 2020 23:49
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.

4 participants