Exemplo n.º 1
0
    def post(self):
        """
        Returns a answer on a question.
        * Privileges required: **none**
        """
        data = request.json
        data_q = data.get('question')
        intent = intent_classifier.predict(data_q)

        if intent == 'Code':
            lang = None
            code_ans, lang = code(data_q, intent, lang)
            if type(lang) != str:
                lang = data.get('question_lang')
                code_ans, lang = code(data_q, intent, lang)
            if type(code_ans) != str:
                result = {}
                result["options"] = [{
                    "answer": code_ans[i],
                    "answer_options": i
                } for i in code_ans]
                return result, 200, security_headers()
            elif type(code_ans) == str and type(lang) != str:
                result = {}
                result["options"] = [{
                    "answer": code_ans,
                    "answer_options": i,
                    "answer_lang": lang[i]
                } for i in lang]
                return result, 200, security_headers()

            else:
                result = {
                    "options": [{
                        "answer": code_ans,
                        "answer_options": 0,
                        "answer_lang": lang
                    }]
                }
                return result, 200, security_headers()

        else:
            result1 = des_sol(data_q, intent)
            if type(result1) != str:
                result = {}
                result["options"] = [{
                    "answer": result1[i],
                    "answer_options": i,
                    "answer_intent": None
                } for i in result1]
                return result, 200, security_headers()
            else:
                result = {
                    "options": [{
                        "answer": result1,
                        "answer_options": 0,
                        "answer_intent": None
                    }]
                }
                return result, 200, security_headers()
Exemplo n.º 2
0
 def get(self):
     """
     Returns list of code example items.
     * Privileges required: **none**
     """
     result = get_code_items()
     return result, 200, security_headers()
 def get(self, id):
     """
     Returns list of question post items.
     * Privileges required: **none**
     """
     result = get_post_items(id)
     return result, 200, security_headers()
Exemplo n.º 4
0
 def get(self, id):
     """
     Returns a kb item.
     * Privileges required: **none**
     """
     result = get_kb_item(id)
     return result, 200, security_headers()
Exemplo n.º 5
0
 def get(self):
     """
     Returns list of kb items.
     * Privileges required: **none**
     """
     result = get_kb_items()
     return result, 200, security_headers()
Exemplo n.º 6
0
 def get(self):
     """
     Returns list of labs.
     * Privileges required: **none**
     """
     result = get_labs()
     return result, 200, security_headers()
Exemplo n.º 7
0
 def put(self, id):
     data = request.json
     val_num(data.get('accessToken'))
     val_alpha_num_special(data.get('username'))
     val_num(id)
     result = activate_user(id, data)
     return result, 200, security_headers()
Exemplo n.º 8
0
 def get(self, id):
     """
     Returns a kb item.
     * Privileges required: **none**
     """
     result = get_kb_item(id)
     return result, 200, security_headers()
Exemplo n.º 9
0
 def get(self):
     """
     Login an anonymous user.
     * Privileges required: **none**
     """
     result = login_skip()
     return result, 200, security_headers()
Exemplo n.º 10
0
 def get(self, id):
     """
     Returns list of question post items.
     * Privileges required: **none**
     """
     result = get_post_items(id)
     return result, 200, security_headers()
 def get(self, maturity):
     """
     Returns list of checklist types.
     * Privileges required: **none**
     """
     result = get_checklist_item_types_with_filter(maturity)
     return result, 200, security_headers()
Exemplo n.º 12
0
 def get(self, id_checklist):
     """
     Returns list of checklist items including the correlated knowledge base items.
     * Privileges required: **none**
     """
     result = get_checklist_items(id_checklist)
     return result, 200, security_headers()
Exemplo n.º 13
0
 def get(self, id_checklist):
     """
     Returns list of checklist items.
     * Privileges required: **none**
     """
     result = get_checklist_items(id_checklist)
     return result, 200, security_headers()
Exemplo n.º 14
0
 def get(self, code_lang):
     """
     Returns a code example item.
     * Privileges required: **none**
     """
     result = get_code_items_lang(code_lang)
     return result, 200, security_headers()
Exemplo n.º 15
0
 def get(self, code_lang):
     """
     Returns a code example item.
     * Privileges required: **none**
     """
     result = get_code_items_lang(code_lang)
     return result, 200, security_headers()
 def get(self):
     """
     Returns list of question items.
     * Privileges required: **none**
     """
     result = get_sprint_items()
     return result, 200, security_headers()
Exemplo n.º 17
0
 def test_security_headers(self):
     """Test if the security_headers method is working"""
     result_headers = security_headers()
     self.assertEqual(result_headers['X-Frame-Options'], "deny")
     self.assertEqual(result_headers['X-XSS-Protection'], "1")
     self.assertEqual(result_headers['X-Content-Type-Options'], "nosniff")
     self.assertEqual(result_headers['Cache-Control'], "no-store, no-cache")
