管理组管理增加控制普通管理组的文章和商品权限,文章、商品操作增加权限判断

This commit is contained in:
2020-11-11 18:15:04 +08:00
parent bfe720fcd1
commit 7f796a5b18
61 changed files with 4531 additions and 7234 deletions
@@ -314,7 +314,20 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
numPerPage = limit;
currentPage = page;
startRowIndex = (currentPage - 1) * numPerPage;
Expression ex = Article._.Id > 0;
Expression ex = new Expression(); ;
Admin my = Admin.GetMyInfo();
List<int> aclist = new List<int>();
if (my.Roles.IsSuperAdmin != 1)
{
aclist = Newtonsoft.Json.JsonConvert.DeserializeObject<List<int>>(string.IsNullOrEmpty(my.Roles.AuthorizedArticleCagegory)?"[]": my.Roles.AuthorizedArticleCagegory);
if (aclist == null) aclist = new List<int>();
if (aclist.Count == 0) aclist.Add(0);
ex &= Article._.KId.In(aclist);
//仅显示有权限内容
if (my.Roles.OnlyEditMyselfArticle == 1)
ex &= Article._.AuthorId == my.Id;
}
if (!string.IsNullOrWhiteSpace(keyword))
{
@@ -401,6 +414,22 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
tip.Message = "静态化文件名错误,请填写正确的,或者留空!";
return Json(tip);
}
Admin my = Admin.GetMyInfo();
List<int> aclist = new List<int>();
if (my.Roles.IsSuperAdmin != 1)
{
aclist = JsonConvert.DeserializeObject<List<int>>(string.IsNullOrEmpty(my.Roles.AuthorizedArticleCagegory) ? "[]" : my.Roles.AuthorizedArticleCagegory);
if (aclist == null) aclist = new List<int>();
if (aclist.Count == 0) aclist.Add(0);
if (aclist.FindIndex(x => x == model.KId) == -1)
{
tip.Message = "当前选择栏目不存在,或者您没这个栏目的权限!";
return Json(tip);
}
}
//处理文章更多图片
string[] moreImgSrc = Request.Form["nImgUrl"];
string morIMG = string.Empty;//更多图片的时候用到
@@ -421,7 +450,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
model.Content = content;
}
model.ItemImg = morIMG;
model.AuthorId = Core.Admin.GetMyInfo().Id;
model.AuthorId = my.Id;
model.Insert();
ArticleCategory.UpdateDetailCount(model.KId);
SessionHelper.WriteSession("com_add_article_kid", model.KId);
@@ -490,6 +519,28 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
tip.Message = "静态化文件名错误,请填写正确的,或者留空!";
return Json(tip);
}
Admin my = Admin.GetMyInfo();
List<int> aclist = new List<int>();
if (my.Roles.IsSuperAdmin != 1)
{
aclist = JsonConvert.DeserializeObject<List<int>>(string.IsNullOrEmpty(my.Roles.AuthorizedArticleCagegory) ? "[]" : my.Roles.AuthorizedArticleCagegory);
if (aclist == null) aclist = new List<int>();
if (aclist.Count == 0) aclist.Add(0);
if (aclist.FindIndex(x => x == model.KId) == -1)
{
tip.Message = "当前选择栏目不存在,或者您没这个栏目的权限!";
return Json(tip);
}
if(my.Roles.OnlyEditMyselfArticle ==1 && entity.AuthorId != my.Id)
{
tip.Message = "系统限制,您无法编辑非自己添加的文章!";
return Json(tip);
}
}
//处理文章更多图片
string[] moreImgSrc = Request.Form["nImgUrl"];
string morIMG = string.Empty;//更多图片的时候用到
@@ -580,6 +631,28 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
tip.Message = "系统找不到本文章!";
return Json(tip);
}
Admin my = Admin.GetMyInfo();
List<int> aclist = new List<int>();
if (my.Roles.IsSuperAdmin != 1)
{
aclist = JsonConvert.DeserializeObject<List<int>>(string.IsNullOrEmpty(my.Roles.AuthorizedArticleCagegory) ? "[]" : my.Roles.AuthorizedArticleCagegory);
if (aclist == null) aclist = new List<int>();
if (aclist.Count == 0) aclist.Add(0);
if (aclist.FindIndex(x => x == entity.KId) == -1)
{
tip.Message = "者您没这个栏目的权限,无法删除该栏目文章!";
return Json(tip);
}
if (my.Roles.OnlyEditMyselfArticle == 1 && entity.AuthorId != my.Id)
{
tip.Message = "系统限制,您无法删除非自己添加的文章!";
return Json(tip);
}
}
int kid = entity.Id;
//删除TAG
//Tag.DeleteTag(RTType.RatuoModule.Article, entity.Id);
@@ -131,7 +131,14 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
//获取所有的菜单列表
IList<AdminMenu> list = AdminMenu.GetListTree(0, -1, false, false);
ViewBag.MenuList = list;
Core.Admin.WriteLogActions("查看添加管理页面;");
//获取所有文章 商品栏目
IList<ArticleCategory> aclist = ArticleCategory.GetListTree(0, -1, true, true);
ViewBag.aclist = aclist;
IList<Category> pclist = Category.GetListTree(0, -1, true, true);
ViewBag.pclist = pclist;
Core.Admin.WriteLogActions("查看添加管理组页面;");
return View();
}
//执行添加管理组
@@ -143,6 +150,13 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
string RoleDescription = fc["RoleDescription"];
string IsSuperAdmin = fc["IsSuperAdmin"];
string NotAllowDel = fc["NotAllowDel"];
string OnlyEditMyselfArticle = fc["OnlyEditMyselfArticle"];
string OnlyEditMyselfProduct = fc["OnlyEditMyselfProduct"];
if (string.IsNullOrEmpty(OnlyEditMyselfArticle) || !Utils.IsInt(OnlyEditMyselfProduct)) OnlyEditMyselfProduct = "0";
if (string.IsNullOrEmpty(OnlyEditMyselfProduct) || !Utils.IsInt(OnlyEditMyselfProduct)) OnlyEditMyselfProduct = "0";
if (string.IsNullOrEmpty(RoleName))
{
tip.Message = "管理组名称不能为空!";
@@ -155,6 +169,8 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
entity.RoleDescription = RoleDescription;
entity.IsSuperAdmin = int.Parse(IsSuperAdmin);
entity.NotAllowDel = !string.IsNullOrEmpty(NotAllowDel) && NotAllowDel == "1" ? 1 : 0;
entity.OnlyEditMyselfArticle = int.Parse(OnlyEditMyselfArticle);
entity.OnlyEditMyselfProduct = int.Parse(OnlyEditMyselfProduct);
//处理权限
if (entity.IsSuperAdmin == 1)
@@ -208,6 +224,30 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
}
}
//处理文章和商品栏目权限
string[] acpower = Request.Form["acpower"];
string[] pcpower = Request.Form["pcpower"];
List<int> acids = new List<int>();
List<int> pcids = new List<int>();
foreach (var item in acpower)
{
if (!string.IsNullOrEmpty(item) && Utils.IsInt(item))
{
acids.Add(int.Parse(item));
}
}
foreach (var item in pcpower)
{
if (!string.IsNullOrEmpty(item) && Utils.IsInt(item))
{
pcids.Add(int.Parse(item));
}
}
entity.AuthorizedArticleCagegory = JsonConvert.SerializeObject(acids);
entity.AuthorizedCagegory = JsonConvert.SerializeObject(pcids);
entity.Insert();
tip.Status = JsonTip.SUCCESS;
tip.Message = "添加管理组成功";
@@ -230,8 +270,20 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
entity.Powers = "[]";
if (string.IsNullOrEmpty(entity.Menus))
entity.Menus = "[]";
if (string.IsNullOrEmpty(entity.AuthorizedArticleCagegory))
entity.AuthorizedArticleCagegory = "[]";
if (string.IsNullOrEmpty(entity.AuthorizedCagegory))
entity.AuthorizedCagegory = "[]";
//获取所有的菜单列表
IList<AdminMenu> list = AdminMenu.GetListTree(0, -1, false, false);
//获取所有文章 商品栏目
IList<ArticleCategory> aclist = ArticleCategory.GetListTree(0, -1, true, true);
ViewBag.aclist = aclist;
IList<Category> pclist = Category.GetListTree(0, -1, true, true);
ViewBag.pclist = pclist;
ViewBag.MenuList = list;
Core.Admin.WriteLogActions($"查看管理组({id})详情;");
return View(entity);
@@ -246,6 +298,12 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
string RoleDescription = fc["RoleDescription"];
string IsSuperAdmin = fc["IsSuperAdmin"];
string NotAllowDel = fc["NotAllowDel"];
string OnlyEditMyselfArticle = fc["OnlyEditMyselfArticle"];
string OnlyEditMyselfProduct = fc["OnlyEditMyselfProduct"];
if (string.IsNullOrEmpty(OnlyEditMyselfArticle) || !Utils.IsInt(OnlyEditMyselfProduct)) OnlyEditMyselfProduct = "0";
if (string.IsNullOrEmpty(OnlyEditMyselfProduct) || !Utils.IsInt(OnlyEditMyselfProduct)) OnlyEditMyselfProduct = "0";
if (string.IsNullOrEmpty(Id))
{
tip.Message = "错误参数传递!";
@@ -268,6 +326,8 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
entity.RoleDescription = RoleDescription;
entity.IsSuperAdmin = int.Parse(IsSuperAdmin);
entity.NotAllowDel = !string.IsNullOrEmpty(NotAllowDel) && NotAllowDel == "1" ? 1 : 0;
entity.OnlyEditMyselfArticle = int.Parse(OnlyEditMyselfArticle);
entity.OnlyEditMyselfProduct = int.Parse(OnlyEditMyselfProduct);
//处理权限
if (entity.IsSuperAdmin == 1)
@@ -320,6 +380,31 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
}
}
}
//处理文章和商品栏目权限
string[] acpower = Request.Form["acpower"];
string[] pcpower = Request.Form["pcpower"];
List<int> acids = new List<int>();
List<int> pcids = new List<int>();
foreach (var item in acpower)
{
if (!string.IsNullOrEmpty(item) && Utils.IsInt(item))
{
acids.Add(int.Parse(item));
}
}
foreach (var item in pcpower)
{
if (!string.IsNullOrEmpty(item) && Utils.IsInt(item))
{
pcids.Add(int.Parse(item));
}
}
entity.AuthorizedArticleCagegory = JsonConvert.SerializeObject(acids);
entity.AuthorizedCagegory = JsonConvert.SerializeObject(pcids);
entity.Update();
tip.Status = JsonTip.SUCCESS;
tip.Message = "编辑管理组详情成功";
@@ -208,7 +208,20 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
numPerPage = limit;
currentPage = page;
startRowIndex = (currentPage - 1) * numPerPage;
Expression ex = Product._.Id > 0;
Expression ex = new Expression();
Admin my = Admin.GetMyInfo();
List<int> aclist = new List<int>();
if (my.Roles.IsSuperAdmin != 1)
{
aclist = JsonConvert.DeserializeObject<List<int>>(string.IsNullOrEmpty(my.Roles.AuthorizedCagegory) ? "[]" : my.Roles.AuthorizedCagegory);
if (aclist == null) aclist = new List<int>();
if (aclist.Count == 0) aclist.Add(0);
ex &= Product._.KId.In(aclist);
//仅显示有权限内容
if (my.Roles.OnlyEditMyselfProduct == 1)
ex &= Product._.AuthorId == my.Id;
}
if (!string.IsNullOrWhiteSpace(keyword))
{
@@ -292,6 +305,22 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
tip.Message = "商品图片填写的不是图片格式!";
return Json(tip);
}
Admin my = Admin.GetMyInfo();
List<int> aclist = new List<int>();
if (my.Roles.IsSuperAdmin != 1)
{
aclist = JsonConvert.DeserializeObject<List<int>>(string.IsNullOrEmpty(my.Roles.AuthorizedCagegory)?"[]": my.Roles.AuthorizedCagegory);
if (aclist == null) aclist = new List<int>();
if (aclist.Count == 0) aclist.Add(0);
if (aclist.FindIndex(x => x == model.KId) == -1)
{
tip.Message = "当前选择栏目不存在,或者您没这个栏目的权限!";
return Json(tip);
}
}
//处理商品更多图片
string[] moreImgSrc = Request.Form["nImgUrl"];
string morIMG = string.Empty;//更多图片的时候用到
@@ -312,7 +341,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
model.Content = content;
}
model.ItemImg = morIMG;
model.AuthorId = Core.Admin.GetMyInfo().Id;
model.AuthorId = my.Id;
model.Insert();
Category.UpdateDetailCount(model.KId);
//添加TAG
@@ -381,6 +410,28 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
tip.Message = "商品图片填写的不是图片格式!";
return Json(tip);
}
Admin my = Admin.GetMyInfo();
List<int> aclist = new List<int>();
if (my.Roles.IsSuperAdmin != 1)
{
aclist = JsonConvert.DeserializeObject<List<int>>(string.IsNullOrEmpty(my.Roles.AuthorizedCagegory) ? "[]" : my.Roles.AuthorizedCagegory);
if (aclist == null) aclist = new List<int>();
if (aclist.Count == 0) aclist.Add(0);
if (aclist.FindIndex(x => x == model.KId) == -1)
{
tip.Message = "当前选择栏目不存在,或者您没这个栏目的权限!";
return Json(tip);
}
if (my.Roles.OnlyEditMyselfProduct == 1 && entity.AuthorId != my.Id)
{
tip.Message = "系统限制,您无法编辑非自己添加的商品!";
return Json(tip);
}
}
//处理商品更多图片
string[] moreImgSrc = Request.Form["nImgUrl"];
string morIMG = string.Empty;//更多图片的时候用到
@@ -439,6 +490,28 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
tip.Message = "系统找不到本商品!";
return Json(tip);
}
Admin my = Admin.GetMyInfo();
List<int> aclist = new List<int>();
if (my.Roles.IsSuperAdmin != 1)
{
aclist = JsonConvert.DeserializeObject<List<int>>(string.IsNullOrEmpty(my.Roles.AuthorizedCagegory) ? "[]" : my.Roles.AuthorizedCagegory);
if (aclist == null) aclist = new List<int>();
if (aclist.Count == 0) aclist.Add(0);
if (aclist.FindIndex(x => x == entity.KId) == -1)
{
tip.Message = "者您没这个栏目的权限,无法删除该栏目商品!";
return Json(tip);
}
if (my.Roles.OnlyEditMyselfArticle == 1 && entity.AuthorId != my.Id)
{
tip.Message = "系统限制,您无法删除非自己添加的商品!";
return Json(tip);
}
}
int kid = entity.KId;
//删除TAG
//Tag.DeleteTag(RTType.RatuoModule.Article, entity.Id);