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
d0a59715
Commit
d0a59715
authored
Jun 07, 2021
by
Gary Holtz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a GET endpoint to user preferences
Changelog: added
parent
dda51887
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
2 deletions
+59
-2
doc/api/users.md
doc/api/users.md
+26
-2
lib/api/users.rb
lib/api/users.rb
+10
-0
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+23
-0
No files found.
doc/api/users.md
View file @
d0a59715
...
...
@@ -453,7 +453,6 @@ Parameters:
|
`twitter`
| No | Twitter account |
|
`username`
| Yes | Username |
|
`view_diffs_file_by_file`
| No | Flag indicating the user sees only one file diff per page |
|
`show_whitespace_in_diffs`
| No | Flag indicating the user sees whitespace changes in diffs
|
`website_url`
| No | Website URL |
## User modification
...
...
@@ -694,6 +693,29 @@ Example response:
}
```
## Get user preferences
Get a list of currently authenticated user's preferences.
```
plaintext
GET /user/preferences
```
Example response:
```
json
{
"id"
:
1
,
"user_id"
:
1
"view_diffs_file_by_file"
:
true
,
"show_whitespace_in_diffs"
:
false
}
```
Parameters:
-
**none**
## User preference modification
Update the current user's preferences.
...
...
@@ -706,7 +728,8 @@ PUT /user/preferences
{
"id"
:
1
,
"user_id"
:
1
"view_diffs_file_by_file"
:
true
"view_diffs_file_by_file"
:
true
,
"show_whitespace_in_diffs"
:
false
}
```
...
...
@@ -715,6 +738,7 @@ Parameters:
| Attribute | Required | Description |
| :--------------------------- | :------- | :---------------------------------------------------------- |
|
`view_diffs_file_by_file`
| Yes | Flag indicating the user sees only one file diff per page. |
|
`show_whitespace_in_diffs`
| Yes | Flag indicating the user sees whitespace changes in diffs |
## Set user status
...
...
lib/api/users.rb
View file @
d0a59715
...
...
@@ -1045,6 +1045,16 @@ module API
end
end
desc
"Get the current user's preferences"
do
success
Entities
::
UserPreferences
detail
'This feature was introduced in GitLab 14.0.'
end
get
"preferences"
,
feature_category: :users
do
authenticate!
present
current_user
.
user_preference
,
with:
Entities
::
UserPreferences
end
desc
'Get a single email address owned by the currently authenticated user'
do
success
Entities
::
Email
end
...
...
spec/requests/api/users_spec.rb
View file @
d0a59715
...
...
@@ -2077,6 +2077,29 @@ RSpec.describe API::Users do
it_behaves_like
'get user info'
,
'v4'
end
describe
"GET /user/preferences"
do
context
"when unauthenticated"
do
it
"returns authentication error"
do
get
api
(
"/user/preferences"
)
expect
(
response
).
to
have_gitlab_http_status
(
:unauthorized
)
end
end
context
"when authenticated"
do
it
"returns user preferences"
do
user
.
user_preference
.
view_diffs_file_by_file
=
false
user
.
user_preference
.
show_whitespace_in_diffs
=
true
user
.
save!
get
api
(
"/user/preferences"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
"view_diffs_file_by_file"
]).
to
eq
(
user
.
user_preference
.
view_diffs_file_by_file
)
expect
(
json_response
[
"show_whitespace_in_diffs"
]).
to
eq
(
user
.
user_preference
.
show_whitespace_in_diffs
)
end
end
end
describe
"GET /user/keys"
do
context
"when unauthenticated"
do
it
"returns authentication error"
do
...
...
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