Skip to content

Commit 9a4c794

Browse files
authored
VCST-3663: User groups are not scoped within a current company. (#46)
1 parent 40b1bf9 commit 9a4c794

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

src/VirtoCommerce.Xapi.Core/Services/ILoadUserToEvalContextService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ namespace VirtoCommerce.Xapi.Core.Services
66
public interface ILoadUserToEvalContextService
77
{
88
Task SetShopperDataFromMember(EvaluationContextBase evalContextBase, string customerId);
9+
10+
Task SetShopperDataFromOrganization(EvaluationContextBase evalContextBase, string organizationId);
911
}
1012
}

src/VirtoCommerce.Xapi.Data/Services/LoadUserToEvalContextService.cs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,37 @@ public virtual async Task SetShopperDataFromMember(EvaluationContextBase evalCon
4343

4444
evalContextBase.GeoTimeZone = contact.TimeZone;
4545

46-
evalContextBase.UserGroups = contact.Groups?.ToArray();
46+
var userGroups = new List<string>();
4747

48-
if (!contact.Organizations.IsNullOrEmpty())
48+
if (!evalContextBase.UserGroups.IsNullOrEmpty())
4949
{
50-
var userGroups = new List<string>();
51-
52-
if (!evalContextBase.UserGroups.IsNullOrEmpty())
53-
{
54-
userGroups.AddRange(evalContextBase.UserGroups);
55-
}
50+
userGroups.AddRange(evalContextBase.UserGroups);
51+
}
5652

57-
var organizations = await _memberService.GetByIdsAsync(contact.Organizations.ToArray(), MemberResponseGroup.WithGroups.ToString());
58-
userGroups.AddRange(organizations.OfType<Organization>().SelectMany(x => x.Groups));
53+
userGroups.AddRange(contact.Groups?.ToArray());
5954

60-
evalContextBase.UserGroups = userGroups.Distinct().ToArray();
61-
}
55+
evalContextBase.UserGroups = userGroups.Distinct().ToArray();
6256
}
6357
}
6458

59+
public async Task SetShopperDataFromOrganization(EvaluationContextBase evalContextBase, string organizationId)
60+
{
61+
if (organizationId.IsNullOrEmpty())
62+
{
63+
return;
64+
}
65+
66+
var userGroups = new List<string>();
67+
68+
if (!evalContextBase.UserGroups.IsNullOrEmpty())
69+
{
70+
userGroups.AddRange(evalContextBase.UserGroups);
71+
}
72+
73+
var organizations = await _memberService.GetByIdsAsync([organizationId], MemberResponseGroup.WithGroups.ToString());
74+
userGroups.AddRange(organizations.OfType<Organization>().SelectMany(x => x.Groups));
75+
76+
evalContextBase.UserGroups = userGroups.Distinct().ToArray();
77+
}
6578
}
6679
}

0 commit comments

Comments
 (0)