示例#1
0
def byUserName(userName, userId=None):
    """
    Return the list of shifts a user has created.
    Parameters:
        userName - a user name.
    Returns:
        A list of the user's shifts.
    """
    id = user.idForName(userName)
    return core.query(schema.shiftByUser, id)
示例#2
0
def publish(id, publishData):
    """
    Set draft status of a shift to false. Sync publishData field.
    If the shift is private only publish to the streams that
    the user has access. If the shift is publich publish it to
    any of the public non-user streams. Creates the comment stream
    if it doesn't already exist.
    Parameters:
        id - a shift id.
        publishData - a dictionary holding the publish options.
    """
    db = core.connect()
    theShift = db[id]
    theUser = db[theShift["createdBy"]]
    userId = theUser["_id"]
    allowed = []
    publishStreams = publishData.get("streams") or []
    if (publishData.get("private") == True) or (publishData.get("private") == None and isPrivate(id)):
        allowedStreams = permission.writeableStreams(userId)
        allowed = list(set(allowedStreams).intersection(set(publishStreams)))
        # add any private user streams this shift is directed to
        if publishData.get("users"):
            allowed.extend([user.privateStream(user.idForName(userName)) 
                            for userName in publishData["users"]
                            if user.read(userName)])
            del publishData["users"]
        # add streams this user can post to
        allowed.extend([astream for astream in publishStreams
                        if stream.canPost(astream, userId)])
    else:
        allowed.append(user.publicStream(userId))
    # TODO: commentStreams should use the permission of the streams the shift has been published to. -David 7/14/09
    if not commentStream(id):
        streamId = createCommentStream(id)
        user.addNotification(userId, streamId)
        
    # remove duplicates
    publishData["streams"] = list(set(allowed))
    newData = theShift["publishData"]
    newData.update(publishData)
    theShift["publishData"] = newData
    theShift["publishData"]["draft"] = False
    db[id] = theShift