Пример #1
0
    def __func():
        data = request.get_json()
        case_obj = running_context.CaseSubscription.query.filter_by(
            id=data['id']).first()
        if case_obj:
            original_name = case_obj.name
            case_name = data['name'] if 'name' in data else original_name

            if 'note' in data and data['note']:
                case_obj.note = data['note']
            if 'name' in data and data['name']:
                case_subscription.rename_case(case_obj.name, data['name'])
                case_obj.name = data['name']
                db.session.commit()
                current_app.logger.debug(
                    'Case name changed from {0} to {1}'.format(
                        original_name, data['name']))
            if 'subscriptions' in data:
                case_obj.subscriptions = json.dumps(data['subscriptions'])
                subscriptions = {
                    subscription['uid']: subscription['events']
                    for subscription in data['subscriptions']
                }
                for uid, events in subscriptions.items():
                    case_subscription.modify_subscription(
                        case_name, uid, events)
            db.session.commit()
            return case_obj.as_json(), SUCCESS
        else:
            current_app.logger.error(
                'Cannot update case {0}. Case does not exist.'.format(
                    data['id']))
            return {"error": "Case does not exist."}, OBJECT_DNE_ERROR
Пример #2
0
def update_case(case_name):
    form = forms.EditCaseForm(request.form)
    if form.validate():
        if form.name.data:
            rename_case(case_name, form.name.data)
            case = running_context.CaseSubscription.query.filter_by(
                name=case_name).first()
            if case:
                case.name = form.name.data
                running_context.db.session.commit()
            if form.note.data:
                case_database.case_db.edit_case_note(form.name.data,
                                                     form.note.data)
        elif form.note.data:
            case_database.case_db.edit_case_note(case_name, form.note.data)
        return json.dumps(case_database.case_db.cases_as_json())
Пример #3
0
 def test_rename_case(self):
     cases = copy.deepcopy(self.cases1)
     subs.set_subscriptions(self.cases1)
     self.assertTrue(subs.rename_case('case1', 'renamed'))
     cases['renamed'] = cases.pop('case1')
     self.assertInMemoryCasesAreCorrect(cases)
     self.assertDatabaseCasesAreCorrect({'renamed', 'case2'})
Пример #4
0
 def test_rename_case_no_cases(self):
     self.assertFalse(subs.rename_case('case1', 'renamed'))
     self.assertInMemoryCasesAreCorrect({})
     self.assertDatabaseCasesAreCorrect(set())
Пример #5
0
 def test_rename_case_to_existing_case(self):
     cases = copy.deepcopy(self.cases1)
     subs.set_subscriptions(self.cases1)
     self.assertFalse(subs.rename_case('case1', 'case2'))
     self.assertInMemoryCasesAreCorrect(cases)
     self.assertDatabaseCasesAreCorrect({'case1', 'case2'})
Пример #6
0
@app.route('/cases/<string:case_name>/<string:action>', methods=['POST'])
@auth_token_required
@roles_accepted(*userRoles['/cases'])
def crud_case(case_name, action):
    if action == 'add':
        case = CaseSubscriptions()
        add_cases({"{0}".format(str(case_name)): case})
        return json.dumps(case_subscription.subscriptions_as_json())
    elif action == 'delete':
        delete_cases([case_name])
        return json.dumps(case_subscription.subscriptions_as_json())
    elif action == 'edit':
        form = forms.EditCaseForm(request.form)
        if form.validate():
            if form.name.data:
                rename_case(case_name, form.name.data)
                if form.note.data:
                    case_database.case_db.edit_case_note(
                        form.name.data, form.note.data)
            elif form.note.data:
                case_database.case_db.edit_case_note(case_name, form.note.data)
            return json.dumps(case_database.case_db.cases_as_json())
    else:
        return json.dumps({"status": "Invalid operation {0}".format(action)})


@app.route('/cases/<string:case_name>', methods=['GET'])
@auth_token_required
@roles_accepted(*userRoles['/cases'])
def display_case(case_name):
    case = case_database.case_db.session.query(case_database.Case) \