Example #1
0
    def post(self, user_id):
        data = Report.parser.parse_args()

        if ReportModel.is_reported(user_id):
            return {"message": "This account is already reported"}, 400

        ReportModel.add_to_database(ReportModel(**data))
        return {"message": "This user is reported, please for judging"}, 200
Example #2
0
    def post(self):
        """
		Crea un nuevo reporte sobre un usuario.
		"""
        data = ReportList.parser.parse_args()
        if not UserModel.find_by_id(data['user_id']):
            return {
                "message": f"El usuario con ID {data['user_id']!r} no existe."
            }, 404

        new_report = ReportModel(**data)
        new_report.save_to_db()

        return new_report.json(), 201
Example #3
0
    def get(self):
        """
		Devuelve la lista de reportes, incluyendo los datos del usuario reportado. Solo admins.
		"""
        if current_identity.user_type != user_types['admin']:
            return {"message": "No tiene permitido consultar reportes."}, 401
        return [report.json() for report in ReportModel.get_all()]
Example #4
0
 def delete(self, name):
     report = ReportModel.find_by_name(name)
     if report is None:
         return {'message': "Report not found!"}, 404
     else:
         report.delete_from_db()
         return {'message': "Report deleted."}
Example #5
0
    def delete(self, id):
        try:
            report = ReportModel.get_by_id(id)
            report.delete()
            return 'No Content', 204

        except Exception as e:
            return f"{e}", 500
Example #6
0
    def put(self, name):
        data = Report.parser.parse_args()

        report = ReportModel.find_by_name(name)

        if report is None:
            report = ReportModel(name, **data)
        else:
            report.benchmark = data['benchmark']
            report.content = data['content']
            report.status = data['status']

        try:
            report.save_to_db()
        except:
            return {'message': "An error occured."}, 500

        return report.json()
Example #7
0
    def post(self):
        item = request.get_json() if request.get_json() else request.form
        # reports = ReportModel.list_all()

        try:
            if item:
                model = ReportModel()
                model.status = item['status']
                model.vehicle_id = item['vehicle_id']
                model.client_id = item['client_id']
                model.description = item['description']
                model.timestamp = date.today()
                model.save()

                return 'created', 201
            else:
                return 'not created, invalid payload', 400
        except Exception as e:
            return f"{e}", 500
Example #8
0
    def get(self, report_id: int):
        """
		Devuelve los datos de un reporte especĂ­fico, incluyendo los datos del usuario reportado. Solo admins.
		"""
        if current_identity.user_type != user_types['admin']:
            return {"message": "No tiene permitido consultar reportes."}, 401

        report = ReportModel.find_by_id(report_id)
        if not report:
            return {
                "message":
                f"El reporte con ID {report_id!r} no ha sido encontrado."
            }, 404
        return report.json()
Example #9
0
    def put(self, id):
        item = request.get_json() if request.get_json() else request.form

        try:
            if item:
                model = ReportModel()
                model = ReportModel.get_by_id(id)
                if 'status' in item:
                    model.status = item['status']
                if 'vehicle_id' in item:
                    model.vehicle_id = item['vehicle_id']
                if 'client_id' in item:
                    model.client_id = item['client_id']
                if 'description' in item:
                    model.description = item['description']
                model.save()

                return 'edited', 204
            else:
                return 'unedited, invalid payload', 400

        except Exception as e:
            return f"{e}", 500
Example #10
0
    def delete(self, report_id: int):
        """
		Elimina un reporte de la base de datos. Solo admins.
		"""
        if current_identity.user_type != user_types['admin']:
            return {"message": "No tiene permitido eliminar reportes."}, 401

        report = ReportModel.find_by_id(report_id)
        if not report:
            return {
                "message":
                f"El reporte con ID {report_id!r} no ha sido encontrado."
            }, 404

        report.delete_from_db()
        return {
            "message": f"Reporte con ID {report_id!r} eliminado correctamente."
        }
Example #11
0
    def _list_by_client(self, client_id):
        reports = ReportModel.get_by_client(client_id)

        res = []
        for report in reports:
            client = ClientModel.get_by_id(report.client_id)
            res.append({
                'id': report.id,
                'status': report.status,
                'client_id': report.client_id,
                'vehicle_id': report.vehicle_id,
                'description': report.description,
                'client': {
                    'id': client.id,
                    'first_name': client.first_name
                }
            })

        return res
Example #12
0
    def post(self, name):
        if ReportModel.find_by_name(name):
            return {'message': "A report with that name already exists!"}, 400

        data = Report.parser.parse_args()

        report = ReportModel(name, **data)

        try:
            report.save_to_db()
        except:
            return {
                'message': "An error occured while creating the report."
            }, 500

        return report.json()
