Exemple #1
0
def update_user_password():
    if request.data:
        try:
            payload = json.loads(request.data)
            email = payload["email"]
            username = payload["username"]
            password = payload["password"]
            new_password = payload["newPassword"]
            existing_user = User.query.filter_by(email=email).first()
            if existing_user is not None:
                if existing_user.username == username and existing_user.password == password:
                    existing_user.update(new_password)
                    status_text = "User password updated"
                    return jsonify(statusText=status_text)
                else:
                    status_text = "Can't authenticate user"
                    response = jsonify(statusText=status_text)
                    response.status_code = 400
                    return response
            else:
                status_text = "No such user exists"
                response = jsonify(statusText=status_text)
                response.status_code = 404
                return response
        except KeyError:
            pass
    return QuickJson.invalid_json()
Exemple #2
0
def delete_user():
    # TODO: upon deleting a user, we need to delete all data associated with that user
    if request.data:
        try:
            payload = json.loads(request.data)
            email = payload["email"]
            username = payload["username"]
            password = payload["password"]
            existing_user = User.query.filter_by(email=email).first()
            if existing_user is not None:
                if existing_user.username == username and existing_user.password == password:
                    existing_user.delete()
                    status_text = "User deleted"
                    return jsonify(statusText=status_text)
                else:
                    status_text = "Can't authenticate user"
                    response = jsonify(statusText=status_text)
                    response.status_code = 400
                    return response
            else:
                status_text = "No such user exists"
                response = jsonify(statusText=status_text)
                response.status_code = 404
                return response
        except KeyError:
            pass
    return QuickJson.invalid_json()
Exemple #3
0
def validate_user():
    if request.data:
        try:
            payload = json.loads(request.data)
            email = payload["email"]
            password = payload["password"]
            existing_user = User.query.filter_by(email=email).first()
            if existing_user is not None:
                if existing_user.password == password:
                    username = existing_user.username
                    status_text = "User exists"
                    return jsonify(username=username, statusText=status_text)
                else:
                    status_text = "Invalid password"
                    response = jsonify(statusText=status_text)
                    response.status_code = 400
                    return response
            else:
                status_text = "No such user exists"
                response = jsonify(statusText=status_text)
                response.status_code = 404
                return response
        except KeyError:
            pass
    return QuickJson.invalid_json()
Exemple #4
0
def create_ticket():
    if request.data:
        try:
            payload = json.loads(request.data)
            ticket_name = payload['ticketName']
            owner = payload['owner']
            project = payload['projectName']
            description = payload['description']
            existing_ticket = Ticket.query.filter_by(ticket_name=ticket_name, owner=owner, associated_project=project).first()
            if existing_ticket == None:
                new_ticket = Ticket(ticket_name, owner, description, project)
                new_ticket.create()
                status_text = "Ticket created succesfully"
                response = jsonify(statusText=status_text)
                response.status_code = 200
                return response
            else:
                status_text = "Ticket already exists"
                response = jsonify(statusText=status_text)
                response.status_code = 400
                return response
        except KeyError:
            pass
    return QuickJson.invalid_json()
                
    pass
Exemple #5
0
def add_project_members():
    """" Endpoint that is used to add members to a project """
    if request.data:
        try:
            payload = json.loads(request.data)
            project_name = payload["projectName"]
            owner = payload["owner"]
            member = payload["member"]
            # TODO: Check to see if user is already a part of the project
            # TODO: Query Project to get the id of the project and Query User to get id of member
        except KeyError:
            pass
    return QuickJson.invalid_json()
Exemple #6
0
def get_project():
    if request.data:
        try:
            payload = json.loads(request.data)
            owner = payload["owner"]
            all_projects = Project.query.filter_by(owner=owner).all()
            if all_projects is not None:
                return json.dumps(Project.decompose(all_projects))
            else:
                status_text = "This user has no projects"
                response = jsonify(statusText=status_text)
                response.status_code = 404
                return response
        except KeyError:
            pass
    return QuickJson.invalid_json()
Exemple #7
0
def delete_project():
    if request.data:
        try:
            payload = json.loads(request.data)
            project_name = payload["projectName"]
            owner = payload["owner"]
            project = Project.query.filter_by(project_name=project_name, owner=owner).first()
            if project is not None:
                project.delete()
                status_text = "Project deleted"
                return jsonify(statusText=status_text)
            else:
                status_text = "The project " + project_name + " doesn't exist"
                response = jsonify(statusText=status_text)
                response.status_code = 404
                return response
        except KeyError:
            pass
    return QuickJson.invalid_json()
Exemple #8
0
def delete_ticket():
    if request.data:
        try:
            payload = json.loads(request.data)
            ticket_name = payload["ticketName"]
            owner = payload["owner"]
            ticket = Ticket.query.filter_by(ticket_name=ticket_name, owner=owner).first()
            if ticket is not None:
                ticket.delete()
                status_text = "ticket deleted"
                return jsonify(statusText=status_text)
            else:
                status_text = "Ticket does not exist"
                response = jsonify(statusText=status_text)
                response.status_code = 404
                return response
        except KeyError:
            pass
    return QuickJson.invalid_json()
Exemple #9
0
def create_project():
    if request.data:
        try:
            payload = json.loads(request.data)
            project_name = payload["projectName"]
            owner = payload["owner"]
            existing_project = Project.query.filter_by(project_name=project_name, owner=owner).first()
            if existing_project is None:
                new_project = Project(project_name, owner)
                new_project.create()
                status_text = "Project succesfully added"
                response = jsonify(statusText=status_text)
                response.status_code = 200
                return response
            else:
                status_text = "Project with name of " + project_name + " already exists"
                response = jsonify(statusText=status_text)
                response.status_code = 400
                return response
        except KeyError:
            pass
    return QuickJson.invalid_json()
Exemple #10
0
def create_user():
    if request.data:
        try:
            payload = json.loads(request.data)
            email = payload["email"]
            username = payload["username"]
            password = payload["password"]
            existing_user = User.query.filter_by(email=email).first()
            if existing_user is None:
                new_user = User(email, username, password)
                new_user.create()
                status_text = "User succesfully added"
                response = jsonify(statusText=status_text)
                response.status_code = 200
                return response
            else:
                status_text = "User already exists"
                response = jsonify(statusText=status_text)
                response.status_code = 400
                return response
        except KeyError:
            pass
    return QuickJson.invalid_json()
Exemple #11
0
@app.route("/get-ticket", methods=["POST"])
def get_ticket():
    if request.data:
        payload = json.loads(request.data)
        project = payload["associated_project"]
        all_tickets = Ticket.query.filter_by(associated_project=project).all()
        if all_tickets is not None:
            return json.dumps(Ticket.decompose(all_tickets))
        else:
            status_text = "This project has no tickets"
            response = jsonify(status_text=status_text)
            response.status_code = 404
            return response
    except KeyError:
        pass
    return QuickJson.invalid_json()


@app.route("/get-comment", methods=["POST"])
def get_comment():
    pass


@app.route("/get-team", methods=["POST"])
def get_team():
    pass


""" PUT """