Skip to content

Commit 54c1fc4

Browse files
committed
fix: issue with keeping RPE state between tabs in cloud
1 parent 9ba37cd commit 54c1fc4

4 files changed

Lines changed: 82 additions & 8 deletions

File tree

src/app/devices/devices.service.spec.ts

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,14 @@ describe('DevicesService', () => {
587587

588588
const req = httpMock.expectOne(`${mockEnvironment.mpsServer}/api/v1/amt/features/device1`)
589589
expect(req.request.method).toBe('POST')
590-
expect(req.request.body).toEqual(payload)
590+
expect(req.request.body).toEqual({
591+
userConsent: 'none',
592+
enableKVM: true,
593+
enableSOL: true,
594+
enableIDER: true,
595+
ocr: true,
596+
platformEraseEnabled: true
597+
})
591598
req.flush(mockResponse)
592599
})
593600

@@ -652,6 +659,56 @@ describe('DevicesService', () => {
652659
expect((latest as any).status).toBeUndefined()
653660
})
654661

662+
it('keeps the cached rpe value when a stale GET response arrives after a save', () => {
663+
const seeded: AMTFeaturesResponse = {
664+
userConsent: 'none',
665+
optInState: 0,
666+
redirection: true,
667+
kvmAvailable: true,
668+
KVM: true,
669+
SOL: false,
670+
IDER: false,
671+
ocr: false,
672+
httpsBootSupported: true,
673+
winREBootSupported: true,
674+
localPBABootSupported: true,
675+
rpe: true,
676+
rpeSupported: true,
677+
pbaBootFilesPath: [],
678+
winREBootFilesPath: { instanceID: '', biosBootString: '', bootString: '' }
679+
}
680+
const emitted: AMTFeaturesResponse[] = []
681+
service.featuresChanges('device1').subscribe((v) => {
682+
if (v) emitted.push(v)
683+
})
684+
service.getAMTFeatures('device1').subscribe()
685+
httpMock.expectOne(`${mockEnvironment.mpsServer}/api/v1/amt/features/device1`).flush(seeded)
686+
687+
service
688+
.setAmtFeatures('device1', {
689+
userConsent: 'all',
690+
enableKVM: true,
691+
enableSOL: true,
692+
enableIDER: true,
693+
ocr: true,
694+
rpe: false
695+
})
696+
.subscribe()
697+
httpMock.expectOne(`${mockEnvironment.mpsServer}/api/v1/amt/features/device1`).flush({ status: 'SUCCESS' } as any)
698+
699+
let latestGet: AMTFeaturesResponse | undefined
700+
service.getAMTFeatures('device1').subscribe((r) => {
701+
latestGet = r
702+
})
703+
httpMock.expectOne(`${mockEnvironment.mpsServer}/api/v1/amt/features/device1`).flush({
704+
...seeded,
705+
rpe: true
706+
})
707+
708+
expect(emitted[emitted.length - 1].rpe).toBe(false)
709+
expect(latestGet?.rpe).toBe(false)
710+
})
711+
655712
it('derives redirection from the chosen features rather than keeping the stale cached value', () => {
656713
const seeded: AMTFeaturesResponse = {
657714
userConsent: 'none',

src/app/devices/devices.service.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,14 @@ export class DevicesService {
283283

284284
getAMTFeatures(guid: string): Observable<AMTFeaturesResponse> {
285285
return this.http.get<AMTFeaturesResponse>(`${environment.mpsServer}/api/v1/amt/features/${guid}`).pipe(
286-
tap((features) => this.getOrCreateFeaturesStream(guid).next(this.applyRpeOverride(guid, features))),
286+
map((features) => {
287+
const stream = this.getOrCreateFeaturesStream(guid)
288+
const current = stream.value
289+
const merged = current === null ? features : { ...features, rpe: current.rpe }
290+
const nextFeatures = this.applyRpeOverride(guid, merged)
291+
stream.next(nextFeatures)
292+
return nextFeatures
293+
}),
287294
catchError((err) => {
288295
throw err
289296
})
@@ -466,8 +473,16 @@ export class DevicesService {
466473
if (payload.rpe) {
467474
this.rpeDisabledAfterErase.delete(deviceId)
468475
}
476+
const requestBody = {
477+
userConsent: payload.userConsent,
478+
enableKVM: payload.enableKVM,
479+
enableSOL: payload.enableSOL,
480+
enableIDER: payload.enableIDER,
481+
ocr: payload.ocr,
482+
platformEraseEnabled: payload.rpe
483+
}
469484
return this.http
470-
.post<AMTFeaturesResponse>(`${environment.mpsServer}/api/v1/amt/features/${deviceId}`, payload)
485+
.post<AMTFeaturesResponse>(`${environment.mpsServer}/api/v1/amt/features/${deviceId}`, requestBody)
471486
.pipe(
472487
tap(() => this.applyFeaturesSelection(deviceId, payload)),
473488
catchError((err) => {

src/app/devices/general/general.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
[matTooltip]="'general.remotePlatformEraseNotSupported.value' | translate"
165165
[matTooltipDisabled]="!amtEnabledFeatures.get('rpe')?.disabled"
166166
matTooltipPosition="after">
167-
<mat-checkbox formControlName="rpe" (change)="setAmtFeatures()"></mat-checkbox>
167+
<mat-checkbox formControlName="rpe" (change)="setAmtFeatures({ rpe: $event.checked })"></mat-checkbox>
168168
</div>
169169
<div class="flex flex-50 items-end">
170170
<p>{{ 'general.ideRedirection.value' | translate }}</p>

src/app/devices/general/general.component.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,14 @@ export class GeneralComponent implements OnInit, OnDestroy {
189189
return !!(enableKVM || enableSOL || enableIDER)
190190
}
191191

192-
setAmtFeatures(): void {
192+
setAmtFeatures(override: Partial<AMTFeaturesRequest> = {}): void {
193193
this.isLoading.set(true)
194+
const payload = {
195+
...this.amtEnabledFeatures.getRawValue(),
196+
...override
197+
} as AMTFeaturesRequest
194198
this.devicesService
195-
.setAmtFeatures(this.deviceId(), {
196-
...this.amtEnabledFeatures.getRawValue()
197-
} as AMTFeaturesRequest)
199+
.setAmtFeatures(this.deviceId(), payload)
198200
.pipe(
199201
finalize(() => {
200202
this.isLoading.set(false)

0 commit comments

Comments
 (0)