Skip to content

Commit

Permalink
Merge pull request #16872 from ahmedhamidawan/restore_old_tools_api_r…
Browse files Browse the repository at this point in the history
…oute

Restore ToolsApi and create new api route for new panel structure
  • Loading branch information
jmchilton authored Oct 20, 2023
2 parents 8bac65f + a739f88 commit 96aa7b4
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 101 deletions.
4 changes: 2 additions & 2 deletions client/src/components/Panels/ToolBox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ describe("ToolBox", () => {

it("test filter functions correctly matching: (1) Tools store array-of-objects with (2) Results array", async () => {
axiosMock
.onGet(`/api/tools`)
.onGet(`/api/tool_panel`)
.replyOnce(200, toolsListInPanel)
.onGet(`/api/tools?in_panel=False`)
.onGet(`/api/tool_panel?in_panel=False`)
.replyOnce(200, toolsMock)
.onGet(/api\/tools?.*/)
.replyOnce(200, resultsMock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ describe("ToolSchemaJson/ToolsView.vue", () => {

beforeEach(async () => {
axiosMock = new MockAdapter(axios);
axiosMock.onGet("/api/tools?in_panel=False&tool_help=True").reply(200, testToolsListResponse);
axiosMock.onGet("/api/tools").reply(200, testToolsListInPanelResponse);
axiosMock.onGet("/api/tool_panel?in_panel=False&tool_help=True").reply(200, testToolsListResponse);
axiosMock.onGet("/api/tool_panel").reply(200, testToolsListInPanelResponse);
wrapper = shallowMount(ToolsJson, { localVue });
await flushPromises();
});
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/ToolsView/ToolsSchemaJson/ToolsJson.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default {
async created() {
let tools = {};
await axios
.get(`${getAppRoot()}api/tools?in_panel=False&tool_help=True`)
.get(`${getAppRoot()}api/tool_panel?in_panel=False&tool_help=True`)
.then(({ data }) => {
tools = data.tools;
})
Expand All @@ -22,7 +22,7 @@ export default {
});
if (Object.keys(tools).length > 0) {
await axios
.get(`${getAppRoot()}api/tools`)
.get(`${getAppRoot()}api/tool_panel`)
.then(({ data }) => {
this.schemaTagObj = this.createToolsJson(tools, data.default);
const el = document.createElement("script");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Services.mockImplementation(() => {
describe("RepositoryDetails", () => {
it("test repository details index", async () => {
const axiosMock = new MockAdapter(axios);
axiosMock.onGet("api/tools?in_panel=true&view=default").reply(200, {});
axiosMock.onGet("api/tool_panel?in_panel=true&view=default").reply(200, {});
mockFetcher.path("/api/configuration").method("get").mock({ data: {} });
const localVue = getLocalVue();
const pinia = createPinia();
Expand Down
2 changes: 0 additions & 2 deletions client/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { datasetPathDestinationStore } from "./datasetPathDestinationStore";
import { gridSearchStore } from "./gridSearchStore";
import { invocationStore } from "./invocationStore";
import { jobDestinationParametersStore } from "./jobDestinationParametersStore";
import { panelStore } from "./panelStore";
import { syncVuextoGalaxy } from "./syncVuextoGalaxy";
import { tagStore } from "./tagStore";

Expand Down Expand Up @@ -48,7 +47,6 @@ export function createStore() {
datasetPathDestination: datasetPathDestinationStore,
invocations: invocationStore,
gridSearch: gridSearchStore,
panels: panelStore,
tags: tagStore,
},
};
Expand Down
66 changes: 0 additions & 66 deletions client/src/store/panelStore.js

This file was deleted.

8 changes: 4 additions & 4 deletions client/src/stores/toolStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export const useToolStore = defineStore("toolStore", () => {
if (!loading.value && !allToolsByIdFetched.value) {
loading.value = true;
await axios
.get(`${getAppRoot()}api/tools?in_panel=False`)
.get(`${getAppRoot()}api/tool_panel?in_panel=False`)
.then(({ data }) => {
saveAllTools(data.tools);
loading.value = false;
Expand All @@ -177,7 +177,7 @@ export const useToolStore = defineStore("toolStore", () => {
currentPanelView.value = panelView;
}
await axios
.get(`${getAppRoot()}api/tools?in_panel=true&view=${panelView}`)
.get(`${getAppRoot()}api/tool_panel?in_panel=true&view=${panelView}`)
.then(({ data }) => {
loading.value = false;
savePanelView(panelView, data[panelView]);
Expand All @@ -199,14 +199,14 @@ export const useToolStore = defineStore("toolStore", () => {
return;
}
loading.value = true;
const { data } = await axios.get(`${getAppRoot()}api/tools?in_panel=true&view=${panelView}`);
const { data } = await axios.get(`${getAppRoot()}api/tool_panel?in_panel=true&view=${panelView}`);
savePanelView(panelView, data[panelView]);
loading.value = false;
}
}

async function fetchPanel(panelView: string) {
const { data } = await axios.get(`${getAppRoot()}api/tools?in_panel=true&view=${panelView}`);
const { data } = await axios.get(`${getAppRoot()}api/tool_panel?in_panel=true&view=${panelView}`);
savePanelView(panelView, data[panelView]);
}

Expand Down
56 changes: 56 additions & 0 deletions lib/galaxy/webapps/galaxy/api/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,62 @@ def index(self, trans: GalaxyWebTransaction, **kwds):
detected_versions = self.service._detect(trans, tool_id)
return detected_versions

# Return everything.
try:
return self.app.toolbox.to_dict(
trans, in_panel=in_panel, trackster=trackster, tool_help=tool_help, view=view
)
except exceptions.MessageException:
raise
except Exception:
raise exceptions.InternalServerError("Error: Could not convert toolbox to dictionary")

@expose_api_anonymous_and_sessionless
def panel_view(self, trans: GalaxyWebTransaction, **kwds):
"""
GET /api/tool_panel
returns a dictionary of all tools or panels defined by parameters
:param in_panel: if true, tool sections are returned in panel
structure, with tool ids and labels
:param view: ToolBox view to apply (default is 'default')
:param trackster: if true, only tools that are compatible with
Trackster are returned
:param q: if present search on the given query will be performed
:param tool_id: if present the given tool_id will be searched for
all installed versions
"""

# Read params.
in_panel = util.string_as_bool(kwds.get("in_panel", "True"))
trackster = util.string_as_bool(kwds.get("trackster", "False"))
q = kwds.get("q", "")
tool_id = kwds.get("tool_id", "")
tool_help = util.string_as_bool(kwds.get("tool_help", "False"))
view = kwds.get("view", None)

# Find whether to search.
if q:
hits = self.service._search(q, view)
results = []
if hits:
for hit in hits:
try:
tool = self.service._get_tool(trans, hit, user=trans.user)
if tool:
results.append(tool.id)
except exceptions.AuthenticationFailed:
pass
except exceptions.ObjectNotFound:
pass
return results

# Find whether to detect.
if tool_id:
detected_versions = self.service._detect(trans, tool_id)
return detected_versions

# Return everything.
try:
return self.app.toolbox.to_panel_view(
Expand Down
1 change: 1 addition & 0 deletions lib/galaxy/webapps/galaxy/buildapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ def populate_api_routes(webapp, app):
# ====== TOOLS API ======
# =======================

webapp.mapper.connect("/api/tool_panel", action="panel_view", controller="tools")
webapp.mapper.connect("/api/tools/all_requirements", action="all_requirements", controller="tools")
webapp.mapper.connect("/api/tools/error_stack", action="error_stack", controller="tools")
webapp.mapper.connect("/api/tools/{id:.+?}/build", action="build", controller="tools")
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy_test/api/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def test_search_grep(self):
assert "Grep1" in get_response

def test_no_panel_index(self):
index = self._get("tools", data=dict(in_panel=False))
index = self._get("tool_panel", data=dict(in_panel=False))
tools_index = index.json().get("tools", {})
# No need to flatten out sections, with in_panel=False, only tools by
# ids are returned.
Expand Down Expand Up @@ -2640,7 +2640,7 @@ def _run_cat1(self, history_id, inputs, assert_ok=False, **kwargs):
return self._run("cat1", history_id, inputs, assert_ok=assert_ok, **kwargs)

def __tool_ids(self):
index = self._get("tools")
index = self._get("tool_panel")
tools_index = index.json().get("default", {})
# In panels by default, so flatten out sections...
tool_ids = []
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy_test/base/populators.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def skip_without_tool(tool_id: str):
def method_wrapper(method):
def get_tool_ids(api_test_case: HasAnonymousGalaxyInteractor):
interactor = api_test_case.anonymous_galaxy_interactor
index = interactor.get("tools", data=dict(in_panel=False))
index = interactor.get("tool_panel", data=dict(in_panel=False))
api_asserts.assert_status_code_is_ok(index, "Failed to fetch toolbox for target Galaxy.")
tools = index.json().get("tools", {})
# `in_panel=False`, so we have a toolsById dict...
Expand Down Expand Up @@ -2287,7 +2287,7 @@ def _run_cwl_tool_job(

if os.path.exists(tool_id):
raw_tool_id = os.path.basename(tool_id)
index = self.dataset_populator._get("tools", data=dict(in_panel=False))
index = self.dataset_populator._get("tool_panel", data=dict(in_panel=False))
index.raise_for_status()
tools = index.json().get("tools", {})
tool_ids = list(tools.keys())
Expand Down
4 changes: 2 additions & 2 deletions lib/tool_shed/test/functional/test_galaxy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_install_simple_tool(self):
installable_revisions = populator.get_ordered_installable_revisions(owner, name)
latest_install_revision = installable_revisions.__root__[-1]
self.install_repository(owner, name, latest_install_revision, tool_shed_url=self.url)
response = self.galaxy_interactor._get("tools?in_panel=False")
response = self.galaxy_interactor._get("tool_panel?in_panel=False")
response.raise_for_status()
expected_tool = populator.tool_guid(self, repository, "Add_a_column1", "1.1.0")
tool_ids = list((response.json().get("tools", {})).keys())
Expand All @@ -26,7 +26,7 @@ def test_install_simple_after_repository_metadata_reset(self):
metadata_response = populator.reset_metadata(repository)
assert metadata_response.status == "ok"
self.install_repository(owner, name, latest_install_revision, tool_shed_url=self.url)
response = self.galaxy_interactor._get("tools?in_panel=False")
response = self.galaxy_interactor._get("tool_panel?in_panel=False")
response.raise_for_status()
expected_tool = f"{self.host}:{self.port}/repos/{owner}/{name}/Add_a_column1/1.1.0"
tool_ids = list((response.json().get("tools", {})).keys())
Expand Down
4 changes: 2 additions & 2 deletions test/integration/test_edam_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def handle_galaxy_config_kwds(cls, config):
config["edam_panel_views"] = "merged"

def test_edam_toolbox(self):
index = self.galaxy_interactor.get("tools", data=dict(in_panel=True, view="ontology:edam_merged"))
index = self.galaxy_interactor.get("tool_panel", data=dict(in_panel=True, view="ontology:edam_merged"))
index.raise_for_status()
index_panel = index.json().get("ontology:edam_merged", {})
sections = [x for _, x in index_panel.items() if x["model_class"] == "ToolSection"]
Expand Down Expand Up @@ -40,7 +40,7 @@ def handle_galaxy_config_kwds(cls, config):
config["default_panel_view"] = "ontology:edam_topics"

def test_edam_toolbox(self):
index = self.galaxy_interactor.get("tools", data=dict(in_panel=True))
index = self.galaxy_interactor.get("tool_panel", data=dict(in_panel=True))
index.raise_for_status()
index_panel = index.json().get("ontology:edam_topics", {})
sections = [x for _, x in index_panel.items() if x["model_class"] == "ToolSection"]
Expand Down
Loading

0 comments on commit 96aa7b4

Please sign in to comment.