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_elastic_model_names_round_trip(self): # getting the private ones (model_names_idx, model_names_idx_types) = elastic_factory.get_elastic_model_names(auth_public=False) self.assertIn('target_mifsud_idx', model_names_idx, 'target_mifsud_idx found') self.assertIn('cp_stats_gwas-gwas-anderson_idx_type', model_names_idx_types, 'cp_stats_gwas-gwas-anderson_idx_type found') (idx_keys, idx_type_keys) = elastic_factory.get_keys_from_model_names(model_names_idx, model_names_idx_types) self.assertIn('TARGET_MIFSUD', idx_keys, 'TARGET_MIFSUD found') self.assertIn('CP_STATS_IC.IC-NAR_FARACO', idx_type_keys, 'CP_STATS_IC.IC-NAR_FARACO found')
def test_get_keys_from_model_names(self): idx_model_names = ['disease_idx', 'gene_idx'] idx_type_model_names = ['gene-interactions_idx_type', 'marker-ic_idx_type', 'publication-publication_idx_type'] (idx_keys, idx_type_keys) = elastic_factory.get_keys_from_model_names(idx_model_names, idx_type_model_names) self.assertTrue('DISEASE' in idx_keys, 'got right idx key : DISEASE') self.assertTrue('GENE' in idx_keys, 'got right idx key : GENE') self.assertTrue('GENE.INTERACTIONS' in idx_type_keys, 'got right idx type key : GENE.INTERACTIONS') self.assertTrue('MARKER.IC' in idx_type_keys, 'got right idx type key : MARKER.IC') self.assertTrue('PUBLICATION.PUBLICATION' in idx_type_keys, 'got right idx type key : PUBLICATION.PUBLICATION')
def test_elastic_model_names_round_trip(self): # getting the private ones (model_names_idx, model_names_idx_types) = elastic_factory.get_elastic_model_names( auth_public=False) self.assertIn('target_mifsud_idx', model_names_idx, 'target_mifsud_idx found') self.assertIn('cp_stats_gwas-gwas-anderson_idx_type', model_names_idx_types, 'cp_stats_gwas-gwas-anderson_idx_type found') (idx_keys, idx_type_keys) = elastic_factory.get_keys_from_model_names( model_names_idx, model_names_idx_types) self.assertIn('TARGET_MIFSUD', idx_keys, 'TARGET_MIFSUD found') self.assertIn('CP_STATS_IC.IC-NAR_FARACO', idx_type_keys, 'CP_STATS_IC.IC-NAR_FARACO found')
def test_get_keys_from_model_names(self): idx_model_names = ['disease_idx', 'gene_idx'] idx_type_model_names = [ 'gene-interactions_idx_type', 'marker-ic_idx_type', 'publication-publication_idx_type' ] (idx_keys, idx_type_keys) = elastic_factory.get_keys_from_model_names( idx_model_names, idx_type_model_names) self.assertTrue('DISEASE' in idx_keys, 'got right idx key : DISEASE') self.assertTrue('GENE' in idx_keys, 'got right idx key : GENE') self.assertTrue('GENE.INTERACTIONS' in idx_type_keys, 'got right idx type key : GENE.INTERACTIONS') self.assertTrue('MARKER.IC' in idx_type_keys, 'got right idx type key : MARKER.IC') self.assertTrue('PUBLICATION.PUBLICATION' in idx_type_keys, 'got right idx type key : PUBLICATION.PUBLICATION')
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)