Skip to content

Commit 0648c78

Browse files
No need to process store user id / roles as these now store guids which are trasnferable
1 parent 16efe17 commit 0648c78

File tree

1 file changed

+11
-74
lines changed

1 file changed

+11
-74
lines changed

src/Umbraco.Commerce.Deploy/Connectors/ServiceConnectors/UmbracoCommerceStoreServiceConnector.cs

Lines changed: 11 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ public override IAsyncEnumerable<StoreReadOnly> GetEntitiesAsync(CancellationTok
7676
GiftCardDaysValid = entity.GiftCardDaysValid,
7777
GiftCardCodeTemplate = entity.GiftCardCodeTemplate,
7878
GiftCardPropertyAliases = entity.GiftCardPropertyAliases,
79-
GiftCardActivationMethod = (int)entity.GiftCardActivationMethod
79+
GiftCardActivationMethod = (int)entity.GiftCardActivationMethod,
80+
AllowedUsers = entity.AllowedUsers.Select(x => x.UserId).ToList(),
81+
AllowedUserRoles = entity.AllowedUserRoles.Select(x => x.Role).ToList(),
8082
};
8183

8284
// Base currency
@@ -169,52 +171,6 @@ public override IAsyncEnumerable<StoreReadOnly> GetEntitiesAsync(CancellationTok
169171
artifact.ErrorEmailTemplateUdi = depUdi;
170172
}
171173

172-
// Allowed users
173-
// NB: Users can't be deployed so don't add to dependencies collection
174-
// instead we'll just have to hope that they exist on all environments
175-
// and if not, when it comes to restore, we'll just not set anything
176-
if (entity.AllowedUsers.Count > 0)
177-
{
178-
var users = new List<string>();
179-
180-
foreach (var id in entity.AllowedUsers)
181-
{
182-
var user = _userService.GetByProviderKey(id.UserId);
183-
if (user != null)
184-
{
185-
users.Add(user.Username);
186-
}
187-
}
188-
189-
if (users.Count > 0)
190-
{
191-
artifact.AllowedUsers = users;
192-
}
193-
}
194-
195-
// Allowed user roles
196-
// NB: Users roles can't be deployed so don't add to dependencies collection
197-
// instead we'll just have to hope that they exist on all environments
198-
// and if not, when it comes to restore, we'll just not set anything
199-
if (entity.AllowedUserRoles.Count > 0)
200-
{
201-
var userRoles = new List<string>();
202-
203-
foreach (var role in entity.AllowedUserRoles)
204-
{
205-
var userGroup = _userService.GetUserGroupByAlias(role.Role);
206-
if (userGroup != null)
207-
{
208-
userRoles.Add(userGroup.Alias);
209-
}
210-
}
211-
212-
if (userRoles.Count > 0)
213-
{
214-
artifact.AllowedUserRoles = userRoles;
215-
}
216-
}
217-
218174
// Stock sharing store
219175
if (entity.ShareStockFromStoreId.HasValue)
220176
{
@@ -244,9 +200,9 @@ public override async Task ProcessAsync(ArtifactDeployState<StoreArtifact, Store
244200
}
245201
}
246202

247-
private Task Pass1Async(ArtifactDeployState<StoreArtifact, StoreReadOnly> state, IDeployContext context, CancellationToken cancellationToken = default)
248-
=> _umbracoCommerceApi.Uow.ExecuteAsync(
249-
(uow, ct) =>
203+
private async Task Pass1Async(ArtifactDeployState<StoreArtifact, StoreReadOnly> state, IDeployContext context, CancellationToken cancellationToken = default)
204+
=> await _umbracoCommerceApi.Uow.ExecuteAsync(
205+
async (uow, ct) =>
250206
{
251207
StoreArtifact artifact = state.Artifact;
252208

@@ -272,7 +228,9 @@ private Task Pass1Async(ArtifactDeployState<StoreArtifact, StoreReadOnly> state,
272228
.SetGiftCardValidityTimeframe(artifact.GiftCardDaysValid)
273229
.SetGiftCardPropertyAliases(artifact.GiftCardPropertyAliases, SetBehavior.Replace)
274230
.SetGiftCardActivationMethod((GiftCardActivationMethod)artifact.GiftCardActivationMethod)
275-
.SetSortOrder(artifact.SortOrder);
231+
.SetSortOrder(artifact.SortOrder)
232+
.SetAllowedUsers(artifact.AllowedUsers)
233+
.SetAllowedUserRoles(artifact.AllowedUserRoles);
276234

277235
if (artifact.CookieTimeout.HasValue)
278236
{
@@ -283,35 +241,14 @@ private Task Pass1Async(ArtifactDeployState<StoreArtifact, StoreReadOnly> state,
283241
entity.DisableCookies();
284242
}
285243

286-
if (artifact.AllowedUsers != null && artifact.AllowedUsers.Any())
287-
{
288-
var userIds = artifact.AllowedUsers.Select(x => _userService.GetByUsername(x))
289-
.Where(x => x != null)
290-
.Select(x => x.Id.ToString(CultureInfo.InvariantCulture))
291-
.ToList();
292-
293-
entity.SetAllowedUsers(userIds, SetBehavior.Replace);
294-
}
295-
296-
if (artifact.AllowedUserRoles != null && artifact.AllowedUserRoles.Any())
297-
{
298-
var userRoles = artifact.AllowedUserRoles.Select(x => _userService.GetUserGroupByAlias(x))
299-
.Where(x => x != null)
300-
.Select(x => x.Alias)
301-
.ToList();
302-
303-
entity.SetAllowedUserRoles(userRoles, SetBehavior.Replace);
304-
}
305-
306244
_umbracoCommerceApi.SaveStore(entity);
307245

308246
state.Entity = entity;
309247

310248
uow.Complete();
311-
312-
return Task.CompletedTask;
313249
},
314-
cancellationToken);
250+
cancellationToken)
251+
.ConfigureAwait(false);
315252

316253
private Task Pass4Async(ArtifactDeployState<StoreArtifact, StoreReadOnly> state, IDeployContext context, CancellationToken cancellationToken = default) =>
317254
_umbracoCommerceApi.Uow.ExecuteAsync(

0 commit comments

Comments
 (0)