From ecfd6d6481eaf4014bc53fc4de6614b69da61955 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 26 Mar 2019 17:12:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9BUG=EF=BC=9A=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E6=95=8F=E6=84=9F=E6=95=B0=E6=8D=AE=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=BF=9D=E6=8A=A4=E5=8A=9F=E8=83=BD=20closed?= =?UTF-8?q?=20#ITEI0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #Issue https://gitee.com/LongbowEnterprise/dashboard/issues?id=ITEI0 --- Bootstrap.Admin/BootstrapAdmin.db | Bin 90112 -> 90112 bytes .../Controllers/AccountController.cs | 5 ++++ Bootstrap.Admin/Views/Account/Login.cshtml | 6 ++-- Bootstrap.DataAccess/Dict.cs | 6 ++++ Bootstrap.DataAccess/Helper/DictHelper.cs | 28 ++++++++++++++++++ Bootstrap.DataAccess/Helper/GroupHelper.cs | 3 +- Bootstrap.DataAccess/Helper/MenuHelper.cs | 21 +++++++++++++ Bootstrap.DataAccess/Helper/RoleHelper.cs | 12 ++++++-- Bootstrap.DataAccess/Helper/UserHelper.cs | 19 +++++++++++- DatabaseScripts/InitData.sql | 1 + .../MongoDB/BootstrapAdmin.Dicts.json | 7 +++++ DatabaseScripts/MySQL/initData.sql | 1 + DatabaseScripts/Postgresql/initData.sql | 1 + DatabaseScripts/SQLite/InitData.sql | 1 + UnitTest/DB/UnitTest.db | Bin 90112 -> 90112 bytes 15 files changed, 103 insertions(+), 8 deletions(-) diff --git a/Bootstrap.Admin/BootstrapAdmin.db b/Bootstrap.Admin/BootstrapAdmin.db index 903de3b2ae8da7dabf90a3b81eecfe3e864c2491..4971ced0a372c2c745c82a3d33c8f0681ac9f80d 100644 GIT binary patch delta 74 zcmZoTz}j$tb%HeGw23m#jMFwIEIH4t%+)-Z{emkKSMz2;0aGqTd1W>RRaJhD=bLvw d-#!1ux_!_0u6wp;%JU_=AR-2vm)weJ1pqa0A~gU2 delta 37 vcmV+=0NVe6zy*N71&|v7m604n0hO^}q|XB)3Z#<<&_%Nm5LgPcq}p7C4VMm} diff --git a/Bootstrap.Admin/Controllers/AccountController.cs b/Bootstrap.Admin/Controllers/AccountController.cs index 0aca2d20..d55d294d 100644 --- a/Bootstrap.Admin/Controllers/AccountController.cs +++ b/Bootstrap.Admin/Controllers/AccountController.cs @@ -28,6 +28,11 @@ namespace Bootstrap.Admin.Controllers [HttpGet] public ActionResult Login() { + if (DictHelper.RetrieveSystemModel()) + { + ViewBag.UserName = "Admin"; + ViewBag.Password = "123789"; + } return User.Identity.IsAuthenticated ? (ActionResult)Redirect("~/Home/Index") : View("Login", new ModelBase()); } diff --git a/Bootstrap.Admin/Views/Account/Login.cshtml b/Bootstrap.Admin/Views/Account/Login.cshtml index f4000a6f..c60ab59e 100644 --- a/Bootstrap.Admin/Views/Account/Login.cshtml +++ b/Bootstrap.Admin/Views/Account/Login.cshtml @@ -1,4 +1,4 @@ -@model ModelBase +@model ModelBase @{ ViewBag.Title = Model.Title; Layout = "_Layout"; @@ -52,7 +52,7 @@ - +
@@ -62,7 +62,7 @@
- +
diff --git a/Bootstrap.DataAccess/Dict.cs b/Bootstrap.DataAccess/Dict.cs index 7fe74422..78ef6672 100644 --- a/Bootstrap.DataAccess/Dict.cs +++ b/Bootstrap.DataAccess/Dict.cs @@ -163,5 +163,11 @@ namespace Bootstrap.DataAccess /// /// public int RetrieveAccessLogPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "系统设置" && d.Name == "访问日志保留时长" && d.Define == 0)?.Code, 1); + + /// + /// 获得 是否为演示系统 默认为 false 不是演示系统 + /// + /// + public bool RetrieveSystemModel() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "系统设置" && d.Name == "访问日志保留时长" && d.Define == 0)?.Code, "0") == "1"; } } diff --git a/Bootstrap.DataAccess/Helper/DictHelper.cs b/Bootstrap.DataAccess/Helper/DictHelper.cs index 5ed3bee2..3a4cfae3 100644 --- a/Bootstrap.DataAccess/Helper/DictHelper.cs +++ b/Bootstrap.DataAccess/Helper/DictHelper.cs @@ -2,6 +2,7 @@ using Bootstrap.Security; using Longbow.Cache; using Longbow.Data; using System.Collections.Generic; +using System.Linq; namespace Bootstrap.DataAccess { @@ -36,6 +37,13 @@ namespace Bootstrap.DataAccess /// public static bool Delete(IEnumerable value) { + if (RetrieveSystemModel()) + { + // 允许删除自定义数据字典 + var systemDicts = RetrieveDicts().Where(d => d.Category == "0"); + value = value.Where(v => !systemDicts.Any(d => d.Id == v)); + if (!value.Any()) return true; + } var ret = DbContextManager.Create().Delete(value); CacheCleanUtility.ClearCache(dictIds: value); return ret; @@ -48,6 +56,20 @@ namespace Bootstrap.DataAccess /// public static bool Save(BootstrapDict p) { + if (RetrieveSystemModel()) + { + if (string.IsNullOrEmpty(p.Id)) + { + if (p.Category == "0") p.Category = "1"; + } + else + { + if (RetrieveDicts().Where(m => m.Category == "0").Any(m => m.Id == p.Id)) + { + return true; + } + } + } var ret = DbContextManager.Create().Save(p); if (ret) CacheCleanUtility.ClearCache(dictIds: new List()); return ret; @@ -149,5 +171,11 @@ namespace Bootstrap.DataAccess /// /// public static int RetrieveAccessLogPeriod() => DbContextManager.Create().RetrieveAccessLogPeriod(); + + /// + /// 获得 是否为演示系统 默认为 false 不是演示系统 + /// + /// + public static bool RetrieveSystemModel() => DbContextManager.Create().RetrieveSystemModel(); } } diff --git a/Bootstrap.DataAccess/Helper/GroupHelper.cs b/Bootstrap.DataAccess/Helper/GroupHelper.cs index 6e9262d3..c0b5e018 100644 --- a/Bootstrap.DataAccess/Helper/GroupHelper.cs +++ b/Bootstrap.DataAccess/Helper/GroupHelper.cs @@ -1,4 +1,4 @@ -using Longbow.Cache; +using Longbow.Cache; using Longbow.Data; using System.Collections.Generic; @@ -17,7 +17,6 @@ namespace Bootstrap.DataAccess /// /// 查询所有群组信息 /// - /// /// public static IEnumerable Retrieves() => CacheManager.GetOrAdd(RetrieveGroupsDataKey, key => DbContextManager.Create().Retrieves()); diff --git a/Bootstrap.DataAccess/Helper/MenuHelper.cs b/Bootstrap.DataAccess/Helper/MenuHelper.cs index 95248522..012fd24d 100644 --- a/Bootstrap.DataAccess/Helper/MenuHelper.cs +++ b/Bootstrap.DataAccess/Helper/MenuHelper.cs @@ -31,6 +31,20 @@ namespace Bootstrap.DataAccess /// public static bool Save(BootstrapMenu p) { + if (DictHelper.RetrieveSystemModel()) + { + if (p.Id.IsNullOrEmpty()) + { + if (p.Category == "0") p.Category = "1"; + } + else + { + if (RetrieveAllMenus("Admin").Where(m => m.Category == "0").Any(m => m.Id == p.Id)) + { + return true; + } + } + } var ret = DbContextManager.Create().Save(p); if (ret) CacheCleanUtility.ClearCache(menuIds: string.IsNullOrEmpty(p.Id) ? new List() : new List() { p.Id }); return ret; @@ -43,6 +57,13 @@ namespace Bootstrap.DataAccess /// public static bool Delete(IEnumerable value) { + if (DictHelper.RetrieveSystemModel()) + { + // 允许删除自定义菜单 + var systemMenus = RetrieveAllMenus("Admin").Where(m => m.Category == "0"); + value = value.Where(v => !systemMenus.Any(m => m.Id == v)); + if (!value.Any()) return true; + } var ret = DbContextManager.Create().Delete(value); if (ret) CacheCleanUtility.ClearCache(menuIds: value); return ret; diff --git a/Bootstrap.DataAccess/Helper/RoleHelper.cs b/Bootstrap.DataAccess/Helper/RoleHelper.cs index a3e9ca49..ae22b9a9 100644 --- a/Bootstrap.DataAccess/Helper/RoleHelper.cs +++ b/Bootstrap.DataAccess/Helper/RoleHelper.cs @@ -1,6 +1,8 @@ -using Longbow.Cache; +using Longbow.Cache; using Longbow.Data; +using System; using System.Collections.Generic; +using System.Linq; namespace Bootstrap.DataAccess { @@ -19,7 +21,6 @@ namespace Bootstrap.DataAccess /// /// 查询所有角色 /// - /// /// public static IEnumerable Retrieves() => CacheManager.GetOrAdd(RetrieveRolesDataKey, key => DbContextManager.Create().Retrieves()); @@ -48,6 +49,10 @@ namespace Bootstrap.DataAccess /// public static bool Delete(IEnumerable value) { + var roles = new string[] { "Administrators", "Default" }; + var rs = Retrieves().Where(r => roles.Any(rl => rl.Equals(r.RoleName, StringComparison.OrdinalIgnoreCase))); + value = value.Where(v => !rs.Any(r => r.Id == v)); + if (!value.Any()) return true; var ret = DbContextManager.Create().Delete(value); if (ret) CacheCleanUtility.ClearCache(roleIds: value); return ret; @@ -60,6 +65,9 @@ namespace Bootstrap.DataAccess /// public static bool Save(Role p) { + var roles = new string[] { "Administrators", "Default" }; + var rs = Retrieves().Where(r => roles.Any(rl => rl.Equals(r.RoleName, StringComparison.OrdinalIgnoreCase))); + if (rs.Any(r => r.Id == p.Id)) return true; var ret = DbContextManager.Create().Save(p); if (ret) CacheCleanUtility.ClearCache(roleIds: string.IsNullOrEmpty(p.Id) ? new List() : new List { p.Id }); return ret; diff --git a/Bootstrap.DataAccess/Helper/UserHelper.cs b/Bootstrap.DataAccess/Helper/UserHelper.cs index 9ba2d7ef..69354b06 100644 --- a/Bootstrap.DataAccess/Helper/UserHelper.cs +++ b/Bootstrap.DataAccess/Helper/UserHelper.cs @@ -1,8 +1,9 @@ -using Bootstrap.Security; +using Bootstrap.Security; using Longbow.Cache; using Longbow.Data; using System; using System.Collections.Generic; +using System.Linq; using System.Text.RegularExpressions; namespace Bootstrap.DataAccess @@ -69,6 +70,9 @@ namespace Bootstrap.DataAccess /// public static bool Delete(IEnumerable value) { + var admins = Retrieves().Where(u => u.UserName.Equals("Admin", StringComparison.OrdinalIgnoreCase)); + value = value.Where(v => !admins.Any(u => u.Id == v)); + if (!value.Any()) return true; var ret = DbContextManager.Create().Delete(value); if (ret) CacheCleanUtility.ClearCache(userIds: value); return ret; @@ -95,6 +99,12 @@ namespace Bootstrap.DataAccess public static bool Save(User user) { if (!UserChecker(user)) return false; + + if (DictHelper.RetrieveSystemModel() && !user.Id.IsNullOrEmpty()) + { + var admins = Retrieves().Where(u => u.UserName.Equals("Admin", StringComparison.OrdinalIgnoreCase)); + if (admins.Any(v => v.Id == user.Id)) return true; + } var ret = DbContextManager.Create().Save(user); if (ret) CacheCleanUtility.ClearCache(userIds: string.IsNullOrEmpty(user.Id) ? new List() : new List() { user.Id }); return ret; @@ -110,6 +120,11 @@ namespace Bootstrap.DataAccess public static bool Update(string id, string password, string displayName) { if (!UserChecker(new User { Password = password, DisplayName = displayName })) return false; + if (DictHelper.RetrieveSystemModel()) + { + var admins = Retrieves().Where(u => u.UserName.Equals("Admin", StringComparison.OrdinalIgnoreCase)); + if (admins.Any(v => v.Id == id)) return true; + } var ret = DbContextManager.Create().Update(id, password, displayName); if (ret) CacheCleanUtility.ClearCache(userIds: string.IsNullOrEmpty(id) ? new List() : new List() { id }); return ret; @@ -138,6 +153,7 @@ namespace Bootstrap.DataAccess public static bool ChangePassword(string userName, string password, string newPass) { if (!UserChecker(new User { UserName = userName, Password = password })) return false; + if (DictHelper.RetrieveSystemModel() && userName.Equals("Admin", StringComparison.OrdinalIgnoreCase)) return true; return DbContextManager.Create().ChangePassword(userName, password, newPass); } @@ -150,6 +166,7 @@ namespace Bootstrap.DataAccess public static bool ResetPassword(string userName, string password) { if (!UserChecker(new User { UserName = userName, Password = password })) return false; + if (DictHelper.RetrieveSystemModel() && userName.Equals("Admin", StringComparison.OrdinalIgnoreCase)) return true; return DbContextManager.Create().ResetPassword(userName, password); } diff --git a/DatabaseScripts/InitData.sql b/DatabaseScripts/InitData.sql index becca188..703ecb3f 100644 --- a/DatabaseScripts/InitData.sql +++ b/DatabaseScripts/InitData.sql @@ -41,6 +41,7 @@ INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'系统设 INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'系统设置', N'Cookie保留时长', '7', 0) INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'系统设置', N'获取IP地点', '0', 0) +INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'系统设置', N'演示系统', '0', 0) DELETE FROM Navigations DBCC CHECKIDENT(Navigations, RESEED, 0) diff --git a/DatabaseScripts/MongoDB/BootstrapAdmin.Dicts.json b/DatabaseScripts/MongoDB/BootstrapAdmin.Dicts.json index ed414ab4..ed575e5e 100644 --- a/DatabaseScripts/MongoDB/BootstrapAdmin.Dicts.json +++ b/DatabaseScripts/MongoDB/BootstrapAdmin.Dicts.json @@ -320,5 +320,12 @@ "Name": "访问日志保留时长", "Code": "1", "Define": NumberInt(0) + }, + { + "_id": ObjectId("5bd6c73d5fa31256f77e4a46"), + "Category": "系统设置", + "Name": "演示系统", + "Code": "0", + "Define": NumberInt(0) } ] \ No newline at end of file diff --git a/DatabaseScripts/MySQL/initData.sql b/DatabaseScripts/MySQL/initData.sql index 1293d12d..25e7c815 100644 --- a/DatabaseScripts/MySQL/initData.sql +++ b/DatabaseScripts/MySQL/initData.sql @@ -38,6 +38,7 @@ INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', '访问 INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', 'Cookie保留时长', '7', 0); INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', '获取IP地点', '0', 0); +INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', '演示系统', '0', 0); DELETE FROM Navigations; Truncate Navigations; diff --git a/DatabaseScripts/Postgresql/initData.sql b/DatabaseScripts/Postgresql/initData.sql index c9e9ad9e..71744a87 100644 --- a/DatabaseScripts/Postgresql/initData.sql +++ b/DatabaseScripts/Postgresql/initData.sql @@ -38,6 +38,7 @@ INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', '访问 INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', 'Cookie保留时长', '7', 0); INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', '获取IP地点', '0', 0); +INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', '演示系统', '0', 0); DELETE FROM Navigations; ALTER SEQUENCE navigations_id_seq RESTART WITH 1; diff --git a/DatabaseScripts/SQLite/InitData.sql b/DatabaseScripts/SQLite/InitData.sql index b4ab1298..fd9998dd 100644 --- a/DatabaseScripts/SQLite/InitData.sql +++ b/DatabaseScripts/SQLite/InitData.sql @@ -36,6 +36,7 @@ INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('系统设置 INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('系统设置', 'Cookie保留时长', '7', 0); INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('系统设置', '获取IP地点', '0', 0); +INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('系统设置', '演示系统', '0', 0); DELETE FROM Navigations; INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (0, '后台管理', 10, 'fa fa-gear', '~/Admin/Index', '0'); diff --git a/UnitTest/DB/UnitTest.db b/UnitTest/DB/UnitTest.db index 3ff801be95ede425cd407e4d43dcb1ba63fb17d6..a0df0183814932bb2469f0ccfe9e156ef22590a1 100644 GIT binary patch delta 74 zcmZoTz}j$tb%Hdb+C&*=MzxIzOU^SZb2U$9zu?Nm)x23yz?4f-UYU(SRh6IP`R3iv cch7&ZZr}60>z?hI@_flIh={@FCAVT)0sgTeRR910 delta 37 tcmZoTz}j$tb%Hdb>O>i5M%9f8OU^SZaV?q5e!+FKpg;uI<|VgcS^@Vs4Zr{Z