From 6674ad4c9dd61b7d5702500eb4083939e7804b94 Mon Sep 17 00:00:00 2001 From: Codie Jones Date: Tue, 17 Aug 2021 12:30:13 -0700 Subject: [PATCH 1/2] feat(updatecustomerpowerusers): check plan total license pool and update if flag is passed --- src/index.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 2c513d8..040ff09 100644 --- a/src/index.ts +++ b/src/index.ts @@ -315,10 +315,14 @@ class Egnyte { * @param numOfUsers how many licenses to assign to customer * @returns response object */ - async updateCustomerPowerUsers(customerId: string, numOfUsers: number): Promise { + async updateCustomerPowerUsers( + customerId: string, + numOfUsers: number, + autoAddToPool?: boolean, + ): Promise { customerId = customerId.toLowerCase() const customer = await this.getOneCustomer(customerId) - if (customer.powerUsers.available <= 0) + if (customer.powerUsers.available <= 0 && !autoAddToPool) throw new Error('No available licenses on customers reseller plan.') if (numOfUsers < customer.powerUsers.used && this._config.forceLicenseChange !== true) { const response: EgnyteUpdateResponse = { @@ -333,6 +337,18 @@ class Egnyte { } return response } + if (autoAddToPool) { + const plans = await this.getPlans() + const { planId, totalPowerUsers, availablePowerUsers } = plans.find( + (e: any) => e.planId === customer.planId, + ) + const usersNeeded = numOfUsers - customer.powerUsers.total + if (usersNeeded > availablePowerUsers) { + const licensesToAdd = Math.ceil((usersNeeded - availablePowerUsers) / 5) * 5 + const updatedLicenesTotal = licensesToAdd + totalPowerUsers + this.UpdatePowerUserLicensing(planId, updatedLicenesTotal) + } + } const { authCookie, csrfToken } = await this._authenticate() const res = await this._egnyteRequest(`/msp/change_power_users/${this.resellerId}/`, { From dded07ec8207b9be0cb59c8c4771a5a7cdbba0f2 Mon Sep 17 00:00:00 2001 From: santese <43831817+santese@users.noreply.github.com> Date: Tue, 17 Aug 2021 13:01:37 -0700 Subject: [PATCH 2/2] Add referer and await --- src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 040ff09..03ee96c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -297,6 +297,7 @@ class Egnyte { Cookie: `${authCookie}; csrftoken=${csrfToken}`, 'X-Requested-With': 'XMLHttpRequest', 'X-CSRFToken': csrfToken, + Referer: 'https://resellers.egnyte.com', }, data: { plan_id: planId, @@ -346,7 +347,8 @@ class Egnyte { if (usersNeeded > availablePowerUsers) { const licensesToAdd = Math.ceil((usersNeeded - availablePowerUsers) / 5) * 5 const updatedLicenesTotal = licensesToAdd + totalPowerUsers - this.UpdatePowerUserLicensing(planId, updatedLicenesTotal) + + await this.UpdatePowerUserLicensing(planId, updatedLicenesTotal) } } const { authCookie, csrfToken } = await this._authenticate()