コード例 #1
0
    /// <summary>
    /// Saves users data
    /// </summary>
    private void SaveUsersData()
    {
        Guid stepSourcePointGuid = (SourcePointGuid == null) ? Guid.Empty : SourcePointGuid.Value;

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

        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 userId = ValidationHelper.GetInteger(item, 0);
                    // If user is authorized, remove it
                    WorkflowStepUserInfo wsu = WorkflowStepUserInfoProvider.GetWorkflowStepUserInfo(WorkflowStepID, userId, stepSourcePointGuid);
                    if (wsu != null)
                    {
                        wsu.Delete();
                    }
                }
            }
        }

        // Add new items
        items = DataHelper.GetNewItemsInList(currentUsers, 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 userId = ValidationHelper.GetInteger(item, 0);

                    // If user is not authorized, authorize it
                    if (WorkflowStepUserInfoProvider.GetWorkflowStepUserInfo(WorkflowStepID, userId, stepSourcePointGuid) == null)
                    {
                        WorkflowStepUserInfoProvider.AddUserToWorkflowStep(WorkflowStepID, userId, stepSourcePointGuid);
                    }
                }
            }
        }

        ShowChangesSaved();
    }
コード例 #2
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;
        }
    }