Exemple #1
0
    /// <summary>
    /// Publishes document.
    /// </summary>
    /// <param name="node">Node to publish</param>
    /// <param name="wm">Workflow manager</param>
    /// <returns>Whether node is already published</returns>
    private bool Publish(TreeNode node, WorkflowManager wm)
    {
        string           pathCulture      = HTMLHelper.HTMLEncode(node.NodeAliasPath + " (" + node.DocumentCulture + ")");
        WorkflowStepInfo currentStep      = wm.GetStepInfo(node);
        bool             alreadyPublished = (currentStep == null) || currentStep.StepIsPublished;

        if (!alreadyPublished)
        {
            using (CMSActionContext ctx = new CMSActionContext()
            {
                LogEvents = false
            })
            {
                // Remove possible checkout
                if (node.DocumentCheckedOutByUserID > 0)
                {
                    TreeProvider.ClearCheckoutInformation(node);
                    node.Update();
                }
            }

            // Publish document
            currentStep = wm.PublishDocument(node, null);
        }

        // Document is already published, check if still under workflow
        if (alreadyPublished && (currentStep != null) && currentStep.StepIsPublished)
        {
            WorkflowScopeInfo wsi = wm.GetNodeWorkflowScope(node);
            if (wsi == null)
            {
                DocumentHelper.ClearWorkflowInformation(node);
                VersionManager vm = VersionManager.GetInstance(node.TreeProvider);
                vm.RemoveWorkflow(node);
            }
        }

        // Document already published
        if (alreadyPublished)
        {
            AddLog(string.Format(ResHelper.GetString("content.publishedalready"), pathCulture));
        }
        else if ((currentStep == null) || !currentStep.StepIsPublished)
        {
            AddError(string.Format(ResHelper.GetString("content.PublishWasApproved"), pathCulture));
            return(true);
        }
        else
        {
            // Add log record
            AddLog(pathCulture);
        }

        return(false);
    }
Exemple #2
0
    /// <summary>
    /// Publishes document.
    /// </summary>
    /// <param name="node">Node to publish</param>
    /// <param name="wm">Workflow manager</param>
    /// <param name="currentStep">Current workflow step</param>
    /// <returns>Whether node is already published</returns>
    private static bool Publish(TreeNode node, WorkflowManager wm, WorkflowStepInfo currentStep)
    {
        bool toReturn = true;

        if (currentStep != null)
        {
            // For archive step start new version
            if (currentStep.StepName.ToLower() == "archived")
            {
                VersionManager vm = new VersionManager(node.TreeProvider);
                currentStep = vm.CheckOut(node, node.IsPublished, true);
                vm.CheckIn(node, null, null);
            }

            // Approve until the step is publish
            while ((currentStep != null) && (currentStep.StepName.ToLower() != "published"))
            {
                currentStep = wm.MoveToNextStep(node, string.Empty);
                toReturn    = false;
            }

            // Document is already published, check if still under workflow
            if (toReturn && (currentStep.StepName.ToLower() == "published"))
            {
                WorkflowScopeInfo wsi = wm.GetNodeWorkflowScope(node);
                if (wsi == null)
                {
                    DocumentHelper.ClearWorkflowInformation(node);
                    VersionManager vm = new VersionManager(node.TreeProvider);
                    vm.RemoveWorkflow(node);
                }
            }
        }

        return(toReturn);
    }