Example #13
0
    def _get_report(self, id_report):
        report = ReportModel.get_by_id(id_report)

        if report is None:
            return {'message': 'report not found'}, 404

        client = ClientModel.get_by_id(report.client_id)
        vehicle = VehicleModel.get_by_id(report.vehicle_id)

        return {
            'id': report.id,
            'status': report.status,
            'client_id': report.client_id,
            'vehicle_id': report.vehicle_id,
            'client': {
                'id': client.id,
                'first_name': client.first_name
            },
            'vehicle': {
                'model': vehicle.model,
                'board': vehicle.board
            },
            'description': report.description
        }
Example #14
0
    def setReport(self, userID, expId, request):
        ExperimentDetaile = saverModel.getExperimentDetaile(userID, expId)
        allQuestions = QuestionModel.find_all_Question()
        questions = []
        for question in allQuestions:
            if question.section == 1:
                questions.append(question)
        type1Ids = []
        type2Ids = []
        type3Ids = []
        for question in questions:
            if (question.type == 1):
                type1Ids.append(question.id)
            else:
                if (question.type == 2):
                    type2Ids.append(question.id)
                else:
                    type3Ids.append(question.id)
        if (ExperimentDetaile.questionDisplay == 1):
            # first part => Traditional approach
            tempStr = '$answer[0][]'
            answers = request.form.getlist(tempStr)
            indexAnswer = 0
            ExperimentDetaileID = ExperimentDetaile.id
            for j in range(0, len(type1Ids)):
                questionId = type1Ids[j]
                answer = answers[indexAnswer]
                part = 2
                securtyID = 0
                indexAnswer += 1
                report = ReportModel(ExperimentDetaileID, questionId, answer,
                                     part, securtyID)
                report.save_to_db()
            for j in range(0, len(type2Ids)):
                questionId = type2Ids[j]
                answer = answers[indexAnswer]
                part = 2
                securtyID = 0
                indexAnswer += 1
                report = ReportModel(ExperimentDetaileID, questionId, answer,
                                     part, securtyID)
                report.save_to_db()
            for j in range(0, len(type3Ids)):
                questionId = type3Ids[j]
                answer = answers[indexAnswer]
                part = 2
                securtyID = 0
                indexAnswer += 1
                report = ReportModel(ExperimentDetaileID, questionId, answer,
                                     part, securtyID)
                report.save_to_db()
            # secind part => Contextual approach - fitzer image
            rowsNum = len(helper.getAppImage(
                ExperimentDetaile.applicationId)) - 2
            SecurtyIds = helper.getSecurtyIds(ExperimentDetaile.applicationId)
            i = 1
            for SecurtyId in SecurtyIds:
                tempStr = '$answer[' + str(i) + '][]'
                answers = request.form.getlist(tempStr)
                indexAnswer = 0
                ExperimentDetaileID = ExperimentDetaile.id
                for j in range(0, len(type1Ids)):
                    questionId = type1Ids[j]
                    answer = answers[indexAnswer]
                    part = 2
                    securtyID = SecurtyId
                    indexAnswer += 1
                    report = ReportModel(ExperimentDetaileID, questionId,
                                         answer, part, securtyID)
                    report.save_to_db()
                for j in range(0, len(type2Ids)):
                    questionId = type2Ids[j]
                    answer = answers[indexAnswer]
                    part = 2
                    securtyID = SecurtyId
                    indexAnswer += 1
                    report = ReportModel(ExperimentDetaileID, questionId,
                                         answer, part, securtyID)
                    report.save_to_db()
                for j in range(0, len(type3Ids)):
                    questionId = type3Ids[j]
                    answer = answers[indexAnswer]
                    part = 2
                    securtyID = SecurtyId
                    indexAnswer += 1
                    report = ReportModel(ExperimentDetaileID, questionId,
                                         answer, part, securtyID)
                    report.save_to_db()
                i += 1
        else:
            if (ExperimentDetaile.questionDisplay == 2):
                # first part => Contextual approach
                SecurtyIds = helper.getSecurtyIds(
                    ExperimentDetaile.applicationId)
                i = 0
                for SecurtyId in SecurtyIds:
                    tempStr = '$answer[' + str(i) + '][]'
                    answers = request.form.getlist(tempStr)
                    indexAnswer = 0
                    ExperimentDetaileID = ExperimentDetaile.id
                    for j in range(0, len(type1Ids)):
                        questionId = type1Ids[j]
                        answer = answers[indexAnswer]
                        part = 2
                        securtyID = SecurtyId
                        indexAnswer += 1
                        report = ReportModel(ExperimentDetaileID, questionId,
                                             answer, part, securtyID)
                        report.save_to_db()
                    for j in range(0, len(type2Ids)):
                        questionId = type2Ids[j]
                        answer = answers[indexAnswer]
                        part = 2
                        securtyID = SecurtyId
                        indexAnswer += 1
                        report = ReportModel(ExperimentDetaileID, questionId,
                                             answer, part, securtyID)
                        report.save_to_db()
                    for j in range(0, len(type3Ids)):
                        questionId = type3Ids[j]
                        answer = answers[indexAnswer]
                        part = 2
                        securtyID = SecurtyId
                        indexAnswer += 1
                        report = ReportModel(ExperimentDetaileID, questionId,
                                             answer, part, securtyID)
                        report.save_to_db()
                    i += 1
                # secind part => Traditional approach
                tempStr = '$answer[' + str(i) + '][]'
                answers = request.form.getlist(tempStr)
                indexAnswer = 0
                ExperimentDetaileID = ExperimentDetaile.id
                for j in range(0, len(type1Ids)):
                    questionId = type1Ids[j]
                    answer = answers[indexAnswer]
                    part = 2
                    securtyID = 0
                    indexAnswer += 1
                    report = ReportModel(ExperimentDetaileID, questionId,
                                         answer, part, securtyID)
                    report.save_to_db()
                for j in range(0, len(type2Ids)):
                    questionId = type2Ids[j]
                    answer = answers[indexAnswer]
                    part = 2
                    securtyID = 0
                    indexAnswer += 1
                    report = ReportModel(ExperimentDetaileID, questionId,
                                         answer, part, securtyID)
                    report.save_to_db()
                for j in range(0, len(type3Ids)):
                    questionId = type3Ids[j]
                    answer = answers[indexAnswer]
                    part = 2
                    securtyID = 0
                    indexAnswer += 1
                    report = ReportModel(ExperimentDetaileID, questionId,
                                         answer, part, securtyID)
                    report.save_to_db()
            else:
                if (ExperimentDetaile.questionDisplay == 3):
                    # first part => Contextual approach
                    SecurtyIds = helper.getSecurtyIds(
                        ExperimentDetaile.applicationId)
                    i = 0
                    for SecurtyId in SecurtyIds:
                        tempStr = '$answer[' + str(i) + '][]'
                        answers = request.form.getlist(tempStr)
                        indexAnswer = 0
                        ExperimentDetaileID = ExperimentDetaile.id
                        for j in range(0, len(type1Ids)):
                            questionId = type1Ids[j]
                            answer = answers[indexAnswer]
                            part = 2
                            securtyID = SecurtyId
                            indexAnswer += 1
                            report = ReportModel(ExperimentDetaileID,
                                                 questionId, answer, part,
                                                 securtyID)
                            report.save_to_db()
                        for j in range(0, len(type2Ids)):
                            questionId = type2Ids[j]
                            answer = answers[indexAnswer]
                            part = 2
                            securtyID = SecurtyId
                            indexAnswer += 1
                            report = ReportModel(ExperimentDetaileID,
                                                 questionId, answer, part,
                                                 securtyID)
                            report.save_to_db()
                        for j in range(0, len(type3Ids)):
                            questionId = type3Ids[j]
                            answer = answers[indexAnswer]
                            part = 2
                            securtyID = SecurtyId
                            indexAnswer += 1
                            report = ReportModel(ExperimentDetaileID,
                                                 questionId, answer, part,
                                                 securtyID)
                            report.save_to_db()
                        i += 1

                else:
                    if (ExperimentDetaile.questionDisplay == 4):
                        # first part => Traditional approach
                        tempStr = '$answer[0][]'
                        answers = request.form.getlist(tempStr)
                        indexAnswer = 0
                        ExperimentDetaileID = ExperimentDetaile.id
                        for j in range(0, len(type1Ids)):
                            questionId = type1Ids[j]
                            answer = answers[indexAnswer]
                            part = 1
                            securtyID = 0
                            indexAnswer += 1
                            report = ReportModel(ExperimentDetaileID,
                                                 questionId, answer, part,
                                                 securtyID)
                            report.save_to_db()
                        for j in range(0, len(type2Ids)):
                            questionId = type2Ids[j]
                            answer = answers[indexAnswer]
                            part = i
                            securtyID = 0
                            indexAnswer += 1
                            report = ReportModel(ExperimentDetaileID,
                                                 questionId, answer, part,
                                                 securtyID)
                            report.save_to_db()
                        for j in range(0, len(type3Ids)):
                            questionId = type3Ids[j]
                            answer = answers[indexAnswer]
                            part = i
                            securtyID = 0
                            indexAnswer += 1
                            report = ReportModel(ExperimentDetaileID,
                                                 questionId, answer, part,
                                                 securtyID)
                            report.save_to_db()
                    else:
                        # first part => Traditional approach
                        tempStr = '$answer[0][]'
                        answers = request.form.getlist(tempStr)
                        indexAnswer = 0
                        ExperimentDetaileID = ExperimentDetaile.id
                        part = 2
                        for j in range(0, len(type1Ids)):
                            questionId = type1Ids[j]
                            answer = answers[indexAnswer]
                            securtyID = 0
                            indexAnswer += 1
                            report = ReportModel(ExperimentDetaileID,
                                                 questionId, answer, part,
                                                 securtyID)
                            report.save_to_db()
                        for j in range(0, len(type2Ids)):
                            questionId = type2Ids[j]
                            answer = answers[indexAnswer]
                            securtyID = 0
                            indexAnswer += 1
                            report = ReportModel(ExperimentDetaileID,
                                                 questionId, answer, part,
                                                 securtyID)
                            report.save_to_db()
                        for j in range(0, len(type3Ids)):
                            questionId = type3Ids[j]
                            answer = answers[indexAnswer]
                            securtyID = 0
                            indexAnswer += 1
                            report = ReportModel(ExperimentDetaileID,
                                                 questionId, answer, part,
                                                 securtyID)
                            report.save_to_db()
        return saverModel.removeExperimentDetaile(userID, expId)
