def test_get_learner_dict_with_deleted_exp_fails_validation(self): self.save_new_valid_collection( self.COLLECTION_ID, self.owner_id, exploration_id=self.EXP_ID) summary_services.get_learner_collection_dict_by_id( self.COLLECTION_ID, self.owner_id) exp_services.delete_exploration(self.owner_id, self.EXP_ID) with self.assertRaisesRegexp( utils.ValidationError, 'Expected collection to only reference valid explorations, but ' 'found an exploration with ID: exploration_id'): summary_services.get_learner_collection_dict_by_id( self.COLLECTION_ID, self.owner_id)
def test_get_learner_dict_with_deleted_exp_fails_validation(self): self.save_new_valid_collection( self.COLLECTION_ID, self.owner_id, exploration_id=self.EXP_ID) summary_services.get_learner_collection_dict_by_id( self.COLLECTION_ID, self.owner) exp_services.delete_exploration(self.owner_id, self.EXP_ID) with self.assertRaisesRegex( utils.ValidationError, 'Expected collection to only reference valid explorations, but ' 'found an exploration with ID: exploration_id'): summary_services.get_learner_collection_dict_by_id( self.COLLECTION_ID, self.owner)
def put(self, collection_id): """Updates properties of the given collection.""" collection = collection_services.get_collection_by_id(collection_id) version = self.payload.get('version') _require_valid_version(version, collection.version) commit_message = self.payload.get('commit_message') if (commit_message is not None and len(commit_message) > constants.MAX_COMMIT_MESSAGE_LENGTH): raise self.InvalidInputException( 'Commit messages must be at most %s characters long.' % constants.MAX_COMMIT_MESSAGE_LENGTH) change_list = self.payload.get('change_list') collection_services.update_collection(self.user_id, collection_id, change_list, commit_message) collection_dict = (summary_services.get_learner_collection_dict_by_id( collection_id, self.user, allow_invalid_explorations=True)) # Send the updated collection back to the frontend. self.values.update({'collection': collection_dict}) self.render_json(self.values)
def put(self, collection_id): """Updates properties of the given collection.""" collection = collection_services.get_collection_by_id(collection_id) version = self.payload.get('version') self._require_valid_version(version, collection.version) commit_message = self.payload.get('commit_message') change_list = self.payload.get('change_list') try: collection_services.update_collection( self.user_id, collection_id, change_list, commit_message) except utils.ValidationError as e: raise self.InvalidInputException(e) collection_dict = ( summary_services.get_learner_collection_dict_by_id( collection_id, self.user_id, allow_invalid_explorations=True)) # Send the updated collection back to the frontend. self.values.update({ 'collection': collection_dict }) self.render_json(self.values)
def get(self, collection_id): """Populates the data on the individual collection page.""" allow_invalid_explorations = bool( self.request.get('allow_invalid_explorations')) try: collection_dict = ( summary_services.get_learner_collection_dict_by_id( collection_id, self.user_id, allow_invalid_explorations=allow_invalid_explorations)) except Exception as e: raise self.PageNotFoundException(e) self.values.update({ 'can_edit': (self.user_id and rights_manager.Actor(self.user_id).can_edit( rights_manager.ACTIVITY_TYPE_COLLECTION, collection_id)), 'collection': collection_dict, 'is_logged_in': bool(self.user_id), 'session_id': utils.generate_new_session_id(), }) self.render_json(self.values)
def get(self, collection_id): """Populates the data on the individual collection page.""" collection_dict = (summary_services.get_learner_collection_dict_by_id( collection_id, self.user, allow_invalid_explorations=True)) self.values.update({'collection': collection_dict}) self.render_json(self.values)
def test_get_learner_dict_when_referencing_inaccessible_explorations(self): self.save_new_default_collection(self.COLLECTION_ID, self.owner_id) self.save_new_valid_exploration(self.EXP_ID, self.editor_id) collection_services.update_collection( self.owner_id, self.COLLECTION_ID, [{ 'cmd': collection_domain.CMD_ADD_COLLECTION_NODE, 'exploration_id': self.EXP_ID }], 'Added another creator\'s private exploration') # A collection cannot access someone else's private exploration. rights_manager.publish_collection(self.owner, self.COLLECTION_ID) with self.assertRaisesRegex( utils.ValidationError, 'Expected collection to only reference valid explorations, but ' 'found an exploration with ID: exploration_id'): summary_services.get_learner_collection_dict_by_id( self.COLLECTION_ID, self.owner) # After the exploration is published, the dict can now be created. rights_manager.publish_exploration(self.editor, self.EXP_ID) summary_services.get_learner_collection_dict_by_id( self.COLLECTION_ID, self.owner)
def test_get_learner_dict_when_referencing_inaccessible_explorations(self): self.save_new_default_collection(self.COLLECTION_ID, self.owner_id) self.save_new_valid_exploration(self.EXP_ID, self.editor_id) collection_services.update_collection( self.owner_id, self.COLLECTION_ID, [{ 'cmd': collection_domain.CMD_ADD_COLLECTION_NODE, 'exploration_id': self.EXP_ID }], 'Added another creator\'s private exploration') # A collection cannot access someone else's private exploration. rights_manager.publish_collection(self.owner_id, self.COLLECTION_ID) with self.assertRaisesRegexp( utils.ValidationError, 'Expected collection to only reference valid explorations, but ' 'found an exploration with ID: exploration_id'): summary_services.get_learner_collection_dict_by_id( self.COLLECTION_ID, self.owner_id) # After the exploration is published, the dict can now be created. rights_manager.publish_exploration(self.editor_id, self.EXP_ID) summary_services.get_learner_collection_dict_by_id( self.COLLECTION_ID, self.owner_id)
def get(self, collection_id): """Populates the data on the individual collection page.""" try: # Try to retrieve collection collection_dict = ( summary_services.get_learner_collection_dict_by_id( collection_id, self.user, allow_invalid_explorations=True)) except Exception as e: raise self.PageNotFoundException(e) self.values.update({'collection': collection_dict}) self.render_json(self.values)
def test_get_learner_collection_dict_by_id_without_user_id(self): self.save_new_valid_exploration(self.EXP_ID, self.owner_id) self.save_new_valid_collection(self.COLLECTION_ID, self.owner_id, exploration_id=self.EXP_ID) rights_manager.publish_exploration(self.owner, self.EXP_ID) rights_manager.publish_collection(self.owner, self.COLLECTION_ID) mock_user = user_services.get_user_actions_info(None) collection_dict = (summary_services.get_learner_collection_dict_by_id( self.COLLECTION_ID, mock_user)) self.assertEqual( len(collection_dict['playthrough_dict'] ['completed_exploration_ids']), 0) self.assertEqual( collection_dict['playthrough_dict']['next_exploration_id'], self.EXP_ID)
def get(self, collection_id): """Populates the data on the individual collection page.""" try: # Try to retrieve collection collection_dict = ( summary_services.get_learner_collection_dict_by_id( collection_id, self.user_id, allow_invalid_explorations=True)) except Exception as e: raise self.PageNotFoundException(e) self.values.update({ 'collection': collection_dict }) self.render_json(self.values)
def get(self, collection_id): """Populates the data on the individual collection page.""" try: collection_dict = ( summary_services.get_learner_collection_dict_by_id( collection_id, self.user, allow_invalid_explorations=False)) except Exception as e: raise self.PageNotFoundException(e) collection_rights = rights_manager.get_collection_rights( collection_id, strict=False) self.values.update({ 'can_edit': rights_manager.check_can_edit_activity( self.user, collection_rights), 'collection': collection_dict, 'is_logged_in': bool(self.user_id), 'session_id': utils.generate_new_session_id(), }) self.render_json(self.values)
def get(self, collection_id): """Populates the data on the individual collection page.""" try: collection_dict = ( summary_services.get_learner_collection_dict_by_id( collection_id, self.user_id, allow_invalid_explorations=False)) except Exception as e: raise self.PageNotFoundException(e) self.values.update({ 'can_edit': ( self.user_id and rights_manager.Actor(self.user_id).can_edit( feconf.ACTIVITY_TYPE_COLLECTION, collection_id)), 'collection': collection_dict, 'is_logged_in': bool(self.user_id), 'session_id': utils.generate_new_session_id(), }) self.render_json(self.values)
def put(self, collection_id): """Updates properties of the given collection.""" collection = collection_services.get_collection_by_id(collection_id) version = self.normalized_payload.get('version') _require_valid_version(version, collection.version) commit_message = self.normalized_payload.get('commit_message') change_list = self.normalized_payload.get('change_list') collection_services.update_collection( self.user_id, collection_id, [change.to_dict() for change in change_list], commit_message) collection_dict = (summary_services.get_learner_collection_dict_by_id( collection_id, self.user, allow_invalid_explorations=True)) # Send the updated collection back to the frontend. self.values.update({'collection': collection_dict}) self.render_json(self.values)
def test_get_learner_dict_with_allowed_private_exps(self): self.save_new_valid_collection( self.COLLECTION_ID, self.owner_id, exploration_id=self.EXP_ID) self.save_new_valid_exploration(self.EXP_ID_1, self.editor_id) collection_services.update_collection( self.owner_id, self.COLLECTION_ID, [{ 'cmd': collection_domain.CMD_ADD_COLLECTION_NODE, 'exploration_id': self.EXP_ID_1 }], 'Added another creator\'s private exploration') rights_manager.publish_collection(self.owner_id, self.COLLECTION_ID) collection_dict = summary_services.get_learner_collection_dict_by_id( self.COLLECTION_ID, self.owner_id, allow_invalid_explorations=True) # The author's private exploration will be contained in the public # collection since invalid explorations are being allowed, but the # private exploration of another author will not. collection_node_dicts = collection_dict['nodes'] self.assertEqual( collection_node_dicts[0]['exploration_summary']['id'], self.EXP_ID) self.assertIsNone(collection_node_dicts[1]['exploration_summary'])
def test_get_learner_dict_with_allowed_private_exps(self): self.save_new_valid_collection(self.COLLECTION_ID, self.owner_id, exploration_id=self.EXP_ID) self.save_new_valid_exploration(self.EXP_ID_1, self.editor_id) collection_services.update_collection( self.owner_id, self.COLLECTION_ID, [{ 'cmd': collection_domain.CMD_ADD_COLLECTION_NODE, 'exploration_id': self.EXP_ID_1 }], 'Added another creator\'s private exploration') rights_manager.publish_collection(self.owner, self.COLLECTION_ID) collection_dict = summary_services.get_learner_collection_dict_by_id( self.COLLECTION_ID, self.owner, allow_invalid_explorations=True) # The author's private exploration will be contained in the public # collection since invalid explorations are being allowed, but the # private exploration of another author will not. collection_node_dicts = collection_dict['nodes'] self.assertEqual(collection_node_dicts[0]['exploration_summary']['id'], self.EXP_ID) self.assertIsNone(collection_node_dicts[1]['exploration_summary'])
def get(self, collection_id): """Populates the data on the individual collection page.""" collection_dict = (summary_services.get_learner_collection_dict_by_id( collection_id, self.user, allow_invalid_explorations=False)) collection_rights = rights_manager.get_collection_rights(collection_id, strict=False) self.values.update({ 'can_edit': rights_manager.check_can_edit_activity(self.user, collection_rights), 'collection': collection_dict, 'is_logged_in': bool(self.user_id), 'session_id': utils.generate_new_session_id(), 'meta_name': collection_dict['title'], 'meta_description': utils.capitalize_string(collection_dict['objective']) }) self.render_json(self.values)
def test_get_learner_dict_with_private_exp_fails_validation(self): self.save_new_valid_collection( self.COLLECTION_ID, self.owner_id, exploration_id=self.EXP_ID) # Since both the collection and exploration are private, the learner # dict can be created. summary_services.get_learner_collection_dict_by_id( self.COLLECTION_ID, self.owner) # A public collection referencing a private exploration is bad, however. rights_manager.publish_collection(self.owner, self.COLLECTION_ID) with self.assertRaisesRegex( utils.ValidationError, 'Cannot reference a private exploration within a public ' 'collection, exploration ID: exploration_id'): summary_services.get_learner_collection_dict_by_id( self.COLLECTION_ID, self.owner) # After the exploration is published, the learner dict can be crated # again. rights_manager.publish_exploration(self.owner, self.EXP_ID) summary_services.get_learner_collection_dict_by_id( self.COLLECTION_ID, self.owner)
def test_get_learner_dict_with_private_exp_fails_validation(self): self.save_new_valid_collection( self.COLLECTION_ID, self.owner_id, exploration_id=self.EXP_ID) # Since both the collection and exploration are private, the learner # dict can be created. summary_services.get_learner_collection_dict_by_id( self.COLLECTION_ID, self.owner_id) # A public collection referencing a private exploration is bad, however. rights_manager.publish_collection(self.owner_id, self.COLLECTION_ID) with self.assertRaisesRegexp( utils.ValidationError, 'Cannot reference a private exploration within a public ' 'collection, exploration ID: exploration_id'): summary_services.get_learner_collection_dict_by_id( self.COLLECTION_ID, self.owner_id) # After the exploration is published, the learner dict can be crated # again. rights_manager.publish_exploration(self.owner_id, self.EXP_ID) summary_services.get_learner_collection_dict_by_id( self.COLLECTION_ID, self.owner_id)