check if user has module edit permission when page is not in edit mode

Viewed 1843

I am developing a module for DNN 7.1+ and I need to display / hide a link in the module based on if the user has edit permission for that module. I want this to happen regardless of whether or not the page is in edit mode.

Currently I have the following code in the view.ascx of the custom module page load event:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    Try
        ''other code goes here.......
        If IsEditable = True Then
            AdminEdit.Visible = True
        Else
            AdminEdit.Visible = False
        End If
    Catch exc As Exception
        Exceptions.ProcessModuleLoadException(Me, exc)
    End Try

End Sub

AdminEdit is the ID of the element I want to hide. This code works when the page is in edit mode, but I want this to always be visible, regardless of edit mode, if the user has edit permission for that module.

Right now the IsEditbale returns false if page is not in edit mode.

QUESTION: How can I check the user permission without the page being in edit mode?

EDIT: I would also be happy with checking against the user's edit permission for the page containing the module

SOLUTION:

Here is what I ended up with thanks to bdukes:

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Try

            ''display template selector if user has edit rights over module
            If DotNetNuke.Security.Permissions.ModulePermissionController.CanEditModuleContent(Me.ModuleConfiguration) Then
                AdminEdit.Visible = True
            Else
                AdminEdit.Visible = False
            End If
        Catch exc As Exception
            Exceptions.ProcessModuleLoadException(Me, exc)
        End Try

    End Sub
1 Answers
Related