Example #15
0
    def getAnswerTable(self, experimentId):
        Experiment = ExperimentModel.find_by_id(experimentId)
        ExperimentDetailes = ExperimentDetaileModel.find_all_ExperimentDetailes_by_ExperimentID(
            experimentId)
        users = UserModel.find_all_user()
        table = []
        Application = ApplicationModel.find_all()
        Questions = QuestionModel.find_all_Question()

        dictApp = unionModel.getApplictionsDict(Application)
        dictUser = unionModel.getUsersDict(users)
        dictQustion = unionModel.getQustionDict(Questions)

        Securties = SecurtyModel.find_all_SecurtyFeature()
        SecurtyDict = unionModel.getSecurtyDict(Securties)

        generalReports = generalReportModel.find_by_experimentId(experimentId)
        column = {}
        column['user'] = '******'
        column['Traditional_summary_old'] = '-'
        column['Traditional_summary_new'] = '-'

        for Securty in Securties:
            column[SecurtyDict[Securty.id]] = '-'
        # run on all grop exp
        j = 0
        for i in range(0, Experiment.numberParti):
            groupExpDict = {}
            for ExperimentDetaile in ExperimentDetailes:
                if ExperimentDetaile.groupExp != i:
                    continue
                j += 1
                dictExp = {}
                strType = ""
                if ExperimentDetaile.questionDisplay == 1:
                    strType = 'new traditional summary => Security features'
                else:
                    if ExperimentDetaile.questionDisplay == 2:
                        strType = 'Security features => new traditional summary'
                    else:
                        if ExperimentDetaile.questionDisplay == 3:
                            strType = 'Security features'
                        else:
                            if ExperimentDetaile.questionDisplay == 4:
                                strType = 'old traditional summary'
                            else:
                                strType = 'new traditional summary'
                key = dictApp[ExperimentDetaile.applicationId] + ': ' + strType
                dictExp[key] = {}
                Reports = ReportModel.find_all_report_by_experimentDetailes(
                    ExperimentDetaile.id)
                for Question in Questions:
                    if (Question.section == 1):
                        columnCopy = column.copy()
                        if (ExperimentDetaile.userID != 0):
                            columnCopy['user'] = dictUser[
                                ExperimentDetaile.userID]
                        for Report in Reports:
                            if (Report.questionID == Question.id):
                                if Report.part == 1:
                                    columnCopy[
                                        'Traditional_summary_old'] = Report.answer
                                else:
                                    if Report.part == 2 and int(
                                            Report.securityId) == 0:
                                        columnCopy[
                                            'Traditional_summary_new'] = Report.answer
                                    else:
                                        columnCopy[SecurtyDict[int(
                                            Report.securityId
                                        )]] = Report.answer
                        dictExp[key][dictQustion[Question.id]] = columnCopy
                groupExpDict[j] = dictExp
            table.append(groupExpDict)

        # generalReport
        columnGeneral = {}
        for Question in Questions:
            if (Question.section == 2):
                columnGeneral[dictQustion[Question.id]] = '-'

        generalDict = {}
        generalDict['general report'] = {}
        lastUser = -1
        for generalReport in generalReports:
            if (lastUser == -1
                    or (lastUser != -1 and lastUser != generalReport.userID)):
                generalDict['general report'][dictUser[
                    generalReport.userID]] = copy.deepcopy(columnGeneral)
            lastUser = generalReport.userID
            generalDict['general report'][dictUser[generalReport.userID]][
                dictQustion[generalReport.questionID]] = generalReport.answer
        table.append(generalDict)

        return table
Example #16
0
 def get(self, name):
     report = ReportModel.find_by_name(name)
     if report:
         return report.json()
     return {'message': "Report not found!"}, 404