Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
f5285aa2
Commit
f5285aa2
authored
Jul 11, 2020
by
Adam Hegyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent API error when NULL bio is given
parent
58e88479
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
12 deletions
+36
-12
app/models/user_detail.rb
app/models/user_detail.rb
+8
-0
changelogs/unreleased/227863-fix-api-error-on-null-bio.yml
changelogs/unreleased/227863-fix-api-error-on-null-bio.yml
+5
-0
doc/api/users.md
doc/api/users.md
+15
-12
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+8
-0
No files found.
app/models/user_detail.rb
View file @
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
changelogs/unreleased/227863-fix-api-error-on-null-bio.yml
0 → 100644
View file @
f5285aa2
---
title
:
Fix API errors when
null
value is given for the bio
merge_request
:
36650
author
:
type
:
fixed
doc/api/users.md
View file @
f5285aa2
...
...
@@ -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"
:
""
,
...
...
spec/requests/api/users_spec.rb
View file @
f5285aa2
...
...
@@ -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'
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment