Skip to content

Commit

Permalink
[feat]角色表新增租户字段,部分业务场景需要允许租户设置自己的角色。NewLifeX/NewLife.Cube#97
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Nov 24, 2024
1 parent 30a8942 commit 39ae469
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
3 changes: 3 additions & 0 deletions XCode/Membership/Interfaces/IRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public partial interface IRole
/// <summary>系统。用于业务系统开发使用,不受数据权限约束,禁止修改名称或删除</summary>
Boolean IsSystem { get; set; }

/// <summary>租户。角色所属组合,0表示全局角色</summary>
Int32 TenantId { get; set; }

/// <summary>权限。对不同资源的权限,逗号分隔,每个资源的权限子项竖线分隔</summary>
String? Permission { get; set; }

Expand Down
1 change: 1 addition & 0 deletions XCode/Membership/Member.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<Column Name="Name" DataType="String" Master="True" Nullable="False" Description="名称" />
<Column Name="Enable" DataType="Boolean" Description="启用" />
<Column Name="IsSystem" DataType="Boolean" Description="系统。用于业务系统开发使用,不受数据权限约束,禁止修改名称或删除" />
<Column Name="TenantId" DataType="Int32" Map="Tenant@Id@$" Description="租户。角色所属组合,0表示全局角色" />
<Column Name="Permission" DataType="String" Length="-1" Description="权限。对不同资源的权限,逗号分隔,每个资源的权限子项竖线分隔" />
<Column Name="Sort" DataType="Int32" Description="排序" />
<Column Name="Ex1" DataType="Int32" Description="扩展1" Category="扩展" />
Expand Down
11 changes: 11 additions & 0 deletions XCode/Membership/Membership.htm
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,17 @@ <h3>角色(Role)</h3>
<td>用于业务系统开发使用,不受数据权限约束,禁止修改名称或删除</td>
</tr>

<tr>
<td>TenantId</td>
<td>租户</td>
<td>Int32</td>
<td></td>
<td></td>
<td></td>
<td>N</td>
<td>角色所属组合,0表示全局角色</td>
</tr>

<tr>
<td>Permission</td>
<td>权限</td>
Expand Down
6 changes: 6 additions & 0 deletions XCode/Membership/Models/RoleModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public partial class RoleModel : IModel
/// <summary>系统。用于业务系统开发使用,不受数据权限约束,禁止修改名称或删除</summary>
public Boolean IsSystem { get; set; }

/// <summary>租户。角色所属组合,0表示全局角色</summary>
public Int32 TenantId { get; set; }

/// <summary>权限。对不同资源的权限,逗号分隔,每个资源的权限子项竖线分隔</summary>
public String? Permission { get; set; }

Expand Down Expand Up @@ -91,6 +94,7 @@ public virtual Object? this[String name]
"Name" => Name,
"Enable" => Enable,
"IsSystem" => IsSystem,
"TenantId" => TenantId,
"Permission" => Permission,
"Sort" => Sort,
"Ex1" => Ex1,
Expand Down Expand Up @@ -119,6 +123,7 @@ public virtual Object? this[String name]
case "Name": Name = Convert.ToString(value); break;
case "Enable": Enable = value.ToBoolean(); break;
case "IsSystem": IsSystem = value.ToBoolean(); break;
case "TenantId": TenantId = value.ToInt(); break;
case "Permission": Permission = Convert.ToString(value); break;
case "Sort": Sort = value.ToInt(); break;
case "Ex1": Ex1 = value.ToInt(); break;
Expand Down Expand Up @@ -151,6 +156,7 @@ public void Copy(IRole model)
Name = model.Name;
Enable = model.Enable;
IsSystem = model.IsSystem;
TenantId = model.TenantId;
Permission = model.Permission;
Sort = model.Sort;
Ex1 = model.Ex1;
Expand Down
2 changes: 1 addition & 1 deletion XCode/Membership/角色.Biz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace XCode.Membership;

