Ejemplo n.º 1
0
    /// <summary>
    /// Moves the document to the previous step in the workflow process. Called when the "Move to previous step" button is pressed.
    /// Expects the "CreateExampleObjects" and "MoveToNextStep" method to be run first.
    /// </summary>
    private bool MoveToPreviousStep()
    {
        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)
        {
            WorkflowManager workflowManager = WorkflowManager.GetInstance(tree);

            WorkflowInfo workflow = workflowManager.GetNodeWorkflow(node);

            // Check if the document uses workflow
            if (workflow != null)
            {
                // Check if the workflow doesn't use automatic publishing, otherwise, documents can't change workflow steps.
                if (!workflow.WorkflowAutoPublishChanges)
                {
                    // Check if the current user can move the document to the next step
                    if (workflowManager.CheckStepPermissions(node, WorkflowActionEnum.Reject))
                    {
                        // Move the document to the previous step
                        workflowManager.MoveToPreviousStep(node, null);

                        return(true);
                    }
                    else
                    {
                        apiMoveToPreviousStep.ErrorMessage = "You are not authorized to reject the document.";
                    }
                }
                else
                {
                    apiMoveToPreviousStep.ErrorMessage = "The document uses versioning without workflow, changes are published automatically.";
                }
            }
            else
            {
                apiMoveToPreviousStep.ErrorMessage = "The document doesn't use workflow.";
            }
        }

        return(false);
    }
Ejemplo n.º 2
0
    protected object gridHistory_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        sourceName = sourceName.ToLowerCSafe();
        switch (sourceName)
        {
        case "rollback":
            ImageButton imgRollback = ((ImageButton)sender);
            if (!WorkflowManager.CheckStepPermissions(Node, WorkflowActionEnum.Approve) || !CanModify || (CheckedOutByAnotherUser && !CanCheckIn))
            {
                imgRollback.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/undodisabled.png");
                imgRollback.Enabled  = false;
            }
            break;

        case "allowdestroy":
            ImageButton imgDestroy = ((ImageButton)sender);
            if (!CanDestroy || (CheckedOutByAnotherUser && !CanCheckIn))
            {
                imgDestroy.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/deletedisabled.png");
                imgDestroy.Enabled  = false;
            }
            break;

        case "tobepublished":
            return(ValidationHelper.GetBoolean(parameter, false) ? "<span class=\"StatusEnabled\">" + GetString("general.yes") + "</span>" : string.Empty);

        case "publishfrom":
        case "publishto":
        case "waspublishedfrom":
        case "waspublishedto":

        case "publishfromtooltip":
        case "publishtotooltip":
        case "waspublishedfromtooltip":
        case "waspublishedtotooltip":
            return(TimeZoneHelper.ConvertToUserTimeZone(ValidationHelper.GetDateTime(parameter, DateTimeHelper.ZERO_TIME), sourceName.EndsWithCSafe("tooltip"), CurrentUser, CurrentSiteInfo));

        case "modifiedwhenby":
        case "modifiedwhenbytooltip":
            DataRowView data         = (DataRowView)parameter;
            DateTime    modifiedwhen = ValidationHelper.GetDateTime(data["ModifiedWhen"], DateTimeHelper.ZERO_TIME);
            if (sourceName == "modifiedwhenbytooltip")
            {
                return(TimeZoneHelper.ConvertToUserTimeZone(modifiedwhen, true, CurrentUser, CurrentSiteInfo));
            }
            else
            {
                string userName = ValidationHelper.GetString(data["UserName"], String.Empty);
                string fullName = ValidationHelper.GetString(data["FullName"], String.Empty);

                return(TimeZoneHelper.ConvertToUserTimeZone(modifiedwhen, false, CurrentUser, CurrentSiteInfo) + "<br />" + HTMLHelper.HTMLEncode(Functions.GetFormattedUserName(userName, fullName)));
            }
        }

        return(parameter);
    }
