Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0How to add more permission into my module How to add more permission into my module
Previous
 
Next
New Post
3/3/2008 8:46 AM
 

Dear core team,

I have a problem (sorry if my question was already answered).

I am developing CMS module (in C#, SQL 2005). And I want each role (ie Admin, Editor ...) have different permission. For example : Admin has full control but Editor only can edit some article and i can set permission for each role in Settings Page. Now, DNN has just 2 permisson in each module :View & Edit. If i want add more permission, i can manualy add it on Permission table in Database.  But I want to add data into Permission table automatically as UDT or Feedback module.

I have tried using IUpgradeable & InitPermission but It does not work. That's is my code:

public string UpgradeModule(string Version)

{

       InitPermissions();

       return Version;

}

private void InitPermissions()
        {
            bool _canEdit = false;
            int moduleDefId;
            DotNetNuke.Security.Permissions.PermissionController pc = new DotNetNuke.Security.Permissions.PermissionController();
            ArrayList permissions = pc.GetPermissionByCodeAndKey("CMS_CODE", null);
            DotNetNuke.Entities.Modules.DesktopModuleController dc = new DesktopModuleController();
            DotNetNuke.Entities.Modules.DesktopModuleInfo desktopInfo;
            desktopInfo = dc.GetDesktopModuleByName("CMS");
            DotNetNuke.Entities.Modules.Definitions.ModuleDefinitionController mc = new DotNetNuke.Entities.Modules.Definitions.ModuleDefinitionController();
            DotNetNuke.Entities.Modules.Definitions.ModuleDefinitionInfo mInfo;
            mInfo = mc.GetModuleDefinitionByName(desktopInfo.DesktopModuleID, "CMS");
            moduleDefId = mInfo.ModuleDefID;
            foreach (DotNetNuke.Security.Permissions.PermissionInfo p in permissions)
            {
                if ((p.PermissionKey == "EDITARTICLE")&&(p.ModuleDefID == moduleDefId))
                {
                    _canEdit = true;
                }
            }
            if (!_canEdit)
            {
                DotNetNuke.Security.Permissions.PermissionInfo p = new DotNetNuke.Security.Permissions.PermissionInfo();
                p.ModuleDefID = moduleDefId;
                p.PermissionCode = CMS_CODE;
                p.PermissionKey = "EDITARTICLE";
                p.PermissionName = "Can edit";
                pc.AddPermission(p);
            }
        }
    }

So what i wrong and how can i make it work.

Thanks & Regards

 
New Post
3/3/2008 10:24 AM
 

Now, DNN has just 2 permisson in each module :View & Edit

It looks like you are doing an awful lot of work for something that is built in with DotNetNuke. You can Add more roles using Admin|Security Roles|Add new role. Then look at page settings and you will notice your new roles are listed. You can select which users can view the content and which users can edit the content. Note that this also works per module so you can allow viewing and editing of any module.

All this without one line of code.

I hope this is of some help to you.


Dwayne J. Baldwin
 
New Post
3/3/2008 11:30 AM
 

Dwayne Baldwin wrote

 Now, DNN has just 2 permisson in each module :View & Edit

It looks like you are doing an awful lot of work for something that is built in with DotNetNuke. You can Add more roles using Admin|Security Roles|Add new role. Then look at page settings and you will notice your new roles are listed. You can select which users can view the content and which users can edit the content. Note that this also works per module so you can allow viewing and editing of any module.

All this without one line of code.

I hope this is of some help to you.

I guess that you miss understand my question. Of course, I know how to create Role. All I want is to create more permission similar to View and Edit. Example: I add 2 more permissions - Moderate Feedback Posts  &  Manage Feedback Lists.  So that I can select which user can view, edit, Moderate Feedback Posts  &  Manage Feedback Lists.  

And how can i make my module has its permissions (Create, Approve, Publish ...).

 

 
New Post
3/3/2008 1:18 PM
 

Huyaloha:

I don't have an exact answer to the issue with your code but I can share the way I do it.  First of all, the matrix in your picture has always confused me (okay, maybe I'm not that smart) because it still relies on the basic roles in DNN.  In the modules I have done that are used in Intranet specific apps, I don't do it that way, and it is part of my overall module dev architecture.  I have only one View module and load all other User Controls dynamically so, the method shown in the picture would not work.  Instead, I create new roles like Module Admin, Managers, Analysts, Customers, etc.  Then in my User Controls, I manually check for to see if the user is in the roles the specific functionality needs.  I know, this is kind of hard coded but these modules are not for sale, they are custom apps, and in this way you can take the security down to a single control level.  I do check that all the necessary roles exist when the module loads however.  I'm not saying you have to do it this way, but this is how I do it, it works for me, and I actually understand the whole thing.

