Skip to content

Commit

Permalink
🐛 Fix loosing permissions when updating the user
Browse files Browse the repository at this point in the history
  • Loading branch information
0x46616c6b committed Nov 26, 2023
1 parent 3c105ed commit 6660198
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/api/middleware/me/me.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (
"github.com/systemli/ticker/internal/storage"
)

func MeMiddleware(storage storage.Storage) gin.HandlerFunc {
func MeMiddleware(store storage.Storage) gin.HandlerFunc {
return func(c *gin.Context) {
userID, exists := c.Get("id")
if !exists {
c.AbortWithStatusJSON(http.StatusBadRequest, response.ErrorResponse(response.CodeDefault, response.UserIdentifierMissing))
return
}

user, err := storage.FindUserByID(int(userID.(float64)))
user, err := store.FindUserByID(int(userID.(float64)), storage.WithTickers())
if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, response.ErrorResponse(response.CodeDefault, response.UserNotFound))
return
Expand Down
4 changes: 2 additions & 2 deletions internal/api/middleware/me/me_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (s *MeTestSuite) TestMeMiddleware() {
s.Run("when id is present", func() {
s.Run("when user is not found", func() {
mockStorage := &storage.MockStorage{}
mockStorage.On("FindUserByID", mock.Anything).Return(storage.User{}, errors.New("not found"))
mockStorage.On("FindUserByID", mock.Anything, mock.Anything).Return(storage.User{}, errors.New("not found"))
mw := MeMiddleware(mockStorage)
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
Expand All @@ -48,7 +48,7 @@ func (s *MeTestSuite) TestMeMiddleware() {

s.Run("when user is found", func() {
mockStorage := &storage.MockStorage{}
mockStorage.On("FindUserByID", mock.Anything).Return(storage.User{ID: 1}, nil)
mockStorage.On("FindUserByID", mock.Anything, mock.Anything).Return(storage.User{ID: 1}, nil)
mw := MeMiddleware(mockStorage)
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
Expand Down

0 comments on commit 6660198

Please sign in to comment.