/// <summary>
    /// Saves roles data
    /// </summary>
    private void SaveRolesData()
    {
        Guid stepSourcePointGuid = (SourcePointGuid == null) ? Guid.Empty : SourcePointGuid.Value;

        // Remove old items
        string newValues = ValidationHelper.GetString(usRoles.Value, null);
        string items     = DataHelper.GetNewItemsInList(newValues, currentRoles);

        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                // Add all new items to site
                foreach (string item in newItems)
                {
                    int roleId = ValidationHelper.GetInteger(item, 0);
                    // If role is authorized, remove it
                    WorkflowStepRoleInfo wsr = WorkflowStepRoleInfoProvider.GetWorkflowStepRoleInfo(WorkflowStepID, roleId, stepSourcePointGuid);
                    if (wsr != null)
                    {
                        wsr.Delete();
                    }
                }
            }
        }

        // Add new items
        items = DataHelper.GetNewItemsInList(currentRoles, newValues);
        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                // Add all new items to site
                foreach (string item in newItems)
                {
                    int roleId = ValidationHelper.GetInteger(item, 0);

                    // If role is not authorized, authorize it
                    if (WorkflowStepRoleInfoProvider.GetWorkflowStepRoleInfo(WorkflowStepID, roleId, stepSourcePointGuid) == null)
                    {
                        WorkflowStepRoleInfoProvider.AddRoleToWorkflowStep(WorkflowStepID, roleId, stepSourcePointGuid);
                    }
                }
            }
        }

        ShowChangesSaved();
    }
Esempio n. 2
0
    /// <summary>
    /// Removes the assignment of the CMS Editors role from a workflow step. Called when the "Remove role from step" button is pressed.
    /// Expects the CreateWorkflow, CreateWorkflowStep and AddRoleToStep methods to be run first.
    /// </summary>
    private bool RemoveRoleFromStep()
    {
        // Get the workflow
        WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("MyNewWorkflow", WorkflowTypeEnum.Approval);

        if (workflow != null)
        {
            // Get the custom step
            WorkflowStepInfo step = WorkflowStepInfoProvider.GetWorkflowStepInfo("MyNewWorkflowStep", workflow.WorkflowID);

            if (step != null)
            {
                // Get the role to be assigned to the step
                RoleInfo role = RoleInfoProvider.GetRoleInfo("CMSEditor", SiteContext.CurrentSiteID);

                if (role != null)
                {
                    // Get the step - role relationship
                    WorkflowStepRoleInfo stepRoleInfo = WorkflowStepRoleInfoProvider.GetWorkflowStepRoleInfo(step.StepID, role.RoleID);

                    if (stepRoleInfo != null)
                    {
                        // Remove the assignment
                        WorkflowStepRoleInfoProvider.RemoveRoleFromWorkflowStep(step.StepID, role.RoleID);

                        return(true);
                    }
                    else
                    {
                        // The role is not assigned to the step
                        apiRemoveRoleFromStep.ErrorMessage = "The 'CMS Editors' role is not assigned to the step.";
                    }
                }
                else
                {
                    // The role was not found
                    apiRemoveRoleFromStep.ErrorMessage = "The role 'CMS Editors' was not found.";
                }
            }
            else
            {
                // The step was not found
                apiRemoveRoleFromStep.ErrorMessage = "The step 'My new workflow step' was not found.";
            }
        }

        return(false);
    }