Skip to content

Commit

Permalink
[MI-3676] Review fixes:
Browse files Browse the repository at this point in the history
- Added fallback to use bot when comment author is not connected.
  • Loading branch information
raghavaggarwal2308 committed Oct 31, 2023
1 parent 13dcb55 commit 7e27ce0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions server/instance_cloud_oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ func (ci *cloudOAuthInstance) GetClient(connection *Connection) (Client, error)
func (ci *cloudOAuthInstance) getClientForConnection(connection *Connection) (*jira.Client, *http.Client, error) {
oauth2Conf := ci.GetOAuthConfig()
ctx := context.Background()

// Checking if this user's connection is for a JWT instance
if ci.JWTInstance != nil && connection.OAuth2Token == nil {
ci.Plugin.API.LogDebug("Returning a JWT token client since the stored JWT instance is not nil and the user's oauth token is nil")
return ci.JWTInstance.getClientForConnection(connection)
Expand Down
12 changes: 10 additions & 2 deletions server/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,17 @@ func (p *Plugin) InstallInstance(newInstance Instance) error {
// Storing the JWT instance data inside the OAuth instance data. We will use this to use the stored JWT token in case the user has not connected to OAuth yet.
p.API.LogDebug("Instance type stored in KV store", "ID", previousInstance.GetID(), "Type", previousInstance.Common().Type)
if previousInstance.Common().Type == CloudInstanceType {
oAuthInstance.JWTInstance = previousInstance.(*cloudInstance)
ci, ok := previousInstance.(*cloudInstance)
if !ok {
p.API.LogError("Instance type is `cloud` but failed to assert instance.(*cloudInstance).", "ID", newInstance.GetID())
}
oAuthInstance.JWTInstance = ci
} else if previousInstance.Common().Type == CloudOAuthInstanceType {
oAuthInstance.JWTInstance = previousInstance.(*cloudOAuthInstance).JWTInstance
ci, ok := previousInstance.(*cloudOAuthInstance)
if !ok {
p.API.LogError("Instance type is `cloud-oauth` but failed to assert instance.(*cloudOAuthInstance).", "ID", newInstance.GetID())
}
oAuthInstance.JWTInstance = ci.JWTInstance
}

if oAuthInstance.JWTInstance != nil {
Expand Down
13 changes: 12 additions & 1 deletion server/webhook_jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,20 @@ func (jwh *JiraWebhook) expandIssue(p *Plugin, instanceID types.ID) error {
}

jwh.Issue = *issue
} else if _, ok := instance.(*cloudOAuthInstance); ok {
} else if instance, ok := instance.(*cloudOAuthInstance); ok {
mmUserID, err := p.userStore.LoadMattermostUserID(instanceID, jwh.Comment.Author.AccountID)
if err != nil {
if instance.JWTInstance != nil {
var issue *jira.Issue
issue, err = p.getIssueDataForCloudWebhook(instance.JWTInstance, jwh.Issue.ID)
if err != nil {
return err
}

jwh.Issue = *issue
return nil
}

return errors.Wrap(err, "Cannot create subscription posts for this comment as the Jira comment author is not connected to Mattermost.")
}

Expand Down

0 comments on commit 7e27ce0

Please sign in to comment.