Esempio n. 1
0
def permissionForUser(userId, streamId):
    """
    Returns the permission for a particular stream.
    Parameters:
        userId - a user id.
        streamId - a stream id.
    Returns:
        A permission document.
    """
    return core.single(schema.permissionByUserAndStream, [userId, streamId])
Esempio n. 2
0
def byUniqueName(uniqueName):
    """
    Return the stream with a unique name. Used mainly when using streams
    to support tagging.
    Parameters:
        uniqueName - the unique name for that stream.
    Returns:
        A stream id (string).
    """
    return core.single(schema.streamByUniqueName, uniqueName)
Esempio n. 3
0
def commentStream(id):
    """
    Return the comment stream id for the specified shift.
    Parameters:
        id - a shift id.
    """
    stream = core.single(schema.commentStreams, id)
    if stream:
        return stream["_id"]
    else:
        return None
Esempio n. 4
0
def readFull(userName, deleteType=True):
    """
    Return the full data for a user.
    Parameters:
        userName - the user name.
        deleteType - delete the type field from the dictionary
            to be returned.
    Returns:
        a dictionary containing all the data for a user.
    """
    theUser = core.single(schema.userByName, userName)
    if theUser and deleteType:
        del theUser["type"]
    return theUser
Esempio n. 5
0
def shifts(byHref, userId=None, byFollowing=False, byGroups=False, start=0, perPage=25):
    """
    Returns a list of shifts based on whether
        1. href
        3. By public streams specified user is following. 
        4. By groups streams specified user is following.
    Parameters:
        byHref - a url
        byDomain - a url string
        byFollowing - a user id
        byGroups - a user id
    Returns:
        A list of shifts that match the specifications.
    """
    db = core.connect()
    # NOTE: to prevent errors on a newly created DB - David 9/11/09
    if core.single(schema.statsCount, "shift") == None:
        return []
    lucene = core.lucene()
    # TODO: validate byHref - David
    queryString = "(href:\"%s\" AND draft:false AND private:false)" % byHref
    if userId:
        queryString = queryString + " OR createdBy:%s" % userId
        streams = ""
        if byFollowing:
            following = user.followStreams(userId)
            streams = streams + " ".join(following)
        if byGroups:
            groups = user.groupStreams(userId)
            streams = streams + " ".join(groups)
        # TODO: make sure streams cannot be manipulated from client - David
        queryString = queryString + ((" OR (draft:false%s)" % ((len(streams) > 0 and (" AND streams:%s" % streams)) or "")))
    rows = lucene.search("shifts", q=queryString, sort="\modified", skip=start, limit=perPage)

    shifts = [db[row["id"]] for row in rows]
    return shifts
Esempio n. 6
0
def byShortName(shortName):
    return core.single(schema.groupByShortName, shortName)
Esempio n. 7
0
def favoriteCount(id):
    return core.single(schema.favoritesByShift, id) or 0