mirror of
https://github.com/github-tijlxyz/khatru-pyramid.git
synced 2025-04-23 01:01:24 +00:00
39 lines
1010 B
Go
39 lines
1010 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/fiatjaf/khatru"
|
|
)
|
|
|
|
func allowPubKeyHandler(ctx context.Context, pubkey, reason string) error {
|
|
loggedUser := khatru.GetAuthed(ctx)
|
|
|
|
if loggedUser != s.RelayPubkey && hasInvitedAtLeast(loggedUser, s.MaxInvitesPerPerson) {
|
|
return fmt.Errorf("cannot invite more than %d", s.MaxInvitesPerPerson)
|
|
}
|
|
if err := addToWhitelist(pubkey, loggedUser); err != nil {
|
|
return fmt.Errorf("failed to add to whitelist: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func banPubKeyHandler(ctx context.Context, pubkey, reason string) error {
|
|
loggedUser := khatru.GetAuthed(ctx)
|
|
|
|
// check if this user is a descendant of the user who issued the delete command
|
|
if !isAncestorOf(loggedUser, pubkey) {
|
|
return fmt.Errorf("insufficient permissions to delete this")
|
|
}
|
|
|
|
// if we got here that means we have permission to delete the target
|
|
delete(whitelist, pubkey)
|
|
|
|
// delete all people who were invited by the target
|
|
removeDescendantsFromWhitelist(pubkey)
|
|
|
|
return saveWhitelist()
|
|
}
|