mirror of
https://github.com/status-im/status-go.git
synced 2026-08-31 09:01:16 +00:00
Part of the Go project layout migration, item 27. Pure move plus import-path rewrite across 502 files. No API or behaviour change. `internal/` keeps the messaging application logic unimportable from outside the module, which is what the issue asks for -- status-go is consumed through the C-bindings in mobile/, not as a Go library. Things that had to follow the move, beyond the Go imports: - tools/generate-handlers/template.txt. messenger_handlers.go is generated, and the template hard-codes the imports it emits, so the generated file kept importing protocol/common and failed typecheck. - .gitignore. The ignore rule for that generated file was pinned to the old path; without moving it, a 1486-line generated file starts being tracked. - Makefile: the logosstorage and torrent test targets (both the archive packages and ./protocol itself), the archive README, migration-protocol. - scripts/run_unit_tests.sh, which names the protocol package explicitly to shard its tests. - scripts/cleanup_generated_files.sh and .golangci.yml. scripts/migration_check.sh also needed a fix that is not specific to this move: it validated every file the branch touched under a migration dir against the timestamp naming rule, and a directory rename makes every migration in it look newly added. It now excludes renames, so moving a migration is not mistaken for adding one. refs #7067
84 lines
2.0 KiB
Go
84 lines
2.0 KiB
Go
package communities
|
|
|
|
import (
|
|
"github.com/status-im/status-go/internal/protocol/protobuf"
|
|
"github.com/status-im/status-go/internal/protocol/requests"
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
if len(chat.CategoryId) != 0 {
|
|
if _, exists := desc.Categories[chat.CategoryId]; !exists {
|
|
return ErrInvalidCommunityDescriptionUnknownChatCategory
|
|
}
|
|
}
|
|
|
|
if chat.Identity == nil {
|
|
return ErrInvalidCommunityDescriptionChatIdentity
|
|
}
|
|
|
|
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 validateCommunityCategory(category *protobuf.CommunityCategory) error {
|
|
if len(category.CategoryId) == 0 {
|
|
return ErrInvalidCommunityDescriptionCategoryNoID
|
|
}
|
|
|
|
if len(category.Name) == 0 {
|
|
return ErrInvalidCommunityDescriptionCategoryNoName
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
valid := requests.ValidateTags(desc.Tags)
|
|
if !valid {
|
|
return ErrInvalidCommunityTags
|
|
}
|
|
|
|
for _, category := range desc.Categories {
|
|
if err := validateCommunityCategory(category); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
for _, chat := range desc.Chats {
|
|
if err := validateCommunityChat(desc, chat); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|