Ejemplo n.º 3
0
    protected void btnCheckin_Click(object sender, EventArgs e)
    {
        try
        {
            // Check permissions
            if (!WorkflowManager.CheckStepPermissions(Node, WorkflowActionEnum.Approve) || ((versionsElem.CheckedOutByUserID != MembershipContext.AuthenticatedUser.UserID) && !versionsElem.CanCheckIn))
            {
                DisableForm();
                return;
            }

            // Check in the document
            string version = null;
            if (txtVersion.Text.Trim() != string.Empty)
            {
                version = txtVersion.Text.Trim();
            }
            string comment = null;
            if (txtComment.Text.Trim() != string.Empty)
            {
                comment = txtComment.Text.Trim();
            }

            VersionManager.CheckIn(Node, version, comment);

            txtComment.Text = "";
            txtVersion.Text = "";

            DocumentManager.ClearContentChanged();

            // Refresh tree if icon checked out was displayed
            if (DocumentUIHelper.IsIconUsed(IconType.CheckedOut, SiteContext.CurrentSiteName))
            {
                AddAfterActionScript();
            }

            ReloadData();
            versionsElem.ReloadData();
        }
        catch (WorkflowException)
        {
            ShowError(GetString("EditContent.DocumentCannotCheckIn"));
        }
        catch (Exception ex)
        {
            // Log exception
            EventLogProvider.LogException("Content", "CHECKIN", ex);
            ShowError(ex.Message);
        }
    }
Ejemplo n.º 4
0
    protected object gridHistory_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        sourceName = sourceName.ToLowerInvariant();
        switch (sourceName)
        {
        case "rollback":
        {
            CMSGridActionButton imgRollback = ((CMSGridActionButton)sender);
            int versionId = ValidationHelper.GetInteger(imgRollback.CommandArgument, 0);
            if (!WorkflowManager.CheckStepPermissions(Node, WorkflowActionEnum.Approve) || !CanModify || (CheckedOutByAnotherUser && !CanCheckIn) || (versionId == Node.DocumentCheckedOutVersionHistoryID))
            {
                imgRollback.Enabled = false;
            }
        }
        break;

        case "allowdestroy":
        {
            CMSGridActionButton imgDestroy = ((CMSGridActionButton)sender);
            int versionId = ValidationHelper.GetInteger(imgDestroy.CommandArgument, 0);
            if (!CanDestroy || (CheckedOutByAnotherUser && !CanCheckIn) || (versionId == Node.DocumentCheckedOutVersionHistoryID))
            {
                imgDestroy.Enabled = false;
            }
        }
        break;

        case "modifiedwhenby":
            DataRowView data         = (DataRowView)parameter;
            DateTime    modifiedwhen = ValidationHelper.GetDateTime(data["ModifiedWhen"], DateTimeHelper.ZERO_TIME);
            int         userId       = ValidationHelper.GetInteger(data["ModifiedByUserID"], 0);

            var tr = new ObjectTransformation("cms.user", userId);
            tr.EncodeOutput   = false;
            tr.Transformation = string.Format("{0} <br /> {{% Object.GetFormattedUserName()|(encode) %}}", UniGridFunctions.UserDateTimeGMT(modifiedwhen));
            return(tr);
        }

        return(parameter);
    }
Ejemplo n.º 5
0
    protected void btnUndoCheckout_Click(object sender, EventArgs e)
    {
        try
        {
            // Check permissions
            if (!WorkflowManager.CheckStepPermissions(Node, WorkflowActionEnum.Approve))
            {
                DisableForm();
                return;
            }

            // Undo check out
            VersionManager.UndoCheckOut(Node);

            txtComment.Text = "";
            txtVersion.Text = "";

            DocumentManager.ClearContentChanged();

            // Refresh tree if icon checked out was displayed
            if (DocumentUIHelper.IsIconUsed(IconType.CheckedOut, SiteContext.CurrentSiteName))
            {
                AddAfterActionScript();
            }

            ReloadData();
            versionsElem.ReloadData();
        }
        catch (WorkflowException)
        {
            ShowError(GetString("EditContent.DocumentCannotUndoCheckOut"));
        }
        catch (Exception ex)
        {
            // Log exception
            EventLogProvider.LogException("Content", "UNDOCHECKOUT", ex);
            ShowError(ex.Message);
        }
    }
