示例#1
0
def new_project(user_id, data):
    log("User created new project", "MEDIUM", "PASS")
    val_num(user_id)
    val_alpha_num_special(data.get('name'))
    val_alpha_num(data.get('version'))
    val_alpha_num_special(data.get('description'))
    projectName = data.get('name')
    projectVersion = data.get('version')
    projectDesc = data.get('description')
    userID = user_id
    groupmember = groupmembers.query.filter(
        groupmembers.userID == userID).one()
    ownerID = groupmember.ownerID
    groupID = groupmember.groupID
    now = datetime.datetime.now()
    timestamp = now.strftime("%Y-%m-%d %H:%M")
    project = projects(userID, groupID, projectName, projectVersion,
                       projectDesc, ownerID, timestamp)
    db.session.add(project)
    db.session.commit()
    result = projects.query.filter(projects.userID == user_id).order_by(
        desc(projects.projectID)).first()
    return {
        'projectID': result.projectID,
        'message': 'Project successfully created'
    }
示例#2
0
文件: business.py 项目: sitshu/skf
def new_comment_item(user_id, data):
    log("User requested update a specific comment item", "LOW", "PASS")
    val_num(user_id)
    val_alpha_num(data.get('checklistID'))
    val_num(data.get('sprintID'))
    val_num(data.get('status'))
    val_alpha_num_special(data.get('comment'))
    sprint_id = data.get('sprintID')
    checklist_id = data.get('checklistID')
    status = data.get('status')
    comment = data.get('comment')
    now = datetime.datetime.now()
    dateLog = now.strftime("%Y-%m-%d %H:%M:%S")
    result = comments(sprint_id, checklist_id, user_id, status, comment,
                      dateLog)
    db.session.add(result)
    db.session.commit()
    result = checklists_results.query.filter(
        checklists_results.sprintID == sprint_id).filter(
            checklists_results.checklistID == checklist_id).all()
    for row in result:
        row.status = status
        db.session.add(row)
        db.session.commit()
    return {'message': 'Comment item successfully created'}
示例#3
0
def activate_user(user_id, data):
    log("User is activated", "HIGH", "PASS")
    val_num(user_id)
    val_num(data.get('accessToken'))
    val_alpha_num(data.get('username'))
    val_alpha_num_special(data.get('email'))
    username = data.get('username')
    username = username.replace(" ", "")
    result = User.query.filter(User.id == user_id).one()
    if not result.activated:
        if result.email == data.get('email'):
            if data.get('password') == data.get('repassword'):
                if data.get('accessToken') == result.accessToken:
                    pw_hash = generate_password_hash(
                        data.get('password')).decode('utf-8')
                    result.password = pw_hash
                    result.access = True
                    result.activated = True
                    result.username = username
                    db.session.add(result)
                    db.session.commit()
                    return {'message': 'User successfully activated'}
    else:
        log("User triggered error activation failed", "HIGH", "FAIL")
        return {'message': 'User could not be activated'}
示例#4
0
def update_project(project_id, user_id, data):
    log("User updated project", "MEDIUM", "PASS")
    val_num(project_id)
    val_num(user_id)
    val_alpha_num_special(data.get('name'))
    val_alpha_num(data.get('version'))
    val_alpha_num_special(data.get('description'))
    try:
        project = Project.query.filter(Project.id == project_id).one()
        project.projectName = data.get('name')
        project.projectVersion = data.get('version')
        project.projectDesc = data.get('description')
        project.userID = user_id
        #groupmember = groupmembers.query.filter(groupmembers.userID == user_id).one()
        #ownerID = groupmember.ownerID
        #groupID = groupmember.groupID
        now = datetime.datetime.now()
        project.timestamp = now.strftime("%Y-%m-%d %H:%M")
        db.session.add(project)
        db.session.commit()
    except Exception as e:
        db.session.rollback()
        raise

    return {'message': 'Project successfully updated'}
