Skip to content

Commit

Permalink
Merge 41ab0f9 into ea400b9
Browse files Browse the repository at this point in the history
  • Loading branch information
nad2000 committed Oct 22, 2019
2 parents ea400b9 + 41ab0f9 commit 0d9606d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
3 changes: 2 additions & 1 deletion orcid_hub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
# disable Sentry if there is no SENTRY_DSN:
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration
from sentry_sdk.integrations.redis import RedisIntegration
from sentry_sdk.integrations.rq import RqIntegration

from . import config
Expand Down Expand Up @@ -213,7 +214,7 @@ def configure_routes(self): # noqa: D102
if SENTRY_DSN:
sentry_sdk.init(
SENTRY_DSN,
integrations=[FlaskIntegration(), RqIntegration()],
integrations=[FlaskIntegration(), RqIntegration(), RedisIntegration()],
debug=app.debug,
environment=app.config.get("ENV"),
send_default_pii=True)
Expand Down
10 changes: 8 additions & 2 deletions orcid_hub/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ class AppResource(Resource):
oauth.require_oauth(),
]

@property
def org(self):
"""Get the organisation the app belongs to."""
return request.oauth.access_token.client.org

def dispatch_request(self, *args, **kwargs):
"""Do some pre-handling and post-handling."""
resp = super().dispatch_request(*args, **kwargs)
Expand Down Expand Up @@ -364,7 +369,8 @@ def handle_affiliation_task(self, task_id=None):
filename=filename,
task_id=task_id,
skip_schema_validation=True,
override=(request.method == "POST"))
override=(request.method == "POST"),
org=self.org)
except Exception as ex:
app.logger.exception("Failed to handle affiliation API request.")
return jsonify({"error": "Unhandled exception occurred.", "exception": str(ex)}), 400
Expand Down Expand Up @@ -910,7 +916,7 @@ def post(self, *args, **kwargs):
description: "User ORCID ID"
"""
if request.content_type in ["text/csv", "text/tsv"]:
task = AffiliationRecord.load_from_csv(request.data.decode("utf-8"), filename=self.filename)
task = AffiliationRecord.load_from_csv(request.data.decode("utf-8"), filename=self.filename, org=self.org)
return self.jsonify_task(task)
return self.handle_affiliation_task()

Expand Down
12 changes: 0 additions & 12 deletions orcid_hub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4295,18 +4295,6 @@ def to_dict(self, *args, **kwargs):
d["invitees"] = [i.to_export_dict() for i in self.invitees]
return d

# class MessageRecordInvitee(BaseModel):
# """Link from a record to an invitee."""

# put_code = IntegerField(null=True)
# record = ForeignKeyField(MessageRecord)
# invitee = ForeignKeyField(Invitee)
# processed_at = DateTimeField(null=True)
# status = TextField(null=True, help_text="Record processing status.")


# ThroughDeferred.set_model(MessageRecordInvitee)


RecordInvitee = MessageRecord.invitees.get_through_model()

Expand Down
3 changes: 3 additions & 0 deletions orcid_hub/queuing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
from flask_rq2 import RQ
import rq_dashboard
from rq import Queue as _Queue
# import redis
# with redis.Redis.from_url(REDIS_URL, socket_connect_timeout=1) as r:
# r.ping()

class ThrottledQueue(_Queue):
"""Queue with throttled deque."""
Expand Down

0 comments on commit 0d9606d

Please sign in to comment.