示例#1
0
        private AuditInfoEntity CreateAuditInfo(ActionExecutingContext context)
        {
            var routeValues = context.ActionDescriptor.RouteValues;
            var auditInfo   = new AuditInfoEntity
            {
                AccountId     = _loginInfo.AccountId,
                Area          = routeValues["area"] ?? "",
                Controller    = routeValues["controller"],
                Action        = routeValues["action"],
                Parameters    = JsonConvert.SerializeObject(context.ActionArguments),
                Platform      = _loginInfo.Platform,
                IP            = _loginInfo.IP,
                ExecutionTime = DateTime.Now
            };

            var controllerDescriptor = _mvcHelper.GetAllController().FirstOrDefault(m =>
                                                                                    m.Area.EqualsIgnoreCase(auditInfo.Area) && m.Name.EqualsIgnoreCase(auditInfo.Controller));

            if (controllerDescriptor != null)
            {
                auditInfo.ControllerDesc = controllerDescriptor.Description;

                var actionDescription = _mvcHelper.GetAllAction().FirstOrDefault(m =>
                                                                                 m.Controller == controllerDescriptor && m.Name.EqualsIgnoreCase(auditInfo.Action));
                if (actionDescription != null)
                {
                    auditInfo.ActionDesc = actionDescription.Description;
                }
            }

            //记录浏览器UA
            if (_loginInfo.Platform == Platform.Web)
            {
                auditInfo.BrowserInfo = context.HttpContext.Request.Headers["User-Agent"];
            }

            return(auditInfo);
        }
示例#2
0
        private AuditInfoAddModel CreateAuditInfo(ActionExecutingContext context)
        {
            try
            {
                var routeValues = context.ActionDescriptor.RouteValues;
                var auditInfo   = new AuditInfoAddModel
                {
                    Area       = routeValues["area"] ?? "",
                    Controller = routeValues["controller"],
                    Action     = routeValues["action"],
                    Parameters = context.ActionArguments.ToJson(),
                    IP         = _loginInfo.IP
                };

                var controllerDescriptor = _mvcHelper.GetAllController().FirstOrDefault(m => m.Area.NotNull() && m.Area.EqualsIgnoreCase(auditInfo.Area) && m.Name.EqualsIgnoreCase(auditInfo.Controller));
                if (controllerDescriptor != null)
                {
                    auditInfo.ControllerDesc = controllerDescriptor.Description;

                    var actionDescription = _mvcHelper.GetAllAction().FirstOrDefault(m => m.Controller == controllerDescriptor && m.Name.EqualsIgnoreCase(auditInfo.Action));
                    if (actionDescription != null)
                    {
                        auditInfo.ActionDesc = actionDescription.Description;
                    }
                }

                auditInfo.BrowserInfo = context.HttpContext.Request.Headers["User-Agent"];

                return(auditInfo);
            }
            catch (Exception ex)
            {
                _logger.LogError("审计日志创建异常:{@ex}", ex);
            }

            return(null);
        }
        /// <summary>
        /// 加载权限树
        /// </summary>
        /// <returns></returns>
        private void LoadTree()
        {
            var config = _configProvider.Get <SystemConfig>();

            _tree = new TreeResultModel <string, PermissionTreeModel>
            {
                Id    = "",
                Label = config.Title,
                Item  = new PermissionTreeModel()
            };
            _tree.Path.Add(_tree.Label);

            var controllers = _mvcHelper.GetAllController();

            //模块
            foreach (var module in _moduleCollection)
            {
                var moduleNode = new TreeResultModel <string, PermissionTreeModel>
                {
                    Id    = module.Code,
                    Label = module.Name,
                    Item  = new PermissionTreeModel
                    {
                        Label = module.Name,
                        Code  = module.Code
                    }
                };

                moduleNode.Path.AddRange(_tree.Path);
                moduleNode.Path.Add(module.Name);

                //控制器
                foreach (var controller in controllers.Where(m => m.Area.EqualsIgnoreCase(module.Code)))
                {
                    var controllerName = controller.Description ?? controller.Name;
                    var controllerNode = new TreeResultModel <string, PermissionTreeModel>
                    {
                        Id    = $"{module.Code}_{controller.Name}".ToLower(),
                        Label = controllerName,
                        Item  = new PermissionTreeModel
                        {
                            Label = controllerName
                        }
                    };

                    controllerNode.Item.Code = controllerNode.Id;

                    controllerNode.Path.AddRange(moduleNode.Path);
                    controllerNode.Path.Add(controllerName);

                    var permissions = Query(module.Code, controller.Name);
                    //权限
                    foreach (var permission in permissions)
                    {
                        var permissionName = permission.Name.Contains("_") ? permission.Name.Split('_')[1] : permission.Name;
                        var permissionNode = new TreeResultModel <string, PermissionTreeModel>
                        {
                            Id    = permission.Code,
                            Label = permissionName,
                            Item  = new PermissionTreeModel
                            {
                                Label        = permissionName,
                                Code         = permission.Code,
                                IsPermission = true
                            }
                        };

                        permissionNode.Path.AddRange(controllerNode.Path);
                        permissionNode.Path.Add(permissionName);

                        controllerNode.Children.Add(permissionNode);
                    }

                    moduleNode.Children.Add(controllerNode);
                }
                _tree.Children.Add(moduleNode);
            }
        }
