You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sys_controller.rb 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2022 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. class SysController < ActionController::Base
  19. include ActiveSupport::SecurityUtils
  20. before_action :check_enabled
  21. def projects
  22. p = Project.active.has_module(:repository).
  23. order("#{Project.table_name}.identifier").preload(:repository).to_a
  24. # extra_info attribute from repository breaks activeresource client
  25. render :json =>
  26. p.to_json(:only => [:id, :identifier, :name, :is_public, :status],
  27. :include => {:repository => {:only => [:id, :url]}})
  28. end
  29. def create_project_repository
  30. project = Project.find(params[:id])
  31. if project.repository
  32. head 409
  33. else
  34. logger.info "Repository for #{project.name} was reported to be created by #{request.remote_ip}."
  35. repository = Repository.factory(params[:vendor])
  36. repository.safe_attributes = params[:repository]
  37. repository.project = project
  38. if repository.save
  39. render :json => {repository.class.name.underscore.tr('/', '-') => {:id => repository.id, :url => repository.url}}, :status => 201
  40. else
  41. head 422
  42. end
  43. end
  44. end
  45. def fetch_changesets
  46. projects = []
  47. scope = Project.active.has_module(:repository)
  48. if params[:id]
  49. project = nil
  50. if /^\d*$/.match?(params[:id].to_s)
  51. project = scope.find(params[:id])
  52. else
  53. project = scope.find_by_identifier(params[:id])
  54. end
  55. raise ActiveRecord::RecordNotFound unless project
  56. projects << project
  57. else
  58. projects = scope.to_a
  59. end
  60. projects.each do |project|
  61. project.repositories.each do |repository|
  62. repository.fetch_changesets
  63. end
  64. end
  65. head 200
  66. rescue ActiveRecord::RecordNotFound
  67. head 404
  68. end
  69. protected
  70. def check_enabled
  71. User.current = nil
  72. unless Setting.sys_api_enabled? && secure_compare(params[:key].to_s, Setting.sys_api_key.to_s)
  73. render :plain => 'Access denied. Repository management WS is disabled or key is invalid.', :status => 403
  74. return false
  75. end
  76. end
  77. end