未启用多租户时,不要操作租户相关表
This commit is contained in:
parent
9df6dfaa35
commit
231a8b413f
|
@ -218,18 +218,32 @@ public class ReadOnlyEntityController<TEntity> : ControllerBaseX where TEntity :
|
|||
}
|
||||
|
||||
// 多租户
|
||||
var ctxTenant = TenantContext.Current;
|
||||
if (ctxTenant != null && IsTenantSource)
|
||||
var set = CubeSetting.Current;
|
||||
if (set.EnableTenant)
|
||||
{
|
||||
var tenant = Tenant.FindById(ctxTenant.TenantId);
|
||||
if (tenant != null)
|
||||
var ctxTenant = TenantContext.Current;
|
||||
if (ctxTenant != null && IsTenantSource)
|
||||
{
|
||||
HttpContext.Items["TenantId"] = tenant.Id;
|
||||
var tenant = Tenant.FindById(ctxTenant.TenantId);
|
||||
if (tenant != null)
|
||||
{
|
||||
HttpContext.Items["TenantId"] = tenant.Id;
|
||||
|
||||
if (!exp.IsNullOrEmpty())
|
||||
exp = "TenantId={#TenantId} and " + exp;
|
||||
else
|
||||
exp = "TenantId={#TenantId}";
|
||||
if (typeof(TEntity) == typeof(Tenant))
|
||||
{
|
||||
if (!exp.IsNullOrEmpty())
|
||||
exp = "Id={#TenantId} and " + exp;
|
||||
else
|
||||
exp = "Id={#TenantId}";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!exp.IsNullOrEmpty())
|
||||
exp = "TenantId={#TenantId} and " + exp;
|
||||
else
|
||||
exp = "TenantId={#TenantId}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,8 +47,9 @@ public class IndexController : ControllerBaseX
|
|||
ViewBag.Config = SysConfig.Current;
|
||||
|
||||
//!!! 租户切换
|
||||
var set = CubeSetting.Current;
|
||||
var tenantId = Request.Query["TenantId"].ToInt(-1);
|
||||
if (tenantId >= 0)
|
||||
if (tenantId >= 0 && set.EnableTenant)
|
||||
{
|
||||
// 判断租户关系
|
||||
var list = TenantUser.FindAllByUserId(user.ID);
|
||||
|
|
|
@ -232,27 +232,31 @@ public class ReadOnlyEntityController<TEntity> : ControllerBaseX where TEntity :
|
|||
}
|
||||
|
||||
// 多租户
|
||||
var ctxTenant = TenantContext.Current;
|
||||
if (ctxTenant != null && IsTenantSource)
|
||||
var set = CubeSetting.Current;
|
||||
if (set.EnableTenant)
|
||||
{
|
||||
var tenant = Tenant.FindById(ctxTenant.TenantId);
|
||||
if (tenant != null)
|
||||
var ctxTenant = TenantContext.Current;
|
||||
if (ctxTenant != null && IsTenantSource)
|
||||
{
|
||||
HttpContext.Items["TenantId"] = tenant.Id;
|
||||
var tenant = Tenant.FindById(ctxTenant.TenantId);
|
||||
if (tenant != null)
|
||||
{
|
||||
HttpContext.Items["TenantId"] = tenant.Id;
|
||||
|
||||
if (typeof(TEntity) == typeof(Tenant))
|
||||
{
|
||||
if (!exp.IsNullOrEmpty())
|
||||
exp = "Id={#TenantId} and " + exp;
|
||||
if (typeof(TEntity) == typeof(Tenant))
|
||||
{
|
||||
if (!exp.IsNullOrEmpty())
|
||||
exp = "Id={#TenantId} and " + exp;
|
||||
else
|
||||
exp = "Id={#TenantId}";
|
||||
}
|
||||
else
|
||||
exp = "Id={#TenantId}";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!exp.IsNullOrEmpty())
|
||||
exp = "TenantId={#TenantId} and " + exp;
|
||||
else
|
||||
exp = "TenantId={#TenantId}";
|
||||
{
|
||||
if (!exp.IsNullOrEmpty())
|
||||
exp = "TenantId={#TenantId} and " + exp;
|
||||
else
|
||||
exp = "TenantId={#TenantId}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,6 +73,9 @@ public static class ManagerProviderHelper
|
|||
/// <param name="userId"></param>
|
||||
public static void ChooseTenant(this HttpContext context, Int32 userId)
|
||||
{
|
||||
var set = CubeSetting.Current;
|
||||
if (!set.EnableTenant) return;
|
||||
|
||||
/*
|
||||
* 用户登录后的租户选择逻辑:
|
||||
* 已选租户且有效
|
||||
|
|
|
@ -21,7 +21,8 @@ public class TenantMiddleware
|
|||
var changed = false;
|
||||
try
|
||||
{
|
||||
if (TenantContext.Current == null)
|
||||
var set = CubeSetting.Current;
|
||||
if (set.EnableTenant && TenantContext.Current == null)
|
||||
{
|
||||
var tenantId = ctx.GetTenantId();
|
||||
if (tenantId > 0)
|
||||
|
|
Loading…
Reference in New Issue