Ejemplo n.º 6
0
    protected void btnCheckout_Click(object sender, EventArgs e)
    {
        try
        {
            // Check permissions
            if (!WorkflowManager.CheckStepPermissions(Node, WorkflowActionEnum.Approve))
            {
                DisableForm();
                return;
            }

            VersionManager.EnsureVersion(Node, Node.IsPublished);

            // Check out the document
            VersionManager.CheckOut(Node);

            // Refresh tree if icon checked out should be displayed
            if (UIHelper.DisplayCheckedOutIcon(CMSContext.CurrentSiteName))
            {
                AddAfterActionScript();
            }

            ReloadData();
            versionsElem.ReloadData();
        }
        catch (WorkflowException)
        {
            ShowError(GetString("EditContent.DocumentCannotCheckOut"));
        }
        catch (Exception ex)
        {
            // Log exception
            EventLogProvider ep = new EventLogProvider();
            ep.LogEvent("Content", "CHECKOUT", ex);
            ShowError(ex.Message);
        }
    }
Ejemplo n.º 7
0
        //move that document to previous version workflow state
        //it will move to the state or previous version that we edited
        protected static bool MoveToWorkflowStep(int VersionWorkFlowStepID, TreeProvider tree, TreeNode node)
        {
            bool versionChangedStatus = false;

            WorkflowManager workflowManager = WorkflowManager.GetInstance(tree);
            WorkflowInfo    workflow        = workflowManager.GetNodeWorkflow(node);

            // Check if the document uses workflow
            if (workflow != null)
            {
                // Check if the workflow doesn't use automatic publishing, otherwise, documents can't change workflow steps.
                if (!workflow.WorkflowAutoPublishChanges)
                {
                    // Check if the current user can move the document to the next step
                    if (workflowManager.CheckStepPermissions(node, WorkflowActionEnum.Reject))
                    {
                        // Get workflowStepInfo object based on workflow step ID
                        WorkflowStepInfo workflowStep = WorkflowStepInfoProvider.GetWorkflowStepInfo(VersionWorkFlowStepID);
                        if (workflowStep.StepDisplayName.ToLower() == SMEConstant.WORKFLOW_PUBLISHED.ToLower())
                        {
                            // Move the document to the specified step
                            workflowManager.MoveToSpecificStep(node, workflowStep);
                            versionChangedStatus = true;
                        }
                        else if (workflowStep.StepDisplayName.ToLower() == SMEConstant.WORKFLOW_ARCHIVED.ToLower())
                        {
                            // Archive the document
                            workflowManager.ArchiveDocument(node, null);
                            // Move the document to the specified step
                            //workflowManager.MoveToSpecificStep(node, workflowStep);
                            versionChangedStatus = true;
                        }
                    }
                }
            }
            return(versionChangedStatus);
        }