示例#5
0
def new_sprint(user_id, data):
    log("User created new sprint", "MEDIUM", "PASS")
    
    val_alpha_num_special(data.get('name'))
    val_alpha_num_special(data.get('description'))
    val_num(data.get('project_id'))
    #val_num(data.get('checklist_type_id'))
    
    name = data.get('name')
    description = data.get('description')
    project_id = data.get('project_id')
    checklist_type_id = data.get('checklist_type_id')

    #groupmember = groupmembers.query.filter(groupmembers.userID == user_id).one()
    #groupID = groupmember.groupID

    try:
        user = User.query.get(user_id)
        #group = user.groups[0]
        sprint = ProjectSprint(name, description)
        sprint.group_id = 1
        sprint.project_id = project_id
        sprint.checklist_type_id = checklist_type_id
        db.session.add(sprint)
        db.session.commit()

    except:
         db.session.rollback()
         raise

    # somewhat funky query to obtain the id
    result = ProjectSprint.query.order_by(desc(ProjectSprint.id)).first()
    return {'sprint_id': result.id, 'message': 'Sprint successfully created'}
示例#6
0
def create_user(data):
    log("A new user created", "MEDIUM", "PASS")
    val_num(data.get('privilege_id'))
    val_alpha_num_special(data.get('email'))
    email = data.get('email')
    privilege_id = data.get('privilege_id')
    my_secure_rng = random.SystemRandom()
    accessToken = my_secure_rng.randrange(10000000, 99999999)
    #access = False # By default
    #activated = False # By default
    password = ""

    try:
        user = User(email)
        user.privilege_id = privilege_id
        user.username = accessToken
        user.accessToken = accessToken
        # Add user to default groupmember issue #422
        user.group_id = 0
        #user.groups.add = Group.query.order_by(desc(Group.id)).first()

        db.session.add(user)
        db.session.commit()

    except:
        db.session.rollback()
        raise

    result = User.query.filter(User.email == email).one()
    return result
示例#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()
示例#8
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()
 def get(self, checklist_kb_id):
     """
     Returns list of code example items that have correlation with requirements.
     * Privileges required: **edit**
     """
     val_alpha_num_special(checklist_kb_id)
     validate_privilege(self, 'edit')
     result = get_code_items_checklist_kb(checklist_kb_id)
     return result, 200, security_headers()
示例#10
0
 def get(self, checklist_id, checklist_type):
     """
     Returns a checklist item.
     * Privileges required: **none**
     """
     val_alpha_num_special(checklist_id)
     val_num(checklist_type)
     result = get_checklist_item(checklist_id, checklist_type)
     return result, 200, security_headers()
示例#11
0
 def post(self):
     """
     Login an user.
     * Privileges required: **none**
     """
     data = request.json
     val_alpha_num_special(data.get('username'))
     result = login_user(data)
     return result, 200, security_headers()
示例#12
0
 def delete(self, checklist_id, checklist_type):
     """
     Delete a checklist item.
     * Privileges required: **delete**
     """
     val_num(checklist_type)
     val_alpha_num_special(checklist_id)
     validate_privilege(self, 'delete')
     result = delete_checklist_item(checklist_id, checklist_type)
     return result, 200, security_headers()
示例#13
0
 def put(self, category_id):
     """
     Create new kb item.
     * Privileges required: **edit**
     """
     validate_privilege(self, 'edit')
     data = request.json
     val_alpha_num_special(data.get('title'))
     result = create_kb_item(data, category_id)
     return result, 200, security_headers()
示例#14
0
 def put(self):
     """
     Create a new checklist category.
     * Privileges required: **edit**
     """
     data = request.json
     val_alpha_num_special(data.get('name'))
     val_alpha_num_special(data.get('description'))
     validate_privilege(self, 'edit')
     result = create_checklist_category(data)
     return result, 200, security_headers()
示例#15
0
 def put(self, kb_id):
     """
     Update a kb item.
     * Privileges required: **edit**
     """
     data = request.json
     val_num(kb_id)
     val_alpha_num_special(data.get('title'))
     validate_privilege(self, 'edit')
     result = update_kb_item(kb_id, data)
     return result, 200, security_headers()
