Merge pull request #3000 from dpalou/MOBILE-3695
MOBILE-3695 push: Allow unregister device when site logged out
This commit is contained in:
		
						commit
						4fa1d72a2b
					
				| @ -51,6 +51,11 @@ export enum CoreSiteQRCodeType { | ||||
|     QR_CODE_LOGIN = 2, // QR code type login value
 | ||||
| } | ||||
| 
 | ||||
| // WS that we allow to call even if the site is logged out.
 | ||||
| const ALLOWED_LOGGEDOUT_WS = [ | ||||
|     'core_user_remove_user_device', | ||||
| ]; | ||||
| 
 | ||||
| /** | ||||
|  * Class that represents a site (combination of site + user). | ||||
|  * It will have all the site data and provide utility functions regarding a site. | ||||
| @ -496,7 +501,7 @@ export class CoreSite { | ||||
|      */ | ||||
|     // eslint-disable-next-line @typescript-eslint/no-explicit-any
 | ||||
|     async request<T = unknown>(method: string, data: any, preSets: CoreSiteWSPreSets, retrying?: boolean): Promise<T> { | ||||
|         if (this.isLoggedOut()) { | ||||
|         if (this.isLoggedOut() && !ALLOWED_LOGGEDOUT_WS.includes(method)) { | ||||
|             // Site is logged out, it cannot call WebServices.
 | ||||
|             CoreEvents.trigger(CoreEvents.SESSION_EXPIRED, {}, this.id); | ||||
| 
 | ||||
|  | ||||
| @ -519,20 +519,10 @@ export class CorePushNotificationsProvider { | ||||
|             appid: CoreConstants.CONFIG.app_id, | ||||
|             uuid:  Device.uuid, | ||||
|         }; | ||||
|         let response: CoreUserRemoveUserDeviceWSResponse; | ||||
| 
 | ||||
|         try { | ||||
|             const response = await site.write<CoreUserRemoveUserDeviceWSResponse>('core_user_remove_user_device', data); | ||||
| 
 | ||||
|             if (!response || !response.removed) { | ||||
|                 throw new CoreError('Cannot unregister device'); | ||||
|             } | ||||
| 
 | ||||
|             await CoreUtils.ignoreErrors(Promise.all([ | ||||
|                 // Remove the device from the local DB.
 | ||||
|                 site.getDb().deleteRecords(REGISTERED_DEVICES_TABLE_NAME, this.getRegisterData()), | ||||
|                 // Remove pending unregisters for this site.
 | ||||
|                 db.deleteRecords(PENDING_UNREGISTER_TABLE_NAME, { siteid: site.getId() }), | ||||
|             ])); | ||||
|             response = await site.write<CoreUserRemoveUserDeviceWSResponse>('core_user_remove_user_device', data); | ||||
|         } catch (error) { | ||||
|             if (CoreUtils.isWebServiceError(error)) { | ||||
|                 throw error; | ||||
| @ -546,7 +536,20 @@ export class CorePushNotificationsProvider { | ||||
|                 info: JSON.stringify(site.getInfo()), | ||||
|             }; | ||||
|             await db.insertRecord(PENDING_UNREGISTER_TABLE_NAME, entry); | ||||
| 
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         if (!response.removed) { | ||||
|             throw new CoreError('Cannot unregister device'); | ||||
|         } | ||||
| 
 | ||||
|         await CoreUtils.ignoreErrors(Promise.all([ | ||||
|             // Remove the device from the local DB.
 | ||||
|             site.getDb().deleteRecords(REGISTERED_DEVICES_TABLE_NAME, this.getRegisterData()), | ||||
|             // Remove pending unregisters for this site.
 | ||||
|             db.deleteRecords(PENDING_UNREGISTER_TABLE_NAME, { siteid: site.getId() }), | ||||
|         ])); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user