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 a9a83df301)
This commit is contained in:
Alex Jbanca 2024-04-17 16:56:26 +03:00 committed by Alex Jbanca
parent 4a066a2f48
commit 5e33540307
2 changed files with 9 additions and 7 deletions

View File

@ -935,12 +935,13 @@ proc updateTokenPermissionModel*(self: Module, permissions: Table[string, CheckP
var updatedTokenCriteriaItems: seq[TokenCriteriaItem] = @[] var updatedTokenCriteriaItems: seq[TokenCriteriaItem] = @[]
var permissionSatisfied = true var permissionSatisfied = true
var aCriteriaChanged = false
for index, tokenCriteriaItem in tokenPermissionItem.getTokenCriteria().getItems(): for index, tokenCriteriaItem in tokenPermissionItem.getTokenCriteria().getItems():
let criteriaMet = criteriaResult.criteria[index] let criteriaMet = criteriaResult.criteria[index]
if tokenCriteriaItem.criteriaMet == criteriaMet: if tokenCriteriaItem.criteriaMet != criteriaMet:
continue aCriteriaChanged = true
let updatedTokenCriteriaItem = initTokenCriteriaItem( let updatedTokenCriteriaItem = initTokenCriteriaItem(
tokenCriteriaItem.symbol, tokenCriteriaItem.symbol,
@ -956,7 +957,7 @@ proc updateTokenPermissionModel*(self: Module, permissions: Table[string, CheckP
updatedTokenCriteriaItems.add(updatedTokenCriteriaItem) updatedTokenCriteriaItems.add(updatedTokenCriteriaItem)
if updatedTokenCriteriaItems.len == 0: if not aCriteriaChanged:
continue continue
thereWasAnUpdate = true thereWasAnUpdate = true

View File

@ -905,13 +905,13 @@ proc applyPermissionResponse*(self: Module, communityId: string, permissions: Ta
var updatedTokenCriteriaItems: seq[TokenCriteriaItem] = @[] var updatedTokenCriteriaItems: seq[TokenCriteriaItem] = @[]
var permissionSatisfied = true var permissionSatisfied = true
var aCriteriaChanged = false
for index, tokenCriteriaItem in tokenPermissionItem.getTokenCriteria().getItems(): for index, tokenCriteriaItem in tokenPermissionItem.getTokenCriteria().getItems():
let criteriaMet = criteriaResult.criteria[index] let criteriaMet = criteriaResult.criteria[index]
if tokenCriteriaItem.criteriaMet == criteriaMet: if tokenCriteriaItem.criteriaMet != criteriaMet:
continue aCriteriaChanged = true
let updatedTokenCriteriaItem = initTokenCriteriaItem( let updatedTokenCriteriaItem = initTokenCriteriaItem(
tokenCriteriaItem.symbol, tokenCriteriaItem.symbol,
@ -927,8 +927,9 @@ proc applyPermissionResponse*(self: Module, communityId: string, permissions: Ta
updatedTokenCriteriaItems.add(updatedTokenCriteriaItem) updatedTokenCriteriaItems.add(updatedTokenCriteriaItem)
if updatedTokenCriteriaItems.len == 0: if not aCriteriaChanged:
continue continue
let updatedTokenPermissionItem = initTokenPermissionItem( let updatedTokenPermissionItem = initTokenPermissionItem(
tokenPermissionItem.id, tokenPermissionItem.id,
tokenPermissionItem.`type`, tokenPermissionItem.`type`,