示例#16
0
 def put(self):
     """
     Create an user.
     * Privileges required: **manage**
     """
     data = request.json
     val_alpha_num_special(data.get('username'))
     val_alpha_num_special(data.get('privilege_id'))
     validate_privilege(self, 'manage')
     result = create_user(data)
     return result, 200, security_headers()
 def put(self, id):
     """
     Update a checklist type.
     * Privileges required: **edit**
     """
     data = request.json
     val_num(id)
     val_alpha_num_special(data.get('name'))
     val_alpha_num_special(data.get('description'))
     validate_privilege(self, 'edit')
     result = update_checklist_category(id, data)
     return result, 200, security_headers()
示例#18
0
 def put(self, checklist_result_id):
     """
     Deletes a checklist_result item from your sprint/feature.
     * Privileges required: **read**
     """
     validate_privilege(self, 'read')
     data = request.json
     val_alpha_num_special(data.get('evidence'))
     val_alpha_num(data.get('resolved'))
     val_num(checklist_result_id)
     result = update_checklist_result(checklist_result_id, data)
     return result, 200, security_headers()
示例#19
0
文件: business.py 项目: sitshu/skf
def update_sprint(sprint_id, user_id, data):
    log("User updated sprint", "MEDIUM", "PASS")
    val_num(sprint_id)
    val_num(user_id)
    sprint = project_sprints.query.filter(project_sprints.sprintID == sprint_id).one()
    val_alpha_num_special(data.get('name'))
    val_alpha_num_special(data.get('description'))
    sprint.sprintName = data.get('name')
    sprint.sprintDesc = data.get('description')
    db.session.add(sprint) 
    db.session.commit()
    return {'message': 'Sprint successfully updated'}
示例#20
0
 def put(self, category_id):
     """
     Create new code example item.
     * Privileges required: **edit**
     """
     data = request.json
     val_alpha_num_special(data.get('title'))
     val_alpha_num(data.get('code_lang'))
     val_num(category_id)
     validate_privilege(self, 'edit')
     result = create_code_item(data, category_id)
     return result, 200, security_headers()
示例#21
0
 def put(self):
     """
     Create new sprint item.
     * Privileges required: **edit**
     """
     data = request.json
     val_alpha_num_special(data.get('name'))
     val_alpha_num_special(data.get('description'))
     val_num(data.get('project_id'))
     validate_privilege(self, 'edit')
     result = new_sprint(data)
     return result, 200, security_headers()
示例#22
0
 def put(self, id):
     """
     Update question sprint item.
     * Privileges required: **edit**
     """
     data = request.json
     val_num(id)
     val_num(data.get('checklist_type'))
     val_alpha_num_special(data.get('question'))
     validate_privilege(self, 'edit')
     result = update_question(id, data)
     return result, 200, security_headers()
示例#23
0
 def put(self, id):
     """
     Update a code example item.
     * Privileges required: **manage**
     """
     data = request.json
     val_alpha_num_special(data.get('title'))
     val_alpha_num(data.get('code_lang'))
     val_num(id)
     validate_privilege(self, 'manage')
     result = update_code_item(id, data)
     return result, 200, security_headers()
示例#24
0
def update_question(id_question, data):
    log("User updated sprint question item", "MEDIUM", "PASS")
    val_num(id_question)
    val_num(data.get('checklist_type'))
    val_alpha_num_special(data.get('question'))
    sprint_question = data.get('question')
    sprint_checklist_type = data.get('checklist_type')
    sprint = Question.query.filter(Question.id == id_question).one()
    sprint.question = sprint_question
    sprint.checklist_type = sprint_checklist_type
    db.session.add(sprint)
    db.session.commit()
    return {'message': 'Question successfully updated'}
