Skip to content
Permalink
Browse files

Merge branch 'ORCIDHUB-402' of github.com:Royal-Society-of-New-Zealan…

…d/NZ-ORCID-Hub into ORCIDHUB-402
  • Loading branch information...
nad2000 committed Sep 12, 2019
2 parents cd16aa1 + 859c16a commit e9a380d58178b848fb02322df34c70afc25fae2b
@@ -6,7 +6,7 @@
No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501
OpenAPI spec version: Latest
Generated by: https://github.com/swagger-api/swagger-codegen.git
"""

@@ -52,10 +52,14 @@ def __init__(self, name=None, group_id=None, description=None, type=None, put_co
self._type = None
self._put_code = None
self.discriminator = None
self.name = name
self.group_id = group_id
self.description = description
self.type = type
if name is not None:
self.name = name
if group_id is not None:
self.group_id = group_id
if description is not None:
self.description = description
if type is not None:
self.type = type
if put_code is not None:
self.put_code = put_code

@@ -380,7 +380,8 @@ def __init__(self, *args, form_type=None, **kwargs):
class GroupIdForm(FlaskForm):
"""GroupID record form."""

group_id_name = StringField("Group ID Name", [validators.required()])
group_id = StringField("Group ID")
name = StringField("Name")
page_size = StringField("Page Size")
page = StringField("Page")
search = SubmitField("Search", render_kw={"class": "btn btn-primary"})
@@ -1410,9 +1410,9 @@ class GroupIdRecord(RecordModel):
" a publisher (Society of Criminal Justice), or non-specific description (Legal Journal)"
" as required.")
group_id = CharField(max_length=120,
help_text="The group's identifier, formatted as type:identifier, e.g. issn:12345678. "
help_text="The group's identifier, formatted as type:identifier, e.g. ringgold:12345678. "
"This can be as specific (e.g. the journal's ISSN) or vague as required. "
"Valid types include: issn, ringold, orcid-generated, fundref, publons.")
"Valid types include: ringgold:|issn:|orcid-generated:|fundref:|publons:")
description = CharField(max_length=1000,
help_text="A brief textual description of the group. "
"This can be as specific or vague as required.")
@@ -220,7 +220,7 @@ def is_emp_or_edu_record_present(self, affiliation_type):
def create_or_update_record_id_group(self, org=None, group_name=None, group_id=None, description=None,
type=None, put_code=None):
"""Create or update group id record."""
rec = GroupIdRecord() # noqa: F405
rec = v3.GroupIdRecord() # noqa: F405

rec.name = group_name
rec.group_id = group_id
@@ -230,7 +230,7 @@ def create_or_update_record_id_group(self, org=None, group_name=None, group_id=N
rec.put_code = put_code

try:
api_call = self.update_group_id_record if put_code else self.create_group_id_record
api_call = self.update_group_id_recordv3 if put_code else self.create_group_id_recordv3

params = dict(body=rec, _preload_content=False)
if put_code:
@@ -10,10 +10,11 @@ <h1>{{"Search GroupID Records"}}</h1>
</div>
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-12">
{{ render_field(form.group_id_name) }}
{{ render_field(form.name) }}
{{ render_field(form.page_size) }}
</div>
<div class="col-md-6 col-sm-6 col-xs-12">
{{ render_field(form.group_id) }}
{{ render_field(form.page) }}
<br>
<span class="pull-right" style="padding-bottom: 40px;">
@@ -50,8 +51,8 @@ <h1>{{"Search GroupID Records"}}</h1>
{% if r.get("group-id") %}
<td class="list-buttons-column" align="center">
<form class="icon" method="POST" action="{{url_for('search_group_id_record')}}">
<input id="name" name="name" type="hidden" value="{{r.get('name')}}">
<input id="group_id" name="group_id" type="hidden" value="{{r.get('group-id')}}">
<input id="g_name" name="g_name" type="hidden" value="{{r.get('name')}}">
<input id="g_id" name="g_id" type="hidden" value="{{r.get('group-id')}}">
<input id="description" name="description" type="hidden" value="{{r.get('description')}}">
<input id="type" name="type" type="hidden" value="{{r.get('type')}}">
<input id="put_code" name="put_code" type="hidden" value="{{r.get('put-code')}}">
@@ -2039,7 +2039,7 @@ def get_client_credentials_token(org, scopes="/webhook"):
client_secret=org.orcid_secret,
scope=scopes,
grant_type="client_credentials"))
OrcidToken.delete().where(OrcidToken.org == org, OrcidToken.scopes == "/webhook").execute()
OrcidToken.delete().where(OrcidToken.org == org, OrcidToken.scopes == scopes).execute()
data = resp.json()
token = OrcidToken.create(
org=org,
@@ -1937,14 +1937,13 @@ def action_insert_update(self, ids):
try:
orcid_token = OrcidToken.get(org=org, scopes='/group-id-record/update')
except OrcidToken.DoesNotExist:
orcid_token = utils.get_client_credentials_token(org=org, scope="/group-id-record/update")
orcid_token = utils.get_client_credentials_token(org=org, scopes="/group-id-record/update")
except Exception as ex:
flash("Something went wrong in ORCID call, "
"please contact orcid@royalsociety.org.nz for support", "warning")
app.logger.exception(f'Exception occured {ex}')

orcid_client.configuration.access_token = orcid_token.access_token
api = orcid_client.MemberAPI(org=org, access_token=orcid_token.access_token)
api = orcid_client.MemberAPIV3(org=org, access_token=orcid_token.access_token)

put_code, created = api.create_or_update_record_id_group(put_code=gid.put_code,
org=org, group_name=gid.name,
@@ -2714,8 +2713,8 @@ def search_group_id_record():
form.process(data=data)

if request.method == "POST" and not form.search.data:
group_id = request.form.get('group_id')
name = request.form.get('name')
group_id = request.form.get('g_id')
name = request.form.get('g_name')
description = request.form.get('description')
id_type = request.form.get('type')
put_code = request.form.get('put_code')
@@ -2742,26 +2741,20 @@ def search_group_id_record():
return redirect(_url)
elif form.validate_on_submit():
try:
group_id_name = form.group_id_name.data
page_size = form.page_size.data
page = form.page.data

orcid_token = None
org = current_user.organisation
try:
orcid_token = OrcidToken.get(org=org, scope='/group-id-record/read')
orcid_token = OrcidToken.get(org=org, scopes='/group-id-record/read')
except OrcidToken.DoesNotExist:
orcid_token = utils.get_client_credentials_token(org=org, scope="/group-id-record/read")
orcid_token = utils.get_client_credentials_token(org=org, scopes="/group-id-record/read")
except Exception as ex:
flash("Something went wrong in ORCID call, "
"please contact orcid@royalsociety.org.nz for support", "warning")
app.logger.exception(f'Exception occured {ex}')

orcid_client.configuration.access_token = orcid_token.access_token
api = orcid_client.MemberAPI(org=org, access_token=orcid_token.access_token)

api_response = api.view_group_id_records(page_size=page_size, page=page, name=group_id_name,
_preload_content=False)
api = orcid_client.MemberAPIV3(org=org, access_token=orcid_token.access_token)
params = {f.name: f.data for f in form if f.data and f.name in ['group_id', 'name', 'page_size', 'page']}
api_response = api.view_group_id_recordsv3(**params, _preload_content=False)
if api_response:
data = json.loads(api_response.data)
# Currently the api only gives correct response for one entry otherwise it throws 500 exception.
@@ -2749,8 +2749,8 @@ def test_action_insert_update_group_id(mocker, client):
client.login(admin)

with patch.object(
orcid_client.MemberAPIV20Api,
"create_group_id_record",
orcid_client.MemberAPIV3,
"create_group_id_recordv3",
MagicMock(return_value=fake_response)):

resp = client.post(
@@ -2766,28 +2766,28 @@ def test_action_insert_update_group_id(mocker, client):
# checking if the GroupID Record is updated with put_code supplied from fake response
assert 12399 == group_id_record.put_code
# Save selected groupid record into existing group id record list.
with patch.object(orcid_client.MemberAPIV20Api, "view_group_id_records",
with patch.object(orcid_client.MemberAPIV3, "view_group_id_recordsv3",
MagicMock(return_value=fake_response)):
client.login(admin)
resp = client.post(
"/search/group_id_record/list",
data={
"group_id": "test",
"name": "test",
"g_id": "test",
"g_name": "test",
"description": "TEST",
"type": "TEST"
})
assert resp.status_code == 302
assert urlparse(resp.location).path == "/admin/groupidrecord/"
# Search the group id record from ORCID
with patch.object(orcid_client.MemberAPIV20Api, "view_group_id_records",
with patch.object(orcid_client.MemberAPIV3, "view_group_id_recordsv3",
MagicMock(return_value=fake_response)):
client.login(admin)
resp = client.post(
"/search/group_id_record/list",
data={
"group_id": "test",
"group_id_name": "test",
"name": "test",
"description": "TEST",
"search": True,
"type": "TEST"

0 comments on commit e9a380d

Please sign in to comment.
You can’t perform that action at this time.