From 1d848fee54d98e241a4991b72933042a8cd2914b Mon Sep 17 00:00:00 2001 From: Igor Drozdov Date: Tue, 21 Nov 2023 21:59:30 +0100 Subject: [PATCH 1/2] Enable API redirection for moved projects Changelog: fixed --- .../development/api_redirect_moved_projects.yml | 8 -------- doc/api/rest/index.md | 7 +------ lib/api/helpers.rb | 3 +-- spec/requests/api/projects_spec.rb | 10 ---------- 4 files changed, 2 insertions(+), 26 deletions(-) delete mode 100644 config/feature_flags/development/api_redirect_moved_projects.yml diff --git a/config/feature_flags/development/api_redirect_moved_projects.yml b/config/feature_flags/development/api_redirect_moved_projects.yml deleted file mode 100644 index 56c01d3862b0d3..00000000000000 --- a/config/feature_flags/development/api_redirect_moved_projects.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -name: api_redirect_moved_projects -introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/128642 -rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/421992 -milestone: '16.3' -type: development -group: group::source code -default_enabled: false diff --git a/doc/api/rest/index.md b/doc/api/rest/index.md index fd98952185b93e..37808298d88eb4 100644 --- a/doc/api/rest/index.md +++ b/doc/api/rest/index.md @@ -347,12 +347,7 @@ The following table shows the possible return codes for API requests. ## Redirects -> Introduced in GitLab 16.4 [with a flag](../../user/feature_flags.md) named `api_redirect_moved_projects`. Disabled by default. - -FLAG: -On GitLab.com, this feature is not available. -On self-managed GitLab, by default this feature is not available. To make it available, -an administrator can [enable the feature flag](../../user/feature_flags.md) named `api_redirect_moved_projects`. +> Introduced in GitLab 16.4. REST API can respond with a redirect and users should be able to handle such responses. The users should follow the redirect and repeat the request to the URI specified in the `Location` header. diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index bb94d5d14d07b8..7c57666b843919 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -146,7 +146,7 @@ def find_project(id) if id.is_a?(Integer) || id =~ INTEGER_ID_REGEX projects.find_by(id: id) elsif id.include?("/") - projects.find_by_full_path(id, follow_redirects: Feature.enabled?(:api_redirect_moved_projects)) + projects.find_by_full_path(id, follow_redirects: true) end end # rubocop: enable CodeReuse/ActiveRecord @@ -905,7 +905,6 @@ def sanitize_id_param(id) end def project_moved?(id, project) - return false unless Feature.enabled?(:api_redirect_moved_projects) return false unless id.is_a?(String) && id.include?('/') return false if project.blank? || project.full_path.casecmp?(id) return false unless params[:id] == id diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index e9319d514aab58..364c5720346ccf 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -2852,16 +2852,6 @@ def failure_message(diff) expect(response).to have_gitlab_http_status(:not_found) end end - - context 'when api_redirect_moved_projects is disabled' do - it 'returns a 404 error' do - stub_feature_flags(api_redirect_moved_projects: false) - - perform_request - - expect(response).to have_gitlab_http_status(:not_found) - end - end end it 'returns a 404 error if not found' do -- GitLab From 197916f19b75185a6cf136a0776da47e68d996fb Mon Sep 17 00:00:00 2001 From: Amy Qualls Date: Tue, 21 Nov 2023 21:12:08 +0000 Subject: [PATCH 2/2] Improve Redirects API documentation --- doc/api/rest/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/api/rest/index.md b/doc/api/rest/index.md index 37808298d88eb4..be878ca2bcf908 100644 --- a/doc/api/rest/index.md +++ b/doc/api/rest/index.md @@ -347,7 +347,8 @@ The following table shows the possible return codes for API requests. ## Redirects -> Introduced in GitLab 16.4. +> - Introduced in GitLab 16.4 [with a flag](../../user/feature_flags.md) named `api_redirect_moved_projects`. Disabled by default. +> - [Generally available](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/137578) in GitLab 16.7. Feature flag `api_redirect_moved_projects` removed. REST API can respond with a redirect and users should be able to handle such responses. The users should follow the redirect and repeat the request to the URI specified in the `Location` header. -- GitLab