Skip to content

Commit

Permalink
Merge branch 'release_24.1' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Jun 8, 2024
2 parents df19283 + a2fdcb3 commit b5e8d50
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 7 deletions.
11 changes: 11 additions & 0 deletions lib/galaxy/files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ def user_vault(self) -> Dict[str, Any]: ...
@property
def app_vault(self) -> Dict[str, Any]: ...

@property
def anonymous(self) -> bool: ...


OptionalUserContext = Optional[FileSourcesUserContext]

Expand Down Expand Up @@ -422,6 +425,10 @@ def app_vault(self):
def file_sources(self):
return self.trans.app.file_sources

@property
def anonymous(self) -> bool:
return self.trans.anonymous


class DictFileSourcesUserContext(FileSourcesUserContext, FileSourceDictifiable):
def __init__(self, **kwd):
Expand Down Expand Up @@ -466,3 +473,7 @@ def app_vault(self):
@property
def file_sources(self):
return self._kwd.get("file_sources")

@property
def anonymous(self) -> bool:
return bool(self._kwd.get("username"))
3 changes: 3 additions & 0 deletions lib/galaxy/managers/file_source_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,9 @@ def user_file_sources_to_dicts(
exclude_kind: Optional[Set[PluginKind]] = None,
) -> List[FilesSourceProperties]:
"""Write out user file sources as list of config dictionaries."""
if user_context.anonymous:
return []

as_dicts = []
for files_source_properties in self._all_user_file_source_properties(user_context):
plugin_kind = PluginKind.rfs
Expand Down
19 changes: 15 additions & 4 deletions lib/galaxy/managers/jobs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import json
import logging
import typing
from datetime import (
date,
datetime,
)
from typing import (
cast,
Dict,
List,
Optional,
)

import sqlalchemy
Expand Down Expand Up @@ -38,6 +39,7 @@
Safety,
)
from galaxy.managers.collections import DatasetCollectionManager
from galaxy.managers.context import ProvidesUserContext
from galaxy.managers.datasets import DatasetManager
from galaxy.managers.hdas import HDAManager
from galaxy.managers.lddas import LDDAManager
Expand Down Expand Up @@ -106,7 +108,9 @@ def __init__(self, app: StructuredApp):
self.app = app
self.dataset_manager = DatasetManager(app)

def index_query(self, trans, payload: JobIndexQueryPayload) -> sqlalchemy.engine.Result:
def index_query(
self, trans: ProvidesUserContext, payload: JobIndexQueryPayload
) -> Optional[sqlalchemy.engine.ScalarResult]:
"""The caller is responsible for security checks on the resulting job if
history_id, invocation_id, or implicit_collection_jobs_id is set.
Otherwise this will only return the user's jobs or all jobs if the requesting
Expand All @@ -122,6 +126,13 @@ def index_query(self, trans, payload: JobIndexQueryPayload) -> sqlalchemy.engine
search = payload.search
order_by = payload.order_by

if trans.user is None:
# If the user is anonymous we can only return jobs for the current session history
if trans.galaxy_session and trans.galaxy_session.current_history_id:
history_id = trans.galaxy_session.current_history_id
else:
return None

def build_and_apply_filters(stmt, objects, filter_func):
if objects is not None:
if isinstance(objects, (str, date, datetime)):
Expand Down Expand Up @@ -208,7 +219,7 @@ def add_search_criteria(stmt):
if user_details:
stmt = stmt.outerjoin(Job.user)
else:
if history_id is None and invocation_id is None and implicit_collection_jobs_id is None:
if history_id is None and invocation_id is None and implicit_collection_jobs_id is None and trans.user:
stmt = stmt.where(Job.user_id == trans.user.id)
# caller better check security

Expand Down Expand Up @@ -647,7 +658,7 @@ def _build_stmt_for_dce(self, stmt, data_conditions, used_ids, k, v):
return stmt


def view_show_job(trans, job: Job, full: bool) -> typing.Dict:
def view_show_job(trans, job: Job, full: bool) -> Dict:
is_admin = trans.user_is_admin
job_dict = job.to_dict("element", system_details=is_admin)
if trans.app.config.expose_dataset_path and "command_line" not in job_dict:
Expand Down
4 changes: 3 additions & 1 deletion lib/galaxy/webapps/galaxy/services/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def index(
or payload.history_id is not None
)
jobs = self.job_manager.index_query(trans, payload)
out = []
out: List[Dict[str, Any]] = []
if jobs is None:
return out
for job in jobs.yield_per(model.YIELD_PER_ROWS):
# TODO: optimize if this crucial
if check_security_of_jobs and not security_check(trans, job.history, check_accessible=True):
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/workflow/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ def to_cwl(value, hda_references, step):
element_identifier = None
if isinstance(value, model.HistoryDatasetCollectionAssociation):
value = value.collection
if isinstance(value, model.DatasetCollectionElement) and value.hda:
if isinstance(value, model.DatasetCollectionElement):
element_identifier = value.element_identifier
value = value.hda
value = value.element_object
if isinstance(value, model.HistoryDatasetAssociation):
# I think the following two checks are needed but they may
# not be needed.
Expand Down
12 changes: 12 additions & 0 deletions test/unit/workflows/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,18 @@ def test_to_cwl_nested_collection():
assert result["outer"][0]["basename"] == "inner"


def test_to_cwl_dataset_collection_element():
hda = model.HistoryDatasetAssociation(create_dataset=True, flush=False)
hda.dataset.state = model.Dataset.states.OK
dc_inner = model.DatasetCollection(collection_type="list")
model.DatasetCollectionElement(collection=dc_inner, element_identifier="inner", element=hda)
dc_outer = model.DatasetCollection(collection_type="list:list")
dce_outer = model.DatasetCollectionElement(collection=dc_outer, element_identifier="outer", element=dc_inner)
result = modules.to_cwl(dce_outer, [], model.WorkflowStep())
assert result[0]["class"] == "File"
assert result[0]["basename"] == "inner"


class MapOverTestCase(NamedTuple):
data_input: str
step_input_def: Union[str, List[str]]
Expand Down

0 comments on commit b5e8d50

Please sign in to comment.