Exemple #1
0
def projectPhoto(pid):
    project = ProjectModel.getProject(pid)
    if not ProjectModel.isProjectAdmin(getCurrentUid(), pid):
        return render_template("private-api/forbidden-request.html")

    if request.method == "POST":
        size = len(request.data) / 1000000
        if size > 2:
            return json.dumps({
                "result": "fail",
                "msg": "File can not be more than 2 MB"
            })

        newFileName = str(pid) + "_" + generateCode(10) + ".jpg"

        with open(UPLOAD_FOLDER + "/projects/pp/" + newFileName, "wb") as fh:
            fh.write(request.data)
            ProjectModel.updateProjectPhoto(pid, newFileName)

            #Delete old uploaded file
            if project["photo"] != None:
                try:
                    os.remove(UPLOAD_FOLDER + "/projects/pp/" +
                              project["photo"])
                except:
                    print("File couldn't be uploaded.")

            return json.dumps({"result": "success"})
    return json.dumps({"result": "fail"})
Exemple #2
0
def aspireSeater(sid):
    seater = SeaterModel.getSeater(sid)
    if ProjectModel.isProjectAdmin(getCurrentUid(), seater["pid"]):
        SeaterModel.assignUser(getCurrentUid(), sid)
    else:
        SeaterModel.aspireSeater(getCurrentUid(), sid)
    return json.dumps({"result": "success"})
Exemple #3
0
def updateProjectFullDescription(pid):
    if not ProjectModel.isProjectAdmin(getCurrentUid(), pid):
        return render_template("private-api/forbidden-request.html")

    description = json.loads(request.data)["description"]

    ProjectModel.updateFullDescription(pid, description)
    return json.dumps({"result": "success"})
Exemple #4
0
def removeSeater(sid):
    seater = SeaterModel.getSeater(sid)
    if seater != None:
        if ProjectModel.isProjectAdmin(getCurrentUid(), seater["pid"]):
            SeaterModel.removeSeater(sid)
            return json.dumps({"result": "success"})
        else:
            return render_template("private-api/forbidden-request.html")
    return render_template("private-api/unknown-request.html")
Exemple #5
0
def projectLinks(pid):
    if request.method == "GET":
        #Getting all project's links
        links = ProjectModel.getProjectLinks(pid)
        return json.dumps(links, cls=DateTimeEncoder)
    elif request.method == "POST":
        #Stripping
        data = json.loads(request.data)
        data["name"] = data["name"].strip()
        data["link"] = data["link"].strip()

        #Adding new project link
        if data["name"] != "" and data["link"] != "":
            plid = ProjectModel.addProjectLink(pid, data["name"], data["link"])
            return json.dumps({"result": "success", "plid": plid})

    elif request.method == "PUT" and isLoggedIn():
        #Updating a user link
        data = json.loads(request.data)
        plid = request.args.get("plid")
        link = ProjectModel.getProjectLink(plid)

        if ProjectModel.isProjectAdmin(getCurrentUid(), pid):
            ProjectModel.updateProjectLink(plid, data["name"], data["link"])
            return json.dumps({"result": "success"})
        else:
            return render_template("private-api/forbidden-request.html")

    else:
        #Delete a user link
        #DELETE request

        plid = request.args.get("plid")
        link = ProjectModel.getProjectLink(plid)

        if isLoggedIn() and ProjectModel.isProjectAdmin(
                getCurrentUid(), link["pid"]):
            ProjectModel.removeProjectLink(plid)
            return json.dumps({"result": "success"})
        else:
            return render_template("private-api/forbidden-request.html")
    return render_template("private-api/unknown-request.html")
Exemple #6
0
def updateProjectName(pid, newName):
    if not ProjectModel.isProjectAdmin(getCurrentUid(), pid):
        return render_template("private-api/forbidden-request.html")

    if not isValidProjectName(newName):
        return json.dumps({
            "result": "fail",
            "msg": "Project name is not valid"
        })

    ProjectModel.updateProjectName(pid, newName)
    return json.dumps({"result": "success"})
Exemple #7
0
def assignUser(sid, uid):
    seater = SeaterModel.getSeater(sid)

    if seater != None:
        if ProjectModel.isProjectAdmin(getCurrentUid(), seater["pid"]):
            if SeaterModel.isThereSeaterAspiration(uid, sid):
                SeaterModel.assignUser(uid, sid)
                return json.dumps({"result": "success"})
        else:
            return render_template("private-api/forbidden-request.html")

    return render_template("private-api/unknown-request.html")
