def get_authenticated_idx_and_idx_types(user=None, idx_keys=None, idx_type_keys=None): ''' Check permissions on elastic indexes and returns indexes that the given user can see''' # get all public idx_keys and idx_type_keys (idx_keys_public, idx_type_keys_public) = elastic_factory.get_idx_and_idx_type_keys(auth_public=True) # get all the private idx_keys and idx_type_keys (idx_keys_private, idx_type_keys_private) = elastic_factory.get_idx_and_idx_type_keys(auth_public=False) # user is None...return all public keys if user is None: return idx_keys_public, idx_type_keys_public idx_keys_auth = [] idx_type_keys_auth = [] # idx_keys or idx_type_keys is None, first fetch and add public keys # if idx_keys is None or idx_type_keys is None: if idx_keys is None: # First add all the public idx keys idx_keys_auth.extend(idx_keys_public) # Assign the idx keys that need to be checked idx_keys = idx_keys_private else: # don't add all, limit the one that the user has passed idx_keys_auth = [idx_key for idx_key in idx_keys if idx_key in idx_keys_public] if idx_type_keys is None: # First add all the public idx type keys idx_type_keys_auth.extend(idx_type_keys_public) # Assign the idx type keys that need to be checked idx_type_keys = idx_type_keys_private else: # don't add all, limit the one that the user has passed idx_type_keys_auth = [idx_key for idx_key in idx_type_keys if idx_key in idx_type_keys_public] # get elastic model names for the idx_keys and types (model_names_idx, model_names_idx_types) = elastic_factory.get_elastic_model_names(idx_keys=idx_keys, idx_type_keys=idx_type_keys) # @IgnorePep8 # check if the user has permissions to see the idx model model_names_idx_auth = _check_content_type_perms(model_names_idx, user) # check if the user has permissions to see the idx type model model_names_idx_types_auth = _check_content_type_perms(model_names_idx_types, user) # finally get the actual idx keys from model names and return them (idx_auth, idx_types_auth) = elastic_factory.get_keys_from_model_names(model_names_idx_auth, model_names_idx_types_auth) if idx_auth is not None and len(idx_auth) > 0: for idx in idx_auth: if idx not in idx_keys_auth: idx_keys_auth.append(idx) if idx_types_auth is not None and len(idx_types_auth) > 0: for idx in idx_types_auth: if idx not in idx_type_keys_auth: idx_type_keys_auth.append(idx) return (idx_keys_auth, idx_type_keys_auth)
def test_get_idx_and_idx_type_keys_pydgin(self): '''create idx and idxtype keys for chicp''' elastic_factory.create_dynamic_models() # get all private idx and keys (idx_keys, idx_type_keys) = elastic_factory.get_idx_and_idx_type_keys( auth_public=False) # private idx keys self.assertIn('DISEASE', idx_keys) # public idx keys self.assertNotIn('GENE', idx_keys) self.assertNotIn('MARKER', idx_keys) self.assertNotIn('PUBLICATION', idx_keys) # private idx type keys self.assertIn('DISEASE.DISEASE', idx_type_keys) self.assertIn('GENE.PATHWAY', idx_type_keys) self.assertIn('GENE.INTERACTIONS', idx_type_keys) self.assertIn('PUBLICATION.PUBLICATION', idx_type_keys) # public idx type keys self.assertNotIn('GENE.GENE', idx_type_keys) self.assertNotIn('MARKER.MARKER', idx_type_keys) # get all public idx and keys (idx_keys, idx_type_keys) = elastic_factory.get_idx_and_idx_type_keys( auth_public=True) # private idx key self.assertNotIn('DISEASE', idx_keys) # public idx key self.assertIn('MARKER', idx_keys) self.assertIn('PUBLICATION', idx_keys) self.assertIn('GENE', idx_keys) # private idx type keys self.assertNotIn('DISEASE.DISEASE', idx_type_keys) self.assertNotIn('GENE.PATHWAY', idx_type_keys) self.assertNotIn('GENE.INTERACTIONS', idx_type_keys) self.assertNotIn('PUBLICATION.PUBLICATION', idx_type_keys) # public idx type keys self.assertIn('GENE.GENE', idx_type_keys) self.assertIn('MARKER.MARKER', idx_type_keys) self.assertIn('MARKER.MARKER', idx_type_keys) self.assertIn('MARKER.MARKER', idx_type_keys)
def test_get_idx_and_idx_type_keys_pydgin(self): '''create idx and idxtype keys for chicp''' elastic_factory.create_dynamic_models() # get all private idx and keys (idx_keys, idx_type_keys) = elastic_factory.get_idx_and_idx_type_keys(auth_public=False) # private idx keys self.assertIn('DISEASE', idx_keys) # public idx keys self.assertNotIn('GENE', idx_keys) self.assertNotIn('MARKER', idx_keys) self.assertNotIn('PUBLICATION', idx_keys) # private idx type keys self.assertIn('DISEASE.DISEASE', idx_type_keys) self.assertIn('GENE.PATHWAY', idx_type_keys) self.assertIn('GENE.INTERACTIONS', idx_type_keys) self.assertIn('PUBLICATION.PUBLICATION', idx_type_keys) # public idx type keys self.assertNotIn('GENE.GENE', idx_type_keys) self.assertNotIn('MARKER.MARKER', idx_type_keys) # get all public idx and keys (idx_keys, idx_type_keys) = elastic_factory.get_idx_and_idx_type_keys(auth_public=True) # private idx key self.assertNotIn('DISEASE', idx_keys) # public idx key self.assertIn('MARKER', idx_keys) self.assertIn('PUBLICATION', idx_keys) self.assertIn('GENE', idx_keys) # private idx type keys self.assertNotIn('DISEASE.DISEASE', idx_type_keys) self.assertNotIn('GENE.PATHWAY', idx_type_keys) self.assertNotIn('GENE.INTERACTIONS', idx_type_keys) self.assertNotIn('PUBLICATION.PUBLICATION', idx_type_keys) # public idx type keys self.assertIn('GENE.GENE', idx_type_keys) self.assertIn('MARKER.MARKER', idx_type_keys) self.assertIn('MARKER.MARKER', idx_type_keys) self.assertIn('MARKER.MARKER', idx_type_keys)
def test_get_idx_and_idx_type_keys_cp(self): '''create idx and idxtype keys for chicp''' elastic_factory.create_dynamic_models() # usually you can get the IDX dict via ElasticSettings.attrs().get('IDX') (idx_keys, idx_type_keys) = elastic_factory.get_idx_and_idx_type_keys( auth_public=False) # private idx self.assertIn('TARGET_MIFSUD', idx_keys) self.assertIn('CP_STATS_UD', idx_keys) # private idx types self.assertIn('CP_STATS_IC.IC-MS_IMSGC', idx_type_keys) self.assertIn('CP_STATS_IC.IC-JIA_HINKS_UK', idx_type_keys) self.assertIn('CP_STATS_IC.IC-NAR_FARACO', idx_type_keys) self.assertIn('CP_STATS_GWAS.GWAS-BARRETT', idx_type_keys) self.assertIn('CP_STATS_GWAS.GWAS-ANDERSON', idx_type_keys) self.assertIn('CP_STATS_GWAS.GWAS-STAHL', idx_type_keys) self.assertIn('CP_STATS_GWAS.GWAS-OKADA', idx_type_keys) # public idx (idx_keys, idx_type_keys) = elastic_factory.get_idx_and_idx_type_keys( auth_public=True) # public idx self.assertIn('CP_STATS_IC', idx_keys) self.assertIn('CP_STATS_GWAS', idx_keys) self.assertIn('TARGET_MARTIN', idx_keys) self.assertIn('TARGET_CHICAGO', idx_keys) # public idx and idx_type self.assertIn('CP_STATS_IC.IC-T1D_ONENGUT', idx_type_keys) self.assertIn('CP_STATS_IC.IC-ATD_COOPER', idx_type_keys) self.assertIn('CP_STATS_IC.IC-CEL_TRYNKA', idx_type_keys) self.assertIn('CP_STATS_IC.IC-RA_EYRE', idx_type_keys) self.assertIn('CP_STATS_IC.IC-PBC_LIU', idx_type_keys) self.assertIn('CP_STATS_GWAS.GWAS-COOPER', idx_type_keys) self.assertIn('CP_STATS_GWAS.GWAS-DUBOIS', idx_type_keys) self.assertIn('CP_STATS_GWAS.GWAS-FRANKE', idx_type_keys) self.assertIn('CP_STATS_GWAS.GWAS-IMSGC', idx_type_keys)
def test_get_idx_and_idx_type_keys_cp(self): '''create idx and idxtype keys for chicp''' elastic_factory.create_dynamic_models() # usually you can get the IDX dict via ElasticSettings.attrs().get('IDX') (idx_keys, idx_type_keys) = elastic_factory.get_idx_and_idx_type_keys(auth_public=False) # private idx self.assertIn('TARGET_MIFSUD', idx_keys) self.assertIn('CP_STATS_UD', idx_keys) # private idx types self.assertIn('CP_STATS_IC.IC-MS_IMSGC', idx_type_keys) self.assertIn('CP_STATS_IC.IC-JIA_HINKS_UK', idx_type_keys) self.assertIn('CP_STATS_IC.IC-NAR_FARACO', idx_type_keys) self.assertIn('CP_STATS_GWAS.GWAS-BARRETT', idx_type_keys) self.assertIn('CP_STATS_GWAS.GWAS-ANDERSON', idx_type_keys) self.assertIn('CP_STATS_GWAS.GWAS-STAHL', idx_type_keys) self.assertIn('CP_STATS_GWAS.GWAS-OKADA', idx_type_keys) # public idx (idx_keys, idx_type_keys) = elastic_factory.get_idx_and_idx_type_keys(auth_public=True) # public idx self.assertIn('CP_STATS_IC', idx_keys) self.assertIn('CP_STATS_GWAS', idx_keys) self.assertIn('TARGET_MARTIN', idx_keys) self.assertIn('TARGET_CHICAGO', idx_keys) # public idx and idx_type self.assertIn('CP_STATS_IC.IC-T1D_ONENGUT', idx_type_keys) self.assertIn('CP_STATS_IC.IC-ATD_COOPER', idx_type_keys) self.assertIn('CP_STATS_IC.IC-CEL_TRYNKA', idx_type_keys) self.assertIn('CP_STATS_IC.IC-RA_EYRE', idx_type_keys) self.assertIn('CP_STATS_IC.IC-PBC_LIU', idx_type_keys) self.assertIn('CP_STATS_GWAS.GWAS-COOPER', idx_type_keys) self.assertIn('CP_STATS_GWAS.GWAS-DUBOIS', idx_type_keys) self.assertIn('CP_STATS_GWAS.GWAS-FRANKE', idx_type_keys) self.assertIn('CP_STATS_GWAS.GWAS-IMSGC', idx_type_keys)
def test_get_elastic_model_names_chicp(self): '''check whether the right model names are created for chicp''' elastic_factory.create_dynamic_models() (idx_keys, idx_type_keys) = elastic_factory.get_idx_and_idx_type_keys(auth_public=False) (model_names_idx, model_names_idx_types) = elastic_factory.get_elastic_model_names( idx_keys=idx_keys, idx_type_keys=idx_type_keys) self.assertIn('target_mifsud_idx', model_names_idx) self.assertIn('cp_stats_ic-ic-ms_imsgc_idx_type', model_names_idx_types) self.assertIn('cp_stats_ic-ic-nar_faraco_idx_type', model_names_idx_types) self.assertIn('cp_stats_gwas-gwas-okada_idx_type', model_names_idx_types) self.assertIn('cp_stats_gwas-gwas-stahl_idx_type', model_names_idx_types)
def test_get_elastic_model_names_chicp(self): '''check whether the right model names are created for chicp''' elastic_factory.create_dynamic_models() (idx_keys, idx_type_keys) = elastic_factory.get_idx_and_idx_type_keys( auth_public=False) (model_names_idx, model_names_idx_types) = elastic_factory.get_elastic_model_names( idx_keys=idx_keys, idx_type_keys=idx_type_keys) self.assertIn('target_mifsud_idx', model_names_idx) self.assertIn('cp_stats_ic-ic-ms_imsgc_idx_type', model_names_idx_types) self.assertIn('cp_stats_ic-ic-nar_faraco_idx_type', model_names_idx_types) self.assertIn('cp_stats_gwas-gwas-okada_idx_type', model_names_idx_types) self.assertIn('cp_stats_gwas-gwas-stahl_idx_type', model_names_idx_types)
def get_authenticated_idx_and_idx_types(user=None, idx_keys=None, idx_type_keys=None): ''' Check permissions on elastic indexes and returns indexes that the given user can see''' # get all public idx_keys and idx_type_keys (idx_keys_public, idx_type_keys_public) = elastic_factory.get_idx_and_idx_type_keys( auth_public=True) # get all the private idx_keys and idx_type_keys (idx_keys_private, idx_type_keys_private) = elastic_factory.get_idx_and_idx_type_keys( auth_public=False) # user is None...return all public keys if user is None: return idx_keys_public, idx_type_keys_public idx_keys_auth = [] idx_type_keys_auth = [] # idx_keys or idx_type_keys is None, first fetch and add public keys # if idx_keys is None or idx_type_keys is None: if idx_keys is None: # First add all the public idx keys idx_keys_auth.extend(idx_keys_public) # Assign the idx keys that need to be checked idx_keys = idx_keys_private else: # don't add all, limit the one that the user has passed idx_keys_auth = [ idx_key for idx_key in idx_keys if idx_key in idx_keys_public ] if idx_type_keys is None: # First add all the public idx type keys idx_type_keys_auth.extend(idx_type_keys_public) # Assign the idx type keys that need to be checked idx_type_keys = idx_type_keys_private else: # don't add all, limit the one that the user has passed idx_type_keys_auth = [ idx_key for idx_key in idx_type_keys if idx_key in idx_type_keys_public ] # get elastic model names for the idx_keys and types (model_names_idx, model_names_idx_types) = elastic_factory.get_elastic_model_names( idx_keys=idx_keys, idx_type_keys=idx_type_keys) # @IgnorePep8 # check if the user has permissions to see the idx model model_names_idx_auth = _check_content_type_perms(model_names_idx, user) # check if the user has permissions to see the idx type model model_names_idx_types_auth = _check_content_type_perms( model_names_idx_types, user) # finally get the actual idx keys from model names and return them (idx_auth, idx_types_auth) = elastic_factory.get_keys_from_model_names( model_names_idx_auth, model_names_idx_types_auth) if idx_auth is not None and len(idx_auth) > 0: for idx in idx_auth: if idx not in idx_keys_auth: idx_keys_auth.append(idx) if idx_types_auth is not None and len(idx_types_auth) > 0: for idx in idx_types_auth: if idx not in idx_type_keys_auth: idx_type_keys_auth.append(idx) return (idx_keys_auth, idx_type_keys_auth)