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

documents_controller.rb 4.2 kB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 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 DocumentsController < ApplicationController
  18. layout 'base_projects'#by young
  19. default_search_scope :documents
  20. model_object Document
  21. before_filter :find_project_by_project_id, :only => [:index, :new, :create]
  22. before_filter :find_model_object, :except => [:index, :new, :create]
  23. before_filter :find_project_from_association, :except => [:index, :new, :create]
  24. before_filter :authorize , :except => [:index]#Added by young
  25. before_filter :authorize_document
  26. helper :attachments
  27. helper :project_score
  28. def index
  29. @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
  30. temp = @project.documents.includes(:attachments, :category).all
  31. documents = []
  32. temp.each do |doc|
  33. if doc.has_right?(@project)
  34. documents << doc
  35. end
  36. end
  37. case @sort_by
  38. when 'date'
  39. @grouped = documents.group_by {|d| d.updated_on.to_date }
  40. when 'title'
  41. @grouped = documents.group_by {|d| d.title.first.upcase}
  42. when 'author'
  43. # @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
  44. @grouped = documents.group_by(&:user)
  45. else
  46. @grouped = documents.group_by(&:category)
  47. end
  48. @document = @project.documents.build
  49. if @project.project_type == 1
  50. render :layout => 'base_courses'
  51. else
  52. render :layout => false if request.xhr?
  53. end
  54. end
  55. def show
  56. @attachments = @document.attachments.all
  57. if @project.project_type ==1
  58. render :action => 'show', :layout => 'base_courses'
  59. end
  60. respond_to do |format|
  61. format.html
  62. format.api
  63. end
  64. end
  65. def new
  66. @document = @project.documents.build
  67. @document.safe_attributes = params[:document]
  68. end
  69. def create
  70. @document = @project.documents.build
  71. @document.safe_attributes = params[:document]
  72. @document.user = User.current
  73. @document.save_attachments(params[:attachments])
  74. if @document.save
  75. render_attachment_warning_if_needed(@document)
  76. flash[:notice] = l(:notice_successful_create)
  77. redirect_to project_documents_url(@project)
  78. else
  79. render :action => 'new'
  80. end
  81. end
  82. def edit
  83. end
  84. def update
  85. @document.safe_attributes = params[:document]
  86. @document.save_attachments(params[:attachments])
  87. if request.put? and @document.save
  88. flash[:notice] = l(:notice_successful_update)
  89. redirect_to document_url(@document)
  90. else
  91. render :action => 'edit'
  92. end
  93. end
  94. def destroy
  95. @document.destroy if request.delete?
  96. redirect_to project_documents_url(@project)
  97. end
  98. def add_attachment
  99. attachments = Attachment.attach_files(@document, params[:attachments])
  100. render_attachment_warning_if_needed(@document)
  101. # if attachments.present? && attachments[:files].present? && Setting.notified_events.include?('document_added')
  102. # # Mailer.run.attachments_added(attachments[:files])
  103. # end
  104. redirect_to document_url(@document)
  105. end
  106. # 权限判断
  107. # add by nwb
  108. def authorize_document
  109. if !(User.current.admin? || User.current.member_of?(@project) || @document == nil || (@document != nil && @document.is_public==1))
  110. render_403 :message => :notice_not_authorized
  111. end
  112. end
  113. end

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...