Skip to content

Commit

Permalink
ZoomPhone fixes (#117)
Browse files Browse the repository at this point in the history
* Added AssigneeType and fixed help info

* Made confirmation messages more readable.

---------

Co-authored-by: Andrew Hoggins <andyhoggins@me.com>
  • Loading branch information
andrew-hoggins and Andrew Hoggins authored May 6, 2024
1 parent 0d54314 commit 22e3cb7
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function Add-ZoomPhoneCommonAreaCallingPlan {
$RequestBody = @{ }
$ChosenLicense = @{ }

$ZoomCommonAreaInfo = Get-ZoomPhoneCommonArea -CommonAreaId $_ -ErrorAction Stop

$KeyValuePairs = @{
'type' = $LicenseType
Expand All @@ -79,7 +80,7 @@ Body:
$RequestBody
"@

if ($pscmdlet.ShouldProcess($Message, $CommonAreaId, "Adding calling plan $LicenseType")) {
if ($pscmdlet.ShouldProcess($Message, $ZoomCommonAreaInfo.display_name, "Adding calling plan: $LicenseType")) {
$response = Invoke-ZoomRestMethod -Uri $request.Uri -Body $requestBody -Method POST

if (-not $PassThru) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function Add-ZoomPhoneCommonAreaNumber {
}

$NumberInfo = Get-ZoomPhoneNumber -ErrorAction Stop | Where-object Number -eq $number
$ZoomCommonAreaInfo = Get-ZoomPhoneCommonArea -CommonAreaId $CommonArea -ErrorAction Stop

if (-not ($NumberInfo)) {
Throw "Provided number was not found in the accounts's phone number list"
Expand Down Expand Up @@ -94,7 +95,7 @@ $RequestBody
"@


if ($pscmdlet.ShouldProcess($Message, $CommonArea, "Adding $Number")) {
if ($pscmdlet.ShouldProcess($Message, $ZoomCommonAreaInfo.display_name, "Adding $ChosenNumber")) {
$response = Invoke-ZoomRestMethod -Uri $request.Uri -Body $requestBody -Method POST

if (-not $PassThru) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function Remove-ZoomPhoneCommonAreaCallingPlan {
"SinglePlan" {
Foreach($CommonArea in $CommonAreaId){
$Request = [System.UriBuilder]"https://api.$ZoomURI/v2/phone/common_areas/$CommonArea/calling_plans/$LicenseType"
$ZoomCommonAreaInfo = Get-ZoomPhoneCommonArea -CommonAreaId $CommonArea -ErrorAction Stop
$Message =
@"
Expand All @@ -84,7 +85,7 @@ Body:
$RequestBody
"@

if ($pscmdlet.ShouldProcess($Message, $CommonArea, "Remove calling plan $LicenseType")) {
if ($pscmdlet.ShouldProcess($Message, $ZoomCommonAreaInfo.display_name, "Remove calling plan $LicenseType")) {
$response = Invoke-ZoomRestMethod -Uri $request.Uri -Method Delete

if (-not $PassThru) {
Expand Down Expand Up @@ -120,7 +121,7 @@ Body:
$RequestBody
"@

if ($pscmdlet.ShouldProcess($Message, $CommonArea, "Remove calling plan $CurrentLicense")) {
if ($pscmdlet.ShouldProcess($Message, $CommonArea, "Remove calling plan: $CurrentLicense")) {
$response = Invoke-ZoomRestMethod -Uri $request.Uri -Method Delete

if (-not $PassThru) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Body:
$RequestBody
"@

if ($pscmdlet.ShouldProcess($Message, $_, "Remove $NumberTBR")) {
if ($pscmdlet.ShouldProcess($Message, $ZoomEntityInfo.display_name, "Remove $($NumberTBR.number)")) {
$response = Invoke-ZoomRestMethod -Uri $request.Uri -Method DELETE

if (-not $PassThru) {
Expand Down
33 changes: 30 additions & 3 deletions PSZoom/Public/Phone/DeskPhone/Get-ZoomPhoneDevice.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ List all the desk phone devices that are configured with Zoom Phone on an accoun
.DESCRIPTION
List all the desk phone devices that are configured with Zoom Phone on an account.
.PARAMETER UserId
.PARAMETER DeviceId
Unique Identifier of the device.
.PARAMETER SiteId
Unique Identifier of the site. This can be found in the ListPhoneSites API.
.PARAMETER DeviceStatus
Whether the device is assigned or not.
.PARAMETER AssigneeType
The type of the assignee. It's available if type = assigned.
Allowed: user ┃ commonArea
.PARAMETER DeviceType
The manufacturer name.
Allowed: algo ┃ audioCodes ┃ cisco ┃ cyberData ┃ grandstream ┃ poly ┃ yealink ┃ other
Expand Down Expand Up @@ -39,7 +46,7 @@ Get-ZoomPhoneDevice -DeviceId ######
.EXAMPLE
Return devices of a specific manufacture for a specific site.
Get-ZoomPhoneDevice -SiteId ###### -DeviceType poly
Get-ZoomPhoneDevice -SiteId ###### -DeviceType "poly" -DeviceStatus "assigned"
#>

Expand All @@ -61,7 +68,8 @@ function Get-ZoomPhoneDevice {
[string]$DeviceId,

[parameter(
ParameterSetName="SpecificQuery"
ParameterSetName="SpecificQuery",
Mandatory = $true
)]
[ValidateSet("assigned","unassigned")]
[string]$DeviceStatus,
Expand All @@ -77,6 +85,17 @@ function Get-ZoomPhoneDevice {
)]
[string]$SiteId,

[Parameter(
ParameterSetName="SpecificQuery"
)]
[Alias(
'assignee_type'
)]
[ValidateSet(
"user","commonArea"
)]
[string]$AssigneeType,

[Parameter(
ParameterSetName="SpecificQuery"
)]
Expand Down Expand Up @@ -165,6 +184,14 @@ function Get-ZoomPhoneDevice {
if ($PSBoundParameters.ContainsKey('SiteId')) {
$QueryStatements.Add("site_id", $SiteId)
}
if ($PSBoundParameters.ContainsKey('AssigneeType')) {
if ($AssigneeType -eq "user") {
$AssigneeType = "user"
}elseif ($AssigneeType -eq "commonArea") {
$AssigneeType = "commonArea"
}
$QueryStatements.Add("assignee_type", $AssigneeType)
}
$AggregatedResponse += Get-ZoomPaginatedData -URI $baseURI -PageSize 100 -AdditionalQueryStatements $QueryStatements

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Extension ID of the assignee (user or common area)
Common Area Extension ID is the same as the Common Area ID
.PARAMETER UnassignAllEntities
Unique number used to locate device.
Unassign all attached entities.
.PARAMETER PassThru
When switched the command will pass the DeviceId back.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function Add-ZoomPhoneUserCallingPlan {

process {
foreach ($user in $UserId) {

if (-not (Get-ZoomUserSettings -UserId $user | Select-Object -ExpandProperty "feature" | Select-Object -ExpandProperty "zoom_phone")) {
Update-ZoomUserSettings -UserId $user -ZoomPhone $True
}
Expand All @@ -70,6 +70,8 @@ function Add-ZoomPhoneUserCallingPlan {

$RequestBody.Add("calling_plans", $ChosenLicense)

$ZoomUserInfo = Get-ZoomPhoneUser -UserId $user -ErrorAction Stop

$RequestBody = $RequestBody | ConvertTo-Json
$Message =
@"
Expand All @@ -80,7 +82,7 @@ Body:
$RequestBody
"@

if ($pscmdlet.ShouldProcess($Message, $UserId, "Update calling plan")) {
if ($pscmdlet.ShouldProcess($Message, $ZoomUserInfo.email, "Update calling plan: $LicenseType")) {
$response = Invoke-ZoomRestMethod -Uri $request.Uri -Body $requestBody -Method POST

if (-not $PassThru) {
Expand Down
3 changes: 2 additions & 1 deletion PSZoom/Public/Phone/UserPhone/Add-ZoomPhoneUserNumber.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function Add-ZoomPhoneUserNumber {
$number = "{0}$number" -f '+'
}

$ZoomUserInfo = Get-ZoomPhoneUser -UserId $user -ErrorAction Stop
$NumberInfo = Get-ZoomPhoneNumber -ErrorAction Stop | Where-object Number -eq $number

if (-not ($NumberInfo)) {
Expand Down Expand Up @@ -92,7 +93,7 @@ Body:
$RequestBody
"@

if ($pscmdlet.ShouldProcess($Message, $UserId, "Adding $Number")) {
if ($pscmdlet.ShouldProcess($Message, $ZoomUserInfo.email, "Adding $($NumberInfo.number)")) {
$response = Invoke-ZoomRestMethod -Uri $request.Uri -Body $requestBody -Method POST

if (-not $PassThru) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ function Remove-ZoomPhoneUserCallingPlan {

process {
foreach ($user in $UserId) {
$CurrentLicense = Get-ZoomPhoneUser -UserId $user | Select-Object -ExpandProperty "calling_plans" | Select-Object -ExpandProperty "type"
$ZoomUserInfo = Get-ZoomPhoneUser -UserId $user -ErrorAction Stop
$CurrentLicense = $ZoomUserInfo | Select-Object -ExpandProperty "calling_plans" | Select-Object -ExpandProperty "type"
$Request = [System.UriBuilder]"https://api.$ZoomURI/v2/phone/users/$user/calling_plans/$CurrentLicense"
$Message =
@"
Expand All @@ -48,7 +49,7 @@ Body:
$RequestBody
"@

if ($pscmdlet.ShouldProcess($Message, $User, "Remove calling plan")) {
if ($pscmdlet.ShouldProcess($Message, $ZoomUserInfo.email, "Remove calling plan: $CurrentLicense")) {
$response = Invoke-ZoomRestMethod -Uri $request.Uri -Method Delete

if (-not $PassThru) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Body:
$RequestBody
"@

if ($pscmdlet.ShouldProcess($Message, $User, "Remove $Number")) {
if ($pscmdlet.ShouldProcess($Message, $ZoomUserInfo.email, "Remove $($_.number)")) {
$response = Invoke-ZoomRestMethod -Uri $request.Uri -Method DELETE

if (-not $PassThru) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function Update-ZoomPhoneUserCallingPlan {
process {
foreach ($user in $UserId) {

$CurrentLicense = Get-ZoomPhoneUser -UserId $user | Select-Object -ExpandProperty "calling_plans" | Select-Object -ExpandProperty "type"
$ZoomUserInfo = Get-ZoomPhoneUser -UserId $user -ErrorAction Stop
$CurrentLicense = $ZoomUserInfo | Select-Object -ExpandProperty "calling_plans" | Select-Object -ExpandProperty "type"

$Request = [System.UriBuilder]"https://api.$ZoomURI/v2/phone/users/$user/calling_plans"
$RequestBody = @{ }
Expand All @@ -77,7 +78,7 @@ Body:
$RequestBody
"@

if ($pscmdlet.ShouldProcess($Message, $User, "Update calling plan")) {
if ($pscmdlet.ShouldProcess($Message, $ZoomUserInfo.email, "Update calling plan: $LicenseType")) {
$response = Invoke-ZoomRestMethod -Uri $request.Uri -Body $requestBody -Method PUT

if (-not $PassThru) {
Expand Down

0 comments on commit 22e3cb7

Please sign in to comment.