Пример #1
0
    /// <summary>
    /// Deletes a specified document version. Called when the "Delete version" button is pressed.
    /// Expects the "CreateExampleObjects" and at least the "EditDocument" method to be run first.
    /// </summary>
    private bool DeleteVersion()
    {
        TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

        // Prepare parameters
        string siteName  = CMSContext.CurrentSiteName;
        string aliasPath = "/API-Example";
        string culture   = "en-us";
        bool   combineWithDefaultCulture = false;
        string classNames = TreeProvider.ALL_CLASSNAMES;

        string where = null;
        string orderBy             = null;
        int    maxRelativeLevel    = -1;
        bool   selectOnlyPublished = false;
        string columns             = null;

        // Get the document
        TreeNode node = DocumentHelper.GetDocument(siteName, aliasPath, culture, combineWithDefaultCulture, classNames, where, orderBy, maxRelativeLevel, selectOnlyPublished, columns, tree);

        if (node != null)
        {
            // Prepare the WHERE condition for the latest document version
            where   = "DocumentID = " + node.DocumentID;
            orderBy = "ModifiedWhen DESC";
            int topN = 1;

            // Get the version ID
            DataSet versionHistory = VersionHistoryInfoProvider.GetVersionHistories(where, orderBy, topN, columns);

            if (!DataHelper.DataSourceIsEmpty(versionHistory))
            {
                // Create the Version history info object
                VersionHistoryInfo version = new VersionHistoryInfo(versionHistory.Tables[0].Rows[0]);

                VersionManager versionManager = VersionManager.GetInstance(tree);

                // Delete the version
                versionManager.DestroyDocumentVersion(version.VersionHistoryID);

                return(true);
            }
            else
            {
                apiDeleteVersion.ErrorMessage = "The document's version history is empty.";
            }
        }

        return(false);
    }
Пример #2
0
        //Reverting to published version if i am editing a published document and then go for edit it.
        //But i have not changed any thing and click on cancel button.
        //Document should shown as published again
        //It was showing as draft because its creating a new version.So added code here for showing that document as published.
        public static bool RollbackToPreviousVersion(int NodeID)
        {
            TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);

            // Prepare parameters
            string siteName = SiteContext.CurrentSiteName;
            string culture  = "en-us";

            string where = null;
            string orderBy = null;
            string columns = null;

            // Get the document
            TreeNode node = DocumentHelper.GetDocument(NodeID, culture, tree);

            if (node != null)
            {
                // Prepare the WHERE condition for the oldest document version
                where   = "DocumentID = " + node.DocumentID;
                orderBy = "ModifiedWhen DESC";
                int topN = 2;

                // Get the version ID
                DataSet versionHistory = VersionHistoryInfoProvider.GetVersionHistories(where, orderBy, topN, columns);

                if (!DataHelper.DataSourceIsEmpty(versionHistory) && node.IsPublished == true)
                {
                    // Create the Version history info object
                    //get the details of previous version of this document
                    VersionHistoryInfo version        = new VersionHistoryInfo(versionHistory.Tables[0].Rows[1]);
                    VersionManager     versionManager = VersionManager.GetInstance(tree);
                    //get the workflow stepid of previous version of this document
                    int WorkFlowStepID = Convert.ToInt32(version.VersionWorkflowStepID);
                    //move that document to previous version workflow state
                    MoveToWorkflowStep(WorkFlowStepID, tree, node);
                }
                else if (!DataHelper.DataSourceIsEmpty(versionHistory) && versionHistory.Tables[0].Rows.Count > 1)
                {
                    // Create the Version history info object
                    //get the details of previous version of this document
                    VersionHistoryInfo version        = new VersionHistoryInfo(versionHistory.Tables[0].Rows[1]);
                    VersionManager     versionManager = VersionManager.GetInstance(tree);
                    //get the workflow stepid of previous version of this document
                    int WorkFlowStepID = Convert.ToInt32(version.VersionWorkflowStepID);
                    //move that document to previous version workflow state
                    MoveToWorkflowStep(WorkFlowStepID, tree, node);
                }
            }
            return(true);
        }
Пример #3
0
 private void DestroyDocumentHistory(VersionHistoryInfo versionHistoryInfo, VersionManager versionManager)
 {
     try
     {
         if (IsAuthorizedPerDocument(versionHistoryInfo, "Destroy", mCurrentUser))
         {
             versionManager.DestroyDocumentHistory(versionHistoryInfo.DocumentID);
             ShowConfirmation(GetString("recyclebin.destroyok"));
         }
         else
         {
             ShowError(String.Format(ResHelper.GetString("recyclebin.destructionfailedpermissions", mCurrentCulture), HTMLHelper.HTMLEncode(versionHistoryInfo.DocumentNamePath)));
         }
     }
     catch (Exception ex)
     {
         LogAndShowError("Content", "DESTROYDOC", ex);
     }
 }
Пример #4
0
 private void RestoreDocumentVersion(VersionHistoryInfo versionHistoryInfo, VersionManager versionManager)
 {
     try
     {
         if (IsAuthorizedPerDocument(versionHistoryInfo, "Create", mCurrentUser))
         {
             versionManager.RestoreDocument(versionHistoryInfo.VersionHistoryID);
             ShowConfirmation(GetString("Recyclebin.RestorationOK"));
         }
         else
         {
             ShowError(String.Format(ResHelper.GetString("Recyclebin.RestorationFailedPermissions", mCurrentCulture), HTMLHelper.HTMLEncode(versionHistoryInfo.DocumentNamePath)));
         }
     }
     catch (Exception ex)
     {
         LogAndShowError("Content", "RESTOREDOC", ex);
     }
 }
