aboutsummaryrefslogtreecommitdiffstats
path: root/commands/webui.go
diff options
context:
space:
mode:
authorLuke Granger-Brown <git@lukegb.com>2020-06-19 00:26:47 +0100
committerMichael Muré <batolettre@gmail.com>2020-06-27 23:01:09 +0200
commite5a316e40c377a8563e92f62b0773ed34321a91a (patch)
tree4788a8135201a1d3c0f05014ff1c8c2ca4060c57 /commands/webui.go
parent766aff2b2f9db339d7c42321fe6cd37309631be3 (diff)
downloadgit-bug-e5a316e40c377a8563e92f62b0773ed34321a91a.tar.gz
Pull out context-stuff from identity into graphqlidentity package
Diffstat (limited to 'commands/webui.go')
-rw-r--r--commands/webui.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/commands/webui.go b/commands/webui.go
index 24bdeced..90679c79 100644
--- a/commands/webui.go
+++ b/commands/webui.go
@@ -19,6 +19,7 @@ import (
"github.com/spf13/cobra"
"github.com/MichaelMure/git-bug/graphql"
+ "github.com/MichaelMure/git-bug/graphql/graphqlidentity"
"github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/repository"
"github.com/MichaelMure/git-bug/util/git"
@@ -34,10 +35,10 @@ var (
const webUIOpenConfigKey = "git-bug.webui.open"
-func authMiddleware(repo repository.RepoCommon, id *identity.Identity) func(http.Handler) http.Handler {
+func authMiddleware(id *identity.Identity) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- ctx := identity.AttachToContext(r.Context(), repo, id)
+ ctx := graphqlidentity.AttachToContext(r.Context(), id)
next.ServeHTTP(w, r.WithContext(ctx))
})
}
@@ -83,7 +84,7 @@ func runWebUI(cmd *cobra.Command, args []string) error {
router.Path("/gitfile/{hash}").Handler(newGitFileHandler(repo))
router.Path("/upload").Methods("POST").Handler(newGitUploadFileHandler(repo))
router.PathPrefix("/").Handler(http.FileServer(assetsHandler))
- router.Use(authMiddleware(repo, id))
+ router.Use(authMiddleware(id))
srv := &http.Server{
Addr: addr,
@@ -210,7 +211,11 @@ func newGitUploadFileHandler(repo repository.Repo) http.Handler {
}
func (gufh *gitUploadFileHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
- if identity.ForContext(r.Context(), gufh.repo) == nil {
+ id, err := graphqlidentity.ForContextUncached(r.Context(), gufh.repo)
+ if err != nil {
+ http.Error(rw, fmt.Sprintf("loading identity: %v", err), http.StatusInternalServerError)
+ return
+ } else if id == nil {
http.Error(rw, fmt.Sprintf("read-only mode or not logged in"), http.StatusForbidden)
return
}