Exemplo n.º 1
0
def save_comment():
    post_json = request.get_json()
    tsk_id = None
    comment = None
    resp = {}
    resp_json = jsonify({})

    if "tsk_id" in post_json:
        tsk_id = post_json["tsk_id"]
    if "comment" in post_json:
        comment = post_json["comment"]
    
    if tsk_id and comment:
        is_exp_date_in_session_valid, tsk_auth = _is_exp_date_in_session_valid(int(tsk_id))
        if is_exp_date_in_session_valid or _is_granted():
            task = Task.query.filter_by(tsk_id=tsk_id).first()
            if task:
                _add_log_item(tsk_id, "comment", comment)
                resp["state"] = "success"
        else:
            resp["state"] = "error"
            resp["msg"] = "Keine Berechtigung!"
    else:
        resp["state"] = "error"
        resp["msg"] = "Keine Task ID angegeben!"

    resp_json = jsonify(resp)

    return resp_json
Exemplo n.º 2
0
def new_qrcode_image(tsk_id):
    qrcode_only = request.args.get('qrcode_only')
    path = Path(current_app.root_path)
    new_token = session.get('NEW_TOKEN', "empty")

    suffix = ""
    if qrcode_only and new_token != "empty":
        suffix = "_qrcode_only"

    if tsk_id:
        # Prüfen ob der Token auch zur Task ID passt.
        # Task ermitteln
        htk = None
        htk = htk_from_token(new_token)
        task_id = None
        task = None
        if htk:
            task_id = htk.htk_tsk_id
            if task_id == int(tsk_id):
                task = Task.query.filter_by(tsk_id=task_id).first()
                if task:
                    is_exp_date_in_session_valid, tsk_auth = _is_exp_date_in_session_valid(int(tsk_id))
                    if is_exp_date_in_session_valid or _is_granted():
                        return send_file("../qr_codes/" + new_token + suffix + ".png", mimetype='image/png')
                    else:
                        return send_file(str(path.parent.absolute()) + "/qr_codes/empty.png", mimetype='image/png')
                else:
                    return send_file(str(path.parent.absolute()) + "/qr_codes/empty.png", mimetype='image/png')
            else:
                return send_file(str(path.parent.absolute()) + "/qr_codes/empty.png", mimetype='image/png')
        else:
            return send_file(str(path.parent.absolute()) + "/qr_codes/empty.png", mimetype='image/png')
    else:
        return send_file(str(path.parent.absolute()) + "/qr_codes/empty.png", mimetype='image/png')
Exemplo n.º 3
0
def change_state():
    post_json = request.get_json()
    tsk_id = None
    new_state = None
    resp = {}
    resp_json = jsonify({})

    if "tsk_id" in post_json:
        tsk_id = post_json["tsk_id"]
    if "new_state" in post_json:
        new_state = post_json["new_state"]
    
    if tsk_id and new_state:
        is_exp_date_in_session_valid, tsk_auth = _is_exp_date_in_session_valid(int(tsk_id))
        if is_exp_date_in_session_valid or _is_granted():
            task = Task.query.filter_by(tsk_id=tsk_id).first()
            if task:
                old_state = task.tsk_state
                task.tsk_state = new_state
                db.session.commit()

                old_state_caption = db.session.query(State.sta_caption).filter(State.sta_name == old_state).first()[0]
                new_state_caption = db.session.query(State.sta_caption).filter(State.sta_name == new_state).first()[0]
                
                _add_log_item(tsk_id, "action", "Status von '" + old_state_caption + "' auf '" + new_state_caption + "' geändert.")
                
                resp["state"] = "success"
        else:
            resp["state"] = "error"
            resp["msg"] = "Keine Berechtigung!"
    else:
        resp["state"] = "error"
        resp["msg"] = "Keine Task ID angegeben!"

    resp_json = jsonify(resp)

    return resp_json
Exemplo n.º 4
0
def task():
    tsk_id = None
    task = None
    resp = {}
    resp_json = jsonify({})
    new_task_indicator = False
    
    tsk_id = request.args.get('tsk_id')
    new_task_indicator = request.args.get('new_task_indicator')

    if tsk_id:
        task = Task.query.filter_by(tsk_id=tsk_id).first()
        if task:
            resp['writeable'] = False
            resp['tsk_id'] = task.tsk_id
            resp['dev_name'] = task.device.dev_name
            resp['dev_mnf_name'] = task.device.dev_mnf_name
            resp['dev_category'] = task.device.dev_category
            resp['tsk_fault_description'] = task.tsk_fault_description

            is_exp_date_in_session_valid, tsk_auth = _is_exp_date_in_session_valid(task.tsk_id)
            
            is_granted = _is_granted()
            if is_exp_date_in_session_valid or is_granted:
                resp['cus_first_name'] = task.customer.cus_first_name
                resp['cus_last_name'] = task.customer.cus_last_name
                resp['cus_phone'] = task.customer.cus_phone_no
                resp['cus_email'] = task.customer.cus_email
                resp['tsk_auth'] = tsk_auth
                resp['tsk_state'] = task.tsk_state
                resp['tsk_next_step'] = task.tsk_next_step

                state = State.query.filter_by(sta_name=task.tsk_state).first()
                next_step = Step.query.filter_by(ste_name=task.tsk_next_step).first()
                resp['tsk_state_caption'] = state.sta_caption
                resp['tsk_next_step_caption'] = next_step.ste_caption
                
                resp['tsk_auth'] = tsk_auth

                if(tsk_auth == 'dev' or is_granted):
                    resp['writeable'] = True
                    resp['hash_tokens'] = [{
                    'htk_id': item.htk_id,
                    'htk_auth': item.htk_auth,
                    'htk_creation_date': item.htk_creation_date.strftime("%d.%m.%Y")}
                    for item in task.hash_tokens]
                    if task.log_list:
                        log_list = []
                        for d in task.log_list:
                            user_name = ""
                            if d.user:
                                user_name = d.user.usr_name
                            log_tuple = (d.log_type, d.log_msg, user_name, d.log_timestamp.strftime("%d.%m.%Y"))
                            log_list.append(log_tuple)
                        resp['log_list'] = log_list

                if new_task_indicator:
                    resp['new_token'] = session.get('NEW_TOKEN', None)
            else:
                resp['writeable'] = False
  
        else:
            resp["state"] = "error"
            resp["msg"] = "Task nicht gefunden!"
    else:
        resp["state"] = "error"
        resp["msg"] = "Keine Task ID angegeben!"

    resp_json = jsonify(resp)

    return resp_json