Ticket Q108244
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

Security.Permissions - Abstract permission classes are displayed in the New Action's Items list

How to prevent abstract permission class from showing on New menu?

created 17 years ago

I have a MustInherit class (AllowDenyPermissionBase) that descends from PermissionBase. I use this as the ancestor for all my simple custom Allow/Deny permission types so that they only require a couple of lines each to define.
The problem is that AllowDenyPermissionBase shows up on the New action menu when editing the Permissions list for a Role.
I have tried (1) applying the CreatableItem(False) attribute to the class, (2) making the DetailView and ListView for the class ReadOnly, and (3) using a regular ObjectAccessPermission to deny AllAccess to the class. No joy.
Is there a way to prevent the New action menu from showing abstract classes?
Thanks…

Show previous comments (3)
Dennis Garavsky (DevExpress) 17 years ago

    Hi David,
    Thank you for the update.
    Your last solution is also correct and you can use it.
    I have converted my code in VB.Net and it will look like this in the 8.2 version of the suite:

    Visual Basic
    Partial Public Class ViewController1 Inherits ViewController Public Sub New() TargetViewId = "RoleBase_PersistentPermissions_ListView" End Sub Protected Overrides Sub OnActivated() MyBase.OnActivated() AddHandler Frame.GetController(Of NewObjectViewController)().CollectDescendantTypes, AddressOf ViewController1_CollectDescendantTypes End Sub Private Sub ViewController1_CollectDescendantTypes(ByVal sender As Object, ByVal e As CollectTypesEventArgs) For Each item As Type In e.Types If item Is GetType(MyPermissionBase) Then e.Types.Remove(item) Return End If Next item End Sub End Class Public MustInherit Class MyPermissionBase Inherits PermissionBase Protected Friend Sub New() End Sub End Class Public Class MyClass1 Inherits MyPermissionBase Public Overrides Function Copy() As System.Security.IPermission Return New MyClass1() End Function End Class Public Class MyClass2 Inherits MyPermissionBase Public Overrides Function Copy() As System.Security.IPermission Return New MyClass2() End Function End Class End Class

    It all works fine for me. Could you please upgrade to the latest version of XAF?
    I have also created a new bug report with ID B31829 (Security.Permissions - Abstract permission classes are displayed in the New Action's Items list) advising against using such controllers as a workaround.
    Thanks,
    Dennis

      I think I see part of the problem.
      Your original C# code attached a handler to Frame.GetController<NewObjectViewController>().CollectDescendants.
      Your new VB code attaches the handler to Frame.GetController(Of NewObjectViewController)().CollectDescendantTypes instead.
      In 8.1.6, event CollectDescendantTypes doesn't exist, but event CollectDescendants does. Maybe these function a little differently.
      So I'm assuming that this code works only in 8.2. I'll just have to wait as I can't really work with that until it gets out of beta.
      Thanks…

      Dennis Garavsky (DevExpress) 17 years ago

        Hi David,
        I suggest you use your own work around since it is more effective than mine. I have attached a complete and refactored version of my sample project which works fine for me for both CS and VB projects under the 8.1.6 version of the suite:

        C#
        Imports Microsoft.VisualBasic Imports System Imports DevExpress.ExpressApp Imports DevExpress.ExpressApp.SystemModule Imports DevExpress.ExpressApp.Security Imports DevExpress.ExpressApp.Actions Namespace WinSolution.Module.Win Partial Public Class ViewController1 Inherits ViewController Public Sub New() InitializeComponent() RegisterActions(components) TargetViewId = "RoleBase_PersistentPermissions_ListView" End Sub Protected Overrides Sub OnActivated() MyBase.OnActivated() AddHandler View.ControlsCreated, AddressOf View_ControlsCreated End Sub Private Sub View_ControlsCreated(ByVal sender As Object, ByVal e As EventArgs) Dim action As SingleChoiceAction = Frame.GetController(Of NewObjectViewController)().NewObjectAction action.BeginUpdate() action.Items.Remove(action.Items.Find(GetType(MyPermissionBase))) action.EndUpdate() End Sub End Class End Namespace

        Please let me know in case of any difficulty.
        Thanks,
        Dennis

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.