managers Package

managers Package

Classes that manage resources (models, tools, etc.) by using the current Transaction.

Encapsulates the intersection of trans (or trans.sa_session), models, and Controllers.

Responsibilities:

model operations that involve the trans/sa_session (CRUD) security:

ownership, accessibility
common aspect-oriented operations via new mixins:
sharable, annotatable, tagable, ratable
Not responsible for:
encoding/decoding ids any http gobblygook formatting of returned data (always python structures) formatting of raised errors
The goal is to have Controllers only handle:
query-string/payload parsing and encoding/decoding ids http return formatting
and:
control, improve namespacing in Controllers DRY for Controller ops (define here - use in both UI/API Controllers)

In other words, ‘Business logic’ independent of web transactions/user context (trans) should be pushed into models - but logic that requires the context trans should be placed under this module.

api_keys Module

class galaxy.managers.api_keys.ApiKeyManager(app)[source]

Bases: object

create_api_key(user)[source]
get_or_create_api_key(user)[source]

base Module

class galaxy.managers.base.ModelManager[source]

Bases: object

class galaxy.managers.base.ModelSerializer[source]

Bases: object

galaxy.managers.base.get_class(class_name)[source]

Returns the class object that a string denotes. Without this method, we’d have to do eval(<class_name>).

galaxy.managers.base.get_object(trans, id, class_name, check_ownership=False, check_accessible=False, deleted=None)[source]

Convenience method to get a model object with the specified checks. This is a generic method for dealing with objects uniformly from the older controller mixin code - however whenever possible the managers for a particular model should be used to load objects.

galaxy.managers.base.security_check(trans, item, check_ownership=False, check_accessible=False)[source]

Security checks for an item: checks if (a) user owns item or (b) item is accessible to user. This is a generic method for dealing with objects uniformly from the older controller mixin code - however whenever possible the managers for a particular model should be used to perform security checks.

citations Module

class galaxy.managers.citations.BaseCitation[source]

Bases: object

equals(other_citation)[source]
has_doi()[source]
to_dict(citation_format)[source]
class galaxy.managers.citations.BibtexCitation(elem, directory, citation_manager)[source]

Bases: galaxy.managers.citations.BaseCitation

to_bibtex()[source]
class galaxy.managers.citations.CitationCollection[source]

Bases: object

add(new_citation)[source]
class galaxy.managers.citations.CitationsManager(app)[source]

Bases: object

citations_for_tool(tool)[source]
citations_for_tool_ids(tool_ids)[source]
parse_citation(citation_elem, tool_directory)[source]
class galaxy.managers.citations.DoiCache(config)[source]

Bases: object

get_bibtex(doi)[source]
class galaxy.managers.citations.DoiCitation(elem, directory, citation_manager)[source]

Bases: galaxy.managers.citations.BaseCitation

BIBTEX_UNSET = <object object>
doi()[source]
has_doi()[source]
to_bibtex()[source]
galaxy.managers.citations.parse_citation(elem, directory, citation_manager)[source]

Parse an abstract citation entry from the specified XML element. The directory parameter should be used to find external files for this citation.

collections Module

class galaxy.managers.collections.DatasetCollectionManager(app)[source]

Bases: object

Abstraction for interfacing with dataset collections instance - ideally abstarcts out model and plugin details.

copy(trans, parent, source, encoded_source_id)[source]
create(trans, parent, name, collection_type, element_identifiers=None, elements=None, implicit_collection_info=None)[source]
delete(trans, instance_type, id)[source]
get_dataset_collection(trans, encoded_id)[source]
get_dataset_collection_instance(trans, instance_type, id, **kwds)[source]
history_dataset_collections(history, query)[source]
match_collections(collections_to_match)[source]

May seem odd to place it here, but planning to grow sophistication and get plugin types involved so it will likely make sense in the future.

update(trans, instance_type, id, payload)[source]

