public bool CheckdistinguishedNames(Guid transactionid, List <string> distinguishedNames, out ErrorCodeInfo error) { bool bResult = true; error = new ErrorCodeInfo(); try { do { string rootOuPath = ConfigADProvider.GetCompanyOuDistinguishedName(); foreach (string distinguishedName in distinguishedNames) { string ouPath = string.Empty; if (distinguishedName.ToLower().Contains("cn=")) { ouPath = distinguishedName.Substring(ouPath.IndexOf(',') + 1); } else { ouPath = distinguishedName; } do { ouPath = ouPath.Substring(ouPath.IndexOf(',') + 1); if (distinguishedNames.Contains(ouPath)) { bResult = false; error.Code = ErrorCode.HaveParentOu; error.SetInfo(distinguishedName); break; } } while (ouPath.ToLower().Contains("ou=")); } } while (false); } catch (Exception ex) { LoggerHelper.Error("CheckdistinguishedNames", string.Empty, ex.ToString(), transactionid); error.Code = ErrorCode.Exception; bResult = false; } return(bResult); }
public bool ModifyMailAudit(Guid transactionid, AdminInfo admin, MailAuditInfo mailAuditInfo, out string strJsonResult) { bool result = true; strJsonResult = string.Empty; ErrorCodeInfo error = new ErrorCodeInfo(); string message = string.Empty; string paramstr = string.Empty; paramstr += $"AdminID:{admin.UserID}"; paramstr += $"||AdminAccount:{admin.UserAccount}"; paramstr += $"||GroupID:{mailAuditInfo.Group.GroupID}"; for (int i = 0; i < mailAuditInfo.Audits.Count; i++) { paramstr += $"||AuditID:{mailAuditInfo.Audits[i].UserID}"; } string funname = "ModifyMailAudit"; try { do { error = mailAuditInfo.ChangeCheckProp(); if (error.Code != ErrorCode.None) { strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info); LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid); result = false; break; } MailAuditDBProvider provider = new MailAuditDBProvider(); MailAuditInfo oldMailAuditInfo = new MailAuditInfo(); oldMailAuditInfo.ID = mailAuditInfo.ID; if (!provider.GetMailAuditInfo(transactionid, admin, ref oldMailAuditInfo, out error)) { strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info); LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid); result = false; break; } //判断审批人有效性 DirectoryEntry entry = new DirectoryEntry(); CommonProvider commonProvider = new CommonProvider(); List <UserInfo> audits = new List <UserInfo>(); List <Guid> users = new List <Guid>(); if (mailAuditInfo.Audits.Count > 0) { for (int i = 0; i < mailAuditInfo.Audits.Count; i++) { if (!commonProvider.GetADEntryByGuid(mailAuditInfo.Audits[i].UserID, out entry, out message)) { continue; } mailAuditInfo.Audits[i].DisplayName = entry.Properties["cn"].Value == null ? "" : Convert.ToString(entry.Properties["cn"].Value); mailAuditInfo.Audits[i].UserAccount = entry.Properties["userPrincipalName"].Value == null ? "" : Convert.ToString(entry.Properties["userPrincipalName"].Value); mailAuditInfo.Audits[i].IsCreateMail = entry.Properties["mail"].Value == null ? false : true; if (!mailAuditInfo.Audits[i].IsCreateMail) { error.Code = ErrorCode.UserNotExchange; error.SetInfo(mailAuditInfo.Audits[i].DisplayName + "(" + mailAuditInfo.Audits[i].UserAccount + ")"); strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info); LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid); result = false; break; } mailAuditInfo.AuditUsers += mailAuditInfo.Audits[i].DisplayName + "(" + mailAuditInfo.Audits[i].UserAccount + "),"; users.Add(mailAuditInfo.Audits[i].UserID); audits.Add(mailAuditInfo.Audits[i]); } } if (result) { mailAuditInfo.AuditUsers = string.IsNullOrEmpty(mailAuditInfo.AuditUsers) ? string.Empty : mailAuditInfo.AuditUsers.Remove(mailAuditInfo.AuditUsers.LastIndexOf(','), 1); DirectoryEntry groupEntry = new DirectoryEntry(); if (!commonProvider.GetADEntryByGuid(mailAuditInfo.Group.GroupID, out groupEntry, out message)) { error.Code = ErrorCode.SearchADDataError; strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info); LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid); LoggerHelper.Error("ModifyMailAudit调用GetADEntryByGuid异常", paramstr, message, transactionid); result = false; break; } mailAuditInfo.Group.Account = groupEntry.Properties["mail"].Value == null ? "" : Convert.ToString(groupEntry.Properties["mail"].Value); mailAuditInfo.Group.DisplayName = groupEntry.Properties["cn"].Value == null ? "" : Convert.ToString(groupEntry.Properties["cn"].Value); ADManagerWebService.ManagerWebService webService = new ADManagerWebService.ManagerWebService(); webService.Timeout = -1; //Set Group Exchange webService.SetDistributionGroupModeratedBy(transactionid, mailAuditInfo.Group.GroupID.ToString(), false, new List <Guid>().ToArray(), out message); //Set Group Exchange if (!webService.SetDistributionGroupModeratedBy(transactionid, mailAuditInfo.Group.GroupID.ToString(), true, users.ToArray(), out message)) { error.Code = ErrorCode.Exception; LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid); LoggerHelper.Error("MailAuditManager调用AddMailAudit异常", paramstr, message, transactionid); strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info); result = false; break; } if (!provider.ModifyMailAudit(transactionid, admin, mailAuditInfo, out error)) { strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info); LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid); result = false; break; } foreach (UserInfo u in audits) { if (!provider.AddMailAuditUsers(transactionid, mailAuditInfo, u, out error)) { continue; } } error.Code = ErrorCode.None; LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), true, transactionid); strJsonResult = JsonHelper.ReturnJson(true, Convert.ToInt32(error.Code), error.Info); #region 操作日志 LogInfo operateLog = new LogInfo(); operateLog.AdminID = admin.UserID; operateLog.AdminAccount = admin.UserAccount; operateLog.RoleID = admin.RoleID; operateLog.ClientIP = _clientip; operateLog.OperateResult = true; operateLog.OperateType = "修改邮件审批规则"; operateLog.OperateLog = $"{admin.UserAccount}于{DateTime.Now}修改邮件审批规则。" + $"原对象:{oldMailAuditInfo.Group.DisplayName},现对象:{mailAuditInfo.Group.DisplayName};" + $"原审批人:{oldMailAuditInfo.AuditUsers},现审批人:{mailAuditInfo.AuditUsers}"; LogManager.AddOperateLog(transactionid, operateLog); #endregion result = true; } } while (false); } catch (Exception ex) { error.Code = ErrorCode.Exception; LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid); LoggerHelper.Error("MailAuditManager调用ModifySensitiveMail异常", paramstr, ex.ToString(), transactionid); strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info); result = false; } return(result); }