From 5e33540307b8afca37f55f491cf745957422ed42 Mon Sep 17 00:00:00 2001 From: Alex Jbanca Date: Wed, 17 Apr 2024 16:56:26 +0300 Subject: [PATCH] fix(CommunityPermissions): Fix token criteria updates in the permissions model Re-create the token criteria and include all items whenever the model changes. The previous perf optimisation fix filtered the items where the criteriaMet doesn't change. (cherry picked from commit a9a83df301f2b2b6b20e255b699dd56dcb0c4a73) --- src/app/modules/main/chat_section/module.nim | 7 ++++--- src/app/modules/main/communities/module.nim | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index a712a82b24..50fd1fc545 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -935,12 +935,13 @@ proc updateTokenPermissionModel*(self: Module, permissions: Table[string, CheckP var updatedTokenCriteriaItems: seq[TokenCriteriaItem] = @[] var permissionSatisfied = true + var aCriteriaChanged = false for index, tokenCriteriaItem in tokenPermissionItem.getTokenCriteria().getItems(): let criteriaMet = criteriaResult.criteria[index] - if tokenCriteriaItem.criteriaMet == criteriaMet: - continue + if tokenCriteriaItem.criteriaMet != criteriaMet: + aCriteriaChanged = true let updatedTokenCriteriaItem = initTokenCriteriaItem( tokenCriteriaItem.symbol, @@ -956,7 +957,7 @@ proc updateTokenPermissionModel*(self: Module, permissions: Table[string, CheckP updatedTokenCriteriaItems.add(updatedTokenCriteriaItem) - if updatedTokenCriteriaItems.len == 0: + if not aCriteriaChanged: continue thereWasAnUpdate = true diff --git a/src/app/modules/main/communities/module.nim b/src/app/modules/main/communities/module.nim index 816b82f1f3..6e0c0e74b8 100644 --- a/src/app/modules/main/communities/module.nim +++ b/src/app/modules/main/communities/module.nim @@ -905,13 +905,13 @@ proc applyPermissionResponse*(self: Module, communityId: string, permissions: Ta var updatedTokenCriteriaItems: seq[TokenCriteriaItem] = @[] var permissionSatisfied = true + var aCriteriaChanged = false for index, tokenCriteriaItem in tokenPermissionItem.getTokenCriteria().getItems(): let criteriaMet = criteriaResult.criteria[index] - if tokenCriteriaItem.criteriaMet == criteriaMet: - continue - + if tokenCriteriaItem.criteriaMet != criteriaMet: + aCriteriaChanged = true let updatedTokenCriteriaItem = initTokenCriteriaItem( tokenCriteriaItem.symbol, @@ -927,8 +927,9 @@ proc applyPermissionResponse*(self: Module, communityId: string, permissions: Ta updatedTokenCriteriaItems.add(updatedTokenCriteriaItem) - if updatedTokenCriteriaItems.len == 0: + if not aCriteriaChanged: continue + let updatedTokenPermissionItem = initTokenPermissionItem( tokenPermissionItem.id, tokenPermissionItem.`type`,