-
Notifications
You must be signed in to change notification settings - Fork 674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MF-922 - Add UpdateUser endpoint #923
Conversation
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
users/tracing/users.go
Outdated
defer span.Finish() | ||
ctx = opentracing.ContextWithSpan(ctx, span) | ||
|
||
return urm.repo.Update(ctx, user) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this update whole user structure or just Metadata?
If it updates whole user structure, it means that User can change his own "constructive" information - which is contrary to the ide that users are created and managed by the admins - and can lead to security breaches.
@nmarcetic please review this one and advise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nmarcetic please review and advise here so we can move further.
Codecov Report
@@ Coverage Diff @@
## master #923 +/- ##
==========================================
- Coverage 83.59% 82.93% -0.67%
==========================================
Files 75 75
Lines 5341 5385 +44
==========================================
+ Hits 4465 4466 +1
- Misses 610 652 +42
- Partials 266 267 +1
Continue to review full report at Codecov.
|
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
users/api/logging.go
Outdated
|
||
func (lm *loggingMiddleware) UpdateMetadata(ctx context.Context, token string, metadata map[string]interface{}) (email string, err error) { | ||
defer func(begin time.Time) { | ||
message := fmt.Sprintf("Method user_update for user %s took %s to complete", email, time.Since(begin)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change user_update
to update_metadata
.
users/api/metrics.go
Outdated
|
||
func (ms *metricsMiddleware) UpdateMetadata(ctx context.Context, token string, metadata map[string]interface{}) (email string, err error) { | ||
defer func(begin time.Time) { | ||
ms.counter.With("method", "user_update").Add(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
users/api/http/endpoint.go
Outdated
@@ -90,6 +90,23 @@ func userInfoEndpoint(svc users.Service) endpoint.Endpoint { | |||
} | |||
} | |||
|
|||
func userUpdateMetaEndpoint(svc users.Service) endpoint.Endpoint { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename this method name.
users/api/http/requests.go
Outdated
@@ -28,6 +28,18 @@ func (req viewUserInfoReq) validate() error { | |||
return nil | |||
} | |||
|
|||
type updateUserReq struct { | |||
Token string | |||
User users.User |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, I want to ask why is Token
public? Second, I still think that here you should have fields that you're updating (for now just metadata
). If you leave it this way, I can pass email and pass, and the request will be accepted.
users/api/logging.go
Outdated
|
||
func (lm *loggingMiddleware) UpdateUser(ctx context.Context, token string, u users.User) (err error) { | ||
defer func(begin time.Time) { | ||
message := fmt.Sprintf("Method update_user_info for user %s took %s to complete", u.Email, time.Since(begin)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to update_user
users/api/metrics.go
Outdated
|
||
func (ms *metricsMiddleware) UpdateUser(ctx context.Context, token string, u users.User) (err error) { | ||
defer func(begin time.Time) { | ||
ms.counter.With("method", "update_user_info").Add(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to update_user
.
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests need to be added for this new endpoint.
Add missing tests in this issue: https://github.com/mainflux/mainflux/issues/926 |
* MF-922 - Add User Update endpoint Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Revert Update function Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Update swagger Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix Things swagger Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix swagger Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * update Things swagger Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix users swagger Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix mocks Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix method name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix swagger Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix swagger Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix swagger Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Use User instead of metadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale manuel.imperiale@gmail.com
Closes #922