@@ -371,17 +371,28 @@ export class SaveToOneNote {
371
371
} ) ;
372
372
}
373
373
374
- private static checkIfUserHasPermissionToPatch ( ) : Promise < any > {
375
- let patchPermissionCheckEvent = new Log . Event . PromiseEvent ( Log . Event . Label . PatchPermissionCheck ) ;
374
+ private static checkIfUserHasPermissionToPatch ( ) : Promise < void > {
376
375
return new Promise < any > ( ( resolve , reject ) => {
377
- SaveToOneNote . getPages ( { top : 1 , sectionId : this . clipperState . saveLocation } ) . then ( ( getPagesResponse ) => {
378
- resolve ( getPagesResponse ) ;
379
- } , ( error ) => {
380
- patchPermissionCheckEvent . setStatus ( Log . Status . Failed ) ;
381
- patchPermissionCheckEvent . setFailureInfo ( { error : error } ) ;
382
- reject ( error ) ;
383
- } ) . then ( ( ) => {
384
- Clipper . logger . logEvent ( patchPermissionCheckEvent ) ;
376
+ Clipper . getStoredValue ( ClipperStorageKeys . hasPatchPermissions , ( hasPermissions ) => {
377
+ // We have checked their permissions successfully in the past, or the user signed in on this device (with the latest scope)
378
+ if ( hasPermissions ) {
379
+ resolve ( ) ;
380
+ } else {
381
+ // As of v3.2.9, we have added a new scope for MSA to allow for PATCHing, however currently-logged-in users will not have
382
+ // this scope, so this call is a workaround to check for permissions, but is very unperformant. We need to investigate a
383
+ // quicker way of doing this ... perhaps exposing an endpoint that we can use for this sole purpose.
384
+ let patchPermissionCheckEvent = new Log . Event . PromiseEvent ( Log . Event . Label . PatchPermissionCheck ) ;
385
+ SaveToOneNote . getPages ( { top : 1 , sectionId : this . clipperState . saveLocation } ) . then ( ( ) => {
386
+ Clipper . storeValue ( ClipperStorageKeys . hasPatchPermissions , "true" ) ;
387
+ resolve ( ) ;
388
+ } , ( error ) => {
389
+ patchPermissionCheckEvent . setStatus ( Log . Status . Failed ) ;
390
+ patchPermissionCheckEvent . setFailureInfo ( { error : error } ) ;
391
+ reject ( error ) ;
392
+ } ) . then ( ( ) => {
393
+ Clipper . logger . logEvent ( patchPermissionCheckEvent ) ;
394
+ } ) ;
395
+ }
385
396
} ) ;
386
397
} ) ;
387
398
}
0 commit comments