Skip to content

Commit b57d6ed

Browse files
committed
Move method into User model class
1 parent 4b6b85e commit b57d6ed

3 files changed

Lines changed: 8 additions & 15 deletions

File tree

lib/galaxy/managers/workflows.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,13 @@
2727
and_,
2828
desc,
2929
false,
30-
func,
3130
or_,
32-
select,
3331
true,
3432
)
3533
from sqlalchemy.orm import (
3634
aliased,
3735
joinedload,
3836
Query,
39-
Session,
4037
subqueryload,
4138
)
4239

@@ -53,10 +50,7 @@
5350
from galaxy.managers.base import decode_id
5451
from galaxy.managers.context import ProvidesUserContext
5552
from galaxy.managers.executables import artifact_class
56-
from galaxy.model import (
57-
StoredWorkflow,
58-
StoredWorkflowUserShareAssociation,
59-
)
53+
from galaxy.model import StoredWorkflow
6054
from galaxy.model.base import transaction
6155
from galaxy.model.index_filter_util import (
6256
append_user_filter,
@@ -1978,9 +1972,3 @@ def import_workflow(self, workflow, **kwds):
19781972
raise NotImplementedError(
19791973
"Direct format 2 import of nested workflows is not yet implemented, use bioblend client."
19801974
)
1981-
1982-
1983-
def count_stored_workflow_user_assocs(session: Session, user, stored_workflow) -> int:
1984-
stmt = select(StoredWorkflowUserShareAssociation).filter_by(user=user, stored_workflow=stored_workflow)
1985-
stmt = select(func.count()).select_from(stmt)
1986-
return session.scalar(stmt)

lib/galaxy/model/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,12 @@ def quota_source_usage_for(self, quota_source_label: Optional[str]) -> Optional[
11691169
return quota_source_usage
11701170
return None
11711171

1172+
def count_stored_workflow_user_assocs(self, stored_workflow) -> int:
1173+
stmt = select(StoredWorkflowUserShareAssociation).filter_by(user=self, stored_workflow=stored_workflow)
1174+
stmt = select(func.count()).select_from(stmt)
1175+
session = object_session(self)
1176+
return session.scalar(stmt)
1177+
11721178

11731179
class PasswordResetToken(Base):
11741180
__tablename__ = "password_reset_token"

lib/galaxy/webapps/galaxy/api/workflows.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
invocation_job_source_iter,
4141
)
4242
from galaxy.managers.workflows import (
43-
count_stored_workflow_user_assocs,
4443
MissingToolsException,
4544
RefactorRequest,
4645
WorkflowCreateOptions,
@@ -193,7 +192,7 @@ def show(self, trans: GalaxyWebTransaction, id, **kwd):
193192
"""
194193
stored_workflow = self.__get_stored_workflow(trans, id, **kwd)
195194
if stored_workflow.importable is False and stored_workflow.user != trans.user and not trans.user_is_admin:
196-
wf_count = count_stored_workflow_user_assocs(trans.sa_session, trans.user, stored_workflow)
195+
wf_count = trans.user.count_stored_workflow_user_assocs(stored_workflow)
197196
if wf_count == 0:
198197
message = "Workflow is neither importable, nor owned by or shared with current user"
199198
raise exceptions.ItemAccessibilityException(message)

0 commit comments

Comments
 (0)