Exemplo n.º 1
0
 private void FillOrgSecurityGroupMembers(int SecurityGroupID, int OrgGroupID)
 {
     try {
         lbxOrgGroupMembers.Items.Clear();
         DataSet  ds = OrgSecurityGroupMembership.Items(SecurityGroupID, OrgGroupID);
         DataView dv = new DataView(ds.Tables[0]);
         dv.Sort = "DisplayName ASC";
         lbxOrgGroupMembers.DataSource     = dv;
         lbxOrgGroupMembers.DataTextField  = "DisplayName";
         lbxOrgGroupMembers.DataValueField = "UserID";
         lbxOrgGroupMembers.DataBind();
         if (lbxOrgGroupMembers.Items.Count > 0)
         {
             btnRemove.Enabled = true;
         }
         else
         {
             btnRemove.Enabled = false;
         }
     } catch (Exception ex) {
         SPA.Error.WriteError(ex);
         if (ShowDebug)
         {
             lblErrorMessage.Text = ex.ToString();
         }
     }
 }
Exemplo n.º 2
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            try {
                if (hfViewMode.Value == "app")
                {
                    // get role name associated with selected security group
                    SecurityGroup Group = new SecurityGroup(Int32.Parse(lbxAppGroups.SelectedValue));
                    Role          role  = new Role(Group.RoleID);
                    // evaluate if user may administor members of security group based on role
                    if (CurrentUser.InRole(role.Name))
                    {
                        foreach (ListItem li in lbxUserLookup.Items)
                        {
                            if (li.Selected)
                            {
                                // add individual membership
                                SecurityGroupMembership membership = new SecurityGroupMembership();
                                membership.SecurityGroupID = Int32.Parse(lbxAppGroups.SelectedValue);
                                membership.UserID          = int.Parse(li.Value);
                                membership.CreatedBy       = CurrentUser.DisplayName;
                                membership.ModifiedBy      = CurrentUser.DisplayName;

                                if (!membership.Insert())
                                {
                                    Transaction xAction = new Transaction();
                                    xAction.Action    = string.Format("Failed to add {0} to security group {1}", li.Text, lbxAppGroups.SelectedItem.Text);
                                    xAction.Category  = "Application Administration";
                                    xAction.Type      = Transaction.TYPE_FAILURE;
                                    xAction.CreatedBy = CurrentUser.DisplayName;
                                    xAction.Insert();
                                }
                                else
                                {
                                    Transaction xAction = new Transaction();
                                    xAction.Action    = string.Format("Successfully added {0} to security group {1}", li.Text, lbxAppGroups.SelectedItem.Text);
                                    xAction.Category  = "Application Administration";
                                    xAction.Type      = Transaction.TYPE_SUCCESS;
                                    xAction.CreatedBy = CurrentUser.DisplayName;
                                    xAction.Insert();
                                    Action.Write(string.Format("Assigned {0} to the application security group {1}", li.Text, lbxAppGroups.SelectedItem.Text), CurrentUser.DisplayName);
                                }
                            }
                        }
                        FillAppSecurityGroupMembers(Int32.Parse(lbxAppGroups.SelectedValue));
                    }
                    else
                    {
                        ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('You do not have permission to add members to this security group!');", true);
                    }
                }
                else
                {
                    // get role name associated with selected security group
                    OrgSecurityGroup Group = new OrgSecurityGroup(Int32.Parse(lbxOrgGroups.SelectedValue));
                    Role             role  = new Role(Group.RoleID);
                    // evaluate if user may administor members of security group based on role
                    if (CurrentUser.InRole(role.Name, int.Parse(ddlOrganizations.SelectedValue)))
                    {
                        foreach (ListItem li in lbxUserLookup.Items)
                        {
                            if (li.Selected)
                            {
                                // add individual membership
                                OrgSecurityGroupMembership membership = new OrgSecurityGroupMembership();
                                membership.OrgSecurityGroupID = Int32.Parse(lbxOrgGroups.SelectedValue);
                                membership.OrgGroupID         = int.Parse(ddlOrganizations.SelectedValue);
                                membership.UserID             = int.Parse(li.Value);
                                membership.CreatedBy          = CurrentUser.DisplayName;
                                membership.ModifiedBy         = CurrentUser.DisplayName;

                                if (!membership.Insert())
                                {
                                    Transaction xAction = new Transaction();
                                    xAction.Action    = string.Format("Failed to add {0} to org security group {1}", li.Text, lbxOrgGroups.SelectedItem.Text);
                                    xAction.Category  = "Application Administration";
                                    xAction.Type      = Transaction.TYPE_FAILURE;
                                    xAction.CreatedBy = CurrentUser.DisplayName;
                                    xAction.Insert();
                                }
                                else
                                {
                                    Transaction xAction = new Transaction();
                                    xAction.Action    = string.Format("Successfully added {0} to org security group {1}", li.Text, lbxOrgGroups.SelectedItem.Text);
                                    xAction.Category  = "Application Administration";
                                    xAction.Type      = Transaction.TYPE_SUCCESS;
                                    xAction.CreatedBy = CurrentUser.DisplayName;
                                    xAction.Insert();
                                    Action.Write(string.Format("Assigned {0} to the {1} application security group {2}", li.Text, ddlOrganizations.SelectedItem.Text, lbxOrgGroups.SelectedItem.Text), CurrentUser.DisplayName);
                                }
                            }
                        }
                        FillOrgSecurityGroupMembers(Int32.Parse(lbxOrgGroups.SelectedValue), int.Parse(ddlOrganizations.SelectedValue));
                    }
                    else
                    {
                        ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('You do not have permission to add members to this security group!');", true);
                    }
                }
            } catch (Exception ex) {
                SPA.Error.WriteError(ex);
                if (ShowDebug)
                {
                    lblErrorMessage.Text = ex.ToString();
                }
            }
        }