Exemple #3
0
    private void RemoveWorkflow(object parameter)
    {
        VersionManager verMan = VersionManager.GetInstance(Tree);
        TreeNode       node   = null;

        // Custom logging
        Tree.LogEvents         = false;
        Tree.AllowAsyncActions = false;
        CanceledString         = ResHelper.GetString("workflowdocuments.removingcanceled", currentCulture);
        try
        {
            // Begin log
            AddLog(ResHelper.GetString("content.preparingdocuments", currentCulture));

            string where = parameter as string;

            // Get the documents
            DataSet documents = GetDocumentsToProcess(where);

            if (!DataHelper.DataSourceIsEmpty(documents))
            {
                // Begin log
                AddLog(ResHelper.GetString("workflowdocuments.removingwf", currentCulture));

                foreach (DataTable classTable in documents.Tables)
                {
                    foreach (DataRow nodeRow in classTable.Rows)
                    {
                        // Get the current document
                        string className  = ValidationHelper.GetString(nodeRow["ClassName"], string.Empty);
                        string aliasPath  = ValidationHelper.GetString(nodeRow["NodeAliasPath"], string.Empty);
                        string docCulture = ValidationHelper.GetString(nodeRow["DocumentCulture"], string.Empty);
                        string siteName   = ValidationHelper.GetString(nodeRow["SiteName"], string.Empty);

                        // Get published version
                        node = Tree.SelectSingleNode(siteName, aliasPath, docCulture, false, className, false);
                        string encodedAliasPath = HTMLHelper.HTMLEncode(ValidationHelper.GetString(aliasPath, string.Empty) + " (" + node.GetValue("DocumentCulture") + ")");

                        // Destroy document history
                        verMan.DestroyDocumentHistory(node.DocumentID);

                        // Clear workflow
                        DocumentHelper.ClearWorkflowInformation(node);
                        node.Update();

                        // Add log record
                        AddLog(encodedAliasPath);

                        // Add record to eventlog
                        LogContext.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "Content", "REMOVEDOCWORKFLOW", currentUser.UserID,
                                            currentUser.UserName, node.NodeID, node.GetDocumentName(),
                                            HTTPHelper.UserHostAddress, string.Format(GetString("workflowdocuments.removeworkflowsuccess"), encodedAliasPath),
                                            node.NodeSiteID, HTTPHelper.GetAbsoluteUri(), HTTPHelper.MachineName, HTTPHelper.GetUrlReferrer(), HTTPHelper.GetUserAgent());
                    }
                }
                CurrentInfo = GetString("workflowdocuments.removecomplete");
            }
            else
            {
                AddError(ResHelper.GetString("workflowdocuments.nodocumentstoclear", currentCulture));
            }
        }
        catch (ThreadAbortException ex)
        {
            string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty);
            if (state == CMSThread.ABORT_REASON_STOP)
            {
                // When canceled
                CurrentInfo = CanceledString;
            }
            else
            {
                int siteId = (node != null) ? node.NodeSiteID : CMSContext.CurrentSiteID;
                // Log error
                LogExceptionToEventLog("REMOVEDOCWORKFLOW", "workflowdocuments.removefailed", ex, siteId);
            }
        }
        catch (Exception ex)
        {
            int siteId = (node != null) ? node.NodeSiteID : CMSContext.CurrentSiteID;
            // Log error
            LogExceptionToEventLog("REMOVEDOCWORKFLOW", "workflowdocuments.removefailed", ex, siteId);
        }
    }
    private void RemoveWorkflow(object parameter)
    {
        VersionManager verMan = VersionManager.GetInstance(Tree);
        TreeNode       node   = null;

        // Custom logging
        Tree.LogEvents         = false;
        Tree.AllowAsyncActions = false;
        CanceledString         = GetString("workflowdocuments.removingcanceled", mCurrentCulture);
        try
        {
            // Begin log
            AddLog(GetString("content.preparingdocuments", mCurrentCulture));

            string where = parameter as string;

            // Get the documents
            DataSet documents = GetDocumentsToProcess(where);

            if (!DataHelper.DataSourceIsEmpty(documents))
            {
                // Begin log
                AddLog(GetString("workflowdocuments.removingwf", mCurrentCulture));

                foreach (DataTable classTable in documents.Tables)
                {
                    foreach (DataRow nodeRow in classTable.Rows)
                    {
                        // Get the current document
                        string className  = ValidationHelper.GetString(nodeRow["ClassName"], string.Empty);
                        string aliasPath  = ValidationHelper.GetString(nodeRow["NodeAliasPath"], string.Empty);
                        string docCulture = ValidationHelper.GetString(nodeRow["DocumentCulture"], string.Empty);
                        string siteName   = SiteInfoProvider.GetSiteName(nodeRow["NodeSiteID"].ToInteger(0));

                        // Get published version
                        node = Tree.SelectSingleNode(siteName, aliasPath, docCulture, false, className, false);
                        string encodedAliasPath = HTMLHelper.HTMLEncode(ValidationHelper.GetString(aliasPath, string.Empty) + " (" + node.GetValue("DocumentCulture") + ")");

                        // Destroy document history
                        verMan.DestroyDocumentHistory(node.DocumentID);

                        using (new CMSActionContext {
                            LogEvents = false
                        })
                        {
                            // Clear workflow
                            DocumentHelper.ClearWorkflowInformation(node);
                            node.Update();
                        }

                        // Add log record
                        AddLog(encodedAliasPath);

                        // Add record to eventlog
                        LogContext.LogEventToCurrent(EventType.INFORMATION, "Content", "REMOVEDOCWORKFLOW", string.Format(GetString("workflowdocuments.removeworkflowsuccess"), encodedAliasPath), RequestContext.RawURL, mCurrentUser.UserID, mCurrentUser.UserName, node.NodeID, node.GetDocumentName(), RequestContext.UserHostAddress, node.NodeSiteID, SystemContext.MachineName, RequestContext.URLReferrer, RequestContext.UserAgent, DateTime.Now);
                    }
                }
                CurrentInfo = GetString("workflowdocuments.removecomplete");
            }
            else
            {
                AddError(GetString("workflowdocuments.nodocumentstoclear", mCurrentCulture));
            }
        }
        catch (ThreadAbortException ex)
        {
            if (CMSThread.Stopped(ex))
            {
                // When canceled
                CurrentInfo = CanceledString;
            }
            else
            {
                int siteId = (node != null) ? node.NodeSiteID : SiteContext.CurrentSiteID;
                // Log error
                LogExceptionToEventLog("REMOVEDOCWORKFLOW", "workflowdocuments.removefailed", ex, siteId);
            }
        }
        catch (Exception ex)
        {
            int siteId = (node != null) ? node.NodeSiteID : SiteContext.CurrentSiteID;
            // Log error
            LogExceptionToEventLog("REMOVEDOCWORKFLOW", "workflowdocuments.removefailed", ex, siteId);
        }
    }
