Beispiel #1
0
def contact_preferences(item_id):
    try:
        verification_api = VerificationAPI()
        case = verification_api.get_item(item_id)
        form = _build_contact_form(case)

        if form.validate_on_submit():
            contactable = request.form['contactable'] == 'yes'

            params = {
                'updated_data': {
                    'contactable':
                    contactable,
                    'contact_preferences':
                    request.form.getlist('contact_preferences')
                },
                'staff_id': _get_user_name()
            }

            verification_api.update_user_details(item_id, params)
            return redirect(url_for('verification.get_item', item_id=item_id))

        return render_template('app/contact_preferences.html',
                               form=form,
                               item_id=item_id)
    except ApplicationError:
        raise ApplicationError(
            'Something went wrong while updating user contact preferences'
            'Please raise an incident quoting the following id: {}'.format(
                g.trace_id))
    def test_get_item_timeout_error(self, mock_get):
        mock_get.side_effect = Timeout(self.error_msg)

        with self.assertRaises(ApplicationError) as context:
            verification_api = VerificationAPI()
            verification_api.get_item(self.item_id)

        self.assertEqual(
            context.exception.message,
            'Connection to verification_api timed out: {}'.format(
                self.error_msg))
        self.assertEqual(context.exception.code, 'E403')
        self.assertEqual(context.exception.http_code, 500)
    def test_get_item_connection_error(self, mock_get):
        mock_get.side_effect = ConnectionError(self.error_msg)

        with self.assertRaises(ApplicationError) as context:
            verification_api = VerificationAPI()
            verification_api.get_item(self.item_id)

        self.assertEqual(
            context.exception.message,
            'Encountered an error connecting to verification_api: {}'.format(
                self.error_msg))
        self.assertEqual(context.exception.code, 'E402')
        self.assertEqual(context.exception.http_code, 500)
    def test_get_item_http_error(self, mock_get):
        mock_get.side_effect = HTTPError(self.error_msg)

        with self.assertRaises(ApplicationError) as context:
            verification_api = VerificationAPI()
            verification_api.get_item(self.item_id)

        self.assertEqual(
            context.exception.message,
            'Received the following response from verification_api: {}'.format(
                self.error_msg))
        self.assertEqual(context.exception.code, 'E401')
        self.assertEqual(context.exception.http_code, 500)
    def test_get_item(self, mock_get):
        mock_get.return_value.json.return_value = [{'case_id': self.item_id}]
        mock_get.return_value.status_code = 200

        verification_api = VerificationAPI()
        response = verification_api.get_item(self.item_id)

        self.assertEqual(response, [{'case_id': self.item_id}])
Beispiel #6
0
def check_correct_lock_user(item_id, username):
    verficiation_api = VerificationAPI()
    result = verficiation_api.get_item(item_id)
    locked_user = result['staff_id']
    current_user = username
    if locked_user is None:
        return True
    elif locked_user != current_user:
        return False
    else:
        return True
Beispiel #7
0
def get_item(item_id):
    current_app.logger.info(
        'User requested to view item {}...'.format(item_id))
    try:
        _get_user_name()
        verification_api = VerificationAPI()
        case = verification_api.get_item(item_id)
        lock = _handle_lock(case, verification_api) if case['status'] in [
            'Pending', 'In Progress'
        ] else None

        if case['status'] == 'Approved':
            dataset_activity = verification_api.get_dataset_activity(item_id)
            dataset_access = verification_api.get_user_dataset_access(item_id)

        from_search = request.args.get('from', None) == 'search'
        if not from_search:
            session['search_params'] = None

    except ApplicationError as error:
        if error.http_code == 404:
            return render_template('app/errors/unhandled.html', http_code=404)

        raise ApplicationError(
            'Something went wrong when requesting the application details. '
            'Please raise and incident quoting the following id: {}'.format(
                g.trace_id))
    else:
        current_app.logger.info(
            'Putting worklist item information into viewable format...')

        case_data_for_template = {
            'id':
            item_id,
            'status':
            case['status'],
            'info':
            build_details_table(case),
            'notes': [{
                'text': note['note_text'],
                'meta_data': format_note_metadata(note)
            } for note in case['notes']]
        }

        if case['status'] in ['Pending', 'In Progress', 'Declined']:
            forms = _build_app_forms(item_id, case['status'], lock is None,
                                     verification_api)
            return render_template('app/application_details.html',
                                   case_data=case_data_for_template,
                                   forms=forms,
                                   search=from_search,
                                   lock=lock)
        else:
            account_name = ' '.join([
                case['registration_data']['title'],
                case['registration_data']['first_name'],
                case['registration_data']['last_name']
            ])
            if case['status'] == 'Approved':
                forms = _build_acc_forms(item_id, case['status'],
                                         dataset_access)
                activity = build_dataset_activity(dataset_activity)
                return render_template('app/account_details.html',
                                       case_data=case_data_for_template,
                                       forms=forms,
                                       search=from_search,
                                       activity=activity,
                                       account_name=account_name,
                                       dataset_access=dataset_access)
            else:
                forms = _build_acc_forms(item_id, case['status'])
                return render_template('app/account_details.html',
                                       case_data=case_data_for_template,
                                       forms=forms,
                                       search=from_search,
                                       account_name=account_name)