Beispiel #1
0
def update_dataset_access():
    try:
        current_app.logger.info('Updating dataset access...')
        item_id = request.form['item_id']
        staff_id = _get_user_name()
        updated_access = request.form

        verification_api = VerificationAPI()
        current_access = verification_api.get_user_dataset_access(item_id)

        # Temporarily filter out ocod/ccod/nps_sample/res_cov_direct from access being updated
        for dataset in current_access:
            if dataset['name'] == 'licenced':
                dataset['licences'] = {}

            # Filter out sample and direct licence entries
            licences = {
                k: v
                for (k, v) in dataset['licences'].items()
                if '_direct' not in k and '_sample' not in k
            }
            dataset['licences'] = licences

        verification_api.update_dataset_access(item_id, staff_id,
                                               current_access, updated_access)

        flash("User's data access was updated")
        return redirect(url_for('verification.get_item', item_id=item_id))
    except ApplicationError:
        raise ApplicationError(
            'Something went wrong when updating users data access. '
            'Please raise an incident quoting the following id: {}'.format(
                g.trace_id))
Beispiel #2
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)