-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop old repositories, group repo functions in one module
- Loading branch information
Showing
35 changed files
with
218 additions
and
348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,164 @@ | ||
from typing import Any | ||
from typing import Optional | ||
|
||
from sqlalchemy import select | ||
from sqlalchemy import ( | ||
cast, | ||
false, | ||
func, | ||
Integer, | ||
null, | ||
or_, | ||
select, | ||
true, | ||
update, | ||
) | ||
from sqlalchemy.orm import Session | ||
|
||
from galaxy.model import Base | ||
from galaxy.model import ( | ||
APIKeys, | ||
Group, | ||
GroupRoleAssociation, | ||
HistoryDatasetAssociation, | ||
Job, | ||
PageRevision, | ||
Quota, | ||
StoredWorkflowUserShareAssociation, | ||
User, | ||
UserGroupAssociation, | ||
YIELD_PER_ROWS, | ||
) | ||
from galaxy.model.tool_shed_install import ToolShedRepository | ||
|
||
MappedType = Base | ||
|
||
# all models | ||
def get_all(session: Session, model_class): | ||
return session.scalars(select(model_class)).all() | ||
|
||
class ModelRepository: | ||
def __init__(self, session: Session, model_class: MappedType): | ||
self.session = session | ||
self.model_class = model_class | ||
|
||
def get_all(self): | ||
return self.session.scalars(select(self.model_class)).all() | ||
# api_keys | ||
def get_api_key(session: Session, user_id: int): | ||
stmt = select(APIKeys).filter_by(user_id=user_id, deleted=False).order_by(APIKeys.create_time.desc()).limit(1) | ||
return session.scalars(stmt).first() | ||
|
||
|
||
def mark_all_api_keys_as_deleted(session: Session, user_id: int): | ||
stmt = ( | ||
update(APIKeys) | ||
.where(APIKeys.user_id == user_id) | ||
.where(APIKeys.deleted == false()) | ||
.values(deleted=True) | ||
.execution_options(synchronize_session="evaluate") | ||
) | ||
return session.execute(stmt) | ||
|
||
|
||
# groups | ||
def get_group_by_name(session: Session, name: str): | ||
stmt = select(Group).filter(Group.name == name).limit(1) | ||
return session.scalars(stmt).first() | ||
|
||
|
||
def get_not_deleted_groups(session: Session): | ||
stmt = select(Group).where(Group.deleted == false()) | ||
return session.scalars(stmt) | ||
|
||
|
||
# hdas | ||
def get_fasta_hdas_by_history(session: Session, history_id: int): | ||
stmt = ( | ||
select(HistoryDatasetAssociation) | ||
.filter_by(history_id=history_id, extension="fasta", deleted=False) | ||
.order_by(HistoryDatasetAssociation.hid.desc()) | ||
) | ||
return session.scalars(stmt).all() | ||
|
||
|
||
def get_len_files_by_history(session: Session, history_id: int): | ||
stmt = select(HistoryDatasetAssociation).filter_by(history_id=history_id, extension="len", deleted=False) | ||
return session.scalars(stmt) | ||
|
||
|
||
# jobs | ||
def get_jobs_to_check_at_startup(session: Session, track_jobs_in_database: bool, config): | ||
if track_jobs_in_database: | ||
in_list = (Job.states.QUEUED, Job.states.RUNNING, Job.states.STOPPED) | ||
else: | ||
in_list = (Job.states.NEW, Job.states.QUEUED, Job.states.RUNNING) | ||
|
||
stmt = ( | ||
select(Job) | ||
.execution_options(yield_per=YIELD_PER_ROWS) | ||
.filter(Job.state.in_(in_list) & (Job.handler == config.server_name)) | ||
) | ||
if config.user_activation_on: | ||
# Filter out the jobs of inactive users. | ||
stmt = stmt.outerjoin(User).filter(or_((Job.user_id == null()), (User.active == true()))) | ||
|
||
return session.scalars(stmt) | ||
|
||
|
||
# page_revisions | ||
def get_page_revision(session: Session, page_id: int): | ||
stmt = select(PageRevision).filter_by(page_id=page_id) | ||
return session.scalars(stmt) | ||
|
||
|
||
# quotas | ||
def get_quotas(session: Session, deleted: bool = False): | ||
is_deleted = true() | ||
if not deleted: | ||
is_deleted = false() | ||
stmt = select(Quota).where(Quota.deleted == is_deleted) | ||
return session.scalars(stmt) | ||
|
||
|
||
# roles | ||
def get_group_role(session: Session, group, role) -> Optional[GroupRoleAssociation]: | ||
stmt = ( | ||
select(GroupRoleAssociation).where(GroupRoleAssociation.group == group).where(GroupRoleAssociation.role == role) | ||
) | ||
return session.execute(stmt).scalar_one_or_none() | ||
|
||
|
||
# tool_shed_repositories | ||
def get_tool_shed_repositories(session: Session, **kwd): | ||
stmt = select(ToolShedRepository) | ||
for key, value in kwd.items(): | ||
if value is not None: | ||
column = ToolShedRepository.table.c[key] | ||
stmt = stmt.filter(column == value) | ||
stmt = stmt.order_by(ToolShedRepository.name).order_by(cast(ToolShedRepository.ctx_rev, Integer).desc()) | ||
return session.scalars(stmt).all() | ||
|
||
|
||
# users | ||
def get_group_user(session: Session, user, group) -> Optional[UserGroupAssociation]: | ||
stmt = ( | ||
select(UserGroupAssociation).where(UserGroupAssociation.user == user).where(UserGroupAssociation.group == group) | ||
) | ||
return session.execute(stmt).scalar_one_or_none() | ||
|
||
|
||
def get_users_by_ids(session: Session, user_ids): | ||
stmt = select(User).where(User.id.in_(user_ids)) | ||
return session.scalars(stmt).all() | ||
|
||
|
||
# The get_user_by_email and get_user_by_username functions may be called from | ||
# the tool_shed app, which has its own User model, which is different from | ||
# galaxy.model.User. In that case, the tool_shed user model should be passed as | ||
# the model_class argument. | ||
def get_user_by_email(session, email: str, model_class=User): | ||
stmt = select(model_class).filter(model_class.email == email).limit(1) | ||
return session.scalars(stmt).first() | ||
|
||
|
||
def get_user_by_username(session, username: str, model_class=User): | ||
stmt = select(model_class).filter(model_class.username == username).limit(1) | ||
return session.scalars(stmt).first() | ||
|
||
|
||
# workflows | ||
def count_stored_workflow_user_assocs(session: Session, user, stored_workflow) -> int: | ||
stmt = select(StoredWorkflowUserShareAssociation).filter_by(user=user, stored_workflow=stored_workflow) | ||
stmt = select(func.count()).select_from(stmt) | ||
return session.scalar(stmt) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.