diff options
| author | mo khan <mo@mokhan.ca> | 2025-04-17 14:08:18 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-04-17 14:08:18 -0600 |
| commit | 62c24d360745ef8778a322c276a9ad577dfc7713 (patch) | |
| tree | a93eb5de35fb283bfa014bd3c23094017a2e72c4 /app/controllers/dashboard | |
| parent | 81d3482b6937617ba3fd778a42d2fbbbf0b8e2b7 (diff) | |
refactor: move context keys to key package
Diffstat (limited to 'app/controllers/dashboard')
| -rw-r--r-- | app/controllers/dashboard/controller.go | 7 | ||||
| -rw-r--r-- | app/controllers/dashboard/controller_test.go | 3 |
2 files changed, 4 insertions, 6 deletions
diff --git a/app/controllers/dashboard/controller.go b/app/controllers/dashboard/controller.go index d805027..b27ebe1 100644 --- a/app/controllers/dashboard/controller.go +++ b/app/controllers/dashboard/controller.go @@ -4,13 +4,10 @@ import ( "html/template" "net/http" - "github.com/xlgmokha/x/pkg/context" "github.com/xlgmokha/x/pkg/x" - "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/domain" + "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/key" ) -var CurrentUserKey context.Key[*domain.User] = context.Key[*domain.User]("current_user") - type Controller struct { } @@ -23,7 +20,7 @@ func (c *Controller) MountTo(mux *http.ServeMux) { } func (c *Controller) Show(w http.ResponseWriter, r *http.Request) { - currentUser := CurrentUserKey.From(r.Context()) + currentUser := key.CurrentUserKey.From(r.Context()) if x.IsZero(currentUser) { http.Redirect(w, r, "/", http.StatusFound) diff --git a/app/controllers/dashboard/controller_test.go b/app/controllers/dashboard/controller_test.go index ff2482f..b8199c4 100644 --- a/app/controllers/dashboard/controller_test.go +++ b/app/controllers/dashboard/controller_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/assert" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/domain" + "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/key" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/test" ) @@ -29,7 +30,7 @@ func TestController(t *testing.T) { t.Run("when authenticated", func(t *testing.T) { t.Run("renders a dashboard page", func(t *testing.T) { - ctx := CurrentUserKey.With(t.Context(), &domain.User{}) + ctx := key.CurrentUserKey.With(t.Context(), &domain.User{}) r, w := test.RequestResponse("GET", "/dashboard", test.WithContext(ctx)) mux.ServeHTTP(w, r) |
