Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion docs/data/classes/reference.tools.tfsusermappingtool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ configurationSamples:
"Microsoft.VSTS.Common.ClosedBy"
],
"UserMappingFile": "C:\\temp\\userExport.json",
"MatchUsersByEmail": false
"MatchUsersByEmail": false,
"ProjectCollectionValidUsersGroupName": "Project Collection Valid Users"
}
sampleFor: MigrationTools.Tools.TfsUserMappingToolOptions
description: The TfsUserMappingTool is used to map users from the source to the target system. Run it with the ExportUsersForMappingContext to create a mapping file then with WorkItemMigrationContext to use the mapping file to update the users in the target system as you migrate the work items.
Expand All @@ -90,6 +91,10 @@ options:
type: Boolean
description: By default, users in source are mapped to target users by their display name. If this is set to true, then the users will be mapped by their email address first. If no match is found, then the display name will be used.
defaultValue: missing XML code comments
- parameterName: ProjectCollectionValidUsersGroupName
type: String
description: This is the regionalized "Project Collection Valid Users" group name. Default is "Project Collection Valid Users".
defaultValue: missing XML code comments
- parameterName: UserMappingFile
type: String
description: This is the file that will be used to export or import the user mappings. Use the ExportUsersForMapping processor to create the file.
Expand Down
4 changes: 4 additions & 0 deletions docs/static/schema/configuration.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,10 @@
"description": "By default, users in source are mapped to target users by their display name. If this is set to true, then the users will be mapped by their email address first. If no match is found, then the display name will be used.",
"type": "boolean"
},
"projectCollectionValidUsersGroupName": {
"description": "This is the regionalized \"Project Collection Valid Users\" group name. Default is \"Project Collection Valid Users\".",
"type": "string"
},
"userMappingFile": {
"description": "This is the file that will be used to export or import the user mappings. Use the ExportUsersForMapping processor to create the file.",
"type": "string"
Expand Down
4 changes: 4 additions & 0 deletions docs/static/schema/schema.tools.tfsusermappingtool.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"description": "By default, users in source are mapped to target users by their display name. If this is set to true, then the users will be mapped by their email address first. If no match is found, then the display name will be used.",
"type": "boolean"
},
"projectCollectionValidUsersGroupName": {
"description": "This is the regionalized \"Project Collection Valid Users\" group name. Default is \"Project Collection Valid Users\".",
"type": "string"
},
"userMappingFile": {
"description": "This is the file that will be used to export or import the user mappings. Use the ExportUsersForMapping processor to create the file.",
"type": "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/// </summary>
public class TfsUserMappingTool : Tool<TfsUserMappingToolOptions>
{
new public TfsUserMappingToolOptions Options => (TfsUserMappingToolOptions)base.Options;

Check warning on line 22 in src/MigrationTools.Clients.TfsObjectModel/Tools/TfsUserMappingTool.cs

View workflow job for this annotation

GitHub Actions / Build, Test, Sonar Cloud Analysis, & Package

Remove this unnecessary cast to 'TfsUserMappingToolOptions'. (https://rules.sonarsource.com/csharp/RSPEC-1905)

public TfsUserMappingTool(
IOptions<TfsUserMappingToolOptions> options,
Expand All @@ -43,7 +43,7 @@
public static void SerializeUserMap(string fileName, Dictionary<string, string> userMap, ILogger logger)
{
File.WriteAllText(fileName, JsonConvert.SerializeObject(userMap, Formatting.Indented));
logger.LogInformation("User mappings writen to: {fileName}", fileName);

Check warning on line 46 in src/MigrationTools.Clients.TfsObjectModel/Tools/TfsUserMappingTool.cs

View workflow job for this annotation

GitHub Actions / Build, Test, Sonar Cloud Analysis, & Package

Use PascalCase for named placeholders. (https://rules.sonarsource.com/csharp/RSPEC-6678)
}

/// <summary>
Expand All @@ -62,23 +62,23 @@
}
catch (Exception)
{
logger.LogError($"TfsUserMappingTool::DeserializeUserMap User mapping could not be deserialized from file '{fileName}'.", fileName);

Check warning on line 65 in src/MigrationTools.Clients.TfsObjectModel/Tools/TfsUserMappingTool.cs

View workflow job for this annotation

GitHub Actions / Build, Test, Sonar Cloud Analysis, & Package

Don't use string interpolation in logging message templates. (https://rules.sonarsource.com/csharp/RSPEC-2629)

Check warning on line 65 in src/MigrationTools.Clients.TfsObjectModel/Tools/TfsUserMappingTool.cs

View workflow job for this annotation

GitHub Actions / Build, Test, Sonar Cloud Analysis, & Package

Logging in a catch clause should pass the caught exception as a parameter. (https://rules.sonarsource.com/csharp/RSPEC-6667)
}
return [];
}

private HashSet<string> GetUsersFromWorkItems(List<WorkItemData> workitems, List<string> identityFieldsToCheck)

Check warning on line 70 in src/MigrationTools.Clients.TfsObjectModel/Tools/TfsUserMappingTool.cs

View workflow job for this annotation

GitHub Actions / Build, Test, Sonar Cloud Analysis, & Package

Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
HashSet<string> foundUsers = new(StringComparer.CurrentCultureIgnoreCase);
foreach (var wItem in workitems)
{
foreach (var rItem in wItem.Revisions.Values)
{
foreach (var fItem in rItem.Fields.Values)

Check warning on line 77 in src/MigrationTools.Clients.TfsObjectModel/Tools/TfsUserMappingTool.cs

View workflow job for this annotation

GitHub Actions / Build, Test, Sonar Cloud Analysis, & Package

Loops should be simplified using the "Where" LINQ method (https://rules.sonarsource.com/csharp/RSPEC-3267)
{
if (identityFieldsToCheck.Contains(fItem.ReferenceName, _workItemNameComparer))
{
if (!foundUsers.Contains(fItem.Value) && !string.IsNullOrEmpty((string)fItem.Value))

Check warning on line 81 in src/MigrationTools.Clients.TfsObjectModel/Tools/TfsUserMappingTool.cs

View workflow job for this annotation

GitHub Actions / Build, Test, Sonar Cloud Analysis, & Package

Merge this if statement with the enclosing one. (https://rules.sonarsource.com/csharp/RSPEC-1066)
{
foundUsers.Add(fItem.Value.ToString());
}
Expand All @@ -97,7 +97,7 @@
{
if (Options.Enabled && Options.IdentityFieldsToCheck.Contains(field.ReferenceName))
{
Log.LogDebug($"TfsUserMappingTool::MapUserIdentityField [ReferenceName|{field.ReferenceName}]");

Check warning on line 100 in src/MigrationTools.Clients.TfsObjectModel/Tools/TfsUserMappingTool.cs

View workflow job for this annotation

GitHub Actions / Build, Test, Sonar Cloud Analysis, & Package

Don't use string interpolation in logging message templates. (https://rules.sonarsource.com/csharp/RSPEC-2629)
if (UserMappings.Value.ContainsKey(field.Value.ToString()))
{
var original = field.Value;
Expand All @@ -121,7 +121,7 @@

private List<IdentityItemData> GetUsersListFromServer(IGroupSecurityService gss)
{
Identity allIdentities = gss.ReadIdentity(SearchFactor.AccountName, "Project Collection Valid Users", QueryMembership.Expanded);
Identity allIdentities = gss.ReadIdentity(SearchFactor.AccountName, Options.ProjectCollectionValidUsersGroupName, QueryMembership.Expanded);
Log.LogInformation("TfsUserMappingTool::GetUsersListFromServer Found {count} identities (users and groups) in server.", allIdentities.Members.Length);

List<IdentityItemData> foundUsers = new List<IdentityItemData>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public class TfsUserMappingToolOptions : ToolOptions, ITfsUserMappingToolOptions
/// </summary>
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool SkipValidateAllUsersExistOrAreMapped { get; set; } = false;

/// <summary>
/// This is the regionalized "Project Collection Valid Users" group name. Default is "Project Collection Valid Users".
/// </summary>
public string ProjectCollectionValidUsersGroupName { get; set; } = "Project Collection Valid Users";

}

public interface ITfsUserMappingToolOptions
Expand Down
Loading