Carlos

 

 
New Post
3/3/2008 1:31 PM
 

Although I prefer to use PermissionController.GetPermissionsByModuleDefID (ByVal ModuleDefID as Integer) to obtain an ArrayList of the current permissions for the specific ModuleDefID rather than permissions for all ModuleDefID's you're code looks like it should work provided that the ModuleDefID that you are getting is correct. I'm wondering if the code is actually getting called.

  • Have you set a break point in the code to see if it is getting hit when the module is installed?
  • Am I correct that the UpgradeModule method is located in your BusinessClassController and the name of the controller class properly referenced in your .dnn manifest file?
  • Have you checked that following installation of the module, the module definition is showing Upgradable as one of its Supported Features. Do you have at least one xx.xx.xxSqlDataProvider file included in the install package and referenced in the .dnn manifest?
  • Since the UpgradeModule method is not directly called from the installation code but rather by an event which has been placed in the EventQueue table and run when the application restarts immediately following the install, you should be able to look at this table to see if the event was created and that it actually ran to completion. The event would have "UpgradeModule" in the ProcessorCommand column and infomation about the BusinessClassController name, DesktopModuleID, etc. in the Attributes column.  If the event was successfully run the IsCompleted column should be True.

For comparison, here's the code I usually use (in VB - sorry). The identifiers Permission.Code, Permission.ModerateKey, etc. are simply constants:

Public Function UpgradeModule(ByVal Version As String) As String Implements DotNetNuke.Entities.Modules.IUpgradeable.UpgradeModule
   Dim Result As String
   Dim dmc As New Entities.Modules.DesktopModuleController
   Dim dmi As Entities.Modules.DesktopModuleInfo = dmc.GetDesktopModuleByModuleName(Consts.ModuleName)
   If dmi Is Nothing Then
           Result = Version & " - " & "failure to obtain DesktopModuleInfo object for ModuleName " & Consts.ModuleName
   Else
       If Version = "04.00.00" Then
            Try
                Dim mdc As New Entities.Modules.Definitions.ModuleDefinitionController
                Dim mdi As Entities.Modules.Definitions.ModuleDefinitionInfo = mdc.GetModuleDefinitionByName(dmi.DesktopModuleID, dmi.FriendlyName)
                Dim ModuleDefID As Integer = mdi.ModuleDefID
                Dim pc As New Permissions.PermissionController
                Dim pi As Permissions.PermissionInfo
                Dim ModulePermissions As ArrayList = pc.GetPermissionsByModuleDefID(ModuleDefID)

                Dim PostPermissionIsDefined, ModeratePermissionIsDefined As Boolean
                For Each pi In ModulePermissions
                    If pi.PermissionCode = Permission.Code And pi.PermissionKey = Permission.PostKey Then PostPermissionIsDefined = True
                    If pi.PermissionCode = Permission.Code And pi.PermissionKey = Permission.ModerateKey Then ModeratePermissionIsDefined = True
                Next

                If Not PostPermissionIsDefined Then
                    pi = New Permissions.PermissionInfo
                    With pi
                       .ModuleDefID = ModuleDefID
                       .PermissionCode = Permission.Code
                       .PermissionKey = Permission.PostKey
                        .PermissionName = Permission.PostName
                    End With
                    pc.AddPermission(pi)
                End If

                If Not ModeratePermissionIsDefined Then
                     pi = New Permissions.PermissionInfo
                     With pi
                        .ModuleDefID = ModuleDefID
                        .PermissionCode = Permission.Code
                        .PermissionKey = Permission.ModerateKey
                        .PermissionName = Permission.ModerateName
                     End With
                     pc.AddPermission(pi)
                End If
                Result = Version & " - " & Permission.Code & " permissions " & Permission.PostName & " and " & Permission.ModerateName & " successfully added"
            Catch ex As Exception
                Result = Version & " - " & "Error in adding " & Permission.Code & " permissions: " & ex.Message
            End Try
       'other code to run here . . .
       End If
    End If
    Return Result
End Function

Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0How to add more permission into my module How to add more permission into my module


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out