[MM-48161] Change data types for collections and topics (#21634)
* Change data types for collections and topics * Address suggestions Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2171ad8abf
Коммит
9f9e19e05d
@@ -78,10 +78,10 @@ type Channels struct {
|
|||||||
postReminderMut sync.Mutex
|
postReminderMut sync.Mutex
|
||||||
postReminderTask *model.ScheduledTask
|
postReminderTask *model.ScheduledTask
|
||||||
|
|
||||||
// collectionTypes maps collection types array to the registering plugin
|
// collectionTypes maps from collection types to the registering plugin id
|
||||||
collectionTypes map[string][]string
|
collectionTypes map[string]string
|
||||||
// topicTypes maps topic types array to collection types
|
// topicTypes maps from topic types to collection types
|
||||||
topicTypes map[string][]string
|
topicTypes map[string]string
|
||||||
collectionAndTopicTypesMut sync.Mutex
|
collectionAndTopicTypesMut sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,8 +103,8 @@ func NewChannels(s *Server, services map[ServiceKey]any) (*Channels, error) {
|
|||||||
srv: s,
|
srv: s,
|
||||||
imageProxy: imageproxy.MakeImageProxy(s.platform, s.httpService, s.Log()),
|
imageProxy: imageproxy.MakeImageProxy(s.platform, s.httpService, s.Log()),
|
||||||
uploadLockMap: map[string]bool{},
|
uploadLockMap: map[string]bool{},
|
||||||
collectionTypes: map[string][]string{},
|
collectionTypes: map[string]string{},
|
||||||
topicTypes: map[string][]string{},
|
topicTypes: map[string]string{},
|
||||||
}
|
}
|
||||||
|
|
||||||
// To get another service:
|
// To get another service:
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
|
|
||||||
"github.com/mattermost/mattermost-server/v6/model"
|
"github.com/mattermost/mattermost-server/v6/model"
|
||||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||||
"github.com/mattermost/mattermost-server/v6/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a *App) registerCollectionAndTopic(pluginID, collectionType, topicType string) error {
|
func (a *App) registerCollectionAndTopic(pluginID, collectionType, topicType string) error {
|
||||||
@@ -17,29 +16,20 @@ func (a *App) registerCollectionAndTopic(pluginID, collectionType, topicType str
|
|||||||
defer a.ch.collectionAndTopicTypesMut.Unlock()
|
defer a.ch.collectionAndTopicTypesMut.Unlock()
|
||||||
|
|
||||||
// check if collectionType was already registered by other plugin
|
// check if collectionType was already registered by other plugin
|
||||||
for existingPluginID, existingCollectionTypes := range a.ch.collectionTypes {
|
existingPluginID, ok := a.ch.collectionTypes[collectionType]
|
||||||
if existingPluginID != pluginID && utils.StringInSlice(collectionType, existingCollectionTypes) {
|
if ok && existingPluginID != pluginID {
|
||||||
return model.NewAppError("registerCollectionAndTopic", "app.collection.add_collection.exists.app_error", nil, "", http.StatusBadRequest)
|
return model.NewAppError("registerCollectionAndTopic", "app.collection.add_collection.exists.app_error", nil, "", http.StatusBadRequest)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if topicType was already registered to other collection
|
// check if topicType was already registered to other collection
|
||||||
for existingCollectionType, existingTopicTypes := range a.ch.topicTypes {
|
existingCollectionType, ok := a.ch.topicTypes[topicType]
|
||||||
if existingCollectionType != collectionType && utils.StringInSlice(topicType, existingTopicTypes) {
|
if ok && existingCollectionType != collectionType {
|
||||||
return model.NewAppError("registerCollectionAndTopic", "app.collection.add_topic.exists.app_error", nil, "", http.StatusBadRequest)
|
return model.NewAppError("registerCollectionAndTopic", "app.collection.add_topic.exists.app_error", nil, "", http.StatusBadRequest)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
a.ch.collectionTypes[pluginID] = appendIfUnique(a.ch.collectionTypes[pluginID], collectionType)
|
a.ch.collectionTypes[collectionType] = pluginID
|
||||||
a.ch.topicTypes[collectionType] = appendIfUnique(a.ch.topicTypes[collectionType], topicType)
|
a.ch.topicTypes[topicType] = collectionType
|
||||||
|
|
||||||
a.ch.srv.Log().Info("registered collection and topic type", mlog.String("plugin_id", pluginID), mlog.String("collection_type", collectionType), mlog.String("topic_type", topicType))
|
a.ch.srv.Log().Info("registered collection and topic type", mlog.String("plugin_id", pluginID), mlog.String("collection_type", collectionType), mlog.String("topic_type", topicType))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendIfUnique(slice []string, a string) []string {
|
|
||||||
if utils.StringInSlice(a, slice) {
|
|
||||||
return slice
|
|
||||||
}
|
|
||||||
return append(slice, a)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -486,10 +486,19 @@ func (a *App) DisablePlugin(id string) *model.AppError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ch *Channels) disablePlugin(id string) *model.AppError {
|
func (ch *Channels) disablePlugin(id string) *model.AppError {
|
||||||
for _, collectionType := range ch.collectionTypes[id] {
|
// find all collectionTypes registered by plugin
|
||||||
delete(ch.topicTypes, collectionType)
|
for collectionTypeToRemove, existingPluginId := range ch.collectionTypes {
|
||||||
|
if existingPluginId != id {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// find all topicTypes for existing collectionType
|
||||||
|
for topicTypeToRemove, existingCollectionType := range ch.topicTypes {
|
||||||
|
if existingCollectionType == collectionTypeToRemove {
|
||||||
|
delete(ch.topicTypes, topicTypeToRemove)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete(ch.collectionTypes, collectionTypeToRemove)
|
||||||
}
|
}
|
||||||
delete(ch.collectionTypes, id)
|
|
||||||
|
|
||||||
pluginsEnvironment := ch.GetPluginsEnvironment()
|
pluginsEnvironment := ch.GetPluginsEnvironment()
|
||||||
if pluginsEnvironment == nil {
|
if pluginsEnvironment == nil {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user