コード例 #1
0
    /// <summary>
    /// Returns true if document had passed through one/all specified workflow steps.
    /// </summary>
    /// <param name="document">Document to check</param>
    /// <param name="steps">Workflow step names separated with a semicolon</param>
    /// <param name="allSteps">If true all specified steps must have been passed.</param>
    public static bool PassedThroughSteps(object document, string steps, bool allSteps)
    {
        TreeNode doc = document as TreeNode;

        if (doc != null)
        {
            if (!String.IsNullOrEmpty(steps))
            {
                string[] stepArray = steps.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                // Get only the step names of workflow steps visited in history that are selected by user
                string where = String.Format("[HistoryObjectID] = {0} AND HistoryObjectType = '{1}' AND {2}", doc.DocumentID, DocumentObjectType.DOCUMENT, SqlHelperClass.GetWhereCondition("StepName", stepArray));

                var history = WorkflowHistoryInfoProvider.GetWorkflowHistories(where, null, 0, "StepName").Items;
                if (history.Count > 0)
                {
                    // At least of the selected steps was found in the history
                    if (!allSteps)
                    {
                        return(true);
                    }

                    // Check whether all of the selected steps are in the history
                    return(stepArray.All(s => history.Any <WorkflowHistoryInfo>(h => h.StepName.EqualsCSafe(s, true))));
                }
            }
            else if (allSteps)
            {
                return(true);
            }
        }

        return(false);
    }
コード例 #2
0
ファイル: Utility.cs プロジェクト: SMEWebmaster/Kentico16
        //After getting dataset of all document filtering data as per required conditions
        public static DataSet UpdateDocumentsDataset(DataSet ds)
        {
            // Display and initialize grid if datasource is not empty
            for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
            {
                if (!string.IsNullOrEmpty(ds.Tables[0].Rows[i]["DocumentWorkflowStepID"].ToString()))
                {
                    int stepId   = Convert.ToInt32(ds.Tables[0].Rows[i]["DocumentWorkflowStepID"]);
                    var workFlow = string.Empty;
                    if (stepId > 0)
                    {
                        // Get workflow step display name
                        WorkflowStepInfo wsi = WorkflowStepInfoProvider.GetWorkflowStepInfo(stepId);
                        if (wsi != null)
                        {
                            workFlow = ResHelper.LocalizeString(wsi.StepDisplayName);
                        }

                        //if its in draft state then display documents created by current user only
                        if (workFlow == SMEConstant.WORKFLOW_DRAFT)
                        {
                            int    userID = MembershipContext.AuthenticatedUser.UserID;
                            int    DocumentCreatedByUserID  = Convert.ToInt32(ds.Tables[0].Rows[i]["DocumentCreatedByUserID"]);
                            int    DocumentModifiedByUserID = Convert.ToInt32(ds.Tables[0].Rows[i]["DocumentModifiedByUserID"]);
                            string NodeAliasPath            = ds.Tables[0].Rows[i]["NodeAliasPath"].ToString();
                            int    DocumentID = Convert.ToInt32(ds.Tables[0].Rows[i]["DocumentID"]);
                            int    DocumentCheckedOutVersionHistoryID = Convert.ToInt32(ds.Tables[0].Rows[i]["DocumentCheckedOutVersionHistoryID"]);
                            //checking that current document is already rejected or not
                            DataSet dsRejected = WorkflowHistoryInfoProvider.GetWorkflowHistories("WasRejected = 1 AND VersionHistoryID = " + DocumentCheckedOutVersionHistoryID + " ", null, 100, null);
                            //checking wether that document is already is published or not. if its already published then anyone can see and edit it
                            //if that document is rejected then it will display to all and it will not go inside if condition
                            bool isPublished = isPublishedStatusBynodeAliasPath(NodeAliasPath);
                            if (!isPublished && DataHelper.DataSourceIsEmpty(dsRejected))
                            {
                                //if a document is modified by me then it should display to me although its not created by me
                                //if that document is not created or not modified then no need to display on my list
                                if (DocumentCreatedByUserID != userID && DocumentModifiedByUserID != userID)
                                {
                                    ds.Tables[0].Rows[i].Delete();
                                }
                            }
                        }
                    }
                }
            }
            ds.Tables[0].AcceptChanges();
            return(ds);
        }
コード例 #3
0
    /// <summary>
    /// Returns true if document had passed through one/all selected workflow actions.
    /// </summary>
    /// <param name="document">Document to check</param>
    /// <param name="actions">Workflow action names separated with a semicolon</param>
    /// <param name="allActions">If true all actions must have been passed.</param>
    public static bool PassedThroughActions(object document, string actions, bool allActions)
    {
        TreeNode doc = document as TreeNode;

        if (doc != null)
        {
            if (!String.IsNullOrEmpty(actions))
            {
                // Get IDs of action steps this document visited in history
                string historyWhere = String.Format("StepType = {0} AND HistoryObjectID = {1} AND HistoryObjectType = '{2}'", (int)WorkflowStepTypeEnum.Action, doc.DocumentID, DocumentObjectType.DOCUMENT);
                var    history      = WorkflowHistoryInfoProvider.GetWorkflowHistories(historyWhere, null, 0, "StepID");

                // Get action IDs of actions associated to the visited action steps
                string stepWhere   = SqlHelperClass.GetWhereCondition("StepID", history.Select <WorkflowHistoryInfo, int>(h => h.StepID).ToList());
                var    actionSteps = WorkflowStepInfoProvider.GetWorkflowSteps(stepWhere, null, 0, "StepActionID");

                string[] selectedActions = actions.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                // Get action infos to visited actions that have selected name
                string actionWhere = SqlHelperClass.GetWhereCondition("ActionID", actionSteps.Select <WorkflowStepInfo, int>(s => s.StepActionID).ToList());
                actionWhere = SqlHelperClass.AddWhereCondition(actionWhere, SqlHelperClass.GetWhereCondition("ActionName", selectedActions));

                var actionInfos = WorkflowActionInfoProvider.GetWorkflowActions(actionWhere, null, "ActionName").Items;

                // Return true if all/any actions were visited in history
                return(allActions ? (actionInfos.Count == selectedActions.Length) : (actionInfos.Count > 0));
            }
            else if (allActions)
            {
                // No actions were selected
                return(true);
            }
        }

        return(false);
    }
