Skip to content

Commit

Permalink
Merge pull request #868 from sryoya/remove_user_parameter_from_-SetUs…
Browse files Browse the repository at this point in the history
…erRealName

Remove the unnecessary parameter from SetUserRealName and update optional param handling in profile setting
  • Loading branch information
kanata2 authored Dec 11, 2020
2 parents 177377b + ba3451d commit a0e6f30
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
14 changes: 11 additions & 3 deletions users.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ func (api *Client) DeleteUserPhotoContext(ctx context.Context) (err error) {
//
// For more information see SetUserRealNameContextWithUser
func (api *Client) SetUserRealName(realName string) error {
return api.SetUserRealNameContextWithUser(context.Background(), realName, realName)
return api.SetUserRealNameContextWithUser(context.Background(), "", realName)
}

// SetUserRealNameContextWithUser will set a real name for the provided user with a custom context
Expand All @@ -531,11 +531,15 @@ func (api *Client) SetUserRealNameContextWithUser(ctx context.Context, user, rea
}

values := url.Values{
"user": {user},
"token": {api.token},
"profile": {string(profile)},
}

// optional field. It should not be set if empty
if user != "" {
values["user"] = []string{user}
}

response := &userResponseFull{}
if err = api.postMethod(ctx, "users.profile.set", values, response); err != nil {
return err
Expand Down Expand Up @@ -598,11 +602,15 @@ func (api *Client) SetUserCustomStatusContextWithUser(ctx context.Context, user,
}

values := url.Values{
"user": {user},
"token": {api.token},
"profile": {string(profile)},
}

// optional field. It should not be set if empty
if user != "" {
values["user"] = []string{user}
}

response := &userResponseFull{}
if err = api.postMethod(ctx, "users.profile.set", values, response); err != nil {
return err
Expand Down
12 changes: 5 additions & 7 deletions users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,11 @@ func newProfileHandler(up *UserProfile) (setter func(http.ResponseWriter, *http.

values := r.Form

if len(values["user"]) == 0 {
httpTestErrReply(w, true, `POST data must include a "user" field`)
return
}
if up.RealName != "" && values["user"][0] != up.RealName {
httpTestErrReply(w, true, fmt.Sprintf(`POST data field "user" expected to be %q but got %q`, up.RealName, values["user"][0]))
return
if v, ok := values["user"]; ok {
if len(v) == 0 || v[0] == "" {
httpTestErrReply(w, true, `POST data must not include an empty in a "user" field`)
return
}
}

if len(values["profile"]) == 0 {
Expand Down

0 comments on commit a0e6f30

Please sign in to comment.