diff --git a/CellTypes/CascaderCellType.cs b/CellTypes/CascaderCellType.cs index b40f8f322f5a72611964fd852414f6b24257eb96..e28e48f31a252b2b4899af891c7cd3b12b5a146e 100644 --- a/CellTypes/CascaderCellType.cs +++ b/CellTypes/CascaderCellType.cs @@ -302,7 +302,7 @@ namespace ElementUI } - public class TreeNodeBase : ITreeNode, ICloneable where T : ITreeNode + public class TreeNodeBase : ObjectPropertyBase, ITreeNode where T : ITreeNode { [SRDisplayName(nameof(Resources.CascaderCellType_value))] [Required] @@ -347,11 +347,6 @@ namespace ElementUI children = value.OfType().ToList(); } } - - public object Clone() - { - return PluginUtilities.CommonClone(this); - } } internal class ParentAndLabel diff --git a/CellTypes/NavMenuCellType.cs b/CellTypes/NavMenuCellType.cs index e3ffc78c6020edb809ec2bab6a9fa5078c7ba21c..4d86e984b340b21672dd2c06495edd905897bef9 100644 --- a/CellTypes/NavMenuCellType.cs +++ b/CellTypes/NavMenuCellType.cs @@ -78,13 +78,30 @@ namespace ElementUI public class MenuNodeDesigner : ObjectDesigner { - public override EditorSetting GetEditorSetting(PropertyDescriptor property, IBuilderContextBase contextBase) + public override bool GetDesignerPropertyVisible(string propertyName, IBuilderContextBase contextBase) + { + if (propertyName == nameof(MenuNode.CanVisitRoleList)) + { + return contextBase.PermissionMode == PermissionMode.Role; + } + if (propertyName == nameof(MenuNode.CanVisitPermissionGroupList)) + { + return contextBase.PermissionMode == PermissionMode.PermissionGroup; + } + return base.GetDesignerPropertyVisible(propertyName, contextBase); + } + + public override EditorSetting GetEditorSetting(PropertyDescriptor property, IBuilderContextBase contextBase) { if (property.Name == nameof(MenuNode.CanVisitRoleList)) { return new RolePermissionEditorSetting(); } - return base.GetEditorSetting(property, contextBase); + if (property.Name == nameof(MenuNode.CanVisitPermissionGroupList)) + { + return new PermissionGroupEditorSetting(); + } + return base.GetEditorSetting(property, contextBase); } } @@ -232,6 +249,7 @@ namespace ElementUI Enabled = true, Ignore = true, AllowRoles = new List() { DefaultRoleManager.FGC_Anonymous }, + AllowPermissionGroups = ["-2"], Children = GetSubUIPermisison(this.options.OfType().ToList()) }; @@ -272,10 +290,16 @@ namespace ElementUI var allowRoles = permission.AllowRoles; if (allowRoles != null) { - item.CanVisitRoleList.AddRange(allowRoles.Select(r => r)); + item.CanVisitRoleList.AddRange(allowRoles); } - - SetSubUIPermission(item.children, permission.Children); + item.CanVisitPermissionGroupList.Clear(); + var allowPermissionGroup = permission.AllowPermissionGroups; + if (allowPermissionGroup != null) + { + item.CanVisitPermissionGroupList.AddRange(allowPermissionGroup); + } + + SetSubUIPermission(item.children, permission.Children); } } @@ -287,7 +311,8 @@ namespace ElementUI var itemPermission = new SubUIPermission() { Name = item.label, - AllowRoles = item.CanVisitRoleList.Select(r => r).ToList() + AllowRoles = item.CanVisitRoleList.Select(r => r).ToList(), + AllowPermissionGroups = item.CanVisitPermissionGroupList.Select(r => r).ToList() }; if (item.children?.Any() == true) @@ -489,7 +514,8 @@ namespace ElementUI { DefaultRoleManager.FGC_Anonymous }; - } + CanVisitPermissionGroupList = ["-2"]; + } public override string value { get => base.value; set => base.value = value; } [TextProperty(CanSelectResource = true)] @@ -537,7 +563,38 @@ namespace ElementUI } } - [SRDisplayName(nameof(Resources.NavMenuCellType_expend))] + + private List _canVisitPermissionGroupList; + + [PageMetadataJsonIgnore] + [SRDisplayName(nameof(Resources.Permission))] + [JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Replace)] + [DiffRoleList] + public List CanVisitPermissionGroupList + { + get + { + if (_canVisitPermissionGroupList == null) + { + _canVisitPermissionGroupList = new List(); + } + + return _canVisitPermissionGroupList; + } + set + { + if (value == null) + { + _canVisitPermissionGroupList = ["-2"]; + } + else + { + _canVisitPermissionGroupList = value; + } + } + } + + [SRDisplayName(nameof(Resources.NavMenuCellType_expend))] public bool expend { get; set; } } diff --git a/CellTypes/TableCellType.cs b/CellTypes/TableCellType.cs index 8c2916513786e4165897e1ac036dae907bb25b6e..e729e54a99c331851cc765a361d4a6431886ba2d 100644 --- a/CellTypes/TableCellType.cs +++ b/CellTypes/TableCellType.cs @@ -471,6 +471,7 @@ namespace ElementUI Enabled = true, Ignore = true, AllowRoles = new List() { DefaultRoleManager.FGC_Anonymous }, + AllowPermissionGroups = ["-2"], Children = GetSubUIPermisison() }; @@ -503,6 +504,7 @@ namespace ElementUI if (dic.TryGetValue(item.label, out var permission)) { item.allowRoles = permission.AllowRoles; + item.allowPermissionGroups = permission.AllowPermissionGroups; } } } @@ -513,7 +515,8 @@ namespace ElementUI if (dic.TryGetValue(item.Name, out var permission)) { item.allowRoles = permission.AllowRoles; - } + item.allowPermissionGroups = permission.AllowPermissionGroups; + } } } } @@ -526,15 +529,17 @@ namespace ElementUI subUIPermissions = subUIPermissions.Union(columns.OfType().Select(i => new SubUIPermission() { Name = i.label, - AllowRoles = i.allowRoles - })).ToList(); + AllowRoles = i.allowRoles, + AllowPermissionGroups = i.allowPermissionGroups + })).ToList(); } if (this.showActionButtons && this.actionButtons?.Count > 0) { subUIPermissions = subUIPermissions.Union(actionButtons.OfType().Select(i => new SubUIPermission() { Name = i.Name, - AllowRoles = i.allowRoles + AllowRoles = i.allowRoles, + AllowPermissionGroups = i.allowPermissionGroups })).ToList(); } var hashSet = new HashSet(); @@ -736,7 +741,20 @@ namespace ElementUI } } } - } + + public override bool GetDesignerPropertyVisible(string propertyName, IBuilderContextBase contextBase) + { + if (propertyName == nameof(ColumnSetting.allowRoles)) + { + return contextBase.PermissionMode == PermissionMode.Role; + } + if (propertyName == nameof(ColumnSetting.allowPermissionGroups)) + { + return contextBase.PermissionMode == PermissionMode.PermissionGroup; + } + return base.GetDesignerPropertyVisible(propertyName, contextBase); + } + } public class ActionButtonDesigner : ObjectDesigner { @@ -766,7 +784,19 @@ namespace ElementUI } return base.GetEditorSetting(property, contextBase); } - } + public override bool GetDesignerPropertyVisible(string propertyName, IBuilderContextBase contextBase) + { + if (propertyName == nameof(ActionButton.allowRoles)) + { + return contextBase.PermissionMode == PermissionMode.Role; + } + if (propertyName == nameof(ActionButton.allowPermissionGroups)) + { + return contextBase.PermissionMode == PermissionMode.PermissionGroup; + } + return base.GetDesignerPropertyVisible(propertyName, contextBase); + } + } sealed public class ColumnSetting : ColumnSettingBase, INamedObject { @@ -789,7 +819,17 @@ namespace ElementUI get; set; } = new List() { "FGC_Anonymous" }; - string INamedObject.Name + + [JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Replace)] + [PermissionGroupSelectorProperty] + [OrderWeight(30)] + [SRDisplayName(nameof(Resources.Permission))] + public List allowPermissionGroups + { + get; set; + } = ["-2"]; + + string INamedObject.Name { get { @@ -1131,7 +1171,16 @@ namespace ElementUI get; set; } = new List() { "FGC_Anonymous" }; - public override bool GetDesignerPropertyVisible(string propertyName) + [JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Replace)] + [PermissionGroupSelectorProperty] + [SRDisplayName(nameof(Resources.Permission))] + public List allowPermissionGroups + { + get; set; + } = new List() { "-2" }; + + + public override bool GetDesignerPropertyVisible(string propertyName) { if (propertyName == nameof(icon)) { diff --git a/CellTypes/VirtualizedTableCellType.cs b/CellTypes/VirtualizedTableCellType.cs index 8c0f33b766df46932b85e09f35bad6b7d5313d1e..9dcb89e1cce9d294ab67181d5ad42b6ddb06579e 100644 --- a/CellTypes/VirtualizedTableCellType.cs +++ b/CellTypes/VirtualizedTableCellType.cs @@ -393,6 +393,7 @@ public class VirtualizedTableCellType : ElementCellTypeBase, ISupportUIPermissio Enabled = true, Ignore = true, AllowRoles = new List() { DefaultRoleManager.FGC_Anonymous }, + AllowPermissionGroups = ["-2"], Children = GetSubUIPermisison() }; @@ -425,6 +426,7 @@ public class VirtualizedTableCellType : ElementCellTypeBase, ISupportUIPermissio if (dic.TryGetValue(item.Label, out var permission)) { item.allowRoles = permission.AllowRoles; + item.allowPermissionGroups = permission.AllowPermissionGroups; } } } @@ -435,6 +437,7 @@ public class VirtualizedTableCellType : ElementCellTypeBase, ISupportUIPermissio if (dic.TryGetValue(item.Name, out var permission)) { item.allowRoles = permission.AllowRoles; + item.allowPermissionGroups = permission.AllowPermissionGroups; } } } @@ -448,16 +451,18 @@ public class VirtualizedTableCellType : ElementCellTypeBase, ISupportUIPermissio subUIPermissions = subUIPermissions.Union(Columns.OfType().Select(i => new SubUIPermission() { Name = i.Label, - AllowRoles = i.allowRoles - })).ToList(); + AllowRoles = i.allowRoles, + AllowPermissionGroups = i.allowPermissionGroups + })).ToList(); } if (this.ShowOperationColumn && this.OperationColumnSettings?.ActionButtons?.Count > 0) { subUIPermissions = subUIPermissions.Union(this.OperationColumnSettings.ActionButtons.OfType().Select(i => new SubUIPermission() { Name = i.Name, - AllowRoles = i.allowRoles - })).ToList(); + AllowRoles = i.allowRoles, + AllowPermissionGroups = i.allowPermissionGroups + })).ToList(); } var hashSet = new HashSet(); return subUIPermissions.Where(i => @@ -622,7 +627,16 @@ public class VirtualizedTableColumnSetting : VirtualizedTableColumnSettingBase, get; set; } = new List() { "FGC_Anonymous" }; - string INamedObject.Name + [JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Replace)] + [PermissionGroupSelectorProperty] + [OrderWeight(30)] + [SRDisplayName(nameof(Resources.Permission))] + public List allowPermissionGroups + { + get; set; + } = [ "-2" ]; + + string INamedObject.Name { get => Label; set => Label = value; @@ -661,6 +675,19 @@ public class VirtualizedTableColumnSettingDesigner : ObjectDesigner ColumnSettingDesigner.InitCellTypeSettings(propertyName, propertyValue, properties); base.OnPropertyEditorChanged(propertyName, propertyValue, properties); } + + public override bool GetDesignerPropertyVisible(string propertyName, IBuilderContextBase contextBase) + { + if (propertyName == nameof(VirtualizedTableColumnSetting.allowRoles)) + { + return contextBase.PermissionMode == PermissionMode.Role; + } + if (propertyName == nameof(VirtualizedTableColumnSetting.allowPermissionGroups)) + { + return contextBase.PermissionMode == PermissionMode.PermissionGroup; + } + return base.GetDesignerPropertyVisible(propertyName, contextBase); + } } public class VirtualizedTableCellTypeDesigner : CellTypeDesigner, ISupportPropertyInitialize, @@ -1002,6 +1029,19 @@ public class VirtualizedTableActionButtonDesigner : ObjectDesigner } return base.GetEditorSetting(property, contextBase); } + + public override bool GetDesignerPropertyVisible(string propertyName, IBuilderContextBase contextBase) + { + if (propertyName == nameof(VirtualizedTableActionButton.allowRoles)) + { + return contextBase.PermissionMode == PermissionMode.Role; + } + if (propertyName == nameof(VirtualizedTableActionButton.allowPermissionGroups)) + { + return contextBase.PermissionMode == PermissionMode.PermissionGroup; + } + return base.GetDesignerPropertyVisible(propertyName, contextBase); + } } [Designer("ElementUI.VirtualizedTableActionButtonDesigner, ElementUI")] @@ -1064,7 +1104,17 @@ public class VirtualizedTableActionButton : ObjectPropertyBase, INamedObject get; set; } = new List() { "FGC_Anonymous" }; - public override bool GetDesignerPropertyVisible(string propertyName) + [JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Replace)] + [PermissionGroupSelectorProperty] + [OrderWeight(30)] + [SRDisplayName(nameof(Resources.Permission))] + public List allowPermissionGroups + { + get; set; + } = ["-2"]; + + + public override bool GetDesignerPropertyVisible(string propertyName) { if (propertyName == nameof(Icon)) { diff --git a/ReferForguncyDLL/Forguncy.Commands.Design.dll b/ReferForguncyDLL/Forguncy.Commands.Design.dll index dd311dd370d055c880c313b5f86e720b9e5bfc25..609cd794b4a1b76102c7d0736b5dc3e9f4dabfdf 100644 Binary files a/ReferForguncyDLL/Forguncy.Commands.Design.dll and b/ReferForguncyDLL/Forguncy.Commands.Design.dll differ diff --git a/ReferForguncyDLL/Forguncy.Commands.dll b/ReferForguncyDLL/Forguncy.Commands.dll index 3163c873beede3199eaaeca5304c4e54b787b639..d1a8cd156ac7f36bc7859e2cae8d3632ca8a1183 100644 Binary files a/ReferForguncyDLL/Forguncy.Commands.dll and b/ReferForguncyDLL/Forguncy.Commands.dll differ diff --git a/ReferForguncyDLL/Forguncy.RbacPermission.Abstractions.dll b/ReferForguncyDLL/Forguncy.RbacPermission.Abstractions.dll index 847f31bbb79dd82b4bae93f78ef80aadf33a20d8..6e6c3a497a161b50990a9dd7b1b3958dcdaa71ba 100644 Binary files a/ReferForguncyDLL/Forguncy.RbacPermission.Abstractions.dll and b/ReferForguncyDLL/Forguncy.RbacPermission.Abstractions.dll differ diff --git a/ReferForguncyDLL/GrapeCity.Forguncy.CellTypes.Design.dll b/ReferForguncyDLL/GrapeCity.Forguncy.CellTypes.Design.dll index 575d1e93a4eb046ec2ecc64956e1512c71df6c5f..2f38b50daa3478b02229698c0f90ebe8bbd0cad1 100644 Binary files a/ReferForguncyDLL/GrapeCity.Forguncy.CellTypes.Design.dll and b/ReferForguncyDLL/GrapeCity.Forguncy.CellTypes.Design.dll differ diff --git a/ReferForguncyDLL/GrapeCity.Forguncy.CellTypes.dll b/ReferForguncyDLL/GrapeCity.Forguncy.CellTypes.dll index 97b50963b742c94fd2a772384cb562dac7e63839..e0fa328a398847ab766fe0f3fe9470d25940165c 100644 Binary files a/ReferForguncyDLL/GrapeCity.Forguncy.CellTypes.dll and b/ReferForguncyDLL/GrapeCity.Forguncy.CellTypes.dll differ diff --git a/ReferForguncyDLL/GrapeCity.Forguncy.Plugin.Design.dll b/ReferForguncyDLL/GrapeCity.Forguncy.Plugin.Design.dll index 34777b5575200184f6e7d31ac03ad35f33839daf..a4becc4f491972bc85cc02fdc16d4e509e0575e5 100644 Binary files a/ReferForguncyDLL/GrapeCity.Forguncy.Plugin.Design.dll and b/ReferForguncyDLL/GrapeCity.Forguncy.Plugin.Design.dll differ diff --git a/ReferForguncyDLL/GrapeCity.Forguncy.Plugin.dll b/ReferForguncyDLL/GrapeCity.Forguncy.Plugin.dll index c0ee3a1e928a3fa8ebcf527a91c678bd2ab3d7cc..499ddaeaff5ab9aab75081f8c89a59ecba731bb3 100644 Binary files a/ReferForguncyDLL/GrapeCity.Forguncy.Plugin.dll and b/ReferForguncyDLL/GrapeCity.Forguncy.Plugin.dll differ diff --git a/Resources/CellTypes/NavMenu.ts b/Resources/CellTypes/NavMenu.ts index b12df2f203c450cf6e4bad059bd21c361aebb07f..caa0435b7890c6cc519eb6a19c93374a7aac8af6 100644 --- a/Resources/CellTypes/NavMenu.ts +++ b/Resources/CellTypes/NavMenu.ts @@ -487,7 +487,7 @@ namespace ElementCellTypes { } return options.filter((option, index) => { if (permissions[index]) { - const hasPermission = this.checkRoleAuthority(permissions[index].AllowRoles); + const hasPermission = this.checkPermission(permissions[index]); if (hasPermission) { option.children = this.filterOptionsByPermission(option.children, permissions[index].Children); } @@ -497,6 +497,18 @@ namespace ElementCellTypes { }); } + private checkPermission(permission: Forguncy.Plugin.SubUIPermission): boolean { + const permissionMode = this.getPermissionMode(); + switch (permissionMode) { + case Forguncy.PermissionMode.Role: + return this.checkRoleAuthority(permission.AllowRoles); + case Forguncy.PermissionMode.PermissionGroup: + return this.checkPermissionGroupsAuthority(permission.AllowPermissionGroups); + default: + return false; + } + } + private getDefaultMenuItemSlot() { return ` diff --git a/Resources/CellTypes/Table.ts b/Resources/CellTypes/Table.ts index 97ad6872ab28434ff3a7afaf37201ffe750df89d..b34b39ce4be12cfcd257b6001e31a4cdb4b2c9e6 100644 --- a/Resources/CellTypes/Table.ts +++ b/Resources/CellTypes/Table.ts @@ -101,7 +101,7 @@ namespace ElementCellTypes { if (!this.isDesignerPreview && uiPermission?.Children) { for (var i = 0; i < uiPermission.Children.length; i++) { var permission = uiPermission.Children[i]; - permissionDic[permission.Name] = permission.AllowRoles; + permissionDic[permission.Name] = permission } } @@ -115,13 +115,13 @@ namespace ElementCellTypes { } cellType.columns.forEach(c => { if (permissionDic[c.label]) { - c.hide = !this.checkRoleAuthority(permissionDic[c.label]); + c.hide = !this.checkPermission(permissionDic[c.label]); } c.label = this.getApplicationResource(c.label); }); cellType.actionButtons.forEach(b => { if (permissionDic[b.Name]) { - b.hide = !this.checkRoleAuthority(permissionDic[b.Name]); + b.hide = !this.checkPermission(permissionDic[b.Name]); } b.Name = this.getApplicationResource(b.Name); }); @@ -503,6 +503,18 @@ height="100%" return true; } + private checkPermission(permission: Forguncy.Plugin.SubUIPermission): boolean { + const permissionMode = this.getPermissionMode(); + switch (permissionMode) { + case Forguncy.PermissionMode.Role: + return this.checkRoleAuthority(permission.AllowRoles); + case Forguncy.PermissionMode.PermissionGroup: + return this.checkPermissionGroupsAuthority(permission.AllowPermissionGroups); + default: + return false; + } + } + public getCustomSlotByPath(slotPath: SlotPath): string { let slot = super.getCustomSlotByPath(slotPath); if (this.isEmpty(slot)) { diff --git a/Resources/CellTypes/VirtualizedTable.ts b/Resources/CellTypes/VirtualizedTable.ts index 1ad4cb356bb48c70d60f772433477db197c98117..a2af83d60bc8d32d7e7f65155236b599d06d385b 100644 --- a/Resources/CellTypes/VirtualizedTable.ts +++ b/Resources/CellTypes/VirtualizedTable.ts @@ -425,6 +425,18 @@ namespace ElementCellTypes { return newColumns; } + private checkPermission(permission: Forguncy.Plugin.SubUIPermission): boolean { + const permissionMode = this.getPermissionMode(); + switch (permissionMode) { + case Forguncy.PermissionMode.Role: + return this.checkRoleAuthority(permission.AllowRoles); + case Forguncy.PermissionMode.PermissionGroup: + return this.checkPermissionGroupsAuthority(permission.AllowPermissionGroups); + default: + return false; + } + } + public onPageLoaded(info: Forguncy.Plugin.CellTypeInfo) { const self = this; let isLoading = false; @@ -434,7 +446,7 @@ namespace ElementCellTypes { if (!this.isDesignerPreview && uiPermission?.Children) { for (var i = 0; i < uiPermission.Children.length; i++) { var permission = uiPermission.Children[i]; - permissionDic[permission.Name] = permission.AllowRoles; + permissionDic[permission.Name] = permission; } } @@ -454,14 +466,14 @@ namespace ElementCellTypes { this.cellType.Columns.forEach(c => { if (permissionDic[c.Label]) { - c.hide = !this.checkRoleAuthority(permissionDic[c.Label]); + c.hide = !this.checkPermission(permissionDic[c.Label]); } }); this.cellType.Columns = this.cellType.Columns.filter(i => !i.hide); this.cellType.OperationColumnSettings.ActionButtons.forEach((button: IActionButton) => { if (permissionDic[button.Name]) { - button.hide = !this.checkRoleAuthority(permissionDic[button.Name]); + button.hide = !this.checkPermission(permissionDic[button.Name]); } button.StyleType = Forguncy.ConvertToCssColor(button.StyleType); diff --git a/Resources/Declaration/forguncy.Plugin.d.ts b/Resources/Declaration/forguncy.Plugin.d.ts index 76b662c3a94d26a15dd37cc0d9807d8a9d9a28f3..f5fb54ab74ca0f967340df1deaae4c5a69cc3f41 100644 --- a/Resources/Declaration/forguncy.Plugin.d.ts +++ b/Resources/Declaration/forguncy.Plugin.d.ts @@ -452,6 +452,26 @@ declare namespace Forguncy.Plugin { */ protected checkRoleAuthority(allowRoles: string[]): boolean; + /** + * Check whether the current user exists in allow access permission groups. + * 检查当前用户是否在有权限的权限组列表中。 + * + * @param allowPermissionGroups The permission group list which has ui permission. + * 有权限的权限组列表。 + * + * @returns Return true means current user has permission, and otherwise means current user has no permission. + * 如果当前用户有权限返回True,否则返回False。 + * + */ + protected checkPermissionGroupsAuthority(allowPermissionGroups: string[]): boolean; + + /** + * get permission mode + * 获取权限认证模式 + * @returns PermissionMode + */ + protected getPermissionMode(): PermissionMode; + /** * 执行自定义命令对象列表。 * @param command @@ -865,6 +885,13 @@ declare namespace Forguncy.Plugin { * 有单元格权限的角色列表。 */ AllowRoles: string[]; + /** + * The permission group list which has celltype ui permission. + * 有单元格权限的权限组列表。 + * + * + */ + AllowPermissionGroups: string[]; /** * 单元格中所有子项的的单元格权限信息。 */ @@ -883,6 +910,13 @@ declare namespace Forguncy.Plugin { * 有单元格权限的角色列表。 */ AllowRoles: string[]; + /** + * The permission group list which has celltype ui permission. + * 有单元格权限的权限组列表。 + * + * + */ + AllowPermissionGroups: string[]; /** * 单元格子项的子项的单元格权限信息。 */ @@ -1154,7 +1188,6 @@ declare namespace Forguncy.Plugin { */ MediumDashed = 8, } - } declare namespace Forguncy { @@ -1164,4 +1197,19 @@ declare namespace Forguncy { */ getCellType(): Forguncy.Plugin.CellTypeBase; } + + /** + * 权限认证模式 + */ + const enum PermissionMode { + /** + * 按照角色来认证资源权限 + */ + Role, + + /** + * 按照权限组来认证资源权限 + */ + PermissionGroup + } }