collections_util Module

galaxy.managers.collections_util.api_payload_to_create_params(payload)[source]

Cleanup API payload to pass into dataset_collections.

galaxy.managers.collections_util.dictify_dataset_collection_instance(dataset_colleciton_instance, parent, security, view='element')[source]
galaxy.managers.collections_util.dictify_element(element)[source]
galaxy.managers.collections_util.validate_input_element_identifiers(element_identifiers)[source]

Scan through the list of element identifiers supplied by the API consumer and verify the structure is valid.

context Module

Mixins for transaction-like objects.

class galaxy.managers.context.ProvidesAppContext[source]

Bases: object

For transaction-like objects to provide Galaxy convience layer for database and event handling.

Mixed in class must provide app property.

expunge_all()[source]
get_toolbox()[source]

Returns the application toolbox

install_model
log_action(user=None, action=None, context=None, params=None)[source]

Application-level logging of user actions.

log_event(message, tool_id=None, **kwargs)[source]

Application level logging. Still needs fleshing out (log levels and such) Logging events is a config setting - if False, do not log.

model
request_types()[source]
sa_session

Returns a SQLAlchemy session – currently just gets the current session from the threadlocal session context, but this is provided to allow migration toward a more SQLAlchemy 0.4 style of use.

class galaxy.managers.context.ProvidesHistoryContext[source]

Bases: object

For transaction-like objects to provide Galaxy convience layer for reasoning about histories.

Mixed in class must provide user, history, and app properties.

db_builds

Returns the builds defined by galaxy and the builds defined by the user (chromInfo in history).

db_dataset_for(dbkey)[source]

Returns the db_file dataset associated/needed by dataset, or None.

class galaxy.managers.context.ProvidesUserContext[source]

Bases: object

For transaction-like objects to provide Galaxy convience layer for reasoning about users.

Mixed in class must provide user, api_inherit_admin, and app properties.

anonymous
get_current_user_roles()[source]
user_can_do_run_as()[source]
user_ftp_dir
user_is_admin()[source]

folders Module

Manager and Serializer for Library Folders.

class galaxy.managers.folders.FolderManager[source]

Bases: object

Interface/service object for interacting with folders.

can_add_item(trans, folder)[source]

Return true if the user has permissions to add item to the given folder.

check_accessible(trans, folder)[source]

Check whether the folder is accessible to current user. By default every folder is accessible (contents have their own permissions).

check_manageable(trans, folder)[source]

Check whether the user can manage the folder.

Returns:the original folder
Return type:LibraryFolder
Raises:AuthenticationRequired, InsufficientPermissionsException
create(trans, parent_folder_id, new_folder_name, new_folder_description='')[source]

Create a new folder under the given folder.

Parameters:
  • parent_folder_id (int) – decoded id
  • new_folder_name (str) – name of the new folder
  • new_folder_description (str) – description of the folder (optional, defaults to empty string)
Returns:

the new folder

Return type:

LibraryFolder

Raises:

InsufficientPermissionsException

cut_and_decode(trans, encoded_folder_id)[source]

Cuts the folder prefix (the prepended ‘F’) and returns the decoded id.

cut_the_prefix(encoded_folder_id)[source]

Remove the prefix from the encoded folder id.

decode_folder_id(trans, encoded_folder_id)[source]

Decode the folder id given that it has already lost the prefixed ‘F’.

delete(trans, folder, undelete=False)[source]

Mark given folder deleted/undeleted based on the flag.

Raises:ItemAccessibilityException
get(trans, decoded_folder_id, check_manageable=False, check_accessible=True)[source]

Get the folder from the DB.

Parameters:
  • decoded_folder_id (int) – decoded folder id
  • check_manageable (bool) – flag whether the check that user can manage item
  • check_accessible (bool) – flag whether to check that user can access item
Returns:

the requested folder

Return type:

LibraryFolder

