diff --git a/server/channels/app/shared_channel.go b/server/channels/app/shared_channel.go index 71d2252178..7cb7a27ead 100644 --- a/server/channels/app/shared_channel.go +++ b/server/channels/app/shared_channel.go @@ -16,12 +16,16 @@ import ( "github.com/mattermost/mattermost/server/v8/channels/store" ) -func (a *App) getSharedChannelsService() (SharedChannelServiceIFace, error) { +func (a *App) getSharedChannelsService(ensureIsActive bool) (SharedChannelServiceIFace, error) { scService := a.Srv().GetSharedChannelSyncService() - if scService == nil || !scService.Active() { + if scService == nil { return nil, model.NewAppError("getSharedChannelsService", "api.command_share.service_disabled", nil, "", http.StatusBadRequest) } + if ensureIsActive && !scService.Active() { + return nil, model.NewAppError("getSharedChannelsService", "api.command_share.service_inactive", + nil, "", http.StatusInternalServerError) + } return scService, nil } @@ -51,7 +55,7 @@ func (a *App) checkChannelIsShared(channelId string) error { } func (a *App) CheckCanInviteToSharedChannel(channelId string) error { - scService, err := a.getSharedChannelsService() + scService, err := a.getSharedChannelsService(false) if err != nil { return err } @@ -61,7 +65,7 @@ func (a *App) CheckCanInviteToSharedChannel(channelId string) error { // SharedChannels func (a *App) ShareChannel(c request.CTX, sc *model.SharedChannel) (*model.SharedChannel, error) { - scService, err := a.getSharedChannelsService() + scService, err := a.getSharedChannelsService(false) if err != nil { return nil, err } @@ -89,7 +93,7 @@ func (a *App) GetSharedChannelsCount(opts model.SharedChannelFilterOpts) (int64, } func (a *App) UpdateSharedChannel(sc *model.SharedChannel) (*model.SharedChannel, error) { - scService, err := a.getSharedChannelsService() + scService, err := a.getSharedChannelsService(false) if err != nil { return nil, err } @@ -97,7 +101,7 @@ func (a *App) UpdateSharedChannel(sc *model.SharedChannel) (*model.SharedChannel } func (a *App) UnshareChannel(channelID string) (bool, error) { - scService, err := a.getSharedChannelsService() + scService, err := a.getSharedChannelsService(false) if err != nil { return false, err } @@ -107,7 +111,7 @@ func (a *App) UnshareChannel(channelID string) (bool, error) { // SharedChannelRemotes func (a *App) InviteRemoteToChannel(channelID, remoteID, userID string, shareIfNotShared bool) error { - ssService, err := a.getSharedChannelsService() + ssService, err := a.getSharedChannelsService(false) if err != nil { return err } @@ -115,7 +119,7 @@ func (a *App) InviteRemoteToChannel(channelID, remoteID, userID string, shareIfN } func (a *App) UninviteRemoteFromChannel(channelID, remoteID string) error { - ssService, err := a.getSharedChannelsService() + ssService, err := a.getSharedChannelsService(false) if err != nil { return err } diff --git a/server/channels/app/status.go b/server/channels/app/status.go index ad7d099e66..4402179579 100644 --- a/server/channels/app/status.go +++ b/server/channels/app/status.go @@ -71,7 +71,7 @@ func (a *App) UpdateDNDStatusOfUsers() { return } - scs, _ := a.getSharedChannelsService() + scs, _ := a.getSharedChannelsService(false) for i := range statuses { a.Srv().Platform().AddStatusCache(statuses[i]) a.Srv().Platform().BroadcastStatus(statuses[i]) diff --git a/server/i18n/en.json b/server/i18n/en.json index 0b3181088d..aaa2f232ef 100644 --- a/server/i18n/en.json +++ b/server/i18n/en.json @@ -1621,6 +1621,10 @@ "id": "api.command_share.service_disabled", "translation": "Shared Channels Service is disabled." }, + { + "id": "api.command_share.service_inactive", + "translation": "Shared Channels Service is enabled but not active." + }, { "id": "api.command_share.share_channel.error", "translation": "Cannot share this channel: {{.Error}}"