Skip to content

Commit

Permalink
Some improvments to cloud connect flow. (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
crspeller committed May 21, 2019
1 parent 0ae9bce commit c5fab89
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion server/instance_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (jci jiraCloudInstance) parseHTTPRequestJWT(r *http.Request) (*jwt.Token, s
// HMAC secret is a []byte
return []byte(jci.AtlassianSecurityContext.SharedSecret), nil
})
if err != nil {
if err != nil || !token.Valid {
return nil, "", errors.WithMessage(err, "failed to validatte JWT")
}

Expand Down
5 changes: 5 additions & 0 deletions server/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ func httpUserConnect(ji Instance, w http.ResponseWriter, r *http.Request) (int,
return http.StatusUnauthorized, errors.New("not authorized")
}

// Users shouldn't be able to make multiple connections.
if jiraUser, err := ji.GetPlugin().LoadJIRAUser(ji, mattermostUserId); err == nil && len(jiraUser.Key) != 0 {
return http.StatusBadRequest, errors.New("Already connected to a JIRA account. Please use /jira disconnect to disconnect.")
}

redirectURL, err := ji.GetUserConnectURL(mattermostUserId)
if err != nil {
return http.StatusInternalServerError, err
Expand Down
7 changes: 1 addition & 6 deletions server/user_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ const (
argMMToken = "mm_token"
)

const requireUserApproval = true

func httpACUserRedirect(jci *jiraCloudInstance, w http.ResponseWriter, r *http.Request) (int, error) {
if r.Method != http.MethodGet {
return http.StatusMethodNotAllowed,
Expand All @@ -32,10 +30,7 @@ func httpACUserRedirect(jci *jiraCloudInstance, w http.ResponseWriter, r *http.R
return http.StatusBadRequest, err
}

submitURL := path.Join(jci.Plugin.GetPluginURLPath(), routeACUserConnected)
if requireUserApproval {
submitURL = path.Join(jci.Plugin.GetPluginURLPath(), routeACUserConfirm)
}
submitURL := path.Join(jci.Plugin.GetPluginURLPath(), routeACUserConfirm)

return jci.Plugin.respondWithTemplate(w, r, "text/html", struct {
SubmitURL string
Expand Down

0 comments on commit c5fab89

Please sign in to comment.