/// <summary>角色</summary>
public partial class Role : LogEntity<Role>, IRole
public partial class Role : LogEntity<Role>, IRole, ITenantSource
{
#region 对象操作

Expand Down
25 changes: 25 additions & 0 deletions XCode/Membership/角色.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public partial class Role : IRole, IEntity<IRole>
[BindColumn("IsSystem", "系统。用于业务系统开发使用,不受数据权限约束,禁止修改名称或删除", "")]
public Boolean IsSystem { get => _IsSystem; set { if (OnPropertyChanging("IsSystem", value)) { _IsSystem = value; OnPropertyChanged("IsSystem"); } } }

private Int32 _TenantId;
/// <summary>租户。角色所属组合,0表示全局角色</summary>
[DisplayName("租户")]
[Description("租户。角色所属组合,0表示全局角色")]
[DataObjectField(false, false, false, 0)]
[BindColumn("TenantId", "租户。角色所属组合,0表示全局角色", "")]
public Int32 TenantId { get => _TenantId; set { if (OnPropertyChanging("TenantId", value)) { _TenantId = value; OnPropertyChanged("TenantId"); } } }

private String? _Permission;
/// <summary>权限。对不同资源的权限,逗号分隔,每个资源的权限子项竖线分隔</summary>
[DisplayName("权限")]
Expand Down Expand Up @@ -215,6 +223,7 @@ public void Copy(IRole model)
Name = model.Name;
Enable = model.Enable;
IsSystem = model.IsSystem;
TenantId = model.TenantId;
Permission = model.Permission;
Sort = model.Sort;
Ex1 = model.Ex1;
Expand Down Expand Up @@ -247,6 +256,7 @@ public override Object? this[String name]
"Name" => _Name,
"Enable" => _Enable,
"IsSystem" => _IsSystem,
"TenantId" => _TenantId,
"Permission" => _Permission,
"Sort" => _Sort,
"Ex1" => _Ex1,
Expand Down Expand Up @@ -274,6 +284,7 @@ public override Object? this[String name]
case "Name": _Name = Convert.ToString(value); break;
case "Enable": _Enable = value.ToBoolean(); break;
case "IsSystem": _IsSystem = value.ToBoolean(); break;
case "TenantId": _TenantId = value.ToInt(); break;
case "Permission": _Permission = Convert.ToString(value); break;
case "Sort": _Sort = value.ToInt(); break;
case "Ex1": _Ex1 = value.ToInt(); break;
Expand All @@ -298,6 +309,14 @@ public override Object? this[String name]
#endregion

#region 关联映射
/// <summary>租户</summary>
[XmlIgnore, IgnoreDataMember, ScriptIgnore]
public Tenant? Tenant => Extends.Get(nameof(Tenant), k => Tenant.FindById(TenantId));

/// <summary>租户</summary>
[Map(nameof(TenantId), typeof(Tenant), "Id")]
public String? TenantName => Tenant?.ToString();

#endregion

#region 扩展查询
Expand All @@ -319,6 +338,9 @@ public partial class _
/// <summary>系统。用于业务系统开发使用,不受数据权限约束,禁止修改名称或删除</summary>
public static readonly Field IsSystem = FindByName("IsSystem");

/// <summary>租户。角色所属组合,0表示全局角色</summary>
public static readonly Field TenantId = FindByName("TenantId");

/// <summary>权限。对不同资源的权限,逗号分隔,每个资源的权限子项竖线分隔</summary>
public static readonly Field Permission = FindByName("Permission");

Expand Down Expand Up @@ -388,6 +410,9 @@ public partial class __
/// <summary>系统。用于业务系统开发使用,不受数据权限约束,禁止修改名称或删除</summary>
public const String IsSystem = "IsSystem";

/// <summary>租户。角色所属组合,0表示全局角色</summary>
public const String TenantId = "TenantId";

/// <summary>权限。对不同资源的权限,逗号分隔,每个资源的权限子项竖线分隔</summary>
public const String Permission = "Permission";

Expand Down

0 comments on commit 39ae469

Please sign in to comment.