Skip to content

Commit

Permalink
Merge pull request #5018 from martenson/api-for-admin-decode
Browse files Browse the repository at this point in the history
add API that allows admins to decode galaxy objects' ids
  • Loading branch information
jmchilton committed Nov 20, 2017
2 parents 299ae5c + 8a35b94 commit db2c3a4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/galaxy/webapps/galaxy/api/configuration.py
Expand Up @@ -90,6 +90,18 @@ def dynamic_tool_confs(self, trans):
confs = self.app.toolbox.dynamic_confs(include_migrated_tool_conf=True)
return map(_tool_conf_to_dict, confs)

@expose_api
@require_admin
def decode_id(self, trans, encoded_id, **kwds):
"""Decode a given id."""
decoded_id = None
# Handle the special case for library folders
if ((len(encoded_id) % 16 == 1) and encoded_id.startswith('F')):
decoded_id = trans.security.decode_id(encoded_id[1:])
else:
decoded_id = trans.security.decode_id(encoded_id)
return {"decoded_id": decoded_id}

@expose_api
@require_admin
def tool_lineages(self, trans):
Expand Down
4 changes: 4 additions & 0 deletions lib/galaxy/webapps/galaxy/buildapp.py
Expand Up @@ -339,6 +339,10 @@ def populate_api_routes(webapp, app):
"/api/whoami", controller='configuration',
action='whoami',
conditions=dict(method=["GET"]))
webapp.mapper.connect("api_decode",
"/api/configuration/decode/{encoded_id}", controller='configuration',
action='decode_id',
conditions=dict(method=["GET"]))
webapp.mapper.resource('datatype',
'datatypes',
path_prefix='/api',
Expand Down
23 changes: 23 additions & 0 deletions test/api/test_configuration.py
Expand Up @@ -3,6 +3,9 @@
assert_has_keys,
assert_not_has_keys,
)
from base.populators import (
LibraryPopulator
)

TEST_KEYS_FOR_ALL_USERS = [
'enable_unique_workflow_defaults',
Expand All @@ -24,6 +27,10 @@

class ConfigurationApiTestCase(api.ApiTestCase):

def setUp(self):
super(ConfigurationApiTestCase, self).setUp()
self.library_populator = LibraryPopulator(self)

def test_normal_user_configuration(self):
config = self._get_configuration()
assert_has_keys(config, *TEST_KEYS_FOR_ALL_USERS)
Expand All @@ -34,6 +41,22 @@ def test_admin_user_configuration(self):
assert_has_keys(config, *TEST_KEYS_FOR_ALL_USERS)
assert_has_keys(config, *TEST_KEYS_FOR_ADMIN_ONLY)

def test_admin_decode_id(self):
new_lib = self.library_populator.new_library('DecodeTestLibrary')
decode_response = self._get("configuration/decode/" + new_lib["id"], admin=True)
response_id = decode_response.json()["decoded_id"]
decoded_library_id = self.security.decode_id(new_lib["id"])
assert decoded_library_id == response_id
# fake valid folder id by prepending F
valid_encoded_folder_id = 'F' + new_lib["id"]
folder_decode_response = self._get("configuration/decode/" + valid_encoded_folder_id, admin=True)
folder_response_id = folder_decode_response.json()["decoded_id"]
assert decoded_library_id == folder_response_id

def test_normal_user_decode_id(self):
decode_response = self._get("configuration/decode/badhombre", admin=False)
self._assert_status_code_is(decode_response, 403)

def _get_configuration(self, data={}, admin=False):
response = self._get("configuration", data=data, admin=admin)
self._assert_status_code_is(response, 200)
Expand Down

0 comments on commit db2c3a4

Please sign in to comment.