Skip to content

Commit

Permalink
Merge 055950b into 5e982de
Browse files Browse the repository at this point in the history
  • Loading branch information
rpaw053 committed Oct 21, 2019
2 parents 5e982de + 055950b commit 0234484
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion orcid_hub/models.py
Expand Up @@ -3498,7 +3498,7 @@ class Meta: # noqa: D101,D106
class Invitee(BaseModel):
"""Common model bits of the invitees records."""

identifier = CharField(max_length=120, null=True, verbose_name="Local ID")
identifier = CharField(max_length=120, null=True, verbose_name="Local Identifier")
email = CharField(max_length=120, null=True)
orcid = OrcidIdField(null=True)
first_name = CharField(max_length=120, null=True)
Expand Down
22 changes: 17 additions & 5 deletions orcid_hub/utils.py
Expand Up @@ -525,10 +525,10 @@ def create_or_update_resources(user, org_id, records, *args, **kwargs):
OrcidToken.user_id == user.id, OrcidToken.org_id == org.id,
OrcidToken.scopes.contains("/activities/update")).first()
api = orcid_client.MemberAPIV3(org, user, access_token=token.access_token)
resources = api.get_resources().get("group")
resources = api.get_resources()

if resources:

resources = resources.get("group")
resources = [
r for r in resources if any(
rr.get("source", "source-client-id", "path") == org.orcid_client_id
Expand All @@ -552,7 +552,6 @@ def match_record(records, record):
# if all(eid.get("external-id-value") != record.external_id_value
# for eid in rr.get("proposal", "external-ids", "external-id")):
# continue

if put_code in taken_put_codes:
continue

Expand Down Expand Up @@ -581,11 +580,18 @@ def match_record(records, record):
resp = api.post("research-resource", rr.orcid_research_resource)

if resp.status == 201:
orcid, put_code = resp.headers["Location"].split("/")[-3::2]
rr.add_status_line("ORCID record was created.")
else:
orcid = user.orcid
rr.add_status_line("ORCID record was updated.")
if not put_code:
rr.put_code = resp.headers["Location"].split('/')[-1]
if not rr.put_code and put_code:
rr.put_code = int(put_code)
if not rr.orcid and orcid:
rr.orcid = orcid
visibility = json.loads(resp.data).get("visibility") if hasattr(resp, "data") else None
if rr.visibility != visibility:
rr.visibility = visibility

except ApiException as ex:
if ex.status == 404:
Expand Down Expand Up @@ -2014,6 +2020,7 @@ def process_resource_records(max_rows=20, record_id=None):
tasks = tasks.where(ResourceRecord.id.in_(record_id))
else:
tasks = tasks.where(ResourceRecord.id == record_id)

for (task_id, org_id, user), tasks_by_user in groupby(tasks, lambda t: (
t.id,
t.org_id,
Expand Down Expand Up @@ -2539,6 +2546,11 @@ def enqueue_user_records(user):
records = records.join(WorkInvitee).where(
(WorkInvitee.email.is_null() | (WorkInvitee.email == user.email)),
(WorkInvitee.orcid.is_null() | (WorkInvitee.orcid == user.orcid)))
# TODO: Handle Research Resource json enqueing
# elif task.task_type == TaskType.RESOURCE and hasattr(task.record_model, "invitees"):
# inv = task.record_model.invitees.rel_model
# records = records.where((inv.email.is_null() | (inv.email == user.email)),
# (inv.orcid.is_null() | (inv.orcid == user.orcid)))
else:
records = records.where(
(task.record_model.email.is_null() | (task.record_model.email == user.email)),
Expand Down
4 changes: 1 addition & 3 deletions orcid_hub/views.py
Expand Up @@ -803,7 +803,7 @@ def action_activate(self, ids):
try:
status = "The record was activated at " + datetime.now().isoformat(timespec="seconds")
count = self.model.update(is_active=True, status=status).where(
self.model.is_active == False, # noqa: E712
((self.model.is_active.is_null()) | (self.model.is_active == False)), # noqa: E712
self.model.id.in_(ids)).execute()
if self.model == AffiliationRecord:
records = self.model.select().where(self.model.id.in_(ids)).order_by(
Expand Down Expand Up @@ -2045,8 +2045,6 @@ def action_insert_update(self, ids):
class ResourceRecordAdmin(RecordModelView):
"""Researcher resource administration view."""

# column_labels = dict(identifier="Local ID")

form_rules = [
# rules.Header("Record"),
"local_id",
Expand Down

0 comments on commit 0234484

Please sign in to comment.