コード例 #4
0
    private void CreateActions(List <HeaderAction> actions, Control parent)
    {
        int actionsCount = actions.Count;

        // Sort actions by index to be sure the order is ensured for multiple actions
        if (actionsCount > 1)
        {
            // At least one action has index
            if (actions.Exists(a => (a.Index != -1)))
            {
                // Sort the actions
                actions.Sort((a1, a2) => a1.Index.CompareTo(a2.Index));
            }
        }
        var VersionHistoryID = this.DocumentManager.Node.DocumentCheckedOutVersionHistoryID;
        //checking that current document is already rejected or not
        DataSet dsRejected = WorkflowHistoryInfoProvider.GetWorkflowHistories("WasRejected = 1 AND VersionHistoryID = " + VersionHistoryID + " ", null, 100, null);


        // Generate the actions
        for (int i = 0; i < actionsCount; ++i)
        {
            var action = actions[i];
            if (action.EventName != SMEConstant.ACTIONEVENTNAME_DOCUMENTCREATEVERSION && action.EventName != SMEConstant.ACTIONEVENTNAME_DOCUMENTARCHIVE && (action.EventName == "Save" || DataHelper.DataSourceIsEmpty(dsRejected)))
            {
                if ((action.AlternativeActions != null) && action.AlternativeActions.Any() && action.AlternativeActions.Count > 1)
                {
                    action = action.AlternativeActions.First();
                }
                // If the text is not specified or visibility is false, skip the action
                var formButton = action.BaseButton as FormSubmitButton;
                // Get the action parameters
                string     ctrlId = String.Concat(ID, "_HA_", i);
                WebControl actionControl;

                if (!action.IsVisible() || ((action.BaseButton != null) && (!action.BaseButton.Visible || ((formButton != null) && !formButton.RegisterHeaderAction))))
                {
                    // Skip empty action
                    action.Visible = false;
                    continue;
                }

                // Check permission if action is enabled
                if (action.Enabled)
                {
                    action.Enabled = CheckPermissions(action.ResourceName, action.Permission);
                }

                // Set live site flag for resource strings
                action.IsLiveSite = IsLiveSite;

                // Use multi button when action contains alternative actions
                if ((action.AlternativeActions != null) && action.AlternativeActions.Any() && false)
                {
                    // Get main action
                    var controlActions = new List <CMSButtonAction>
                    {
                        GetControlAction(action)
                    };

                    if (action.RegisterShortcutScript)
                    {
                        RegisterSaveShortcutScript(action, ctrlId);
                    }

                    // Get other actions
                    for (int j = 0; j < action.AlternativeActions.Count; j++)
                    {
                        var alternativeAction = action.AlternativeActions[j];

                        controlActions.Add(GetControlAction(alternativeAction));
                        if (action.RegisterShortcutScript)
                        {
                            RegisterSaveShortcutScript(action, ctrlId + "_" + j);
                        }
                    }

                    var button = action.Inactive ? (CMSMultiButtonBase) new CMSToggleButton() : new CMSMoreOptionsButton();

                    button.Enabled = Enabled;
                    button.ID      = ctrlId;
                    button.Actions = controlActions;

                    actionControl = button;
                }
                // Use classic button
                else
                {
                    // Get action
                    var controlAction = GetControlAction(action);

                    var button = new CMSButton
                    {
                        ButtonStyle   = action.ButtonStyle,
                        ID            = ctrlId,
                        Enabled       = controlAction.Enabled,
                        Text          = controlAction.Text,
                        OnClientClick = controlAction.OnClientClick,
                        //OnClientClick = string.Concat("if(jQuery('form').validationEngine('validate')){jQuery('.modal-backdrop').show();jQuery('.loading').show();", controlAction.OnClientClick + "}"),
                        ToolTip           = action.Tooltip,
                        UseSubmitBehavior = false
                    };

                    if (Utility.IsUserInAdminRole() && action.EventName == SMEConstant.ACTIONEVENTNAME_DOCUMENTAPPROVE)
                    {
                        var culture = SiteContext.CurrentSite.DefaultVisitorCulture;
                        button.Text    = ValidationHelper.GetString(GetString("ApproveButtonText", culture), "Approve & Publish");
                        button.ToolTip = ValidationHelper.GetString(GetString("ApproveButtonText", culture), "Approve & Publish");
                    }

                    if (action.EventName == SMEConstant.ACTIONEVENTNAME_DOCUMENTSAVE)
                    {
                        var culture = SiteContext.CurrentSite.DefaultVisitorCulture;
                        button.Text    = ValidationHelper.GetString(GetString("SubmitText", culture), "Save");
                        button.ToolTip = ValidationHelper.GetString(GetString("SubmitTextToolTip", culture), "Save Event");
                    }


                    if (action.RegisterShortcutScript)
                    {
                        RegisterSaveShortcutScript(action, ctrlId);
                    }

                    actionControl = button;
                    actionControl.AddCssClass(string.Concat(action.CssClass, " modulebtn"));
                }

                if (action.CssClass != null)
                {
                    actionControl.AddCssClass(string.Concat(action.CssClass, " btn-primary"));
                }

                // Add control to the panel
                parent.Controls.Add(actionControl);
            }
        }
    }