Warning

This document is for an old release of Galaxy. You can alternatively view this page in the latest release if it exists or view the top of the latest release's documentation.

Source code for galaxy.managers.roles

"""
Manager and Serializer for Roles.
"""
import logging

from sqlalchemy.orm import exc as sqlalchemy_exceptions

import galaxy.exceptions
from galaxy import model
from galaxy.managers import base

log = logging.getLogger(__name__)


[docs]class RoleManager(base.ModelManager): """ Business logic for roles. """ model_class = model.Role foreign_key_name = 'role' user_assoc = model.UserRoleAssociation group_assoc = model.GroupRoleAssociation
[docs] def __init__(self, app): super(RoleManager, self).__init__(app)
[docs] def get(self, trans, decoded_role_id): """ Method loads the role from the DB based on the given role id. :param decoded_role_id: id of the role to load from the DB :type decoded_role_id: int :returns: the loaded Role object :rtype: galaxy.model.Role :raises: InconsistentDatabase, RequestParameterInvalidException, InternalServerError """ try: role = (self.session().query(self.model_class) .filter(self.model_class.id == decoded_role_id).one()) except sqlalchemy_exceptions.MultipleResultsFound: raise galaxy.exceptions.InconsistentDatabase('Multiple roles found with the same id.') except sqlalchemy_exceptions.NoResultFound: raise galaxy.exceptions.RequestParameterInvalidException('No role found with the id provided.') except Exception as e: raise galaxy.exceptions.InternalServerError('Error loading from the database.' + str(e)) return role