Quantcast
Channel: Optimizely Search & Navigation
Viewing all articles
Browse latest Browse all 6894

FilterOnReadAccess() broken due to changes in VirtualRoleRepository (Episerver please fix it)

$
0
0

Hi

Episerver Find extension method ContentSearchExtensions.FilterOnReadAccess is broken. It no longer returns any results for anonymous users.

The issue happens with the latest nugets:
EPiServer.CMS.Core 9.8.1
EPiServer.Find 11.1.4.4296
EPiServer.Find.Cms 11.1.4.4296
EPiServer.Find.Framework 11.1.4.4296

It seems that the issue is caused by changes in EPiServer.Security.VirtualRoleRepository, which has method VirtualRoleRepository<VirtualRoleProviderBase>.GetDefault() for obtaining an instance. The method is now deprecated and no longer works as it should, but the latest Find nuget uses it. The fix is to use IoC to obtain the instance.

    // Class: EPiServer.Find.Cms.ContentSearchExtensions
    private static IEnumerable<string> GetCurrentUsersRoles()
    {
      List<string> list = Enumerable.ToList<string>((IEnumerable<string>) PrincipalInfo.Current.RoleList);
      // This seems to cause the issue. GetDefault method is deprecated and returns the wrong instance
      VirtualRoleRepository<VirtualRoleProviderBase> @default = VirtualRoleRepository<VirtualRoleProviderBase>.GetDefault();
      // !!! Should use IoC. This retrieves the correct instance
      //VirtualRoleRepository<VirtualRoleProviderBase> @default = ServiceLocator.Current.GetInstance<IVirtualRoleRepository>();
      foreach (string name in @default.GetAllRoles())
      {
        VirtualRoleProviderBase virtualRoleProvider;
        if (@default.TryGetRole(name, out virtualRoleProvider) && virtualRoleProvider.IsInVirtualRole(PrincipalInfo.CurrentPrincipal, (object) null))
          list.Add(name);
      }
      if (Roles.Enabled)
        list.AddRange((IEnumerable<string>) Roles.GetRolesForUser(PrincipalInfo.Current.Name));
      return Enumerable.Distinct<string>((IEnumerable<string>) list);
    }

The latest CMS patch is not rollbackable due to DB changes, and I would really like to avoid making own workaround extensions for Find. So, could you release a fix as soon as possible, please :)


Viewing all articles
Browse latest Browse all 6894

Trending Articles