private void FillListBox() { Userods.RefreshCache(); UserGroups.RefreshCache(); GroupPermissions.RefreshCache(); listUser.BeginUpdate(); listUser.Items.Clear(); if (PrefC.GetBool(PrefName.UserNameManualEntry)) { //Because _listUsers is used to verify the user name typed in, we need to include both non-hidden and CEMT users for offices that type in their credentials instead of picking. _listUsers = Userods.GetUsers(true); } else if (checkShowCEMTUsers.Checked) //Only show list of CEMT users. { _listUsers = Userods.GetUsersForCEMT().Where(x => !x.IsHidden).ToList(); } else //This will be the most common way to fill the user list. Only includes non-hidden, non-CEMT users. { _listUsers = Userods.GetUsers(); } _listUsers.ForEach(x => listUser.Items.Add(x)); if (UserNumPrompt > 0) { listUser.SelectedIndex = _listUsers.FindIndex(x => x.UserNum == UserNumPrompt); //can be -1 if not found } else if (Security.CurUser != null) { listUser.SelectedIndex = _listUsers.FindIndex(x => x.UserNum == Security.CurUser.UserNum); //can be -1 if not found } if (listUser.SelectedIndex == -1 && listUser.Items.Count > 0) //It is possible there are no users in the list if all users are CEMT users. { listUser.SelectedIndex = 0; } listUser.EndUpdate(); }
private void FillTreePerm() { GroupPermissions.RefreshCache(); if (SelectedGroupNum == 0) { labelPerm.Text = ""; treePermissions.Enabled = false; } else { labelPerm.Text = Lan.g(this, "Permissions for group:") + " " + UserGroups.GetGroup(SelectedGroupNum).Description; treePermissions.Enabled = true; } for (int i = 0; i < treePermissions.Nodes.Count; i++) { FillNodes(treePermissions.Nodes[i], SelectedGroupNum); } }
///<summary>Fills the tree's checkboxes depending on whether or not the usergroups in _listUserGroupNums have the specific permission.</summaryZ> public void FillTreePerm() { GroupPermissions.RefreshCache(); if (_listUserGroupNums.Count == 0) { treePermissions.Enabled = false; } else { treePermissions.Enabled = true; } treePermissions.BeginUpdate(); for (int i = 0; i < treePermissions.Nodes.Count; i++) { FillNodes(treePermissions.Nodes[i], _listUserGroupNums); } treePermissions.EndUpdate(); }
private void FillListBox() { Userods.RefreshCache(); UserGroups.RefreshCache(); GroupPermissions.RefreshCache(); listUser.BeginUpdate(); listUser.Items.Clear(); shortList = UserodC.ShortList; for (int i = 0; i < shortList.Count; i++) { listUser.Items.Add(shortList[i]); if (Security.CurUser != null && shortList[i].UserNum == Security.CurUser.UserNum) { listUser.SelectedIndex = i; } } if (listUser.SelectedIndex == -1) { listUser.SelectedIndex = 0; } listUser.EndUpdate(); }
///<summary>Toggles permissions based on the node the user has clicked. ///Will do nothing if in Read-Only mode or more than one usergroup is selected.</summary> private void treePermissions_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if (ReadOnly || _listUserGroupNums.Count != 1) { return; } _clickedPermNode = treePermissions.GetNodeAt(e.X, e.Y); if (_clickedPermNode == null) { return; } //Do nothing if the user didn't click on a check box. if (_clickedPermNode.Parent == null) //level 1 { if (e.X < 5 || e.X > 17) { return; } } else if (_clickedPermNode.Parent.Parent == null) //level 2 { if (e.X < 24 || e.X > 36) { return; } } else if (_clickedPermNode.Parent.Parent.Parent == null) //level 3 { if (e.X < 43 || e.X > 55) { return; } } //User clicked on a check box. Do stuff. if (_clickedPermNode.ImageIndex == 1) //unchecked, so need to add a permission { GroupPermission perm = new GroupPermission(); perm.PermType = (Permissions)_clickedPermNode.Tag; perm.UserGroupNum = _listUserGroupNums.First(); if (GroupPermissions.PermTakesDates(perm.PermType)) { perm.IsNew = true; //Call an event that bubbles back up to the calling Form. The event returns a dialog result so we know how to continue here. DialogResult result = GroupPermissionChecked?.Invoke(sender, new SecurityEventArgs(perm)) ?? DialogResult.Cancel; if (result == DialogResult.Cancel) { treePermissions.EndUpdate(); return; } } else if (perm.PermType == Permissions.Reports) //Reports permission is being checked. //Call an event that bubbles back up to the calling Form. The event returns a dialog result so we know how to continue here. { DialogResult result = ReportPermissionChecked?.Invoke(sender, new SecurityEventArgs(perm)) ?? DialogResult.Cancel; if (result == DialogResult.Cancel) { treePermissions.EndUpdate(); return; } } else { try { GroupPermissions.Insert(perm); SecurityLogs.MakeLogEntry(Permissions.SecurityAdmin, 0, "Permission '" + perm.PermType + "' granted to '" + UserGroups.GetGroup(perm.UserGroupNum).Description + "'"); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } if (perm.PermType.In(Permissions.ProcComplEdit, Permissions.ProcExistingEdit)) { //Adding ProcComplEdit full, so add ProcComplEditlimited too. //Do the same for EO and EC procs GroupPermission permLimited = GroupPermissions.GetPerm(_listUserGroupNums.First(), Permissions.ProcComplEditLimited); if (permLimited == null) { GroupPermissions.RefreshCache(); //refresh NewerDays/Date to add the same for ProcComplEditLimited perm = GroupPermissions.GetPerm(_listUserGroupNums.First(), perm.PermType); permLimited = new GroupPermission(); permLimited.NewerDate = perm.NewerDate; permLimited.NewerDays = perm.NewerDays; permLimited.UserGroupNum = perm.UserGroupNum; permLimited.PermType = Permissions.ProcComplEditLimited; try { GroupPermissions.Insert(permLimited); SecurityLogs.MakeLogEntry(Permissions.SecurityAdmin, 0, "Permission '" + perm.PermType + "' granted to '" + UserGroups.GetGroup(perm.UserGroupNum).Description + "'"); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } } } else if (_clickedPermNode.ImageIndex == 2) //checked, so need to delete the perm { try { GroupPermissions.RemovePermission(_listUserGroupNums.First(), (Permissions)_clickedPermNode.Tag); SecurityLogs.MakeLogEntry(Permissions.SecurityAdmin, 0, "Permission '" + _clickedPermNode.Tag + "' revoked from '" + UserGroups.GetGroup(_listUserGroupNums.First()).Description + "'"); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } if ((Permissions)_clickedPermNode.Tag == Permissions.ProcComplEditLimited) { //Deselecting ProcComplEditLimted, deselect ProcComplEdit and ProcExistingEdit permissions if present. List <Permissions> listPermissions = new List <Permissions>(); if (GroupPermissions.HasPermission(_listUserGroupNums.First(), Permissions.ProcComplEdit, 0)) { listPermissions.Add(Permissions.ProcComplEdit); } if (GroupPermissions.HasPermission(_listUserGroupNums.First(), Permissions.ProcExistingEdit, 0)) { listPermissions.Add(Permissions.ProcExistingEdit); } listPermissions.ForEach(x => { try { GroupPermissions.RemovePermission(_listUserGroupNums.First(), x); SecurityLogs.MakeLogEntry(Permissions.SecurityAdmin, 0, "Permission '" + _clickedPermNode.Tag + "' revoked from '" + UserGroups.GetGroup(_listUserGroupNums.First()).Description + "'"); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } }); } } else if (_clickedPermNode.ImageIndex == 3) //Partially checked (currently only applies to Reports permission) { try { GroupPermissions.RemovePermission(_listUserGroupNums.First(), (Permissions)_clickedPermNode.Tag); SecurityLogs.MakeLogEntry(Permissions.SecurityAdmin, 0, "Permission '" + _clickedPermNode.Tag + "' revoked from '" + UserGroups.GetGroup(_listUserGroupNums.First()).Description + "'"); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } if ((Permissions)_clickedPermNode.Tag == Permissions.AccountProcsQuickAdd) { string programName = PrefC.GetString(PrefName.SoftwareName); MsgBox.Show(this, programName + " needs to be restarted on workstations before the changes will take place."); } FillTreePerm(); }