2024-01-02 17:23:34 -03:00
|
|
|
package nip29
|
|
|
|
|
|
|
|
import (
|
2024-02-08 16:33:39 -03:00
|
|
|
"slices"
|
|
|
|
|
2024-01-02 17:23:34 -03:00
|
|
|
"github.com/nbd-wtf/go-nostr"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Role struct {
|
|
|
|
Name string
|
|
|
|
Permissions map[Permission]struct{}
|
|
|
|
}
|
|
|
|
|
2024-01-04 11:29:21 -03:00
|
|
|
type Permission string
|
2024-01-02 17:23:34 -03:00
|
|
|
|
|
|
|
const (
|
2024-09-14 00:03:33 -03:00
|
|
|
PermAddUser Permission = "add-user"
|
|
|
|
PermEditMetadata Permission = "edit-metadata"
|
|
|
|
PermDeleteEvent Permission = "delete-event"
|
|
|
|
PermRemoveUser Permission = "remove-user"
|
|
|
|
PermAddPermission Permission = "add-permission"
|
|
|
|
PermRemovePermission Permission = "remove-permission"
|
|
|
|
PermEditGroupStatus Permission = "edit-group-status"
|
|
|
|
PermDeleteGroup Permission = "delete-group"
|
2024-01-02 17:23:34 -03:00
|
|
|
)
|
|
|
|
|
|
|
|
type KindRange []int
|
|
|
|
|
2024-01-04 11:33:17 -03:00
|
|
|
var ModerationEventKinds = KindRange{
|
|
|
|
nostr.KindSimpleGroupAddUser,
|
|
|
|
nostr.KindSimpleGroupRemoveUser,
|
|
|
|
nostr.KindSimpleGroupEditMetadata,
|
|
|
|
nostr.KindSimpleGroupAddPermission,
|
|
|
|
nostr.KindSimpleGroupRemovePermission,
|
|
|
|
nostr.KindSimpleGroupDeleteEvent,
|
|
|
|
nostr.KindSimpleGroupEditGroupStatus,
|
2024-07-03 22:17:43 -03:00
|
|
|
nostr.KindSimpleGroupCreateGroup,
|
2024-08-19 17:23:54 +09:00
|
|
|
nostr.KindSimpleGroupDeleteGroup,
|
2024-01-04 11:33:17 -03:00
|
|
|
}
|
2024-01-02 17:23:34 -03:00
|
|
|
|
|
|
|
var MetadataEventKinds = KindRange{
|
|
|
|
nostr.KindSimpleGroupMetadata,
|
|
|
|
nostr.KindSimpleGroupAdmins,
|
|
|
|
nostr.KindSimpleGroupMembers,
|
|
|
|
}
|
|
|
|
|
|
|
|
func (kr KindRange) Includes(kind int) bool {
|
|
|
|
_, ok := slices.BinarySearch(kr, kind)
|
|
|
|
return ok
|
|
|
|
}
|
2024-01-04 11:48:53 -03:00
|
|
|
|
|
|
|
var (
|
|
|
|
// used for normal members without admin powers
|
|
|
|
EmptyRole *Role = nil
|
|
|
|
|
|
|
|
PermissionsMap = map[Permission]struct{}{
|
|
|
|
PermAddUser: {},
|
|
|
|
PermEditMetadata: {},
|
|
|
|
PermDeleteEvent: {},
|
|
|
|
PermRemoveUser: {},
|
|
|
|
PermAddPermission: {},
|
|
|
|
PermRemovePermission: {},
|
|
|
|
PermEditGroupStatus: {},
|
|
|
|
}
|
|
|
|
)
|