Example #1
0
def get_object(trans,
               id,
               class_name,
               check_ownership=False,
               check_accessible=False,
               deleted=None):
    """
    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.
    """
    decoded_id = decode_id(trans.app, id)
    try:
        item_class = get_class(class_name)
        assert item_class is not None
        item = trans.sa_session.query(item_class).get(decoded_id)
        assert item is not None
    except Exception:
        log.exception("Invalid %s id ( %s ) specified." % (class_name, id))
        raise exceptions.MessageException("Invalid %s id ( %s ) specified" %
                                          (class_name, id),
                                          type="error")

    if check_ownership or check_accessible:
        security_check(trans, item, check_ownership, check_accessible)
    if deleted is True and not item.deleted:
        raise exceptions.ItemDeletionException(
            '%s "%s" is not deleted' % (class_name, getattr(item, 'name', id)),
            type="warning")
    elif deleted is False and item.deleted:
        raise exceptions.ItemDeletionException(
            '%s "%s" is deleted' % (class_name, getattr(item, 'name', id)),
            type="warning")
    return item
Example #2
0
    def get(self,
            trans,
            unencoded_id,
            check_ownership=True,
            check_accessible=True,
            deleted=None):
        """
        Get a History from the database by id, verifying ownership.
        """
        # this is a replacement for UsesHistoryMixin because mixins are a bad soln/structure
        history = trans.sa_session.query(
            trans.app.model.History).get(unencoded_id)
        if history is None:
            raise exceptions.ObjectNotFound()
        if deleted is True and not history.deleted:
            raise exceptions.ItemDeletionException(
                'History "%s" is not deleted' % (history.name), type="error")
        elif deleted is False and history.deleted:
            raise exceptions.ItemDeletionException('History "%s" is deleted' %
                                                   (history.name),
                                                   type="error")

        history = self.secure(trans, history, check_ownership,
                              check_accessible)
        return history
Example #3
0
 def undelete(self, user, flush=True):
     """Remove the deleted flag for the given user."""
     if not self.app.config.allow_user_deletion:
         raise exceptions.ConfigDoesNotAllowException('The configuration of this Galaxy instance does not allow admins to undelete users.')
     if user.purged:
         raise exceptions.ItemDeletionException('Purged user cannot be undeleted.')
     super(UserManager, self).undelete(user, flush=flush)
Example #4
0
 def __api_import_shared_workflow(self, trans, workflow_id, payload, **kwd):
     try:
         stored_workflow = self.get_stored_workflow(trans, workflow_id, check_ownership=False)
     except Exception:
         raise exceptions.ObjectNotFound("Malformed workflow id ( %s ) specified." % workflow_id)
     if stored_workflow.importable is False:
         raise exceptions.ItemAccessibilityException('The owner of this workflow has disabled imports via this link.')
     elif stored_workflow.deleted:
         raise exceptions.ItemDeletionException("You can't import this workflow because it has been deleted.")
     imported_workflow = self._import_shared_workflow(trans, stored_workflow)
     item = imported_workflow.to_dict(value_mapper={'id': trans.security.encode_id})
     encoded_id = trans.security.encode_id(imported_workflow.id)
     item['url'] = url_for('workflow', id=encoded_id)
     return item