mirror of
https://github.com/github-tijlxyz/khatru-pyramid.git
synced 2025-06-23 16:05:28 +00:00
fix isAncestorOf() and remove button.
This commit is contained in:
parent
8885d99cac
commit
262d64ef40
@ -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+`"}`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
30
whitelist.go
30
whitelist.go
@ -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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user