Skip to content

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

Restore fetch changesets functionality

Oliver Günther4d7bff2103f5
diff --git a/app/controllers/sys_controller.rb b/app/controllers/sys_controller.rb
index b12087027fe..95e9132540a 100644
--- a/app/controllers/sys_controller.rb
+++ b/app/controllers/sys_controller.rb
@@ -43,6 +43,24 @@ class SysController < ActionController::Base
end
end
+ def fetch_changesets
+ projects = []
+ if params[:id]
+ projects << Project.active.has_module(:repository).find_by!(identifier: params[:id])
+ else
+ projects = Project.active.has_module(:repository)
+ .includes(:repository).references(:repositories)
+ end
+ projects.each do |project|
+ if project.repository
+ project.repository.fetch_changesets
+ end
+ end
+ head :ok
+ rescue ActiveRecord::RecordNotFound
+ head :not_found
+ end
+
private
def authorized?(project, user)
diff --git a/config/routes.rb b/config/routes.rb
index 158ed8a6a29..de4c3eeb1cf 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -703,8 +703,8 @@ Rails.application.routes.draw do
scope controller: "sys" do
match "/sys/repo_auth", action: "repo_auth", via: %i[get post]
+ get "/sys/fetch_changesets", action: "fetch_changesets"
match "/sys/projects", to: proc { [410, {}, [""]] }, via: :all
- match "/sys/fetch_changesets", to: proc { [410, {}, [""]] }, via: :all
match "/sys/projects/:id/repository/update_storage", to: proc { [410, {}, [""]] }, via: :all
end
diff --git a/spec/controllers/sys_controller_spec.rb b/spec/controllers/sys_controller_spec.rb
index 00b3080e3c6..f5db5870a7f 100644
--- a/spec/controllers/sys_controller_spec.rb
+++ b/spec/controllers/sys_controller_spec.rb
@@ -493,4 +493,52 @@ RSpec.describe SysController, with_settings: { sys_api_enabled: true } do
end
end
end
+
+ describe "#fetch_changesets" do
+ let(:params) { { id: repository_project.identifier } }
+
+ before do
+ request.env["HTTP_AUTHORIZATION"] =
+ ActionController::HttpAuthentication::Basic.encode_credentials(
+ valid_user.login,
+ valid_user_password
+ )
+
+ allow_any_instance_of(Repository::Subversion).to receive(:fetch_changesets).and_return(true)
+
+ get "fetch_changesets", params: params.merge({ key: api_key })
+ end
+
+ context "with a project identifier" do
+ it "is successful" do
+ expect(response)
+ .to have_http_status(:ok)
+ end
+ end
+
+ context "without a project identifier" do
+ let(:params) { {} }
+
+ it "is successful" do
+ expect(response)
+ .to have_http_status(:ok)
+ end
+ end
+
+ context "for an unknown project" do
+ let(:params) { { id: 0 } }
+
+ it "returns 404" do
+ expect(response)
+ .to have_http_status(:not_found)
+ end
+ end
+
+ context "when disabled", with_settings: { sys_api_enabled?: false } do
+ it "is 403 forbidden" do
+ expect(response)
+ .to have_http_status(:forbidden)
+ end
+ end
+ end
end