Skip to content

Commit

Permalink
Merge pull request #1258 from Royal-Society-of-New-Zealand/issue-1256
Browse files Browse the repository at this point in the history
Issue 1256
  • Loading branch information
nad2000 committed Dec 3, 2019
2 parents b7f1ad7 + ddf7f2c commit 30e7a6d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 7 additions & 4 deletions orcid_hub/utils.py
Expand Up @@ -2337,13 +2337,13 @@ def notify_about_update(user, event_type="UPDATED"):


@rq.job(timeout=300)
def invoke_webhook_handler(org_id,
def invoke_webhook_handler(org_id=None,
orcid=None,
created_at=None,
updated_at=None,
message=None,
event_type="UPDATED",
attempts=5):
attempts=5, *args, **kwargs):
"""Propagate 'updated' event to the organisation event handler URL."""
if not message:
url = app.config["ORCID_BASE_URL"] + orcid
Expand All @@ -2364,8 +2364,11 @@ def invoke_webhook_handler(org_id,
message["email"] = user.email
if user.eppn:
message["eppn"] = user.eppn

org = Organisation.get(id=org_id)
if org_id:
org = Organisation.get(id=org_id)
else:
org = User.select().where(User.orcid == orcid).first().organisation
org_id = org.id
url = org.webhook_url
if org.webhook_append_orcid:
if not url.endswith('/'):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_webhooks.py
Expand Up @@ -386,6 +386,10 @@ def test_webhook_invokation(client, mocker):
with pytest.raises(Exception):
utils.invoke_webhook_handler(org.id, attempts=1, message=message)

# Test backward compatibility
with pytest.raises(Exception):
utils.invoke_webhook_handler(orcid=user.orcid, attempts=2, message=message, legacy_kwarg="abc123")


def test_org_webhook_api(client, mocker):
"""Test Organisation webhooks."""
Expand Down

0 comments on commit 30e7a6d

Please sign in to comment.