Exemplo n.º 1
0
def edit(id):
    role = api.get(f'/role/{id}')

    # separate get/post form instantiation to resolve
    # ambiguity of missing vs empty multiselect field
    if request.method == 'POST':
        form = RoleForm(request.form)
    else:
        form = RoleForm(data=role)

    utils.populate_collection_choices(form.collection_id, include_none=True)
    utils.populate_scope_choices(form.scope_ids, ('odp', 'client'))

    if request.method == 'POST' and form.validate():
        try:
            api.put(
                '/role/',
                dict(
                    id=id,
                    collection_id=form.collection_id.data or None,
                    scope_ids=form.scope_ids.data,
                ))
            flash(f'Role {id} has been updated.', category='success')
            return redirect(url_for('.view', id=id))

        except api.ODPAPIError as e:
            if response := api.handle_error(e):
                return response
Exemplo n.º 2
0
def edit(id):
    user = api.get(f'/user/{id}')

    # separate get/post form instantiation to resolve
    # ambiguity of missing vs empty multiselect field
    if request.method == 'POST':
        form = UserForm(request.form)
    else:
        form = UserForm(data=user)

    utils.populate_role_choices(form.role_ids)

    if request.method == 'POST' and form.validate():
        try:
            api.put(
                '/user/',
                dict(
                    id=id,
                    active=form.active.data,
                    role_ids=form.role_ids.data,
                ))
            flash(f'User {id} has been updated.', category='success')
            return redirect(url_for('.view', id=id))

        except api.ODPAPIError as e:
            if response := api.handle_error(e):
                return response
Exemplo n.º 3
0
def tag_qc(id):
    record = api.get(f'/record/{id}')

    # separate get/post form instantiation to resolve
    # ambiguity of missing vs false boolean field
    if request.method == 'POST':
        form = RecordTagQCForm(request.form)
    else:
        record_tag = next(
            (tag for tag in record['tags'] if tag['tag_id'] == ODPRecordTag.QC
             and tag['user_id'] == current_user.id), None)
        form = RecordTagQCForm(data=record_tag['data'] if record_tag else None)

    if request.method == 'POST' and form.validate():
        try:
            api.post(
                f'/record/{id}/tag',
                dict(
                    tag_id=ODPRecordTag.QC,
                    data={
                        'pass_': form.pass_.data,
                        'comment': form.comment.data,
                    },
                ))
            flash(f'{ODPRecordTag.QC} tag has been set.', category='success')
            return redirect(url_for('.view', id=id))

        except api.ODPAPIError as e:
            if response := api.handle_error(e):
                return response
Exemplo n.º 4
0
def edit(id):
    project = api.get(f'/project/{id}')

    # separate get/post form instantiation to resolve
    # ambiguity of missing vs empty multiselect field
    if request.method == 'POST':
        form = ProjectForm(request.form)
    else:
        form = ProjectForm(data=project)

    utils.populate_collection_choices(form.collection_ids)

    if request.method == 'POST' and form.validate():
        try:
            api.put(
                '/project/',
                dict(
                    id=id,
                    name=form.name.data,
                    collection_ids=form.collection_ids.data,
                ))
            flash(f'Project {id} has been updated.', category='success')
            return redirect(url_for('.view', id=id))

        except api.ODPAPIError as e:
            if response := api.handle_error(e):
                return response
Exemplo n.º 5
0
def view(id):
    collection = api.get(f'/collection/{id}')
    return render_template(
        'collection_view.html',
        collection=collection,
        ready_tag=get_tag_instance(collection, ODPCollectionTag.READY),
        frozen_tag=get_tag_instance(collection, ODPCollectionTag.FROZEN),
    )
Exemplo n.º 6
0
def populate_collection_choices(field, include_none=False):
    collections = api.get('/collection/')['items']
    field.choices = [('', '(None)')] if include_none else []
    field.choices += [
        (collection['id'],
         Markup(f"{collection['id']} — {collection['name']}"))
        for collection in collections
    ]
