Skip to content

Commit ca2d168

Browse files
authored
Fix New-TfsUser when project is missing (#226)
* Fix New-TfsUser when project is missing * Fix issue with the Project argument * Update release notes * Update tasks
1 parent 645b1fd commit ca2d168

File tree

4 files changed

+59
-35
lines changed

4 files changed

+59
-35
lines changed

.github/workflows/main.yml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
TFSCMDLETS_COLLECTION_URL: 'https://dev.azure.com/tfscmdlets'
2323
steps:
2424
- name: Checkout code
25-
uses: actions/checkout@v3
25+
uses: actions/checkout@v4
2626
with:
2727
fetch-depth: 0
2828
- name: Initialize CodeQL
@@ -37,37 +37,37 @@ jobs:
3737
- name: Perform CodeQL Analysis
3838
uses: github/codeql-action/analyze@v3
3939
- name: Publish Nuget
40-
uses: actions/upload-artifact@v3
40+
uses: actions/upload-artifact@v4
4141
with:
4242
name: nuget
4343
path: "out/Nuget/*.nupkg"
4444
- name: Publish Chocolatey
45-
uses: actions/upload-artifact@v3
45+
uses: actions/upload-artifact@v4
4646
with:
4747
name: chocolatey
4848
path: "out/Chocolatey/*.nupkg"
4949
- name: Publish Portable
50-
uses: actions/upload-artifact@v3
50+
uses: actions/upload-artifact@v4
5151
with:
5252
name: portable
5353
path: "out/Portable/*.zip"
5454
- name: Publish MSI
55-
uses: actions/upload-artifact@v3
55+
uses: actions/upload-artifact@v4
5656
with:
5757
name: msi
5858
path: "out/msi/*"
5959
- name: Publish WinGet
60-
uses: actions/upload-artifact@v3
60+
uses: actions/upload-artifact@v4
6161
with:
6262
name: winget
6363
path: "out/winget/**"
6464
- name: Publish Docs
65-
uses: actions/upload-artifact@v3
65+
uses: actions/upload-artifact@v4
6666
with:
6767
name: docs
6868
path: "out/docs/*.zip"
6969
- name: Publish Release Notes
70-
uses: actions/upload-artifact@v3
70+
uses: actions/upload-artifact@v4
7171
with:
7272
name: releasenotes
7373
path: "docs/ReleaseNotes/**"
@@ -84,7 +84,7 @@ jobs:
8484
BUILD_NAME: ${{ needs.Build.outputs.BUILD_NAME }}
8585
steps:
8686
- name: Download all artifacts
87-
uses: actions/download-artifact@v3
87+
uses: actions/download-artifact@v4
8888
- name: Extract release notes
8989
id: extract_release_notes
9090
shell: pwsh
@@ -138,7 +138,7 @@ jobs:
138138
BUILD_NAME: ${{ needs.Staging.outputs.BUILD_NAME }}
139139
steps:
140140
- name: Cancel Previous Runs
141-
uses: styfle/cancel-workflow-action@0.10.0
141+
uses: styfle/cancel-workflow-action@0.12.1
142142
with:
143143
access_token: ${{ github.token }}
144144
- name: Promote release
@@ -173,12 +173,12 @@ jobs:
173173
RELEASE_NOTES: ${{ needs.Release.outputs.RELEASE_NOTES }}
174174
steps:
175175
- name: Checkout code
176-
uses: actions/checkout@v3
176+
uses: actions/checkout@v4
177177
with:
178178
fetch-depth: 0
179179
path: site
180180
- name: Download artifact
181-
uses: actions/download-artifact@v3
181+
uses: actions/download-artifact@v4
182182
with:
183183
name: docs
184184
- name: Publish site
@@ -206,7 +206,7 @@ jobs:
206206
PSGALLERY_KEY: ${{ secrets.API_KEY }}
207207
steps:
208208
- name: Download artifact
209-
uses: actions/download-artifact@v3
209+
uses: actions/download-artifact@v4
210210
with:
211211
name: portable
212212
- name: Publish artifact
@@ -226,11 +226,11 @@ jobs:
226226
if: ${{ github.event_name != 'pull_request' }}
227227
steps:
228228
- name: Download artifact
229-
uses: actions/download-artifact@v3
229+
uses: actions/download-artifact@v4
230230
with:
231231
name: nuget
232232
- name: Install Nuget 5.x
233-
uses: nuget/setup-nuget@v1
233+
uses: nuget/setup-nuget@v2
234234
with:
235235
nuget-api-key: ${{ secrets.API_KEY }}
236236
nuget-version: '5.x'
@@ -248,7 +248,7 @@ jobs:
248248
CHOCO_KEY: ${{ secrets.API_KEY }}
249249
steps:
250250
- name: Download artifact
251-
uses: actions/download-artifact@v3
251+
uses: actions/download-artifact@v4
252252
with:
253253
name: chocolatey
254254
- name: Install Chocolatey
@@ -280,7 +280,7 @@ jobs:
280280
git fetch upstream
281281
git checkout -b "TfsCmdlets_$BUILD_NAME"
282282
- name: Download artifact
283-
uses: actions/download-artifact@v3
283+
uses: actions/download-artifact@v4
284284
with:
285285
name: winget
286286
path: winget-pkgs

CSharp/TfsCmdlets/Cmdlets/Identity/User/NewUser.cs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ partial class NewUser
4242
/// When omitted, the user is not added to any projects.
4343
/// </summary>
4444
[Parameter]
45-
public object Projects { get; set; }
45+
[Alias("Projects")]
46+
public object Project { get; set; }
4647

4748
/// <summary>
4849
/// Specifies the default group to which the user should be added, when applicable.
@@ -79,31 +80,42 @@ protected override IEnumerable Run()
7980
_ => "stakeholder"
8081
};
8182