示例#25
0
 def put(self):
     """
     Create new project item.
     * Privileges required: **edit**
     """
     data = request.json
     val_alpha_num_special(data.get('name'))
     val_alpha_num(data.get('version'))
     val_alpha_num_special(data.get('description'))
     validate_privilege(self, 'edit')
     user_id = select_userid_jwt(self)
     result = new_project(user_id, data)
     return result, 200, security_headers()
示例#26
0
 def put(self, checklist_id, checklist_type):
     """
     Update a checklist type.
     * Privileges required: **edit**
     """
     data = request.json
     val_num(checklist_type)
     val_alpha_num_special(checklist_id)
     val_num(data.get('question_id'))
     validate_privilege(self, 'edit')
     result = update_checklist_question_correlation(checklist_id,
                                                    checklist_type, data)
     return result, 200, security_headers()
示例#27
0
 def post(self):
     """
     Returns a answer on a question.
     * Privileges required: **none**
     """
     data = request.json
     data_q = data.get('question')
     val_alpha_num_special(data.get('question'))
     intent = intent_classifier.predict(data_q)
     if intent == 'Code':
         lang = None
         code_ans = 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:
             result = {}
             result["options"] = [{"answer": code_ans, "answer_options": 0}]
             return result, 200, security_headers()
         else:
             result = {
                 "options": [{
                     "answer": code_ans,
                     "answer_options": 0
                 }]
             }
             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()
示例#28
0
def create_checklist_type(data):
    log("User requested create a new checklist type", "LOW", "PASS")
    val_alpha_num_special(data.get('name'))
    val_alpha_num_special(data.get('description'))
    checklist_name = data.get('name')
    checklist_description = data.get('description')
    visibility = data.get('visibility')
    checklist_type = ChecklistType(checklist_name, checklist_description, visibility)
    try:
        db.session.add(checklist_type)
        db.session.commit()
    except:
        db.rollback()
        raise
    return {'message': 'Checklist type successfully created'} 
示例#29
0
def delete_checklist_item(checklist_id, checklist_type):
    log("User deleted checklist item", "MEDIUM", "PASS")
    val_num(checklist_type)
    val_alpha_num_special(checklist_id)
    
    try:
        checklist = ChecklistKB.query.filter((ChecklistKB.checklist_id == checklist_id) & (ChecklistKB.checklist_type == checklist_type)).one()
        db.session.delete(checklist)
        db.session.commit()

    except Exception as e:
        db.session.rollback()
        raise

    return {'message': 'Checklist item successfully deleted'}
示例#30
0
def create_kb_item(data):
    log("User requested creating a new kb item", "LOW", "PASS")
    val_alpha_num_special(data.get('title'))
    content = data.get('content')
    title = data.get('title')
    #grab highest kb_id value and +1 it for unique number as kb_id
    item = KBItem.query.order_by(desc(KBItem.kb_id)).first()
    try:
        kb_item = KBItem(title, content, item.kb_id + 1)
        db.session.add(kb_item)
        db.session.commit()
    except:
        db.session.rollback()
        raise
    return {'message': 'KB item successfully created'}
示例#31
0
def new_comment_item(user_id, data):
    log("User requested update a specific comment item", "LOW", "PASS")
    val_num(user_id)
    val_alpha_num(data.get('checklistID'))
    val_num(data.get('sprintID'))
    val_num(data.get('status'))
    val_alpha_num_special(data.get('comment'))
    sprint_id = data.get('sprintID')
    checklist_id = data.get('checklistID')
    status = data.get('status')
    comment = data.get('comment')
    now = datetime.datetime.now()
    dateLog = now.strftime("%Y-%m-%d %H:%M:%S")
    result = comments(sprint_id, checklist_id, user_id, status, comment, dateLog)
    db.session.add(result)
    db.session.commit()
    result = checklists_results.query.filter(checklists_results.sprintID == sprint_id).filter(checklists_results.checklistID == checklist_id).all()
    for row in result:
        row.status = status
        db.session.add(row)
        db.session.commit()
    return {'message': 'Comment item successfully created'}