Exemplo n.º 7
0
def view(id):
    record = api.get(f'/record/{id}')
    catalog_records = api.get(f'/record/{id}/catalog')

    migrated_tag = next(
        (tag
         for tag in record['tags'] if tag['tag_id'] == ODPRecordTag.MIGRATED),
        None)

    qc_tags = {
        'items':
        (items :=
         [tag for tag in record['tags'] if tag['tag_id'] == ODPRecordTag.QC]),
        'total':
        len(items),
        'page':
        1,
        'pages':
        1,
    }
Exemplo n.º 8
0
def edit(id):
    provider = api.get(f'/provider/{id}')
    form = ProviderForm(request.form, data=provider)

    if request.method == 'POST' and form.validate():
        try:
            api.put('/provider/', dict(
                id=id,
                name=form.name.data,
            ))
            flash(f'Provider {id} has been updated.', category='success')
            return redirect(url_for('.view', id=id))

        except api.ODPAPIError as e:
            if response := api.handle_error(e):
                return response
Exemplo n.º 9
0
def index():
    page = request.args.get('page', 1)
    collection_ids = request.args.getlist('collection')

    api_filter = ''
    ui_filter = ''
    for collection_id in collection_ids:
        api_filter += f'&collection_id={collection_id}'
        ui_filter += f'&collection={collection_id}'

    filter_form = RecordFilterForm(request.args)
    utils.populate_collection_choices(filter_form.collection)

    records = api.get(f'/record/?page={page}{api_filter}')
    return render_template('record_list.html',
                           records=records,
                           filter_=ui_filter,
                           filter_form=filter_form)
Exemplo n.º 10
0
def edit(id):
    client = api.get(f'/client/{id}')

    # separate get/post form instantiation to resolve
    # ambiguity of missing vs empty multiselect field
    if request.method == 'POST':
        form = ClientForm(request.form)
    else:
        form = ClientForm(data=client)

    form.secret.description = 'Client secret will remain unchanged if left blank.'
    utils.populate_collection_choices(form.collection_id, include_none=True)
    utils.populate_scope_choices(form.scope_ids)

    if request.method == 'POST' and form.validate():
        try:
            api.put(
                '/client/',
                dict(
                    id=id,
                    name=form.name.data,
                    secret=form.secret.data or None,
                    collection_id=form.collection_id.data or None,
                    scope_ids=form.scope_ids.data,
                    grant_types=form.grant_types.data,
                    response_types=form.response_types.data,
                    redirect_uris=form.redirect_uris.data.split(),
                    post_logout_redirect_uris=form.post_logout_redirect_uris.
                    data.split(),
                    token_endpoint_auth_method=form.token_endpoint_auth_method.
                    data,
                    allowed_cors_origins=form.allowed_cors_origins.data.split(
                    ),
                ))
            flash(f'Client {id} has been updated.', category='success')
            return redirect(url_for('.view', id=id))

        except api.ODPAPIError as e:
            if response := api.handle_error(e):
                return response
Exemplo n.º 11
0
def edit(id):
    collection = api.get(f'/collection/{id}')

    form = CollectionForm(request.form, data=collection)
    utils.populate_provider_choices(form.provider_id)

    if request.method == 'POST' and form.validate():
        try:
            api.put(
                '/collection/',
                dict(
                    id=id,
                    name=form.name.data,
                    provider_id=form.provider_id.data,
                    doi_key=form.doi_key.data or None,
                ))
            flash(f'Collection {id} has been updated.', category='success')
            return redirect(url_for('.view', id=id))

        except api.ODPAPIError as e:
            if response := api.handle_error(e):
                return response
Exemplo n.º 12
0
def tag_embargo(id):
    record = api.get(f'/record/{id}')

    if request.method == 'POST':
        form = RecordTagEmbargoForm(request.form)
    else:
        # embargo tag has cardinality 'multi', so this will always be an insert
        form = RecordTagEmbargoForm()

    if request.method == 'POST' and form.validate():
        if not form.start.data and not form.end.data:
            flash('Please specify a start and/or end date.', category='error')
        else:
            try:
                api.post(
                    f'/record/{id}/tag',
                    dict(
                        tag_id=ODPRecordTag.EMBARGO,
                        data={
                            'start':
                            form.start.data.isoformat()
                            if form.start.data else None,
                            'end':
                            form.end.data.isoformat()
                            if form.end.data else None,
                            'comment':
                            form.comment.data,
                        },
                    ))
                flash(f'{ODPRecordTag.EMBARGO} tag has been set.',
                      category='success')
                return redirect(url_for('.view', id=id))

            except api.ODPAPIError as e:
                if response := api.handle_error(e):
                    return response
