jeremy-farrance / AccuratySolutions-2023

AccuLadder and other helper stuff
MIT License
0 stars 0 forks source link

Need a Simple Way to Show if the current Page is Public or Private - for Authenticated Users #11

Open jeremy-farrance opened 3 months ago

jeremy-farrance commented 3 months ago

Probably should have posted this here for best long-term availability. https://github.com/Accuraty/AccuTheme-Bs4/issues/19

jeremy-farrance commented 3 months ago

This appears to be the winner on simplicity, readability, performance, and accuracy.

<% 
    // is the current page public?
    // retry using PortalSettings.ActiveTab.TabPermissions
    int allUsersRoleId = int.Parse(DotNetNuke.Common.Globals.glbRoleAllUsers); 
    bool IsPublic = PortalSettings.ActiveTab
      .TabPermissions.Cast<DotNetNuke.Security.Permissions.TabPermissionInfo>()
        .Any(pi => pi.RoleID == allUsersRoleId 
          && pi.AllowAccess 
          && pi.PermissionID == 3 // 3 is SYSTEM_TAB, VIEW
        )
    ; 
    debugOutput.AppendLine("--------------------");
    debugOutput.AppendLine($"IsPublic: {IsPublic}");
    debugOutput.AppendLine($"allUsersRoleId: {allUsersRoleId}");

%>