Пример #1
0
    def delete_item(self, location, user_id, revision=None, **kwargs):
        """
        Delete the given item from persistence. kwargs allow modulestore specific parameters.

        Args:
            location: UsageKey of the item to be deleted
            user_id: id of the user deleting the item
            revision:
                None - deletes the item and its subtree, and updates the parents per description above
                ModuleStoreEnum.RevisionOption.published_only - removes only Published versions
                ModuleStoreEnum.RevisionOption.all - removes both Draft and Published parents
                    currently only provided by contentstore.views.item.orphan_handler
                Otherwise, raises a ValueError.
        """
        with self.bulk_operations(location.course_key):
            if revision == ModuleStoreEnum.RevisionOption.published_only:
                branches_to_delete = [ModuleStoreEnum.BranchName.published]
            elif revision == ModuleStoreEnum.RevisionOption.all:
                branches_to_delete = [ModuleStoreEnum.BranchName.published, ModuleStoreEnum.BranchName.draft]
            elif revision is None:
                branches_to_delete = [ModuleStoreEnum.BranchName.draft]
            else:
                raise UnsupportedRevisionError(
                    [
                        None,
                        ModuleStoreEnum.RevisionOption.published_only,
                        ModuleStoreEnum.RevisionOption.all
                    ]
                )

            for branch in branches_to_delete:
                branched_location = location.for_branch(branch)
                parent_loc = self.get_parent_location(branched_location)
                SplitMongoModuleStore.delete_item(self, branched_location, user_id)
                self._auto_publish_no_children(parent_loc, parent_loc.category, user_id, **kwargs)
Пример #2
0
    def delete_item(self, location, user_id, revision=None, **kwargs):
        """
        Delete the given item from persistence. kwargs allow modulestore specific parameters.

        Args:
            location: UsageKey of the item to be deleted
            user_id: id of the user deleting the item
            revision:
                None - deletes the item and its subtree, and updates the parents per description above
                ModuleStoreEnum.RevisionOption.published_only - removes only Published versions
                ModuleStoreEnum.RevisionOption.all - removes both Draft and Published parents
                    currently only provided by contentstore.views.item.orphan_handler
                Otherwise, raises a ValueError.
        """
        if revision == ModuleStoreEnum.RevisionOption.published_only:
            branches_to_delete = [ModuleStoreEnum.BranchName.published]
        elif revision == ModuleStoreEnum.RevisionOption.all:
            branches_to_delete = [ModuleStoreEnum.BranchName.published, ModuleStoreEnum.BranchName.draft]
        elif revision is None:
            branches_to_delete = [ModuleStoreEnum.BranchName.draft]
        else:
            raise UnsupportedRevisionError(
                [
                    None,
                    ModuleStoreEnum.RevisionOption.published_only,
                    ModuleStoreEnum.RevisionOption.all
                ]
            )

        for branch in branches_to_delete:
            branched_location = location.for_branch(branch)
            parent_loc = self.get_parent_location(branched_location)
            SplitMongoModuleStore.delete_item(self, branched_location, user_id)
            self._auto_publish_no_children(parent_loc, parent_loc.category, user_id, **kwargs)
Пример #3
0
    def revert_to_published(self, location, user_id):
        """
        Reverts an item to its last published version (recursively traversing all of its descendants).
        If no published version exists, a VersionConflictError is thrown.

        If a published version exists but there is no draft version of this item or any of its descendants, this
        method is a no-op.

        :raises InvalidVersionError: if no published version exists for the location specified
        """
        if location.category in DIRECT_ONLY_CATEGORIES:
            return

        if not self.has_item(location, revision=ModuleStoreEnum.RevisionOption.published_only):
            raise InvalidVersionError(location)

        SplitMongoModuleStore.copy(
            self,
            user_id,
            # Directly using the replace function rather than the for_branch function
            # because for_branch obliterates the version_guid and will lead to missed version conflicts.
            # TODO Instead, the for_branch implementation should be fixed in the Opaque Keys library.
            location.course_key.replace(branch=ModuleStoreEnum.BranchName.published),
            location.course_key.for_branch(ModuleStoreEnum.BranchName.draft),
            [location]
        )
Пример #4
0
    def delete_item(self, location, user_id, revision=None, **kwargs):
        """
        Delete the given item from persistence. kwargs allow modulestore specific parameters.

        Args:
            location: UsageKey of the item to be deleted
            user_id: id of the user deleting the item
            revision:
                None - deletes the item and its subtree, and updates the parents per description above
                ModuleStoreEnum.RevisionOption.published_only - removes only Published versions
                ModuleStoreEnum.RevisionOption.all - removes both Draft and Published parents
                    currently only provided by contentstore.views.item.orphan_handler
                Otherwise, raises a ValueError.
        """
        if revision == ModuleStoreEnum.RevisionOption.published_only:
            branches_to_delete = [ModuleStoreEnum.BranchName.published]
        elif revision == ModuleStoreEnum.RevisionOption.all:
            branches_to_delete = [
                ModuleStoreEnum.BranchName.published,
                ModuleStoreEnum.BranchName.draft
            ]
        elif revision is None:
            branches_to_delete = [ModuleStoreEnum.BranchName.draft]
        else:
            raise ValueError(
                'revision not one of None, ModuleStoreEnum.RevisionOption.published_only, or ModuleStoreEnum.RevisionOption.all'
            )
        for branch in branches_to_delete:
            SplitMongoModuleStore.delete_item(self,
                                              location.for_branch(branch),
                                              user_id, **kwargs)
