[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
|
||||
postReminderTask *model.ScheduledTask
|
||||
|
||||
// collectionTypes maps collection types array to the registering plugin
|
||||
collectionTypes map[string][]string
|
||||
// topicTypes maps topic types array to collection types
|
||||
topicTypes map[string][]string
|
||||
// collectionTypes maps from collection types to the registering plugin id
|
||||
collectionTypes map[string]string
|
||||
// topicTypes maps from topic types to collection types
|
||||
topicTypes map[string]string
|
||||
collectionAndTopicTypesMut sync.Mutex
|
||||
}
|
||||
|
||||
@@ -103,8 +103,8 @@ func NewChannels(s *Server, services map[ServiceKey]any) (*Channels, error) {
|
||||
srv: s,
|
||||
imageProxy: imageproxy.MakeImageProxy(s.platform, s.httpService, s.Log()),
|
||||
uploadLockMap: map[string]bool{},
|
||||
collectionTypes: map[string][]string{},
|
||||
topicTypes: map[string][]string{},
|
||||
collectionTypes: map[string]string{},
|
||||
topicTypes: map[string]string{},
|
||||
}
|
||||
|
||||
// To get another service:
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
"github.com/mattermost/mattermost-server/v6/utils"
|
||||
)
|
||||
|
||||
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()
|
||||
|
||||
// check if collectionType was already registered by other plugin
|
||||
for existingPluginID, existingCollectionTypes := range a.ch.collectionTypes {
|
||||
if existingPluginID != pluginID && utils.StringInSlice(collectionType, existingCollectionTypes) {
|
||||
return model.NewAppError("registerCollectionAndTopic", "app.collection.add_collection.exists.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
existingPluginID, ok := a.ch.collectionTypes[collectionType]
|
||||
if ok && existingPluginID != pluginID {
|
||||
return model.NewAppError("registerCollectionAndTopic", "app.collection.add_collection.exists.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
// check if topicType was already registered to other collection
|
||||
for existingCollectionType, existingTopicTypes := range a.ch.topicTypes {
|
||||
if existingCollectionType != collectionType && utils.StringInSlice(topicType, existingTopicTypes) {
|
||||
return model.NewAppError("registerCollectionAndTopic", "app.collection.add_topic.exists.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
existingCollectionType, ok := a.ch.topicTypes[topicType]
|
||||
if ok && existingCollectionType != collectionType {
|
||||
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.topicTypes[collectionType] = appendIfUnique(a.ch.topicTypes[collectionType], topicType)
|
||||
a.ch.collectionTypes[collectionType] = pluginID
|
||||
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))
|
||||
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 {
|
||||
for _, collectionType := range ch.collectionTypes[id] {
|
||||
delete(ch.topicTypes, collectionType)
|
||||
// find all collectionTypes registered by plugin
|
||||
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()
|
||||
if pluginsEnvironment == nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user