Skip to content

Commit

Permalink
根据多租户开关,控制多租户菜单是否显示
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Nov 8, 2023
1 parent baf4a26 commit 866c10c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions CubeDemoNC/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
//app.UseMetronic8(env);
//app.UseLayuiAdmin(env);
//app.UseBlazor(env);
app.UseCubeHome();

app.UseAuthorization();

Expand Down
19 changes: 19 additions & 0 deletions NewLife.Cube/Web/WebHelper2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using NewLife.Cube.Extensions;
using NewLife.Serialization;
using XCode;
using XCode.Membership;

namespace NewLife.Cube;

Expand Down Expand Up @@ -143,4 +144,22 @@ public static String GetLinuxName()
/// <returns></returns>
public static String GetReferer(this HttpRequest request) => request.Headers["Referer"].FirstOrDefault();
#endregion

/// <summary>修正多租户菜单</summary>
public static void FixTenantMenu()
{
var root = Menu.FindByName("Admin");
if (root != null)
{
var set = CubeSetting.Current;
foreach (var item in root.Childs)
{
if (item.Name.Contains("Tenant"))
{
item.Visible = set.EnableTenant;
item.Update();
}
}
}
}
}
12 changes: 12 additions & 0 deletions NewLife.CubeNC/Areas/Admin/Controllers/CubeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,16 @@ public override void OnActionExecuting(ActionExecutingContext filterContext)
/// <returns></returns>
[AllowAnonymous]
public ActionResult GetLoginConfig() => Ok(data: new LoginConfigModel());

/// <summary>更新时触发</summary>
/// <param name="obj"></param>
/// <returns></returns>
public override ActionResult Update(CubeSetting obj)
{
var rs = base.Update(obj);

WebHelper2.FixTenantMenu();

return rs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace NewLife.Cube.Admin.Controllers;
/// <summary>字典参数</summary>
[DisplayName("字典参数")]
[Area("Admin")]
[Menu(30, false, Icon = "fa-wrench")]
[Menu(30, true, Icon = "fa-wrench")]
public class ParameterController : EntityController<Parameter, ParameterModel>
{
static ParameterController()
Expand Down
2 changes: 2 additions & 0 deletions NewLife.CubeNC/CubeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Stardust;
using Stardust.Registry;
using XCode.DataAccessLayer;
using XCode.Membership;

namespace NewLife.Cube;

Expand Down Expand Up @@ -296,6 +297,7 @@ public static IApplicationBuilder UseCube(this IApplicationBuilder app, IWebHost
// 调整魔方表名
FixAppTableName();
FixAvatar();
WebHelper2.FixTenantMenu();

// 使用管理提供者
app.UseManagerProvider();
Expand Down

0 comments on commit 866c10c

Please sign in to comment.