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.

admin_controller.rb 7.7 kB

13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 AdminController < ApplicationController
  18. layout 'admin'
  19. menu_item :projects, :only => :projects
  20. menu_item :plugins, :only => :plugins
  21. menu_item :info, :only => :info
  22. before_filter :require_admin
  23. helper :sort
  24. helper :Users
  25. include SortHelper
  26. def index
  27. @no_configuration_data = Redmine::DefaultData::Loader::no_data?
  28. end
  29. def projects
  30. @status = params[:status] || 1
  31. scope = Project.status(@status).order('lft')
  32. scope = scope.like(params[:name]) if params[:name].present?
  33. @projects = scope.all
  34. render :action => "projects", :layout => false if request.xhr?
  35. end
  36. def users
  37. @project_type = params[:project_type]
  38. role = params[:role]
  39. sort_init 'login', 'asc'
  40. sort_update %w(login firstname lastname mail admin created_on last_login_on)
  41. case params[:format]
  42. when 'xml', 'json'
  43. @offset, @limit = api_offset_and_limit({:limit => 15})
  44. else
  45. @limit = 15#per_page_option
  46. end
  47. @status = params[:status] || 1
  48. has = {
  49. "show_changesets" => true
  50. }
  51. # @count = Redmine::Activity::Fetcher.new(User.current, :author => @user).scope_select {|t| !has["show_#{t}"].nil?}.events(nil, nil).count
  52. scope = UserStatus.visible
  53. case role
  54. when 'teacher'
  55. scope = UserStatus.teacher
  56. when 'student'
  57. scope = UserStatus.student
  58. else
  59. end
  60. scope = scope.in_group(params[:group_id]) if params[:group_id].present?
  61. # scope.each do |user|
  62. # UserStatus.create(:changesets_count => user.changesets.count, :watchers_count => user.watcher_users.count, :user_id => user.id)
  63. # end
  64. @user_count = scope.count
  65. @user_pages = Paginator.new @user_count, @limit, params['page']
  66. #@offset ||= @user_pages.offset
  67. #@users = scope.order(sort_clause).limit(@limit).offset(@offset).all
  68. @user_base_tag = params[:id] ? 'base_users':'base'
  69. if params[:user_sort_type].present?
  70. case params[:user_sort_type]
  71. when '0'
  72. @offset ||= @user_pages.reverse_offset
  73. unless @offset == 0
  74. @users_statuses = scope.offset(@offset).limit(@limit).all.reverse
  75. else
  76. limit = @user_count % @limit
  77. if limit == 0
  78. limit = @limit
  79. end
  80. @users_statuses = scope.offset(@offset).limit(limit).all.reverse
  81. end
  82. @s_type = 0
  83. # @projects = @projects.sort {|x,y| y.created_on <=> x.created_on }
  84. # @projects = @projects[@offset, @limit]
  85. when '1'
  86. @offset ||= @user_pages.reverse_offset
  87. unless @offset == 0
  88. @users_statuses = scope.reorder('grade').offset(@offset).limit(@limit).all.reverse
  89. else
  90. limit = @user_count % @limit
  91. if limit == 0
  92. limit = @limit
  93. end
  94. @users_statuses = scope.reorder('grade').offset(@offset).limit(limit).all.reverse
  95. end
  96. @s_type = 1
  97. #sort {|x,y| y.user_status.changesets_count <=> x.user_status.changesets_count}
  98. #@users = @users[@offset, @limit]
  99. when '2'
  100. @offset ||= @user_pages.reverse_offset
  101. unless @offset == 0
  102. @users_statuses = scope.reorder('watchers_count').offset(@offset).limit(@limit).all.reverse
  103. else
  104. limit = @user_count % @limit
  105. if limit == 0
  106. limit = @limit
  107. end
  108. @users_statuses = scope.reorder('watchers_count').offset(@offset).limit(limit).all.reverse
  109. end
  110. @s_type = 2
  111. #@users = @users[@offset, @limit]
  112. end
  113. else
  114. @offset ||= @user_pages.reverse_offset
  115. unless @offset == 0
  116. @users_statuses = scope.reorder('grade').offset(@offset).limit(@limit).all.reverse
  117. else
  118. limit = @user_count % @limit
  119. if limit == 0
  120. limit = @limit
  121. end
  122. @users_statuses = scope.reorder('grade').offset(@offset).limit(limit).all.reverse
  123. end
  124. @s_type = 1
  125. # @projects = @projects.sort {|x,y| y.created_on <=> x.created_on }
  126. # @projects = @projects[@offset, @limit]
  127. end
  128. @users = []
  129. @users_statuses.each do |obj|
  130. @users << User.find_by_id("#{obj.user_id}")
  131. end
  132. respond_to do |format|
  133. format.html {
  134. @groups = Group.all.sort
  135. }
  136. format.api
  137. end
  138. end
  139. def plugins
  140. @plugins = Redmine::Plugin.all
  141. end
  142. # Loads the default configuration
  143. # (roles, trackers, statuses, workflow, enumerations)
  144. def default_configuration
  145. if request.post?
  146. begin
  147. Redmine::DefaultData::Loader::load(params[:lang])
  148. flash[:notice] = l(:notice_default_data_loaded)
  149. rescue Exception => e
  150. flash[:error] = l(:error_can_t_load_default_data, e.message)
  151. end
  152. end
  153. redirect_to admin_path
  154. end
  155. def test_email
  156. raise_delivery_errors = ActionMailer::Base.raise_delivery_errors
  157. # Force ActionMailer to raise delivery errors so we can catch it
  158. ActionMailer::Base.raise_delivery_errors = true
  159. begin
  160. @test = Mailer.test_email(User.current).deliver
  161. flash[:notice] = l(:notice_email_sent, User.current.mail)
  162. rescue Exception => e
  163. flash[:error] = l(:notice_email_error, e.message)
  164. end
  165. ActionMailer::Base.raise_delivery_errors = raise_delivery_errors
  166. redirect_to settings_path(:tab => 'notifications')
  167. end
  168. def info
  169. @db_adapter_name = ActiveRecord::Base.connection.adapter_name
  170. @checklist = [
  171. [:text_default_administrator_account_changed, User.default_admin_account_changed?],
  172. [:text_file_repository_writable, File.writable?(Attachment.storage_path)],
  173. [:text_plugin_assets_writable, File.writable?(Redmine::Plugin.public_directory)],
  174. [:text_rmagick_available, Object.const_defined?(:Magick)]
  175. ]
  176. end
  177. #管理功能用户列表的搜索
  178. def search
  179. sort_init 'login', 'asc'
  180. sort_update %w(login firstname lastname mail admin created_on last_login_on)
  181. case params[:format]
  182. when 'xml', 'json'
  183. @offset, @limit = api_offset_and_limit({:limit => 15})
  184. else
  185. @limit = 15#per_page_option
  186. end
  187. @status = params[:status] || 1
  188. has = {
  189. "show_changesets" => true
  190. }
  191. scope = User.logged.status(@status)
  192. scope = scope.like(params[:name]) if params[:name].present?
  193. @user_count = scope.count
  194. @user_pages = Paginator.new @user_count, @limit, params['page']
  195. @user_base_tag = params[:id] ? 'base_users':'base'
  196. @offset ||= @user_pages.reverse_offset
  197. unless @offset == 0
  198. @users = scope.offset(@offset).limit(@limit).all.reverse
  199. else
  200. limit = @user_count % @limit
  201. if limit == 0
  202. limit = @limit
  203. end
  204. @users = scope.offset(@offset).limit(limit).all.reverse
  205. end
  206. respond_to do |format|
  207. format.html {
  208. @groups = Group.all.sort
  209. }
  210. format.api
  211. end
  212. end
  213. end

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