Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
lampo1024 committed May 5, 2019
2 parents 895969b + 171a3d9 commit f1f52cf
Show file tree
Hide file tree
Showing 99 changed files with 2,810 additions and 902 deletions.
2 changes: 1 addition & 1 deletion DncZeus.Api/Auth/AppAuthenticationSettings.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************
* AUTHOR: Rector
* CREATEDON: 2018-09-26
* OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* 版权所有,请勿删除
******************************************/

Expand Down
2 changes: 1 addition & 1 deletion DncZeus.Api/Auth/JwtBearerAuthenticationExtension.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************
* AUTHOR: Rector
* CREATEDON: 2018-09-26
* OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* 版权所有,请勿删除
******************************************/

Expand Down
2 changes: 1 addition & 1 deletion DncZeus.Api/Configurations/MappingProfile.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************
* AUTHOR: Rector
* CREATEDON: 2018-09-26
* OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* 版权所有,请勿删除
******************************************/

Expand Down
123 changes: 101 additions & 22 deletions DncZeus.Api/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/******************************************
* AUTHOR: Rector
* CREATEDON: 2018-09-26
* OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* 版权所有,请勿删除
******************************************/

using DncZeus.Api.Entities;
using DncZeus.Api.Extensions;
using DncZeus.Api.Extensions.AuthContext;
using DncZeus.Api.Extensions.DataAccess;
using DncZeus.Api.ViewModels.Rbac.DncMenu;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -56,40 +56,23 @@ public IActionResult Profile()
LEFT JOIN DncPermission AS P ON P.Code = RPM.PermissionCode
INNER JOIN DncMenu AS M ON M.Guid = P.MenuGuid
WHERE P.IsDeleted=0 AND P.Status=1 AND EXISTS (SELECT 1 FROM DncUserRoleMapping AS URM WHERE URM.UserGuid={0} AND URM.RoleCode=RPM.RoleCode)";
if (user.UserType == UserType.SuperAdministator)
if (user.UserType == UserType.SuperAdministrator)
{
//如果是超级管理员
sqlPermission = @"SELECT P.Code AS PermissionCode,P.ActionCode AS PermissionActionCode,P.Name AS PermissionName,P.Type AS PermissionType,M.Name AS MenuName,M.Guid AS MenuGuid,M.Alias AS MenuAlias,M.IsDefaultRouter FROM DncPermission AS P
INNER JOIN DncMenu AS M ON M.Guid = P.MenuGuid
WHERE P.IsDeleted=0 AND P.Status=1";
}
var permissions = _dbContext.DncPermissionWithMenu.FromSql(sqlPermission, user.Guid).ToList();
var allowPages = new List<string> { };

if (user.UserType == UserType.SuperAdministator)
{
allowPages.AddRange(menus.Select(x => x.Alias));
}
else
{
allowPages.AddRange(menus.Where(x => x.IsDefaultRouter == YesOrNo.Yes).Select(x => x.Alias));
foreach (var permission in permissions.Where(x => x.PermissionType == PermissionType.Menu))
{
allowPages.AddRange(FindParentMenuAlias(menus, permission.MenuGuid));
}
}

//var allowPages = FindParentMenuAlias(menus);
var pages = allowPages.Distinct().ToList();
var pagePermissions = permissions.GroupBy(x => x.MenuAlias).ToDictionary(g=>g.Key,g=>g.Select(x=>x.PermissionActionCode));

var pagePermissions = permissions.GroupBy(x => x.MenuAlias).ToDictionary(g => g.Key, g => g.Select(x => x.PermissionActionCode).Distinct());
response.SetData(new
{
access = new string[] { },
avator = user.Avatar,
user_guid = user.Guid,
user_name = user.DisplayName,
user_type = user.UserType,
pages, // =new[] { "rbac", "rbac_user_page", "rbac_menu_page", "rbac_role_page", "rbac_permission_page", "rbac_role_permission_page" },
permissions = pagePermissions

});
Expand Down Expand Up @@ -120,5 +103,101 @@ private List<string> FindParentMenuAlias(List<DncMenu> menus, Guid? parentGuid)

return pages.Distinct().ToList();
}

