Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(typo) botUsertID => botUserID #644

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions server/automute_preferences_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestUpdateAutomutingOnPreferencesChanged(t *testing.T) {
assertChannelNotAutomuted(t, p, linkedChannel.Id, user.Id)
assertChannelNotAutomuted(t, p, unlinkedChannel.Id, user.Id)
assertChannelNotAutomuted(t, p, dmChannel.Id, user.Id)
th.assertDMFromUser(t, p.botUsertID, user.Id, userChoseMattermostPrimaryMessage)
th.assertDMFromUser(t, p.botUserID, user.Id, userChoseMattermostPrimaryMessage)

p.PreferencesHaveChanged(&plugin.Context{}, []model.Preference{
{
Expand All @@ -83,7 +83,7 @@ func TestUpdateAutomutingOnPreferencesChanged(t *testing.T) {
assertChannelAutomuted(t, p, linkedChannel.Id, user.Id)
assertChannelNotAutomuted(t, p, unlinkedChannel.Id, user.Id)
assertChannelAutomuted(t, p, dmChannel.Id, user.Id)
th.assertDMFromUser(t, p.botUsertID, user.Id, userChoseTeamsPrimaryMessage)
th.assertDMFromUser(t, p.botUserID, user.Id, userChoseTeamsPrimaryMessage)
})

t.Run("should unmute linked channels when their primary platform changes from MS Teams to MM", func(t *testing.T) {
Expand All @@ -103,7 +103,7 @@ func TestUpdateAutomutingOnPreferencesChanged(t *testing.T) {
assertChannelAutomuted(t, p, linkedChannel.Id, user.Id)
assertChannelNotAutomuted(t, p, unlinkedChannel.Id, user.Id)
assertChannelAutomuted(t, p, dmChannel.Id, user.Id)
th.assertDMFromUser(t, p.botUsertID, user.Id, userChoseTeamsPrimaryMessage)
th.assertDMFromUser(t, p.botUserID, user.Id, userChoseTeamsPrimaryMessage)

p.PreferencesHaveChanged(&plugin.Context{}, []model.Preference{
{
Expand All @@ -119,7 +119,7 @@ func TestUpdateAutomutingOnPreferencesChanged(t *testing.T) {
assertChannelNotAutomuted(t, p, linkedChannel.Id, user.Id)
assertChannelNotAutomuted(t, p, unlinkedChannel.Id, user.Id)
assertChannelNotAutomuted(t, p, dmChannel.Id, user.Id)
th.assertDMFromUser(t, p.botUsertID, user.Id, userChoseMattermostPrimaryMessage)
th.assertDMFromUser(t, p.botUserID, user.Id, userChoseMattermostPrimaryMessage)
})

t.Run("should unmute linked channels when a MS Teams user disconnects", func(t *testing.T) {
Expand All @@ -139,7 +139,7 @@ func TestUpdateAutomutingOnPreferencesChanged(t *testing.T) {
assertChannelAutomuted(t, p, linkedChannel.Id, user.Id)
assertChannelNotAutomuted(t, p, unlinkedChannel.Id, user.Id)
assertChannelAutomuted(t, p, dmChannel.Id, user.Id)
th.assertDMFromUser(t, p.botUsertID, user.Id, userChoseTeamsPrimaryMessage)
th.assertDMFromUser(t, p.botUserID, user.Id, userChoseTeamsPrimaryMessage)

checkTime := model.GetMillisForTime(time.Now())
args := &model.CommandArgs{
Expand All @@ -151,7 +151,7 @@ func TestUpdateAutomutingOnPreferencesChanged(t *testing.T) {
assertChannelNotAutomuted(t, p, linkedChannel.Id, user.Id)
assertChannelNotAutomuted(t, p, unlinkedChannel.Id, user.Id)
assertChannelNotAutomuted(t, p, dmChannel.Id, user.Id)
th.assertNoDMFromUser(t, p.botUsertID, user.Id, checkTime)
th.assertNoDMFromUser(t, p.botUserID, user.Id, checkTime)
})

t.Run("should do nothing when unrelated preferences change", func(t *testing.T) {
Expand All @@ -165,7 +165,7 @@ func TestUpdateAutomutingOnPreferencesChanged(t *testing.T) {
Value: "full",
},
})
th.assertNoDMFromUser(t, p.botUsertID, user.Id, model.GetMillisForTime(time.Now().Add(-5*time.Second)))
th.assertNoDMFromUser(t, p.botUserID, user.Id, model.GetMillisForTime(time.Now().Add(-5*time.Second)))
})

t.Run("should do nothing when an unconnected user turns on automuting", func(t *testing.T) {
Expand Down Expand Up @@ -196,7 +196,7 @@ func TestUpdateAutomutingOnPreferencesChanged(t *testing.T) {
assertChannelNotAutomuted(t, p, linkedChannel.Id, unconnectedUser.Id)
assertChannelNotAutomuted(t, p, unlinkedChannel.Id, unconnectedUser.Id)
assertChannelNotAutomuted(t, p, dmChannel.Id, unconnectedUser.Id)
th.assertNoDMFromUser(t, p.botUsertID, unconnectedUser.Id, model.GetMillisForTime(time.Now().Add(-5*time.Second)))
th.assertNoDMFromUser(t, p.botUserID, unconnectedUser.Id, model.GetMillisForTime(time.Now().Add(-5*time.Second)))
})

t.Run("should not affect other users when a connected user turns on automuting", func(t *testing.T) {
Expand Down Expand Up @@ -227,7 +227,7 @@ func TestUpdateAutomutingOnPreferencesChanged(t *testing.T) {
})

assertUserHasAutomuteEnabled(t, p, user.Id)
th.assertDMFromUser(t, p.botUsertID, user.Id, userChoseTeamsPrimaryMessage)
th.assertDMFromUser(t, p.botUserID, user.Id, userChoseTeamsPrimaryMessage)

assertChannelAutomuted(t, p, linkedChannel.Id, user.Id)
assertChannelNotAutomuted(t, p, unlinkedChannel.Id, user.Id)
Expand Down Expand Up @@ -270,7 +270,7 @@ func TestUpdateAutomutingOnPreferencesChanged(t *testing.T) {
})

assertUserHasAutomuteEnabled(t, p, user.Id)
th.assertDMFromUser(t, p.botUsertID, user.Id, userChoseTeamsPrimaryMessage)
th.assertDMFromUser(t, p.botUserID, user.Id, userChoseTeamsPrimaryMessage)

for _, channel := range channels {
assertChannelAutomuted(t, p, channel.Id, user.Id)
Expand All @@ -286,7 +286,7 @@ func TestUpdateAutomutingOnPreferencesChanged(t *testing.T) {
})

assertUserHasAutomuteDisabled(t, p, user.Id)
th.assertDMFromUser(t, p.botUsertID, user.Id, userChoseMattermostPrimaryMessage)
th.assertDMFromUser(t, p.botUserID, user.Id, userChoseMattermostPrimaryMessage)

for _, channel := range channels {
assertChannelNotAutomuted(t, p, channel.Id, user.Id)
Expand Down
4 changes: 2 additions & 2 deletions server/bot_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
)

func (p *Plugin) botSendDirectMessage(userID, message string) error {
channel, err := p.apiClient.Channel.GetDirect(userID, p.botUsertID)
channel, err := p.apiClient.Channel.GetDirect(userID, p.botUserID)
if err != nil {
return errors.Wrapf(err, "failed to get bot DM channel with user_id %s", userID)
}

return p.apiClient.Post.CreatePost(&model.Post{
Message: message,
UserId: p.botUsertID,
UserId: p.botUserID,
ChannelId: channel.Id,
})
}
Expand Down
18 changes: 9 additions & 9 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (p *Plugin) cmdError(args *model.CommandArgs, detailedError string) (*model
func (p *Plugin) sendBotEphemeralPost(userID, channelID, message string) {
_ = p.API.SendEphemeralPost(userID, &model.Post{
Message: message,
UserId: p.botUsertID,
UserId: p.botUserID,
ChannelId: channelID,
})
}
Expand Down Expand Up @@ -245,7 +245,7 @@ func (p *Plugin) executeLinkCommand(args *model.CommandArgs, parameters []string
TeamId: channelLink.MattermostTeamID,
Home: true,
ReadOnly: false,
CreatorId: p.botUsertID,
CreatorId: p.botUserID,
RemoteId: p.remoteID,
ShareName: channelLink.MattermostChannelID,
}); err != nil {
Expand Down Expand Up @@ -492,22 +492,22 @@ func (p *Plugin) executeConnectBotCommand(args *model.CommandArgs) (*model.Comma
return p.cmdError(args, "Unable to connect the bot account, only system admins can connect the bot account.")
}

if storedToken, _ := p.store.GetTokenForMattermostUser(p.botUsertID); storedToken != nil {
if storedToken, _ := p.store.GetTokenForMattermostUser(p.botUserID); storedToken != nil {
return p.cmdError(args, "The bot account is already connected to MS Teams. Please disconnect the bot account first before connecting again.")
}

genericErrorMessage := "Error in trying to connect the bot account, please try again."

hasRightToConnect, err := p.UserHasRightToConnect(p.botUsertID)
hasRightToConnect, err := p.UserHasRightToConnect(p.botUserID)
if err != nil {
p.API.LogWarn("Error in checking if the bot user has the right to connect", "bot_user_id", p.botUsertID, "error", err.Error())
p.API.LogWarn("Error in checking if the bot user has the right to connect", "bot_user_id", p.botUserID, "error", err.Error())
return p.cmdError(args, genericErrorMessage)
}

if !hasRightToConnect {
canOpenlyConnect, openConnectErr := p.UserCanOpenlyConnect(p.botUsertID)
canOpenlyConnect, openConnectErr := p.UserCanOpenlyConnect(p.botUserID)
if openConnectErr != nil {
p.API.LogWarn("Error in checking if the bot user can openly connect", "bot_user_id", p.botUsertID, "error", openConnectErr.Error())
p.API.LogWarn("Error in checking if the bot user can openly connect", "bot_user_id", p.botUserID, "error", openConnectErr.Error())
return p.cmdError(args, genericErrorMessage)
}

Expand Down Expand Up @@ -549,11 +549,11 @@ func (p *Plugin) executeDisconnectBotCommand(args *model.CommandArgs) (*model.Co
return p.cmdError(args, "Unable to disconnect the bot account, only system admins can disconnect the bot account.")
}

if _, err := p.store.MattermostToTeamsUserID(p.botUsertID); err != nil {
if _, err := p.store.MattermostToTeamsUserID(p.botUserID); err != nil {
return p.cmdSuccess(args, "Error: unable to find the connected bot account")
}

if err := p.store.DeleteUserInfo(p.botUsertID); err != nil {
if err := p.store.DeleteUserInfo(p.botUserID); err != nil {
return p.cmdSuccess(args, fmt.Sprintf("Error: unable to disconnect the bot account, %s", err.Error()))
}

Expand Down
4 changes: 2 additions & 2 deletions server/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ func TestExecuteDisconnectBotCommand(t *testing.T) {
ChannelId: model.NewId(),
}

err := th.p.store.SetUserInfo(th.p.botUsertID, "bot_team_user_id", &oauth2.Token{AccessToken: "token", Expiry: time.Now().Add(10 * time.Minute)})
err := th.p.store.SetUserInfo(th.p.botUserID, "bot_team_user_id", &oauth2.Token{AccessToken: "token", Expiry: time.Now().Add(10 * time.Minute)})

require.NoError(t, err)

Expand Down Expand Up @@ -886,7 +886,7 @@ func TestExecuteConnectBotCommand(t *testing.T) {
ChannelId: model.NewId(),
}

err := th.p.store.SetUserInfo(th.p.botUsertID, "bot_team_user_id", &oauth2.Token{AccessToken: "token", Expiry: time.Now().Add(10 * time.Minute)})
err := th.p.store.SetUserInfo(th.p.botUserID, "bot_team_user_id", &oauth2.Token{AccessToken: "token", Expiry: time.Now().Add(10 * time.Minute)})
require.NoError(t, err)

commandResponse, appErr := th.p.executeConnectBotCommand(args)
Expand Down
4 changes: 2 additions & 2 deletions server/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ func (p *Plugin) SendInviteMessage(user *model.User, pendingSince time.Time, cur
invitedUser.InvitePendingSince = currentTime
}

channel, err := p.apiClient.Channel.GetDirect(user.Id, p.botUsertID)
channel, err := p.apiClient.Channel.GetDirect(user.Id, p.botUserID)
if err != nil {
return errors.Wrapf(err, "failed to get bot DM channel with user_id %s", user.Id)
}

message := fmt.Sprintf("@%s, you’re invited to use the Microsoft Teams connected experience for Mattermost. ", user.Username)
invitePost := &model.Post{
Message: message,
UserId: p.botUsertID,
UserId: p.botUserID,
ChannelId: channel.Id,
}
if err := p.apiClient.Post.CreatePost(invitePost); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions server/message_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (p *Plugin) UserWillLogIn(_ *plugin.Context, user *model.User) string {

func (p *Plugin) MessageHasBeenDeleted(_ *plugin.Context, post *model.Post) {
if post.Props != nil {
if _, ok := post.Props["msteams_sync_"+p.botUsertID].(bool); ok {
if _, ok := post.Props["msteams_sync_"+p.botUserID].(bool); ok {
return
}
}
Expand Down Expand Up @@ -100,7 +100,7 @@ func (p *Plugin) MessageHasBeenPosted(_ *plugin.Context, post *model.Post) {
isDirectOrGroupMessage := channel.IsGroupOrDirect()

if post.Props != nil {
if _, ok := post.Props["msteams_sync_"+p.botUsertID].(bool); ok {
if _, ok := post.Props["msteams_sync_"+p.botUserID].(bool); ok {
return
}
}
Expand Down Expand Up @@ -629,7 +629,7 @@ func (p *Plugin) Send(teamID, channelID string, user *model.User, post *model.Po
text := post.Message
client, err := p.GetClientForUser(user.Id)
if err != nil {
client, err = p.GetClientForUser(p.botUsertID)
client, err = p.GetClientForUser(p.botUserID)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -708,7 +708,7 @@ func (p *Plugin) Delete(teamID, channelID string, user *model.User, post *model.

client, err := p.GetClientForUser(user.Id)
if err != nil {
client, err = p.GetClientForUser(p.botUsertID)
client, err = p.GetClientForUser(p.botUserID)
if err != nil {
return err
}
Expand Down Expand Up @@ -778,7 +778,7 @@ func (p *Plugin) Update(teamID, channelID string, user *model.User, newPost *mod

client, err := p.GetClientForUser(user.Id)
if err != nil {
client, err = p.GetClientForUser(p.botUsertID)
client, err = p.GetClientForUser(p.botUserID)
if err != nil {
return err
}
Expand Down
14 changes: 7 additions & 7 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ type Plugin struct {
stopSubscriptions func()
stopContext context.Context

botUsertID string
remoteID string
apiClient *pluginapi.Client
botUserID string
remoteID string
apiClient *pluginapi.Client

store store.Store
subscriptionsClusterMutex *cluster.Mutex
Expand Down Expand Up @@ -138,7 +138,7 @@ func (p *Plugin) GetBufferSizeForStreaming() int {
}

func (p *Plugin) GetBotUserID() string {
return p.botUsertID
return p.botUserID
}

func (p *Plugin) GetSelectiveSync() bool {
Expand Down Expand Up @@ -481,7 +481,7 @@ func (p *Plugin) onActivate() error {
return err
}

p.botUsertID, err = p.apiClient.Bot.EnsureBot(&model.Bot{
p.botUserID, err = p.apiClient.Bot.EnsureBot(&model.Bot{
Username: botUsername,
DisplayName: botDisplayName,
Description: "Created by the MS Teams Sync plugin.",
Expand All @@ -493,7 +493,7 @@ func (p *Plugin) onActivate() error {
p.remoteID, err = p.API.RegisterPluginForSharedChannels(model.RegisterPluginOpts{
Displayname: pluginID,
PluginID: pluginID,
CreatorID: p.botUsertID,
CreatorID: p.botUserID,
AutoShareDMs: false,
AutoInvited: true,
})
Expand Down Expand Up @@ -550,7 +550,7 @@ func (p *Plugin) onActivate() error {
TeamId: linkedChannel.MattermostTeamID,
Home: true,
ReadOnly: false,
CreatorId: p.botUsertID,
CreatorId: p.botUserID,
RemoteId: p.remoteID,
ShareName: linkedChannel.MattermostChannelID,
})
Expand Down
2 changes: 1 addition & 1 deletion server/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func newTestPlugin(t *testing.T) *Plugin {
plugin.apiHandler = NewAPI(plugin, plugin.store)

plugin.metricsService = mockMetricsService
plugin.botUsertID = "bot-user-id"
plugin.botUserID = "bot-user-id"
return plugin
}

Expand Down
Loading