-
Notifications
You must be signed in to change notification settings - Fork 150
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
/api/v1/connected should be publicly accessible #279
Conversation
@@ -351,6 +351,8 @@ func (p *Plugin) getConnected(w http.ResponseWriter, r *http.Request, userID str | |||
Organization: config.GitHubOrg, | |||
} | |||
|
|||
userID := r.Header.Get("Mattermost-User-ID") | |||
|
|||
info, _ := p.getGitHubUserInfo(userID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Not sure if necessary, but to make more clear this, I would only call getGitHubUserInfo if the userID is different to the empty string. This function will be clearer in its intent, and we will do one less call to the KVStore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point on the call to KV Store. I tried implementing it that way, but the code didn't got cleaner. By increasing the indenting, it's harder to read what the code does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if clearer or not, but what about deferring the marshaling and writing of resp? Something like this:
resp := ...
defer func () {
b, _ := json.Marshal(resp)
w.Write(b)
}()
userID := r.Header.Get("Mattermost-User-ID")
if userID == "" {
return
}
info, _ := p.getGitHubUserInfo(userID)
if info == nil || info.Token == nil {
return
}
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another solution would be to declare such function inside the function and use it before the returns.
resp := ...
writeResp := func () {
b, _ := json.Marshal(resp)
w.Write(b)
}
userID := r.Header.Get("Mattermost-User-ID")
if userID == "" {
writeResp()
return
}
info, _ := p.getGitHubUserInfo(userID)
if info == nil || info.Token == nil {
writeResp()
return
}
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the helper methods added in #252 to make the code cleaner. I will alter the code when either PR get's merged.
Codecov Report
@@ Coverage Diff @@
## master #279 +/- ##
==========================================
- Coverage 18.13% 18.09% -0.05%
==========================================
Files 10 10
Lines 2371 2377 +6
==========================================
Hits 430 430
- Misses 1916 1922 +6
Partials 25 25
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and passed
- When logging in as a user not connected to GutHub in incognito session, the corresponding 401 error in js console no longer occurs
- Regression tested connecting and disconnecting a user a precaution - No change in behavior
LGTM!
Summary
/api/v1/connected
should be publicly accessible. Otherwise, the webapp can't figure out if a user is connected or not in the login screen.QA Steps
Ticket Link
Fixes #278