Esempio n. 1
0
    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)
Esempio n. 2
0
    def put(self, exploration_id):
        """Handles PUT requests for draft updation."""
        # Raise an Exception if the draft change list fails non-strict
        # validation.
        change_list_dict = self.normalized_payload.get('change_list')
        change_list = [
            exp_domain.ExplorationChange(change) for change in change_list_dict
        ]

        version = self.normalized_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 changes are
        # not mergeable, 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),
            'changes_are_mergeable':
            exp_services.are_changes_mergeable(exploration_id, version,
                                               change_list)
        })
Esempio n. 3
0
    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)