コード例 #1
0
    /// <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();
    }
コード例 #2
0
    private void SaveData()
    {
        // Remove old items
        string newValues = ValidationHelper.GetString(usRoles.Value, null);
        string items     = DataHelper.GetNewItemsInList(newValues, currentValues);

        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, unauthorize it
                    if (IsRoleAuthorized(roleID.ToString(), workflowStepId))
                    {
                        WorkflowStepRoleInfoProvider.RemoveRoleFromWorkflowStep(workflowStepId, roleID);
                    }
                }
            }
        }

        // Add new items
        items = DataHelper.GetNewItemsInList(currentValues, 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 (!IsRoleAuthorized(roleID.ToString(), workflowStepId))
                    {
                        WorkflowStepRoleInfoProvider.AddRoleToWorkflowStep(workflowStepId, roleID);
                    }
                }
            }
        }

        lblInfo.Visible = true;
        lblInfo.Text    = GetString("General.ChangesSaved");
    }
コード例 #3
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);
    }
コード例 #4
0
    /// <summary>
    /// Assings the CMS Editors role to a workflow step. Called when the "Add role to step" button is pressed.
    /// Expects the CreateWorkflow and CreateWorkflowStep methods to be run first.
    /// </summary>
    private bool AddRoleToStep()
    {
        // Get the workflow
        WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("MyNewWorkflow");

        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)
                {
                    // Make the assignment
                    WorkflowStepRoleInfoProvider.AddRoleToWorkflowStep(step.StepID, role.RoleID);

                    return(true);
                }
                else
                {
                    // Role was not found
                    apiAddRoleToStep.ErrorMessage = "Role 'CMS Editors' was not found.";
                }
            }
            else
            {
                // Step was not found
                apiAddRoleToStep.ErrorMessage = "Step 'My new workflow step' was not found.";
            }
        }

        return(false);
    }
コード例 #5
0
ファイル: Security.ascx.cs プロジェクト: isatriya/kentico10
    protected void Page_Load(object sender, EventArgs e)
    {
        if (WorkflowStepID <= 0)
        {
            StopProcessing = true;
            return;
        }

        EditedObject = WorkflowStep;

        if (SourcePointGuid != null)
        {
            ShowInformation(GetString("workflowsteppoint.securityInfo"));
        }
        else if (WorkflowStep.StepAllowBranch)
        {
            ShowInformation(GetString("workflowstep.securityInfo"));
        }

        if (Workflow.IsAutomation)
        {
            headRoles.ResourceString = "processstep.rolessecurity";
            headUsers.ResourceString = "processstep.userssecurity";
        }
        else
        {
            headRoles.ResourceString = (SourcePointGuid == null) ? "workflowstep.rolessecurity" : "workflowsteppoint.rolessecurity";
            headUsers.ResourceString = (SourcePointGuid == null) ? "workflowstep.userssecurity" : "workflowsteppoint.userssecurity";
        }

        // Set site selector
        siteSelector.AllowGlobal = true;
        siteSelector.DropDownSingleSelect.AutoPostBack = true;
        siteSelector.AllowAll         = false;
        siteSelector.OnlyRunningSites = false;
        siteSelector.UniSelector.OnSelectionChanged += UniSelector_OnSelectionChanged;
        usRoles.OnSelectionChanged      += usRoles_OnSelectionChanged;
        usUsers.OnSelectionChanged      += usUsers_OnSelectionChanged;
        usRoles.ObjectType               = RoleInfo.OBJECT_TYPE;
        usUsers.ObjectType               = UserInfo.OBJECT_TYPE;
        rbRoleType.SelectedIndexChanged += rbRoleType_SelectedIndexChanged;
        rbUserType.SelectedIndexChanged += rbUserType_SelectedIndexChanged;

        if (!RequestHelper.IsPostBack())
        {
            siteId             = SiteID;
            siteSelector.Value = siteId;
            string resPrefix = (SourcePointGuid == null) ? "workflowstep" : "workflowsteppoint";
            ControlsHelper.FillListControlWithEnum <WorkflowStepSecurityEnum>(rbRoleType, resPrefix + ".security");
            ControlsHelper.FillListControlWithEnum <WorkflowStepSecurityEnum>(rbUserType, resPrefix + ".usersecurity");
            rbRoleType.SelectedValue = ((int)RolesSecurity).ToString();
            rbUserType.SelectedValue = ((int)UsersSecurity).ToString();
        }
        else
        {
            // Make sure the current site is always selected
            int selectedId = ValidationHelper.GetInteger(siteSelector.Value, 0);
            if (selectedId == 0)
            {
                selectedId         = SiteID;
                siteSelector.Value = SiteID;
            }
            siteId = selectedId;
        }

        // If global role selected - set siteID to 0
        if (siteSelector.GlobalRecordValue == siteId.ToString())
        {
            siteId = 0;
        }

        string siteIDWhere = (siteId == 0) ? "SiteID IS NULL" : "SiteID = " + siteId;

        usRoles.WhereCondition = siteIDWhere + " AND RoleGroupID IS NULL";
        usUsers.WhereCondition = "(UserIsHidden = 0 OR UserIsHidden IS NULL)";

        // Get the active roles for this site
        string where = String.Format("[StepID] = {0} AND [StepSourcePointGuid] {1}", WorkflowStepID, (SourcePointGuid == null ? "IS NULL" : String.Format("= '{0}'", SourcePointGuid.ToString())));

        var roles = WorkflowStepRoleInfoProvider.GetWorkflowStepRoles(where, null, 0, "RoleID").Select <WorkflowStepRoleInfo, string>(r => r.RoleID.ToString());

        currentRoles = string.Join(";", roles.ToArray());

        // Get the active users for this site
        var users = WorkflowStepUserInfoProvider.GetWorkflowStepUsers(where, null, 0, "UserID").Select <WorkflowStepUserInfo, string>(u => u.UserID.ToString());

        currentUsers = string.Join(";", users.ToArray());

        // Init lists when security type changes
        if (!RequestHelper.IsPostBack() || ControlsHelper.GetPostBackControlID(Page).StartsWithCSafe(rbRoleType.UniqueID) || ControlsHelper.GetPostBackControlID(Page).StartsWithCSafe(rbUserType.UniqueID))
        {
            usRoles.Value = currentRoles;
            usUsers.Value = currentUsers;
        }
    }