diff options
| -rw-r--r-- | app/controllers/dashboard/controller.go | 6 | ||||
| -rw-r--r-- | app/controllers/dashboard/dto.go | 2 | ||||
| -rw-r--r-- | pkg/web/middleware/init.go | 15 | ||||
| -rw-r--r-- | pkg/web/middleware/user.go | 4 |
4 files changed, 20 insertions, 7 deletions
diff --git a/app/controllers/dashboard/controller.go b/app/controllers/dashboard/controller.go index 106666b..02238bb 100644 --- a/app/controllers/dashboard/controller.go +++ b/app/controllers/dashboard/controller.go @@ -31,10 +31,8 @@ func (c *Controller) Show(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) w.Header().Add("Content-Type", "text/html") - if err := views.Render(w, "dashboard/show", &ViewDashboardDTO{ - CurrentUser: currentUser, - Sparkles: []string{}, - }); err != nil { + dto := &ViewDashboardDTO{CurrentUser: currentUser} + if err := views.Render(w, "dashboard/show", dto); err != nil { log.WithFields(r.Context(), log.Fields{"error": err}) w.WriteHeader(http.StatusInternalServerError) return diff --git a/app/controllers/dashboard/dto.go b/app/controllers/dashboard/dto.go index 4243adc..ff587ae 100644 --- a/app/controllers/dashboard/dto.go +++ b/app/controllers/dashboard/dto.go @@ -4,6 +4,4 @@ import "gitlab.com/gitlab-org/software-supply-chain-security/authorization/spark type ViewDashboardDTO struct { CurrentUser *domain.User - Sparkles []string - Title string } diff --git a/pkg/web/middleware/init.go b/pkg/web/middleware/init.go new file mode 100644 index 0000000..ccf4836 --- /dev/null +++ b/pkg/web/middleware/init.go @@ -0,0 +1,15 @@ +package middleware + +import ( + "github.com/xlgmokha/x/pkg/mapper" + "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/domain" + "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/oidc" +) + +func init() { + mapper.Register(func(idToken *oidc.IDToken) *domain.User { + return &domain.User{ + ID: idToken.Subject, + } + }) +} diff --git a/pkg/web/middleware/user.go b/pkg/web/middleware/user.go index ab4e3cc..1e95ce0 100644 --- a/pkg/web/middleware/user.go +++ b/pkg/web/middleware/user.go @@ -4,10 +4,12 @@ import ( "net/http" "github.com/xlgmokha/x/pkg/log" + "github.com/xlgmokha/x/pkg/mapper" "github.com/xlgmokha/x/pkg/x" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/db" "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/oidc" ) func User(db db.Repository[*domain.User]) func(http.Handler) http.Handler { @@ -21,7 +23,7 @@ func User(db db.Repository[*domain.User]) func(http.Handler) http.Handler { user := db.Find(idToken.Subject) if x.IsZero(user) { - user = &domain.User{ID: idToken.Subject} + user = mapper.MapFrom[*oidc.IDToken, *domain.User](idToken) if err := db.Save(user); err != nil { log.WithFields(r.Context(), log.Fields{"error": err}) next.ServeHTTP(w, r) |
