Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

sys_controller.rb 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 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 :json => p.to_json(
  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])
  35. repository.safe_attributes = params[:repository]
  36. repository.project = project
  37. if repository.save
  38. render :json => {repository.class.name.underscore.tr('/', '-') => {:id => repository.id, :url => repository.url}}, :status => 201
  39. else
  40. head 422
  41. end
  42. end
  43. end
  44. def fetch_changesets
  45. projects = []
  46. scope = Project.active.has_module(:repository)
  47. if params[:id]
  48. project = nil
  49. if params[:id].to_s =~ /^\d*$/
  50. project = scope.find(params[:id])
  51. else
  52. project = scope.find_by_identifier(params[:id])
  53. end
  54. raise ActiveRecord::RecordNotFound unless project
  55. projects << project
  56. else
  57. projects = scope.to_a
  58. end
  59. projects.each do |project|
  60. project.repositories.each do |repository|
  61. repository.fetch_changesets
  62. end
  63. end
  64. head 200
  65. rescue ActiveRecord::RecordNotFound
  66. head 404
  67. end
  68. protected
  69. def check_enabled
  70. User.current = nil
  71. unless Setting.sys_api_enabled? && params[:key].to_s == Setting.sys_api_key
  72. render :plain => 'Access denied. Repository management WS is disabled or key is invalid.', :status => 403
  73. return false
  74. end
  75. end
  76. end