Пример #5
0
 def publish(self, location, user_id, **kwargs):
     """
     Save a current draft to the underlying modulestore.
     Returns the newly published item.
     """
     SplitMongoModuleStore.copy(
         self,
         user_id,
         location.course_key.for_branch(ModuleStoreEnum.BranchName.draft),
         location.course_key.for_branch(ModuleStoreEnum.BranchName.published),
         [location],
     )
Пример #6
0
 def publish(self, location, user_id, **kwargs):
     """
     Save a current draft to the underlying modulestore.
     Returns the newly published item.
     """
     SplitMongoModuleStore.copy(
         self,
         user_id,
         location.course_key.for_branch(ModuleStoreEnum.BranchName.draft),
         location.course_key.for_branch(
             ModuleStoreEnum.BranchName.published),
         [location],
     )
Пример #7
0
 def publish(self, location, user_id, blacklist=None, **kwargs):
     """
     Publishes the subtree under location from the draft branch to the published branch
     Returns the newly published item.
     """
     SplitMongoModuleStore.copy(
         self,
         user_id,
         # Directly using the replace function rather than the for_branch function
         # because for_branch obliterates the version_guid and will lead to missed version conflicts.
         location.course_key.replace(branch=ModuleStoreEnum.BranchName.draft),
         location.course_key.for_branch(ModuleStoreEnum.BranchName.published),
         [location],
         blacklist=blacklist
     )
     return self.get_item(location.for_branch(ModuleStoreEnum.BranchName.published), **kwargs)
Пример #8
0
 def publish(self, location, user_id, blacklist=None, **kwargs):
     """
     Publishes the subtree under location from the draft branch to the published branch
     Returns the newly published item.
     """
     SplitMongoModuleStore.copy(
         self,
         user_id,
         # Directly using the replace function rather than the for_branch function
         # because for_branch obliterates the version_guid and will lead to missed version conflicts.
         # TODO Instead, the for_branch implementation should be fixed in the Opaque Keys library.
         location.course_key.replace(branch=ModuleStoreEnum.BranchName.draft),
         # We clear out the version_guid here because the location here is from the draft branch, and that
         # won't have the same version guid
         location.course_key.replace(branch=ModuleStoreEnum.BranchName.published, version_guid=None),
         [location],
         blacklist=blacklist
     )
     return self.get_item(location.for_branch(ModuleStoreEnum.BranchName.published), **kwargs)
Пример #9
0
 def publish(self, location, user_id, blacklist=None, **kwargs):
     """
     Publishes the subtree under location from the draft branch to the published branch
     Returns the newly published item.
     """
     SplitMongoModuleStore.copy(
         self,
         user_id,
         # Directly using the replace function rather than the for_branch function
         # because for_branch obliterates the version_guid and will lead to missed version conflicts.
         location.course_key.replace(branch=ModuleStoreEnum.BranchName.draft
                                     ),
         location.course_key.for_branch(
             ModuleStoreEnum.BranchName.published),
         [location],
         blacklist=blacklist)
     return self.get_item(
         location.for_branch(ModuleStoreEnum.BranchName.published),
         **kwargs)
Пример #10
0
 def get_parent_location(self, location, revision=None, **kwargs):
     '''
     Returns the given location's parent location in this course.
     Args:
         revision:
             None - uses the branch setting for the revision
             ModuleStoreEnum.RevisionOption.published_only
                 - return only the PUBLISHED parent if it exists, else returns None
             ModuleStoreEnum.RevisionOption.draft_preferred
                 - return either the DRAFT or PUBLISHED parent, preferring DRAFT, if parent(s) exists,
                     else returns None
     '''
     if revision == ModuleStoreEnum.RevisionOption.draft_preferred:
         revision = ModuleStoreEnum.RevisionOption.draft_only
     location = self._map_revision_to_branch(location, revision=revision)
     return SplitMongoModuleStore.get_parent_location(self, location, **kwargs)
Пример #11
0
 def get_parent_location(self, location, revision=None, **kwargs):
     '''
     Returns the given location's parent location in this course.
     Args:
         revision:
             None - uses the branch setting for the revision
             ModuleStoreEnum.RevisionOption.published_only
                 - return only the PUBLISHED parent if it exists, else returns None
             ModuleStoreEnum.RevisionOption.draft_preferred
                 - return either the DRAFT or PUBLISHED parent, preferring DRAFT, if parent(s) exists,
                     else returns None
     '''
     if revision == ModuleStoreEnum.RevisionOption.draft_preferred:
         revision = ModuleStoreEnum.RevisionOption.draft_only
     location = self._map_revision_to_branch(location, revision=revision)
     return SplitMongoModuleStore.get_parent_location(self, location, **kwargs)