From 781476858e14bfb25cce142af891c42c2cc5e8db Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Mon, 11 Mar 2024 13:20:00 +0100 Subject: [PATCH 01/12] Don't create unnecessary histories for anon users The previous galaxy_session.user guard meant that anon users would always get a new history. --- lib/galaxy/webapps/base/webapp.py | 47 ++++++++++++++++--------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/lib/galaxy/webapps/base/webapp.py b/lib/galaxy/webapps/base/webapp.py index a13059484f94..fa02d840d532 100644 --- a/lib/galaxy/webapps/base/webapp.py +++ b/lib/galaxy/webapps/base/webapp.py @@ -912,29 +912,30 @@ def get_or_create_default_history(self): Gets or creates a default history and associates it with the current session. """ - - # There must be a user to fetch a default history. - if not self.galaxy_session.user: - return self.new_history() - - # Look for default history that (a) has default name + is not deleted and - # (b) has no datasets. If suitable history found, use it; otherwise, create - # new history. - stmt = select(self.app.model.History).filter_by( - user=self.galaxy_session.user, name=self.app.model.History.default_name, deleted=False - ) - unnamed_histories = self.sa_session.scalars(stmt) - default_history = None - for history in unnamed_histories: - if history.empty: - # Found suitable default history. - default_history = history - break - - # Set or create history. - if default_history: - history = default_history - self.set_history(history) + history = self.galaxy_session.current_history + if history and not history.deleted: + return history + + user = self.galaxy_session.user + if user: + # Look for default history that (a) has default name + is not deleted and + # (b) has no datasets. If suitable history found, use it; otherwise, create + # new history. + stmt = select(self.app.model.History).filter_by( + user=user, name=self.app.model.History.default_name, deleted=False + ) + unnamed_histories = self.sa_session.scalars(stmt) + default_history = None + for history in unnamed_histories: + if history.empty: + # Found suitable default history. + default_history = history + break + + # Set or create history. + if default_history: + history = default_history + self.set_history(history) else: history = self.new_history() From 5e080223a5bf0a01c9d23c49ade2145e1fbaaf50 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Mon, 11 Mar 2024 13:23:43 +0100 Subject: [PATCH 02/12] Only create histories if client includes session cookie --- lib/galaxy/webapps/base/webapp.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/galaxy/webapps/base/webapp.py b/lib/galaxy/webapps/base/webapp.py index fa02d840d532..c3c1dd8bbcf2 100644 --- a/lib/galaxy/webapps/base/webapp.py +++ b/lib/galaxy/webapps/base/webapp.py @@ -650,11 +650,11 @@ def _ensure_valid_session(self, session_cookie: str, create: bool = True) -> Non galaxy_session = self.__create_new_session(prev_galaxy_session, user_for_new_session) galaxy_session_requires_flush = True self.galaxy_session = galaxy_session - if self.webapp.name == "galaxy": - self.get_or_create_default_history() self.__update_session_cookie(name=session_cookie) else: self.galaxy_session = galaxy_session + if self.webapp.name == "galaxy": + self.get_or_create_default_history() # Do we need to flush the session? if galaxy_session_requires_flush: self.sa_session.add(galaxy_session) @@ -799,10 +799,10 @@ def _associate_user_history(self, user, prev_galaxy_session=None): and not users_last_session.current_history.deleted ): history = users_last_session.current_history - elif not history: - history = self.get_history(create=True, most_recent=True) if history not in self.galaxy_session.histories: self.galaxy_session.add_history(history) + if not history: + history = self.new_history() if history.user is None: history.user = user self.galaxy_session.current_history = history From c5839eec371e7a020a4a8812039fa1bd4ce5ce4a Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Tue, 12 Mar 2024 15:50:21 +0100 Subject: [PATCH 03/12] Add test for history creation logic --- lib/galaxy_test/api/test_authenticate.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/galaxy_test/api/test_authenticate.py b/lib/galaxy_test/api/test_authenticate.py index 41f437d49134..7cd375516a32 100644 --- a/lib/galaxy_test/api/test_authenticate.py +++ b/lib/galaxy_test/api/test_authenticate.py @@ -53,3 +53,25 @@ def test_tool_runner_session_cookie_handling(self): current_history_json_response.raise_for_status() current_history = current_history_json_response.json() assert current_history["contents_active"]["active"] == 1 + + def test_anon_history_creation(self): + # First request: + # We don't create any histories, just return a session cookie + response = get(self.url) + cookie = {"galaxysession": response.cookies["galaxysession"]} + # Check that we don't have any histories (API doesn't auto-create new histories) + histories_response = get( + urljoin( + self.url, + "api/histories", + ) + ) + assert not histories_response.json() + # Second request, we know client follows conventions by including cookies, + # default history is created. + get(self.url, cookies=cookie) + second_histories_response = get( + urljoin(self.url, "history/current_history_json"), + cookies=cookie, + ) + assert second_histories_response.json() From 27dc621fec6ea5dbc3459801f08ec175fd3f25cf Mon Sep 17 00:00:00 2001 From: guerler Date: Fri, 8 Mar 2024 15:00:24 -0500 Subject: [PATCH 04/12] Remove archived histories link from Masthead --- client/src/entry/analysis/menu.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/client/src/entry/analysis/menu.js b/client/src/entry/analysis/menu.js index b870446bbd3f..495b0ae231a2 100644 --- a/client/src/entry/analysis/menu.js +++ b/client/src/entry/analysis/menu.js @@ -243,10 +243,6 @@ export function fetchMenu(options = {}) { url: "/interactivetool_entry_points/list", }); } - userTab.menu.push({ - title: _l("Archived Histories"), - url: "/histories/archived", - }); if (Galaxy.config.enable_notification_system) { userTab.menu.push({ title: _l("Notifications"), From 9ef959a43cc730a9c5efbbcf4243e2528a267a11 Mon Sep 17 00:00:00 2001 From: guerler Date: Fri, 8 Mar 2024 15:02:30 -0500 Subject: [PATCH 05/12] Add archived histories to histories grid tabs --- client/src/components/Grid/GridHistory.vue | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/src/components/Grid/GridHistory.vue b/client/src/components/Grid/GridHistory.vue index fe61e4ab0103..70e0ca0ab909 100644 --- a/client/src/components/Grid/GridHistory.vue +++ b/client/src/components/Grid/GridHistory.vue @@ -17,7 +17,7 @@ const userStore = useUserStore(); library.add(faPlus); interface Props { - activeList?: "my" | "shared" | "published"; + activeList?: "archived" | "my" | "shared" | "published"; username?: string; } @@ -64,6 +64,9 @@ const props = withDefaults(defineProps(), { Public Histories + + Archived Histories + From bd28440b882db6c2d1675d6994554bd6ee4cad79 Mon Sep 17 00:00:00 2001 From: guerler Date: Fri, 8 Mar 2024 15:05:28 -0500 Subject: [PATCH 06/12] Redirect route for archived histories to grid history component --- client/src/components/Grid/GridHistory.vue | 8 +++++++- client/src/entry/analysis/router.js | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/client/src/components/Grid/GridHistory.vue b/client/src/components/Grid/GridHistory.vue index 70e0ca0ab909..a54e2437d3be 100644 --- a/client/src/components/Grid/GridHistory.vue +++ b/client/src/components/Grid/GridHistory.vue @@ -11,6 +11,7 @@ import { useUserStore } from "@/stores/userStore"; import Heading from "@/components/Common/Heading.vue"; import LoginRequired from "@/components/Common/LoginRequired.vue"; import GridList from "@/components/Grid/GridList.vue"; +import HistoryArchive from "@/components/History/Archiving/HistoryArchive.vue"; const userStore = useUserStore(); @@ -70,6 +71,11 @@ const props = withDefaults(defineProps(), { - + + diff --git a/client/src/entry/analysis/router.js b/client/src/entry/analysis/router.js index 3d0c5f792736..aa9e540be7d6 100644 --- a/client/src/entry/analysis/router.js +++ b/client/src/entry/analysis/router.js @@ -63,7 +63,6 @@ import { patchRouterPush } from "./router-push"; import AboutGalaxy from "@/components/AboutGalaxy.vue"; import GridVisualization from "@/components/Grid/GridVisualization.vue"; -import HistoryArchive from "@/components/History/Archiving/HistoryArchive.vue"; import HistoryArchiveWizard from "@/components/History/Archiving/HistoryArchiveWizard.vue"; import HistoryDatasetPermissions from "@/components/History/HistoryDatasetPermissions.vue"; import NotificationsList from "@/components/Notifications/NotificationsList.vue"; @@ -288,7 +287,10 @@ export function getRouter(Galaxy) { }, { path: "histories/archived", - component: HistoryArchive, + component: GridHistory, + props: { + activeList: "archived", + }, }, { path: "histories/list", From 142dcebb7746f87cbd4ddf0540569feb581e08ed Mon Sep 17 00:00:00 2001 From: guerler Date: Fri, 8 Mar 2024 15:06:23 -0500 Subject: [PATCH 07/12] Remove header title from archived histories --- client/src/components/History/Archiving/HistoryArchive.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/client/src/components/History/Archiving/HistoryArchive.vue b/client/src/components/History/Archiving/HistoryArchive.vue index 927fb77e91f9..e8d880489e46 100644 --- a/client/src/components/History/Archiving/HistoryArchive.vue +++ b/client/src/components/History/Archiving/HistoryArchive.vue @@ -135,7 +135,6 @@ async function onImportCopy(history: ArchivedHistorySummary) { From 6a33805d94cf87ef7c94fd124c2a701941ef656b Mon Sep 17 00:00:00 2001 From: Ahmed Hamid Awan Date: Tue, 12 Mar 2024 18:36:27 -0500 Subject: [PATCH 11/12] Update client/src/components/History/CurrentHistory/HistoryNavigation.vue Co-authored-by: Dannon --- .../src/components/History/CurrentHistory/HistoryNavigation.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/components/History/CurrentHistory/HistoryNavigation.vue b/client/src/components/History/CurrentHistory/HistoryNavigation.vue index ea8bce71f748..a2c0f7b3a0d4 100644 --- a/client/src/components/History/CurrentHistory/HistoryNavigation.vue +++ b/client/src/components/History/CurrentHistory/HistoryNavigation.vue @@ -277,7 +277,7 @@ function userTitle(title: string) { @ok="onDelete" @show="purgeHistory = false">

- Do you also want to purge the history {{ history.name }} + Do you also want to permanently delete the history {{ history.name }}

Purge history From ac6ca59baa83fccd7e9b02322c163e6b0a0bcbc7 Mon Sep 17 00:00:00 2001 From: Ahmed Hamid Awan Date: Tue, 12 Mar 2024 18:37:02 -0500 Subject: [PATCH 12/12] Update client/src/components/History/CurrentHistory/HistoryNavigation.vue Co-authored-by: Dannon --- .../src/components/History/CurrentHistory/HistoryNavigation.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/components/History/CurrentHistory/HistoryNavigation.vue b/client/src/components/History/CurrentHistory/HistoryNavigation.vue index a2c0f7b3a0d4..1caa443ec266 100644 --- a/client/src/components/History/CurrentHistory/HistoryNavigation.vue +++ b/client/src/components/History/CurrentHistory/HistoryNavigation.vue @@ -280,7 +280,7 @@ function userTitle(title: string) { Do you also want to permanently delete the history {{ history.name }}

- Purge history + Yes, permanently delete this history.