Exemplo n.º 13
0
def edit(id):
    record = api.get(f'/record/{id}')

    form = RecordForm(request.form, data=record)
    utils.populate_collection_choices(form.collection_id)
    utils.populate_schema_choices(form.schema_id, 'metadata')

    if request.method == 'POST' and form.validate():
        api_route = '/record/'
        if ODPScope.RECORD_ADMIN in g.user_permissions:
            api_route += 'admin/'

        try:
            api.put(
                api_route + id,
                dict(
                    doi=(doi := form.doi.data) or None,
                    sid=(sid := form.sid.data) or None,
                    collection_id=form.collection_id.data,
                    schema_id=form.schema_id.data,
                    metadata=json.loads(form.metadata.data),
                ))
            flash(f'Record {doi or sid} has been updated.', category='success')
            return redirect(url_for('.view', id=id))
Exemplo n.º 14
0
def index():
    page = request.args.get('page', 1)
    collections = api.get(f'/collection/?page={page}')
    return render_template('collection_list.html', collections=collections)
Exemplo n.º 15
0
def index():
    page = request.args.get('page', 1)
    roles = api.get(f'/role/?page={page}')
    return render_template('role_list.html', roles=roles)
Exemplo n.º 16
0
def populate_scope_choices(field, scope_types=None):
    scopes = api.get('/scope/')['items']
    field.choices = [(scope['id'], scope['id']) for scope in scopes
                     if scope_types is None or scope['type'] in scope_types]
Exemplo n.º 17
0
def populate_role_choices(field):
    roles = api.get('/role/')['items']
    field.choices = [(role['id'], role['id']) for role in roles]
Exemplo n.º 18
0
def populate_provider_choices(field, include_none=False):
    providers = api.get('/provider/')['items']
    field.choices = [('', '(None)')] if include_none else []
    field.choices += [(provider['id'],
                       Markup(f"{provider['id']} — {provider['name']}"))
                      for provider in providers]
Exemplo n.º 19
0
def populate_schema_choices(field, schema_type):
    schemas = api.get(f'/schema/?schema_type={schema_type}')['items']
    field.choices = [(schema['id'], schema['id']) for schema in schemas]
Exemplo n.º 20
0
def view(id):
    project = api.get(f'/project/{id}')
    return render_template('project_view.html', project=project)
Exemplo n.º 21
0
def index():
    page = request.args.get('page', 1)
    clients = api.get(f'/client/?page={page}')
    return render_template('client_list.html', clients=clients)
Exemplo n.º 22
0
def view(id):
    catalog = api.get(f'/catalog/{id}')
    return render_template('catalog_view.html', catalog=catalog)
Exemplo n.º 23
0
def index():
    page = request.args.get('page', 1)
    projects = api.get(f'/project/?page={page}')
    return render_template('project_list.html', projects=projects)
Exemplo n.º 24
0
def index():
    page = request.args.get('page', 1)
    catalogs = api.get(f'/catalog/?page={page}')
    return render_template('catalog_list.html', catalogs=catalogs)
Exemplo n.º 25
0
def view(id):
    tag = api.get(f'/tag/{id}')
    return render_template('tag_view.html', tag=tag)
Exemplo n.º 26
0
def index():
    page = request.args.get('page', 1)
    schemas = api.get(f'/schema/?schema_type=metadata&page={page}')
    return render_template('schema_list.html', schemas=schemas)
Exemplo n.º 27
0
def view(id):
    role = api.get(f'/role/{id}')
    return render_template('role_view.html', role=role)
Exemplo n.º 28
0
def index():
    page = request.args.get('page', 1)
    tags = api.get(f'/tag/?page={page}')
    return render_template('tag_list.html', tags=tags)
Exemplo n.º 29
0
def view(id):
    client = api.get(f'/client/{id}')
    return render_template('client_view.html', client=client)
Exemplo n.º 30
0
def view(id):
    schema = api.get(f'/schema/{id}')
    return render_template('schema_view.html', schema=schema)