/// <summary>
///
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult Menu()
{
var strSql = @"SELECT M.* FROM DncRolePermissionMapping AS RPM
LEFT JOIN DncPermission AS P ON P.Code = RPM.PermissionCode
INNER JOIN DncMenu AS M ON M.Guid = P.MenuGuid
WHERE P.IsDeleted=0 AND P.Status=1 AND P.Type=0 AND M.IsDeleted=0 AND M.Status=1 AND EXISTS (SELECT 1 FROM DncUserRoleMapping AS URM WHERE URM.UserGuid={0} AND URM.RoleCode=RPM.RoleCode)";

if (AuthContextService.CurrentUser.UserType == UserType.SuperAdministrator)
{
//如果是超级管理员
strSql = @"SELECT * FROM DncMenu WHERE IsDeleted=0 AND Status=1";
}
var menus = _dbContext.DncMenu.FromSql(strSql, AuthContextService.CurrentUser.Guid).ToList();
var rootMenus = _dbContext.DncMenu.Where(x => x.IsDeleted == IsDeleted.No && x.Status == Status.Normal && x.ParentGuid == Guid.Empty).ToList();
foreach (var root in rootMenus)
{
if (menus.Exists(x => x.Guid == root.Guid))
{
continue;
}
menus.Add(root);
}
var menu = MenuItemHelper.LoadMenuTree(menus, "0");
return Ok(menu);
}
}

/// <summary>
///
/// </summary>
public static class MenuItemHelper
{
/// <summary>
///
/// </summary>
/// <param name="menus"></param>
/// <param name="selectedGuid"></param>
/// <returns></returns>
public static List<MenuItem> BuildTree(this List<MenuItem> menus, string selectedGuid = null)
{
var lookup = menus.ToLookup(x => x.ParentId);

List<MenuItem> Build(string pid)
{
return lookup[pid]
.Select(x => new MenuItem()
{
Guid = x.Guid,
ParentId = x.ParentId,
Children = Build(x.Guid),
Component = x.Component ?? "Main",
Name = x.Name,
Path = x.Path,
Meta = new MenuMeta
{
BeforeCloseFun = x.Meta.BeforeCloseFun,
HideInMenu = x.Meta.HideInMenu,
Icon = x.Meta.Icon,
NotCache = x.Meta.NotCache,
Title = x.Meta.Title,
Permission = x.Meta.Permission
}
}).ToList();
}

var result = Build(selectedGuid);
return result;
}

public static List<MenuItem> LoadMenuTree(List<DncMenu> menus, string selectedGuid = null)
{
var temp = menus.Select(x => new MenuItem
{
Guid = x.Guid.ToString(),
ParentId = x.ParentGuid != null && ((Guid)x.ParentGuid) == Guid.Empty ? "0" : x.ParentGuid?.ToString(),
Name = x.Alias,
Path = $"/{x.Url}",
Component = x.Component,
Meta = new MenuMeta
{
BeforeCloseFun = x.BeforeCloseFun ?? "",
HideInMenu = x.HideInMenu == YesOrNo.Yes,
Icon = x.Icon,
NotCache = x.NotCache == YesOrNo.Yes,
Title = x.Name
}
}).ToList();
var tree = temp.BuildTree(selectedGuid);
return tree;
}
}
}
2 changes: 1 addition & 1 deletion DncZeus.Api/Controllers/Api/V1/MessageController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************
* AUTHOR: Rector
* CREATEDON: 2018-09-26
* OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* 版权所有,请勿删除
******************************************/

Expand Down
2 changes: 1 addition & 1 deletion DncZeus.Api/Controllers/Api/V1/Rbac/IconController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************
* AUTHOR: Rector
* CREATEDON: 2018-09-26
* OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* 版权所有,请勿删除
******************************************/

Expand Down
7 changes: 5 additions & 2 deletions DncZeus.Api/Controllers/Api/V1/Rbac/MenuController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************
* AUTHOR: Rector
* CREATEDON: 2018-09-26
* OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* 版权所有,请勿删除
******************************************/

Expand Down Expand Up @@ -155,7 +155,10 @@ public IActionResult Edit(MenuEditViewModel model)
entity.ModifiedOn = DateTime.Now;
entity.Description = model.Description;
entity.ParentName = model.ParentName;

