/// <summary> /// 通过OU选择岗位 /// </summary> /// <param name="actionContext"></param> /// <param name="httpContext"></param> /// <returns>null</returns> public Forward FindGroupByOU(ActionContext actionContext, HttpContext httpContext) { AjaxForwardUtils.InitResponse(httpContext.Response); JavaScriptArray jsonArray = new JavaScriptArray(); string ouUnid = RequestUtils.GetStringParameter(httpContext, "ouUnid", null); string groupType = RequestUtils.GetStringParameter(httpContext, "groupType", "0");// 岗位类型:0--全部类型(默认),1--可派单岗位,2--不可派单岗位 if (string.IsNullOrEmpty(ouUnid)) { throw new Exception("OUUnid不能为空!需要在请求参数中包含有效的OUUnid值。"); } // 获取该OU中的岗位信息 IList groups = this.groupService.FindByOU(ouUnid, false, groupType); if (logger.IsDebugEnabled) { logger.Debug("ouUnid=" + ouUnid); logger.Debug("groupType=" + groupType); logger.Debug("count=" + groups.Count); } // 组合信息 if (groups != null && groups.Count > 0) { foreach (Group group in groups) { jsonArray.Add(JsonUtils.CreateJsonObject(group)); } } httpContext.Response.Write(JavaScriptConvert.SerializeObject(jsonArray)); return(null); }
/// <summary> /// 修改密码 /// </summary> /// <param name="actionContext"></param> /// <param name="httpContext"></param> /// <returns></returns> public Forward UpdateUser(ActionContext actionContext, HttpContext httpContext) { AjaxForwardUtils.InitResponse(httpContext.Response); JavaScriptObject jsonObj = new JavaScriptObject(); try { long userID = long.Parse(httpContext.Request.Params["id"]); if (-1 != userID) { string password = httpContext.Request.Params["p"]; string newEncryptPassword = this.userService.ChangeUserPasswordOne(null, userID, password); // Domain = userInfoService.Load(userInfoID); //httpContext.Response.Write("ok"); jsonObj.Add("newEncryptPassword", newEncryptPassword); return(AjaxForwardUtils.SuccessForward(httpContext, jsonObj, "USERINFO.CHANGE_PASSWORD.WEB.SUCCESS", null)); } if (logger.IsDebugEnabled) { logger.Debug("update:" + userID); } return(null); } catch (Exception e) { return(AjaxForwardUtils.ExceptionForward(httpContext, jsonObj, e)); } }
/// <summary> /// 生成列表对应的json字符串并写入到请求的响应中 /// </summary> /// <param name="httpContext">Http上下文</param> /// <param name="lists">CTI列表</param> private static void WriteOptionsJsonData(HttpContext httpContext, IList lists) { JavaScriptArray jsonOptions = new JavaScriptArray(); if (lists != null) { foreach (OptionItem item in lists) { jsonOptions.Add(JsonUtils.CreateJsonObject(item)); } } string jsonString = JavaScriptConvert.SerializeObject(jsonOptions); if (logger.IsDebugEnabled) { logger.Debug("json=" + jsonString); } AjaxForwardUtils.InitResponse(httpContext.Response); httpContext.Response.Write(jsonString); }
public virtual Forward GetUnitTree(ActionContext actionContext, HttpContext httpContext) { string node = httpContext.Request.Params["node"]; IList unitTree = null; User curUser = TSWEBContext.Current.CurUser; if (TSWEBContext.Current.IsHasPrivilege(Constants.ADMIN_ALL)) { unitTree = this.ouInfoService.GetUnitTree(curUser, Constants.OT_ALL); } else if (TSWEBContext.Current.IsHasPrivilege(Constants.ADMIN_LOCALANDCHILD)) { unitTree = this.ouInfoService.GetUnitTree(curUser, Constants.OT_LOCALANDCHILD); } else if (TSWEBContext.Current.IsHasPrivilege(Constants.ADMIN_LOCAL)) { unitTree = this.ouInfoService.GetUnitTree(curUser, Constants.OT_LOCAL); } Newtonsoft.Json.JavaScriptArray jsonArray = new Newtonsoft.Json.JavaScriptArray(); if (!(string.IsNullOrEmpty(node) || unitTree == null)) { foreach (object obj in unitTree) { string[] nodeInfo = obj as string[]; if (node.Equals(nodeInfo[1], StringComparison.OrdinalIgnoreCase)) { Newtonsoft.Json.JavaScriptObject jsonObject = new Newtonsoft.Json.JavaScriptObject(); jsonObject.Add("id", nodeInfo[0]); jsonObject.Add("text", nodeInfo[2]); jsonArray.Add(jsonObject); } } } AjaxForwardUtils.InitResponse(httpContext.Response); httpContext.Response.Write(Newtonsoft.Json.JavaScriptConvert.SerializeObject(jsonArray)); return(null); }
/// <summary> /// 获取OUInfo的详细信息 /// </summary> /// <param name="actionContext"></param> /// <param name="httpContext"></param> /// <returns>null</returns> public Forward GetDetail(ActionContext actionContext, HttpContext httpContext) { AjaxForwardUtils.InitResponse(httpContext.Response); JavaScriptObject json = new JavaScriptObject(); try { string unid = RequestUtils.GetStringParameter(httpContext, "unid", null); logger.Debug("unid:" + unid); if (string.IsNullOrEmpty(unid)) { MsgException e = new MsgException("OUInfo的Unid不能为空,需要在请求参数中包含有效的OUInfo的Unid值!"); logger.Error(e.Message, e); return(AjaxForwardUtils.ExceptionForward(httpContext, json, e)); } OUInfo ouInfo = this.ouInfoService.Load(unid); if (ouInfo == null) { MsgException e = new MsgException("指定Unid的OUInfo在系统中不存在:unid=" + unid); logger.Error(e.Message, e); return(AjaxForwardUtils.ExceptionForward(httpContext, json, e)); } string jsonStr = JavaScriptConvert.SerializeObject(ouInfo); if (logger.IsDebugEnabled) { logger.Debug("json=" + jsonStr); } httpContext.Response.Write(jsonStr); return(null); } catch (Exception e) { logger.Error(e.Message, e); return(AjaxForwardUtils.ExceptionForward(httpContext, json, e)); } }
/// <summary> /// 通过OU选择岗位 /// </summary> /// <param name="actionContext"></param> /// <param name="httpContext"></param> /// <returns>null</returns> public Forward GetDepartmentNodes(ActionContext actionContext, HttpContext httpContext) { AjaxForwardUtils.InitResponse(httpContext.Response); string node = RequestUtils.GetStringParameter(httpContext, "node", "");// 指定的ou的unid(点击树节点) string type = RequestUtils.GetStringParameter(httpContext, "type", "all"); string ouType = RequestUtils.GetStringParameter(httpContext, "ouType", null); if (logger.IsDebugEnabled) { logger.Debug("node=" + node); logger.Debug("type=" + type); logger.Debug("ouType=" + ouType); } bool isRoot = false; // 判断当前用户可选的权限范围 IList ouInfoLists = new ArrayList(); User userInfo = TSWEBContext.Current.CurUser; if (userInfo.HasPrivilege(Constants.DP_ALL)) // 用户拥有查看所有单位结构的权限 { if (node == "-1" || node == "root" || node == "") { isRoot = true; ouInfoLists = this.ouInfoService.FindChilds("", OUInfo.OT_UNIT);// 所有单位信息 } else { ouInfoLists = getChildOUInfos(node, type, ouType); } if (logger.IsDebugEnabled) { logger.Debug("Constants.DP_ALL"); logger.Debug("Count1=" + ouInfoLists.Count.ToString()); } } else if (userInfo.HasPrivilege(Constants.DP_LOCALANDCHILD)) // 用户拥有查看本级单位结构的权限 { if (node == "-1" || node == "root" || node == "") { isRoot = true; OUInfo ouInfo = this.ouInfoService.Load(userInfo.UnitUnid);// 当前用户所在单位 if (null != ouInfo) { ouInfoLists.Add(ouInfo); } } else { ouInfoLists = getChildOUInfos(node, type, ouType); } if (logger.IsDebugEnabled) { logger.Debug("Constants.DP_LOCALANDCHILD"); } } else // 用户只拥有查看本单位结构的权限 { if (node == "-1" || node == "root" || node == "") { isRoot = true; OUInfo ouInfo = this.ouInfoService.Load(userInfo.UnitUnid);// 当前用户所在单位 if (null != ouInfo) { ouInfoLists.Add(ouInfo); } } else { if (!OUInfo.OT_UNIT.Equals(ouType, StringComparison.OrdinalIgnoreCase)) { ouInfoLists = this.ouInfoService.FindChilds(node, OUInfo.OT_DEPARTMENT);// ou下的所有子部门 } } if (logger.IsDebugEnabled) { logger.Debug("Constants.DP_LOCAL"); } } // 获取是否需要产生链接(不推荐使用) string link = RequestUtils.GetStringParameter(httpContext, "link", "N"); bool isLink = false; if (link.Equals(Constants.YESNO_YES, StringComparison.OrdinalIgnoreCase)) { isLink = true; } bool singleClickExpand = RequestUtils.GetBoolParameter(httpContext, "singleClickExpand", false); // 组合返回的信息 JavaScriptArray jsonArray = createOUInfosJsonArray(ouInfoLists, isLink, singleClickExpand); if (logger.IsDebugEnabled) { logger.Debug("Count2=" + ouInfoLists.Count.ToString()); } // 如果是加载根节点的子节点,则同时预加载第一个子节点的下一级子节点 if (isRoot && ouInfoLists.Count > 0) { OUInfo ouInfo = (OUInfo)ouInfoLists[0]; IList ouInfos2 = getChildOUInfos(ouInfo.Unid, type, ouType); JavaScriptArray childJsonArray = createOUInfosJsonArray(ouInfos2, isLink, singleClickExpand); ((JavaScriptObject)jsonArray[0]).Add("children", childJsonArray); if (logger.IsDebugEnabled) { logger.Debug("firstNode.children.Count=" + ouInfos2.Count.ToString()); } } string jsonStr = JavaScriptConvert.SerializeObject(jsonArray); if (logger.IsDebugEnabled) { logger.Debug("isRoot=" + isRoot.ToString()); logger.Debug("json=" + jsonStr); } httpContext.Response.Write(jsonStr); return(null); }
/// <summary> /// 获取权限节点 /// </summary> /// <param name="actionContext"></param> /// <param name="httpContext"></param> /// <returns></returns> public Forward GetPrivilegeNodes(ActionContext actionContext, HttpContext httpContext) { logger.Debug("begin load Privilege's nodes"); AjaxForwardUtils.InitResponse(httpContext.Response); JavaScriptArray jsonArray = new JavaScriptArray(); JavaScriptObject json; string node = RequestUtils.GetStringParameter(httpContext, "node", "root"); if (logger.IsDebugEnabled) { logger.Debug("node=" + node); } if ("root".Equals(node, StringComparison.OrdinalIgnoreCase)) { node = null; } ArrayList modelsList = new ArrayList(); ArrayList privilegesList = new ArrayList(); modelsList.AddRange(this.modelService.FindChildren(node)); privilegesList.AddRange(this.privilegeService.FindByModelAndType(node, Privilege.PRIVILEGETYPE_MODEL)); if (modelsList.Count == 0 && privilegesList.Count == 0) { logger.Error("modelsList或privilegesList为空!"); httpContext.Response.Write(JavaScriptConvert.SerializeObject(jsonArray)); return(null); } // 先获取当前用户所拥有的全部权限列表 SessionHelper sessionHelper = new SessionHelper(); User userInfo = sessionHelper.GetSession(TSLibWeb.Constants.Session_User) as User; if (null == userInfo) { return(null); } ArrayList userPrivilegesList = new ArrayList(); userPrivilegesList.AddRange(userInfo.Privileges.Values); if (null == userPrivilegesList || userPrivilegesList.Count == 0) { logger.Error("userPrivilegesList为空!"); httpContext.Response.Write(JavaScriptConvert.SerializeObject(jsonArray)); return(null); } // 首先处理模块权限 Model model, tempModel; Privilege privilege; for (int i = 0; i < modelsList.Count; i++) { model = (Model)modelsList[i]; if (null == model) { continue; } // 判断用户所拥有的权限是否在本模块中 bool isAdd = false; for (int j = 0; j < userPrivilegesList.Count; j++) { privilege = (Privilege)userPrivilegesList[j]; if (null == privilege || !Privilege.PRIVILEGETYPE_MODEL.Equals(privilege.Type, StringComparison.OrdinalIgnoreCase)) { continue; } tempModel = privilege.Model; while (null != tempModel) { if (tempModel.ID == model.ID) { isAdd = true; break; } tempModel = tempModel.Parent; } if (isAdd) { break; } } if (isAdd) { json = new JavaScriptObject(); json.Add("text", model.Name); json.Add("id", model.Unid); //json.Add("unid", model.Unid); json.Add("isModel", true); json.Add("singleClickExpand", true); // TODO: 更改该样式 json.Add("cls", "folder"); jsonArray.Add(json); } } // 再处理功能权限 string rootPath = TSLibWeb.WEB.Page.GetContextPath(httpContext.Request) + "/"; for (int i = 0; i < privilegesList.Count; i++) { privilege = (Privilege)privilegesList[i]; if (null == privilege) { continue; } if (!Privilege.PRIVILEGETYPE_MODEL.Equals(privilege.Type, StringComparison.OrdinalIgnoreCase)) { continue; } // 判断用户所拥有的权限是否在本模块中 bool isAdd = false; for (int j = 0; j < userPrivilegesList.Count; j++) { Privilege privilegeTmp = (Privilege)userPrivilegesList[j]; if (null == privilegeTmp) { continue; } if (privilegeTmp.ID == privilege.ID) { isAdd = true; break; } } if (isAdd) { json = new JavaScriptObject(); json.Add("text", privilege.Name); json.Add("id", privilege.Unid); //json.Add("unid", privilege.Unid); json.Add("isPrivilege", true); json.Add("leaf", true); // TODO: 更改该样式 json.Add("cls", "cls"); json.Add("iconCls", "egd-icon-privilege"); string urlPath = privilege.UrlPath; if (urlPath != null) { urlPath = urlPath.Replace("../", rootPath); urlPath = urlPath.Replace("{rootPath}", rootPath); json.Add("urlPath", urlPath); json.Add("href", urlPath); if (logger.IsDebugEnabled) { logger.Debug("href old=" + privilege.UrlPath); logger.Debug("href new=" + urlPath); } } // 该代码会导致IE6中打开的页面为空 //json.Add("href", "javascript:openUrl('" + privilege.UrlPath + "," + privilege.Name + "')"); jsonArray.Add(json); } } if (logger.IsDebugEnabled) { logger.Debug("json=" + JavaScriptConvert.SerializeObject(jsonArray)); } httpContext.Response.Write(JavaScriptConvert.SerializeObject(jsonArray)); return(null); }