Add Options field to RemoteClusters (#25771)

* add Option flag to RemoteClusters

* add Options column to RemoteClusters table
Этот коммит содержится в:
Doug Lauder
2023-12-19 13:01:35 -05:00
коммит произвёл GitHub
родитель f118b4f0ed
Коммит d56dc9d0ce
8 изменённых файлов: 102 добавлений и 15 удалений

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

@@ -21,25 +21,30 @@ const (
RemoteOfflineAfterMillis = 1000 * 60 * 5 // 5 minutes
RemoteNameMinLength = 1
RemoteNameMaxLength = 64
BitflagOptionAutoShareDMs Bitmask = 1 << iota
)
var (
validRemoteNameChars = regexp.MustCompile(`^[a-zA-Z0-9\.\-\_]+$`)
)
type Bitmask uint32
type RemoteCluster struct {
RemoteId string `json:"remote_id"`
RemoteTeamId string `json:"remote_team_id"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
SiteURL string `json:"site_url"`
CreateAt int64 `json:"create_at"`
LastPingAt int64 `json:"last_ping_at"`
Token string `json:"token"`
RemoteToken string `json:"remote_token"`
Topics string `json:"topics"`
CreatorId string `json:"creator_id"`
PluginID string `json:"plugin_id"` // non-empty when sync message are to be delivered via plugin API
RemoteId string `json:"remote_id"`
RemoteTeamId string `json:"remote_team_id"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
SiteURL string `json:"site_url"`
CreateAt int64 `json:"create_at"`
LastPingAt int64 `json:"last_ping_at"`
Token string `json:"token"`
RemoteToken string `json:"remote_token"`
Topics string `json:"topics"`
CreatorId string `json:"creator_id"`
PluginID string `json:"plugin_id"` // non-empty when sync message are to be delivered via plugin API
Options Bitmask `json:"options"` // bit-flag set of options
}
func (rc *RemoteCluster) Auditable() map[string]interface{} {
@@ -53,6 +58,7 @@ func (rc *RemoteCluster) Auditable() map[string]interface{} {
"last_ping_at": rc.LastPingAt,
"creator_id": rc.CreatorId,
"plugin_id": rc.PluginID,
"options": rc.Options,
}
}
@@ -98,6 +104,18 @@ func (rc *RemoteCluster) IsValid() *AppError {
return nil
}
func (rc *RemoteCluster) IsOptionFlagSet(flag Bitmask) bool {
return rc.Options&flag != 0
}
func (rc *RemoteCluster) SetOptionFlag(flag Bitmask) {
rc.Options |= flag
}
func (rc *RemoteCluster) UnsetOptionFlag(flag Bitmask) {
rc.Options &= ^flag
}
func IsValidRemoteName(s string) bool {
if len(s) < RemoteNameMinLength || len(s) > RemoteNameMaxLength {
return false