Ejemplo n.º 8
0
    protected void gridHistory_OnAction(string actionName, object actionArgument)
    {
        int versionHistoryId = ValidationHelper.GetInteger(actionArgument, 0);

        switch (actionName.ToLowerInvariant())
        {
        case "rollback":
            if (versionHistoryId > 0)
            {
                if (CheckedOutByUserID > 0)
                {
                    // Document is checked out
                    ShowError(GetString("VersionProperties.CannotRollbackCheckedOut"));
                }
                else
                {
                    // Check permissions
                    if (!WorkflowManager.CheckStepPermissions(Node, WorkflowActionEnum.Approve) || !CanModify || (CheckedOutByAnotherUser && !CanCheckIn) || (versionHistoryId == Node.DocumentCheckedOutVersionHistoryID))
                    {
                        ShowError(String.Format(GetString("cmsdesk.notauthorizedtoeditdocument"), HTMLHelper.HTMLEncode(Node.GetDocumentName())));
                    }
                    else
                    {
                        try
                        {
                            VersionManager.RollbackVersion(versionHistoryId);

                            if (!IsLiveSite)
                            {
                                // Refresh content tree (for the case that document name has been changed)
                                ScriptHelper.RefreshTree(Page, NodeID, Node.NodeParentID);
                            }

                            // Refresh node instance
                            InvalidateNode();
                            ShowConfirmation(GetString("VersionProperties.RollbackOK"));
                        }
                        catch (Exception ex)
                        {
                            ShowError(ex.Message);
                        }
                    }
                }
            }
            break;

        case "destroy":
            if (versionHistoryId > 0)
            {
                if (Node != null)
                {
                    // Check permissions
                    if (!CanDestroy || (CheckedOutByAnotherUser && !CanCheckIn) || (versionHistoryId == Node.DocumentCheckedOutVersionHistoryID))
                    {
                        ShowError(GetString("History.ErrorNotAllowedToDestroy"));
                    }
                    else
                    {
                        // Refresh node instance
                        InvalidateNode();
                        VersionManager.DestroyDocumentVersion(versionHistoryId);
                        ShowConfirmation(GetString("VersionProperties.DestroyOK"));
                    }
                }
            }
            break;
        }
    }
Ejemplo n.º 9
0
    /// <summary>
    /// Reloads the page data.
    /// </summary>
    private void ReloadData()
    {
        // If no workflow set for node, hide the data
        if (WorkflowInfo == null)
        {
            headCheckOut.ResourceString = "properties.scopenotset";
            DisableForm();
            pnlVersions.Visible = false;
        }
        else
        {
            if (!WorkflowStepInfo.StepIsDefault && !WorkflowManager.CheckStepPermissions(Node, WorkflowActionEnum.Approve))
            {
                ShowInfo(GetString("EditContent.NotAuthorizedToApprove"), true);
            }
        }

        bool useCheckInCheckOut = false;

        if (WorkflowInfo != null)
        {
            useCheckInCheckOut = WorkflowInfo.UseCheckInCheckOut(SiteContext.CurrentSiteName);
        }

        // Check modify permissions
        if (!versionsElem.CanModify)
        {
            DisableForm();
            plcForm.Visible = false;
            ShowInfo(String.Format(GetString("cmsdesk.notauthorizedtoeditdocument"), Node.NodeAliasPath), true);
        }
        else if (useCheckInCheckOut || (versionsElem.CheckedOutByUserID != 0))
        {
            btnCheckout.Visible     = false;
            btnCheckout.Enabled     = true;
            btnCheckin.Visible      = false;
            btnCheckin.Enabled      = true;
            btnUndoCheckout.Visible = false;
            btnUndoCheckout.Enabled = true;
            txtComment.Enabled      = true;
            txtVersion.Enabled      = true;
            lblComment.Enabled      = true;
            lblVersion.Enabled      = true;

            // Check whether to check out or in
            if (WorkflowInfo == null)
            {
                btnCheckout.Visible         = true;
                headCheckOut.ResourceString = "VersionsProperties.CheckOut";
                DisableForm();
            }
            else if (!Node.IsCheckedOut)
            {
                headCheckOut.ResourceString = "VersionsProperties.CheckOut";
                DisableForm();
                btnCheckout.Visible = true;
                // Do not allow checkout for published or archived step in advanced workflow
                btnCheckout.Enabled = (WorkflowInfo.IsBasic || (!WorkflowStepInfo.StepIsPublished && !WorkflowStepInfo.StepIsArchived));
            }
            else
            {
                // If checked out by current user, allow to check-in
                if (versionsElem.CheckedOutByUserID == MembershipContext.AuthenticatedUser.UserID)
                {
                    btnCheckin.Visible      = true;
                    btnUndoCheckout.Visible = true;
                }
                else
                {
                    // Else checked out by somebody else
                    btnCheckin.Visible  = true;
                    btnCheckout.Visible = false;

                    btnUndoCheckout.Visible = versionsElem.CanCheckIn;
                    btnUndoCheckout.Enabled = versionsElem.CanCheckIn;
                    btnCheckin.Enabled      = versionsElem.CanCheckIn;
                    txtComment.Enabled      = versionsElem.CanCheckIn;
                    txtVersion.Enabled      = versionsElem.CanCheckIn;
                }

                headCheckOut.ResourceString = "VersionsProperties.CheckIn";
            }

            if (!WorkflowManager.CheckStepPermissions(Node, WorkflowActionEnum.Approve))
            {
                DisableForm();
            }
        }
        else
        {
            plcForm.Visible = false;
        }
    }
