Ejemplo 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
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
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
Ejemplo n.º 6
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