MM-57786 Fix Shared Channels plugin api (#26753)

* always ping on plugin registration; SharedChannel.IsValid allow no team for GM

* wait for services to start before ping

* ping plugin remotes synchronously on startup

* remove the waitForInterClusterServices stuff

* don't set remoteid when inviting remote to channel

* Update server/public/model/remote_cluster_test.go

Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>

* address review comments

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Этот коммит содержится в:
Doug Lauder
2024-04-15 16:18:25 -04:00
коммит произвёл GitHub
родитель 9e8f9a3715
Коммит 6aaabfb376
13 изменённых файлов: 152 добавлений и 32 удалений

Просмотреть файл

@@ -6,7 +6,9 @@ package model
import (
"crypto/aes"
"crypto/cipher"
"crypto/md5"
"crypto/rand"
"encoding/base32"
"encoding/json"
"errors"
"io"
@@ -80,7 +82,11 @@ func (rc *RemoteCluster) Auditable() map[string]interface{} {
func (rc *RemoteCluster) PreSave() {
if rc.RemoteId == "" {
rc.RemoteId = NewId()
if rc.PluginID != "" {
rc.RemoteId = newIDFromBytes([]byte(rc.PluginID))
} else {
rc.RemoteId = NewId()
}
}
if rc.DisplayName == "" {
@@ -120,6 +126,16 @@ func (rc *RemoteCluster) IsValid() *AppError {
return nil
}
func newIDFromBytes(b []byte) string {
hash := md5.New()
_, _ = hash.Write(b)
buf := hash.Sum(nil)
var encoding = base32.NewEncoding("ybndrfg8ejkmcpqxot1uwisza345h769").WithPadding(base32.NoPadding)
id := encoding.EncodeToString(buf)
return id[:26]
}
func (rc *RemoteCluster) IsOptionFlagSet(flag Bitmask) bool {
return rc.Options.IsBitSet(flag)
}
@@ -385,5 +401,6 @@ type RemoteClusterQueryFilter struct {
CreatorId string
OnlyConfirmed bool
PluginID string
OnlyPlugins bool
RequireOptions Bitmask
}

Просмотреть файл

@@ -136,3 +136,25 @@ func makeInvite(url string) RemoteClusterInvite {
Token: NewId(),
}
}
func TestNewIDFromBytes(t *testing.T) {
tests := []struct {
name string
ss string
}{
{name: "empty", ss: ""},
{name: "very short", ss: "x"},
{name: "normal", ss: "com.mattermost.msteams-sync"},
{name: "long", ss: "com.mattermost.msteams-synccom.mattermost.msteams-synccom.mattermost.msteams-synccom.mattermost.msteams-sync"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got1 := newIDFromBytes([]byte(tt.ss))
assert.True(t, IsValidId(got1), "not a valid id")
got2 := newIDFromBytes([]byte(tt.ss))
assert.Equal(t, got1, got2, "newIDFromBytes must generate same id for same inputs")
})
}
}

Просмотреть файл

@@ -42,7 +42,7 @@ func (sc *SharedChannel) IsValid() *AppError {
return NewAppError("SharedChannel.IsValid", "model.channel.is_valid.id.app_error", nil, "ChannelId="+sc.ChannelId, http.StatusBadRequest)
}
if sc.Type != ChannelTypeDirect && !IsValidId(sc.TeamId) {
if sc.Type != ChannelTypeDirect && sc.Type != ChannelTypeGroup && !IsValidId(sc.TeamId) {
return NewAppError("SharedChannel.IsValid", "model.channel.is_valid.id.app_error", nil, "TeamId="+sc.TeamId, http.StatusBadRequest)
}