def get_datasets(info_role): """ Retourne la liste des datasets Parameters: info_role(TRole) active (boolean) id_acquisition_framework (integer) """ with_mtd_error = False if current_app.config["CAS_PUBLIC"]["CAS_AUTHENTIFICATION"]: # synchronise the CA and JDD from the MTD WS try: mtd_utils.post_jdd_from_user( id_user=info_role.id_role, id_organism=info_role.id_organisme ) except Exception as e: gunicorn_error_logger.info(e) log.error(e) with_mtd_error = True params = dict(request.args) datasets = get_datasets_cruved(info_role, params) datasets_resp = {"data": datasets} if with_mtd_error: datasets_resp["with_mtd_errors"] = True if not datasets: return datasets_resp, 404 return datasets_resp
def get_datasets(info_role): """ Get datasets list .. :quickref: Metadata; :param info_role: add with kwargs :type info_role: TRole :query boolean active: filter on active fiel :query int id_acquisition_framework: get only dataset of given AF :returns: `dict{'data':list<TDatasets>, 'with_erros': <boolean>}` """ with_mtd_error = False if current_app.config["CAS_PUBLIC"]["CAS_AUTHENTIFICATION"]: # synchronise the CA and JDD from the MTD WS try: mtd_utils.post_jdd_from_user(id_user=info_role.id_role, id_organism=info_role.id_organisme) except Exception as e: gunicorn_error_logger.info(e) log.error(e) with_mtd_error = True params = request.args.to_dict() datasets = get_datasets_cruved(info_role, params) datasets_resp = {"data": datasets} if with_mtd_error: datasets_resp["with_mtd_errors"] = True if not datasets: return datasets_resp, 404 return datasets_resp
def get_datasets(info_role): """ Retourne la liste des datasets Parameters: info_role(TRole) active (boolean) id_acquisition_framework (integer) """ with_mtd_error = False if current_app.config["CAS_PUBLIC"]["CAS_AUTHENTIFICATION"]: # synchronise the CA and JDD from the MTD WS try: mtd_utils.post_jdd_from_user( id_user=info_role.id_role, id_organism=info_role.id_organisme ) except Exception as e: gunicorn_error_logger.info(e) log.error(e) with_mtd_error = True params = dict(request.args) datasets = get_datasets_cruved(info_role, params) datasets_resp = {"data": datasets} if with_mtd_error: datasets_resp["with_mtd_errors"] = True if not datasets: return datasets_resp, 404 return datasets_resp
def post_jdd_from_user_id(id_user=None, id_organism=None): """ Post a jdd from the mtd XML .. :quickref: Metadata; """ return mtd_utils.post_jdd_from_user(id_user=id_user, id_organism=id_organism)
def test_mtd_interraction(self): from geonature.core.gn_meta.mtd_utils import post_jdd_from_user, get_jdd_by_user_id, parse_jdd_xml """ Test du web service MTD A partir d'un utilisateur renvoyé par le CAS on insert l'utilisateur 'demo.geonature' et son organisme s'il existe pas puis on poste les CA et JDD renvoyé à le WS MTD """ user = { "id_role": 10991, "identifiant": 'test.mtd', "nom_role": 'test_mtd', "prenom_role": 'test_mtd', "id_organisme": 104, } organism = {"id_organisme": 104, "nom_organisme": 'test'} resp = users.insert_organism(organism) assert resp.status_code == 200 resp = users.insert_role(user) users.insert_in_cor_role(20003, user['id_role']) assert resp.status_code == 200 jdds = post_jdd_from_user(id_user=10991, id_organism=104) assert len(jdds) >= 1
def test_mtd_interraction(self): from geonature.core.gn_meta.mtd_utils import ( post_jdd_from_user, get_jdd_by_user_id, parse_jdd_xml, ) """ Test du web service MTD A partir d'un utilisateur renvoyé par le CAS on insert l'utilisateur 'demo.geonature' et son organisme s'il existe pas puis on poste les CA et JDD renvoyé à le WS MTD """ user = { "id_role": 10991, "identifiant": "test.mtd", "nom_role": "test_mtd", "prenom_role": "test_mtd", "id_organisme": 104, } organism = {"id_organisme": 104, "nom_organisme": "test"} resp = users.insert_organism(organism) assert resp.status_code == 200 resp = users.insert_role(user) # id_role 10 = id_socle 1 in test users.insert_in_cor_role(10, user["id_role"]) assert resp.status_code == 200 jdds = post_jdd_from_user(id_user=10991, id_organism=104) assert len(jdds) >= 1
def get_af_and_ds_metadata(info_role): """ Get all AF with their datasets The Cruved in only apply on dataset in order to see all the AF where the user have rights with its dataset Use in maplist Add the CRUVED permission for each row (Dataset and AD) .. :quickref: Metadata; :param info_role: add with kwargs :type info_role: TRole :returns: `dict{'data':list<AF with Datasets>, 'with_erros': <boolean>}` """ with_mtd_error = False if current_app.config["CAS_PUBLIC"]["CAS_AUTHENTIFICATION"]: # synchronise the CA and JDD from the MTD WS try: mtd_utils.post_jdd_from_user(id_user=info_role.id_role, id_organism=info_role.id_organisme) except Exception as e: gunicorn_error_logger.info(e) log.error(e) with_mtd_error = True params = request.args.to_dict() params["orderby"] = "dataset_name" datasets = get_datasets_cruved(info_role, params, as_model=True) ids_dataset_user = TDatasets.get_user_datasets(info_role, only_user=True) ids_dataset_organisms = TDatasets.get_user_datasets(info_role, only_user=False) ids_afs_user = TAcquisitionFramework.get_user_af(info_role, only_user=True) ids_afs_org = TAcquisitionFramework.get_user_af(info_role, only_user=False) user_cruved = cruved_scope_for_user_in_module( id_role=info_role.id_role, module_code="METADATA", )[0] # get all af from the JDD filtered with cruved or af where users has rights ids_afs_cruved = [ d.id_acquisition_framework for d in get_af_cruved(info_role, as_model=True) ] list_id_af = [d.id_acquisition_framework for d in datasets] + ids_afs_cruved afs = (DB.session.query(TAcquisitionFramework).filter( TAcquisitionFramework.id_acquisition_framework.in_( list_id_af)).order_by( TAcquisitionFramework.acquisition_framework_name).all()) afs_dict = [] # get cruved for each AF and prepare dataset for af in afs: af_dict = af.as_dict() af_dict["cruved"] = af.get_object_cruved( user_cruved=user_cruved, id_object=af.id_acquisition_framework, ids_object_user=ids_afs_user, ids_object_organism=ids_afs_org, ) af_dict["datasets"] = [] afs_dict.append(af_dict) # get cruved for each ds and push them in the af for d in datasets: dataset_dict = d.as_dict() dataset_dict["cruved"] = d.get_object_cruved( user_cruved=user_cruved, id_object=d.id_dataset, ids_object_user=ids_dataset_user, ids_object_organism=ids_dataset_organisms, ) af_of_dataset = get_af_from_id(d.id_acquisition_framework, afs_dict) af_of_dataset["datasets"].append(dataset_dict) afs_resp = {"data": afs_dict} if with_mtd_error: afs_resp["with_mtd_errors"] = True if not datasets: return afs_resp, 404 return afs_resp
def post_jdd_from_user_id(id_user=None, id_organism=None): """ Post a jdd from the mtd XML""" return mtd_utils.post_jdd_from_user(id_user=id_user, id_organism=id_organism)
def post_jdd_from_user_id(id_user=None, id_organism=None): """ Post a jdd from the mtd XML""" return mtd_utils.post_jdd_from_user(id_user=id_user, id_organism=id_organism)