Skip to content

Commit

Permalink
Add method to WorkflowRepository, api.workflows
Browse files Browse the repository at this point in the history
count_stored_workflow_user_assocs
  • Loading branch information
jdavcs committed Aug 17, 2023
1 parent 284a8ac commit 9858cb8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
16 changes: 15 additions & 1 deletion lib/galaxy/model/repositories/workflow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
from typing import cast

from galaxy.model import Workflow
from sqlalchemy import (
func,
select,
)

from galaxy.model import (
StoredWorkflowUserShareAssociation,
Workflow,
)
from galaxy.model.repositories import (
BaseRepository,
MappedType,
Expand All @@ -14,3 +22,9 @@ def __init__(self, session: SessionType):

def get(self, primary_key: int) -> Workflow:
return cast(Workflow, super().get(primary_key))

def count_stored_workflow_user_assocs(self, user: MappedType, stored_workflow: MappedType) -> int:
# type-ignore/SessionlessContext
stmt = select(StoredWorkflowUserShareAssociation).filter_by(user=user, stored_workflow=stored_workflow)
stmt = select(func.count()).select_from(stmt)
return self.session.scalar(stmt) # type:ignore[union-attr]
12 changes: 4 additions & 8 deletions lib/galaxy/webapps/galaxy/api/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
from gxformat2._yaml import ordered_dump
from markupsafe import escape
from pydantic import Extra
from sqlalchemy import (
func,
select,
)
from starlette.responses import StreamingResponse

from galaxy import (
Expand All @@ -52,6 +48,7 @@
from galaxy.model.base import transaction
from galaxy.model.item_attrs import UsesAnnotations
from galaxy.model.repositories.stored_workflow import StoredWorkflowRepository
from galaxy.model.repositories.workflow import WorkflowRepository
from galaxy.model.store import BcoExportOptions
from galaxy.schema.fields import DecodedDatabaseIdField
from galaxy.schema.invocation import InvocationMessageResponseModel
Expand Down Expand Up @@ -198,11 +195,10 @@ def show(self, trans: GalaxyWebTransaction, id, **kwd):
"""
stored_workflow = self.__get_stored_workflow(trans, id, **kwd)
if stored_workflow.importable is False and stored_workflow.user != trans.user and not trans.user_is_admin:
stmt = select(model.StoredWorkflowUserShareAssociation).filter_by(
user=trans.user, stored_workflow=stored_workflow
wf_count = WorkflowRepository(trans.sa_session).count_stored_workflow_user_assocs(
trans.user, stored_workflow
)
stmt = select(func.count()).select_from(stmt)
if trans.sa_session.scalar(stmt) == 0:
if wf_count == 0:
message = "Workflow is neither importable, nor owned by or shared with current user"
raise exceptions.ItemAccessibilityException(message)
if kwd.get("legacy", False):
Expand Down

0 comments on commit 9858cb8

Please sign in to comment.