Exemple #5
0
    protected override void OnInit(EventArgs e)
    {
        ManagersContainer = plcManagers;

        CurrentUserInfo currentUser = CMSContext.CurrentUser;

        // Check UIProfile
        if (!currentUser.IsAuthorizedPerUIElement("CMS.Content", "EditForm"))
        {
            RedirectToCMSDeskUIElementAccessDenied("CMS.Content", "EditForm");
        }

        base.OnInit(e);

        ScriptHelper.RegisterStartupScript(this, typeof(string), "spellCheckDialog", GetSpellCheckDialog());

        // Register scripts
        string script = "function " + formElem.ClientID + "_RefreshForm(){" + Page.ClientScript.GetPostBackEventReference(btnRefresh, "") + " }";

        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), formElem.ClientID + "_RefreshForm", ScriptHelper.GetScript(script));

        ScriptHelper.RegisterCompletePageScript(this);
        ScriptHelper.RegisterProgress(this);
        ScriptHelper.RegisterDialogScript(this);

        confirmChanges = SettingsKeyProvider.GetBoolValue(CMSContext.CurrentSiteName + ".CMSConfirmChanges");

        formElem.TreeProvider     = TreeProvider;
        formElem.OnAfterDataLoad += formElem_OnAfterDataLoad;

        // Current nodeID
        nodeId = QueryHelper.GetInteger("nodeid", 0);

        // ClassID, used when creating new document
        classId = QueryHelper.GetInteger("classid", 0);

        // TemplateID, used when Use template selection is enabled in actual class
        templateId = QueryHelper.GetInteger("templateid", 0);


        // Analyze the action parameter
        switch (QueryHelper.GetString("action", "").ToLower())
        {
        case "new":
            // Check if document type is allowed under parent node
            if ((nodeId > 0) && (classId > 0))
            {
                // Get the node
                TreeNode      treeNode = TreeProvider.SelectSingleNode(nodeId);
                DataClassInfo dci      = DataClassInfoProvider.GetDataClass(classId);
                if ((treeNode == null) || (dci == null))
                {
                    throw new Exception("[Content.Edit]: Given node or document class cannot be found!");
                }

                // Check allowed document type
                if (!DataClassInfoProvider.IsChildClassAllowed(ValidationHelper.GetInteger(treeNode.GetValue("NodeClassID"), 0), classId))
                {
                    AddNotAllowedScript("child");
                }

                if (!currentUser.IsAuthorizedToCreateNewDocument(treeNode, dci.ClassName))
                {
                    AddNotAllowedScript("new");
                }
            }

            newdocument = true;
            break;

        case "newculture":
            // Check permissions
            bool authorized = false;
            if (nodeId > 0)
            {
                // Get the node
                TreeNode treeNode = TreeProvider.SelectSingleNode(nodeId);
                if (treeNode != null)
                {
                    authorized = currentUser.IsAuthorizedToCreateNewDocument(treeNode.NodeParentID, treeNode.NodeClassName);
                }
            }

            if (!authorized)
            {
                AddNotAllowedScript("newculture");
            }

            newculture = true;
            break;
        }

        // Get the node
        if (newculture || newdocument)
        {
            node = DocumentHelper.GetDocument(nodeId, TreeProvider.ALL_CULTURES, TreeProvider);
            if (newculture)
            {
                DocumentHelper.ClearWorkflowInformation(node);
            }
        }
        else
        {
            node = DocumentHelper.GetDocument(nodeId, CMSContext.PreferredCultureCode, TreeProvider);
            if ((node == null) && displaySplitMode)
            {
                URLHelper.Redirect("~/CMSModules/Content/CMSDesk/New/NewCultureVersion.aspx" + URLHelper.Url.Query);
            }
        }

        // Set edited document
        EditedDocument = node;

        if (!confirmChanges)
        {
            AddScript("confirmChanges = false;");
        }

        // If node found, init the form
        if (node != null)
        {
            // CMSForm initialization
            formElem.NodeId      = node.NodeID;
            formElem.CultureCode = CMSContext.PreferredCultureCode;

            // Set the form mode
            if (newdocument)
            {
                ci = DataClassInfoProvider.GetDataClass(classId);
                if (ci == null)
                {
                    throw new Exception("[Content/Edit.aspx]: Class ID '" + classId + "' not found.");
                }

                if (ci.ClassName.ToLower() == "cms.blog")
                {
                    if (!LicenseHelper.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Blogs, VersionActionEnum.Insert))
                    {
                        RedirectToAccessDenied(String.Format(GetString("cmsdesk.bloglicenselimits"), ""));
                    }
                }

                if (!LicenseHelper.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Documents, VersionActionEnum.Insert))
                {
                    RedirectToAccessDenied(String.Format(GetString("cmsdesk.documentslicenselimits"), ""));
                }

                // Check if need template selection, if so, then redirect to template selection page
                if ((ci.ClassShowTemplateSelection) && (templateId == 0) && (ci.ClassName.ToLower() != "cms.menuitem"))
                {
                    URLHelper.Redirect("~/CMSModules/Content/CMSDesk/TemplateSelection.aspx" + URLHelper.Url.Query);
                }

                // Set default template ID
                formElem.DefaultPageTemplateID = templateId > 0 ? templateId : ci.ClassDefaultPageTemplateID;

                formElem.FormMode = FormModeEnum.Insert;
                string newClassName = ci.ClassName;
                formElem.FormName = newClassName + ".default";
            }
            else if (newculture)
            {
                if (node.NodeClassName.ToLower() == "cms.blog")
                {
                    if (!LicenseHelper.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Blogs, VersionActionEnum.Insert))
                    {
                        RedirectToAccessDenied(String.Format(GetString("cmsdesk.bloglicenselimits"), ""));
                    }
                }

                if (!LicenseHelper.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Documents, VersionActionEnum.Insert))
                {
                    RedirectToAccessDenied(String.Format(GetString("cmsdesk.documentslicenselimits"), ""));
                }

                formElem.FormMode = FormModeEnum.InsertNewCultureVersion;
                // Default data document ID
                formElem.CopyDefaultDataFromDocumentId = ValidationHelper.GetInteger(Request.QueryString["sourcedocumentid"], 0);

                ci = DataClassInfoProvider.GetDataClass(node.NodeClassName);
                formElem.FormName = node.NodeClassName + ".default";
            }
            else
            {
                formElem.FormMode = FormModeEnum.Update;
                ci = DataClassInfoProvider.GetDataClass(node.NodeClassName);
            }
            formElem.Visible = true;

            // Display / hide the CK editor toolbar area
            FormInfo fi = FormHelper.GetFormInfo(ci.ClassName, false);

            if (fi.UsesHtmlArea())
            {
                // Add script to display toolbar
                if (formElem.HtmlAreaToolbarLocation.ToLower() == "out:cktoolbar")
                {
                    mShowToolbar = true;
                }
            }

            ReloadForm();
        }

        AddScript(
            "function SaveDocument(nodeId, createAnother) { document.getElementById('hidAnother').value = createAnother; " + (confirmChanges ? "AllowSubmit(); " : "") + ClientScript.GetPostBackEventReference(btnSave, null) + "; } \n" +
            "function Approve(nodeId) { SubmitAction(); " + ClientScript.GetPostBackEventReference(btnApprove, null) + "; } \n" +
            "function Reject(nodeId) { SubmitAction(); " + ClientScript.GetPostBackEventReference(btnReject, null) + "; } \n" +
            "function CheckIn(nodeId) { SubmitAction(); " + ClientScript.GetPostBackEventReference(btnCheckIn, null) + "; } \n" +
            (confirmChanges ? "var confirmLeave='" + GetString("Content.ConfirmLeave") + "'; \n" : "")
            );
    }