def create(): form = ClientForm(request.form) form.secret.validators = [input_required()] 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.post( '/client/', dict( id=(id := form.id.data), name=form.name.data, secret=form.secret.data, 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 created.', category='success') return redirect(url_for('.view', id=id))
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
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
def create(): form = ProjectForm(request.form) utils.populate_collection_choices(form.collection_ids) if request.method == 'POST' and form.validate(): try: api.post( '/project/', dict( id=(id := form.id.data), name=form.name.data, collection_ids=form.collection_ids.data, )) flash(f'Project {id} has been created.', category='success') return redirect(url_for('.view', id=id))
def create(): form = RoleForm(request.form) 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.post( '/role/', dict( id=(id := form.id.data), collection_id=form.collection_id.data or None, scope_ids=form.scope_ids.data, )) flash(f'Role {id} has been created.', category='success') return redirect(url_for('.view', id=id))
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)
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
def create(): form = RecordForm(request.form) utils.populate_collection_choices(form.collection_id, include_none=True) 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: record = api.post( api_route, 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 created.', category='success') return redirect(url_for('.view', id=record['id']))
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))