get_current_roles(trans, folder)[source]

Find all roles currently connected to relevant permissions on the folder.

Parameters:folder (LibraryFolder) – the model object
Returns:dict of current roles for all available permission types
Return type:dictionary
get_folder_dict(trans, folder)[source]

Return folder data in the form of a dictionary.

Parameters:folder (LibraryFolder) – folder item
Returns:dict with data about the folder
Return type:dictionary
secure(trans, folder, check_manageable=True, check_accessible=True)[source]

Check if (a) user can manage folder or (b) folder is accessible to user.

Parameters:
  • folder (LibraryFolder) – folder item
  • check_manageable (bool) – flag whether to check that user can manage item
  • check_accessible (bool) – flag whether to check that user can access item
Returns:

the original folder

Return type:

LibraryFolder

hdas Module

Manager and Serializer for HDAs.

HistoryDatasetAssociations (HDAs) are datasets contained or created in a history.

class galaxy.managers.hdas.HDAManager[source]

Bases: galaxy.managers.base.ModelManager

Interface/service object for interacting with HDAs.

can_access_dataset(trans, hda)[source]

Use security agent to see if current user has access to dataset.

check_accessible(trans, hda)[source]

Raise error if HDA is not accessible.

check_ownership(trans, hda)[source]

Use history to see if current user owns HDA.

err_if_uploading(trans, hda)[source]

Raise error if HDA is still uploading.

get(trans, unencoded_id, check_ownership=True, check_accessible=True)[source]

Get an HDA by its unencoded db id, checking ownership (via its history) or accessibility (via dataset shares/permissions).

get_display_apps(trans, hda)[source]

Return dictionary containing new-style display app urls.

get_hda_dict(trans, hda)[source]

Return full details of this HDA in dictionary form.

get_hda_dict_with_error(trans, hda=None, history_id=None, id=None, error_msg='Error')[source]

Return truncated serialization of HDA when error raised getting details.

get_inaccessible_hda_dict(trans, hda)[source]

Return truncated serialization of HDA when inaccessible to user.

get_old_display_applications(trans, hda)[source]

Return dictionary containing old-style display app urls.

secure(trans, hda, check_ownership=True, check_accessible=True)[source]

check ownership (via its history) or accessibility (via dataset shares/permissions).

class galaxy.managers.hdas.HistorySerializer[source]

Bases: galaxy.managers.base.ModelSerializer

Interface/service object for serializing HDAs into dictionaries.

histories Module

Manager and Serializer for histories.

Histories are containers for datasets or dataset collections created (or copied) by users over the course of an analysis.

class galaxy.managers.histories.HistoryManager(*args, **kwargs)[source]

Bases: galaxy.managers.base.ModelManager

Interface/service object for interacting with HDAs.

by_user(trans, user=None, include_deleted=False, only_deleted=False)[source]

Get all the histories for a given user (defaulting to trans.user) ordered by update time and filtered on whether they’ve been deleted.

check_accessible(trans, history)[source]

Raises error if the current user can’t access the history.

check_ownership(trans, history)[source]

Raises error if the current user is not the owner of the history.

get(trans, unencoded_id, check_ownership=True, check_accessible=True, deleted=None)[source]

Get a History from the database by id, verifying ownership.

get_history_dict(trans, history, contents_dictionaries=None)[source]

Returns history data in the form of a dictionary.

is_accessible(trans, history)[source]

True if the user can access (read) the current history.

is_current(trans, history)[source]

True if the given history is the user’s current history.

Returns False if the session has no current history.

is_owner(trans, history)[source]

True if the current user is the owner of the given history.

most_recent(trans, user=None, deleted=False)[source]
secure(trans, history, check_ownership=True, check_accessible=True)[source]

Checks if (a) user owns item or (b) item is accessible to user.

class galaxy.managers.histories.HistorySerializer[source]

Bases: galaxy.managers.base.ModelSerializer