Ejemplo n.º 10
0
    protected void gridHistory_OnAction(string actionName, object actionArgument)
    {
        int versionHistoryId = ValidationHelper.GetInteger(actionArgument, 0);

        switch (actionName.ToLowerCSafe())
        {
        case "rollback":
            if (versionHistoryId > 0)
            {
                if (CheckedOutByUserID > 0)
                {
                    // Document is checked out
                    ShowError(GetString("VersionProperties.CannotRollbackCheckedOut"));
                }
                else
                {
                    // Check permissions
                    if (!WorkflowManager.CheckStepPermissions(Node, WorkflowActionEnum.Approve) || !CanModify)
                    {
                        ShowError(String.Format(GetString("cmsdesk.notauthorizedtoeditdocument"), Node.NodeAliasPath));
                    }
                    else
                    {
                        try
                        {
                            VersionManager.RollbackVersion(versionHistoryId);

                            if (!IsLiveSite)
                            {
                                // Refresh content tree (for the case that document name has been changed)
                                string refreshTreeScript = ScriptHelper.GetScript("if(window.RefreshTree!=null){RefreshTree(" + Node.NodeParentID + ", " + Node.NodeID + ");}");
                                ScriptHelper.RegisterStartupScript(this, typeof(string), "refreshTree" + ClientID, refreshTreeScript);
                            }

                            ShowConfirmation(GetString("VersionProperties.RollbackOK"));
                        }
                        catch (Exception ex)
                        {
                            ShowError(ex.Message);
                        }
                    }
                }
            }
            break;

        case "destroy":
            if (versionHistoryId > 0)
            {
                if (Node != null)
                {
                    // Check permissions
                    if (!CanDestroy || (CheckedOutByAnotherUser && !CanCheckIn))
                    {
                        ShowError(GetString("History.ErrorNotAllowedToDestroy"));
                    }
                    else
                    {
                        VersionManager.DestroyDocumentVersion(versionHistoryId);
                        ShowConfirmation(GetString("VersionProperties.DestroyOK"));
                    }
                }
            }
            break;
        }
    }
