-
Notifications
You must be signed in to change notification settings - Fork 246
/
validator.go
49 lines (42 loc) · 1.24 KB
/
validator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package communities
import (
"github.com/status-im/status-go/protocol/protobuf"
)
func validateCommunityChat(desc *protobuf.CommunityDescription, chat *protobuf.CommunityChat) error {
if chat == nil {
return ErrInvalidCommunityDescription
}
if chat.Permissions == nil {
return ErrInvalidCommunityDescriptionNoChatPermissions
}
if chat.Permissions.Access == protobuf.CommunityPermissions_UNKNOWN_ACCESS {
return ErrInvalidCommunityDescriptionUnknownChatAccess
}
for pk := range chat.Members {
if desc.Members == nil {
return ErrInvalidCommunityDescriptionMemberInChatButNotInOrg
}
// Check member is in the org as well
if _, ok := desc.Members[pk]; !ok {
return ErrInvalidCommunityDescriptionMemberInChatButNotInOrg
}
}
return nil
}
func ValidateCommunityDescription(desc *protobuf.CommunityDescription) error {
if desc == nil {
return ErrInvalidCommunityDescription
}
if desc.Permissions == nil {
return ErrInvalidCommunityDescriptionNoOrgPermissions
}
if desc.Permissions.Access == protobuf.CommunityPermissions_UNKNOWN_ACCESS {
return ErrInvalidCommunityDescriptionUnknownOrgAccess
}
for _, chat := range desc.Chats {
if err := validateCommunityChat(desc, chat); err != nil {
return err
}
}
return nil
}