Commit 08585a7b authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '227863-fix-api-error-on-null-bio' into 'master'

Prevent API error when NULL bio is given

Closes #227863

See merge request gitlab-org/gitlab!36650
parents 4ac86d14 f5285aa2
......@@ -9,6 +9,8 @@ class UserDetail < ApplicationRecord
validates :job_title, length: { maximum: 200 }
validates :bio, length: { maximum: 255 }, allow_blank: true
before_save :prevent_nil_bio
cache_markdown_field :bio
def bio_html
......@@ -22,4 +24,10 @@ class UserDetail < ApplicationRecord
def invalidated_markdown_cache?
self.class.column_names.include?('bio_html') && super
end
private
def prevent_nil_bio
self.bio = '' if bio_changed? && bio.nil?
end
end
---
title: Fix API errors when null value is given for the bio
merge_request: 36650
author:
type: fixed
......@@ -89,8 +89,8 @@ GET /users
"web_url": "http://localhost:3000/john_smith",
"created_at": "2012-05-23T08:00:58Z",
"is_admin": false,
"bio": null,
"bio_html": null,
"bio": "",
"bio_html": "",
"location": null,
"skype": "",
"linkedin": "",
......@@ -129,8 +129,8 @@ GET /users
"web_url": "http://localhost:3000/jack_smith",
"created_at": "2012-05-23T08:01:01Z",
"is_admin": false,
"bio": null,
"bio_html": null,
"bio": "",
"bio_html": "",
"location": null,
"skype": "",
"linkedin": "",
......@@ -247,8 +247,8 @@ Parameters:
"avatar_url": "http://localhost:3000/uploads/user/avatar/1/cd8.jpeg",
"web_url": "http://localhost:3000/john_smith",
"created_at": "2012-05-23T08:00:58Z",
"bio": null,
"bio_html": null,
"bio": "",
"bio_html": "",
"location": null,
"public_email": "john@example.com",
"skype": "",
......@@ -283,8 +283,8 @@ Example Responses:
"web_url": "http://localhost:3000/john_smith",
"created_at": "2012-05-23T08:00:58Z",
"is_admin": false,
"bio": null,
"bio_html": null,
"bio": "",
"bio_html": "",
"location": null,
"public_email": "john@example.com",
"skype": "",
......@@ -372,6 +372,9 @@ over `password`. In addition, `reset_password` and
NOTE: **Note:**
From [GitLab 12.1](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/29888/), `private_profile` will default to `false`.
NOTE: **Note:**
From [GitLab 13.2](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/35604), `bio` will default to `""` instead of `null`.
```plaintext
POST /users
```
......@@ -503,8 +506,8 @@ GET /user
"avatar_url": "http://localhost:3000/uploads/user/avatar/1/index.jpg",
"web_url": "http://localhost:3000/john_smith",
"created_at": "2012-05-23T08:00:58Z",
"bio": null,
"bio_html": null,
"bio": "",
"bio_html": "",
"location": null,
"public_email": "john@example.com",
"skype": "",
......@@ -553,8 +556,8 @@ GET /user
"web_url": "http://localhost:3000/john_smith",
"created_at": "2012-05-23T08:00:58Z",
"is_admin": false,
"bio": null,
"bio_html": null,
"bio": "",
"bio_html": "",
"location": null,
"public_email": "john@example.com",
"skype": "",
......
......@@ -910,6 +910,14 @@ RSpec.describe API::Users, :do_not_mock_admin_mode do
expect(user.reload.bio).to eq('')
end
it 'updates user with nil bio' do
put api("/users/#{user.id}", admin), params: { bio: nil }
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['bio']).to eq('')
expect(user.reload.bio).to eq('')
end
it "updates user with new password and forces reset on next login" do
put api("/users/#{user.id}", admin), params: { password: '12345678' }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment