Commit 979e0f6d authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '329577-sync-show-whitespace-changes-in-diffs-user-preference' into 'master'

Add GET endpoint to User Preferences

See merge request gitlab-org/gitlab!63462
parents 53f5ad14 00552d99
......@@ -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
......
......@@ -1045,6 +1045,14 @@ 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
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
......
......@@ -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
......
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