def dataverse_set_config(node_addon, auth, **kwargs): """Saves selected Dataverse and dataset to node settings""" user_settings = node_addon.user_settings user = auth.user if user_settings and user_settings.owner != user: raise HTTPError(http.FORBIDDEN) try: assert_clean(request.json) except AssertionError: # TODO: Test me! raise HTTPError(http.NOT_ACCEPTABLE) alias = request.json.get('dataverse', {}).get('alias') doi = request.json.get('dataset', {}).get('doi') if doi is None or alias is None: return HTTPError(http.BAD_REQUEST) connection = client.connect_from_settings(node_addon) dataverse = client.get_dataverse(connection, alias) dataset = client.get_dataset(dataverse, doi) node_addon.set_folder(dataverse, dataset, auth) return {'dataverse': dataverse.title, 'dataset': dataset.title}, http.OK
def dataverse_set_user_config(auth, **kwargs): user = auth.user try: assert_clean(request.json) except AssertionError: # TODO: Test me! raise HTTPError(http.NOT_ACCEPTABLE) # Log in with DATAVERSE username = request.json.get('dataverse_username') password = request.json.get('dataverse_password') connection = client.connect(username, password) # Check for valid connection if connection is None: raise HTTPError(http.UNAUTHORIZED) user_addon = user.get_addon('dataverse') if user_addon is None: user.add_addon('dataverse') user_addon = user.get_addon('dataverse') user_addon.dataverse_username = username user_addon.dataverse_password = password user_addon.save() return {'username': username}, http.OK
def dataverse_set_user_config(auth, **kwargs): user = auth.user try: assert_clean(request.json) except AssertionError: # TODO: Test me! raise HTTPError(http.NOT_ACCEPTABLE) # Log in with DATAVERSE username = request.json.get('dataverse_username') password = request.json.get('dataverse_password') connection = connect(username, password) # Check for valid connection if connection is None: raise HTTPError(http.UNAUTHORIZED) user_addon = user.get_addon('dataverse') if user_addon is None: user.add_addon('dataverse') user_addon = user.get_addon('dataverse') user_addon.dataverse_username = username user_addon.dataverse_password = password user_addon.save() return {'username': username}, http.OK
def weko_set_config(node_addon, user_addon, auth, **kwargs): """Saves selected WEKO and Index to node settings""" user_settings = node_addon.user_settings user = auth.user if user_settings and user_settings.owner != user: raise HTTPError(http.FORBIDDEN) try: assert_clean(request.json) except AssertionError: # TODO: Test me! raise HTTPError(http.NOT_ACCEPTABLE) index_id = request.json.get('index', {}).get('id') if index_id is None: return HTTPError(http.BAD_REQUEST) connection = client.connect_from_settings(weko_settings, node_addon) index = client.get_index_by_id(connection, index_id) node_addon.set_folder(index, auth) return {'index': index.title}, http.OK
def dataverse_set_config(node_addon, auth, **kwargs): """Saves selected Dataverse and dataset to node settings""" user_settings = node_addon.user_settings user = auth.user if user_settings and user_settings.owner != user: raise HTTPError(http.FORBIDDEN) try: assert_clean(request.json) except AssertionError: # TODO: Test me! raise HTTPError(http.NOT_ACCEPTABLE) alias = request.json.get('dataverse').get('alias') doi = request.json.get('dataset').get('doi') if doi is None: return HTTPError(http.BAD_REQUEST) connection = client.connect_from_settings(node_addon) dataverse = client.get_dataverse(connection, alias) dataset = client.get_dataset(dataverse, doi) node_addon.dataverse_alias = dataverse.alias node_addon.dataverse = dataverse.title node_addon.dataset_doi = dataset.doi node_addon.dataset_id = dataset.id node_addon.dataset = dataset.title node = node_addon.owner node.add_log( action='dataverse_dataset_linked', params={ 'project': node.parent_id, 'node': node._primary_key, 'dataset': dataset.title, }, auth=auth, ) node_addon.save() return {'dataverse': dataverse.title, 'dataset': dataset.title}, http.OK
def set_dataverse_and_study(node_addon, auth, **kwargs): user_settings = node_addon.user_settings user = auth.user if user_settings and user_settings.owner != user: raise HTTPError(http.FORBIDDEN) try: assert_clean(request.json) except AssertionError: # TODO: Test me! raise HTTPError(http.NOT_ACCEPTABLE) alias = request.json.get('dataverse').get('alias') hdl = request.json.get('study').get('hdl') if hdl is None: return HTTPError(http.BAD_REQUEST) connection = client.connect_from_settings(user_settings) dataverse = client.get_dataverse(connection, alias) study = client.get_study(dataverse, hdl) node_addon.dataverse_alias = dataverse.alias node_addon.dataverse = dataverse.title node_addon.study_hdl = study.doi node_addon.study = study.title node = node_addon.owner node.add_log( action='dataverse_study_linked', params={ 'project': node.parent_id, 'node': node._primary_key, 'study': study.title, }, auth=auth, ) node_addon.save() return {'dataverse': dataverse.title, 'study': study.title}, http.OK
def set_dataverse_and_study(node_addon, auth, **kwargs): user_settings = node_addon.user_settings user = get_current_user() if user_settings and user_settings.owner != user: raise HTTPError(http.FORBIDDEN) try: assert_clean(request.json) except AssertionError: # TODO: Test me! raise HTTPError(http.NOT_ACCEPTABLE) alias = request.json.get('dataverse').get('alias') hdl = request.json.get('study').get('hdl') if hdl is None: return HTTPError(http.BAD_REQUEST) connection = connect_from_settings(user_settings) dataverse = get_dataverse(connection, alias) study = get_study(dataverse, hdl) node_addon.dataverse_alias = dataverse.alias node_addon.dataverse = dataverse.title node_addon.study_hdl = study.doi node_addon.study = study.title node = node_addon.owner node.add_log( action='dataverse_study_linked', params={ 'project': node.parent_id, 'node': node._primary_key, 'study': study.title, }, auth=auth, ) node_addon.save() return {'dataverse': dataverse.title, 'study': study.title}, http.OK
def set_dataverse_and_dataset(node_addon, auth, **kwargs): user_settings = node_addon.user_settings user = auth.user if user_settings and user_settings.owner != user: raise HTTPError(http.FORBIDDEN) try: assert_clean(request.json) except AssertionError: # TODO: Test me! raise HTTPError(http.NOT_ACCEPTABLE) alias = request.json.get("dataverse").get("alias") doi = request.json.get("dataset").get("doi") if doi is None: return HTTPError(http.BAD_REQUEST) connection = client.connect_from_settings(user_settings) dataverse = client.get_dataverse(connection, alias) dataset = client.get_dataset(dataverse, doi) node_addon.dataverse_alias = dataverse.alias node_addon.dataverse = dataverse.title node_addon.dataset_doi = dataset.doi node_addon.dataset_id = dataset.id node_addon.dataset = dataset.title node = node_addon.owner node.add_log( action="dataverse_dataset_linked", params={"project": node.parent_id, "node": node._primary_key, "dataset": dataset.title}, auth=auth, ) node_addon.save() return {"dataverse": dataverse.title, "dataset": dataset.title}, http.OK
def dataverse_set_user_config(auth, **kwargs): user = auth.user try: assert_clean(request.json) except AssertionError: # TODO: Test me! raise HTTPError(http.NOT_ACCEPTABLE) # Log in with Dataverse token = request.json.get('api_token') client.connect_or_401(token) user_addon = user.get_addon('dataverse') if user_addon is None: user.add_addon('dataverse') user_addon = user.get_addon('dataverse') user_addon.api_token = token user_addon.save() return {'token': token}, http.OK
def dataverse_set_user_config(auth, **kwargs): user = auth.user try: assert_clean(request.json) except AssertionError: # TODO: Test me! raise HTTPError(http.NOT_ACCEPTABLE) # Log in with Dataverse token = request.json.get("api_token") client.connect_or_401(token) user_addon = user.get_addon("dataverse") if user_addon is None: user.add_addon("dataverse") user_addon = user.get_addon("dataverse") user_addon.api_token = token user_addon.save() return {"token": token}, http.OK