Interface/service object for serializing histories into dictionaries.

lddas Module

class galaxy.managers.lddas.LDDAManager[source]

Bases: galaxy.managers.base.ModelManager

A fairly sparse manager for LDDAs.

get(trans, id, check_accessible=True)[source]

libraries Module

Manager and Serializer for libraries.

class galaxy.managers.libraries.LibraryManager(*args, **kwargs)[source]

Bases: object

Interface/service object for interacting with libraries.

check_accessible(trans, library)[source]

Check whether the library is accessible to current user.

create(trans, name, description='', synopsis='')[source]

Create a new library.

delete(trans, library, undelete=False)[source]

Mark given library deleted/undeleted based on the flag.

get(trans, decoded_library_id, check_accessible=True)[source]

Get the library from the DB.

Parameters:
  • decoded_library_id (int) – decoded library id
  • check_accessible (bool) – flag whether to check that user can access item
Returns:

the requested library

Return type:

Library

get_access_roles(trans, library)[source]

Load access roles for all library permissions

get_add_roles(trans, library)[source]

Load add roles for all library permissions

get_current_roles(trans, library)[source]

Load all permissions currently related to the given library.

Parameters:library (Library) – the model object
Return type:dictionary
Returns:dict of current roles for all available permission types
get_library_dict(trans, library)[source]

Return library data in the form of a dictionary.

Parameters:library (Library) – library
Returns:dict with data about the library
Return type:dictionary
get_manage_roles(trans, library)[source]

Load manage roles for all library permissions

get_modify_roles(trans, library)[source]

Load modify roles for all library permissions

is_public(trans, library)[source]

Return true if lib is public.

list(trans, deleted=False)[source]

Return a list of libraries from the DB.

Parameters:deleted (boolean (optional)) – if True, show only deleted libraries, if False show only non-deleted
Returns:query that will emit all accessible libraries
Return type:sqlalchemy query
make_public(trans, library)[source]

Makes the given library public (removes all access roles)

secure(trans, library, check_accessible=True)[source]

Check if library is accessible to user.

Parameters:
  • folder (Library) – library
  • check_accessible (bool) – flag whether to check that user can access library
Returns:

the original folder

Return type:

LibraryFolder

set_permission_roles(trans, library, access_roles, modify_roles, manage_roles, add_roles)[source]

Set permissions on the given library.

update(trans, library, name=None, description=None, synopsis=None)[source]

Update the given library

roles Module

Manager and Serializer for Roles.

class galaxy.managers.roles.RoleManager[source]

Bases: object

Interface/service object for interacting with folders.

get(trans, decoded_role_id)[source]

Method loads the role from the DB based on the given role id.

Parameters:decoded_role_id (int) – id of the role to load from the DB
Returns:the loaded Role object
Return type:Role
Raises:InconsistentDatabase, RequestParameterInvalidException, InternalServerError

tags Module

class galaxy.managers.tags.TagsManager(app)[source]

Bases: object

Manages CRUD operations related to tagging objects.

set_tags_from_list(trans, item, new_tags_list, user=None)[source]

workflows Module

class galaxy.managers.workflows.WorkflowsManager(app)[source]

Bases: object

Handle CRUD type operaitons related to workflows. More interesting stuff regarding workflow execution, step sorting, etc... can be found in the galaxy.workflow module.

build_invocations_query(trans, decoded_stored_workflow_id)[source]
cancel_invocation(trans, decoded_invocation_id)[source]
check_security(trans, has_workflow, check_ownership=True, check_accessible=True)[source]

check accessibility or ownership of workflows, storedworkflows, and workflowinvocations. Throw an exception or returns True if user has needed level of access.

get_invocation(trans, decoded_invocation_id)[source]
get_invocation_step(trans, decoded_workflow_invocation_step_id)[source]
update_invocation_step(trans, decoded_workflow_invocation_step_id, action)[source]