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.7KB

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