'Get an HDA object by id performing security checks using
the current transaction.'

def get_hda(self, trans, dataset_id, check_ownership=True, check_accessible=False, check_state=True):

    try:
        dataset_id = trans.security.decode_id(dataset_id)
    except (AttributeError, TypeError):
        try:
            dataset_id = int(dataset_id)
        except ValueError:
            raise HTTPBadRequest(('Invalid    dataset    id:    %s.' % str(dataset_id)))
    try:
        data = trans.sa_session.query(trans.app.model.HistoryDatasetAssociation).get(int(dataset_id))
    except:
        raise HTTPRequestRangeNotSatisfiable(('Invalid    dataset    id:    %s.' % str(dataset_id)))
    if check_ownership:
        user = trans.get_user()
        if (not user):
            error('Must    be    logged    in    to    manage    Galaxy    items')
        if (data.history.user != user):
            error(('%s    is    not    owned    by    current    user' % data.__class__.__name__))
    if check_accessible:
        current_user_roles = trans.get_current_user_roles()
        if (not trans.app.security_agent.can_access_dataset(current_user_roles, data.dataset)):
            error('You    are    not    allowed    to    access    this    dataset')
        if (check_state and (data.state == trans.model.Dataset.states.UPLOAD)):
            return trans.show_error_message(('Please    wait    until    this    dataset    finishes    uploading    ' + 'before    attempting    to    view    it.'))
    return data