Exemplo n.º 18
0
 def get(self):
     """
     Returns list of question items.
     * Privileges required: **none**
     """
     result = get_sprint_items()
     return result, 200, security_headers()
 def get(self, checklist_type):
     """
     Returns a list of checklist items, questions, knowledgebase items correlated to a checklist type
     * Privileges required: **none**
     """
     result = get_checklist_item_questions_git(checklist_type)
     return result, 200, security_headers()
Exemplo n.º 20
0
 def get(self, checklist_type):
     """
     Returns list of checklist items including the correlated knowledge base items.
     * Privileges required: **none**
     """
     result = get_checklist_items(checklist_type)
     return result, 200, security_headers()
Exemplo n.º 21
0
 def get(self, checklistID, checklist_type):
     """
     Returns a checklist item.
     * Privileges required: **none**
     """
     result = get_checklist_item(checklistID, checklist_type)
     return result, 200, security_headers()
Exemplo n.º 22
0
 def delete(self, id):
     """
     Deletes project item.
     * Privileges required: **delete**
     """
     validate_privilege(self, 'delete')
     val_num(id)
     return result, 200, security_headers()
Exemplo n.º 23
0
 def delete(self, checklist_id, checklist_type):
     """
     Delete a checklist item.
     * Privileges required: **delete**
     """
     validate_privilege(self, 'delete')
     result = delete_checklist_item(checklist_id, checklist_type)
     return result, 200, security_headers()
Exemplo n.º 24
0
 def get(self, category_id):
     """
     Returns list of code example items.
     * Privileges required: **none**
     """
     val_alpha_num_special(category_id)
     result = get_code_items(category_id)
     return result, 200, security_headers()
Exemplo n.º 25
0
 def get(self, search_string):
     """
     Returns list of search lab hits.
     * Privileges required: **read**
     """
     validate_privilege(self, 'read')
     result = search_lab(search_string)
     return result, 200, security_headers()
Exemplo n.º 26
0
 def get(self):
     """
     List available users.
     * Privileges required: **manage**
     """
     validate_privilege(self, 'manage')
     result = list_privileges()
     return result, 200, security_headers()
Exemplo n.º 27
0
 def put(self, id):
     """
     Activate an user.
     * Privileges required: **none**
     """
     data = request.json
     result = activate_user(id, data)
     return result, 200, security_headers()
Exemplo n.º 28
0
 def get(self, questionID):
     """
     Returns a list of checklist items correlated to question sprint identifier
     * Privileges required: **read**
     """
     validate_privilege(self, 'read')
     result = get_checklist_item_question_sprint(questionID)
     return result, 200, security_headers()
Exemplo n.º 29
0
 def get(self, id):
     """
     Returns a code example item.
     * Privileges required: **none**
     """
     val_num(id)
     result = get_code_item(id)
     return result, 200, security_headers()
Exemplo n.º 30
0
 def get(self, id):
     """
     Returns sprint items.
     * Privileges required: **read**
     """
     validate_privilege(self, 'read')
     result = get_sprint_results(id)
     return result, 200, security_headers()
Exemplo n.º 31
0
 def get(self):
     """
     Returns list of project items.
     * Privileges required: **read**
     """
     validate_privilege(self, 'read')
     result = get_project_items()        
     return result, 200, security_headers()
Exemplo n.º 32
0
 def get(self, solutions_id):
     """
     Returns list of code solutions for the review labs.
     * Privileges required: **none**
     """
     val_num(solutions_id)        
     result = get_labs_code_sol(solutions_id)
     return result, 200, security_headers()
Exemplo n.º 33
0
 def get(self, level):
     """
     Returns list of checklist items based on level.
     * Privileges required: **none**
     """
     lvl = level
     result = get_checklist_items_lvl(lvl)
     return result, 200, security_headers()
Exemplo n.º 34
0
 def post(self):
     """
     Login an user.
     * Privileges required: **none**
     """
     data = request.json
     result = login_user(data)
     return result, 200, security_headers()
Exemplo n.º 35
0
 def get(self, id):
     """
     Returns a single checklist category.
     * Privileges required: **none**
     """
     val_num(id)
     result = get_checklist_category_item(id)
     return result, 200, security_headers()
Exemplo n.º 36
0
 def get(self, question_id):
     """
     Returns single question item by id
     * Privileges required: **none**
     """
     #validate_privilege(self, 'manage')
     result = get_question_by_id(question_id)
     return result, 200, security_headers()
Exemplo n.º 37
0
 def put(self, id):
     """
     Activate an user.
     * Privileges required: **none**
     """
     data = request.json
     result = activate_user(id, data)
     return result, 200, security_headers()
