Esempio n. 1
0
def _do_artifacts_query(context, session, show_level=ga.Showlevel.NONE):
    """Build the query to get all artifacts based on the context"""

    LOG.debug("context.is_admin=%(is_admin)s; context.owner=%(owner)s",
              {'is_admin': context.is_admin, 'owner': context.owner})

    if show_level == ga.Showlevel.NONE:
        query = session.query(models.Artifact).options(
            joinedload(models.Artifact.tags))
    elif show_level == ga.Showlevel.BASIC:
        query = (
            session.query(models.Artifact).
            options(joinedload(
                models.Artifact.properties).
                defer(models.ArtifactProperty.text_value)).
            options(joinedload(models.Artifact.tags)).
            options(joinedload(models.Artifact.blobs).
                    joinedload(models.ArtifactBlob.locations)))
    else:
        # other show_levels aren't supported
        msg = _LW("Show level %s is not supported in this "
                  "operation") % ga.Showlevel.to_str(show_level)
        LOG.warn(msg)
        raise exception.ArtifactUnsupportedShowLevel(shl=show_level)

    # If admin, return everything.
    if context.is_admin:
        return query
    else:
        # If regular user, return only public artifacts.
        # However, if context.owner has a value, return both
        # public and private artifacts of the context.owner.
        if context.owner is not None:
            query = query.filter(
                or_(models.Artifact.owner == context.owner,
                    models.Artifact.visibility == 'public'))
        else:
            query = query.filter(
                models.Artifact.visibility == 'public')
        return query
Esempio n. 2
0
 def from_str(str_value):
     try:
         return Showlevel._level_map[str_value]
     except KeyError:
         raise exception.ArtifactUnsupportedShowLevel()
Esempio n. 3
0
 def to_str(n):
     try:
         return Showlevel._inverted_level_map[n]
     except KeyError:
         raise exception.ArtifactUnsupportedShowLevel()