• Login
  • Register

DNN Forums

Ask questions about your website to get help learning DNN and help resolve issues.

Server Side code to check if the current user has edit rights on one of the modules

You are not authorized to post a reply.
Sort:


Veteran Member


Posts:864
Veteran Member

    I'm looking for the most efficient way to detect if the current user has Edit rights on one of the module on the page.
    I now used

    DotNetNuke.Security.Permissions.ModulePermissionController.CanEditModuleContent()

    But that would mean I would have to first get all modules on the page and check this for each module, which does not feel very efficient as DNN must be doing the same check for the Persona Bar.
    Is there a more efficient way to check this that I missed?



    Basic Member


    Posts:114
    Basic Member

      Looks like the control panel is also looping over all modules on the page: https://github.com/dnnsoftware/Dnn....#L124-L163

      DNN partner specializing in custom, enterprise DNN development https://engagesoftware.com/showcase


      Veteran Member


      Posts:434
      Veteran Member

        an alternative with better performance would be creating an appropriate stored procedure, you may query.


        Veteran Member


        Posts:864
        Veteran Member

          Posted By Brian Dukes on 18 Jun 2021 09:46 AM

          Looks like the control panel is also looping over all modules on the page: https://github.com/dnnsoftware/Dnn....#L124-L163

          Hmm, right.. thanks :-)

           

           



          Veteran Member


          Posts:864
          Veteran Member

            Posted By Sebastian Leupold on 18 Jun 2021 09:48 AM
            an alternative with better performance would be creating an appropriate stored procedure, you may query.

            As I think the Module Settings are cached, so I guess it should not be that slow, it's just that the PB does the same check..

             

             



            Veteran Member


            Posts:434
            Veteran Member

              considering the number of possible permission combinations for roles and users, evaluating it again and again can be time consuming - and it won't be helpful to cache with module and page settings.
              IMO it would be more efficient to cache permission with each user upon login (and once for unauthenticated users and maybe once for registered users).


              Basic Member


              Posts:40
              Basic Member

                I've used this code. But I've copied the "MANGE" permission key from DNN without looking into it.

                public static bool HasModuleEditRights(int tabId, int moduleId)
                {
                try
                {
                if (tabId <= 0 && moduleId <= 0) return true;
                if (tabId == 0) return false;
                if (moduleId == 0) return false;
                var moduleInfo = ModuleController.Instance.GetModule(moduleId, tabId, false);
                if (ModulePermissionController.HasModuleAccess(SecurityAccessLevel.Edit, "MANAGE", moduleInfo))
                {
                return true;
                }
                }
                catch (Exception)
                {
                return false;
                }
                return false;
                }
                You are not authorized to post a reply.

                These Forums are dedicated to discussion of DNN Platform.

                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.

                Would you like to help us?

                Awesome! Simply post in the forums using the link below and we'll get you started.

                Get Involved