Skip to content
This repository has been archived by the owner on Dec 23, 2023. It is now read-only.

Commit

Permalink
fix: missing json fields
Browse files Browse the repository at this point in the history
  • Loading branch information
muety committed Apr 9, 2021
1 parent b6426c4 commit 6b7dc2f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
6 changes: 3 additions & 3 deletions service/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s *UserService) GetAll() (users []*types.User, err error) {
func (s *UserService) GetById(id string) (*types.User, error) {
var user types.User
err := s.store.Get(id, &user)
return user.Sanitize(), err
return &user, err
}

func (s *UserService) Create(signup *dto.Signup) (*types.User, error) {
Expand All @@ -59,7 +59,7 @@ func (s *UserService) Create(signup *dto.Signup) (*types.User, error) {
if s.config.Security.VerifyUsers {
go s.verifyUser(user)
}
return user.Sanitize(), nil
return user, nil
}

func (s *UserService) Update(user *types.User, update *types.User) (*types.User, error) {
Expand All @@ -83,7 +83,7 @@ func (s *UserService) Update(user *types.User, update *types.User) (*types.User,
if err := s.store.Update(user.ID, user); err != nil {
return nil, err
}
return user.Sanitize(), nil
return user, nil
}

func (s *UserService) Delete(id string) error {
Expand Down
2 changes: 1 addition & 1 deletion types/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func AllPermissions() []string {
type Client struct {
ID string `json:"id" boltholdKey:"ID"`
Description string `json:"description"`
UserId string `json:"-" boltholdIndex:"UserId"`
UserId string `json:"user_id" boltholdIndex:"UserId"`
Permissions []string `json:"permissions"`
Sender MailAddress `json:"sender"`
ApiKey *string `json:"api_key"` // caution: usually you want to hide this!
Expand Down
2 changes: 1 addition & 1 deletion types/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
type Template struct {
ID string `json:"id"`
Name string `json:"name"`
UserId string `json:"-" boltholdIndex:"UserId"`
UserId string `json:"user_id" boltholdIndex:"UserId"`
Content string `json:"content"`
}

Expand Down
3 changes: 2 additions & 1 deletion types/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "github.com/muety/mailwhale/util"

type User struct {
ID string `json:"id" boltholdKey:"ID"`
Password string `json:"-"`
Password string `json:"password"` // clear before returning in a response !
Senders []SenderAddress `json:"senders"`
Verified bool `json:"verified"`
}
Expand All @@ -26,6 +26,7 @@ func (u *User) Sanitize() *User {
if u.Senders == nil {
u.Senders = []SenderAddress{}
}
u.Password = ""
return u
}

Expand Down
8 changes: 4 additions & 4 deletions types/verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const (
)

type Verification struct {
Token string `boltholdKey:"Token"`
UserId string
Scope string
Subject string
Token string `json:"token" boltholdKey:"Token"`
UserId string `json:"user_id"`
Scope string `json:"scope"`
Subject string `json:"subject"`
}

func NewVerification(user *User, scope, subject string) *Verification {
Expand Down
6 changes: 3 additions & 3 deletions web/routes/api/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (h *UserHandler) getMe(w http.ResponseWriter, r *http.Request) {
util.RespondError(w, r, http.StatusNotFound, errors.New("user not found"))
return
}
util.RespondJson(w, http.StatusOK, user)
util.RespondJson(w, http.StatusOK, user.Sanitize())
}

func (h *UserHandler) post(w http.ResponseWriter, r *http.Request) {
Expand All @@ -76,7 +76,7 @@ func (h *UserHandler) post(w http.ResponseWriter, r *http.Request) {
}

logbuch.Info("created user '%s'", user.ID)
util.RespondJson(w, http.StatusCreated, user)
util.RespondJson(w, http.StatusCreated, user.Sanitize())
}

func (h *UserHandler) updateMe(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -106,7 +106,7 @@ func (h *UserHandler) updateMe(w http.ResponseWriter, r *http.Request) {
}

logbuch.Info("updated user '%s'", user.ID)
util.RespondJson(w, http.StatusOK, user)
util.RespondJson(w, http.StatusOK, user.Sanitize())
}

func (h *UserHandler) verify(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit 6b7dc2f

Please sign in to comment.