Пример #5
0
    /// <summary>
    /// Restores the document from the recycle bin. Called when the "Restore document" button is pressed.
    /// Expects the "CreateDocumentStructure" and "MoveDocumentToRecycleBin" methods to be run first.
    /// </summary>
    private bool RestoreFromRecycleBin()
    {
        // Prepare the where condition
        string where = "VersionNodeAliasPath LIKE N'/API-Example/Document-1'";

        // Get the recycled document
        DataSet recycleBin = VersionHistoryInfoProvider.GetRecycleBin(CMSContext.CurrentSiteID, where, null, 0, "VersionHistoryID");

        if (!DataHelper.DataSourceIsEmpty(recycleBin))
        {
            // Create a new version history info object from the data row
            VersionHistoryInfo version = new VersionHistoryInfo(recycleBin.Tables[0].Rows[0]);

            // Create a new version manager instance and restore the document
            VersionManager manager = new VersionManager(new TreeProvider(CMSContext.CurrentUser));
            manager.RestoreDocument(version.VersionHistoryID);

            return(true);
        }

        return(false);
    }
Пример #6
0
    /// <summary>
    /// Check user permissions for document.
    /// </summary>
    /// <param name="versionHistoryInfo">Document version history info</param>
    /// <param name="permission">Permissions</param>
    /// <param name="user">User</param>
    /// <returns>TreeNode if authorized, null otherwise</returns>
    private bool IsAuthorizedPerDocument(VersionHistoryInfo versionHistoryInfo, string permission, CurrentUserInfo user)
    {
        // Check global permission
        var userHasGlobalPerm = user.IsAuthorizedPerResource("CMS.Content", permission);

        // Get the values form deleted node
        var className = new DocumentClassNameRetriever(versionHistoryInfo.Data, true).Retrieve();

        var additionalPermission = false;

        if (permission.Equals("create", StringComparison.InvariantCultureIgnoreCase))
        {
            additionalPermission = user.IsAuthorizedPerClassName(className, "CreateSpecific");
        }

        // Check permissions
        if (userHasGlobalPerm || user.IsAuthorizedPerClassName(className, permission) || additionalPermission)
        {
            return(true);
        }

        return(false);
    }
    /// <summary>
    /// Restores the document from the recycle bin. Called when the "Restore document" button is pressed.
    /// Expects the "CreateDocumentStructure" and "MoveDocumentToRecycleBin" methods to be run first.
    /// </summary>
    private bool RestoreFromRecycleBin()
    {
        // Prepare the where condition
        string where = "VersionNodeAliasPath LIKE N'/API-Example/Document-1'";

        // Get the recycled document
        DataSet recycleBin = VersionHistoryInfoProvider.GetRecycleBin(CMSContext.CurrentSiteID, where, null, 0, "VersionHistoryID");

        if (!DataHelper.DataSourceIsEmpty(recycleBin))
        {
            // Create a new version history info object from the data row
            VersionHistoryInfo version = new VersionHistoryInfo(recycleBin.Tables[0].Rows[0]);

            // Create a new version manager instance and restore the document
            VersionManager manager = VersionManager.GetInstance(new TreeProvider(CMSContext.CurrentUser));
            manager.RestoreDocument(version.VersionHistoryID);

            return true;
        }

        return false;
    }
    /// <summary>
    /// Rolls the document back to a specified document version. Called when the "Rollback version" button is pressed.
    /// Expects the "CreateExampleObjects" and at least the "EditDocument" method to be run first.
    /// </summary>
    private bool RollbackVersion()
    {
        TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);

        // Prepare parameters
        string siteName = SiteContext.CurrentSiteName;
        string aliasPath = "/API-Example";
        string culture = "en-us";
        bool combineWithDefaultCulture = false;
        string classNames = TreeProvider.ALL_CLASSNAMES;
        string where = null;
        string orderBy = null;
        int maxRelativeLevel = -1;
        bool selectOnlyPublished = false;
        string columns = null;

        // Get the document
        TreeNode node = DocumentHelper.GetDocument(siteName, aliasPath, culture, combineWithDefaultCulture, classNames, where, orderBy, maxRelativeLevel, selectOnlyPublished, columns, tree);

        if (node != null)
        {
            // Prepare the WHERE condition for the oldest document version
            where = "DocumentID = " + node.DocumentID;
            orderBy = "ModifiedWhen ASC";
            int topN = 1;

            // Get the version ID
            DataSet versionHistory = VersionHistoryInfoProvider.GetVersionHistories(where, orderBy, topN, columns);

            if (!DataHelper.DataSourceIsEmpty(versionHistory))
            {
                // Create the Version history info object
                VersionHistoryInfo version = new VersionHistoryInfo(versionHistory.Tables[0].Rows[0]);

                VersionManager versionManager = VersionManager.GetInstance(tree);

                // Roll back version
                versionManager.RollbackVersion(version.VersionHistoryID);

                return true;
            }
            else
            {
                apiRollbackVersion.ErrorMessage = "The page's version history is empty.";
            }
        }

        return false;
    }