Skip to content

Commit ba09157

Browse files
committed
[#71630] Also update Bim::Bcf::API::V2_1::ProjectsAPI
https://community.openproject.org/wp/71630 This one is an interesting case. The API documentation says an identifier should be allowed as ID param here: https://github.com/opf/openproject/blob/dev/docs/api/bcf/bcf-rest-api.md#41-project-services However, the regex prevented that. I removed the regex to be able to add the identifier redirect (and specs for it). I fear that if I don't fix that now, eventually someone else will find this some day, remove the constraint on the ID but will not add the redirect.
1 parent 50b2fdf commit ba09157

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

modules/bim/app/controllers/bim/bcf/api/v2_1/projects_api.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@ def visible_projects
4141
scope: -> { visible_projects })
4242
.mount
4343

44-
route_param :id, regexp: /\A(\d+)\z/ do
44+
route_param :id do
45+
helpers ::API::Helpers::HistoricalIdentifierRedirect
46+
4547
after_validation do
4648
@project = visible_projects
4749
.find(params[:id])
50+
51+
redirect_if_historical_identifier(:id, @project)
4852
end
4953

5054
get &::Bim::Bcf::API::V2_1::Endpoints::Show.new(model: Project).mount
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# frozen_string_literal: true
2+
3+
#-- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
#++
30+
31+
require "spec_helper"
32+
require "rack/test"
33+
34+
RSpec.describe "BCF 2.1 projects historical identifier redirect", content_type: :json do
35+
shared_let(:project) { create(:project, enabled_module_names: [:bim]) }
36+
shared_let(:role) { create(:project_role, permissions: [:view_work_packages]) }
37+
shared_let(:user) { create(:user, member_with_roles: { project => role }) }
38+
39+
current_user { user }
40+
41+
describe "GET /api/bcf/2.1/projects/:id" do
42+
it_behaves_like "API redirects GET requests using a historical project identifier",
43+
"/api/bcf/2.1/projects/:id"
44+
end
45+
end

0 commit comments

Comments
 (0)