def test_get_all_accessible_by_hash_list_as_superuser_returns_other_user_template( self, ): mock_request = create_mock_request(user=self.superuser1) templates = template_api.get_all_accessible_by_hash_list( [self.fixture.user2_template.hash], request=mock_request) self.assertTrue(self.fixture.user1_template not in list(templates)) self.assertTrue(self.fixture.user2_template in list(templates)) self.assertTrue(self.fixture.global_template not in list(templates))
def test_get_all_accessible_by_hash_list_as_anonymous_does_not_return_global( self): mock_request = create_mock_request(user=self.anonymous_user) templates = template_api.get_all_accessible_by_hash_list( [self.fixture.global_template.hash], request=mock_request) self.assertTrue(templates.count() == 0)
def test_get_all_accessible_by_hash_list_as_user_does_not_return_other_user_template( self, ): mock_request = create_mock_request(user=self.user1) templates = template_api.get_all_accessible_by_hash_list( [self.fixture.user2_template.hash], request=mock_request) self.assertTrue(templates.count() == 0)
def __init__(self, *args, **kwargs): """Init the form Args: template_id_list: template_hash_list: data_url_list: """ self.export_options = [] self.data_url_list = [] self.template_id_list = [] self.template_hash_list = [] request = kwargs.pop("request") if "template_id_list" in kwargs and "template_hash_list" in kwargs: # Only stringified ObjectId in template_id_list self.template_id_list = [ item for item in kwargs.pop("template_id_list") if bson.objectid.ObjectId.is_valid(item) ] self.template_hash_list = kwargs.pop("template_hash_list") # Retrieves all corresponding templates templates_from_id = template_api.get_all_accessible_by_id_list( self.template_id_list, request=request ) templates_from_hash = template_api.get_all_accessible_by_hash_list( self.template_hash_list, request=request ) # Retrieves all common exporter for exporters given exporters_from_ids = list( exporters_api.get_all_by_template_list(templates_from_id) ) # with the hash, we can get more exporters than from ids exporters_from_hash = list( exporters_api.get_all_by_template_list(templates_from_hash) ) # if there is exporters from ids (means local data have been selected) if len(exporters_from_ids) > 0: exporters = exporters_from_ids # if there is exporters from hash (means remote data have been selected) if len(exporters_from_hash) > 0: # we get only common exporters exporters = set(exporters_from_ids).intersection( exporters_from_hash ) else: exporters = exporters_from_hash for exporter in exporters: self.export_options.append((exporter.id, exporter.name)) if "data_url_list" in kwargs: self.data_url_list = kwargs.pop("data_url_list") super(ExportForm, self).__init__(*args, **kwargs) self.fields["my_exporters"].choices = self.export_options