generated from Kentico/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#198 migration of media file refactor; fails for member users resoved
- Loading branch information
Showing
31 changed files
with
531 additions
and
1,242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
namespace Migration.Toolkit.Source.Helpers; | ||
|
||
using CMS.Base; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Migration.Toolkit.Common; | ||
using Migration.Toolkit.KXP.Api.Auxiliary; | ||
using Migration.Toolkit.Source.Model; | ||
|
||
public class AdminUserHelper | ||
{ | ||
/// <summary> | ||
/// maps source user id to target admin user | ||
/// </summary> | ||
/// <param name="sourceUserId">source user id</param> | ||
/// <param name="memberFallbackTargetUserId">in case user was migrated to member, replacement admin user shall be returned</param> | ||
/// <param name="onAdminNotFound">called when no admin user exists in target instance, but is expected to exist</param> | ||
/// <returns>Target admin user ID</returns> | ||
public static int? MapTargetAdminUser(int? sourceUserId, int memberFallbackTargetUserId, Action? onAdminNotFound = null) | ||
{ | ||
if (sourceUserId is null) return null; | ||
|
||
var modelFacade = KsCoreDiExtensions.ServiceProvider.GetRequiredService<ModelFacade>(); | ||
if (modelFacade.SelectById<ICmsUser>(sourceUserId) is { } modifiedByUser) | ||
{ | ||
if (UserHelper.PrivilegeLevelsMigratedAsAdminUser.Contains(modifiedByUser.UserPrivilegeLevel)) | ||
{ | ||
var primaryKeyMappingContext = KsCoreDiExtensions.ServiceProvider.GetRequiredService<IPrimaryKeyMappingContext>(); | ||
switch (primaryKeyMappingContext.MapSourceId<ICmsUser>(u => u.UserID, sourceUserId)) | ||
{ | ||
case { Success: true, MappedId: { } targetUserId }: | ||
return targetUserId; | ||
default: | ||
{ | ||
onAdminNotFound?.Invoke(); | ||
return null; | ||
} | ||
} | ||
} | ||
return CMSActionContext.CurrentUser.UserID; | ||
} | ||
|
||
// user not found, setting fallback | ||
return CMSActionContext.CurrentUser.UserID; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.