82-
IDictionary<string, string> projects = Projects switch
83+
IDictionary<string, string> projects = Project switch
8384
{
8485
string p => new Dictionary<string, string> { { p, defaultGroup } },
8586
IDictionary dict => dict.Cast<DictionaryEntry>().ToDictionary(kv => kv.Key.ToString(), kv => kv.Value.ToString()),
8687
ICollection c => c.Cast<string>().ToDictionary(p => p, g => defaultGroup),
8788
_ => null
8889
};
8990

90-
if (!PowerShell.ShouldProcess(Collection, $"Create user '{User}' with license type '{License}' and the project entitlements \n{string.Join(";", projects.Select(kv => $"{kv.Key}={kv.Value}"))}"))
91+
var projectMsg = string.Empty;
92+
93+
if (projects != null && projects.Count > 0)
94+
{
95+
projectMsg = $" and the project entitlements [{string.Join("; ", projects.Select(kv => $"{kv.Key}={kv.Value}"))}]";
96+
}
97+
98+
if (!PowerShell.ShouldProcess(Collection, $"Create user '{User}' with license type '{License}'{projectMsg}"))
9199
{
92100
yield break;
93101
}
94102

95103
var parsedProjects = new Dictionary<Guid, string>();
96104

97-
foreach (var kv in projects)
105+
if (projects != null && projects.Count > 0)
98106
{
99-
var key = kv.Key switch
107+
foreach (var kv in projects)
100108
{
101-
string s when s.IsGuid() => Guid.Parse(s),
102-
string s => Data.GetItem<WebApiTeamProject>(new { Project = s }).Id,
103-
_ => throw new Exception("Invalid project name")
104-
};
109+
var key = kv.Key switch
110+
{
111+
string s when s.IsGuid() => Guid.Parse(s),
112+
string s => Data.GetItem<WebApiTeamProject>(new { Project = s })?.Id ?? throw new Exception($"Invalid project name '{s}'"),
113+
_ => throw new Exception($"Invalid project name '{kv.Key}'")
114+
};
115+
116+
parsedProjects.Add(key, kv.Value);
117+
}
105118

106-
parsedProjects.Add(key, kv.Value);
107119
}
108120

109121
var entitlements = new ProjectEntitlements(parsedProjects);
@@ -128,16 +140,16 @@ string s when s.IsGuid() => Guid.Parse(s),
128140
.GetResult("Error creating user")
129141
.ToJsonObject() ?? throw new Exception("Unknown error creating user");
130142

131-
if (!((bool) result.isSuccess))
143+
if (!((bool)result.isSuccess))
132144
{
133145
string errorMessage = result.operationResult.errors[0].value;
134-
Logger.LogError($"Error creating user. {errorMessage}");
146+
Logger.LogError($"Error creating user: {errorMessage}");
135147
yield break;
136148
}
137149

138150
if (Passthru)
139151
{
140-
yield return Data.GetItem<AccountEntitlement>(new{User});
152+
yield return Data.GetItem<AccountEntitlement>(new { User });
141153
}
142154
}
143155

Docs/ReleaseNotes/2.8.1.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# TfsCmdlets Release Notes
2+
3+
## Version 2.8.1 (_16/Jul/2024_)
4+
5+
This release fixes an issue with the `New-TfsUser` cmdlet.
6+
7+
### Fixes
8+
9+
- Fixed an issue where the `New-TfsUser` cmdlet could throw an error when not supplying project entitlements via the -Project argument.

RELEASENOTES.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
# TfsCmdlets Release Notes
22

3-
## Version 2.8.0 (_09/Jul/2024_)
3+
## Version 2.8.1 (_16/Jul/2024_)
44

5-
This release adds two new cmdlets: `New-TfsUser` and `Remove-TfsUser`.
5+
This release fixes an issue with the `New-TfsUser` cmdlet.
66

7-
### New cmdlets
7+
### Fixes
88

9-
- `New-TfsUser`: Creates a new user in the organization and optionally adds them to projects.
10-
- `Remove-TfsUser`: Removes a user from the organization.
9+
- Fixed an issue where the `New-TfsUser` cmdlet could throw an error when not supplying project entitlements via the -Project argument.
1110

1211
-----------------------
1312

1413
## Previous Versions
1514

15+
### Version 2.8.0 (_09/Jul/2024_)
16+
17+
See release notes [here](Docs/ReleaseNotes/2.8.0.md).
18+
1619
### Version 2.7.1 (_03/Jul/2024_)
1720

1821
See release notes [here](Docs/ReleaseNotes/2.7.1.md).

0 commit comments

Comments
 (0)