Ejemplo n.º 11
0
    /// <summary>
    /// Gets new table header cell which contains label and rollback image.
    /// </summary>
    /// <param name="suffixID">ID suffix</param>
    /// <param name="documentID">Document ID</param>
    /// <param name="versionID">Version history ID</param>
    private TableHeaderCell GetRollbackTableHeaderCell(string suffixID, int documentID, int versionID)
    {
        TableHeaderCell tblHeaderCell = new TableHeaderCell();

        tblHeaderCell.EnableViewState = false;

        string tooltip = GetString("history.versionrollbacktooltip");

        // Label
        Label lblValue = new Label();

        lblValue.ID              = "lbl" + suffixID;
        lblValue.Text            = HTMLHelper.HTMLEncode(GetVersionNumber(documentID, versionID));
        lblValue.EnableViewState = false;

        // Panel
        Panel pnlLabel = new Panel();

        pnlLabel.ID       = "pnlLabel" + suffixID;
        pnlLabel.CssClass = "LeftAlign";
        pnlLabel.Controls.Add(lblValue);
        pnlLabel.EnableViewState = false;

        // Rollback image
        Image imgRollback = new Image();

        imgRollback.ID              = "imgRollback" + suffixID;
        imgRollback.AlternateText   = tooltip;
        imgRollback.ToolTip         = tooltip;
        imgRollback.EnableViewState = false;

        // Disable buttons according to permissions
        bool canApprove = WorkflowManager.CheckStepPermissions(Node, WorkflowActionEnum.Approve);

        if (!canApprove || !CanModify || (CheckedOutByAnotherUser && !CanCheckIn))
        {
            imgRollback.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/undodisabled.png");
            imgRollback.Enabled  = false;
        }
        else
        {
            imgRollback.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/undo.png");
            imgRollback.Style.Add("cursor", "pointer");

            // Prepare onclick script
            string confirmScript = "if (confirm(" + ScriptHelper.GetString(GetString("Unigrid.VersionHistory.Actions.Rollback.Confirmation")) + ")) { ";
            confirmScript += Page.ClientScript.GetPostBackEventReference(this, versionID.ToString()) + "; return false; }";
            imgRollback.Attributes.Add("onclick", confirmScript);
        }

        // Rollback panel
        Panel pnlImage = new Panel();

        pnlImage.EnableViewState = false;
        pnlImage.ID       = "pnlRollback" + suffixID;
        pnlImage.CssClass = "RightAlign";
        pnlImage.Controls.Add(imgRollback);

        tblHeaderCell.Controls.Add(pnlLabel);
        tblHeaderCell.Controls.Add(pnlImage);

        return(tblHeaderCell);
    }
Ejemplo n.º 12
0
    /// <summary>
    /// Raises event postback event.
    /// </summary>
    /// <param name="eventArgument">Argument</param>
    public void RaisePostBackEvent(string eventArgument)
    {
        int rollbackVersionId = ValidationHelper.GetInteger(eventArgument, 0);

        if (rollbackVersionId > 0)
        {
            if (Node == null)
            {
                return;
            }

            if (CheckedOutByUserID > 0)
            {
                // Document is checked out
                ShowError(GetString("VersionProperties.CannotRollbackCheckedOut"));
            }
            else
            {
                // Check permissions
                bool canApprove = WorkflowManager.CheckStepPermissions(Node, WorkflowActionEnum.Approve);

                if (!canApprove || !CanModify)
                {
                    ShowError(String.Format(GetString("cmsdesk.notauthorizedtoeditdocument"), Node.NodeAliasPath));
                }
                else
                {
                    try
                    {
                        // Rollback version
                        int newVersionHistoryId = VersionManager.RollbackVersion(rollbackVersionId);

                        ShowConfirmation(GetString("VersionProperties.RollbackOK"));

                        string url = URLHelper.CurrentURL;

                        // Add URL parameters
                        url = URLHelper.AddParameterToUrl(url, "versionHistoryId", newVersionHistoryId.ToString());
                        url = URLHelper.AddParameterToUrl(url, "compareHistoryId", versionCompare.ToString());
                        url = URLHelper.AddParameterToUrl(url, "rollbackok", "1");

                        // Prepare URL
                        url = ScriptHelper.GetString(URLHelper.ResolveUrl(url), true);

                        // Prepare script for refresh parent window and this dialog
                        StringBuilder builder = new StringBuilder();
                        builder.Append("if (wopener != null) {\n");
                        builder.Append("if (wopener.RefreshTree != null) {wopener.RefreshTree(", Node.NodeParentID, ", ", Node.NodeID, "); }");
                        builder.Append("wopener.document.location.replace(wopener.document.location);}\n");
                        builder.Append("window.document.location.replace(" + url + ");");

                        string script = ScriptHelper.GetScript(builder.ToString());
                        ScriptHelper.RegisterStartupScript(this, typeof(string), "RefreshAndReload", script);
                    }
                    catch (Exception ex)
                    {
                        ShowError(GetString("versionproperties.rollbackerror"));
                        EventLogProvider.LogException("Content", "ROLLBACKVERSION", ex);
                    }
                }
            }

            // Display form if error occurs
            if (error)
            {
                ReloadData();
            }
        }
    }