Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TfsUserMappingTool Logic Error results in mapping file declaired missing even when not. #2416

Closed
MrHinsh opened this issue Oct 3, 2024 · 0 comments · Fixed by #2417
Closed

Comments

@MrHinsh
Copy link
Member

MrHinsh commented Oct 3, 2024

Current implemention has a logic error where it will squash the found mapping file:

 private Dictionary<string, string> GetMappingFileData()
 {
     if (_UserMappings == null && System.IO.File.Exists(Options.UserMappingFile))
     {
         var fileData = System.IO.File.ReadAllText(Options.UserMappingFile);
         try
         {
             var fileMaps = Newtonsoft.Json.JsonConvert.DeserializeObject<List<IdentityMapData>>(fileData);
             _UserMappings = fileMaps.ToDictionary(x => x.Source.FriendlyName, x => x.target?.FriendlyName);
         }
         catch (Exception)
         {
             _UserMappings = new Dictionary<string, string>();
             Log.LogError($"TfsUserMappingTool::GetMappingFileData [UserMappingFile|{Options.UserMappingFile}] <-- invalid - No mapping are applied!");
         }

     }
     else
     {
         Log.LogError($"TfsUserMappingTool::GetMappingFileData::No User Mapping file Provided! Provide file or disable TfsUserMappingTool");
         _UserMappings = new Dictionary<string, string>();
     }

     return _UserMappings;

 }

proposed replacement is :

       private Dictionary<string, string> GetMappingFileData()
       {
           if (!System.IO.File.Exists(Options.UserMappingFile))
           {
               Log.LogError($"TfsUserMappingTool::GetMappingFileData::No User Mapping file Provided! Provide file or disable TfsUserMappingTool");
               _UserMappings = new Dictionary<string, string>();
           }
           if (_UserMappings == null )
           {
               var fileData = System.IO.File.ReadAllText(Options.UserMappingFile);
               try
               {
                   var fileMaps = Newtonsoft.Json.JsonConvert.DeserializeObject<List<IdentityMapData>>(fileData);
                   _UserMappings = fileMaps.ToDictionary(x => x.Source.FriendlyName, x => x.target?.FriendlyName);
               }
               catch (Exception)
               {
                   _UserMappings = new Dictionary<string, string>();
                   Log.LogError($"TfsUserMappingTool::GetMappingFileData [UserMappingFile|{Options.UserMappingFile}] <-- invalid - No mapping are applied!");
               }

           }
           return _UserMappings;
       }
@MrHinsh MrHinsh linked a pull request Oct 3, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant