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

CUT-4490-ImportUpdate CSV Bug Fix #626

Merged
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
2 changes: 1 addition & 1 deletion PowerShell/JumpCloud Module/Docs/JumpCloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Module Name: JumpCloud
Module Guid: 31c023d1-a901-48c4-90a3-082f91b31646
Download Help Link: https://github.com/TheJumpCloud/support/wiki
Help Version: 2.15.0
Help Version: 2.16.0
Locale: en-Us
---

Expand Down
2 changes: 1 addition & 1 deletion PowerShell/JumpCloud Module/JumpCloud.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'JumpCloud.psm1'

# Version number of this module.
ModuleVersion = '2.15.0'
ModuleVersion = '2.16.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,13 @@ Function Import-JCUsersFromCSV () {
$FormatGroupOutput = $Null
$CustomGroupArrayList = $Null

$CustomAttributes = $UserAdd | Get-Member | Where-Object Name -Like "*Attribute*" | Where-Object { $_.Definition -NotLike "*=" -and $_.Definition -NotLike "*null" } | Select-Object
# Get all the custom attributes that are not null
$CustomAttributes = $UserAdd | Get-Member | Where-Object Name -Like "*Attribute*" | Where-Object { $_.Definition -NotLike "*=" -and $_.Definition -NotLike "*null" }

# Sort the attributes by number and name
$CustomAttributes = $CustomAttributes | Sort-Object {
[int]([regex]::Match($_.Name, '\d+').Value) },
{ $_.Name }

Write-Verbose $CustomAttributes.name.count

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,13 @@ Function Update-JCUsersFromCSV () {
$FormatGroupOutput = $Null
$CustomGroupArrayList = $Null

$CustomAttributes = $UserUpdate | Get-Member | Where-Object Name -Like "*Attribute*" | Where-Object { $_.Definition -NotLike "*=" -and $_.Definition -NotLike "*null" } | Select-Object
# Get all the custom attributes that are not null
$CustomAttributes = $UserUpdate | Get-Member | Where-Object Name -Like "*Attribute*" | Where-Object { $_.Definition -NotLike "*=" -and $_.Definition -NotLike "*null" }

# Sort the attributes by number and name
$CustomAttributes = $CustomAttributes | Sort-Object {
[int]([regex]::Match($_.Name, '\d+').Value) },
{ $_.Name }

if ($CustomAttributes.name.count -gt 1) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,47 @@ Describe -Tag:('JCUsersFromCSV') "Import-JCUsersFromCSV 2.14.2" {
}
}
}
Describe -Tag:('JCUsersFromCSV') "Import-JCUsersFromCSV 2.15.1" {
Context "Import-JCUsersFromCSV with 10 or more custom attributes" {
It "When there are 10 or more custom attributes, the API should not return an error message in the status field and continue to import the user" {
$user = New-RandomUser -Domain "ImportCSVUser.$(New-RandomString -NumberOfChars 5)"
$today = Get-Date
$EnrollmentDays = 14
$CSVDATA = @{
Username = $user.username
LastName = $user.LastName
FirstName = $user.FirstName
Email = $user.Email
Attribute1_name = "Name"
Attribute1_value = "Value"
Attribute2_name = "Name1"
Attribute2_value = "Value1"
Attribute3_name = "Name2"
Attribute3_value = "Value2"
Attribute4_name = "Name3"
Attribute4_value = "Value3"
Attribute5_name = "Name4"
Attribute5_value = "Value4"
Attribute6_name = "Name5"
Attribute6_value = "Value5"
Attribute7_name = "Name6"
Attribute7_value = "Value6"
Attribute8_name = "Name7"
Attribute8_value = "Value7"
Attribute9_name = "Name8"
Attribute9_value = "Value8"
Attribute10_name = "Name9"
Attribute10_value = "Value9"
Attribute11_name = "Name10"
Attribute11_value = "Value10"
}
$CSVFILE = $CSVDATA | Export-Csv "$PesterParams_ImportPath/custom_attribute.csv" -Force
$importResults = Import-JCUsersFromCSV -CSVFilePath "$PesterParams_ImportPath/custom_attribute.csv" -force
# ImportResults should not be error
$importResults[0].Status | Should -Match "User Created"
}
}
}

AfterAll {
Get-JCUser | Where-Object Email -like *testimportcsvuser* | Remove-JCUser -force
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,43 @@ Describe -Tag:('JCUsersFromCSV') "Update-JCUsersFromCSV 2.14.2" {
}
}
}

Describe -Tag:('JCUsersFromCSV') "Update-JCUsersFromCSV 2.15.1" {
Context "User should be updated even with 10 or more custom attributes" {
It "When there are 10 or more custom attributes, the user should still be updated" {
$user = New-RandomUser -Domain "testupdatecsvuser.$(New-RandomString -NumberOfChars 5)" | New-JCUser
$CSVDATA = @{
Username = $user.username
Attribute1_name = "Name"
Attribute1_value = "Value"
Attribute2_name = "Name1"
Attribute2_value = "Value1"
Attribute3_name = "Name2"
Attribute3_value = "Value2"
Attribute4_name = "Name3"
Attribute4_value = "Value3"
Attribute5_name = "Name4"
Attribute5_value = "Value4"
Attribute6_name = "Name5"
Attribute6_value = "Value5"
Attribute7_name = "Name6"
Attribute7_value = "Value6"
Attribute8_name = "Name7"
Attribute8_value = "Value7"
Attribute9_name = "Name8"
Attribute9_value = "Value8"
Attribute10_name = "Name9"
Attribute10_value = "Value9"
Attribute11_name = "Name10"
Attribute11_value = "Value10"
}
$CSVFILE = $CSVDATA | Export-Csv "$PesterParams_UpdatePath/custom_attribute.csv" -Force
$UpdateStatus = Update-JCUsersFromCSV -CSVFilePath "$PesterParams_UpdatePath/custom_attribute.csv" -force
# the error message should show that custom attribute names cannot contain spaces
$UpdateStatus[0].status | Should -Be "User Updated"
}
}
}
AfterAll {
Get-JCUser | Where-Object Email -like *testupdatecsvuser* | Remove-JCUser -force
}
14 changes: 14 additions & 0 deletions PowerShell/ModuleChangelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## 2.16.0

Release Date: December 4, 2024

#### RELEASE NOTES

```
This release introduces a bug fix for `Import-JCUsersFromCSV` and `Update-JCUsersFromCSV` issues with importing more than 10 custom attributes
```

#### BUG FIXES:

- Fixed a bug with `Import-JCUsersFromCSV` and `Update-JCUsersFromCSV` throwing error when importing 10 or more Custom Attributes due to a sorting issue

## 2.15.0

Release Date: November 18, 2024
Expand Down