コード例 #1
0
def projectPosts(pid):
    if request.method == "GET":
        #Get last posts
        ppid = request.args.get("ppid")
        if ppid == None:
            posts = ProjectPostModel.getLastProjectPosts(
                pid, 10, getCurrentUid())
        else:
            posts = ProjectPostModel.getPreviousProjectPosts(
                pid, ppid, 10, getCurrentUid())

        return json.dumps(posts, cls=DateTimeEncoder)

    elif request.method == "POST" and isLoggedIn():
        if not ProjectModel.isProjectMember(getCurrentUid(), pid):
            return render_template("private-api/forbidden-request.html")

        #Stripping
        data = json.loads(request.data)
        data["post"] = data["post"].strip()

        if data["post"] != "":
            #Add project post
            ProjectPostModel.addProjectPost(getCurrentUid(), pid, data["post"])
            return json.dumps({"result": "success"})
        else:
            return json.dumps({
                "result": "fail",
                "msg": "post cannot be empty"
            })

    elif request.method == "PUT" and isLoggedIn():
        if not ProjectModel.isProjectMember(getCurrentUid(), pid):
            return render_template("private-api/forbidden-request.html")

        #Stripping
        data = json.loads(request.data)
        data["post"] = data["post"].strip()

        #Update project post
        ppid = request.args.get("ppid")

        #Validate
        if data["post"] == "" or ppid == None:
            return json.dumps({
                "result": "fail",
                "msg": "ppid and post cannot be empty"
            })

        post = ProjectPostModel.getProjectPost(ppid)

        if post["uid"] == getCurrentUid():
            ProjectPostModel.updateProjectPost(ppid, data["post"])
            return json.dumps({"result": "success"})
        else:
            return render_template("private-api/forbidden-request.html")

    else:
        #Delete a project post
        ppid = request.args.get("ppid")
        post = ProjectPostModel.getProjectPost(ppid, getCurrentUid())

        if post["uid"] == getCurrentUid() and isLoggedIn():
            ProjectPostModel.removeProjectPost(ppid)
            return json.dumps({"result": "success"})
        else:
            return render_template("private-api/forbidden-request.html")
    return render_template("private-api/unknown-request.html")
コード例 #2
0
def isProjectMember(pid, uid):
    result = ProjectModel.isProjectMember(uid, pid)
    return json.dumps({"result": result})