def put(self, exploration_id): """Updates properties of the given exploration.""" exploration = exp_fetchers.get_exploration_by_id(exploration_id) version = self.payload.get('version') _require_valid_version(version, exploration.version) commit_message = self.payload.get('commit_message') change_list_dict = self.payload.get('change_list') change_list = [ exp_domain.ExplorationChange(change) for change in change_list_dict] try: exploration_rights = rights_manager.get_exploration_rights( exploration_id) can_edit = rights_manager.check_can_edit_activity( self.user, exploration_rights) can_voiceover = rights_manager.check_can_voiceover_activity( self.user, exploration_rights) if can_edit: exp_services.update_exploration( self.user_id, exploration_id, change_list, commit_message) elif can_voiceover: exp_services.update_exploration( self.user_id, exploration_id, change_list, commit_message, is_by_voice_artist=True) except utils.ValidationError as e: raise self.InvalidInputException(e) exploration_data = exp_services.get_user_exploration_data( self.user_id, exploration_id) self.values.update(exploration_data) self.render_json(self.values)
def get(self, exploration_id): """Gets the data for the exploration overview page.""" # 'apply_draft' and 'v'(version) are optional parameters because the # exploration history tab also uses this handler, and these parameters # are not used by that tab. version = self.normalized_request.get('v') apply_draft = self.normalized_request.get('apply_draft') user_settings = user_services.get_user_settings(self.user_id) has_seen_editor_tutorial = False has_seen_translation_tutorial = False if user_settings is not None: if user_settings.last_started_state_editor_tutorial: has_seen_editor_tutorial = True if user_settings.last_started_state_translation_tutorial: has_seen_translation_tutorial = True try: exploration_data = exp_services.get_user_exploration_data( self.user_id, exploration_id, apply_draft=apply_draft, version=version) exploration_data['show_state_editor_tutorial_on_load'] = ( self.user_id and not has_seen_editor_tutorial) exploration_data['show_state_translation_tutorial_on_load'] = ( self.user_id and not has_seen_translation_tutorial) exploration_data['exploration_is_linked_to_story'] = ( exp_services.get_story_id_linked_to_exploration(exploration_id) is not None) except Exception as e: raise self.PageNotFoundException from e self.values.update(exploration_data) self.render_json(self.values)
def put(self, exploration_id): """Updates properties of the given exploration. Args: exploration_id: str. Id of exploration to be updated. Raises: InvalidInputException: The exploration update operation failed. PageNotFoundException: No exploration data exist for given user id and exploration id. """ exploration = exp_fetchers.get_exploration_by_id(exploration_id) version = self.payload.get('version') _require_valid_version(version, exploration.version) commit_message = self.payload.get('commit_message') change_list_dict = self.payload.get('change_list') change_list = [ exp_domain.ExplorationChange(change) for change in change_list_dict] try: exp_services.update_exploration( self.user_id, exploration_id, change_list, commit_message, is_by_voice_artist=True) except utils.ValidationError as e: raise self.InvalidInputException(e) exploration_data = exp_services.get_user_exploration_data( self.user_id, exploration_id) self.values.update(exploration_data) self.render_json(self.values)
def put(self, exploration_id): """Updates properties of the given exploration.""" exploration = exp_services.get_exploration_by_id(exploration_id) version = self.payload.get('version') _require_valid_version(version, exploration.version) commit_message = self.payload.get('commit_message') change_list_dict = self.payload.get('change_list') change_list = [ exp_domain.ExplorationChange(change) for change in change_list_dict] try: exp_services.update_exploration( self.user_id, exploration_id, change_list, commit_message) except utils.ValidationError as e: raise self.InvalidInputException(e) try: exploration_data = exp_services.get_user_exploration_data( self.user_id, exploration_id) exploration_data['show_state_editor_tutorial_on_load'] = ( self.user_id and not self.has_seen_editor_tutorial) except: raise self.PageNotFoundException self.values.update(exploration_data) self.render_json(self.values)
def put(self, exploration_id): """Updates properties of the given exploration.""" exploration = exp_fetchers.get_exploration_by_id(exploration_id) version = self.payload.get('version') if version is None: raise base.BaseHandler.InvalidInputException( 'Invalid POST request: a version must be specified.') if version > exploration.version: raise base.BaseHandler.InvalidInputException( 'Trying to update version %s of exploration from version %s, ' 'which is not possible. Please reload the page and try again.' % (exploration.version, 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_dict = self.payload.get('change_list') try: change_list = [ exp_domain.ExplorationChange(change) for change in change_list_dict ] except utils.ValidationError as e: raise self.InvalidInputException(e) changes_are_mergeable = exp_services.are_changes_mergeable( exploration_id, version, change_list) exploration_rights = rights_manager.get_exploration_rights( exploration_id) can_edit = rights_manager.check_can_edit_activity( self.user, exploration_rights) can_voiceover = rights_manager.check_can_voiceover_activity( self.user, exploration_rights) try: if can_edit and changes_are_mergeable: exp_services.update_exploration( self.user_id, exploration_id, change_list, commit_message) elif can_voiceover and changes_are_mergeable: exp_services.update_exploration( self.user_id, exploration_id, change_list, commit_message, is_by_voice_artist=True) except utils.ValidationError as e: raise self.InvalidInputException(e) exploration_data = exp_services.get_user_exploration_data( self.user_id, exploration_id) self.values.update(exploration_data) self.render_json(self.values)
def put(self, exploration_id): """Handles PUT requests for draft updation.""" # Raise an Exception if the draft change list fails non-strict # validation. try: change_list_dict = self.payload.get('change_list') change_list = [ exp_domain.ExplorationChange(change) for change in change_list_dict ] except utils.ValidationError as e: # We leave any pre-existing draft changes in the datastore. raise self.InvalidInputException(e) version = self.payload.get('version') exploration_rights = rights_manager.get_exploration_rights( exploration_id) can_edit = rights_manager.check_can_edit_activity( self.user, exploration_rights) can_voiceover = rights_manager.check_can_voiceover_activity( self.user, exploration_rights) try: if can_edit: exp_services.create_or_update_draft(exploration_id, self.user_id, change_list, version, datetime.datetime.utcnow()) elif can_voiceover: exp_services.create_or_update_draft(exploration_id, self.user_id, change_list, version, datetime.datetime.utcnow(), is_by_voice_artist=True) except utils.ValidationError as e: # We leave any pre-existing draft changes in the datastore. raise self.InvalidInputException(e) exp_user_data = exp_services.get_user_exploration_data( self.user_id, exploration_id) # If the draft_change_list_id is False, have the user discard the draft # changes. We save the draft to the datastore even if the version is # invalid, so that it is available for recovery later. self.render_json({ 'draft_change_list_id': exp_user_data['draft_change_list_id'], 'is_version_of_draft_valid': exp_services.is_version_of_draft_valid(exploration_id, version) })
def put(self, exploration_id): """Updates properties of the given exploration.""" exploration = exp_fetchers.get_exploration_by_id(exploration_id) version = self.payload.get('version') _require_valid_version(version, exploration.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_dict = self.payload.get('change_list') try: change_list = [ exp_domain.ExplorationChange(change) for change in change_list_dict ] except utils.ValidationError as e: raise self.InvalidInputException(e) exploration_rights = rights_manager.get_exploration_rights( exploration_id) can_edit = rights_manager.check_can_edit_activity( self.user, exploration_rights) can_voiceover = rights_manager.check_can_voiceover_activity( self.user, exploration_rights) try: if can_edit: exp_services.update_exploration(self.user_id, exploration_id, change_list, commit_message) elif can_voiceover: exp_services.update_exploration(self.user_id, exploration_id, change_list, commit_message, is_by_voice_artist=True) except utils.ValidationError as e: raise self.InvalidInputException(e) exploration_data = exp_services.get_user_exploration_data( self.user_id, exploration_id) self.values.update(exploration_data) self.render_json(self.values)
def put(self, exploration_id): """Updates properties of the given exploration.""" exploration = exp_fetchers.get_exploration_by_id(exploration_id) version = self.normalized_payload.get('version') if version > exploration.version: raise base.BaseHandler.InvalidInputException( 'Trying to update version %s of exploration from version %s, ' 'which is not possible. Please reload the page and try again.' % (exploration.version, version)) commit_message = self.normalized_payload.get('commit_message') change_list_dict = self.normalized_payload.get('change_list') change_list = [ exp_domain.ExplorationChange(change) for change in change_list_dict ] changes_are_mergeable = exp_services.are_changes_mergeable( exploration_id, version, change_list) exploration_rights = rights_manager.get_exploration_rights( exploration_id) can_edit = rights_manager.check_can_edit_activity( self.user, exploration_rights) can_voiceover = rights_manager.check_can_voiceover_activity( self.user, exploration_rights) try: if can_edit and changes_are_mergeable: exp_services.update_exploration(self.user_id, exploration_id, change_list, commit_message) elif can_voiceover and changes_are_mergeable: exp_services.update_exploration(self.user_id, exploration_id, change_list, commit_message, is_by_voice_artist=True) except utils.ValidationError as e: raise self.InvalidInputException(e) exploration_data = exp_services.get_user_exploration_data( self.user_id, exploration_id) self.values.update(exploration_data) self.render_json(self.values)
def get(self, exploration_id): """Gets the data for the exploration overview page.""" # 'apply_draft' and 'v'(version) are optional parameters because the # exploration history tab also uses this handler, and these parameters # are not used by that tab. version = self.request.get('v', default_value=None) apply_draft = self.request.get('apply_draft', default_value=False) try: exploration_data = exp_services.get_user_exploration_data( self.user_id, exploration_id, apply_draft=apply_draft, version=version) exploration_data['show_state_editor_tutorial_on_load'] = ( self.user_id and not self.has_seen_editor_tutorial) except: raise self.PageNotFoundException self.values.update(exploration_data) self.render_json(self.values)
def put(self, exploration_id): """Updates properties of the given exploration.""" exploration = exp_fetchers.get_exploration_by_id(exploration_id) version = self.payload.get('version') _require_valid_version(version, exploration.version) commit_message = self.payload.get('commit_message') change_list_dict = self.payload.get('change_list') change_list = [ exp_domain.ExplorationChange(change) for change in change_list_dict] try: exp_services.update_exploration( self.user_id, exploration_id, change_list, commit_message) except utils.ValidationError as e: raise self.InvalidInputException(e) exploration_data = exp_services.get_user_exploration_data( self.user_id, exploration_id) self.values.update(exploration_data) self.render_json(self.values)
def get(self, exploration_id): """Gets the data for the exploration overview page.""" # 'apply_draft' and 'v'(version) are optional parameters because the # exploration history tab also uses this handler, and these parameters # are not used by that tab. version = self.request.get('v', default_value=None) apply_draft = self.request.get('apply_draft', default_value=False) try: exploration_data = exp_services.get_user_exploration_data( self.user_id, exploration_id, apply_draft=apply_draft, version=version) exploration_data['show_state_editor_tutorial_on_load'] = ( self.user_id and not self.has_seen_editor_tutorial) except: raise self.PageNotFoundException whitelisted_exp_ids = ( config_domain.WHITELISTED_EXPLORATION_IDS_FOR_PLAYTHROUGHS.value) self.values.update({ 'whitelisted_exploration_ids_for_playthroughs': whitelisted_exp_ids }) self.values.update(exploration_data) self.render_json(self.values)