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

Review fixes of #872 #7

Merged
merged 19 commits into from
Oct 13, 2022
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
17 changes: 8 additions & 9 deletions server/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,18 @@ func getMockUserStoreKV() mockUserStoreKV {

connection := Connection{
User: jira.User{
AccountID: "test",
AccountID: "test-AccountID",
},
}

trueValue := true
withNotifications := connection // copy
withNotifications.Settings = &ConnectionSettings{
Notifications: trueValue,
RolesForDMNotification: map[string]*bool{
subCommandAssignee: &trueValue,
subCommandMention: &trueValue,
subCommandReporter: &trueValue,
subCommandWatching: &trueValue,
Notifications: true,
RolesForDMNotification: map[string]bool{
subCommandAssignee: true,
subCommandMention: true,
subCommandReporter: true,
subCommandWatching: true,
},
}

Expand Down Expand Up @@ -264,7 +263,7 @@ func TestPlugin_ExecuteCommand_Settings(t *testing.T) {
func TestPlugin_ExecuteCommand_Installation(t *testing.T) {
api := &plugintest.API{}
api.On("LogError", mock.AnythingOfTypeArgument("string")).Return(nil)
api.On("LogDebug", mockAnythingOfTypeBatch("string", 11)...).Return(nil)
api.On("LogDebug", mockAnythingOfTypeBatch("string", 11)...).Return()
api.On("KVSet", mock.AnythingOfType("string"), mock.Anything, mock.Anything).Return(nil)
api.On("KVSetWithExpiry", mock.AnythingOfType("string"), mock.Anything, mock.Anything).Return(nil)
api.On("KVGet", keyInstances).Return(nil, nil)
Expand Down
24 changes: 12 additions & 12 deletions server/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,9 @@ func TestSubscribe(t *testing.T) {
api := &plugintest.API{}
p := Plugin{}

api.On("LogDebug", mockAnythingOfTypeBatch("string", 11)...).Return(nil)
api.On("LogError", mockAnythingOfTypeBatch("string", 10)...).Return(nil)
api.On("LogError", mockAnythingOfTypeBatch("string", 13)...).Return(nil)
api.On("LogDebug", mockAnythingOfTypeBatch("string", 11)...).Return()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why it was nil before and now it's not? It doesn't seem like a needed change, but I might be wrong.

Copy link
Author

@Nityanand13 Nityanand13 Oct 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javaguirre because the function LogError and LogDebug does not have a return type.

api.On("LogError", mockAnythingOfTypeBatch("string", 10)...).Return()
api.On("LogError", mockAnythingOfTypeBatch("string", 13)...).Return()

api.On("GetChannelMember", mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(&model.ChannelMember{}, (*model.AppError)(nil))
api.On("CreatePost", mock.AnythingOfType("*model.Post")).Return(&model.Post{}, nil)
Expand Down Expand Up @@ -427,9 +427,9 @@ func TestDeleteSubscription(t *testing.T) {
api := &plugintest.API{}
p := Plugin{}

api.On("LogDebug", mockAnythingOfTypeBatch("string", 11)...).Return(nil)
api.On("LogError", mockAnythingOfTypeBatch("string", 10)...).Return(nil)
api.On("LogError", mockAnythingOfTypeBatch("string", 13)...).Return(nil)
api.On("LogDebug", mockAnythingOfTypeBatch("string", 11)...).Return()
api.On("LogError", mockAnythingOfTypeBatch("string", 10)...).Return()
api.On("LogError", mockAnythingOfTypeBatch("string", 13)...).Return()

api.On("GetChannelMember", mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(&model.ChannelMember{}, (*model.AppError)(nil))
api.On("CreatePost", mock.AnythingOfType("*model.Post")).Return(&model.Post{}, nil)
Expand Down Expand Up @@ -646,9 +646,9 @@ func TestEditSubscription(t *testing.T) {
api := &plugintest.API{}
p := Plugin{}

api.On("LogDebug", mockAnythingOfTypeBatch("string", 11)...).Return(nil)
api.On("LogError", mockAnythingOfTypeBatch("string", 10)...).Return(nil)
api.On("LogError", mockAnythingOfTypeBatch("string", 13)...).Return(nil)
api.On("LogDebug", mockAnythingOfTypeBatch("string", 11)...).Return()
api.On("LogError", mockAnythingOfTypeBatch("string", 10)...).Return()
api.On("LogError", mockAnythingOfTypeBatch("string", 13)...).Return()

api.On("GetChannelMember", mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(&model.ChannelMember{}, (*model.AppError)(nil))
api.On("CreatePost", mock.AnythingOfType("*model.Post")).Return(&model.Post{}, nil)
Expand Down Expand Up @@ -807,9 +807,9 @@ func TestGetSubscriptionsForChannel(t *testing.T) {
api := &plugintest.API{}
p := Plugin{}

api.On("LogDebug", mockAnythingOfTypeBatch("string", 11)...).Return(nil)
api.On("LogError", mockAnythingOfTypeBatch("string", 10)...).Return(nil)
api.On("LogError", mockAnythingOfTypeBatch("string", 13)...).Return(nil)
api.On("LogDebug", mockAnythingOfTypeBatch("string", 11)...).Return()
api.On("LogError", mockAnythingOfTypeBatch("string", 10)...).Return()
api.On("LogError", mockAnythingOfTypeBatch("string", 13)...).Return()

api.On("GetChannelMember", mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(&model.ChannelMember{}, (*model.AppError)(nil))

Expand Down
44 changes: 27 additions & 17 deletions server/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1133,13 +1133,38 @@ func (p *Plugin) GetUserSetting(wh *webhook, instanceID types.ID, jiraAccountID,

func (s *ConnectionSettings) ShouldReceiveNotification(role string) bool {
if val, ok := s.RolesForDMNotification[role]; ok {
return *val
return val
}

// Check old setting for backwards compatibility
return s.Notifications
}

func (p *Plugin) fetchConnectedUserFromAccount(account map[string]string, instance Instance) (Client, *Connection, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javaguirre because this was one of your review comments

var mattermostUserID types.ID
var err error
if account["AccountID"] != "" {
mattermostUserID, err = p.userStore.LoadMattermostUserID(instance.GetID(), account["AccountID"])
} else {
mattermostUserID, err = p.userStore.LoadMattermostUserID(instance.GetID(), account["Name"])
}
if err != nil {
return nil, nil, err
}

connection, err := p.userStore.LoadConnection(instance.GetID(), mattermostUserID)
if err != nil {
return nil, nil, err
}

client, err := instance.GetClient(connection)
if err != nil {
return nil, connection, err
}
Nityanand13 marked this conversation as resolved.
Show resolved Hide resolved

return client, connection, nil
}

func (wh *webhook) fetchConnectedUser(p *Plugin, instanceID types.ID) (Client, *Connection, error) {
var accountInformation []map[string]string

Expand Down Expand Up @@ -1169,22 +1194,7 @@ func (wh *webhook) fetchConnectedUser(p *Plugin, instanceID types.ID) (Client, *
return nil, nil, err
}
for _, account := range accountInformation {
var mattermostUserID types.ID
if account["AccountID"] != "" {
mattermostUserID, err = p.userStore.LoadMattermostUserID(instance.GetID(), account["AccountID"])
} else {
mattermostUserID, err = p.userStore.LoadMattermostUserID(instance.GetID(), account["Name"])
}
if err != nil {
continue
}

connection, err := p.userStore.LoadConnection(instance.GetID(), mattermostUserID)
if err != nil {
continue
}

client, err := instance.GetClient(connection)
client, connection, err := p.fetchConnectedUserFromAccount(account, instance)
if err != nil {
continue
}
Expand Down
Loading