Skip to content

Commit

Permalink
Load user's roles after profile-update
Browse files Browse the repository at this point in the history
  • Loading branch information
darh committed Oct 11, 2021
1 parent db7b21d commit 1fa8482
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions auth/handlers/handle_profile.go
Expand Up @@ -60,6 +60,10 @@ func (h *AuthHandlers) profileProc(req *request.AuthReq) error {
// this way user service will pass us through.
user, err := h.UserService.Update(req.Context(), u)

if err == nil {
err = h.AuthService.LoadRoleMemberships(req.Context(), user)
}

if err == nil {
req.AuthUser.User = user
req.AuthUser.Save(req.Session)
Expand Down
2 changes: 2 additions & 0 deletions auth/handlers/handle_profile_test.go
Expand Up @@ -77,6 +77,8 @@ func Test_profileFormProc(t *testing.T) {
req.PostForm.Add("handle", "handle")
req.PostForm.Add("name", "name")

authService = &authServiceMocked{}

userService = &userServiceMocked{
update: func(c context.Context, u *types.User) (*types.User, error) {
u = makeMockUser()
Expand Down
1 change: 1 addition & 0 deletions auth/handlers/handler.go
Expand Up @@ -43,6 +43,7 @@ type (
ValidateTOTP(ctx context.Context, code string) (err error)
ConfigureTOTP(ctx context.Context, secret string, code string) (u *types.User, err error)
RemoveTOTP(ctx context.Context, userID uint64, code string) (u *types.User, err error)
LoadRoleMemberships(ctx context.Context, u *types.User) error

SendEmailOTP(ctx context.Context) (err error)
ConfigureEmailOTP(ctx context.Context, userID uint64, enable bool) (u *types.User, err error)
Expand Down
5 changes: 5 additions & 0 deletions auth/handlers/mock_test.go
Expand Up @@ -180,6 +180,11 @@ func (s authServiceMocked) ValidateEmailOTP(ctx context.Context, code string) (e
return s.validateEmailOTP(ctx, code)
}

func (s authServiceMocked) LoadRoleMemberships(ctx context.Context, u *types.User) error {
// no-op for now
return nil
}

//
// Mocking oauth2Service
//
Expand Down

0 comments on commit 1fa8482

Please sign in to comment.