Skip to content
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

Merged
merged 22 commits into from
Oct 31, 2019
Merged

MF-922 - Add UpdateUser endpoint #923

merged 22 commits into from
Oct 31, 2019

Conversation

manuio
Copy link
Contributor

@manuio manuio commented Oct 30, 2019

Signed-off-by: Manuel Imperiale manuel.imperiale@gmail.com

Closes #922

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
@manuio manuio requested a review from a team as a code owner October 30, 2019 08:31
users/api/http/transport.go Show resolved Hide resolved
defer span.Finish()
ctx = opentracing.ContextWithSpan(ctx, span)

return urm.repo.Update(ctx, user)
Copy link
Contributor

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.

Copy link
Contributor

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-io
Copy link

codecov-io commented Oct 30, 2019

Codecov Report

Merging #923 into master will decrease coverage by 0.66%.
The diff coverage is 13.72%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
users/users.go 68.42% <ø> (ø) ⬆️
users/api/http/requests.go 53.33% <0%> (-8.21%) ⬇️
users/postgres/users.go 48.64% <0%> (-5.9%) ⬇️
users/api/http/responses.go 50% <0%> (-16.67%) ⬇️
users/service.go 25.64% <0%> (-2.94%) ⬇️
users/api/http/transport.go 78.01% <46.15%> (-4.08%) ⬇️
users/api/http/endpoint.go 73.91% <9.09%> (-12.3%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8be2516...0851a28. Read the comment docs.

users/postgres/users.go Show resolved Hide resolved
users/service.go Outdated Show resolved Hide resolved
users/api/http/requests.go Outdated Show resolved Hide resolved
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>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

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))
Copy link
Contributor

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.


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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@manuio manuio changed the title MF-922 - Add User Update endpoint MF-922 - Add User UpdateMetadata endpoint Oct 31, 2019
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>
@@ -90,6 +90,23 @@ func userInfoEndpoint(svc users.Service) endpoint.Endpoint {
}
}

func userUpdateMetaEndpoint(svc users.Service) endpoint.Endpoint {
Copy link
Contributor

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.

@@ -28,6 +28,18 @@ func (req viewUserInfoReq) validate() error {
return nil
}

type updateUserReq struct {
Token string
User users.User
Copy link
Contributor

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.


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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to update_user


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)
Copy link
Contributor

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>
Copy link
Contributor

@anovakovic01 anovakovic01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@drasko drasko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@drasko drasko left a 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.

@manuio manuio changed the title MF-922 - Add User UpdateMetadata endpoint MF-922 - Add User UpdateUser endpoint Oct 31, 2019
@manuio manuio changed the title MF-922 - Add User UpdateUser endpoint MF-922 - Add UpdateUser endpoint Oct 31, 2019
@manuio
Copy link
Contributor Author

manuio commented Oct 31, 2019

Add missing tests in this issue: https://github.com/mainflux/mainflux/issues/926

@drasko drasko merged commit 28a176a into absmach:master Oct 31, 2019
@manuio manuio deleted the update branch October 31, 2019 15:42
manuio added a commit that referenced this pull request Oct 12, 2020
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add User Update endpoint
4 participants