def map(item): # We're inline importing here to break import loops like this: (-> # means imports): # exp_services -> event_services -> jobs_registry -> # exp_jobs -> exp_services. from core.domain import exp_services if not item.deleted: exp_services.index_explorations_given_ids([item.id])
def _publish_exploration(self, exploration_id): """Publish an exploration. Args: exploration_id: str. Id of the exploration. Raises: InvalidInputException: Given exploration is invalid. """ exploration = exp_services.get_exploration_by_id(exploration_id) try: exploration.validate(strict=True) except utils.ValidationError as e: raise self.InvalidInputException(e) exp_services.publish_exploration_and_update_user_profiles( self.user, exploration_id) exp_services.index_explorations_given_ids([exploration_id])
def _generate_dummy_explorations(self, num_dummy_exps_to_generate, num_dummy_exps_to_publish): """ Generates and publishes the given number of dummy explorations. Args: num_dummy_exps_to_generate: int. Count of dummy explorations to be generated. num_dummy_exps_to_publish: int. Count of explorations to be published. Raises: Exception: Environment is not DEVMODE. """ if feconf.DEV_MODE: logging.info( '[ADMIN] %s generated %s number of dummy explorations' % (self.user_id, num_dummy_exps_to_generate)) possible_titles = [ 'Hulk Neuroscience', 'Quantum Starks', 'Wonder Anatomy', 'Elvish, language of "Lord of the Rings', 'The Science of Superheroes' ] exploration_ids_to_publish = [] for i in range(num_dummy_exps_to_generate): title = random.choice(possible_titles) category = random.choice(feconf.SEARCH_DROPDOWN_CATEGORIES) new_exploration_id = exp_services.get_new_exploration_id() exploration = exp_domain.Exploration.create_default_exploration( new_exploration_id, title=title, category=category, objective='Dummy Objective') exp_services.save_new_exploration(self.user_id, exploration) if i <= num_dummy_exps_to_publish - 1: exploration_ids_to_publish.append(new_exploration_id) rights_manager.publish_exploration(self.user, new_exploration_id) exp_services.index_explorations_given_ids( exploration_ids_to_publish) else: raise Exception( 'Cannot generate dummy explorations in production.')
def setUp(self): super(CollectionNodeMetadataDictsTest, self).setUp() self.signup(self.ALBERT_EMAIL, self.ALBERT_NAME) self.signup(self.BOB_EMAIL, self.BOB_NAME) self.albert_id = self.get_user_id_from_email(self.ALBERT_EMAIL) self.bob_id = self.get_user_id_from_email(self.BOB_EMAIL) self.albert = user_services.get_user_actions_info(self.albert_id) self.bob = user_services.get_user_actions_info(self.bob_id) self.save_new_valid_exploration( self.EXP_ID1, self.albert_id, title='Exploration 1 Albert title', objective='An objective 1') self.save_new_valid_exploration( self.EXP_ID2, self.albert_id, title='Exploration 2 Albert title', objective='An objective 2') self.save_new_valid_exploration( self.EXP_ID3, self.albert_id, title='Exploration 3 Albert title', objective='An objective 3') self.save_new_valid_exploration( self.EXP_ID4, self.bob_id, title='Exploration 4 Bob title', objective='An objective 4') self.save_new_valid_exploration( self.EXP_ID5, self.albert_id, title='Exploration 5 Albert title', objective='An objective 5') rights_manager.publish_exploration(self.albert, self.EXP_ID1) rights_manager.publish_exploration(self.albert, self.EXP_ID2) rights_manager.publish_exploration(self.albert, self.EXP_ID3) rights_manager.publish_exploration(self.bob, self.EXP_ID4) exp_services.index_explorations_given_ids([ self.EXP_ID1, self.EXP_ID2, self.EXP_ID3, self.EXP_ID4])
def test_library_handler_with_given_category_and_language_code(self): self.login(self.ADMIN_EMAIL) exp_id = exp_fetchers.get_new_exploration_id() self.save_new_valid_exploration(exp_id, self.admin_id) self.publish_exploration(self.admin_id, exp_id) exp_services.index_explorations_given_ids([exp_id]) response_dict = self.get_json( feconf.LIBRARY_SEARCH_DATA_URL, params={ 'category': 'A category', 'language_code': 'en' }) activity_list = ( summary_services.get_displayable_exp_summary_dicts_matching_ids( [exp_id])) self.assertEqual(response_dict['activity_list'], activity_list) self.logout()
def setUp(self): super(CollectionNodeMetadataDictsTest, self).setUp() self.albert_id = self.get_user_id_from_email(self.ALBERT_EMAIL) self.signup(self.ALBERT_EMAIL, self.ALBERT_NAME) self.bob_id = self.get_user_id_from_email(self.BOB_EMAIL) self.signup(self.BOB_EMAIL, self.BOB_NAME) self.save_new_valid_exploration(self.EXP_ID1, self.albert_id, title='Exploration 1 Albert title', objective='An objective 1') self.save_new_valid_exploration(self.EXP_ID2, self.albert_id, title='Exploration 2 Albert title', objective='An objective 2') self.save_new_valid_exploration(self.EXP_ID3, self.albert_id, title='Exploration 3 Albert title', objective='An objective 3') self.save_new_valid_exploration(self.EXP_ID4, self.bob_id, title='Exploration 4 Bob title', objective='An objective 4') self.save_new_valid_exploration(self.EXP_ID5, self.albert_id, title='Exploration 5 Albert title', objective='An objective 5') rights_manager.publish_exploration(self.albert_id, self.EXP_ID1) rights_manager.publish_exploration(self.albert_id, self.EXP_ID2) rights_manager.publish_exploration(self.albert_id, self.EXP_ID3) rights_manager.publish_exploration(self.bob_id, self.EXP_ID4) exp_services.index_explorations_given_ids([ self.EXP_ID1, self.EXP_ID2, self.EXP_ID3, self.EXP_ID4])
def put(self, exploration_id): """Updates the editing rights for the given exploration.""" exploration = exp_services.get_exploration_by_id(exploration_id) version = self.payload.get('version') _require_valid_version(version, exploration.version) is_public = self.payload.get('is_public') is_publicized = self.payload.get('is_publicized') is_community_owned = self.payload.get('is_community_owned') new_member_username = self.payload.get('new_member_username') new_member_role = self.payload.get('new_member_role') viewable_if_private = self.payload.get('viewable_if_private') if new_member_username: if not rights_manager.Actor( self.user_id).can_modify_roles( rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration_id): raise self.UnauthorizedUserException( 'Only an owner of this exploration can add or change ' 'roles.') new_member_id = user_services.get_user_id_from_username( new_member_username) if new_member_id is None: raise Exception( 'Sorry, we could not find the specified user.') rights_manager.assign_role_for_exploration( self.user_id, exploration_id, new_member_id, new_member_role) elif is_public is not None: exploration = exp_services.get_exploration_by_id(exploration_id) if is_public: try: exploration.validate(strict=True) except utils.ValidationError as e: raise self.InvalidInputException(e) exp_services.publish_exploration_and_update_user_profiles( self.user_id, exploration_id) exp_services.index_explorations_given_ids([exploration_id]) else: rights_manager.unpublish_exploration( self.user_id, exploration_id) exp_services.delete_documents_from_search_index([ exploration_id]) elif is_publicized is not None: exploration = exp_services.get_exploration_by_id(exploration_id) if is_publicized: try: exploration.validate(strict=True) except utils.ValidationError as e: raise self.InvalidInputException(e) rights_manager.publicize_exploration( self.user_id, exploration_id) else: rights_manager.unpublicize_exploration( self.user_id, exploration_id) elif is_community_owned: exploration = exp_services.get_exploration_by_id(exploration_id) try: exploration.validate(strict=True) except utils.ValidationError as e: raise self.InvalidInputException(e) rights_manager.release_ownership_of_exploration( self.user_id, exploration_id) elif viewable_if_private is not None: rights_manager.set_private_viewability_of_exploration( self.user_id, exploration_id, viewable_if_private) else: raise self.InvalidInputException( 'No change was made to this exploration.') self.render_json({ 'rights': rights_manager.get_exploration_rights( exploration_id).to_dict() })
def map(item): if not item.deleted: exp_services.index_explorations_given_ids([item.id])
def test_gallery_handler_for_created_explorations(self): """Test the gallery data handler for manually created explirations.""" self.set_admins([self.ADMIN_USERNAME]) self.login(self.ADMIN_EMAIL) response_dict = self.get_json(feconf.GALLERY_DATA_URL) self.assertEqual({ 'is_admin': True, 'is_moderator': True, 'is_super_admin': False, 'explorations_list': [], 'user_email': self.ADMIN_EMAIL, 'username': self.ADMIN_USERNAME, 'search_cursor': None, 'profile_picture_data_url': None, 'preferred_language_codes': [feconf.DEFAULT_LANGUAGE_CODE], }, response_dict) # Create exploration A exploration = self.save_new_valid_exploration( 'A', self.admin_id, title='Title A', category='Category A', objective='Objective A') exp_services._save_exploration( # pylint: disable=protected-access self.admin_id, exploration, 'Exploration A', []) # Test that the private exploration isn't displayed. response_dict = self.get_json(feconf.GALLERY_DATA_URL) self.assertEqual(response_dict['explorations_list'], []) # Create exploration B exploration = self.save_new_valid_exploration( 'B', self.admin_id, title='Title B', category='Category B', objective='Objective B') exp_services._save_exploration( # pylint: disable=protected-access self.admin_id, exploration, 'Exploration B', []) rights_manager.publish_exploration(self.admin_id, 'B') rights_manager.publicize_exploration(self.admin_id, 'B') # Publish exploration A rights_manager.publish_exploration(self.admin_id, 'A') exp_services.index_explorations_given_ids(['A', 'B']) # Test gallery response_dict = self.get_json(feconf.GALLERY_DATA_URL) self.assertEqual(len(response_dict['explorations_list']), 2) self.assertDictContainsSubset({ 'id': 'B', 'category': 'Category B', 'title': 'Title B', 'language_code': 'en', 'objective': 'Objective B', 'status': rights_manager.ACTIVITY_STATUS_PUBLICIZED, }, response_dict['explorations_list'][0]) self.assertDictContainsSubset({ 'id': 'A', 'category': 'Category A', 'title': 'Title A', 'language_code': 'en', 'objective': 'Objective A', 'status': rights_manager.ACTIVITY_STATUS_PUBLIC, }, response_dict['explorations_list'][1]) # Delete exploration A exp_services.delete_exploration(self.admin_id, 'A') # Test gallery response_dict = self.get_json(feconf.GALLERY_DATA_URL) self.assertEqual(len(response_dict['explorations_list']), 1) self.assertDictContainsSubset({ 'id': 'B', 'category': 'Category B', 'title': 'Title B', 'language_code': 'en', 'objective': 'Objective B', 'status': rights_manager.ACTIVITY_STATUS_PUBLICIZED, }, response_dict['explorations_list'][0])
def put(self, exploration_id): """Updates the editing rights for the given exploration.""" exploration = exp_services.get_exploration_by_id(exploration_id) version = self.payload.get('version') _require_valid_version(version, exploration.version) is_public = self.payload.get('is_public') is_publicized = self.payload.get('is_publicized') is_community_owned = self.payload.get('is_community_owned') new_member_username = self.payload.get('new_member_username') new_member_role = self.payload.get('new_member_role') viewable_if_private = self.payload.get('viewable_if_private') if new_member_username: if not rights_manager.Actor(self.user_id).can_modify_roles( rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration_id): raise self.UnauthorizedUserException( 'Only an owner of this exploration can add or change ' 'roles.') new_member_id = user_services.get_user_id_from_username( new_member_username) if new_member_id is None: raise Exception('Sorry, we could not find the specified user.') rights_manager.assign_role_for_exploration(self.user_id, exploration_id, new_member_id, new_member_role) elif is_public is not None: exploration = exp_services.get_exploration_by_id(exploration_id) if is_public: try: exploration.validate(strict=True) except utils.ValidationError as e: raise self.InvalidInputException(e) exp_services.publish_exploration_and_update_user_profiles( self.user_id, exploration_id) exp_services.index_explorations_given_ids([exploration_id]) else: rights_manager.unpublish_exploration(self.user_id, exploration_id) exp_services.delete_documents_from_search_index( [exploration_id]) elif is_publicized is not None: exploration = exp_services.get_exploration_by_id(exploration_id) if is_publicized: try: exploration.validate(strict=True) except utils.ValidationError as e: raise self.InvalidInputException(e) rights_manager.publicize_exploration(self.user_id, exploration_id) else: rights_manager.unpublicize_exploration(self.user_id, exploration_id) elif is_community_owned: exploration = exp_services.get_exploration_by_id(exploration_id) try: exploration.validate(strict=True) except utils.ValidationError as e: raise self.InvalidInputException(e) rights_manager.release_ownership_of_exploration( self.user_id, exploration_id) elif viewable_if_private is not None: rights_manager.set_private_viewability_of_exploration( self.user_id, exploration_id, viewable_if_private) else: raise self.InvalidInputException( 'No change was made to this exploration.') self.render_json({ 'rights': rights_manager.get_exploration_rights(exploration_id).to_dict() })
def test_library_handler_for_created_explorations(self): """Test the library data handler for manually created explorations.""" self.set_admins([self.ADMIN_USERNAME]) self.login(self.ADMIN_EMAIL) response_dict = self.get_json(feconf.LIBRARY_SEARCH_DATA_URL) self.assertDictContainsSubset( { 'is_admin': True, 'is_moderator': True, 'is_super_admin': False, 'activity_list': [], 'user_email': self.ADMIN_EMAIL, 'username': self.ADMIN_USERNAME, 'search_cursor': None, }, response_dict) # Create exploration A. exploration = self.save_new_valid_exploration('A', self.admin_id, title='Title A', category='Category A', objective='Objective A') exp_services._save_exploration( # pylint: disable=protected-access self.admin_id, exploration, 'Exploration A', []) # Test that the private exploration isn't displayed. response_dict = self.get_json(feconf.LIBRARY_SEARCH_DATA_URL) self.assertEqual(response_dict['activity_list'], []) # Create exploration B. exploration = self.save_new_valid_exploration('B', self.admin_id, title='Title B', category='Category B', objective='Objective B') exp_services._save_exploration( # pylint: disable=protected-access self.admin_id, exploration, 'Exploration B', []) rights_manager.publish_exploration(self.admin, 'B') # Publish exploration A. rights_manager.publish_exploration(self.admin, 'A') exp_services.index_explorations_given_ids(['A', 'B']) # Load the search results with an empty query. response_dict = self.get_json(feconf.LIBRARY_SEARCH_DATA_URL) self.assertEqual(len(response_dict['activity_list']), 2) self.assertDictContainsSubset( { 'id': 'B', 'category': 'Category B', 'title': 'Title B', 'language_code': 'en', 'objective': 'Objective B', 'status': rights_manager.ACTIVITY_STATUS_PUBLIC, }, response_dict['activity_list'][1]) self.assertDictContainsSubset( { 'id': 'A', 'category': 'Category A', 'title': 'Title A', 'language_code': 'en', 'objective': 'Objective A', 'status': rights_manager.ACTIVITY_STATUS_PUBLIC, }, response_dict['activity_list'][0]) # Delete exploration A. exp_services.delete_exploration(self.admin_id, 'A') # Load the search results with an empty query. response_dict = self.get_json(feconf.LIBRARY_SEARCH_DATA_URL) self.assertEqual(len(response_dict['activity_list']), 1) self.assertDictContainsSubset( { 'id': 'B', 'category': 'Category B', 'title': 'Title B', 'language_code': 'en', 'objective': 'Objective B', 'status': rights_manager.ACTIVITY_STATUS_PUBLIC, }, response_dict['activity_list'][0])
def map(item): exp_services.index_explorations_given_ids([item.id])
def test_gallery_handler_for_created_explorations(self): """Test the gallery data handler for manually created explirations.""" self.set_admins([self.ADMIN_EMAIL]) self.login(self.ADMIN_EMAIL) response_dict = self.get_json(feconf.GALLERY_DATA_URL) self.assertEqual( { 'is_admin': True, 'is_moderator': True, 'is_super_admin': False, 'explorations_list': [], 'user_email': self.ADMIN_EMAIL, 'username': self.ADMIN_USERNAME, 'search_cursor': None, 'profile_picture_data_url': None, 'preferred_language_codes': [feconf.DEFAULT_LANGUAGE_CODE], }, response_dict) # Create exploration A exploration = self.save_new_valid_exploration('A', self.ADMIN_ID, title='Title A', category='Category A', objective='Objective A') exp_services._save_exploration(self.ADMIN_ID, exploration, 'Exploration A', []) # Test that the private exploration isn't displayed. response_dict = self.get_json(feconf.GALLERY_DATA_URL) self.assertEqual(response_dict['explorations_list'], []) # Create exploration B exploration = self.save_new_valid_exploration('B', self.ADMIN_ID, title='Title B', category='Category B', objective='Objective B') exp_services._save_exploration(self.ADMIN_ID, exploration, 'Exploration B', []) rights_manager.publish_exploration(self.ADMIN_ID, 'B') rights_manager.publicize_exploration(self.ADMIN_ID, 'B') # Publish exploration A rights_manager.publish_exploration(self.ADMIN_ID, 'A') exp_services.index_explorations_given_ids(['A', 'B']) # Test gallery response_dict = self.get_json(feconf.GALLERY_DATA_URL) self.assertEqual(len(response_dict['explorations_list']), 2) self.assertDictContainsSubset( { 'id': 'B', 'category': 'Category B', 'title': 'Title B', 'language_code': 'en', 'objective': 'Objective B', 'status': rights_manager.ACTIVITY_STATUS_PUBLICIZED, }, response_dict['explorations_list'][0]) self.assertDictContainsSubset( { 'id': 'A', 'category': 'Category A', 'title': 'Title A', 'language_code': 'en', 'objective': 'Objective A', 'status': rights_manager.ACTIVITY_STATUS_PUBLIC, }, response_dict['explorations_list'][1]) # Delete exploration A exp_services.delete_exploration(self.ADMIN_ID, 'A') # Test gallery response_dict = self.get_json(feconf.GALLERY_DATA_URL) self.assertEqual(len(response_dict['explorations_list']), 1) self.assertDictContainsSubset( { 'id': 'B', 'category': 'Category B', 'title': 'Title B', 'language_code': 'en', 'objective': 'Objective B', 'status': rights_manager.ACTIVITY_STATUS_PUBLICIZED, }, response_dict['explorations_list'][0])
def map(item): from core.domain import exp_services exp_services.index_explorations_given_ids([item.id])