Plugin API for Shared Channels: support auto invite (#25834)
* option for auto inviting plugin to all shared channels. * auto-invite remotes to shared channels when flag set * fix unit test --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
@@ -45,7 +45,7 @@ func (rcs *Service) pingGenerator(pingChan chan *model.RemoteCluster, done <-cha
|
||||
}
|
||||
|
||||
for _, rc := range remotes {
|
||||
if rc.SiteURL != "" { // filter out unconfirmed invites
|
||||
if rc.SiteURL != "" || rc.PluginID != "" { // filter out unconfirmed invites
|
||||
pingChan <- rc
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,6 +248,16 @@ func (scs *Service) processTask(task syncTask) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add all remotes that have the autoinvited option.
|
||||
filter = model.RemoteClusterQueryFilter{
|
||||
RequireOptions: model.BitflagOptionAutoInvited,
|
||||
}
|
||||
remotesAutoInvited, err := scs.server.GetStore().RemoteCluster().GetAll(filter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
remotes = append(remotes, remotesAutoInvited...)
|
||||
} else {
|
||||
rc, err := scs.server.GetStore().RemoteCluster().Get(task.remoteID)
|
||||
if err != nil {
|
||||
|
||||
@@ -79,7 +79,22 @@ func (scs *Service) syncForRemote(task syncTask, rc *model.RemoteCluster) error
|
||||
}
|
||||
|
||||
scr, err := scs.server.GetStore().SharedChannel().GetRemoteByIds(task.channelID, rc.RemoteId)
|
||||
if err != nil {
|
||||
if isNotFoundError(err) && rc.IsOptionFlagSet(model.BitflagOptionAutoInvited) {
|
||||
// if SharedChannelRemote not found and remote has autoinvite flag, create a scr for it, thus inviting the remote.
|
||||
scr = &model.SharedChannelRemote{
|
||||
Id: model.NewId(),
|
||||
ChannelId: task.channelID,
|
||||
CreatorId: rc.CreatorId,
|
||||
IsInviteAccepted: true,
|
||||
IsInviteConfirmed: true,
|
||||
RemoteId: rc.RemoteId,
|
||||
LastPostCreateAt: model.GetMillis(),
|
||||
LastPostUpdateAt: model.GetMillis(),
|
||||
}
|
||||
if scr, err = scs.server.GetStore().SharedChannel().SaveRemote(scr); err != nil {
|
||||
return fmt.Errorf("cannot auto-create shared channel remote (channel_id=%s, remote_id=%s): %w", task.channelID, rc.RemoteId, err)
|
||||
}
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -105,6 +105,10 @@ func mungEmail(remotename string, maxLen int) string {
|
||||
}
|
||||
|
||||
func isConflictError(err error) (string, bool) {
|
||||
if err == nil {
|
||||
return "", false
|
||||
}
|
||||
|
||||
var errConflict *store.ErrConflict
|
||||
if errors.As(err, &errConflict) {
|
||||
return strings.ToLower(errConflict.Resource), true
|
||||
@@ -117,3 +121,12 @@ func isConflictError(err error) (string, bool) {
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
func isNotFoundError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
var errNotFound *store.ErrNotFound
|
||||
return errors.As(err, &errNotFound)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user