Exemplo n.º 38
0
 def get(self, id):
     """
     Returns list of checklist types.
     * Privileges required: **none**
     """
     val_num(id)
     result = get_checklist_item_types(id)
     return result, 200, security_headers()
Exemplo n.º 39
0
 def get(self):
     """
     List available users.
     * Privileges required: **manage**
     """
     validate_privilege(self, 'manage')
     result = list_users()
     return result, 200, security_headers()
Exemplo n.º 40
0
 def post(self):
     """
     Returns a comment item.
     * Privileges required: **read**
     """
     validate_privilege(self, 'read')
     data = request.json
     result = get_comment_items(data)
     return result, 200, security_headers()
Exemplo n.º 41
0
 def get(self, id):
     """
     Returns project stats.
     * Privileges required: **read**
     """
     validate_privilege(self, 'read')
     user_id = select_userid_jwt(self)
     result = stats_project(id)
     return result, 200, security_headers()
Exemplo n.º 42
0
 def put(self):
     """
     Create an user.
     * Privileges required: **manage**
     """
     data = request.json
     validate_privilege(self, 'manage')
     result = create_user(data)
     return result, 200, security_headers()
 def get(self, id):
     """
     Returns sprint export.
     * Privileges required: **read**
     """
     validate_privilege(self, 'read')
     user_id = select_userid_jwt(self)
     result = get_sprint_results_audit_export(id, user_id)
     return result, 200, security_headers()
Exemplo n.º 44
0
 def get(self, id):
     """
     Returns a sprint item.
     * Privileges required: **read**
     """
     validate_privilege(self, 'read')
     user_id = select_userid_jwt(self)
     result = get_sprint_item(id, user_id)
     return result, 200, security_headers()
Exemplo n.º 45
0
 def put(self, id):
     """
     Update a kb item.
     * Privileges required: **manage**
     """
     validate_privilege(self, 'manage')
     data = request.json
     result = update_kb_item(id, data)
     return result, 200, security_headers()
Exemplo n.º 46
0
 def put(self, id):
     """
     Manage an user.
     * Privileges required: **none**
     """
     data = request.json
     validate_privilege(self, 'manage')
     result = manage_user(id, data)
     return result, 200, security_headers()
Exemplo n.º 47
0
 def delete(self, id):
     """
     Deletes sprint item.
     * Privileges required: **delete**
     """
     validate_privilege(self, 'delete')
     user_id = select_userid_jwt(self)
     result = delete_sprint(id, user_id)
     return result, 200, security_headers()
Exemplo n.º 48
0
 def put(self):
     """
     Store list of question pre items.
     * Privileges required: **edit**
     """
     validate_privilege(self, 'edit')
     user_id = select_userid_jwt(self)
     data = request.json
     result = store_pre_questions(user_id, data)
     return result, 200, security_headers()
Exemplo n.º 49
0
 def put(self):
     """
     Create a comment item.
     * Privileges required: **edit**
     """
     validate_privilege(self, 'edit')
     user_id = select_userid_jwt(self)
     data = request.json
     result = new_comment_item(user_id, data)
     return result, 200, security_headers()
Exemplo n.º 50
0
 def put(self, id):
     """
     Update a project item.
     * Privileges required: **edit**
     """
     validate_privilege(self, 'edit')
     user_id = select_userid_jwt(self)
     data = request.json
     result = update_project(id, user_id, data)
     return result, 200, security_headers()
Exemplo n.º 51
0
    def post(self):
        """
        Returns a answer on a question.
        * Privileges required: **none**
        """
        data = request.json
        data_q=data.get('question')
        intent=intent_classifier.predict(data_q)
        
        if intent=='Code':
            lang=None
            code_ans,lang=code(data_q,intent,lang)
            if type(lang)!=str:
               lang=data.get('question_lang')
               code_ans,lang=code(data_q,intent,lang)
            if type(code_ans)!=str:
               result={}
               result["options"] = [{"answer": code_ans[i],"answer_options": i} for i in code_ans]
               return result, 200, security_headers()
            elif type(code_ans)==str and type(lang)!=str:
               result={}
               result["options"] = [{"answer": code_ans,"answer_options": i,"answer_lang":lang[i]} for i in lang]
               return result, 200, security_headers()
              
            else:
               result={ "options": [{"answer": code_ans ,"answer_options": 0,"answer_lang":lang}] }
               return result, 200, security_headers()


        else:
            result1 = des_sol(data_q,intent)              
            if type(result1)!=str:
               result={}
               result["options"] = [{"answer": result1[i],"answer_options": i,"answer_intent":None} for i in result1]
               return result, 200, security_headers()   
            else:
               result={ "options": [{"answer": result1 ,"answer_options": 0,"answer_intent":None}] }
               return result, 200, security_headers()