Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SampleService.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion SampleService.spec
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ module SampleService {
The user must have read permissions to the workspace data.
*/
funcdef get_data_links_from_data(GetDataLinksFromDataParams params)
returns(GetDataLinksFromDataResults results) authentication required;
returns(GetDataLinksFromDataResults results) authentication optional;

/* get_sample_via_data parameters.

Expand Down
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* cache known good users
* cache user roles
* support anonymous users
* get links from data
* get sample via data
* remove self from acls (read/write)
* change sample owner
Expand Down
6 changes: 3 additions & 3 deletions lib/SampleService/SampleServiceImpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SampleService:
######################################### noqa
VERSION = "0.1.0-alpha18"
GIT_URL = "https://github.com/mrcreosote/sample_service.git"
GIT_COMMIT_HASH = "dc5bc302aea67790951dacca3df989fc25017ed5"
GIT_COMMIT_HASH = "85b101160fee573bac94636d9829c61683f5a654"

#BEGIN_CLASS_HEADER
#END_CLASS_HEADER
Expand Down Expand Up @@ -622,11 +622,11 @@ def get_data_links_from_data(self, ctx, params):
upa = _get_upa_from_object(params)
dt = _get_datetime_from_epochmillseconds_in_object(params, 'effective_time')
admin = _check_admin(
self._user_lookup, ctx[_CTX_TOKEN], _AdminPermission.READ,
self._user_lookup, ctx.get(_CTX_TOKEN), _AdminPermission.READ,
# pretty annoying to test ctx.log_info is working, do it manually
'get_data_links_from_data', ctx.log_info, skip_check=not params.get('as_admin'))
links, ts = self._samples.get_links_from_data(
_UserID(ctx[_CTX_USER]), upa, dt, as_admin=admin)
_get_user_from_object(ctx, _CTX_USER), upa, dt, as_admin=admin)
results = {'links': _links_to_dicts(links),
'effective_time': _datetime_to_epochmilliseconds(ts)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/SampleService/SampleServiceServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def __init__(self):
self.rpc_service.add(impl_SampleService.get_data_links_from_data,
name='SampleService.get_data_links_from_data',
types=[dict])
self.method_authentication['SampleService.get_data_links_from_data'] = 'required' # noqa
self.method_authentication['SampleService.get_data_links_from_data'] = 'optional' # noqa
self.rpc_service.add(impl_SampleService.get_sample_via_data,
name='SampleService.get_sample_via_data',
types=[dict])
Expand Down
99 changes: 43 additions & 56 deletions test/SampleService_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2854,19 +2854,10 @@ def test_get_links_from_data(sample_port, workspace):
{'id': id2, 'version': 2, 'node': 'foo3', 'upa': '1/2/2', 'dataid': 'column2'})

# get links from object 1/2/2
ret = requests.post(url, headers=get_authorized_headers(TOKEN3), json={
'method': 'SampleService.get_data_links_from_data',
'version': '1.1',
'id': '42',
'params': [{'upa': '1/2/2'}]
})
# print(ret.text)
assert ret.ok is True
ret = _get_links_from_data(url, TOKEN3, {'upa': '1/2/2'})

assert len(ret.json()['result']) == 1
assert len(ret.json()['result'][0]) == 2
assert_ms_epoch_close_to_now(ret.json()['result'][0]['effective_time'])
res = ret.json()['result'][0]['links']
assert_ms_epoch_close_to_now(ret['effective_time'])
res = ret['links']
expected_links = [
{
'linkid': lid1,
Expand Down Expand Up @@ -2901,19 +2892,10 @@ def test_get_links_from_data(sample_port, workspace):
assert link in res

# get links from object 1/1/1
ret = requests.post(url, headers=get_authorized_headers(TOKEN3), json={
'method': 'SampleService.get_data_links_from_data',
'version': '1.1',
'id': '42',
'params': [{'upa': '1/1/1'}]
})
# print(ret.text)
assert ret.ok is True
ret = _get_links_from_data(url, TOKEN3, {'upa': '1/1/1'})

assert len(ret.json()['result']) == 1
assert len(ret.json()['result'][0]) == 2
assert_ms_epoch_close_to_now(ret.json()['result'][0]['effective_time'])
res = ret.json()['result'][0]['links']
assert_ms_epoch_close_to_now(ret['effective_time'])
res = ret['links']
assert_ms_epoch_close_to_now(res[0]['created'])
del res[0]['created']
assert res == [
Expand All @@ -2931,18 +2913,25 @@ def test_get_links_from_data(sample_port, workspace):
]

# get links from object 1/2/1
ret = requests.post(url, headers=get_authorized_headers(TOKEN3), json={
ret = _get_links_from_data(url, TOKEN3, {'upa': '1/2/1'})

assert_ms_epoch_close_to_now(ret['effective_time'])
assert ret['links'] == []


def _get_links_from_data(url, token, params, print_resp=False):
ret = requests.post(url, headers=get_authorized_headers(token), json={
'method': 'SampleService.get_data_links_from_data',
'version': '1.1',
'id': '42',
'params': [{'upa': '1/2/1'}]
'params': [params]
})
# print(ret.text)
if print_resp:
print(ret.text)
assert ret.ok is True
assert len(ret.json()['result']) == 1
assert len(ret.json()['result'][0]) == 2
assert_ms_epoch_close_to_now(ret.json()['result'][0]['effective_time'])
assert ret.json()['result'][0]['links'] == []
return ret.json()['result'][0]


def test_get_links_from_data_expired(sample_port, workspace):
Expand Down Expand Up @@ -3072,34 +3061,25 @@ def test_get_links_from_data_public_read(sample_port, workspace):
# create links
lid = _create_link(url, TOKEN1, USER1, {'id': id_, 'version': 1, 'node': 'foo', 'upa': '1/1/1'})

# get links from object, user 4 has no explicit perms
ret = requests.post(url, headers=get_authorized_headers(TOKEN4), json={
'method': 'SampleService.get_data_links_from_data',
'version': '1.1',
'id': '42',
'params': [{'upa': '1/1/1'}]
})
# print(ret.text)
assert ret.ok is True
for token in [None, TOKEN4]: # anon user, user 4 has no explicit perms
ret = _get_links_from_data(url, token, {'upa': '1/1/1'})

assert len(ret.json()['result']) == 1
assert len(ret.json()['result'][0]) == 2
assert_ms_epoch_close_to_now(ret.json()['result'][0]['effective_time'])
assert len(ret.json()['result'][0]['links']) == 1
link = ret.json()['result'][0]['links'][0]
assert_ms_epoch_close_to_now(link['created'])
del link['created']
assert link == {
'linkid': lid,
'id': id_,
'version': 1,
'node': 'foo',
'upa': '1/1/1',
'dataid': None,
'createdby': USER1,
'expiredby': None,
'expired': None
}
assert_ms_epoch_close_to_now(ret['effective_time'])
assert len(ret['links']) == 1
link = ret['links'][0]
assert_ms_epoch_close_to_now(link['created'])
del link['created']
assert link == {
'linkid': lid,
'id': id_,
'version': 1,
'node': 'foo',
'upa': '1/1/1',
'dataid': None,
'createdby': USER1,
'expiredby': None,
'expired': None
}


def test_get_links_from_data_as_admin(sample_port, workspace):
Expand Down Expand Up @@ -3179,6 +3159,9 @@ def test_get_links_from_data_fail(sample_port, workspace):
_get_link_from_data_fail(
sample_port, TOKEN4, {'upa': '1/1/1'},
'Sample service error code 20000 Unauthorized: User user4 cannot read upa 1/1/1')
_get_link_from_data_fail(
sample_port, None, {'upa': '1/1/1'},
'Sample service error code 20000 Unauthorized: Anonymous users cannot read upa 1/1/1')
_get_link_from_data_fail(
sample_port, TOKEN3, {'upa': '1/2/1'},
'Sample service error code 50040 No such workspace data: Object 1/2/1 does not exist')
Expand All @@ -3188,6 +3171,10 @@ def test_get_links_from_data_fail(sample_port, workspace):
sample_port, TOKEN4, {'upa': '1/1/1', 'as_admin': 1},
'Sample service error code 20000 Unauthorized: User user4 does not have the necessary ' +
'administration privileges to run method get_data_links_from_data')
_get_link_from_data_fail(
sample_port, None, {'upa': '1/1/1', 'as_admin': 1},
'Sample service error code 20000 Unauthorized: Anonymous users may not act ' +
'as service administrators.')
_get_link_from_data_fail(
sample_port, TOKEN3, {'upa': '1/1/2', 'as_admin': 1},
'Sample service error code 50040 No such workspace data: Object 1/1/2 does not exist')
Expand Down