entity.Component = model.Component;
entity.HideInMenu = model.HideInMenu;
entity.NotCache = model.NotCache;
entity.BeforeCloseFun = model.BeforeCloseFun;
if (!ConfigurationManager.AppSettings.IsTrialVersion)
{
entity.Alias = model.Alias;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************
* AUTHOR: Rector
* CREATEDON: 2018-09-26
* OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* 版权所有,请勿删除
******************************************/

Expand Down
2 changes: 1 addition & 1 deletion DncZeus.Api/Controllers/Api/V1/Rbac/RoleController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************
* AUTHOR: Rector
* CREATEDON: 2018-09-26
* OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* 版权所有,请勿删除
******************************************/

Expand Down
2 changes: 1 addition & 1 deletion DncZeus.Api/Controllers/Api/V1/Rbac/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace DncZeus.Api.Controllers.Api.V1.Rbac
//[CustomAuthorize]
[Route("api/v1/rbac/[controller]/[action]")]
[ApiController]
[CustomAuthorize]
//[CustomAuthorize]
public class UserController : ControllerBase
{
private readonly DncZeusDbContext _dbContext;
Expand Down
2 changes: 1 addition & 1 deletion DncZeus.Api/Controllers/ErrorController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************
* AUTHOR: Rector
* CREATEDON: 2018-09-26
* OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* 版权所有,请勿删除
******************************************/

Expand Down
2 changes: 1 addition & 1 deletion DncZeus.Api/Controllers/OauthController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************
* AUTHOR: Rector
* CREATEDON: 2018-09-26
* OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* 版权所有,请勿删除
******************************************/

Expand Down
8 changes: 7 additions & 1 deletion DncZeus.Api/DncZeus.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
<NoWarn>1701;1702;1591</NoWarn>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Migrations\20190504083800_Init.cs" />
<Compile Remove="Migrations\20190504083800_Init.Designer.cs" />
<Compile Remove="Migrations\20190504084421_Init.cs" />
<Compile Remove="Migrations\20190504084421_Init.Designer.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="8.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="6.0.0" />
Expand All @@ -29,7 +36,6 @@
</ItemGroup>

<ItemGroup>
<Folder Include="Migrations\" />
<Folder Include="wwwroot\css\" />
<Folder Include="wwwroot\js\" />
<Folder Include="wwwroot\images\" />
Expand Down
2 changes: 1 addition & 1 deletion DncZeus.Api/Entities/AuditEntity.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************
* AUTHOR: Rector
* CREATEDON: 2018-09-26
* OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* 版权所有,请勿删除
******************************************/

Expand Down
7 changes: 6 additions & 1 deletion DncZeus.Api/Entities/DncAuthDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************
* AUTHOR: Rector
* CREATEDON: 2018-09-26
* OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* 版权所有,请勿删除
******************************************/

Expand Down Expand Up @@ -81,6 +81,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
entity.HasIndex(x => x.Code).IsUnique();
});

modelBuilder.Entity<DncMenu>(entity =>
{
//entity.haso
});


modelBuilder.Entity<DncUserRoleMapping>(entity =>
{
Expand Down
2 changes: 1 addition & 1 deletion DncZeus.Api/Entities/DncIcon.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************
* AUTHOR: Rector
* CREATEDON: 2018-11-14
* OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* DESCRIPTION: 图标实体类
******************************************/
using System;
Expand Down
21 changes: 20 additions & 1 deletion DncZeus.Api/Entities/DncMenu.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************
* AUTHOR: Rector
* CREATEDON: 2018-11-13
* OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* DESCRIPTION: 菜单实体类
******************************************/

Expand Down Expand Up @@ -103,6 +103,25 @@ public class DncMenu
/// 最近修改者姓名
/// </summary>
public string ModifiedByUserName { get; set; }
/// <summary>
/// 前端组件(.vue)
/// </summary>
[StringLength(255)]
public string Component { get; set; }

/// <summary>
/// 在菜单中隐藏
/// </summary>
public YesOrNo? HideInMenu { get; set; }
/// <summary>
/// 不缓存页面
/// </summary>
public YesOrNo? NotCache { get; set; }
/// <summary>
/// 页面关闭前的回调函数
/// </summary>
[StringLength(255)]
public string BeforeCloseFun { get; set; }

/// <summary>
/// 菜单拥有的权限列表
Expand Down
2 changes: 1 addition & 1 deletion DncZeus.Api/Entities/DncPermission.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************
* AUTHOR: Rector
* CREATEDON: 2018-09-26
* OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* 版权所有,请勿删除
******************************************/

Expand Down
2 changes: 1 addition & 1 deletion DncZeus.Api/Entities/DncRole.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************
* AUTHOR: Rector
* CREATEDON: 2018-11-06
* OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* DESCRIPTION: 角色实体类
******************************************/
using System;
Expand Down
2 changes: 1 addition & 1 deletion DncZeus.Api/Entities/DncRolePermissionMapping.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************
* AUTHOR: Rector
* CREATEDON: 2018-09-26
* OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core
* 版权所有,请勿删除
******************************************/

Expand Down
Loading

0 comments on commit f1f52cf

Please sign in to comment.