示例#4
0
        /// <summary>
        /// 加载权限树
        /// </summary>
        /// <returns></returns>
        private void LoadTree()
        {
            _tree = new TreeResultModel <string, PermissionTreeModel>
            {
                Id       = "",
                Text     = "Zoomtel",
                Item     = new PermissionTreeModel(),
                Children = new List <TreeResultModel <string, PermissionTreeModel> >()
            };
            _tree.Path.Add(_tree.Text);

            var controllers = _mvcHelper.GetAllController().Where(a => a.Area != null);


            //模块
            foreach (var module in _moduleCollection)
            {
                var moduleNode = new TreeResultModel <string, PermissionTreeModel>
                {
                    Id   = module.Code,
                    Text = module.Name,
                    Item = new PermissionTreeModel
                    {
                        Label = module.Name,
                        Code  = module.Code
                    }
                };

                moduleNode.Path.AddRange(_tree.Path);
                moduleNode.Path.Add(module.Name);

                var moduleControllers = controllers.Where(m => m.Area.EqualsIgnoreCase(module.Code));
                if (moduleControllers.Count() > 0)
                {
                    moduleNode.Children = new List <TreeResultModel <string, PermissionTreeModel> >();
                }
                //控制器
                foreach (var controller in moduleControllers)
                {
                    var controllerName = controller.Description ?? controller.Name;
                    var controllerNode = new TreeResultModel <string, PermissionTreeModel>
                    {
                        Id   = $"{module.Code}_{controller.Name}".ToLower(),
                        Text = controllerName,
                        Item = new PermissionTreeModel
                        {
                            Label = controllerName
                        }
                    };

                    controllerNode.Item.Code = controllerNode.Id;

                    controllerNode.Path.AddRange(moduleNode.Path);
                    controllerNode.Path.Add(controllerName);

                    var permissions = Query(module.Code, controller.Name);
                    if (permissions.Count > 0)
                    {
                        controllerNode.Children = new List <TreeResultModel <string, PermissionTreeModel> >();
                    }
                    //权限
                    foreach (var permission in permissions)
                    {
                        var permissionName = permission.Name.Contains("_") ? permission.Name.Split('_')[1] : permission.Name;
                        var permissionNode = new TreeResultModel <string, PermissionTreeModel>
                        {
                            Id   = permission.Code,
                            Text = permissionName,
                            Item = new PermissionTreeModel
                            {
                                Label        = permissionName,
                                Code         = permission.Code,
                                IsPermission = true,
                                IsPage       = permission.IsPage
                            }
                        };

                        permissionNode.Path.AddRange(controllerNode.Path);
                        permissionNode.Path.Add(permissionName);

                        controllerNode.Children.Add(permissionNode);
                    }
                    moduleNode.Children.Add(controllerNode);
                }
                _tree.Children.Add(moduleNode);
            }
        }