fix isAncestorOf() and remove button.

This commit is contained in:
fiatjaf 2023-11-02 21:08:57 -03:00
parent 8885d99cac
commit 262d64ef40
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
2 changed files with 15 additions and 17 deletions

View File

@ -27,7 +27,7 @@ func userRowComponent(ctx context.Context, profile sdk.ProfileMetadata, loggedUs
"hx-post", "/remove-from-whitelist", "hx-post", "/remove-from-whitelist",
"hx-trigger", "click", "hx-trigger", "click",
"hx-target", "#tree", "hx-target", "#tree",
"hx-vals", `{"profile.pubkey": "`+profile.PubKey+`"}`, "hx-vals", `{"pubkey": "`+profile.PubKey+`"}`,
) )
} }

View File

@ -34,23 +34,21 @@ func isPublicKeyInWhitelist(pubkey string) bool {
return ok return ok
} }
func isAncestorOf(pubkey string, target string) bool { func isAncestorOf(ancestor string, target string) bool {
ancestor := target // we must find out if we are an ancestor of the target, but we can delete ourselves parent, ok := whitelist[target]
for { if !ok {
if ancestor == pubkey { // parent is not in whitelist, this means this is a top-level user and can
break // only be deleted by manually editing the users.json file
} return false
parent, ok := whitelist[ancestor]
if !ok {
// parent is not in whitelist, this means this is a top-level user and can
// only be deleted by manually editing the users.json file
return false
}
ancestor = parent
} }
return true
if parent == ancestor {
// if the pubkey is the parent, that means it is an ancestor
return true
}
// otherwise we climb one degree up and test with the parent of the target
return isAncestorOf(ancestor, parent)
} }
func removeFromWhitelist(target string, deleter string) error { func removeFromWhitelist(target string, deleter string) error {