Ejemplo n.º 1
0
 def get_issue(self, issueId: str):
     result = self.db.collection(
         properties.issuesPath).document(issueId).get()
     if result.to_dict() is None:
         return None
     issue = Issue(result.to_dict())
     issue.id = result.id
     return issue
Ejemplo n.º 2
0
def create():
    args = list(request.form.values())
    issue = Issue(email=args[0],
                  description=args[1],
                  category_id=args[2],
                  status_id=args[3])
    dbSession.add(issue)
    dbSession.commit()
    return redirect(url_for("issue_index"))
Ejemplo n.º 3
0
def create(data, repo):
    user = users_service.get(data['user']['id'])
    if user is None:
        user = users_service.create(data['user'])
        db.session.add(user)
    issue = Issue(user, repo, data)
    db.session.add(issue)
    for topic in issue.topics:
        topics_service.update_issues_count(topic)
    return issue
Ejemplo n.º 4
0
def new_issue():
    try:
        data = request.get_json()
        if "issue" in data:
            issue = Issue(data["issue"]).to_dict(remove_id=True)
            issue_ref = firestore_service.create_issue(issue)
            resp = make_response(jsonify({"id": issue_ref}), 200)
        else:
            resp = make_response(jsonify({"error": "not enough args"}), 400)
        return resp
    except Exception as e:
        logging.info("Creating issue triggered the below error :")
        logging.info(e)
        resp = make_response(jsonify({}), 500)
        return resp
Ejemplo n.º 5
0
def new_issue():
    """Report an issue with a car if the user making the report is an admin.
    Also send notifications to all engineers via pushbullet that an issue has
    been reported

    .. :quickref: Issue; Report a new issue.

    **Example request**:

    .. sourcecode:: http

        POST /api/issue HTTP/1.1
        Host: localhost
        Accept: application/json
        Content-Type: application/json

        {
            "car_id": 1,
            "username": "******",
            "details": "Broken tail light"
        }

    **Example response**:

    .. sourcecode:: http

        HTTP/1.1 200 OK
        Content-Type: application/json

        {
            "message": "Success"
        }

    .. sourcecode:: http

        HTTP/1.1 401 UNAUTHORIZED
        Content-Type: application/json

        {
            "message": {
                "user": ["User is not an admin."]
            }
        }

    :<json int car_id: the make of the car being updated
    :<json string username: the username of the person reporting the issue
    :<json string details: details of what the issue may be
    :resheader Content-Type: application/json
    :status 200: creating a new issue was successful
    :status 400: missing or invalid fields
    :status 401: user is not an admin
    """

    response = {
        'message': '',
    }
    status = 200

    form_schema = ReportIssueFormSchema()
    form_errors = form_schema.validate(request.json)
    if form_errors:
        response['message'] = form_errors
        status = 400
    else:
        # Checking if user making the request is an admin
        user = User.query.get(request.json["username"])
        if user.role is not Role.admin:
            response['message'] = {'user': ['User is not an admin.']}
            status = 401
        else:
            car_id = request.json["car_id"]
            time = datetime.utcnow()
            details = request.json["details"]

            issue = Issue(car_id, time, details)
            db.session.add(issue)
            db.session.commit()
            response['message'] = "Success"

    if response['message'] == "Success":
        # Notifying every engineer via Pushbullet if they have a token
        engineers = (User.query.filter(User.role == Role.engineer).filter(
            User.pb_token != None).all())
        for engineer in engineers:
            data = {
                "type": "note",
                "title": "Issue with car #" + str(car_id),
                "body": details
            }
            # Making request to pushbullet API
            requests.post('https://api.pushbullet.com/v2/pushes',
                          data=json.dumps(data),
                          headers={
                              'Authorization': 'Bearer ' + engineer.pb_token,
                              'Content-Type': 'application/json'
                          })

    return response, status