Skip to content

Commit

Permalink
[WIP] Fix SA2.0 (query->select) in webapps.galaxy.controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavcs committed Jul 21, 2023
1 parent 10f5451 commit 1176ebc
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions lib/galaxy/webapps/galaxy/controllers/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

from dateutil.parser import isoparse
from markupsafe import escape
from sqlalchemy import false
from sqlalchemy import (
false,
select,
)
from sqlalchemy.orm import undefer

from galaxy import (
Expand Down Expand Up @@ -372,11 +375,12 @@ def _list_switch(self, trans, histories):
new_history = histories[0]
galaxy_session = trans.get_galaxy_session()
try:
association = (
trans.sa_session.query(trans.app.model.GalaxySessionToHistoryAssociation)
stmt = (
select(trans.app.model.GalaxySessionToHistoryAssociation)
.filter_by(session_id=galaxy_session.id, history_id=new_history.id)
.first()
.limit(1)
)
association = trans.sa_session.scalars(stmt).first()
except Exception:
association = None
new_history.add_galaxy_session(galaxy_session, association=association)
Expand Down Expand Up @@ -405,11 +409,10 @@ def list_shared(self, trans, **kwargs):
# hit if this user isn't having the history shared with her.
history = self.history_manager.by_id(self.decode_id(id))
# Current user is the user with which the histories were shared
association = (
trans.sa_session.query(trans.app.model.HistoryUserShareAssociation)
.filter_by(user=trans.user, history=history)
.one()
stmt = select(trans.app.model.HistoryUserShareAssociation).filter_by(
user=trans.user, history=history
)
association = trans.sa_session.execute(select(stmt)).scalar_one()
trans.sa_session.delete(association)
with transaction(trans.sa_session):
trans.sa_session.commit()
Expand Down Expand Up @@ -483,8 +486,13 @@ def display_by_username_and_slug(self, trans, username, slug, **kwargs):
"""
# Get history.
session = trans.sa_session
user = session.query(model.User).filter_by(username=username).first()
history = trans.sa_session.query(model.History).filter_by(user=user, slug=slug, deleted=False).first()

stmt = select(model.User).filter_by(username=username).limit(1)
user = session.scalars(stmt).first()

stmt = select(model.History).filter_by(user=user, slug=slug, deleted=False).limit(1)
history = session.scalars(stmt).first()

if history is None:
raise web.httpexceptions.HTTPNotFound()

Expand Down Expand Up @@ -541,9 +549,7 @@ def permissions(self, trans, payload=None, **kwd):
permissions = {}
for action_key, action in trans.app.model.Dataset.permitted_actions.items():
in_roles = payload.get(action_key) or []
in_roles = [
trans.sa_session.query(trans.app.model.Role).get(trans.security.decode_id(x)) for x in in_roles
]
in_roles = [trans.sa_session.get(trans.app.model.Role, trans.security.decode_id(x)) for x in in_roles]
permissions[trans.app.security_agent.get_action(action.action)] = in_roles
trans.app.security_agent.history_set_default_permissions(history, permissions)
return {"message": "Default history '%s' dataset permissions have been changed." % history.name}
Expand Down

0 comments on commit 1176ebc

Please sign in to comment.