OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Fix PATCH /api/v3/my_preferences endpoint
Christophe Bliard2fb7e5d05ce4
diff --git a/lib/api/v3/user_preferences/user_preferences_api.rb b/lib/api/v3/user_preferences/user_preferences_api.rbindex c4b4153f87f..2776d834560 100644--- a/lib/api/v3/user_preferences/user_preferences_api.rb+++ b/lib/api/v3/user_preferences/user_preferences_api.rb@@ -37,6 +37,11 @@ module APIpatch doredirect api_v3_paths.user_preferences('me'), permanent: true+ # HTTP 301: GET method unchanged, other methods may or may not be+ # changed to GET depending on the user agent.+ #+ # HTTP 308: Method and body not changed+ status 308endendenddiff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rbindex 04a0fab2e14..d279e050d22 100644--- a/lib/api/v3/utilities/path_helper.rb+++ b/lib/api/v3/utilities/path_helper.rb@@ -442,6 +442,10 @@ module API"#{user(id)}/preferences"end+ def self.my_preferences+ "#{root}/my_preferences"+ end+index :groupshow :groupdiff --git a/spec/requests/api/v3/user_preferences/user_preferences_resource_spec.rb b/spec/requests/api/v3/user_preferences/user_preferences_resource_spec.rbindex 3a32e90b647..a60d26620d6 100644--- a/spec/requests/api/v3/user_preferences/user_preferences_resource_spec.rb+++ b/spec/requests/api/v3/user_preferences/user_preferences_resource_spec.rb@@ -174,4 +174,30 @@ describe 'API v3 UserPreferences resource', type: :request, content_type: :jsonendendend++ describe '/api/v3/my_preferences endpoint' do+ let(:preference_path) { api_v3_paths.my_preferences }++ describe '#GET' do+ before do+ get preference_path+ end++ it 'redirects to /api/v3/users/me/preferences' do+ expect(subject.status).to eq(301) # Moved Permanently, it may change the method to GET+ expect(response.get_header('Location')).to eq(api_v3_paths.user_preferences("me"))+ end+ end++ describe '#PATCH' do+ before do+ patch preference_path+ end++ it 'redirects to /api/v3/users/me/preferences with 308 to keep the http method' do+ expect(subject.status).to eq(308) # Method redirect, it keeps the same HTTP method.+ expect(response.get_header('Location')).to eq(api_v3_paths.user_preferences("me"))+ end+ end+ endend