Skip to content

Commit

Permalink
调整租户设置界面租户管理员设置功能,租户信息新增/变更时自动添加租户用户信息表
Browse files Browse the repository at this point in the history
  • Loading branch information
xi3892 committed Sep 1, 2023
1 parent 7fa21a5 commit da234c6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 13 deletions.
51 changes: 51 additions & 0 deletions NewLife.CubeNC/Areas/Admin/Controllers/TenantController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,55 @@ protected override Boolean Valid(Tenant entity, DataObjectMethodType type, Boole

return base.Valid(entity, type, post);
}

/// <summary></summary>
/// <param name="entity"></param>
/// <returns></returns>
protected override Int32 OnInsert(Tenant entity)
{
var result = base.OnInsert(entity);

var tuEntity = TenantUser.FindByTenantIdAndUserId(entity.Id, entity.ManagerId);
tuEntity ??= new TenantUser()
{
TenantId = entity.Id,
UserId = entity.ManagerId
};

tuEntity.Enable = true;
tuEntity.RoleIds = entity.RoleIds;

tuEntity.Save();

return result;
}

/// <summary></summary>
/// <param name="entity"></param>
/// <returns></returns>
protected override Int32 OnUpdate(Tenant entity)
{
var oldTenantEntity = Tenant.FindById(entity.Id);
var tuEntity = TenantUser.FindByTenantIdAndUserId(oldTenantEntity.Id, oldTenantEntity.ManagerId);

if (entity.ManagerId != oldTenantEntity.ManagerId)
{
tuEntity.Enable = false;
tuEntity.Save();
}

var newTuEntity = TenantUser.FindByTenantIdAndUserId(entity.Id, entity.ManagerId);
newTuEntity ??= new TenantUser()
{
TenantId = entity.Id,
UserId = entity.ManagerId
};

newTuEntity.Enable = entity.Enable;
newTuEntity.RoleIds = entity.RoleIds;

newTuEntity.Save();

return base.OnUpdate(entity);
}
}
15 changes: 2 additions & 13 deletions NewLife.CubeNC/Views/layui/_Navbar.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,9 @@

@if (set.EnableTenant && user != null)
{
var tList = TenantUser.FindAllByUserId(user.ID);
// 创建租户或修改租户管理员时,会自动添加租户管理员到租户用户表,所以这里不需要再添加
// var tManager = Tenant.FindByManagerId(user.ID);
// if (tManager != null)
// {
// tList.Add(new TenantUser()
// {
// TenantId = tManager.Id,
// UserId = user.ID
// });
// }
var tList = TenantUser.FindAllByUserId(user.ID).Where(e => e.Tenant.Enable);
var tenant = XCode.Membership.Tenant.FindById(TenantContext.CurrentId);
var tenantName = tenant?.Name;
var tenantName = tenant == null ? null : tenant.Enable ? tenant.Name : null;

<ul class="layui-nav layui-layout-right" style="right:140px;">
<li class="layui-nav-item layui-show-md-inline-block">
Expand Down

0 comments on commit da234c6

Please sign in to comment.