Exemple #8
0
def seaterPage(projectName, sid):
  project = ProjectModel.getProjectByProjectName(projectName)
  seater = SeaterModel.getSeater(sid, getCurrentUid())
  seater["skills"] = SkillModel.getSeaterSkills(sid)
  assignedUser = UserModel.getUser(seater["uid"])
  seater["isProjectAdmin"] = ProjectModel.isProjectAdmin(getCurrentUid(), project["pid"])

  return render_template(
    "seater-page.html",
    currentUser= getCurrentUser(),
    seater = seater,
    assignedUser = assignedUser
  )
Exemple #9
0
def dismissUserFromSeater(sid):
    seater = SeaterModel.getSeater(sid)

    if seater != None:
        if ProjectModel.isProjectAdmin(getCurrentUid(),
                                       seater["pid"]) or (seater["uid"]
                                                          == getCurrentUid()):
            SeaterModel.dismissUser(sid)
            SeaterModel.cancelAspirationToTheSeater(seater["uid"], sid)
            return json.dumps({"result": "success"})
        else:
            return render_template("private-api/forbidden-request.html")

    return render_template("private-api/unknown-request.html")
Exemple #10
0
def saveSeater(pid):
    if ProjectModel.isProjectAdmin(getCurrentUid(), pid):
        seater = json.loads(request.data)
        seater["pid"] = pid

        if request.method == "POST":
            # Create seater

            sid = SeaterModel.createSeater(pid, seater)

            #Add skills
            for skill in seater["skills"]:
                SkillModel.addSeaterSkill(sid, skill)

            return json.dumps({"result": "success", "sid": sid})
        else:
            # Update seater

            SeaterModel.updateSeater(seater["sid"], seater)

            # Get current skills
            currentSkills = [
                i["name"] for i in SkillModel.getSeaterSkills(seater["sid"])
            ]

            skillsToDelete = set(currentSkills).difference(
                set(seater["skills"]))
            skillToAdd = set(seater["skills"]).difference(set(currentSkills))

            # Delete skills
            for skill in skillsToDelete:
                skill.strip()
                if skill != None and skill != "":
                    SkillModel.removeSeaterSkill(seater["sid"], skill)

            # Add skills
            for skill in skillToAdd:
                skill.strip()
                if skill != None and skill != "":
                    SkillModel.addSeaterSkill(seater["sid"], skill)

            return json.dumps({"result": "success"})

    return render_template("private-api/forbidden-request.html")
Exemple #11
0
def seaterSkills():
    if request.method == "GET":
        #Get seater skills
        sid = request.args.get("sid")

        if sid != None:
            skills = SkillModel.getUserSkills(getCurrentUid)
            return json.dumps(skills, cls=DateTimeEncoder)
        return render_template("private-api/unknown-request.html")

    elif request.method == "POST" and isLoggedIn():
        #Add seater skill
        sid = request.args.get("sid")
        skill = request.args.get("skill")

        pid = SeaterModel.getSeater(sid)["pid"]

        if ProjectModel.isProjectAdmin(getCurrentUid(), pid):
            if skill != None:
                SkillModel.addSeaterSkill(sid, skill)
                return json.dumps({"result": "success"})

    else:
        #Delete a user skill
        skid = request.args.get("skid")

        if skid != None and isLoggedIn():
            skill = SkillModel.getUserSkill(skid)

            if skill["uid"] == getCurrentUid():
                SkillModel.removeUserSkill(skid)
                return json.dumps({"result": "success"})
            else:
                return render_template("private-api/forbidden-request.html")

    return render_template("private-api/unknown-request.html")
Exemple #12
0
def seaterAspirationNumber(sid):
    seater = SeaterModel.getSeater(sid)
    if ProjectModel.isProjectAdmin(getCurrentUid(), seater["pid"]):
        number = SeaterModel.getSeaterAspirationNumber(sid)
        return json.dumps({"number": number})
    return render_template("private-api/forbidden-request.html")
Exemple #13
0
def seaterAspirations(sid):
    seater = SeaterModel.getSeater(sid)
    if ProjectModel.isProjectAdmin(getCurrentUid(), seater["pid"]):
        aspirations = SeaterModel.getSeaterAspirations(sid)
        return json.dumps(aspirations, cls=DateTimeEncoder)
    return render_template("private-api/forbidden-request.html")
Exemple #14
0
def isProjectAdmin(pid, uid):
    result = ProjectModel.isProjectAdmin(uid, pid)
    return json.dumps({"result": result})