Skip to content

Commit

Permalink
Impersonate as selected visitor group
Browse files Browse the repository at this point in the history
`VisitorGroupRole.ImpersonatedVisitorGroupByID` is a key from CMS Core which
lets to impersonate every request for a specific VG

Closes #238
  • Loading branch information
barteksekula committed Sep 1, 2023
1 parent fd31b18 commit 07b3c08
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Expand Up @@ -66,6 +66,7 @@ public object RoutePartial(IContent content, UrlResolverContext segmentContext)
_externalReviewState.IsEditLink = true;
_externalReviewState.Token = token;
_externalReviewState.PreferredLanguage = version.LanguageBranch;
_externalReviewState.ImpersonatedVisitorGroupsById = externalReviewLink.VisitorGroups;

try
{
Expand Down
10 changes: 10 additions & 0 deletions src/Advanced.CMS.ExternalReviews/ExternalReviewState.cs
@@ -1,6 +1,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using EPiServer.Core;
using EPiServer.Personalization.VisitorGroups;
using EPiServer.ServiceLocation;
using Microsoft.AspNetCore.Http;

Expand Down Expand Up @@ -36,6 +37,15 @@ public bool IsEditLink
set => _httpContextAccessor.HttpContext.Items["IsEditLink"] = value.ToString();
}

/// <summary>
/// VisitorGroupRole.ImpersonatedVisitorGroupByID is a special string from CMS Core which allows to impersonate as any VG
/// </summary>
public string[] ImpersonatedVisitorGroupsById
{
get => (string[]) _httpContextAccessor.HttpContext?.Items[VisitorGroupRole.ImpersonatedVisitorGroupByID];
set => _httpContextAccessor.HttpContext.Items[VisitorGroupRole.ImpersonatedVisitorGroupByID] = value;
}

public IList<string> CustomLoaded
{
get
Expand Down
Expand Up @@ -2,7 +2,6 @@
using System.Globalization;
using Advanced.CMS.ExternalReviews.PinCodeSecurity;
using Advanced.CMS.ExternalReviews.ReviewLinksRepository;
using EPiServer.Cms.Shell;
using EPiServer.Core;
using EPiServer.Core.Routing;
using EPiServer.Core.Routing.Pipeline;
Expand Down Expand Up @@ -79,6 +78,7 @@ public object RoutePartial(IContent content, UrlResolverContext segmentContext)
_externalReviewState.Token = token;
_externalReviewState.ProjectId = externalReviewLink.ProjectId;
_externalReviewState.PreferredLanguage = version.LanguageBranch;
_externalReviewState.ImpersonatedVisitorGroupsById = externalReviewLink.VisitorGroups;

// PIN code security check, if user is not authenticated, then redirect to login page
if (!_externalLinkPinCodeSecurityHandler.UserHasAccessToLink(externalReviewLink))
Expand Down

0 comments on commit 07b3c08

Please sign in to comment.