From 6bb2e9eddb49ba45d3831b9615d64d7dff45684c Mon Sep 17 00:00:00 2001 From: tengge1 <930372551@qq.com> Date: Fri, 25 Oct 2019 21:26:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E6=9D=83=E9=99=90=E5=8F=AA=E8=83=BD?= =?UTF-8?q?=E7=9C=8B=E5=88=B0=E8=87=AA=E5=B7=B1=E7=9A=84=E5=8A=A8=E7=94=BB?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AnimationController.cs | 30 +++++++++++++++++-- ShadowEditor.Server/Helpers/ConfigHelper.cs | 26 ++++++++++++++++ .../ShadowEditor.Server.csproj | 1 + 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 ShadowEditor.Server/Helpers/ConfigHelper.cs diff --git a/ShadowEditor.Server/Controllers/AnimationController.cs b/ShadowEditor.Server/Controllers/AnimationController.cs index c0d7957b..5eb8e1be 100644 --- a/ShadowEditor.Server/Controllers/AnimationController.cs +++ b/ShadowEditor.Server/Controllers/AnimationController.cs @@ -35,11 +35,37 @@ namespace ShadowEditor.Server.Controllers var filter = Builders.Filter.Eq("Type", "Animation"); var categories = mongo.FindMany(Constant.CategoryCollectionName, filter).ToList(); - var meshes = mongo.FindAll(Constant.AnimationCollectionName).ToList(); + var docs = new List(); + + if (ConfigHelper.EnableAuthority) + { + var user = UserHelper.GetCurrentUser(); + + if (user != null) + { + var filter1 = Builders.Filter.Eq("UserID", user.ID); + + if (user.Name == "Administrator") + { + var filter2 = Builders.Filter.Exists("UserID"); + var filter3 = Builders.Filter.Not(filter2); + var filter4 = Builders.Filter.Or(filter1, filter3); + docs = mongo.FindMany(Constant.AnimationCollectionName, filter4).ToList(); + } + else + { + docs = mongo.FindMany(Constant.AnimationCollectionName, filter1).ToList(); + } + } + } + else + { + docs = mongo.FindAll(Constant.AnimationCollectionName).ToList(); + } var list = new List(); - foreach (var i in meshes) + foreach (var i in docs) { var categoryID = ""; var categoryName = ""; diff --git a/ShadowEditor.Server/Helpers/ConfigHelper.cs b/ShadowEditor.Server/Helpers/ConfigHelper.cs new file mode 100644 index 00000000..9cce8998 --- /dev/null +++ b/ShadowEditor.Server/Helpers/ConfigHelper.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Configuration; + +namespace ShadowEditor.Server.Helpers +{ + /// + /// 配置管理器 + /// + public sealed class ConfigHelper + { + /// + /// 是否开启权限 + /// + public static bool EnableAuthority + { + get + { + return ConfigurationManager.AppSettings["EnableAuthority"] == "true"; + } + } + } +} diff --git a/ShadowEditor.Server/ShadowEditor.Server.csproj b/ShadowEditor.Server/ShadowEditor.Server.csproj index 3c9287a6..8a937849 100644 --- a/ShadowEditor.Server/ShadowEditor.Server.csproj +++ b/ShadowEditor.Server/ShadowEditor.Server.csproj @@ -131,6 +131,7 @@ +