Merge tag 'V20140708' of http://repository.trustie.net/xianbo/trustie2
升级权限功能、wiki、gtilab前的相对稳定版
This commit is contained in:
commit
70d5ffd95e
|
@ -13,3 +13,4 @@
|
||||||
/Gemfile.lock
|
/Gemfile.lock
|
||||||
/db/schema.rb
|
/db/schema.rb
|
||||||
/Gemfile.lock
|
/Gemfile.lock
|
||||||
|
/lib/plugins/acts_as_versioned/test/debug.log
|
||||||
|
|
30
Gemfile
30
Gemfile
|
@ -14,13 +14,27 @@ gem "i18n", "~> 0.6.0"
|
||||||
gem "coderay", "~> 1.0.6"
|
gem "coderay", "~> 1.0.6"
|
||||||
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
|
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
|
||||||
gem "builder", "3.0.0"
|
gem "builder", "3.0.0"
|
||||||
gem 'acts-as-taggable-on'
|
gem 'acts-as-taggable-on', '2.4.1'
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
gem 'better_errors', path: 'lib/better_errors'
|
gem 'better_errors', path: 'lib/better_errors'
|
||||||
gem 'rack-mini-profiler', path: 'lib/rack-mini-profiler'
|
gem 'rack-mini-profiler', path: 'lib/rack-mini-profiler'
|
||||||
|
if ENV['PRY']
|
||||||
|
gem 'pry'
|
||||||
|
gem 'pry-nav'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
group :test do
|
||||||
|
# shoulda的版本做了改动
|
||||||
|
#gem "shoulda", "~> 3.3.2"
|
||||||
|
gem "shoulda", "> 3.3.2"
|
||||||
|
gem "mocha", "~> 0.13.3"
|
||||||
|
gem 'capybara', '~> 2.0.0'
|
||||||
|
gem 'nokogiri', '< 1.6.0'
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# Gems used only for assets and not required
|
# Gems used only for assets and not required
|
||||||
# in production environments by default.
|
# in production environments by default.
|
||||||
group :assets do
|
group :assets do
|
||||||
|
@ -28,7 +42,7 @@ group :assets do
|
||||||
gem 'coffee-rails', '~> 3.2.1'
|
gem 'coffee-rails', '~> 3.2.1'
|
||||||
|
|
||||||
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
||||||
# gem 'therubyracer', :platforms => :ruby
|
gem 'therubyracer', :platforms => :ruby
|
||||||
|
|
||||||
gem 'uglifier', '>= 1.0.3'
|
gem 'uglifier', '>= 1.0.3'
|
||||||
end
|
end
|
||||||
|
@ -38,6 +52,16 @@ group :ldap do
|
||||||
gem "net-ldap", "~> 0.3.1"
|
gem "net-ldap", "~> 0.3.1"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
platforms :mri, :mingw do
|
||||||
|
group :rmagick do
|
||||||
|
# RMagick 2 supports ruby 1.9
|
||||||
|
# RMagick 1 would be fine for ruby 1.8 but Bundler does not support
|
||||||
|
# different requirements for the same gem on different platforms
|
||||||
|
gem "rmagick", ">= 2.0.0"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Optional gem for OpenID authentication
|
# Optional gem for OpenID authentication
|
||||||
group :openid do
|
group :openid do
|
||||||
gem "ruby-openid", "~> 2.1.4", :require => "openid"
|
gem "ruby-openid", "~> 2.1.4", :require => "openid"
|
||||||
|
@ -63,7 +87,7 @@ if File.exist?(database_file)
|
||||||
adapters.each do |adapter|
|
adapters.each do |adapter|
|
||||||
case adapter
|
case adapter
|
||||||
when 'mysql2'
|
when 'mysql2'
|
||||||
gem "mysql2", "~> 0.3.11", :platforms => [:mri, :mingw]
|
gem "mysql2", "= 0.3.11", :platforms => [:mri, :mingw]
|
||||||
gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
|
gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
|
||||||
when 'mysql'
|
when 'mysql'
|
||||||
gem "mysql", "~> 2.8.1", :platforms => [:mri, :mingw]
|
gem "mysql", "~> 2.8.1", :platforms => [:mri, :mingw]
|
||||||
|
|
53
Gemfile.lock
53
Gemfile.lock
|
@ -52,6 +52,15 @@ GEM
|
||||||
rails (>= 3, < 5)
|
rails (>= 3, < 5)
|
||||||
arel (3.0.2)
|
arel (3.0.2)
|
||||||
builder (3.0.0)
|
builder (3.0.0)
|
||||||
|
capybara (2.0.3)
|
||||||
|
mime-types (>= 1.16)
|
||||||
|
nokogiri (>= 1.3.3)
|
||||||
|
rack (>= 1.0.0)
|
||||||
|
rack-test (>= 0.5.4)
|
||||||
|
selenium-webdriver (~> 2.0)
|
||||||
|
xpath (~> 1.0.0)
|
||||||
|
childprocess (0.5.3)
|
||||||
|
ffi (~> 1.0, >= 1.0.11)
|
||||||
coderay (1.0.9)
|
coderay (1.0.9)
|
||||||
coffee-rails (3.2.2)
|
coffee-rails (3.2.2)
|
||||||
coffee-script (>= 2.2.0)
|
coffee-script (>= 2.2.0)
|
||||||
|
@ -59,11 +68,11 @@ GEM
|
||||||
coffee-script (2.2.0)
|
coffee-script (2.2.0)
|
||||||
coffee-script-source
|
coffee-script-source
|
||||||
execjs
|
execjs
|
||||||
coffee-script-source (1.6.1)
|
coffee-script-source (1.7.0)
|
||||||
erubis (2.7.0)
|
erubis (2.7.0)
|
||||||
execjs (1.4.0)
|
execjs (2.0.2)
|
||||||
multi_json (~> 1.0)
|
|
||||||
fastercsv (1.5.0)
|
fastercsv (1.5.0)
|
||||||
|
ffi (1.9.3-x86-mingw32)
|
||||||
hike (1.2.3)
|
hike (1.2.3)
|
||||||
i18n (0.6.1)
|
i18n (0.6.1)
|
||||||
journey (1.0.4)
|
journey (1.0.4)
|
||||||
|
@ -74,10 +83,14 @@ GEM
|
||||||
mail (2.5.4)
|
mail (2.5.4)
|
||||||
mime-types (~> 1.16)
|
mime-types (~> 1.16)
|
||||||
treetop (~> 1.4.8)
|
treetop (~> 1.4.8)
|
||||||
|
metaclass (0.0.4)
|
||||||
mime-types (1.23)
|
mime-types (1.23)
|
||||||
|
mocha (0.13.3)
|
||||||
|
metaclass (~> 0.0.1)
|
||||||
multi_json (1.7.6)
|
multi_json (1.7.6)
|
||||||
mysql2 (0.3.11-x86-mingw32)
|
mysql2 (0.3.11-x86-mingw32)
|
||||||
net-ldap (0.3.1)
|
net-ldap (0.3.1)
|
||||||
|
nokogiri (1.5.11-x86-mingw32)
|
||||||
polyglot (0.3.3)
|
polyglot (0.3.3)
|
||||||
rack (1.4.5)
|
rack (1.4.5)
|
||||||
rack-cache (1.2)
|
rack-cache (1.2)
|
||||||
|
@ -104,15 +117,28 @@ GEM
|
||||||
rake (>= 0.8.7)
|
rake (>= 0.8.7)
|
||||||
rdoc (~> 3.4)
|
rdoc (~> 3.4)
|
||||||
thor (>= 0.14.6, < 2.0)
|
thor (>= 0.14.6, < 2.0)
|
||||||
rake (10.0.4)
|
rake (10.3.2)
|
||||||
rdoc (3.12.2)
|
rdoc (3.12.2)
|
||||||
json (~> 1.4)
|
json (~> 1.4)
|
||||||
|
rmagick (2.13.2)
|
||||||
ruby-openid (2.1.8)
|
ruby-openid (2.1.8)
|
||||||
sass (3.2.7)
|
rubyzip (1.1.4)
|
||||||
|
sass (3.2.14)
|
||||||
sass-rails (3.2.6)
|
sass-rails (3.2.6)
|
||||||
railties (~> 3.2.0)
|
railties (~> 3.2.0)
|
||||||
sass (>= 3.1.10)
|
sass (>= 3.1.10)
|
||||||
tilt (~> 1.3)
|
tilt (~> 1.3)
|
||||||
|
selenium-webdriver (2.42.0)
|
||||||
|
childprocess (>= 0.5.0)
|
||||||
|
multi_json (~> 1.0)
|
||||||
|
rubyzip (~> 1.0)
|
||||||
|
websocket (~> 1.0.4)
|
||||||
|
shoulda (3.5.0)
|
||||||
|
shoulda-context (~> 1.0, >= 1.0.1)
|
||||||
|
shoulda-matchers (>= 1.4.1, < 3.0)
|
||||||
|
shoulda-context (1.2.1)
|
||||||
|
shoulda-matchers (2.6.1)
|
||||||
|
activesupport (>= 3.0.0)
|
||||||
sprockets (2.2.2)
|
sprockets (2.2.2)
|
||||||
hike (~> 1.2)
|
hike (~> 1.2)
|
||||||
multi_json (~> 1.0)
|
multi_json (~> 1.0)
|
||||||
|
@ -124,9 +150,12 @@ GEM
|
||||||
polyglot
|
polyglot
|
||||||
polyglot (>= 0.3.1)
|
polyglot (>= 0.3.1)
|
||||||
tzinfo (0.3.37)
|
tzinfo (0.3.37)
|
||||||
uglifier (1.0.3)
|
uglifier (2.4.0)
|
||||||
execjs (>= 0.3.0)
|
execjs (>= 0.3.0)
|
||||||
multi_json (>= 1.0.2)
|
json (>= 1.8.0)
|
||||||
|
websocket (1.0.7)
|
||||||
|
xpath (1.0.0)
|
||||||
|
nokogiri (~> 1.3)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
x86-mingw32
|
x86-mingw32
|
||||||
|
@ -134,20 +163,26 @@ PLATFORMS
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
activerecord-jdbc-adapter (= 1.2.5)
|
activerecord-jdbc-adapter (= 1.2.5)
|
||||||
activerecord-jdbcmysql-adapter
|
activerecord-jdbcmysql-adapter
|
||||||
acts-as-taggable-on
|
acts-as-taggable-on (= 2.4.1)
|
||||||
better_errors!
|
better_errors!
|
||||||
builder (= 3.0.0)
|
builder (= 3.0.0)
|
||||||
|
capybara (~> 2.0.0)
|
||||||
coderay (~> 1.0.6)
|
coderay (~> 1.0.6)
|
||||||
coffee-rails (~> 3.2.1)
|
coffee-rails (~> 3.2.1)
|
||||||
fastercsv (~> 1.5.0)
|
fastercsv (~> 1.5.0)
|
||||||
i18n (~> 0.6.0)
|
i18n (~> 0.6.0)
|
||||||
jquery-rails (~> 2.0.2)
|
jquery-rails (~> 2.0.2)
|
||||||
mysql2 (~> 0.3.11)
|
mocha (~> 0.13.3)
|
||||||
|
mysql2 (= 0.3.11)
|
||||||
net-ldap (~> 0.3.1)
|
net-ldap (~> 0.3.1)
|
||||||
|
nokogiri (< 1.6.0)
|
||||||
rack-mini-profiler!
|
rack-mini-profiler!
|
||||||
rack-openid
|
rack-openid
|
||||||
rails (= 3.2.13)
|
rails (= 3.2.13)
|
||||||
|
rmagick (>= 2.0.0)
|
||||||
ruby-openid (~> 2.1.4)
|
ruby-openid (~> 2.1.4)
|
||||||
sass-rails (~> 3.2.3)
|
sass-rails (~> 3.2.3)
|
||||||
seems_rateable!
|
seems_rateable!
|
||||||
|
shoulda (> 3.3.2)
|
||||||
|
therubyracer
|
||||||
uglifier (>= 1.0.3)
|
uglifier (>= 1.0.3)
|
||||||
|
|
35
ReadMe.txt
35
ReadMe.txt
|
@ -1,11 +1,18 @@
|
||||||
patch:
|
patch:
|
||||||
用户姓名的部分,根据issues#655。
|
用户姓名的部分,根据issues#655。
|
||||||
为了修改方便
|
为了修改方便
|
||||||
alias:
|
alias:
|
||||||
方法 之前显示 调整之后
|
方法 之前显示 调整之后
|
||||||
name firstname+lastname login
|
name firstname+lastname login
|
||||||
nickname xxx login
|
nickname xxx login
|
||||||
realname xxx firstname+lastname
|
realname xxx firstname+lastname
|
||||||
|
|
||||||
|
User model经过修改,已经完全集成了user_extensions的功能
|
||||||
|
例如
|
||||||
|
user.gender=1
|
||||||
|
user.save
|
||||||
|
user_extensions字段会自动保存
|
||||||
|
不必要每次user.user_extensions.xxx以及判断是否为空
|
||||||
================================================================================
|
================================================================================
|
||||||
app/models/setting.rb :165
|
app/models/setting.rb :165
|
||||||
# fixed domain url in development. tantantan's bug
|
# fixed domain url in development. tantantan's bug
|
||||||
|
@ -14,22 +21,22 @@ app/models/setting.rb :165
|
||||||
define_singleton_method m do; nil; end if m.to_s =~ /([a-zA-Z]+_domain)$/
|
define_singleton_method m do; nil; end if m.to_s =~ /([a-zA-Z]+_domain)$/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
程序部分链接中制定了subdomain参数,使链接在二级域名中来回跳转。
|
程序部分链接中制定了subdomain参数,使链接在二级域名中来回跳转。
|
||||||
为了开发方便,使之功能在development模式下失效。
|
为了开发方便,使之功能在development模式下失效。
|
||||||
# => nyan
|
# => nyan
|
||||||
================================================================================
|
================================================================================
|
||||||
app/controller/projects_controller.rb ===> projects#fake
|
app/controller/projects_controller.rb ===> projects#fake
|
||||||
fake filter: 修改了传到页面中的Count后缀的数量
|
fake filter: 修改了传到页面中的Count后缀的数量
|
||||||
改为正确的数量,删掉fake过滤器即可
|
改为正确的数量,删掉fake过滤器即可
|
||||||
================================================================================
|
================================================================================
|
||||||
#导航栏匹配域名显示和改变
|
#导航栏匹配域名显示和改变
|
||||||
app\helper\application_helper.rb
|
app\helper\application_helper.rb
|
||||||
# rewrite navigation
|
# rewrite navigation
|
||||||
|
|
||||||
app\views\layouts\_base_header.html.erb
|
app\views\layouts\_base_header.html.erb
|
||||||
# reset navigation by domain name and url through regular match
|
# reset navigation by domain name and url through regular match
|
||||||
================================================================================
|
================================================================================
|
||||||
#首页根据域名匹配进入不同的页面
|
#首页根据域名匹配进入不同的页面
|
||||||
app\controller\welcome_controller.rb
|
app\controller\welcome_controller.rb
|
||||||
def entry_select_user
|
def entry_select_user
|
||||||
if request.original_url.match(/user\.trustie\.net/)
|
if request.original_url.match(/user\.trustie\.net/)
|
||||||
|
@ -37,4 +44,10 @@ app\controller\welcome_controller.rb
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
================================================================================
|
================================================================================
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
0606:新坑
|
||||||
|
user_scores表结构有问题,需要运行
|
||||||
|
bundle exec rake db:migrate:down VERSION=20140410021724
|
||||||
|
bundle exec rake db:migrate:up VERSION=20140410021724
|
|
@ -0,0 +1,2 @@
|
||||||
|
// Place all the behaviors and hooks related to the matching controller here.
|
||||||
|
// All this logic will automatically be available in application.js.
|
|
@ -0,0 +1,2 @@
|
||||||
|
// Place all the behaviors and hooks related to the matching controller here.
|
||||||
|
// All this logic will automatically be available in application.js.
|
|
@ -0,0 +1,2 @@
|
||||||
|
// Place all the behaviors and hooks related to the matching controller here.
|
||||||
|
// All this logic will automatically be available in application.js.
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Place all the behaviors and hooks related to the matching controller here.
|
||||||
|
# All this logic will automatically be available in application.js.
|
||||||
|
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
|
@ -0,0 +1,4 @@
|
||||||
|
/*
|
||||||
|
Place all the styles related to the matching controller here.
|
||||||
|
They will automatically be included in application.css.
|
||||||
|
*/
|
|
@ -0,0 +1,4 @@
|
||||||
|
/*
|
||||||
|
Place all the styles related to the matching controller here.
|
||||||
|
They will automatically be included in application.css.
|
||||||
|
*/
|
|
@ -0,0 +1,4 @@
|
||||||
|
/*
|
||||||
|
Place all the styles related to the matching controller here.
|
||||||
|
They will automatically be included in application.css.
|
||||||
|
*/
|
|
@ -0,0 +1,3 @@
|
||||||
|
// Place all the styles related to the notificationcomments controller here.
|
||||||
|
// They will automatically be included in application.css.
|
||||||
|
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -143,15 +143,18 @@ class AccountController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
#added by bai
|
#added by bai
|
||||||
unless @user.id.nil?
|
if @user.id != nil
|
||||||
ue = UserExtensions.create(:identity => params[:identity].to_i,:technical_title => params[:technical_title], :gender => params[:gender].to_i, :user_id => @user.id, :student_id => params[:no])
|
ue = @user.user_extensions ||= UserExtensions.new
|
||||||
unless params[:province].nil? || params[:city].nil?
|
#ue = UserExtensions.create(:identity => params[:identity].to_i,:technical_title => params[:technical_title], :gender => params[:gender].to_i, :user_id => @user.id, :student_id => )
|
||||||
ue.location = params[:province]
|
ue.identity = params[:identity].to_i
|
||||||
ue.location_city = params[:city]
|
ue.technical_title = params[:technical_title]
|
||||||
ue.save
|
ue.gender = params[:gender].to_i
|
||||||
end
|
ue.user_id = @user.id
|
||||||
|
ue.student_id = params[:no]
|
||||||
|
ue.location = params[:province] if params[:province] != nil
|
||||||
|
ue.location_city = params[:city] if params[:city] != nil
|
||||||
|
ue.save
|
||||||
end
|
end
|
||||||
#end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -94,7 +94,7 @@ class ApplicationController < ActionController::Base
|
||||||
Setting.check_cache
|
Setting.check_cache
|
||||||
# Find the current user
|
# Find the current user
|
||||||
User.current = find_current_user
|
User.current = find_current_user
|
||||||
logger.info(" Current user: " + (User.current.logged? ? "#{User.current.login} (id=#{User.current.id})" : "anonymous")) if logger
|
#logger.info(" Current user: " + (User.current.logged? ? "#{User.current.login} (id=#{User.current.id})" : "anonymous")) if logger
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the current user or nil if no user is logged in
|
# Returns the current user or nil if no user is logged in
|
||||||
|
@ -233,7 +233,15 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
# Authorize the user for the requested action
|
# Authorize the user for the requested action
|
||||||
def authorize(ctrl = params[:controller], action = params[:action], global = false)
|
def authorize(ctrl = params[:controller], action = params[:action], global = false)
|
||||||
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
|
#modify by NWB
|
||||||
|
if @project
|
||||||
|
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
|
||||||
|
elsif @course
|
||||||
|
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @course || @courses, :global => global)
|
||||||
|
else
|
||||||
|
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
|
||||||
|
end
|
||||||
|
|
||||||
if allowed
|
if allowed
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
|
@ -245,6 +253,24 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def authorize_course(ctrl = params[:controller], action = params[:action], global = false)
|
||||||
|
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @course || @course, :global => global)
|
||||||
|
if allowed
|
||||||
|
true
|
||||||
|
else
|
||||||
|
if @course && @course.archived?
|
||||||
|
render_403 :message => :notice_not_authorized_archived_project
|
||||||
|
else
|
||||||
|
deny_access
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def authorize_course_global(ctrl = params[:controller], action = params[:action], global = true)
|
||||||
|
authorize_course(ctrl, action, global)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# Authorize the user for the requested action outside a project
|
# Authorize the user for the requested action outside a project
|
||||||
def authorize_global(ctrl = params[:controller], action = params[:action], global = true)
|
def authorize_global(ctrl = params[:controller], action = params[:action], global = true)
|
||||||
authorize(ctrl, action, global)
|
authorize(ctrl, action, global)
|
||||||
|
@ -259,7 +285,25 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
# Find project of id params[:project_id]
|
# Find project of id params[:project_id]
|
||||||
def find_project_by_project_id
|
def find_project_by_project_id
|
||||||
@project = Project.find(params[:project_id])
|
if params[:project_id]
|
||||||
|
@project = Project.find(params[:project_id])
|
||||||
|
elsif params[:course_id]
|
||||||
|
@course = Course.find(params[:course_id])
|
||||||
|
end
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_contest_by_contest_id
|
||||||
|
@contest = Contest.find(params[:contest_id])
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
|
#<23><><EFBFBD>course_id<69><64>project
|
||||||
|
def find_project_by_course_id
|
||||||
|
@bid = Bid.find params[:course_id]
|
||||||
|
@project = @bid.courses[0]
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
@ -274,11 +318,29 @@ class ApplicationController < ActionController::Base
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_optional_contest
|
||||||
|
@contest = Contest.find(params[:contest_id]) unless params[:contest_id].blank?
|
||||||
|
allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @contest, :global => true)
|
||||||
|
allowed ? true : deny_access
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
# Finds and sets @project based on @object.project
|
# Finds and sets @project based on @object.project
|
||||||
def find_project_from_association
|
def find_project_from_association
|
||||||
render_404 unless @object.present?
|
render_404 unless @object.present?
|
||||||
|
|
||||||
@project = @object.project
|
@project = @object.project
|
||||||
|
if @project == nil && @object.has_attribute?('course_id')
|
||||||
|
@course = @object.course
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_contest_from_association
|
||||||
|
render_404 unless @object.present?
|
||||||
|
|
||||||
|
@contest =@object.contest
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_model_object
|
def find_model_object
|
||||||
|
@ -291,6 +353,24 @@ class ApplicationController < ActionController::Base
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#added by nwb
|
||||||
|
#<23><>ȡ<EFBFBD>γ<EFBFBD>
|
||||||
|
def find_course
|
||||||
|
@course= Course.find(params[:id])
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
|
# def find_model_object_contest
|
||||||
|
# model = self.class.model_object
|
||||||
|
# if model
|
||||||
|
# @object = model.find(params[:id])
|
||||||
|
# self.instance_variable_set('@' + controller_name.singularize, @object) if @object
|
||||||
|
# end
|
||||||
|
# rescue ActiveRecord::RecordNotFound
|
||||||
|
# render_404
|
||||||
|
# end
|
||||||
|
|
||||||
def self.model_object(model)
|
def self.model_object(model)
|
||||||
self.model_object = model
|
self.model_object = model
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,6 +59,8 @@ class AttachmentsController < ApplicationController
|
||||||
:type => detect_content_type(@attachment),
|
:type => detect_content_type(@attachment),
|
||||||
:disposition => (@attachment.image? ? 'inline' : 'attachment')
|
:disposition => (@attachment.image? ? 'inline' : 'attachment')
|
||||||
end
|
end
|
||||||
|
rescue => e
|
||||||
|
redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html"
|
||||||
end
|
end
|
||||||
|
|
||||||
#更新资源文件类型
|
#更新资源文件类型
|
||||||
|
@ -124,10 +126,19 @@ class AttachmentsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @project.nil?
|
# modify by nwb
|
||||||
format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum,@attachment.container) }
|
if @attachment.container_type == 'Course'
|
||||||
|
if @course.nil?
|
||||||
|
format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) }
|
||||||
|
else
|
||||||
|
format.html { redirect_to_referer_or course_path(@course) }
|
||||||
|
end
|
||||||
else
|
else
|
||||||
format.html { redirect_to_referer_or project_path(@project)}
|
if @project.nil?
|
||||||
|
format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) }
|
||||||
|
else
|
||||||
|
format.html { redirect_to_referer_or project_path(@project) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
format.js
|
format.js
|
||||||
|
@ -139,9 +150,9 @@ class AttachmentsController < ApplicationController
|
||||||
# Make sure association callbacks are called
|
# Make sure association callbacks are called
|
||||||
container = @attachment.container
|
container = @attachment.container
|
||||||
@attachment.container.attachments.delete(@attachment)
|
@attachment.container.attachments.delete(@attachment)
|
||||||
if container.attachments.empty?
|
#if container.attachments.empty?
|
||||||
container.delete
|
#container.delete
|
||||||
end
|
#end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to_referer_or respond_path(@bid) }
|
format.html { redirect_to_referer_or respond_path(@bid) }
|
||||||
|
@ -150,7 +161,13 @@ class AttachmentsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def autocomplete
|
def autocomplete
|
||||||
@project = Project.find_by_id(params[:project_id])
|
# modify by nwb
|
||||||
|
if params[:project_id]
|
||||||
|
@project = Project.find_by_id(params[:project_id])
|
||||||
|
elsif params[:course_id]
|
||||||
|
@course = Course.find_by_id(params[:course_id])
|
||||||
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js
|
format.js
|
||||||
end
|
end
|
||||||
|
@ -186,13 +203,47 @@ class AttachmentsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_exist_file_to_course
|
||||||
|
class_id = params[:class_id]
|
||||||
|
attachments = params[:attachment][:attach]
|
||||||
|
|
||||||
|
obj = Course.find_by_id(class_id)
|
||||||
|
attachments.collect do |attach_id|
|
||||||
|
ori = Attachment.find_by_id(attach_id)
|
||||||
|
next if ori.blank?
|
||||||
|
attach_copied_obj = ori.copy
|
||||||
|
attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
|
||||||
|
attach_copied_obj.container = obj
|
||||||
|
attach_copied_obj.created_on = Time.now
|
||||||
|
attach_copied_obj.author_id = User.current.id
|
||||||
|
@obj = obj
|
||||||
|
@save_flag = attach_copied_obj.save
|
||||||
|
@save_message = attach_copied_obj.errors.full_messages
|
||||||
|
end
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.js
|
||||||
|
end
|
||||||
|
rescue NoMethodError
|
||||||
|
@save_flag = false
|
||||||
|
@save_message = [] << l(:error_attachment_empty)
|
||||||
|
respond_to do |format|
|
||||||
|
format.js
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def find_project
|
def find_project
|
||||||
@attachment = Attachment.find(params[:id])
|
@attachment = Attachment.find(params[:id])
|
||||||
# Show 404 if the filename in the url is wrong
|
# Show 404 if the filename in the url is wrong
|
||||||
|
# modify by nwb
|
||||||
raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename
|
raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename
|
||||||
unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication'
|
if @attachment.container_type == 'Course'
|
||||||
@project = @attachment.project
|
@course = @attachment.course
|
||||||
|
else
|
||||||
|
unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication'
|
||||||
|
@project = @attachment.project
|
||||||
|
end
|
||||||
end
|
end
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
|
|
|
@ -25,7 +25,7 @@ class AvatarController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if @temp_file && (@temp_file.size > 0)
|
if @temp_file && (@temp_file.size > 0)
|
||||||
diskfile=disk_filename(@source_type,@source_id)
|
diskfile=disk_filename(@source_type,@source_id)
|
||||||
@urlfile='/' << File.join("images","avatars",avatar_directory(@source_type),avatar_filename(@source_id,@image_file))
|
@urlfile='/' << File.join("images","avatars",avatar_directory(@source_type),avatar_filename(@source_id,@image_file))
|
||||||
logger.info("Saving avatar '#{diskfile}' (#{@temp_file.size} bytes)")
|
logger.info("Saving avatar '#{diskfile}' (#{@temp_file.size} bytes)")
|
||||||
|
@ -55,7 +55,7 @@ class AvatarController < ApplicationController
|
||||||
# saved = @avatar.save
|
# saved = @avatar.save
|
||||||
begin
|
begin
|
||||||
f = Magick::ImageList.new(diskfile)
|
f = Magick::ImageList.new(diskfile)
|
||||||
width = 300.0;
|
width = 300.0
|
||||||
proportion = (width/f[0].columns)
|
proportion = (width/f[0].columns)
|
||||||
height = (f[0].rows*proportion)
|
height = (f[0].rows*proportion)
|
||||||
f.resize_to_fill!(width,height)
|
f.resize_to_fill!(width,height)
|
||||||
|
|
|
@ -3,12 +3,13 @@ class BidsController < ApplicationController
|
||||||
#Added by young
|
#Added by young
|
||||||
menu_item l(:label_homework), :only => [:edit, :udpate]
|
menu_item l(:label_homework), :only => [:edit, :udpate]
|
||||||
menu_item :respond
|
menu_item :respond
|
||||||
|
menu_item :course, :only => :show_courseEx
|
||||||
menu_item :project, :only => [:show_project,:show_results, :new_submit_homework]
|
menu_item :project, :only => [:show_project,:show_results, :new_submit_homework]
|
||||||
menu_item :homework_respond, :only => :homework_respond
|
menu_item :homework_respond, :only => :homework_respond
|
||||||
menu_item :homework_statistics, :only => :homework_statistics
|
menu_item :homework_statistics, :only => :homework_statistics
|
||||||
#Ended by young
|
#Ended by young
|
||||||
before_filter :find_bid, :only => [:show, :show_project, :create,:destroy,:more,:back,:add,:delete,:new,:show_results,:set_reward, :add_homework, :fork, :create_fork,
|
before_filter :find_bid, :only => [:show, :show_project, :create,:destroy,:more,:back,:add,:delete,:new,:show_results,:set_reward, :add_homework, :fork, :create_fork,
|
||||||
:show_course, :show_bid_project, :show_bid_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings]
|
:show_course, :show_courseEx,:show_bid_project, :show_bid_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings]
|
||||||
# added by fq
|
# added by fq
|
||||||
before_filter :require_login, :only => [:join_in_contest, :unjoin_in_contest]
|
before_filter :require_login, :only => [:join_in_contest, :unjoin_in_contest]
|
||||||
# end
|
# end
|
||||||
|
@ -25,7 +26,14 @@ class BidsController < ApplicationController
|
||||||
helper :projects
|
helper :projects
|
||||||
helper :words
|
helper :words
|
||||||
helper :welcome
|
helper :welcome
|
||||||
|
|
||||||
|
def find_project_by_bid_id
|
||||||
|
@bid = Bid.find(params[:id])
|
||||||
|
@project = @bid.courses[0]
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
def homework_ajax_modal
|
def homework_ajax_modal
|
||||||
@bid = Bid.find_by_id(params[:id])
|
@bid = Bid.find_by_id(params[:id])
|
||||||
# find_bid
|
# find_bid
|
||||||
|
@ -176,12 +184,13 @@ class BidsController < ApplicationController
|
||||||
@homework.budget = 0
|
@homework.budget = 0
|
||||||
@homework.author_id = User.current.id
|
@homework.author_id = User.current.id
|
||||||
@homework.commit = 0
|
@homework.commit = 0
|
||||||
@homework.homework_type = params[:bid][:homework_type]
|
@homework.homework_type = 1
|
||||||
|
@homework.is_evaluation = params[:bid][:is_evaluation]
|
||||||
@homework.parent_id = @bid.id
|
@homework.parent_id = @bid.id
|
||||||
@homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
|
@homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
|
||||||
# @bid.
|
# @bid.
|
||||||
if @homework.save
|
if @homework.save
|
||||||
HomeworkForCourse.create(:project_id => params[:course], :bid_id => @homework.id)
|
HomeworkForCourse.create(:course_id => params[:course], :bid_id => @homework.id)
|
||||||
unless @bid.watched_by?(User.current)
|
unless @bid.watched_by?(User.current)
|
||||||
if @bid.add_watcher(User.current)
|
if @bid.add_watcher(User.current)
|
||||||
flash[:notice] = l(:label_bid_succeed)
|
flash[:notice] = l(:label_bid_succeed)
|
||||||
|
@ -191,11 +200,9 @@ class BidsController < ApplicationController
|
||||||
else
|
else
|
||||||
@bid.safe_attributes = params[:bid]
|
@bid.safe_attributes = params[:bid]
|
||||||
@courses = []
|
@courses = []
|
||||||
@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
|
@membership = User.current.coursememberships.all#(:conditions => Project.visible_condition(User.current))
|
||||||
@membership.each do |membership|
|
@membership.each do |membership|
|
||||||
if membership.project.project_type == 1
|
@courses << membership.course
|
||||||
@courses << membership.project
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
render :action => 'fork'
|
render :action => 'fork'
|
||||||
end
|
end
|
||||||
|
@ -281,6 +288,7 @@ class BidsController < ApplicationController
|
||||||
end
|
end
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
# 显示课程
|
||||||
def show_course
|
def show_course
|
||||||
bids = Bid.where('parent_id = ?', @bid.id)
|
bids = Bid.where('parent_id = ?', @bid.id)
|
||||||
@courses = []
|
@courses = []
|
||||||
|
@ -369,7 +377,7 @@ class BidsController < ApplicationController
|
||||||
unless(membership.project.project_type==1)
|
unless(membership.project.project_type==1)
|
||||||
membership.member_roles.each{|role|
|
membership.member_roles.each{|role|
|
||||||
if(role.role_id == 3)
|
if(role.role_id == 3)
|
||||||
@option << membership.project
|
@option << membership.project
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -391,29 +399,31 @@ class BidsController < ApplicationController
|
||||||
end
|
end
|
||||||
@bidding_project = @temp
|
@bidding_project = @temp
|
||||||
else
|
else
|
||||||
#added by nie
|
#added by nie
|
||||||
@temp = []
|
@temp = []
|
||||||
@bidding_project.each do |pro|
|
@bidding_project.each do |pro|
|
||||||
if pro.project && pro.project.project_status
|
if pro.project && pro.project.project_status
|
||||||
@temp << pro
|
@temp << pro
|
||||||
|
end
|
||||||
|
@temp
|
||||||
end
|
end
|
||||||
@temp
|
if @temp.size > 0
|
||||||
end
|
|
||||||
if @temp.size > 0
|
|
||||||
@bidding_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade}
|
@bidding_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade}
|
||||||
end
|
end
|
||||||
#ended
|
#ended
|
||||||
end
|
end
|
||||||
|
|
||||||
if @bid.homework_type == 1
|
if @bid.homework_type == 1
|
||||||
@homework = HomeworkAttach.new
|
@homework = HomeworkAttach.new
|
||||||
@homework_list = @bid.homeworks
|
#@homework_list = @bid.homeworks
|
||||||
|
#增加作业按评分排序,
|
||||||
|
@homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC').order("#{HomeworkAttach.table_name}.created_at ASC")
|
||||||
if params[:student_id].present?
|
if params[:student_id].present?
|
||||||
@temp = []
|
@temp = []
|
||||||
@homework_list.each do |pro|
|
@homework_list.each do |pro|
|
||||||
if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
|
if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
|
||||||
@temp << pro
|
@temp << pro
|
||||||
end
|
end
|
||||||
@temp
|
@temp
|
||||||
end
|
end
|
||||||
@homework_list = @temp
|
@homework_list = @temp
|
||||||
|
@ -422,22 +432,109 @@ class BidsController < ApplicationController
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @bid.reward_type == 3
|
if @bid.reward_type == 3
|
||||||
format.html {
|
format.html {
|
||||||
render :layout => 'base_homework'
|
render :layout => 'base_homework'
|
||||||
}
|
}
|
||||||
elsif @bid.reward_type == 1
|
elsif @bid.reward_type == 1
|
||||||
format.html {
|
format.html {
|
||||||
render :layout => 'base_bids'
|
render :layout => 'base_bids'
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
format.html {
|
format.html {
|
||||||
render :layout => 'base_contest'
|
render :layout => 'base_contest'
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
format.api
|
format.api
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 显示作业课程
|
||||||
|
# add by nwb
|
||||||
|
def show_courseEx
|
||||||
|
if (User.current.logged? && User.current.member_of_course?(@bid.courses.first))
|
||||||
|
# flash[:notice] = ""
|
||||||
|
@membership = User.current.coursememberships.all(:conditions => Course.visible_condition(User.current))
|
||||||
|
@option = []
|
||||||
|
@membership.each do |membership|
|
||||||
|
membership.member_roles.each{|role|
|
||||||
|
if(role.role_id == 3)
|
||||||
|
@option << membership.course
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
@user = @bid.author
|
||||||
|
@bidding_project = @bid.biding_projects.all
|
||||||
|
|
||||||
|
if params[:student_id].present?
|
||||||
|
@temp = []
|
||||||
|
@bidding_project.each do |pro|
|
||||||
|
if pro.project && pro.project.project_status
|
||||||
|
if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
|
||||||
|
@temp << pro
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@temp
|
||||||
|
end
|
||||||
|
@bidding_project = @temp
|
||||||
|
else
|
||||||
|
#added by nie
|
||||||
|
@temp = []
|
||||||
|
@bidding_project.each do |pro|
|
||||||
|
if pro.project && pro.project.project_status
|
||||||
|
@temp << pro
|
||||||
|
end
|
||||||
|
@temp
|
||||||
|
end
|
||||||
|
if @temp.size > 0
|
||||||
|
@bidding_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade}
|
||||||
|
end
|
||||||
|
#ended
|
||||||
|
end
|
||||||
|
|
||||||
|
if @bid.homework_type == 1
|
||||||
|
@homework = HomeworkAttach.new
|
||||||
|
#@homework_list = @bid.homeworks
|
||||||
|
#增加作业按评分排序,
|
||||||
|
#@homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC').order("#{HomeworkAttach.table_name}.created_at ASC")
|
||||||
|
@homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*,
|
||||||
|
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{@bid.author_id}) AS t_score,
|
||||||
|
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id <> #{@bid.author_id}) AS s_score
|
||||||
|
FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY
|
||||||
|
(CASE WHEN t_score IS NULL THEN 0 ELSE t_score * #{@bid.proportion * 1.0 / 100} END + CASE WHEN s_score IS NULL THEN 0 ELSE s_score * #{1 - @bid.proportion * 1.0 / 100} END) DESC,created_at ASC")
|
||||||
|
if params[:student_id].present?
|
||||||
|
@temp = []
|
||||||
|
@homework_list.each do |pro|
|
||||||
|
if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
|
||||||
|
@temp << pro
|
||||||
|
end
|
||||||
|
@temp
|
||||||
|
end
|
||||||
|
@homework_list = @temp
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @bid.reward_type == 3
|
||||||
|
format.html {
|
||||||
|
render :layout => 'base_homework'
|
||||||
|
}
|
||||||
|
elsif @bid.reward_type == 1
|
||||||
|
format.html {
|
||||||
|
render :layout => 'base_bids'
|
||||||
|
}
|
||||||
|
else
|
||||||
|
format.html {
|
||||||
|
render :layout => 'base_contest'
|
||||||
|
}
|
||||||
|
end
|
||||||
|
format.api
|
||||||
|
end
|
||||||
|
else
|
||||||
|
render_403 :message => :notice_not_authorized
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
##### by huang
|
##### by huang
|
||||||
def show_project_homework
|
def show_project_homework
|
||||||
# flash[:notice] = ""
|
# flash[:notice] = ""
|
||||||
|
@ -523,6 +620,7 @@ class BidsController < ApplicationController
|
||||||
message = params[:bid_message][:message] + "\n" + params[:reference_content]
|
message = params[:bid_message][:message] + "\n" + params[:reference_content]
|
||||||
else
|
else
|
||||||
message = params[:bid_message][:message]
|
message = params[:bid_message][:message]
|
||||||
|
@m = message
|
||||||
end
|
end
|
||||||
refer_user_id = params[:bid_message][:reference_user_id].to_i
|
refer_user_id = params[:bid_message][:reference_user_id].to_i
|
||||||
@bid.add_jour(User.current, message, refer_user_id)
|
@bid.add_jour(User.current, message, refer_user_id)
|
||||||
|
@ -689,17 +787,19 @@ class BidsController < ApplicationController
|
||||||
@bid = Bid.new
|
@bid = Bid.new
|
||||||
@bid.name = params[:bid][:name]
|
@bid.name = params[:bid][:name]
|
||||||
@bid.description = params[:bid][:description]
|
@bid.description = params[:bid][:description]
|
||||||
|
@bid.is_evaluation = params[:bid][:is_evaluation]
|
||||||
|
@bid.proportion = params[:bid][:proportion]
|
||||||
@bid.reward_type = 3
|
@bid.reward_type = 3
|
||||||
# @bid.budget = params[:bid][:budget]
|
# @bid.budget = params[:bid][:budget]
|
||||||
@bid.deadline = params[:bid][:deadline]
|
@bid.deadline = params[:bid][:deadline]
|
||||||
@bid.budget = 0
|
@bid.budget = 0
|
||||||
@bid.author_id = User.current.id
|
@bid.author_id = User.current.id
|
||||||
@bid.commit = 0
|
@bid.commit = 0
|
||||||
@bid.homework_type = params[:bid][:homework_type]
|
@bid.homework_type = 1
|
||||||
@bid.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
|
@bid.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
|
||||||
# @bid.
|
# @bid.
|
||||||
if @bid.save
|
if @bid.save
|
||||||
HomeworkForCourse.create(:project_id => params[:course_id], :bid_id => @bid.id)
|
HomeworkForCourse.create(:course_id => params[:course_id], :bid_id => @bid.id)
|
||||||
unless @bid.watched_by?(User.current)
|
unless @bid.watched_by?(User.current)
|
||||||
if @bid.add_watcher(User.current)
|
if @bid.add_watcher(User.current)
|
||||||
flash[:notice] = l(:label_bid_succeed)
|
flash[:notice] = l(:label_bid_succeed)
|
||||||
|
@ -709,19 +809,25 @@ class BidsController < ApplicationController
|
||||||
else
|
else
|
||||||
@bid.safe_attributes = params[:bid]
|
@bid.safe_attributes = params[:bid]
|
||||||
@homework = @bid
|
@homework = @bid
|
||||||
@project = Project.find_by_id(params[:course_id])
|
@course = Course.find_by_id(params[:course_id])
|
||||||
@project_id = @project.id
|
@course_id = @course.id
|
||||||
render file: 'projects/new_homework', layout: 'base_courses'
|
#respond_to do |format|
|
||||||
|
# format.html { redirect_to new_homework_course_path(params[:course_id]),:layout => 'base_courses'}
|
||||||
|
# format.api { render_validation_errors(@bid) }
|
||||||
|
#end
|
||||||
|
render file: 'courses/new_homework', layout: 'base_courses'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# modify by nwb\
|
||||||
|
# 编辑作业
|
||||||
def edit
|
def edit
|
||||||
@bid = Bid.find(params[:bid_id])
|
@bid = Bid.find(params[:bid_id])
|
||||||
if (User.current.admin?||User.current.id==@bid.author_id)
|
if (User.current.admin?||User.current.id==@bid.author_id)
|
||||||
@project_id = params[:project_id]
|
@course_id = params[:course_id]
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {
|
format.html {
|
||||||
@project = Project.find(params[:project_id])
|
@course = Course.find(params[:course_id])
|
||||||
@user= User.find(User.current.id)
|
@user= User.find(User.current.id)
|
||||||
render :layout => 'base_courses'
|
render :layout => 'base_courses'
|
||||||
}
|
}
|
||||||
|
@ -733,11 +839,11 @@ class BidsController < ApplicationController
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@bid = Bid.find(params[:id])
|
@bid = Bid.find(params[:id])
|
||||||
@project = @bid.courses.first#Project.find(params[:course_id])
|
@course = @bid.courses.first#Project.find(params[:course_id])
|
||||||
@bid.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
|
@bid.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
|
||||||
if @bid.update_attributes(params[:bid]) && @bid.save
|
if @bid.update_attributes(params[:bid]) && @bid.save
|
||||||
flash[:notice] = l(:label_update_homework_succeed)
|
flash[:notice] = l(:label_update_homework_succeed)
|
||||||
redirect_to project_homework_path(@project)
|
redirect_to course_homework_path(@course)
|
||||||
else
|
else
|
||||||
@bid.safe_attributes = params[:bid]
|
@bid.safe_attributes = params[:bid]
|
||||||
render :action => 'edit', :layout =>'base_courses'
|
render :action => 'edit', :layout =>'base_courses'
|
||||||
|
@ -872,7 +978,7 @@ class BidsController < ApplicationController
|
||||||
|
|
||||||
def find_bid
|
def find_bid
|
||||||
if params[:id]
|
if params[:id]
|
||||||
@bid = Bid.find(params[:id])
|
@bid = Bid.find(params[:id], :include => [{:homeworks => :user}])
|
||||||
@user = @bid.author
|
@user = @bid.author
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
|
@ -881,9 +987,10 @@ class BidsController < ApplicationController
|
||||||
|
|
||||||
def memberAccess
|
def memberAccess
|
||||||
# 是课程,则判断当前用户是否参加了课程
|
# 是课程,则判断当前用户是否参加了课程
|
||||||
return 0 if @bid.courses.first.project_type == Project::ProjectType_project
|
return true if current_user.admin?
|
||||||
|
#return 0 if @bid.courses.first.project_type == Project::ProjectType_project
|
||||||
currentUser = User.current
|
currentUser = User.current
|
||||||
render_403 unless currentUser.member_of?(@bid.courses.first)
|
render_403 unless currentUser.member_of_cousrse?(@bid.courses.first)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,17 +28,25 @@ class BoardsController < ApplicationController
|
||||||
helper :watchers
|
helper :watchers
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@boards = @project.boards.includes(:last_message => :author).all
|
#modify by nwb
|
||||||
@boards = [] << @boards[0] if @boards.any?
|
if @project
|
||||||
if @boards.size == 1
|
@boards = @project.boards.includes(:last_message => :author).all
|
||||||
@board = @boards.first
|
@boards = [] << @boards[0] if @boards.any?
|
||||||
show and return
|
if @boards.size == 1
|
||||||
end
|
@board = @boards.first
|
||||||
if @project.project_type == 1
|
show and return
|
||||||
render :layout => 'base_courses'
|
end
|
||||||
else
|
render :layout => false if request.xhr?
|
||||||
render :layout => false if request.xhr?
|
elsif @course
|
||||||
|
@boards = @course.boards.includes(:last_message => :author).all
|
||||||
|
@boards = [] << @boards[0] if @boards.any?
|
||||||
|
if @boards.size == 1
|
||||||
|
@board = @boards.first
|
||||||
|
show and return
|
||||||
|
end
|
||||||
|
render :layout => 'base_courses'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@ -60,10 +68,11 @@ class BoardsController < ApplicationController
|
||||||
preload(:author, {:last_reply => :author}).
|
preload(:author, {:last_reply => :author}).
|
||||||
all
|
all
|
||||||
@message = Message.new(:board => @board)
|
@message = Message.new(:board => @board)
|
||||||
if @project.project_type ==1
|
#modify by nwb
|
||||||
render :action => 'show', :layout => 'base_courses'
|
if @project
|
||||||
else
|
|
||||||
render :action => 'show', :layout => !request.xhr?
|
render :action => 'show', :layout => !request.xhr?
|
||||||
|
elsif @course
|
||||||
|
render :action => 'show', :layout => 'base_courses'
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
format.atom {
|
format.atom {
|
||||||
|
@ -72,7 +81,12 @@ class BoardsController < ApplicationController
|
||||||
includes(:author, :board).
|
includes(:author, :board).
|
||||||
limit(Setting.feeds_limit.to_i).
|
limit(Setting.feeds_limit.to_i).
|
||||||
all
|
all
|
||||||
render_feed(@messages, :title => "#{@project}: #{@board}")
|
if @project
|
||||||
|
render_feed(@messages, :title => "#{@project}: #{@board}")
|
||||||
|
elsif @course
|
||||||
|
render_feed(@messages, :title => "#{@course}: #{@board}")
|
||||||
|
end
|
||||||
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
class CommentsController < ApplicationController
|
class CommentsController < ApplicationController
|
||||||
default_search_scope :news
|
default_search_scope :news
|
||||||
model_object News
|
model_object News
|
||||||
before_filter :find_model_object
|
before_filter :find_model_object
|
||||||
before_filter :find_project_from_association
|
before_filter :find_project_from_association
|
||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
|
|
||||||
|
@ -50,4 +50,6 @@ class CommentsController < ApplicationController
|
||||||
@comment = nil
|
@comment = nil
|
||||||
@news
|
@news
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,187 @@
|
||||||
|
class ContestnotificationsController < ApplicationController
|
||||||
|
# GET /contestnotifications
|
||||||
|
# GET /contestnotifications.json
|
||||||
|
layout 'base_newcontest'
|
||||||
|
default_search_scope :contestnotifications
|
||||||
|
model_object Contestnotification
|
||||||
|
# before_filter :find_model_object, :except => [:new, :create, :index]
|
||||||
|
# before_filter :find_contest_from_association, :except => [:new, :create, :index]
|
||||||
|
before_filter :find_contest_by_contest_id, :only => [:new, :create]
|
||||||
|
before_filter :find_contest
|
||||||
|
before_filter :find_author
|
||||||
|
# before_filter :authorize, :except => [:index]
|
||||||
|
before_filter :find_optional_contest, :only => [:index]
|
||||||
|
accept_rss_auth :index
|
||||||
|
accept_api_auth :index
|
||||||
|
|
||||||
|
before_filter :access_edit_destroy, only: [:edit ,:update, :destroy]
|
||||||
|
|
||||||
|
def find_author
|
||||||
|
@user = @contest.author
|
||||||
|
render_404 if @user.nil?
|
||||||
|
end
|
||||||
|
def find_contest
|
||||||
|
@contest = Contest.find(params[:contest_id])
|
||||||
|
render_404 if @contest.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def index
|
||||||
|
|
||||||
|
# @contestnotifications = Contestnotification.all
|
||||||
|
#
|
||||||
|
# respond_to do |format|
|
||||||
|
# format.html # index.html.erb
|
||||||
|
# format.json { render json: @contestnotifications }
|
||||||
|
# end
|
||||||
|
|
||||||
|
### begin ###
|
||||||
|
case params[:format]
|
||||||
|
when 'xml', 'json'
|
||||||
|
@offset, @limit = api_offset_and_limit
|
||||||
|
else
|
||||||
|
@limit = 10
|
||||||
|
end
|
||||||
|
|
||||||
|
scope = @contest ? @contest.contestnotifications.visible : Contestnotifications.visible
|
||||||
|
|
||||||
|
@contestnotifications_count = scope.count
|
||||||
|
@contestnotifications_pages = Paginator.new @contestnotifications_count, @limit, params['page']
|
||||||
|
@offset ||= @contestnotifications_pages.offset
|
||||||
|
@contestnotificationss = scope.all(:include => [:author, :contest],
|
||||||
|
:order => "#{Contestnotification.table_name}.created_at DESC",
|
||||||
|
:offset => @offset,
|
||||||
|
:limit => @limit)
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html {
|
||||||
|
@contestnotification = Contestnotification.new # for adding news inline
|
||||||
|
render :layout => 'base_newcontest'
|
||||||
|
}
|
||||||
|
format.api
|
||||||
|
format.atom { render_feed(@contestnotificationss, :title => (@contest ? @contest.name : Setting.app_title) + ": #{l(:label_contest_notification)}") }
|
||||||
|
end
|
||||||
|
### end ###
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /contestnotifications/1
|
||||||
|
# GET /contestnotifications/1.json
|
||||||
|
def show
|
||||||
|
@contestnotification = Contestnotification.find(params[:id])
|
||||||
|
|
||||||
|
#
|
||||||
|
# respond_to do |format|
|
||||||
|
# format.html # show.html.erb
|
||||||
|
# format.json { render json: @contestnotification }
|
||||||
|
# end
|
||||||
|
@notificationcomments = @contestnotification.notificationcomments
|
||||||
|
@notificationcomments.reverse! if User.current.wants_notificationcomments_in_reverse_order?
|
||||||
|
render :layout => 'base_newcontest'
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /contestnotifications/new
|
||||||
|
# GET /contestnotifications/new.json
|
||||||
|
def new
|
||||||
|
# @contestnotification = Contestnotification.new
|
||||||
|
#
|
||||||
|
# respond_to do |format|
|
||||||
|
# format.html # new.html.erb
|
||||||
|
# format.json { render json: @contestnotification }
|
||||||
|
# end
|
||||||
|
@contestnotification = Contestnotification.new(:contest => @contest, :author => User.current)
|
||||||
|
render :layout => 'base_newcontest'
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /contestnotifications/1/edit
|
||||||
|
def edit
|
||||||
|
@contestnotification = Contestnotification.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
# POST /contestnotifications
|
||||||
|
# POST /contestnotifications.json
|
||||||
|
def create
|
||||||
|
# @contestnotification = Contestnotification.new(params[:contestnotification])
|
||||||
|
#
|
||||||
|
# respond_to do |format|
|
||||||
|
# if @contestnotification.save
|
||||||
|
# format.html { redirect_to @contestnotification, notice: 'Contestnotification was successfully created.' }
|
||||||
|
# format.json { render json: @contestnotification, status: :created, location: @contestnotification }
|
||||||
|
# else
|
||||||
|
# format.html { render action: "new" }
|
||||||
|
# format.json { render json: @contestnotification.errors, status: :unprocessable_entity }
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
@contestnotification = Contestnotification.new(:contest => @contest, :author => User.current)
|
||||||
|
@contestnotification.safe_attributes = params[:contestnotification]
|
||||||
|
@contestnotification.save_attachments(params[:attachments])
|
||||||
|
if @contestnotification.save
|
||||||
|
render_attachment_warning_if_needed(@contestnotification)
|
||||||
|
flash[:notice] = l(:notice_successful_create)
|
||||||
|
redirect_to contest_contestnotifications_path(@contest)
|
||||||
|
else
|
||||||
|
layout_file = 'base_newcontest'
|
||||||
|
render :action => 'new', :layout => layout_file
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# PUT /contestnotifications/1
|
||||||
|
# PUT /contestnotifications/1.json
|
||||||
|
def update
|
||||||
|
# @contestnotification = Contestnotification.find(params[:id])
|
||||||
|
#
|
||||||
|
# respond_to do |format|
|
||||||
|
# if @contestnotification.update_attributes(params[:contestnotification])
|
||||||
|
# format.html { redirect_to @contestnotification, notice: 'Contestnotification was successfully updated.' }
|
||||||
|
# format.json { head :no_content }
|
||||||
|
# else
|
||||||
|
# format.html { render action: "edit" }
|
||||||
|
# format.json { render json: @contestnotification.errors, status: :unprocessable_entity }
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
@contestnotification = Contestnotification.find(params[:id])
|
||||||
|
@contestnotification.safe_attributes = params[:contestnotification]
|
||||||
|
@contestnotification.save_attachments(params[:attachments])
|
||||||
|
if @contestnotification.save
|
||||||
|
render_attachment_warning_if_needed(@contestnotification)
|
||||||
|
flash[:notice] = l(:notice_successful_update)
|
||||||
|
redirect_to contest_contestnotification_path(@contestnotification.contest, @contestnotification)
|
||||||
|
else
|
||||||
|
render :action => 'edit'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# DELETE /contestnotifications/1
|
||||||
|
# DELETE /contestnotifications/1.json
|
||||||
|
def destroy
|
||||||
|
# @contestnotification = Contestnotification.find(params[:id])
|
||||||
|
# @contestnotification.destroy
|
||||||
|
#
|
||||||
|
# respond_to do |format|
|
||||||
|
# format.html { redirect_to contestnotifications_url }
|
||||||
|
# format.json { head :no_content }
|
||||||
|
# end
|
||||||
|
@contestnotification = Contestnotification.find(params[:id])
|
||||||
|
@contestnotification.destroy
|
||||||
|
redirect_to contest_contestnotifications_path(@contest)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def find_optional_contest
|
||||||
|
return true unless params[:id]
|
||||||
|
@contest = Contest.find(params[:id])
|
||||||
|
# authorize
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
|
def access_edit_destroy
|
||||||
|
if (User.current.admin? && User.current.logged? )||(User.current == @contest.author && User.current.logged?)
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
render_403
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -4,9 +4,9 @@ class ContestsController < ApplicationController
|
||||||
menu_item :respond
|
menu_item :respond
|
||||||
menu_item :project, :only => :show_project
|
menu_item :project, :only => :show_project
|
||||||
menu_item :application, :only => :show_softapplication
|
menu_item :application, :only => :show_softapplication
|
||||||
menu_item :attendingcontest, :only => :show_attendingcontest
|
menu_item :attendingcontests, :only => :show_attendingcontest
|
||||||
menu_item :contestnotification, :only => :show_notification
|
menu_item :contestnotifications, :only => :index
|
||||||
before_filter :find_contest, :only => [:show_contest, :show_project, :show_softapplication, :show_attendingcontest, :show_notification, :set_reward_project, :set_reward_softapplication, :create,:destroy,:more,:back,:add,:add_softapplication,:new,:show_results, :set_reward,
|
before_filter :find_contest, :only => [:show_contest, :show_project, :show_softapplication, :show_attendingcontest, :index, :set_reward_project, :set_reward_softapplication, :create,:destroy,:more,:back,:add,:add_softapplication,:new,:show_results, :set_reward,
|
||||||
:show_contest_project, :show_contest_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings]
|
:show_contest_project, :show_contest_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings]
|
||||||
|
|
||||||
# added by fq
|
# added by fq
|
||||||
|
@ -26,8 +26,11 @@ class ContestsController < ApplicationController
|
||||||
# @contests = Contest.visible
|
# @contests = Contest.visible
|
||||||
# @contests ||= []
|
# @contests ||= []
|
||||||
@offset, @limit = api_offset_and_limit({:limit => 10})
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
||||||
@contests = Contest.visible
|
@contests = Contest.visible
|
||||||
@contests = @contests.like(params[:name]) if params[:name].present?
|
@contests = @contests.like(params[:name]) if params[:name].present?
|
||||||
|
if params[:contests_search]
|
||||||
|
(redirect_to contests_path, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
|
||||||
|
end
|
||||||
@contest_count = @contests.count
|
@contest_count = @contests.count
|
||||||
@contest_pages = Paginator.new @contest_count, @limit, params['page']
|
@contest_pages = Paginator.new @contest_count, @limit, params['page']
|
||||||
|
|
||||||
|
@ -74,6 +77,25 @@ class ContestsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def homework
|
||||||
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
||||||
|
@bids = @course.homeworks.order('deadline DESC')
|
||||||
|
@bids = @bids.like(params[:name]) if params[:name].present?
|
||||||
|
@bid_count = @bids.count
|
||||||
|
@bid_pages = Paginator.new @bid_count, @limit, params['page']
|
||||||
|
|
||||||
|
@offset ||= @bid_pages.reverse_offset
|
||||||
|
unless @offset == 0
|
||||||
|
@bids = @bids.offset(@offset).limit(@limit).all.reverse
|
||||||
|
else
|
||||||
|
limit = @bid_count % @limit
|
||||||
|
@bids = @bids.offset(@offset).limit(limit).all.reverse
|
||||||
|
end
|
||||||
|
render :layout => 'base_courses'
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def show_contest
|
def show_contest
|
||||||
@user = @contest.author
|
@user = @contest.author
|
||||||
@jours = @contest.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
|
@jours = @contest.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
|
||||||
|
@ -210,11 +232,14 @@ class ContestsController < ApplicationController
|
||||||
# @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page']
|
# @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page']
|
||||||
@membership.each do |membership|
|
@membership.each do |membership|
|
||||||
unless(membership.project.project_type==1)
|
unless(membership.project.project_type==1)
|
||||||
membership.member_roles.each{|role|
|
#membership.member_roles.each{|role|
|
||||||
if(role.role_id == 3)
|
# if(role.role_id == 3)
|
||||||
@option << membership.project
|
# @option << membership.project
|
||||||
end
|
# end
|
||||||
}
|
#}
|
||||||
|
if User.current.allowed_to?({:controller => "projects", :action => "edit"}, membership.project, :global => false)
|
||||||
|
@option << membership.project
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@user = @contest.author
|
@user = @contest.author
|
||||||
|
@ -301,11 +326,15 @@ class ContestsController < ApplicationController
|
||||||
# @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page']
|
# @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page']
|
||||||
@membership.each do |membership|
|
@membership.each do |membership|
|
||||||
unless(membership.project.project_type==1)
|
unless(membership.project.project_type==1)
|
||||||
membership.member_roles.each{|role|
|
#membership.member_roles.each{|role|
|
||||||
if(role.role_id == 3)
|
#if(role.role_id == 3)
|
||||||
|
#@option << membership.project
|
||||||
|
#end
|
||||||
|
#}
|
||||||
|
#拥有编辑项目权限的可将该项目参赛
|
||||||
|
if User.current.allowed_to?({:controller => "projects", :action => "edit"}, membership.project, :global => false)
|
||||||
@option << membership.project
|
@option << membership.project
|
||||||
end
|
end
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@user = @contest.author
|
@user = @contest.author
|
||||||
|
|
|
@ -1,18 +1,35 @@
|
||||||
class CoursesController < ApplicationController
|
class CoursesController < ApplicationController
|
||||||
|
layout 'base_courses'
|
||||||
include CoursesHelper
|
include CoursesHelper
|
||||||
|
helper :activities
|
||||||
|
helper :members
|
||||||
|
helper :words
|
||||||
|
|
||||||
|
menu_item :overview
|
||||||
|
menu_item :feedback, :only => :feedback
|
||||||
|
menu_item :homework, :only => :homework
|
||||||
|
|
||||||
|
menu_item l(:label_sort_by_time), :only => :index
|
||||||
|
menu_item l(:label_sort_by_active), :only => :index
|
||||||
|
menu_item l(:label_sort_by_influence), :only => :index
|
||||||
|
|
||||||
|
before_filter :find_course, :except => [ :index, :search,:list, :new,:join,:unjoin, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches]
|
||||||
|
before_filter :authorize_course, :only => [:show, :settings, :edit, :update, :modules, :close, :reopen, :view_homework_attaches, :course]
|
||||||
|
before_filter :authorize_course_global, :only => [:view_homework_attaches, :new,:create]
|
||||||
|
before_filter :require_admin, :only => [:copy, :archive, :unarchive, :destroy, :calendar]
|
||||||
|
before_filter :toggleCourse, only: [:finishcourse, :restartcourse]
|
||||||
|
|
||||||
before_filter :require_login, :only => [:join, :unjoin]
|
before_filter :require_login, :only => [:join, :unjoin]
|
||||||
before_filter :allow_join, :only => [:join]
|
before_filter :allow_join, :only => [:join]
|
||||||
|
|
||||||
def join
|
def join
|
||||||
if User.current.logged?
|
if User.current.logged?
|
||||||
course = Project.find(params[:object_id])
|
course = Course.find(params[:object_id])
|
||||||
course_prefs = Course.find_by_extra(course.identifier)
|
if params[:course_password] == course.password
|
||||||
if params[:course_password] == course_prefs.password
|
|
||||||
members = []
|
members = []
|
||||||
members << Member.new(:role_ids => [10], :user_id => User.current.id)
|
members << Member.new(:role_ids => [10], :user_id => User.current.id)
|
||||||
course.members << members
|
course.members << members
|
||||||
|
|
||||||
StudentsForCourse.create(:student_id => User.current.id, :course_id => params[:object_id])
|
StudentsForCourse.create(:student_id => User.current.id, :course_id => params[:object_id])
|
||||||
@state = 0
|
@state = 0
|
||||||
else
|
else
|
||||||
|
@ -21,16 +38,16 @@ class CoursesController < ApplicationController
|
||||||
end
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
||||||
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Project.find(params[:object_id]), :object_id => params[:object_id]} }
|
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Course.find(params[:object_id]), :object_id => params[:object_id]} }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def unjoin
|
def unjoin
|
||||||
if User.current.logged?
|
if User.current.logged?
|
||||||
|
|
||||||
@member = Member.where('project_id = ? and user_id = ?', params[:object_id], User.current.id)
|
@member = Member.where('course_id = ? and user_id = ?', params[:object_id], User.current.id)
|
||||||
@member.first.destroy
|
@member.first.destroy
|
||||||
|
|
||||||
joined = StudentsForCourse.where('student_id = ? and course_id = ?', User.current.id, params[:object_id])
|
joined = StudentsForCourse.where('student_id = ? and course_id = ?', User.current.id, params[:object_id])
|
||||||
joined.each do |join|
|
joined.each do |join|
|
||||||
join.delete
|
join.delete
|
||||||
|
@ -38,25 +55,657 @@ class CoursesController < ApplicationController
|
||||||
end
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
||||||
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Project.find(params[:object_id]), :object_id => params[:object_id]} }
|
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Course.find(params[:object_id]), :object_id => params[:object_id]} }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#更新课程信息
|
||||||
|
def update
|
||||||
|
@course.safe_attributes = params[:course]
|
||||||
|
@course.class_period = params[:class_period]
|
||||||
|
if @course.save
|
||||||
|
if params[:course][:is_public] == '0'
|
||||||
|
course_status = CourseStatus.find_by_course_id(@course.id)
|
||||||
|
course_status.destroy if course_status
|
||||||
|
elsif params[:course][:is_public] == '1'
|
||||||
|
course_status = CourseStatus.find_by_course_id(@course.id)
|
||||||
|
course_status.destroy if course_status
|
||||||
|
course_status = CourseStatus.create(:course_id => @course.id, :grade => 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html {
|
||||||
|
flash[:notice] = l(:notice_successful_update)
|
||||||
|
redirect_to settings_course_path(@course)
|
||||||
|
}
|
||||||
|
format.api { render_api_ok }
|
||||||
|
end
|
||||||
|
else
|
||||||
|
respond_to do |format|
|
||||||
|
format.html {
|
||||||
|
settings
|
||||||
|
render :action => 'settings'
|
||||||
|
}
|
||||||
|
format.api { render_validation_errors(@course) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def new_join
|
||||||
|
@course = Course.find(params[:object_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
# 课程搜索
|
||||||
|
# add by nwb
|
||||||
|
def search
|
||||||
|
courses_all = Course.all_course
|
||||||
|
name = params[:name]
|
||||||
|
(redirect_to courses_path, :notice => l(:label_sumbit_empty);return) if name.blank?
|
||||||
|
@courses = courses_all.visible
|
||||||
|
if params[:name].present?
|
||||||
|
@courses_all = @courses.like(params[:name])
|
||||||
|
else
|
||||||
|
@courses_all = @courses;
|
||||||
|
end
|
||||||
|
@course_count = @courses_all.count
|
||||||
|
@course_pages = Paginator.new @course_count, per_page_option, params['page']
|
||||||
|
|
||||||
|
# 课程的动态数
|
||||||
|
@course_activity_count=Hash.new
|
||||||
|
@courses_all.each do |course|
|
||||||
|
@course_activity_count[course.id]=0
|
||||||
|
end
|
||||||
|
|
||||||
|
case params[:course_sort_type]
|
||||||
|
when '0'
|
||||||
|
@courses = @courses_all.order("created_at desc")
|
||||||
|
@s_type = 0
|
||||||
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
||||||
|
|
||||||
|
@course_activity_count=get_course_activity @courses,@course_activity_count
|
||||||
|
|
||||||
|
when '1'
|
||||||
|
@courses = @courses_all.order("course_ac_para desc")
|
||||||
|
@s_type = 1
|
||||||
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
||||||
|
|
||||||
|
@course_activity_count=get_course_activity @courses,@course_activity_count
|
||||||
|
|
||||||
|
when '2'
|
||||||
|
@courses = @courses_all.order("watchers_count desc")
|
||||||
|
@s_type = 2
|
||||||
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
||||||
|
|
||||||
|
@course_activity_count=get_course_activity @courses,@course_activity_count
|
||||||
|
|
||||||
|
when '3'
|
||||||
|
@course_activity_count=get_course_activity @courses_all,@course_activity_count_array
|
||||||
|
@courses=handle_course @courses_all,@course_activity_count
|
||||||
|
@s_type = 3
|
||||||
|
@courses = @courses[@course_pages.offset, @course_pages.per_page]
|
||||||
|
|
||||||
|
else
|
||||||
|
@s_type = 0
|
||||||
|
@courses = @courses_all.order("created_at desc")
|
||||||
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
||||||
|
|
||||||
|
@course_activity_count=get_course_activity @courses,@course_activity_count
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html {
|
||||||
|
render :layout => 'base'
|
||||||
|
scope = Course
|
||||||
|
unless params[:closed]
|
||||||
|
scope = scope.active
|
||||||
|
end
|
||||||
|
}
|
||||||
|
format.atom {
|
||||||
|
courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
|
||||||
|
render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}")
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def member
|
||||||
|
## 有角色参数的才是课程,没有的就是项目
|
||||||
|
@render_file = 'member_list'
|
||||||
|
@teachers= searchTeacherAndAssistant(@course)
|
||||||
|
@canShowCode = isCourseTeacher(User.current.id)
|
||||||
|
case params[:role]
|
||||||
|
when '1'
|
||||||
|
@subPage_title = l :label_teacher_list
|
||||||
|
@members = searchTeacherAndAssistant(@course)
|
||||||
|
when '2'
|
||||||
|
@subPage_title = l :label_student_list
|
||||||
|
@members = searchStudent(@course)
|
||||||
|
else
|
||||||
|
@subPage_title = ''
|
||||||
|
@members = @course.member_principals.includes(:roles, :principal).all.sort
|
||||||
|
end
|
||||||
|
@members = paginateHelper @members
|
||||||
|
render :layout => 'base_courses'
|
||||||
|
end
|
||||||
|
|
||||||
|
#判断指定用户是否为课程教师
|
||||||
|
def isCourseTeacher(id)
|
||||||
|
result = false
|
||||||
|
if @teachers.find_by_user_id(id) != nil
|
||||||
|
result = true
|
||||||
|
end
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_course courses, activities
|
||||||
|
course_activity_count_array=activities.values()
|
||||||
|
|
||||||
|
course_array=[]
|
||||||
|
i=0;
|
||||||
|
courses.each do |course|
|
||||||
|
course_array[i]=course
|
||||||
|
i=i+1
|
||||||
|
end
|
||||||
|
|
||||||
|
courses=desc_sort_course_by_avtivity(course_activity_count_array, course_array)
|
||||||
|
|
||||||
|
return courses
|
||||||
|
end
|
||||||
|
|
||||||
|
def settings
|
||||||
|
@issue_custom_fields = IssueCustomField.sorted.all
|
||||||
|
@issue_category ||= IssueCategory.new
|
||||||
|
@member ||= @course.members.new
|
||||||
|
@trackers = Tracker.sorted.all
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
if User.current.user_extensions.identity
|
||||||
|
@course = Course.new
|
||||||
|
@course.extra='course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s
|
||||||
|
@course.safe_attributes = params[:course]
|
||||||
|
@course.tea_id = User.current.id
|
||||||
|
# added by bai
|
||||||
|
@course.term = params[:term]
|
||||||
|
@course.time = params[:time]
|
||||||
|
#@course.school_id = params[:occupation]
|
||||||
|
@course.school_id = User.current.user_extensions.school_id
|
||||||
|
@course.setup_time = params[:setup_time]
|
||||||
|
@course.endup_time = params[:endup_time]
|
||||||
|
@course.class_period = params[:class_period]
|
||||||
|
end
|
||||||
|
|
||||||
|
@issue_custom_fields = IssueCustomField.sorted.all
|
||||||
|
@trackers = Tracker.sorted.all
|
||||||
|
|
||||||
|
if User.current.user_extensions.identity == 0
|
||||||
|
if @course.save
|
||||||
|
#unless User.current.admin?
|
||||||
|
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
|
||||||
|
m = Member.new(:user => User.current, :roles => [r])
|
||||||
|
m.project_id = -1
|
||||||
|
course = CourseInfos.new(:user_id => User.current.id, :course_id => @course.id)
|
||||||
|
#user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id)
|
||||||
|
if params[:course][:is_public] == '1'
|
||||||
|
course_status = CourseStatus.create(:course_id => @course.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :course_type => @course_tag)
|
||||||
|
end
|
||||||
|
@course.members << m
|
||||||
|
@course.course_infos << course
|
||||||
|
#end
|
||||||
|
respond_to do |format|
|
||||||
|
format.html {
|
||||||
|
flash[:notice] = l(:notice_successful_create)
|
||||||
|
if params[:continue]
|
||||||
|
redirect_to new_course_path(attrs, :course => '0')
|
||||||
|
elsif params[:course_continue]
|
||||||
|
redirect_to new_course_path(:course => '1')
|
||||||
|
else
|
||||||
|
redirect_to settings_course_path(@course, :course_type => 1)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'courses', :action => 'show', :id => @course.id) }
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@course.destroy
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { render :action => 'new', :layout => 'base' } #Added by young
|
||||||
|
format.api { render_validation_errors(@course) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def course
|
||||||
|
@school_id = params[:school_id]
|
||||||
|
per_page_option = 10
|
||||||
|
if @school_id == "0" or @school_id.nil?
|
||||||
|
@courses_all = Course.active.visible.
|
||||||
|
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id").
|
||||||
|
else
|
||||||
|
@courses_all = Course.active.visible.
|
||||||
|
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id").
|
||||||
|
joins(:course_extra).
|
||||||
|
where("#{Course.table_name}.school_id = ?", @school_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
@course_count = @courses_all.count
|
||||||
|
@course_pages = Paginator.new @course_count, per_page_option, params['page']
|
||||||
|
|
||||||
|
#gcm activity count
|
||||||
|
|
||||||
|
@course_activity_count=Hash.new
|
||||||
|
#count initialize
|
||||||
|
@courses_all.each do |course|
|
||||||
|
@course_activity_count[course.id]=0
|
||||||
|
end
|
||||||
|
|
||||||
|
#@course_activity_count=get_course_activity @courses_all,@course_activity_count
|
||||||
|
#gcm end
|
||||||
|
|
||||||
|
|
||||||
|
case params[:course_sort_type]
|
||||||
|
when '0'
|
||||||
|
@courses = @courses_all.order("created_on desc")
|
||||||
|
@s_type = 0
|
||||||
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
||||||
|
|
||||||
|
#gcm
|
||||||
|
@course_activity_count=get_course_activity @courses,@course_activity_count
|
||||||
|
#gcmend
|
||||||
|
|
||||||
|
when '1'
|
||||||
|
@courses = @courses_all.order("course_ac_para desc")
|
||||||
|
@s_type = 1
|
||||||
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
||||||
|
|
||||||
|
#gcm
|
||||||
|
@course_activity_count=get_course_activity @courses,@course_activity_count
|
||||||
|
#gcmend
|
||||||
|
|
||||||
|
when '2'
|
||||||
|
@courses = @courses_all.order("watchers_count desc")
|
||||||
|
@s_type = 2
|
||||||
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
||||||
|
|
||||||
|
#gcm
|
||||||
|
@course_activity_count=get_course_activity @courses,@course_activity_count
|
||||||
|
#gcmend
|
||||||
|
|
||||||
|
#gcm
|
||||||
|
when '3'
|
||||||
|
|
||||||
|
#gcm
|
||||||
|
@course_activity_count=get_course_activity @courses_all,@course_activity_count
|
||||||
|
#gcmend
|
||||||
|
|
||||||
|
@courses=handle_course @courses_all,@course_activity_count
|
||||||
|
@s_type = 3
|
||||||
|
@courses = @courses[@course_pages.offset, @course_pages.per_page]
|
||||||
|
else
|
||||||
|
@s_type = 0
|
||||||
|
@courses = @courses_all.order("created_on desc")
|
||||||
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
||||||
|
|
||||||
|
#gcm
|
||||||
|
@course_activity_count=get_course_activity @courses,@course_activity_count
|
||||||
|
#gcmend
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html {
|
||||||
|
render :layout => 'base'
|
||||||
|
}
|
||||||
|
format.api {
|
||||||
|
# @offset, @limit = api_offset_and_limit
|
||||||
|
# @course_count = Course.visible.count
|
||||||
|
# @courses = Course.visible.offset(@offset).limit(@limit).order('lft').all
|
||||||
|
}
|
||||||
|
format.atom {
|
||||||
|
courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
|
||||||
|
render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}")
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def new
|
||||||
|
@course_type = params[:course_type] ||= params[:course]
|
||||||
|
@issue_custom_fields = IssueCustomField.sorted.all
|
||||||
|
@trackers = Tracker.sorted.all
|
||||||
|
|
||||||
|
@course = Course.new
|
||||||
|
@course.safe_attributes = params[:course]
|
||||||
|
|
||||||
|
render :layout => 'base'
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def desc_sort_course_by_avtivity(activity_count, courses)
|
||||||
|
return courses if activity_count.size<2
|
||||||
|
(activity_count.size-2).downto(0) do |i|
|
||||||
|
(0..i).each do |j|
|
||||||
|
if activity_count[j]<activity_count[j+1]
|
||||||
|
courses[j], courses[j+1]=courses[j+1], courses[j]
|
||||||
|
activity_count[j], activity_count[j+1]=activity_count[j+1], activity_count[j]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return courses
|
||||||
|
end
|
||||||
|
|
||||||
|
def index
|
||||||
|
@course_type = params[:course_type]
|
||||||
|
@school_id = params[:school_id]
|
||||||
|
per_page_option = 10
|
||||||
|
|
||||||
|
|
||||||
|
if @school_id == "0" or @school_id.nil?
|
||||||
|
@courses_all = Course.active.visible.
|
||||||
|
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id")
|
||||||
|
else
|
||||||
|
@courses_all = Course.active.visible.
|
||||||
|
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id").
|
||||||
|
where("#{Course.table_name}.school_id = ?", @school_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
@course_count = @courses_all.count
|
||||||
|
@course_pages = Paginator.new @course_count, per_page_option, params['page']
|
||||||
|
|
||||||
|
@course_activity_count=Hash.new
|
||||||
|
@courses_all.each do |course|
|
||||||
|
@course_activity_count[course.id]=0
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
case params[:course_sort_type]
|
||||||
|
when '0'
|
||||||
|
@courses = @courses_all.order("created_at desc")
|
||||||
|
@s_type = 0
|
||||||
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
||||||
|
|
||||||
|
@course_activity_count=get_course_activity @courses, @course_activity_count
|
||||||
|
when '1'
|
||||||
|
@courses = @courses_all.order("course_ac_para desc")
|
||||||
|
@s_type = 1
|
||||||
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
||||||
|
|
||||||
|
@course_activity_count=get_course_activity @courses, @course_activity_count
|
||||||
|
when '2'
|
||||||
|
@courses = @courses_all.order("watchers_count desc")
|
||||||
|
@s_type = 2
|
||||||
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
||||||
|
|
||||||
|
@course_activity_count=get_course_activity @courses, @course_activity_count
|
||||||
|
|
||||||
|
when '3'
|
||||||
|
|
||||||
|
@course_activity_count=get_course_activity @courses_all, @course_activity_count
|
||||||
|
|
||||||
|
@courses=handle_course @courses_all, @course_activity_count
|
||||||
|
|
||||||
|
@s_type = 3
|
||||||
|
@courses = @courses[@course_pages.offset, @course_pages.per_page]
|
||||||
|
else
|
||||||
|
@s_type = 0
|
||||||
|
@courses = @courses_all.order("created_at desc")
|
||||||
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
||||||
|
|
||||||
|
@course_activity_count=get_course_activity @courses, @course_activity_count
|
||||||
|
end
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html {
|
||||||
|
render :layout => 'base'
|
||||||
|
}
|
||||||
|
format.atom {
|
||||||
|
courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
|
||||||
|
render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}")
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def homework
|
||||||
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
||||||
|
@bids = @course.homeworks.order('deadline DESC')
|
||||||
|
@bids = @bids.like(params[:name]) if params[:name].present?
|
||||||
|
@bid_count = @bids.count
|
||||||
|
@bid_pages = Paginator.new @bid_count, @limit, params['page']
|
||||||
|
|
||||||
|
@offset ||= @bid_pages.reverse_offset
|
||||||
|
unless @offset == 0
|
||||||
|
@bids = @bids.offset(@offset).limit(@limit).all.reverse
|
||||||
|
else
|
||||||
|
limit = @bid_count % @limit
|
||||||
|
if limit == 0
|
||||||
|
limit = 10
|
||||||
|
end
|
||||||
|
@bids = @bids.offset(@offset).limit(limit).all.reverse
|
||||||
|
end
|
||||||
|
render :layout => 'base_courses'
|
||||||
|
end
|
||||||
|
|
||||||
|
# 新建作业
|
||||||
|
def new_homework
|
||||||
|
@homework = Bid.new
|
||||||
|
@homework.proportion
|
||||||
|
@homework.safe_attributes = params[:bid]
|
||||||
|
if (User.current.logged? && User.current.member_of_course?(Course.find params[:id] ))
|
||||||
|
render :layout => 'base_courses'
|
||||||
|
else
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_course_activity courses, activities
|
||||||
|
@course_ids=activities.keys()
|
||||||
|
|
||||||
|
days = Setting.activity_days_default.to_i
|
||||||
|
date_to ||= Date.today + 1
|
||||||
|
date_from = date_to - days-1.years
|
||||||
|
|
||||||
|
#file_count
|
||||||
|
Attachment.where(container_id: @course_ids, container_type: Course).where("created_on>?", date_from).each do |attachment|
|
||||||
|
activities[attachment.container_id]+=1
|
||||||
|
end
|
||||||
|
|
||||||
|
#message_count
|
||||||
|
Board.where(course_id: @course_ids).each do |board|
|
||||||
|
# activities[board.course_id]+=1
|
||||||
|
activities[board.course_id]+=board.messages.where("updated_on>?", date_from).count
|
||||||
|
end
|
||||||
|
|
||||||
|
#news
|
||||||
|
News.where(course_id: @course_ids).where("created_on>?",date_from).each do |news|
|
||||||
|
activities[news.course_id]+=1
|
||||||
|
end
|
||||||
|
|
||||||
|
#feedbackc_count
|
||||||
|
JournalsForMessage.where(jour_id: @course_ids, jour_type: Course).each do |jourformess|
|
||||||
|
activities[jourformess.jour_id]+=1
|
||||||
|
end
|
||||||
|
|
||||||
|
#activities!=0
|
||||||
|
i=0;
|
||||||
|
courses.each do |course|
|
||||||
|
id=course.id
|
||||||
|
if activities[id]==0
|
||||||
|
activities[id]=1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return activities
|
||||||
|
end
|
||||||
|
|
||||||
|
def toggleCourse
|
||||||
|
@course_prefs = Course.find_by_extra(@course.extra)
|
||||||
|
unless (@course_prefs.teacher == User.current || User.current.admin?)
|
||||||
|
render_403
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_courses
|
||||||
|
@user = User.current
|
||||||
|
membership = @user.coursememberships.all
|
||||||
|
membership.sort! {|older, newer| newer.created_on <=> older.created_on }
|
||||||
|
@memberships = []
|
||||||
|
membership.collect { |e|
|
||||||
|
@memberships.push(e)
|
||||||
|
}
|
||||||
|
@memberships_doing = []
|
||||||
|
@memberships_done = []
|
||||||
|
now_time = Time.now.year
|
||||||
|
@memberships.map { |e|
|
||||||
|
end_time = e.course.get_time.year
|
||||||
|
isDone = course_endTime_timeout?(e.course)
|
||||||
|
if isDone
|
||||||
|
@memberships_done.push e
|
||||||
|
else
|
||||||
|
@memberships_doing.push e
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def finishcourse
|
||||||
|
yesterday = Date.today.prev_day.to_time
|
||||||
|
|
||||||
|
@course_prefs.endup_time = yesterday
|
||||||
|
@save_flag = @course_prefs.save
|
||||||
|
get_courses
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.js
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def restartcourse
|
||||||
|
day = Time.parse("3000-01-01")
|
||||||
|
|
||||||
|
@course_prefs.endup_time = day
|
||||||
|
@save_flag = @course_prefs.save
|
||||||
|
get_courses
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.js {
|
||||||
|
render action:'finishcourse'
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
# try to redirect to the requested menu item
|
||||||
|
if params[:jump] && redirect_to_course_menu_item(@course, params[:jump])
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
@users_by_role = @course.users_by_role
|
||||||
|
if(User.find_by_id(CourseInfos.find_by_course_id(@course.id).try(:user_id)))
|
||||||
|
@user = User.find_by_id(CourseInfos.find_by_course_id(@course.id).user_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@key = User.current.rss_key
|
||||||
|
#新增内容
|
||||||
|
@days = Setting.activity_days_default.to_i
|
||||||
|
|
||||||
|
if params[:from]
|
||||||
|
begin; @date_to = params[:from].to_date + 1; rescue; end
|
||||||
|
end
|
||||||
|
|
||||||
|
has = {
|
||||||
|
"show_course_files" => true,
|
||||||
|
"show_course_news" => true,
|
||||||
|
"show_course_messages" => true,
|
||||||
|
"show_bids" => true,
|
||||||
|
"show_course_journals_for_messages" => true
|
||||||
|
}
|
||||||
|
@date_to ||= Date.today + 1
|
||||||
|
@date_from = @date_to - @days-1.years
|
||||||
|
@author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
|
||||||
|
# 决定显示所用用户或单个用户活动
|
||||||
|
@activity = Redmine::Activity::Fetcher.new(User.current, :course => @course,
|
||||||
|
:with_subprojects => false,
|
||||||
|
:author => @author)
|
||||||
|
@activity.scope_select {|t| has["show_#{t}"]}
|
||||||
|
events = @activity.events(@date_from, @date_to)
|
||||||
|
|
||||||
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
||||||
|
@events_count = events.count
|
||||||
|
@events_pages = Paginator.new @events_count, @limit, params['page']
|
||||||
|
@offset ||= @events_pages.offset
|
||||||
|
events = events.slice(@offset,@limit)
|
||||||
|
|
||||||
|
@events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)}
|
||||||
|
# documents
|
||||||
|
@sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
|
||||||
|
#
|
||||||
|
@teachers= searchTeacherAndAssistant(@course)
|
||||||
|
@canShowRealName = isCourseTeacher(User.current.id)
|
||||||
|
|
||||||
|
if(User.find_by_id(CourseInfos.find_by_course_id(@course.id).try(:user_id)))
|
||||||
|
@user = User.find_by_id(CourseInfos.find_by_course_id(@course.id).user_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html{render :layout => 'base_courses'}
|
||||||
|
format.api
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
#判断指定用户是否为课程教师
|
||||||
|
def isCourseTeacher(id)
|
||||||
|
result = false
|
||||||
|
if @teachers && @teachers.find_by_user_id(id) != nil
|
||||||
|
result = true
|
||||||
|
end
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
|
def feedback
|
||||||
|
page = params[:page]
|
||||||
|
# Find the page of the requested reply
|
||||||
|
@jours = @course.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
|
||||||
|
@limit = 10
|
||||||
|
if params[:r] && page.nil?
|
||||||
|
offset = @jours.count(:conditions => ["#{JournalsForMessage.table_name}.id > ?", params[:r].to_i])
|
||||||
|
page = 1 + offset / @limit
|
||||||
|
end
|
||||||
|
|
||||||
|
@feedback_count = @jours.count
|
||||||
|
@feedback_pages = Paginator.new @feedback_count, @limit, page
|
||||||
|
@offset ||= @feedback_pages.offset
|
||||||
|
@jour = @jours[@offset, @limit]
|
||||||
|
@state = false
|
||||||
|
respond_to do |format|
|
||||||
|
format.html{render :layout => 'base_courses'}
|
||||||
|
format.api
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def allow_join
|
def allow_join
|
||||||
if course_endTime_timeout? Project.find(params[:object_id])
|
if course_endTime_timeout? Course.find(params[:object_id])
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js{
|
format.js {
|
||||||
@state = 2
|
@state = 2
|
||||||
render :partial => 'set_join',
|
render :partial => 'set_join',
|
||||||
:locals => {:user => User.current,
|
:locals => {:user => User.current,
|
||||||
:course => Project.find(params[:object_id]),
|
:course => Course.find(params[:object_id]),
|
||||||
:object_id => params[:object_id]
|
:object_id => params[:object_id]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
|
@ -62,6 +62,7 @@ class DocumentsController < ApplicationController
|
||||||
def create
|
def create
|
||||||
@document = @project.documents.build
|
@document = @project.documents.build
|
||||||
@document.safe_attributes = params[:document]
|
@document.safe_attributes = params[:document]
|
||||||
|
@document.user = User.current
|
||||||
@document.save_attachments(params[:attachments])
|
@document.save_attachments(params[:attachments])
|
||||||
if @document.save
|
if @document.save
|
||||||
render_attachment_warning_if_needed(@document)
|
render_attachment_warning_if_needed(@document)
|
||||||
|
|
|
@ -32,14 +32,16 @@ class FilesController < ApplicationController
|
||||||
'filename' => "#{Attachment.table_name}.filename",
|
'filename' => "#{Attachment.table_name}.filename",
|
||||||
'size' => "#{Attachment.table_name}.filesize",
|
'size' => "#{Attachment.table_name}.filesize",
|
||||||
'downloads' => "#{Attachment.table_name}.downloads"
|
'downloads' => "#{Attachment.table_name}.downloads"
|
||||||
|
|
||||||
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] #modify by Long Jun
|
if params[:project_id]
|
||||||
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
|
@isproject = true
|
||||||
|
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)]
|
||||||
if @project.project_type == 1
|
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
|
||||||
|
render :layout => !request.xhr?
|
||||||
|
elsif params[:course_id]
|
||||||
|
@isproject = false
|
||||||
|
@containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@course.id)]
|
||||||
render :layout => 'base_courses'
|
render :layout => 'base_courses'
|
||||||
else
|
|
||||||
render :layout => !request.xhr?
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -60,37 +62,66 @@ class FilesController < ApplicationController
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js
|
format.js
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@addTag=false
|
#modify by nwb
|
||||||
container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
|
if @project
|
||||||
attachments = Attachment.attach_filesex(container, params[:attachments],params[:attachment_type])
|
@addTag=false
|
||||||
render_attachment_warning_if_needed(container)
|
container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
|
||||||
|
attachments = Attachment.attach_filesex(container, params[:attachments], params[:attachment_type])
|
||||||
|
render_attachment_warning_if_needed(container)
|
||||||
|
|
||||||
if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
|
if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
|
||||||
Mailer.attachments_added(attachments[:files]).deliver
|
Mailer.attachments_added(attachments[:files]).deliver
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: 临时用 nyan
|
# TODO: 临时用 nyan
|
||||||
sort_init 'created_on', 'desc'
|
sort_init 'created_on', 'desc'
|
||||||
sort_update 'created_on' => "#{Attachment.table_name}.created_on",
|
sort_update 'created_on' => "#{Attachment.table_name}.created_on",
|
||||||
'filename' => "#{Attachment.table_name}.filename",
|
'filename' => "#{Attachment.table_name}.filename",
|
||||||
'size' => "#{Attachment.table_name}.filesize",
|
'size' => "#{Attachment.table_name}.filesize",
|
||||||
'downloads' => "#{Attachment.table_name}.downloads"
|
'downloads' => "#{Attachment.table_name}.downloads"
|
||||||
|
|
||||||
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] #modify by Long Jun
|
@containers = [Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] #modify by Long Jun
|
||||||
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
|
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
|
||||||
|
|
||||||
@attachtype = 0
|
@attachtype = 0
|
||||||
@contenttype = 0
|
@contenttype = 0
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js
|
format.js
|
||||||
format.html {
|
format.html {
|
||||||
redirect_to project_files_path(@project)
|
redirect_to project_files_path(@project)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
elsif @course
|
||||||
|
@addTag=false
|
||||||
|
attachments = Attachment.attach_filesex(@course, params[:attachments], params[:attachment_type])
|
||||||
|
|
||||||
end
|
if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
|
||||||
|
Mailer.attachments_added(attachments[:files]).deliver
|
||||||
|
end
|
||||||
|
|
||||||
|
# TODO: 临时用 nyan
|
||||||
|
sort_init 'created_on', 'desc'
|
||||||
|
sort_update 'created_on' => "#{Attachment.table_name}.created_on",
|
||||||
|
'filename' => "#{Attachment.table_name}.filename",
|
||||||
|
'size' => "#{Attachment.table_name}.filesize",
|
||||||
|
'downloads' => "#{Attachment.table_name}.downloads"
|
||||||
|
|
||||||
|
@containers = [Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@course.id)]
|
||||||
|
|
||||||
|
@attachtype = 0
|
||||||
|
@contenttype = 0
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.js
|
||||||
|
format.html {
|
||||||
|
redirect_to course_files_path(@course)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_saveEx
|
def tag_saveEx
|
||||||
|
@ -115,6 +146,8 @@ class FilesController < ApplicationController
|
||||||
@obj = Contest.find_by_id(@obj_id)
|
@obj = Contest.find_by_id(@obj_id)
|
||||||
when '8'
|
when '8'
|
||||||
@obj = OpenSourceProject.find_by_id(@obj_id)
|
@obj = OpenSourceProject.find_by_id(@obj_id)
|
||||||
|
when '9'
|
||||||
|
@obj = Course.find_by_id(@obj_id)
|
||||||
else
|
else
|
||||||
@obj = nil
|
@obj = nil
|
||||||
end
|
end
|
||||||
|
@ -131,16 +164,21 @@ class FilesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# 返回制定资源类型的资源列表
|
# 返回制定资源类型的资源列表
|
||||||
|
# added by nwb
|
||||||
def getattachtype
|
def getattachtype
|
||||||
sort_init 'created_on', 'desc'
|
sort_init 'created_on', 'desc'
|
||||||
sort_update 'created_on' => "#{Attachment.table_name}.created_on",
|
sort_update 'created_on' => "#{Attachment.table_name}.created_on",
|
||||||
'filename' => "#{Attachment.table_name}.filename",
|
'filename' => "#{Attachment.table_name}.filename",
|
||||||
'size' => "#{Attachment.table_name}.filesize",
|
'size' => "#{Attachment.table_name}.filesize",
|
||||||
'downloads' => "#{Attachment.table_name}.downloads"
|
'downloads' => "#{Attachment.table_name}.downloads"
|
||||||
|
|
||||||
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] #modify by Long Jun
|
if @project
|
||||||
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
|
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)]
|
||||||
|
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
|
||||||
|
elsif @course
|
||||||
|
@containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@course.id)]
|
||||||
|
end
|
||||||
|
|
||||||
@attachtype = params[:type].to_i
|
@attachtype = params[:type].to_i
|
||||||
@contenttype = params[:contentType].to_s
|
@contenttype = params[:contentType].to_s
|
||||||
|
|
||||||
|
|
|
@ -129,6 +129,7 @@ class ForumsController < ApplicationController
|
||||||
format.html { redirect_to @forum, notice: l(:label_forum_create_succ) }
|
format.html { redirect_to @forum, notice: l(:label_forum_create_succ) }
|
||||||
format.json { render json: @forum, status: :created, location: @forum }
|
format.json { render json: @forum, status: :created, location: @forum }
|
||||||
else
|
else
|
||||||
|
flash.now[:error] = "#{l :label_forum_create_fail}: #{@forum.errors.full_messages[0]}"
|
||||||
format.html { render action: "new" }
|
format.html { render action: "new" }
|
||||||
format.json { render json: @forum.errors, status: :unprocessable_entity }
|
format.json { render json: @forum.errors, status: :unprocessable_entity }
|
||||||
end
|
end
|
||||||
|
@ -165,6 +166,8 @@ class ForumsController < ApplicationController
|
||||||
|
|
||||||
def search_forum
|
def search_forum
|
||||||
# @forums = paginateHelper Forum.where("name LIKE '%#{params[:name]}%'")
|
# @forums = paginateHelper Forum.where("name LIKE '%#{params[:name]}%'")
|
||||||
|
name = params[:name]
|
||||||
|
(redirect_to forums_path, :notice => l(:label_sumbit_empty);return) if name.blank?
|
||||||
@offset, @limit = api_offset_and_limit({:limit => 10})
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
||||||
@forums_all = Forum.where("name LIKE '%#{params[:name]}%'")
|
@forums_all = Forum.where("name LIKE '%#{params[:name]}%'")
|
||||||
@forums_count = @forums_all.count
|
@forums_count = @forums_all.count
|
||||||
|
|
|
@ -1,5 +1,31 @@
|
||||||
class HomeworkAttachController < ApplicationController
|
class HomeworkAttachController < ApplicationController
|
||||||
|
include CoursesHelper
|
||||||
###############################
|
###############################
|
||||||
|
#判断当前角色权限时需先找到当前操作的project
|
||||||
|
before_filter :find_course_by_bid_id, :only => [:new]
|
||||||
|
before_filter :find_course_by_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users]
|
||||||
|
#判断当前角色是否有操作权限
|
||||||
|
#勿删 before_filter :authorize, :only => [:new,:edit,:update,:destroy]
|
||||||
|
|
||||||
|
def find_course_by_bid_id
|
||||||
|
@bid = Bid.find(params[:id])
|
||||||
|
@course = @bid.courses[0]
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_course_by_hoemwork_id
|
||||||
|
@homework = HomeworkAttach.find(params[:id])
|
||||||
|
@course = @homework.bid.courses[0]
|
||||||
|
end
|
||||||
|
|
||||||
|
#获取作业的成员
|
||||||
|
def get_homework_member homework
|
||||||
|
@hoemwork_users = users_for_homework(@homework)
|
||||||
|
@members = members_for_homework(@homework,@hoemwork_users,params[:q])
|
||||||
|
@members = paginateHelper @members,10
|
||||||
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@homeworks = HomeworkAttach.all
|
@homeworks = HomeworkAttach.all
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
@ -8,106 +34,236 @@ class HomeworkAttachController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_users users
|
#作业添加成员(参与人员)
|
||||||
if users != nil && users.count > 0
|
def add_homework_users
|
||||||
users.each do |user|
|
if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
|
||||||
@homework.homework_users.build(:user_id => user.id)
|
#@homework = HomeworkAttach.find(params[:id])
|
||||||
@homework.save
|
if params[:membership]
|
||||||
|
if params[:membership][:user_ids]
|
||||||
|
attrs = params[:membership].dup
|
||||||
|
user_ids = attrs.delete(:user_ids)
|
||||||
|
user_ids.each do |user_id|
|
||||||
|
@homework.homework_users.build(:user_id => user_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@homework.save
|
||||||
|
get_homework_member @homework
|
||||||
|
respond_to do |format|
|
||||||
|
format.js
|
||||||
|
end
|
||||||
|
else
|
||||||
|
render_403 :message => :notice_not_authorized
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
#作业删除成员(参与人员)
|
||||||
|
def destory_homework_users
|
||||||
|
#@homework = HomeworkAttach.find(params[:id])
|
||||||
|
if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
|
||||||
|
homework_user = @homework.homework_users.where("user_id = #{params[:user_id]}").first
|
||||||
|
homework_user.destroy
|
||||||
|
get_homework_member @homework
|
||||||
|
respond_to do |format|
|
||||||
|
format.js
|
||||||
|
end
|
||||||
|
else
|
||||||
|
render_403 :message => :notice_not_authorized
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
if User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0)
|
bid = Bid.find params[:bid_id]
|
||||||
user_id = params[:user_id]
|
if User.current.admin? || User.current.member_of_course?(bid.courses.first) # modify by nwb
|
||||||
bid_id = params[:bid_id]
|
if bid.homeworks.where("user_id = ?",User.current).count == 0
|
||||||
sta = 0
|
user_id = params[:user_id]
|
||||||
name = params[:new_form][:name]
|
bid_id = params[:bid_id]
|
||||||
description = params[:new_form][:description]
|
if params[:homework_attach]
|
||||||
options = {
|
if params[:homework_attach][:project_id]
|
||||||
:user_id => user_id,
|
project_id = params[:homework_attach][:project_id]
|
||||||
:state => sta,
|
else
|
||||||
:name => name,
|
project_id = 0
|
||||||
:description => description,
|
end
|
||||||
:bid_id => bid_id
|
|
||||||
}
|
|
||||||
|
|
||||||
@homework = HomeworkAttach.new(options)
|
|
||||||
@homework.save_attachments(params[:attachments])
|
|
||||||
render_attachment_warning_if_needed(@homework)
|
|
||||||
|
|
||||||
@homework.save
|
|
||||||
respond_to do |format|
|
|
||||||
if @homework.save
|
|
||||||
format.html { redirect_to @homework, notice: 'Post was successfully created.' }
|
|
||||||
format.json { render json: @homework, status: :created, location: @homework }
|
|
||||||
else
|
else
|
||||||
format.html { render action: "new" }
|
project_id = 0
|
||||||
format.json { render json: @homework.errors, status: :unprocessable_entity }
|
|
||||||
end
|
end
|
||||||
|
sta = 0
|
||||||
|
name = params[:new_form][:name]
|
||||||
|
description = params[:new_form][:description]
|
||||||
|
options = {
|
||||||
|
:user_id => user_id,
|
||||||
|
:state => sta,
|
||||||
|
:name => name,
|
||||||
|
:description => description,
|
||||||
|
:bid_id => bid_id,
|
||||||
|
:project_id => project_id
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#@homework_list = @bid.homeworks
|
||||||
|
|
||||||
|
@homework = HomeworkAttach.new(options)
|
||||||
|
@homework.save_attachments(params[:attachments])
|
||||||
|
render_attachment_warning_if_needed(@homework)
|
||||||
|
|
||||||
|
if @homework.save
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to course_for_bid_path @homework.bid }
|
||||||
|
format.json { head :no_content }
|
||||||
|
end
|
||||||
|
else
|
||||||
|
render_403 :message => :notice_not_authorized
|
||||||
|
end
|
||||||
|
else
|
||||||
|
render_403 :message => :notice_has_homework
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
render_403 :message => :notice_not_authorized
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@homework = HomeworkAttach.new
|
|
||||||
@bid = Bid.find(params[:id])
|
@bid = Bid.find(params[:id])
|
||||||
|
if User.current.admin? || User.current.member_of_course?(@bid.courses.first) #nwb
|
||||||
|
#该课程的学生的集合(新建不实现功能:添加成员)
|
||||||
|
#@members = @bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and user_id <> #{User.current.id}", {:role_id => [5, 10]})
|
||||||
|
|
||||||
respond_to do |format|
|
#@members = paginateHelper @members,10
|
||||||
format.html # new.html.erb
|
#@all_user = []
|
||||||
format.json { render json: @homework }
|
#@bid.courses.first.members.each do |member|
|
||||||
|
# @all_user << member.user
|
||||||
|
#end
|
||||||
|
@homework = HomeworkAttach.new
|
||||||
|
#@homework_user = members_for_homework(@homework) + User.current
|
||||||
|
#@members = @all_user - @homework_user
|
||||||
|
respond_to do |format|
|
||||||
|
format.html # new.html.erb
|
||||||
|
format.json { render json: @homework }
|
||||||
|
end
|
||||||
|
else
|
||||||
|
render_403 :message => :notice_not_authorized
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#获取作业成员的集合
|
||||||
|
def get_homework_member_list
|
||||||
|
@homework = HomeworkAttach.find(params[:bid_id])
|
||||||
|
course = @homework.bid.courses.first
|
||||||
|
if User.current.admin? || User.current.member_of_course?(course)
|
||||||
|
get_homework_member @homework
|
||||||
|
else
|
||||||
|
raise "error"
|
||||||
|
end
|
||||||
|
respond_to do |format|
|
||||||
|
format.js
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
#获取指定作业的所有成员
|
||||||
|
def users_for_homework homework
|
||||||
|
homework.nil? ? [] : (homework.users + [homework.user])
|
||||||
|
end
|
||||||
|
|
||||||
|
#获取可选成员列表
|
||||||
|
#homework:作业
|
||||||
|
#users:该作业所有成员
|
||||||
|
#q:模糊匹配的用户的昵称
|
||||||
|
def members_for_homework homework,users,q
|
||||||
|
homework.bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and user_id not in (:users)", {:role_id => [5, 10],:users => users}).joins(:user).where("users.login like '%#{q}%'")
|
||||||
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@homework = HomeworkAttach.find(params[:id])
|
#@homework = HomeworkAttach.find(params[:id])
|
||||||
|
if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
|
||||||
|
#@members = @homework.bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id)", {:role_id => [5, 10]})
|
||||||
|
get_homework_member @homework
|
||||||
|
else
|
||||||
|
render_403 :message => :notice_not_authorized
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@homework = HomeworkAttach.find(params[:id])
|
#@homework = HomeworkAttach.find(params[:id])
|
||||||
respond_to do |format|
|
course = @homework.bid.courses.first
|
||||||
if @post.update_attributes(params[:homework])
|
if User.current.admin? || User.current.member_of_course?(course)
|
||||||
format.html { redirect_to @homework, notice: 'Homework was successfully updated.' }
|
name = params[:homework_name]
|
||||||
format.json { head :no_content }
|
description = params[:homework_description]
|
||||||
|
if params[:homework_attach]
|
||||||
|
if params[:homework_attach][:project_id]
|
||||||
|
project_id = params[:homework_attach][:project_id]
|
||||||
|
else
|
||||||
|
project_id = 0
|
||||||
|
end
|
||||||
else
|
else
|
||||||
format.html { render action: "edit" }
|
project_id = 0
|
||||||
format.json { render json: @homework.errors, status: :unprocessable_entity }
|
|
||||||
end
|
end
|
||||||
|
@homework.name = name
|
||||||
|
@homework.description = description
|
||||||
|
@homework.project_id = project_id
|
||||||
|
if params[:attachments]
|
||||||
|
@homework.save_attachments(params[:attachments])
|
||||||
|
end
|
||||||
|
if @homework.save
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to course_for_bid_path @homework.bid }
|
||||||
|
format.json { head :no_content }
|
||||||
|
end
|
||||||
|
else
|
||||||
|
end
|
||||||
|
else
|
||||||
|
render_403 :message => :notice_not_authorized
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@homework = HomeworkAttach.find(params([:id]))
|
#@homework = HomeworkAttach.find(params[:id])
|
||||||
@homework.destroy
|
if User.current.admin? || User.current == @homework.user
|
||||||
respond_to do |format|
|
if @homework.destroy
|
||||||
format.html {render @homework}
|
respond_to do |format|
|
||||||
format.json {render json: @homework}
|
format.html { redirect_to course_for_bid_path @homework.bid }
|
||||||
|
format.json { head :no_content }
|
||||||
|
end
|
||||||
|
else
|
||||||
|
end
|
||||||
|
else
|
||||||
|
render_403 :message => :notice_not_authorized
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#显示作业信息
|
#显示作业信息
|
||||||
def show
|
def show
|
||||||
@homework = HomeworkAttach.find(params[:id])
|
#@homework = HomeworkAttach.find(params[:id])
|
||||||
# 打分统计
|
if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
|
||||||
stars_reates = @homework.
|
# 打分统计
|
||||||
rates(:quality)
|
stars_reates = @homework.
|
||||||
stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count
|
rates(:quality)
|
||||||
stars_status = stars_reates.select("stars, count(*) as scount").
|
stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count
|
||||||
group("stars")
|
stars_status = stars_reates.select("stars, count(*) as scount").
|
||||||
@stars_status_map = Hash.new(0.0)
|
group("stars")
|
||||||
stars_status.each do |star_status|
|
@stars_status_map = Hash.new(0.0)
|
||||||
percent = (star_status.scount * 1.0/ stars_reates_count) * 100.to_f
|
stars_status.each do |star_status|
|
||||||
percent_m = format("%.2f", percent)
|
percent = (star_status.scount * 1.0/ stars_reates_count) * 100.to_f
|
||||||
@stars_status_map["star#{star_status.stars.to_i}".to_sym] =
|
percent_m = format("%.2f", percent)
|
||||||
percent_m.to_s + "%"
|
@stars_status_map["star#{star_status.stars.to_i}".to_sym] =
|
||||||
|
percent_m.to_s + "%"
|
||||||
|
end
|
||||||
|
#是否已经进行过评价
|
||||||
|
@has_evaluation = stars_reates.where("rater_id = ?",User.current).count > 0
|
||||||
|
#是否开启互评功能
|
||||||
|
@is_evaluation = @homework.bid.is_evaluation == 1 || @homework.bid.is_evaluation == nil
|
||||||
|
@limit = 10
|
||||||
|
@jours = @homework.journals_for_messages.where("is_comprehensive_evaluation is null").order("created_on DESC")
|
||||||
|
@feedback_count = @jours.count
|
||||||
|
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
|
||||||
|
@offset ||= @feedback_pages.offset
|
||||||
|
@jour = @jours[@offset, @limit]
|
||||||
|
@comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC")
|
||||||
|
|
||||||
|
@totle_score = score_for_homework @homework
|
||||||
|
@teaher_score = teacher_score_for_homework @homework
|
||||||
|
else
|
||||||
|
render_403 :message => :notice_not_authorized
|
||||||
end
|
end
|
||||||
@limit = 10
|
|
||||||
@jours = @homework.journals_for_messages.where("is_comprehensive_evaluation is null").order("created_on DESC")
|
|
||||||
@feedback_count = @jours.count
|
|
||||||
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
|
|
||||||
@offset ||= @feedback_pages.offset
|
|
||||||
@jour = @jours[@offset, @limit]
|
|
||||||
@comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#删除留言
|
#删除留言
|
||||||
|
@ -136,11 +292,24 @@ class HomeworkAttachController < ApplicationController
|
||||||
@offset ||= @feedback_pages.offset
|
@offset ||= @feedback_pages.offset
|
||||||
@jour = @jours[@offset, @limit]
|
@jour = @jours[@offset, @limit]
|
||||||
@comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC")
|
@comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC")
|
||||||
|
|
||||||
|
@totle_score = score_for_homework @homework
|
||||||
|
@teaher_score = teacher_score_for_homework @homework
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js
|
format.js
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#教师综评
|
||||||
|
def comprehensive_evaluation_jour
|
||||||
|
@homework = HomeworkAttach.find(params[:jour_id])
|
||||||
|
@add_jour = @homework.addjours User.current.id, params[:new_form][:user_message],0,params[:is_comprehensive_evaluation]
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to homework_attach_path @homework }
|
||||||
|
format.json { head :no_content }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
#获取指定作业的平均得分
|
#获取指定作业的平均得分
|
||||||
def score
|
def score
|
||||||
#stars_reates = @homework.rates(:quality)
|
#stars_reates = @homework.rates(:quality)
|
||||||
|
|
|
@ -1,3 +1,14 @@
|
||||||
class HomeworkUsersController < ApplicationController
|
class HomeworkUsersController < ApplicationController
|
||||||
|
#新增数据
|
||||||
|
def create option
|
||||||
|
user = HomeworkUser.new option
|
||||||
|
user.save
|
||||||
|
user
|
||||||
|
end
|
||||||
|
#删除数据
|
||||||
|
def destory homework_user
|
||||||
|
user = HomeworkUser.find homework_user
|
||||||
|
user.destroy
|
||||||
|
user
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,6 +19,7 @@ class IssueCategoriesController < ApplicationController
|
||||||
menu_item :settings
|
menu_item :settings
|
||||||
model_object IssueCategory
|
model_object IssueCategory
|
||||||
before_filter :find_model_object, :except => [:index, :new, :create]
|
before_filter :find_model_object, :except => [:index, :new, :create]
|
||||||
|
#before_filter :find_model_object_contest, :except => [:index, :new, :create]
|
||||||
before_filter :find_project_from_association, :except => [:index, :new, :create]
|
before_filter :find_project_from_association, :except => [:index, :new, :create]
|
||||||
before_filter :find_project_by_project_id, :only => [:index, :new, :create]
|
before_filter :find_project_by_project_id, :only => [:index, :new, :create]
|
||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
|
@ -119,4 +120,10 @@ class IssueCategoriesController < ApplicationController
|
||||||
super
|
super
|
||||||
@category = @object
|
@category = @object
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_model_object_contest
|
||||||
|
super
|
||||||
|
@category = @object
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,6 +29,11 @@ class MailHandlerController < ActionController::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#取消邮件通知
|
||||||
|
def cancel_mail_notify
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def check_credential
|
def check_credential
|
||||||
|
|
|
@ -17,19 +17,21 @@
|
||||||
class MembersController < ApplicationController
|
class MembersController < ApplicationController
|
||||||
model_object Member
|
model_object Member
|
||||||
before_filter :find_model_object, :except => [:index, :create, :autocomplete]
|
before_filter :find_model_object, :except => [:index, :create, :autocomplete]
|
||||||
|
#before_filter :find_model_object_contest, :except => [:index, :create, :autocomplete]
|
||||||
before_filter :find_project_from_association, :except => [:index, :create, :autocomplete]
|
before_filter :find_project_from_association, :except => [:index, :create, :autocomplete]
|
||||||
before_filter :find_project_by_project_id, :only => [:index, :create, :autocomplete]
|
before_filter :find_project_by_project_id, :only => [:index, :create, :autocomplete]
|
||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
accept_api_auth :index, :show, :create, :update, :destroy
|
accept_api_auth :index, :show, :create, :update, :destroy
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@offset, @limit = api_offset_and_limit
|
@offset, @limit = api_offset_and_limit
|
||||||
@member_count = @project.member_principals.count
|
@member_count = @project.member_principals.count
|
||||||
@member_pages = Paginator.new @member_count, @limit, params['page']
|
@member_pages = Paginator.new @member_count, @limit, params['page']
|
||||||
@offset ||= @member_pages.offset
|
@offset ||= @member_pages.offset
|
||||||
@members = @project.member_principals.all(
|
@members = @project.member_principals.all(
|
||||||
:order => "#{Member.table_name}.id",
|
:order => "#{Member.table_name}.id",
|
||||||
:limit => @limit,
|
:limit => @limit,
|
||||||
:offset => @offset
|
:offset => @offset
|
||||||
)
|
)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
@ -59,121 +61,217 @@ class MembersController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
#modify by nwb
|
||||||
|
#更改课程成员逻辑
|
||||||
applied_members = false
|
applied_members = false
|
||||||
members = []
|
members = []
|
||||||
project_info = []
|
|
||||||
user_grades = []
|
user_grades = []
|
||||||
if params[:membership]
|
if @project
|
||||||
if params[:membership][:user_ids]
|
project_info = []
|
||||||
attrs = params[:membership].dup
|
if params[:membership]
|
||||||
user_ids = attrs.delete(:user_ids)
|
if params[:membership][:user_ids]
|
||||||
user_ids.each do |user_id|
|
attrs = params[:membership].dup
|
||||||
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id)
|
user_ids = attrs.delete(:user_ids)
|
||||||
user_grades << UserGrade.new(:user_id => user_id, :project_id => @project.id)
|
user_ids.each do |user_id|
|
||||||
|
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id)
|
||||||
|
user_grades << UserGrade.new(:user_id => user_id, :project_id => @project.id)
|
||||||
|
## added by nie
|
||||||
|
if (params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3")
|
||||||
|
project_info << ProjectInfo.new(:user_id => user_id, :project_id => @project.id)
|
||||||
|
# ProjectInfo.create(:name => "test", :user_id => 123)
|
||||||
|
end
|
||||||
|
## end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id])
|
||||||
|
user_grades << UserGrade.new(:user_id => params[:membership][:user_id], :project_id => @project.id)
|
||||||
## added by nie
|
## added by nie
|
||||||
if (params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3")
|
if (params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3")
|
||||||
project_info << ProjectInfo.new(:user_id => user_id, :project_id => @project.id)
|
project_info << ProjectInfo.new(:project_id => @project.id, :user_id => params[:membership][:user_id])
|
||||||
# ProjectInfo.create(:name => "test", :user_id => 123)
|
|
||||||
end
|
end
|
||||||
## end
|
## end
|
||||||
end
|
|
||||||
else
|
|
||||||
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id])
|
|
||||||
user_grades << UserGrade.new(:user_id => params[:membership][:user_id], :project_id => @project.id)
|
|
||||||
## added by nie
|
|
||||||
if (params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3")
|
|
||||||
project_info << ProjectInfo.new(:project_id => @project.id, :user_id => params[:membership][:user_id])
|
|
||||||
end
|
end
|
||||||
## end
|
@project.members << members
|
||||||
|
# added by nie
|
||||||
|
@project.project_infos << project_info
|
||||||
|
@project.user_grades << user_grades
|
||||||
|
# end
|
||||||
end
|
end
|
||||||
@project.members << members
|
if members.present? && members.all? { |m| m.valid? }
|
||||||
# added by nie
|
members.each do |member|
|
||||||
@project.project_infos << project_info
|
AppliedProject.deleteappiled(member.user_id, @project.id)
|
||||||
@project.user_grades << user_grades
|
end
|
||||||
# end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if members.present? && members.all? {|m| m.valid? }
|
|
||||||
members.each do |member|
|
|
||||||
AppliedProject.deleteappiled(member.user_id, @project.id)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
format.html { redirect_to_settings_in_projects }
|
|
||||||
format.js { @members = members;@applied_members = applied_members; }
|
|
||||||
format.api {
|
|
||||||
@member = members.first
|
|
||||||
if @member.valid?
|
|
||||||
render :action => 'show', :status => :created, :location => membership_url(@member)
|
|
||||||
else
|
|
||||||
render_validation_errors(@member)
|
|
||||||
end
|
end
|
||||||
}
|
respond_to do |format|
|
||||||
end
|
format.html { redirect_to_settings_in_projects }
|
||||||
|
format.js { @members = members; @applied_members = applied_members; }
|
||||||
|
format.api {
|
||||||
|
@member = members.first
|
||||||
|
if @member.valid?
|
||||||
|
render :action => 'show', :status => :created, :location => membership_url(@member)
|
||||||
|
else
|
||||||
|
render_validation_errors(@member)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
elsif @course
|
||||||
|
course_info = []
|
||||||
|
if params[:membership]
|
||||||
|
if params[:membership][:user_ids]
|
||||||
|
attrs = params[:membership].dup
|
||||||
|
user_ids = attrs.delete(:user_ids)
|
||||||
|
user_ids.each do |user_id|
|
||||||
|
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id)
|
||||||
|
#user_grades << UserGrade.new(:user_id => user_id, :course_id => @course.id)
|
||||||
|
if (params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3")
|
||||||
|
course_info << CourseInfo.new(:user_id => user_id, :course_id => @course.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id])
|
||||||
|
if (params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3")
|
||||||
|
course_info << CourseInfo.new(:course_id => @course.id, :user_id => params[:membership][:user_id])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@course.members << members
|
||||||
|
@course.course_infos << course_info
|
||||||
|
end
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to_settings_in_courses }
|
||||||
|
format.js { @members = members; @applied_members = applied_members; }
|
||||||
|
format.api {
|
||||||
|
@member = members.first
|
||||||
|
if @member.valid?
|
||||||
|
render :action => 'show', :status => :created, :location => membership_url(@member)
|
||||||
|
else
|
||||||
|
render_validation_errors(@member)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end # end of if @project
|
||||||
|
|
||||||
|
end # end of params[:refusal_button]
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if params[:membership]
|
#modify by nwb
|
||||||
@member.role_ids = params[:membership][:role_ids]
|
#增加对课程成员修改的支持
|
||||||
|
if @project
|
||||||
|
if params[:membership]
|
||||||
|
@member.role_ids = params[:membership][:role_ids]
|
||||||
|
|
||||||
#added by nie
|
#added by nie
|
||||||
if(params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3")
|
if (params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3")
|
||||||
@projectInfo = ProjectInfo.new(:user_id => @member.user_id, :project_id => @project.id)
|
@projectInfo = ProjectInfo.new(:user_id => @member.user_id, :project_id => @project.id)
|
||||||
@projectInfo.save
|
@projectInfo.save
|
||||||
else
|
else
|
||||||
|
user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
|
||||||
|
if user_admin.size > 0
|
||||||
|
user_admin.each do |user|
|
||||||
|
user.destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
saved = @member.save
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to_settings_in_projects }
|
||||||
|
format.js
|
||||||
|
format.api {
|
||||||
|
if saved
|
||||||
|
render_api_ok
|
||||||
|
else
|
||||||
|
render_validation_errors(@member)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
elsif @course
|
||||||
|
if params[:membership]
|
||||||
|
@member.role_ids = params[:membership][:role_ids]
|
||||||
|
|
||||||
|
if (params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3")
|
||||||
|
@courseInfo = CourseInfos.new(:user_id => @member.user_id, :course_id => @course.id)
|
||||||
|
@courseInfo.save
|
||||||
|
else
|
||||||
|
user_admin = CourseInfos.where("user_id = ? and course_id = ?", @member.user_id, @course.id)
|
||||||
|
if user_admin.size > 0
|
||||||
|
user_admin.each do |user|
|
||||||
|
user.destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
saved = @member.save
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to_settings_in_courses }
|
||||||
|
format.js
|
||||||
|
format.api {
|
||||||
|
if saved
|
||||||
|
render_api_ok
|
||||||
|
else
|
||||||
|
render_validation_errors(@member)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
#modify by nwb
|
||||||
|
#课程成员删除修改
|
||||||
|
if @project
|
||||||
|
if request.delete? && @member.deletable?
|
||||||
|
@member.destroy
|
||||||
|
# end
|
||||||
user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
|
user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
|
||||||
if user_admin.size > 0
|
if user_admin.size > 0
|
||||||
user_admin.each do |user|
|
user_admin.each do |user|
|
||||||
user.destroy
|
user.destroy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
user_grade = UserGrade.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
|
||||||
end
|
if user_grade.size > 0
|
||||||
|
user_grade.each do |grade|
|
||||||
saved = @member.save
|
grade.destroy
|
||||||
respond_to do |format|
|
end
|
||||||
format.html { redirect_to_settings_in_projects }
|
|
||||||
format.js
|
|
||||||
format.api {
|
|
||||||
if saved
|
|
||||||
render_api_ok
|
|
||||||
else
|
|
||||||
render_validation_errors(@member)
|
|
||||||
end
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def destroy
|
|
||||||
if request.delete? && @member.deletable?
|
|
||||||
@member.destroy
|
|
||||||
# end
|
|
||||||
user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
|
|
||||||
if user_admin.size > 0
|
|
||||||
user_admin.each do |user|
|
|
||||||
user.destroy
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
user_grade = UserGrade.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
|
respond_to do |format|
|
||||||
if user_grade.size > 0
|
format.html { redirect_to_settings_in_projects }
|
||||||
user_grade.each do |grade|
|
format.js
|
||||||
grade.destroy
|
format.api {
|
||||||
|
if @member.destroyed?
|
||||||
|
render_api_ok
|
||||||
|
else
|
||||||
|
head :unprocessable_entity
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
elsif @course
|
||||||
|
if request.delete? && @member.deletable?
|
||||||
|
@member.destroy
|
||||||
|
user_admin = CourseInfos.where("user_id = ? and course_id = ?", @member.user_id, @course.id)
|
||||||
|
if user_admin.size > 0
|
||||||
|
user_admin.each do |user|
|
||||||
|
user.destroy
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
respond_to do |format|
|
||||||
respond_to do |format|
|
format.html { redirect_to_settings_in_courses }
|
||||||
format.html { redirect_to_settings_in_projects }
|
format.js
|
||||||
format.js
|
format.api {
|
||||||
format.api {
|
if @member.destroyed?
|
||||||
if @member.destroyed?
|
render_api_ok
|
||||||
render_api_ok
|
else
|
||||||
else
|
head :unprocessable_entity
|
||||||
head :unprocessable_entity
|
end
|
||||||
end
|
}
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -188,4 +286,8 @@ class MembersController < ApplicationController
|
||||||
def redirect_to_settings_in_projects
|
def redirect_to_settings_in_projects
|
||||||
redirect_to settings_project_path(@project, :tab => 'members')
|
redirect_to settings_project_path(@project, :tab => 'members')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def redirect_to_settings_in_courses
|
||||||
|
redirect_to settings_course_path(@course, :tab => 'members')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -51,7 +51,10 @@ class MemosController < ApplicationController
|
||||||
|
|
||||||
@memo_new = @memo.dup
|
@memo_new = @memo.dup
|
||||||
@memo = @memo.root # 取出楼主,防止输入帖子id让回复作为主贴显示
|
@memo = @memo.root # 取出楼主,防止输入帖子id让回复作为主贴显示
|
||||||
@memo.update_column(:viewed_count, (@memo.viewed_count.to_i + 1))
|
unless @memo.new_record?
|
||||||
|
@memo.update_column(:viewed_count, (@memo.viewed_count.to_i + 1))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
page = params[:page]
|
page = params[:page]
|
||||||
if params[:r] && page.nil?
|
if params[:r] && page.nil?
|
||||||
|
@ -68,10 +71,14 @@ class MemosController < ApplicationController
|
||||||
limit(@reply_pages.per_page).
|
limit(@reply_pages.per_page).
|
||||||
offset(@reply_pages.offset).
|
offset(@reply_pages.offset).
|
||||||
all
|
all
|
||||||
|
if @memo.new_record?
|
||||||
|
format.html { redirect_to back_url, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" }
|
||||||
|
else
|
||||||
|
format.html { render action: :show }#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" }
|
||||||
|
# format.html { redirect_to back_memo_or_forum_url}#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" }
|
||||||
|
format.json { render json: @memo.errors, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
|
|
||||||
format.html { render action: :show }#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" }
|
|
||||||
# format.html { redirect_to back_memo_or_forum_url}#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" }
|
|
||||||
format.json { render json: @memo.errors, status: :unprocessable_entity }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -49,7 +49,7 @@ class MessagesController < ApplicationController
|
||||||
all
|
all
|
||||||
|
|
||||||
@reply = Message.new(:subject => "RE: #{@message.subject}")
|
@reply = Message.new(:subject => "RE: #{@message.subject}")
|
||||||
if @message.board.project.project_type ==1
|
if @course
|
||||||
render :action => "show", :layout => "base_courses"#by young
|
render :action => "show", :layout => "base_courses"#by young
|
||||||
else
|
else
|
||||||
render :action => "show", :layout => "base_projects"#by young
|
render :action => "show", :layout => "base_projects"#by young
|
||||||
|
@ -68,6 +68,9 @@ class MessagesController < ApplicationController
|
||||||
call_hook(:controller_messages_new_after_save, { :params => params, :message => @message})
|
call_hook(:controller_messages_new_after_save, { :params => params, :message => @message})
|
||||||
render_attachment_warning_if_needed(@message)
|
render_attachment_warning_if_needed(@message)
|
||||||
redirect_to board_message_path(@board, @message)
|
redirect_to board_message_path(@board, @message)
|
||||||
|
else
|
||||||
|
layout_file = @project ? 'base_projects' : 'base_courses'
|
||||||
|
render :action => 'new', :layout => layout_file
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -84,8 +87,11 @@ class MessagesController < ApplicationController
|
||||||
call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply})
|
call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply})
|
||||||
attachments = Attachment.attach_files(@reply, params[:attachments])
|
attachments = Attachment.attach_files(@reply, params[:attachments])
|
||||||
render_attachment_warning_if_needed(@reply)
|
render_attachment_warning_if_needed(@reply)
|
||||||
|
else
|
||||||
|
#render file: 'messages#show', layout: 'base_courses'
|
||||||
end
|
end
|
||||||
redirect_to board_message_path(@board, @topic, :r => @reply)
|
redirect_to board_message_path(@board, @topic, :r => @reply)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Edit a message
|
# Edit a message
|
||||||
|
@ -138,8 +144,14 @@ private
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_board
|
def find_board
|
||||||
@board = Board.find(params[:board_id], :include => :project)
|
#modify by nwb
|
||||||
@project = @board.project
|
@board = Board.find(params[:board_id])
|
||||||
|
if @board.project_id != -1 && @board.project_id != nil
|
||||||
|
@project = @board.project
|
||||||
|
elsif @board.course_id
|
||||||
|
@course = @board.course
|
||||||
|
end
|
||||||
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
nil
|
nil
|
||||||
|
|
|
@ -61,7 +61,7 @@ class MyController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@se = @user.user_extensions ||= UserExtensions.new
|
@se = @user.extensions
|
||||||
@se.school_id = params[:occupation] if params[:occupation]
|
@se.school_id = params[:occupation] if params[:occupation]
|
||||||
@se.gender = params[:gender]
|
@se.gender = params[:gender]
|
||||||
@se.location = params[:province] if params[:province]
|
@se.location = params[:province] if params[:province]
|
||||||
|
|
|
@ -38,37 +38,62 @@ class NewsController < ApplicationController
|
||||||
@limit = 10
|
@limit = 10
|
||||||
end
|
end
|
||||||
|
|
||||||
scope = @project ? @project.news.visible : News.visible
|
# modify by nwb
|
||||||
|
if params[:course_id] && @course==nil
|
||||||
@news_count = scope.count
|
@course = Course.find(params[:course_id])
|
||||||
@news_pages = Paginator.new @news_count, @limit, params['page']
|
|
||||||
@offset ||= @news_pages.offset
|
|
||||||
@newss = scope.all(:include => [:author, :project],
|
|
||||||
:order => "#{News.table_name}.created_on DESC",
|
|
||||||
:offset => @offset,
|
|
||||||
:limit => @limit)
|
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
format.html {
|
|
||||||
@news = News.new # for adding news inline
|
|
||||||
# huang
|
|
||||||
|
|
||||||
if @project.project_type == 1
|
|
||||||
render :layout => 'base_courses'
|
|
||||||
else
|
|
||||||
render :layout => false if request.xhr?
|
|
||||||
end
|
|
||||||
}
|
|
||||||
format.api
|
|
||||||
format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
|
|
||||||
end
|
end
|
||||||
end
|
if @project
|
||||||
|
scope = @project ? @project.news.visible : News.visible
|
||||||
|
|
||||||
|
@news_count = scope.count
|
||||||
|
@news_pages = Paginator.new @news_count, @limit, params['page']
|
||||||
|
@offset ||= @news_pages.offset
|
||||||
|
@newss = scope.all(:include => [:author, :project],
|
||||||
|
:order => "#{News.table_name}.created_on DESC",
|
||||||
|
:offset => @offset,
|
||||||
|
:limit => @limit)
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html {
|
||||||
|
@news = News.new # for adding news inline
|
||||||
|
# huang
|
||||||
|
|
||||||
|
render :layout => false if request.xhr?
|
||||||
|
}
|
||||||
|
format.api
|
||||||
|
format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
|
||||||
|
end
|
||||||
|
elsif @course
|
||||||
|
scope = @course ? @course.news.course_visible : News.course_visible
|
||||||
|
|
||||||
|
@news_count = scope.count
|
||||||
|
@news_pages = Paginator.new @news_count, @limit, params['page']
|
||||||
|
@offset ||= @news_pages.offset
|
||||||
|
@newss = scope.all(:include => [:author, :course],
|
||||||
|
:order => "#{News.table_name}.created_on DESC",
|
||||||
|
:offset => @offset,
|
||||||
|
:limit => @limit)
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html {
|
||||||
|
@news = News.new
|
||||||
|
render :layout => 'base_courses'
|
||||||
|
}
|
||||||
|
format.api
|
||||||
|
format.atom { render_feed(@newss, :title => (@course ? @course.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@comments = @news.comments
|
@comments = @news.comments
|
||||||
@comments.reverse! if User.current.wants_comments_in_reverse_order?
|
@comments.reverse! if User.current.wants_comments_in_reverse_order?
|
||||||
if @project.project_type == 1
|
#modify by nwb
|
||||||
render :layout => 'base_courses'
|
if @news.course_id
|
||||||
|
@course = Course.find(@news.course_id)
|
||||||
|
if @course
|
||||||
|
render :layout => 'base_courses'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -81,16 +106,31 @@ class NewsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@news = News.new(:project => @project, :author => User.current)
|
#modify by nwb
|
||||||
@news.safe_attributes = params[:news]
|
if @project
|
||||||
@news.save_attachments(params[:attachments])
|
@news = News.new(:project => @project, :author => User.current)
|
||||||
if @news.save
|
@news.safe_attributes = params[:news]
|
||||||
render_attachment_warning_if_needed(@news)
|
@news.save_attachments(params[:attachments])
|
||||||
flash[:notice] = l(:notice_successful_create)
|
if @news.save
|
||||||
redirect_to project_news_index_path(@project)
|
render_attachment_warning_if_needed(@news)
|
||||||
else
|
flash[:notice] = l(:notice_successful_create)
|
||||||
layout_file = (@project.project_type == 1) ? 'base_courses' : 'base_projects'
|
redirect_to project_news_index_path(@project)
|
||||||
render :action => 'new', :layout => layout_file
|
else
|
||||||
|
layout_file = @project ? 'base_projects' : 'base_courses'
|
||||||
|
render :action => 'new', :layout => layout_file
|
||||||
|
end
|
||||||
|
elsif @course
|
||||||
|
@news = News.new(:course => @course, :author => User.current)
|
||||||
|
@news.safe_attributes = params[:news]
|
||||||
|
@news.save_attachments(params[:attachments])
|
||||||
|
if @news.save
|
||||||
|
render_attachment_warning_if_needed(@news)
|
||||||
|
flash[:notice] = l(:notice_successful_create)
|
||||||
|
redirect_to course_news_index_path(@course)
|
||||||
|
else
|
||||||
|
layout_file = 'base_courses'
|
||||||
|
render :action => 'new', :layout => layout_file
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -111,7 +151,13 @@ class NewsController < ApplicationController
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@news.destroy
|
@news.destroy
|
||||||
redirect_to project_news_index_path(@project)
|
# modify by nwb
|
||||||
|
if @project
|
||||||
|
redirect_to project_news_index_path(@project)
|
||||||
|
elsif @course
|
||||||
|
redirect_to course_news_index_path(@course)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
class NotificationcommentsController < ApplicationController
|
||||||
|
# default_search_scope :contestnotifications
|
||||||
|
# model_object Contestnotifications
|
||||||
|
# before_filter :authorize
|
||||||
|
|
||||||
|
def create
|
||||||
|
#raise Unauthorized unless @contestnotifications.notificationcommentable?
|
||||||
|
@contest = Contest.find(params[:contest_id])
|
||||||
|
@contestnotification = Contestnotification.find(params[:contestnotification_id])
|
||||||
|
|
||||||
|
# @notificaioncomment = Notificationcomment.new
|
||||||
|
# @notificaioncomment.safe_attributes = params[:notificationcomment]
|
||||||
|
# @notificaioncomment.author = User.current
|
||||||
|
comment = @contestnotification.notificationcomments.new(params[:notificationcomment].merge(author_id: User.current.id))
|
||||||
|
if comment.save
|
||||||
|
flash[:notice] = l(:label_comment_added)
|
||||||
|
end
|
||||||
|
|
||||||
|
redirect_to contest_contestnotification_path(@contest, @contestnotification)
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@contestnotifications.notificaioncomments.find(params[:notificaioncomment_id]).destroy
|
||||||
|
redirect_to contest_contestnotification_path(@contestnotifications)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -9,8 +9,12 @@ class PraiseTreadController < ApplicationController
|
||||||
if request.get?
|
if request.get?
|
||||||
@obj_id = params[:obj_id]
|
@obj_id = params[:obj_id]
|
||||||
@obj_type = params[:obj_type]
|
@obj_type = params[:obj_type]
|
||||||
|
@horizontal = params[:horizontal].downcase == "false" ? false:true
|
||||||
@obj = find_object_by_type_and_id(@obj_type,@obj_id)
|
@obj = find_object_by_type_and_id(@obj_type,@obj_id)
|
||||||
praise_tread_plus(@obj_type,@obj_id,1)
|
unless @obj.author_id == User.current.id
|
||||||
|
praise_tread_plus(@obj_type,@obj_id,1)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -44,8 +48,12 @@ class PraiseTreadController < ApplicationController
|
||||||
if request.get?
|
if request.get?
|
||||||
@obj_id = params[:obj_id]
|
@obj_id = params[:obj_id]
|
||||||
@obj_type = params[:obj_type]
|
@obj_type = params[:obj_type]
|
||||||
|
@horizontal = params[:horizontal].downcase == "false" ? false:true
|
||||||
@obj = find_object_by_type_and_id(@obj_type,@obj_id)
|
@obj = find_object_by_type_and_id(@obj_type,@obj_id)
|
||||||
praise_tread_plus(@obj_type,@obj_id,0)
|
unless @obj.author_id == User.current.id
|
||||||
|
praise_tread_plus(@obj_type,@obj_id,0)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -71,6 +79,10 @@ class PraiseTreadController < ApplicationController
|
||||||
@obj = Bid.find_by_id(id)
|
@obj = Bid.find_by_id(id)
|
||||||
when 'Contest'
|
when 'Contest'
|
||||||
@obj = Contest.find_by_id(id)
|
@obj = Contest.find_by_id(id)
|
||||||
|
when 'Memo'
|
||||||
|
@obj = Memo.find_by_id(id)
|
||||||
|
when 'Message'
|
||||||
|
@obj = Message.find_by_id(id)
|
||||||
end
|
end
|
||||||
return @obj
|
return @obj
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,10 +16,11 @@
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class PreviewsController < ApplicationController
|
class PreviewsController < ApplicationController
|
||||||
before_filter :find_project, :find_attachments
|
before_filter :find_project, :find_attachments, :find_contest, except: [:contestnotification]
|
||||||
|
|
||||||
def issue
|
def issue
|
||||||
@issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
|
@issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
|
||||||
|
@issue = @contest.issues.find_by_id(params[:id]) unless params[:id].blank?
|
||||||
if @issue
|
if @issue
|
||||||
@description = params[:issue] && params[:issue][:description]
|
@description = params[:issue] && params[:issue][:description]
|
||||||
if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n")
|
if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n")
|
||||||
|
@ -41,6 +42,12 @@ class PreviewsController < ApplicationController
|
||||||
render :partial => 'common/preview'
|
render :partial => 'common/preview'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def contestnotification
|
||||||
|
@previewed = Contestnotification.find(params[:id])
|
||||||
|
@text = (params[:contestnotification] ? params[:contestnotification][:description] : nil)
|
||||||
|
render :partial => 'common/preview'
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def find_project
|
def find_project
|
||||||
|
@ -50,4 +57,20 @@ class PreviewsController < ApplicationController
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def contestnotifications
|
||||||
|
if params[:id].present? && contestnotifications = Contestnotifications.visible.find_by_id(params[:id])
|
||||||
|
@previewed = contestnotifications
|
||||||
|
end
|
||||||
|
@text = (params[:contestnotifications] ? params[:contestnotifications][:description] : nil)
|
||||||
|
render :partial => 'common/preview'
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def find_contest
|
||||||
|
contest_id = (params[:issue] && params[:issue][:contest_id]) || params[:contest_id]
|
||||||
|
@contest = Contest.find(contest_id)
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,11 +37,12 @@ class ProjectsController < ApplicationController
|
||||||
# before_filter :authorize, :except => [:new_join, :new_homework, :homework, :statistics, :search, :watcherlist, :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy, :member, :focus, :file,
|
# before_filter :authorize, :except => [:new_join, :new_homework, :homework, :statistics, :search, :watcherlist, :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy, :member, :focus, :file,
|
||||||
# :statistics, :feedback, :course, :enterprise_course, :course_enterprise, :project_respond, :share,
|
# :statistics, :feedback, :course, :enterprise_course, :course_enterprise, :project_respond, :share,
|
||||||
# :show_projects_score, :issue_score_index, :news_score_index, :file_score_index, :code_submit_score_index, :projects_topic_score_index]
|
# :show_projects_score, :issue_score_index, :news_score_index, :file_score_index, :code_submit_score_index, :projects_topic_score_index]
|
||||||
|
#此条勿删 课程相关权限 ,:new_homework,:homework,:feedback,,:member
|
||||||
before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches,:course]
|
before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches,:course]
|
||||||
before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches]
|
before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches]
|
||||||
before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar]
|
before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar]
|
||||||
before_filter :file, :statistics, :watcherlist
|
before_filter :file, :statistics, :watcherlist
|
||||||
|
before_filter :find_project_repository, :only => [:show]
|
||||||
# 除非项目内人员,不可查看成员, TODO: 完了写报表里去
|
# 除非项目内人员,不可查看成员, TODO: 完了写报表里去
|
||||||
before_filter :memberAccess, only: :member
|
before_filter :memberAccess, only: :member
|
||||||
|
|
||||||
|
@ -77,6 +78,14 @@ class ProjectsController < ApplicationController
|
||||||
### added by william
|
### added by william
|
||||||
include ActsAsTaggableOn::TagsHelper
|
include ActsAsTaggableOn::TagsHelper
|
||||||
|
|
||||||
|
def find_project_repository
|
||||||
|
unless @project.repositories.nil?
|
||||||
|
@project.repositories.each do |repository|
|
||||||
|
repository.fetch_changesets if Setting.autofetch_changesets?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def enterprise_course
|
def enterprise_course
|
||||||
session[:enterprise_college] = 2
|
session[:enterprise_college] = 2
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
@ -352,27 +361,13 @@ class ProjectsController < ApplicationController
|
||||||
#gcmend
|
#gcmend
|
||||||
|
|
||||||
|
|
||||||
# added by fq
|
|
||||||
def new_join
|
|
||||||
@course = Project.find(params[:object_id])
|
|
||||||
end
|
|
||||||
|
|
||||||
#Added by young
|
#Added by young
|
||||||
def homework
|
def homework
|
||||||
@offset, @limit = api_offset_and_limit({:limit => 10})
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
||||||
@bids = @project.homeworks.order('deadline DESC')
|
@bids = @project.homeworks.order('deadline')
|
||||||
@bids = @bids.like(params[:name]) if params[:name].present?
|
@bids = @bids.like(params[:name]) if params[:name].present?
|
||||||
@bid_count = @bids.count
|
|
||||||
@bid_pages = Paginator.new @bid_count, @limit, params['page']
|
|
||||||
|
|
||||||
@offset ||= @bid_pages.reverse_offset
|
@bids = paginateHelper @bids
|
||||||
#@bids = @bids.offset(@offset).limit(@limit).all.reverse
|
|
||||||
unless @offset == 0
|
|
||||||
@bids = @bids.offset(@offset).limit(@limit).all.reverse
|
|
||||||
else
|
|
||||||
limit = @bid_count % @limit
|
|
||||||
@bids = @bids.offset(@offset).limit(limit).all.reverse
|
|
||||||
end
|
|
||||||
render :layout => 'base_courses'
|
render :layout => 'base_courses'
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -721,6 +716,9 @@ class ProjectsController < ApplicationController
|
||||||
@teachers= searchTeacherAndAssistant(@project)
|
@teachers= searchTeacherAndAssistant(@project)
|
||||||
@canShowRealName = isCourseTeacher(User.current.id)
|
@canShowRealName = isCourseTeacher(User.current.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#勿删 real_name action为虚拟的该方法并不存在,用来辅助判断真名权限
|
||||||
|
#勿删 @canShowRealName = User.current.allowed_to?({:controller => "projects", :action => "real_name"}, @project || @projects, :global => false)
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html{render :layout => 'base_courses' if @base_courses_tag==1}
|
format.html{render :layout => 'base_courses' if @base_courses_tag==1}
|
||||||
format.api
|
format.api
|
||||||
|
@ -916,11 +914,13 @@ class ProjectsController < ApplicationController
|
||||||
|
|
||||||
# added by bai
|
# added by bai
|
||||||
def show_projects_score
|
def show_projects_score
|
||||||
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
def issue_score_index
|
def issue_score_index
|
||||||
|
respond_to do |format|
|
||||||
|
format.js
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def news_score_index
|
def news_score_index
|
||||||
|
|
|
@ -568,7 +568,7 @@ class RepositoriesController < ApplicationController
|
||||||
project = Project.find(params[:id])
|
project = Project.find(params[:id])
|
||||||
if !User.current.member_of?(project)
|
if !User.current.member_of?(project)
|
||||||
if project.hidden_repo
|
if project.hidden_repo
|
||||||
render_403
|
#render_403
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
|
|
@ -105,7 +105,7 @@ class SchoolController < ApplicationController
|
||||||
end
|
end
|
||||||
options = ""
|
options = ""
|
||||||
@school.each do |s|
|
@school.each do |s|
|
||||||
options << "<li style = 'width: 33%; float: left'><a id=#{s.id} onclick='test(this.id)'>#{s.name}</a></li>"
|
options << "<li style = 'width: 33%; float: left'> <a id=#{s.id} onclick='test(this.id)'>#{s.name}</a></li>"
|
||||||
end
|
end
|
||||||
|
|
||||||
render :text => options
|
render :text => options
|
||||||
|
|
|
@ -108,11 +108,16 @@ class SoftapplicationsController < ApplicationController
|
||||||
# @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page']
|
# @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page']
|
||||||
@membership.each do |membership|
|
@membership.each do |membership|
|
||||||
unless(membership.project.project_type==1)
|
unless(membership.project.project_type==1)
|
||||||
membership.member_roles.each{|role|
|
#membership.member_roles.each{|role|
|
||||||
if(role.role_id == 3)
|
# if(role.role_id == 3)
|
||||||
|
# @option << membership.project
|
||||||
|
# end
|
||||||
|
#}
|
||||||
|
|
||||||
|
#拥有编辑项目权限的可操作该项目
|
||||||
|
if User.current.allowed_to?({:controller => "projects", :action => "edit"}, membership.project, :global => false)
|
||||||
@option << membership.project
|
@option << membership.project
|
||||||
end
|
end
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,8 @@ class TagsController < ApplicationController
|
||||||
layout "base_tags"
|
layout "base_tags"
|
||||||
|
|
||||||
before_filter :require_admin,:only => :show
|
before_filter :require_admin,:only => :show
|
||||||
|
|
||||||
|
include CoursesHelper
|
||||||
include ProjectsHelper
|
include ProjectsHelper
|
||||||
include IssuesHelper
|
include IssuesHelper
|
||||||
include UsersHelper
|
include UsersHelper
|
||||||
|
@ -14,6 +15,7 @@ class TagsController < ApplicationController
|
||||||
include ContestsHelper
|
include ContestsHelper
|
||||||
include ActsAsTaggableOn::TagsHelper
|
include ActsAsTaggableOn::TagsHelper
|
||||||
helper :projects
|
helper :projects
|
||||||
|
helper :courses
|
||||||
include TagsHelper
|
include TagsHelper
|
||||||
helper :tags
|
helper :tags
|
||||||
include OpenSourceProjectsHelper
|
include OpenSourceProjectsHelper
|
||||||
|
@ -62,14 +64,18 @@ class TagsController < ApplicationController
|
||||||
@forum_tags_num, @attachments_tags_num, @open_source_projects_num = get_tags_size
|
@forum_tags_num, @attachments_tags_num, @open_source_projects_num = get_tags_size
|
||||||
|
|
||||||
# 获取搜索结果
|
# 获取搜索结果
|
||||||
@obj,@obj_pages,@results_count,@users_results,
|
@obj,
|
||||||
|
@obj_pages,
|
||||||
|
@results_count,
|
||||||
|
@users_results,
|
||||||
@projects_results,
|
@projects_results,
|
||||||
@issues_results,
|
@issues_results,
|
||||||
@bids_results,
|
@bids_results,
|
||||||
@forums_results,
|
@forums_results,
|
||||||
@attachments_results,
|
attachments_results,
|
||||||
@contests_tags,
|
@contests_results,
|
||||||
@open_source_projects_results = refresh_results(@obj_id,@obj_flag,@selected_tags)
|
@courses_results,
|
||||||
|
@open_source_projects_results= refresh_results(@obj_id,@obj_flag,@selected_tags)
|
||||||
|
|
||||||
# 这里是做tag推荐用的, 用来生产推荐的tags
|
# 这里是做tag推荐用的, 用来生产推荐的tags
|
||||||
unless @obj.nil?
|
unless @obj.nil?
|
||||||
|
@ -94,13 +100,18 @@ class TagsController < ApplicationController
|
||||||
$related_tags.delete(@tag)
|
$related_tags.delete(@tag)
|
||||||
|
|
||||||
# 获取搜索结果
|
# 获取搜索结果
|
||||||
@obj,@obj_pages,@results_count,@users_results,
|
@obj,
|
||||||
|
@obj_pages,
|
||||||
|
@results_count,
|
||||||
|
@users_results,
|
||||||
@projects_results,
|
@projects_results,
|
||||||
@issues_results,
|
@issues_results,
|
||||||
@bids_results,
|
@bids_results,
|
||||||
@forums_results,
|
@forums_results,
|
||||||
@attachments_results,
|
attachments_results,
|
||||||
@contests_results = refresh_results(@obj_id,@show_flag)
|
@contests_results,
|
||||||
|
@courses_results,
|
||||||
|
@open_source_projects_results= refresh_results(@obj_id,@show_flag)
|
||||||
end
|
end
|
||||||
|
|
||||||
# 删除已选tag
|
# 删除已选tag
|
||||||
|
@ -112,13 +123,18 @@ class TagsController < ApplicationController
|
||||||
$selected_tags.delete(@tag)
|
$selected_tags.delete(@tag)
|
||||||
|
|
||||||
# 获取搜索结果
|
# 获取搜索结果
|
||||||
@obj,@obj_pages,@results_count,@users_results,
|
@obj,
|
||||||
|
@obj_pages,
|
||||||
|
@results_count,
|
||||||
|
@users_results,
|
||||||
@projects_results,
|
@projects_results,
|
||||||
@issues_results,
|
@issues_results,
|
||||||
@bids_results,
|
@bids_results,
|
||||||
@forums_results,
|
@forums_results,
|
||||||
@attachments_results,
|
attachments_results,
|
||||||
@contests_results = refresh_results(@obj_id,@show_flag)
|
@contests_results,
|
||||||
|
@courses_results,
|
||||||
|
@open_source_projects_results= refresh_results(@obj_id,@show_flag)
|
||||||
end
|
end
|
||||||
|
|
||||||
def show_all
|
def show_all
|
||||||
|
@ -188,6 +204,7 @@ class TagsController < ApplicationController
|
||||||
@obj_pages = nil
|
@obj_pages = nil
|
||||||
@obj = nil
|
@obj = nil
|
||||||
@result = nil
|
@result = nil
|
||||||
|
@courses_results = nil
|
||||||
|
|
||||||
# 这里为了提高系统的响应速度 把搜索结果放到case中去了
|
# 这里为了提高系统的响应速度 把搜索结果放到case中去了
|
||||||
case obj_flag
|
case obj_flag
|
||||||
|
@ -219,6 +236,9 @@ class TagsController < ApplicationController
|
||||||
when '8'
|
when '8'
|
||||||
@obj = OpenSourceProject.find_by_id(obj_id)
|
@obj = OpenSourceProject.find_by_id(obj_id)
|
||||||
@obj_pages, @open_source_projects_results, @results_count = for_pagination(get_open_source_projects_by_tag(selected_tags))
|
@obj_pages, @open_source_projects_results, @results_count = for_pagination(get_open_source_projects_by_tag(selected_tags))
|
||||||
|
when '9' then
|
||||||
|
@obj = Course.find_by_id(obj_id)
|
||||||
|
@obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags))
|
||||||
else
|
else
|
||||||
@obj = nil
|
@obj = nil
|
||||||
end
|
end
|
||||||
|
@ -232,6 +252,7 @@ class TagsController < ApplicationController
|
||||||
@forums_results,
|
@forums_results,
|
||||||
attachments_results,
|
attachments_results,
|
||||||
@contests_results,
|
@contests_results,
|
||||||
|
@courses_results,
|
||||||
@open_source_projects_results]
|
@open_source_projects_results]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -246,14 +267,14 @@ class TagsController < ApplicationController
|
||||||
|
|
||||||
# 获取有某类对象的tag总数
|
# 获取有某类对象的tag总数
|
||||||
def get_tags_size
|
def get_tags_size
|
||||||
@issues_tags_num = Issue.tag_counts.size
|
@issues_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Issue").count
|
||||||
@projects_tags_num = Project.tag_counts.size
|
@projects_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Project").count
|
||||||
@users_tags_num = User.tag_counts.size
|
@users_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"User").count
|
||||||
@bids_tags_num = Bid.tag_counts.size
|
@bids_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Bid").count
|
||||||
forum_tags_num = Forum.tag_counts.size
|
forum_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Forum").count
|
||||||
attachment_tags_num = Attachment.tag_counts.size
|
attachment_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Attachment").count
|
||||||
@open_source_projects_num = OpenSourceProject.tag_counts.size
|
@open_source_projects_num = ActsAsTaggableOn::Tagging.where(taggable_type:"OpenSourceProject").count
|
||||||
@contests_tags_num = Contest.tag_counts.size
|
@contests_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Contest").count
|
||||||
return @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num, forum_tags_num, attachment_tags_num, @contests_tags_num, @open_source_projects_num
|
return @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num, forum_tags_num, attachment_tags_num, @contests_tags_num, @open_source_projects_num
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -279,6 +300,8 @@ class TagsController < ApplicationController
|
||||||
return 'Contest'
|
return 'Contest'
|
||||||
when '8'
|
when '8'
|
||||||
return 'OpenSourceProject'
|
return 'OpenSourceProject'
|
||||||
|
when '9'
|
||||||
|
return 'Course'
|
||||||
else
|
else
|
||||||
render_error :message => e.message
|
render_error :message => e.message
|
||||||
return
|
return
|
||||||
|
|
|
@ -32,12 +32,14 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :tag_saveEx,:user_projects, :user_newfeedback, :user_comments, :watch_bids, :watch_contests, :info,
|
before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :tag_saveEx,:user_projects, :user_newfeedback, :user_comments, :watch_bids, :watch_contests, :info,
|
||||||
:user_watchlist, :user_fanslist,:update, :user_courses, :user_homeworks, :watch_projects, :show_score, :topic_score_index, :project_score_index,
|
:user_watchlist, :user_fanslist,:update, :user_courses, :user_homeworks, :watch_projects, :show_score, :topic_score_index, :project_score_index,
|
||||||
:activity_score_index, :influence_score_index, :score_index]
|
:activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index,
|
||||||
|
:activity_new_score_index, :influence_new_score_index, :score_new_index,:update_score]
|
||||||
#edit has been deleted by huang, 2013-9-23
|
#edit has been deleted by huang, 2013-9-23
|
||||||
before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses,
|
before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses,
|
||||||
:user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments,
|
:user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments,
|
||||||
:watch_bids, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index,
|
:watch_bids, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index,
|
||||||
:activity_score_index, :influence_score_index, :score_index]
|
:activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index,
|
||||||
|
:activity_new_score_index, :influence_new_score_index, :score_new_index]
|
||||||
before_filter :auth_user_extension, only: :show
|
before_filter :auth_user_extension, only: :show
|
||||||
accept_api_auth :index, :show, :create, :update, :destroy,:tag_save , :tag_saveEx
|
accept_api_auth :index, :show, :create, :update, :destroy,:tag_save , :tag_saveEx
|
||||||
|
|
||||||
|
@ -50,6 +52,7 @@ class UsersController < ApplicationController
|
||||||
helper :custom_fields
|
helper :custom_fields
|
||||||
include CustomFieldsHelper
|
include CustomFieldsHelper
|
||||||
include AvatarHelper
|
include AvatarHelper
|
||||||
|
include WordsHelper
|
||||||
|
|
||||||
# added by liuping 关注
|
# added by liuping 关注
|
||||||
|
|
||||||
|
@ -92,7 +95,11 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
# added by bai
|
# added by bai
|
||||||
def show_score
|
def show_score
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def show_new_score
|
||||||
|
render :layout => false
|
||||||
end
|
end
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
@ -200,19 +207,19 @@ class UsersController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
membership = @user.memberships.all(:conditions => Project.visible_condition(User.current))
|
membership = @user.coursememberships.all#@user.coursememberships.all(:conditions => Course.visible_condition(User.current))
|
||||||
membership.sort! {|older, newer| newer.created_on <=> older.created_on }
|
membership.sort! {|older, newer| newer.created_on <=> older.created_on }
|
||||||
@memberships = []
|
@memberships = []
|
||||||
membership.collect { |e|
|
membership.collect { |e|
|
||||||
@memberships.push(e) if(e.project.project_type == 1)
|
@memberships.push(e)
|
||||||
}
|
}
|
||||||
## 判断课程是否过期 [需封装]
|
## 判断课程是否过期 [需封装]
|
||||||
@memberships_doing = []
|
@memberships_doing = []
|
||||||
@memberships_done = []
|
@memberships_done = []
|
||||||
now_time = Time.now.year
|
now_time = Time.now.year
|
||||||
@memberships.map { |e|
|
@memberships.map { |e|
|
||||||
end_time = e.project.course_extra.get_time.year
|
end_time = e.course.get_time.year
|
||||||
isDone = course_endTime_timeout?(e.project)
|
isDone = course_endTime_timeout?(e.course)
|
||||||
if isDone
|
if isDone
|
||||||
@memberships_done.push e
|
@memberships_done.push e
|
||||||
else
|
else
|
||||||
|
@ -229,7 +236,10 @@ class UsersController < ApplicationController
|
||||||
def user_newfeedback
|
def user_newfeedback
|
||||||
@jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
|
@jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
|
||||||
@jours.update_all(:is_readed => true, :status => false)
|
@jours.update_all(:is_readed => true, :status => false)
|
||||||
|
@jours.each do |journal|
|
||||||
|
fetch_user_leaveWord_reply(journal).update_all(:is_readed => true, :status => false)
|
||||||
|
end
|
||||||
|
|
||||||
@limit = 10
|
@limit = 10
|
||||||
@feedback_count = @jours.count
|
@feedback_count = @jours.count
|
||||||
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
|
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
|
||||||
|
@ -363,7 +373,7 @@ class UsersController < ApplicationController
|
||||||
def search
|
def search
|
||||||
sort_init 'login', 'asc'
|
sort_init 'login', 'asc'
|
||||||
sort_update %w(login firstname lastname mail admin created_on last_login_on)
|
sort_update %w(login firstname lastname mail admin created_on last_login_on)
|
||||||
|
(redirect_to users_path, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
|
||||||
case params[:format]
|
case params[:format]
|
||||||
when 'xml', 'json'
|
when 'xml', 'json'
|
||||||
@offset, @limit = api_offset_and_limit({:limit => 15})
|
@offset, @limit = api_offset_and_limit({:limit => 15})
|
||||||
|
@ -669,6 +679,8 @@ class UsersController < ApplicationController
|
||||||
@obj = Contest.find_by_id(@obj_id)
|
@obj = Contest.find_by_id(@obj_id)
|
||||||
when '8'
|
when '8'
|
||||||
@obj = OpenSourceProject.find_by_id(@obj_id)
|
@obj = OpenSourceProject.find_by_id(@obj_id)
|
||||||
|
when '9'
|
||||||
|
@obj = Course.find_by_id(@obj_id)
|
||||||
else
|
else
|
||||||
@obj = nil
|
@obj = nil
|
||||||
end
|
end
|
||||||
|
@ -710,6 +722,8 @@ class UsersController < ApplicationController
|
||||||
@obj = Contest.find_by_id(@obj_id)
|
@obj = Contest.find_by_id(@obj_id)
|
||||||
when '8'
|
when '8'
|
||||||
@obj = OpenSourceProject.find_by_id(@obj_id)
|
@obj = OpenSourceProject.find_by_id(@obj_id)
|
||||||
|
when '9'
|
||||||
|
@obj = Course.find_by_id(@obj_id)
|
||||||
else
|
else
|
||||||
@obj = nil
|
@obj = nil
|
||||||
end
|
end
|
||||||
|
@ -767,7 +781,30 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
end
|
end
|
||||||
# end
|
# end
|
||||||
|
def topic_new_score_index
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def project_new_score_index
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def activity_new_score_index
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def influence_new_score_index
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def score_new_index
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_score
|
||||||
|
@user = User.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def find_user
|
def find_user
|
||||||
|
|
|
@ -20,6 +20,7 @@ class VersionsController < ApplicationController
|
||||||
menu_item :roadmap
|
menu_item :roadmap
|
||||||
model_object Version
|
model_object Version
|
||||||
before_filter :find_model_object, :except => [:index, :new, :create, :close_completed]
|
before_filter :find_model_object, :except => [:index, :new, :create, :close_completed]
|
||||||
|
#before_filter :find_model_object_contest, :except => [:index, :new, :create]
|
||||||
before_filter :find_project_from_association, :except => [:index, :new, :create, :close_completed]
|
before_filter :find_project_from_association, :except => [:index, :new, :create, :close_completed]
|
||||||
before_filter :find_project_by_project_id, :only => [:index, :new, :create, :close_completed]
|
before_filter :find_project_by_project_id, :only => [:index, :new, :create, :close_completed]
|
||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
|
@ -154,6 +155,13 @@ class VersionsController < ApplicationController
|
||||||
redirect_to settings_project_path(@project, :tab => 'versions')
|
redirect_to settings_project_path(@project, :tab => 'versions')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def close_completed_contest
|
||||||
|
if request.put?
|
||||||
|
@contest.close_completed_versions
|
||||||
|
end
|
||||||
|
redirect_to settings_contest_path(@contest, :tab => 'versions')
|
||||||
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
if @version.fixed_issues.empty?
|
if @version.fixed_issues.empty?
|
||||||
@version.destroy
|
@version.destroy
|
||||||
|
|
|
@ -122,7 +122,9 @@ class WatchersController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_watchables
|
def find_watchables
|
||||||
|
#根据参数获取关注对象的类型(user、project)
|
||||||
klass = Object.const_get(params[:object_type].camelcase) rescue nil
|
klass = Object.const_get(params[:object_type].camelcase) rescue nil
|
||||||
|
#判断获取的对象类型能否响应‘watched_by’方法
|
||||||
if klass && klass.respond_to?('watched_by')
|
if klass && klass.respond_to?('watched_by')
|
||||||
@watchables = klass.find_all_by_id(Array.wrap(params[:object_id]))
|
@watchables = klass.find_all_by_id(Array.wrap(params[:object_id]))
|
||||||
raise Unauthorized if @watchables.any? {|w| w.respond_to?(:visible?) && !w.visible?}
|
raise Unauthorized if @watchables.any? {|w| w.respond_to?(:visible?) && !w.visible?}
|
||||||
|
|
|
@ -18,16 +18,10 @@
|
||||||
class WelcomeController < ApplicationController
|
class WelcomeController < ApplicationController
|
||||||
caches_action :robots
|
caches_action :robots
|
||||||
# before_filter :fake, :only => [:index, :course]
|
# before_filter :fake, :only => [:index, :course]
|
||||||
before_filter :entry_select_course, :entry_select_contest, :entry_select_user, :only => [:index]
|
before_filter :entry_select, :only => [:index]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
projectActive = Project.project_entities.active
|
|
||||||
@projectCount = projectActive.count
|
|
||||||
@projectPublicCount = projectActive.all_public.count
|
|
||||||
@projectHidenCount = @projectCount - @projectPublicCount
|
|
||||||
|
|
||||||
@developerCount = User.developer.count
|
|
||||||
@allUsercount = User.count
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def robots
|
def robots
|
||||||
|
@ -36,10 +30,12 @@ class WelcomeController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def course
|
def course
|
||||||
@courseCount = Project.course_entities.count
|
if params[:school_id]
|
||||||
@teacherCount = User.teacher.count
|
@school_id = params[:school_id]
|
||||||
@studentCount = User.student.count
|
elsif User.current.logged? && User.current.user_extensions.school
|
||||||
@logoLink = logolink()
|
@school_id = User.current.user_extensions.school.try(:id)
|
||||||
|
end
|
||||||
|
@logoLink ||= logolink()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -84,8 +80,7 @@ class WelcomeController < ApplicationController
|
||||||
redirect_to projects_search_path(:name => search_condition,
|
redirect_to projects_search_path(:name => search_condition,
|
||||||
:project_type => Project::ProjectType_project)
|
:project_type => Project::ProjectType_project)
|
||||||
when :courses
|
when :courses
|
||||||
redirect_to projects_search_path(:name => search_condition,
|
redirect_to courses_search_path(:name => search_condition)
|
||||||
:project_type => Project::ProjectType_course)
|
|
||||||
when :users
|
when :users
|
||||||
redirect_to users_search_path(:name => search_condition)
|
redirect_to users_search_path(:name => search_condition)
|
||||||
when :users_teacher
|
when :users_teacher
|
||||||
|
@ -93,7 +88,8 @@ class WelcomeController < ApplicationController
|
||||||
when :users_student
|
when :users_student
|
||||||
redirect_to users_search_path(:name => search_condition, :role => :student)
|
redirect_to users_search_path(:name => search_condition, :role => :student)
|
||||||
else
|
else
|
||||||
redirect_to home_path, :alert => l(:label_sumbit_empty)
|
#redirect_to home_path, :alert => l(:label_sumbit_empty)
|
||||||
|
(redirect_to home_path, :notice => l(:label_sumbit_empty);return) #if params[:name].blank?
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -101,9 +97,28 @@ class WelcomeController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def entry_select
|
||||||
|
url = request.original_url
|
||||||
|
if url.include?("course.trustie.net")
|
||||||
|
course
|
||||||
|
render :course
|
||||||
|
return 0
|
||||||
|
elsif url.include?("contest.trustie.net")
|
||||||
|
contest
|
||||||
|
render :contest
|
||||||
|
return 0
|
||||||
|
elsif url.include?("user.trustie.net")
|
||||||
|
redirect_to(:controller => "users", :action => "index")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
# 判断网站的入口,是课程 course 则跳过index去渲染 course 方法
|
# 判断网站的入口,是课程 course 则跳过index去渲染 course 方法
|
||||||
def entry_select_course
|
def entry_select_course
|
||||||
(course() and render :course and return 0) if request.original_url.match(/course\.trustie\.net/)
|
if request.original_url.match(/course\.trustie\.net/)
|
||||||
|
(course() and render :course and return 0)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def entry_select_contest
|
def entry_select_contest
|
||||||
|
@ -121,25 +136,25 @@ class WelcomeController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def render(*args)
|
# def render(*args)
|
||||||
_fake if @fake_filter
|
# _fake if @fake_filter
|
||||||
super
|
# super
|
||||||
end
|
# end
|
||||||
|
|
||||||
private
|
# private
|
||||||
|
|
||||||
def fake
|
# def fake
|
||||||
@fake_filter = true
|
# @fake_filter = true
|
||||||
end
|
# end
|
||||||
|
|
||||||
# 骗子方法
|
# # 骗子方法
|
||||||
def _fake
|
# def _fake
|
||||||
instance_variables.map { |variable|
|
# instance_variables.map { |variable|
|
||||||
if variable.to_s =~ /Count$/
|
# if variable.to_s =~ /Count$/
|
||||||
self.instance_variable_set(variable.to_sym,
|
# self.instance_variable_set(variable.to_sym,
|
||||||
("1" + (self.instance_variable_get(variable.to_sym).to_s)).to_i)
|
# ("1" + (self.instance_variable_get(variable.to_sym).to_s)).to_i)
|
||||||
end
|
# end
|
||||||
}
|
# }
|
||||||
end
|
# end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -56,7 +56,8 @@ class WordsController < ApplicationController
|
||||||
reply_user_id = params[:reference_user_id]
|
reply_user_id = params[:reference_user_id]
|
||||||
reply_id = params[:reference_message_id] # 暂时不实现
|
reply_id = params[:reference_message_id] # 暂时不实现
|
||||||
content = params[:user_notes]
|
content = params[:user_notes]
|
||||||
options = {:user_id => author_id,
|
options = {:user_id => author_id,
|
||||||
|
:status => true,
|
||||||
:m_parent_id => parent_id,
|
:m_parent_id => parent_id,
|
||||||
:m_reply_id => reply_id,
|
:m_reply_id => reply_id,
|
||||||
:reply_id => reply_user_id,
|
:reply_id => reply_user_id,
|
||||||
|
@ -163,6 +164,20 @@ class WordsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# add by nwb
|
||||||
|
def leave_course_message
|
||||||
|
user = User.current
|
||||||
|
message = params[:new_form][:course_message]
|
||||||
|
feedback = Course.add_new_jour(user, message, params[:id])
|
||||||
|
if(feedback.errors.empty?)
|
||||||
|
redirect_to course_feedback_path(params[:id]), notice: l(:label_feedback_success)
|
||||||
|
else
|
||||||
|
flash[:error] = feedback.errors.full_messages[0]
|
||||||
|
redirect_to course_feedback_path(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
def add_brief_introdution
|
def add_brief_introdution
|
||||||
user = User.current
|
user = User.current
|
||||||
|
@ -182,10 +197,14 @@ class WordsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def obj_distinguish_url_origin
|
def obj_distinguish_url_origin
|
||||||
|
#modify by nwb
|
||||||
|
#添加对课程留言的支持
|
||||||
referer = request.headers["Referer"]
|
referer = request.headers["Referer"]
|
||||||
obj_id = referer.match(%r(/([0-9]{1,})(/|$)))[1]
|
obj_id = referer.match(%r(/([0-9]{1,})(/|$)))[1]
|
||||||
if referer.match(/project/)
|
if referer.match(/project/)
|
||||||
obj = Project.find_by_id(obj_id)
|
obj = Project.find_by_id(obj_id)
|
||||||
|
elsif referer.match(/course/)
|
||||||
|
obj = Course.find_by_id(obj_id)
|
||||||
elsif referer.match(/user/)
|
elsif referer.match(/user/)
|
||||||
obj = User.find_by_id(obj_id)
|
obj = User.find_by_id(obj_id)
|
||||||
elsif ( referer.match(/bids/) || referer.match(/calls/) )
|
elsif ( referer.match(/bids/) || referer.match(/calls/) )
|
||||||
|
@ -203,11 +222,15 @@ class WordsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_reply_adapter options
|
def add_reply_adapter options
|
||||||
|
#modify by nwb
|
||||||
|
#添加对课程留言的支持
|
||||||
obj = obj_distinguish_url_origin
|
obj = obj_distinguish_url_origin
|
||||||
if obj.kind_of? User
|
if obj.kind_of? User
|
||||||
obj.add_jour(nil, nil, nil, options)
|
obj.add_jour(nil, nil, nil, options)
|
||||||
elsif obj.kind_of? Project
|
elsif obj.kind_of? Project
|
||||||
Project.add_new_jour(nil, nil, obj.id, options)
|
Project.add_new_jour(nil, nil, obj.id, options)
|
||||||
|
elsif obj.kind_of? Course
|
||||||
|
Course.add_new_jour(nil, nil, obj.id, options)
|
||||||
elsif obj.kind_of? Bid
|
elsif obj.kind_of? Bid
|
||||||
obj.add_jour(nil, nil, nil, options)
|
obj.add_jour(nil, nil, nil, options)
|
||||||
elsif obj.kind_of? Contest
|
elsif obj.kind_of? Contest
|
||||||
|
|
|
@ -1,7 +1,21 @@
|
||||||
class ZipdownController < ApplicationController
|
class ZipdownController < ApplicationController
|
||||||
|
#查找项目(课程)
|
||||||
|
before_filter :find_project_by_bid_id, :only => [:assort]
|
||||||
|
#检查权限
|
||||||
|
#勿删 before_filter :authorize, :only => [:assort,:download_user_homework]
|
||||||
SAVE_FOLDER = "#{Rails.root}/files"
|
SAVE_FOLDER = "#{Rails.root}/files"
|
||||||
OUTPUT_FOLDER = "#{Rails.root}/tmp/archiveZip"
|
OUTPUT_FOLDER = "#{Rails.root}/tmp/archiveZip"
|
||||||
|
|
||||||
|
#通过作业Id找到项目(课程)
|
||||||
|
def find_project_by_bid_id
|
||||||
|
obj_class = params[:obj_class]
|
||||||
|
obj_id = params[:obj_id]
|
||||||
|
obj = obj_class.constantize.find(obj_id)
|
||||||
|
case obj.class.to_s.to_sym
|
||||||
|
when :Bid
|
||||||
|
@project = obj.courses[0]
|
||||||
|
end
|
||||||
|
end
|
||||||
def assort
|
def assort
|
||||||
obj_class = params[:obj_class]
|
obj_class = params[:obj_class]
|
||||||
obj_id = params[:obj_id]
|
obj_id = params[:obj_id]
|
||||||
|
@ -13,15 +27,39 @@ class ZipdownController < ApplicationController
|
||||||
else
|
else
|
||||||
logger.error "[ZipDown#assort] ===> #{obj.class.to_s.to_sym} unKown !!"
|
logger.error "[ZipDown#assort] ===> #{obj.class.to_s.to_sym} unKown !!"
|
||||||
end
|
end
|
||||||
send_file zipfile, :filename => obj.name, :type => detect_content_type(zipfile) if zipfile
|
send_file zipfile, :filename => obj.name+".zip", :type => detect_content_type(zipfile) if zipfile
|
||||||
|
|
||||||
#rescue NameError, ActiveRecord::RecordNotFound => e
|
#rescue NameError, ActiveRecord::RecordNotFound => e
|
||||||
#logger.error "[ZipDown] ===> #{e}"
|
#logger.error "[ZipDown] ===> #{e}"
|
||||||
#@error = e
|
#@error = e
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#下载某一学生的作业的所有文件
|
||||||
|
def download_user_homework
|
||||||
|
homework = HomeworkAttach.find params[:homework]
|
||||||
|
if homework != nil && (User.current.admin? || User.current.member_of_course?(homework.bid.courses.first))
|
||||||
|
zipfile = zip_homework_by_user homework
|
||||||
|
send_file zipfile, :filename => homework.name+".zip", :type => detect_content_type(zipfile) if zipfile
|
||||||
|
else
|
||||||
|
render_403 :message => :notice_not_authorized
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def zip_user_bid(bid,user_id)
|
||||||
|
# Todo: User Access Controll
|
||||||
|
|
||||||
|
homeattaches = bid.homeworks.where("user_id = ?",user_id)
|
||||||
|
# 得到每一个人所有文件打包的zip文件
|
||||||
|
# 并将每一个人的zip打包为一个并返回路径
|
||||||
|
user_zip_paths = homeattaches.map do |homeattach|
|
||||||
|
zip_homework_by_user homeattach
|
||||||
|
end
|
||||||
|
#zipping "#{Time.now.to_i}_#{bid.name}.zip", user_zip_paths, OUTPUT_FOLDER
|
||||||
|
user_zip_paths
|
||||||
|
end
|
||||||
|
|
||||||
def zip_bid(bid)
|
def zip_bid(bid)
|
||||||
# Todo: User Access Controll
|
# Todo: User Access Controll
|
||||||
|
|
||||||
|
@ -50,7 +88,8 @@ class ZipdownController < ApplicationController
|
||||||
#length = attach.storage_path.length
|
#length = attach.storage_path.length
|
||||||
homeworks_attach_path << attach.diskfile#.to_s.slice((length+1)..-1)
|
homeworks_attach_path << attach.diskfile#.to_s.slice((length+1)..-1)
|
||||||
end
|
end
|
||||||
zipping "#{Time.now.to_i}_#{homeattach.user.name.to_s}.zip", homeworks_attach_path, OUTPUT_FOLDER, true
|
zipping "#{homeattach.user.name.to_s}_#{Time.now.to_i}.zip", homeworks_attach_path, OUTPUT_FOLDER, true
|
||||||
|
#user_attaches_paths
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,9 @@ module ApplicationHelper
|
||||||
# REVIEW: 目测menu的机制,貌似不是很需要转换,再说
|
# REVIEW: 目测menu的机制,貌似不是很需要转换,再说
|
||||||
def link_class(label)
|
def link_class(label)
|
||||||
labels = label.is_a?(Array) ? label : ([] << label)
|
labels = label.is_a?(Array) ? label : ([] << label)
|
||||||
|
#a = current_menu_item
|
||||||
labels.include?(current_menu_item) ? 'selected' : ''
|
labels.include?(current_menu_item) ? 'selected' : ''
|
||||||
|
|
||||||
end
|
end
|
||||||
#Ended by young
|
#Ended by young
|
||||||
# Return true if user is authorized for controller/action, otherwise false
|
# Return true if user is authorized for controller/action, otherwise false
|
||||||
|
@ -47,6 +49,15 @@ module ApplicationHelper
|
||||||
User.current.allowed_to?({:controller => controller, :action => action}, @project)
|
User.current.allowed_to?({:controller => controller, :action => action}, @project)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# add by nwb
|
||||||
|
def authorize_for_course(controller, action)
|
||||||
|
User.current.allowed_to?({:controller => controller, :action => action}, @course)
|
||||||
|
end
|
||||||
|
|
||||||
|
def authorize_for_contest(controller, action)
|
||||||
|
User.current.allowed_to?({:controller => controller, :action => action}, @contest)
|
||||||
|
end
|
||||||
|
|
||||||
# Display a link if user is authorized
|
# Display a link if user is authorized
|
||||||
#
|
#
|
||||||
# @param [String] name Anchor text (passed to link_to)
|
# @param [String] name Anchor text (passed to link_to)
|
||||||
|
@ -57,6 +68,9 @@ module ApplicationHelper
|
||||||
link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
|
link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def link_to_if_authorized_contest(name, options = {}, html_options = nil, *parameters_for_method_reference)
|
||||||
|
link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for_contest(options[:controller] || params[:controller], options[:action])
|
||||||
|
end
|
||||||
# Displays a link to user's account page if active
|
# Displays a link to user's account page if active
|
||||||
def link_to_user(user, canShowRealName = false, options={})
|
def link_to_user(user, canShowRealName = false, options={})
|
||||||
if user.is_a?(User)
|
if user.is_a?(User)
|
||||||
|
@ -170,6 +184,18 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def link_to_course(course, options={}, html_options = nil)
|
||||||
|
if course.archived?
|
||||||
|
h(course.name)
|
||||||
|
elsif options.key?(:action)
|
||||||
|
ActiveSupport::Deprecation.warn "#link_to_course with :action option is deprecated and will be removed in Redmine 3.0."
|
||||||
|
url = {:controller => 'courses', :action => 'show', :id => project}.merge(options)
|
||||||
|
link_to course.name, url, html_options
|
||||||
|
else
|
||||||
|
link_to course.name, course_path(course, options), html_options
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Generates a link to a project settings if active
|
# Generates a link to a project settings if active
|
||||||
def link_to_project_settings(project, options={}, html_options=nil)
|
def link_to_project_settings(project, options={}, html_options=nil)
|
||||||
if project.active?
|
if project.active?
|
||||||
|
@ -186,9 +212,8 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def thumbnail_tag(attachment)
|
def thumbnail_tag(attachment)
|
||||||
imagepath = named_attachment_path(attachment, attachment.filename)
|
link_to image_tag(thumbnail_path(attachment)),
|
||||||
link_to image_tag(imagepath),
|
named_attachment_path(attachment, attachment.filename),
|
||||||
imagepath ,
|
|
||||||
:title => attachment.filename
|
:title => attachment.filename
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -297,7 +322,41 @@ module ApplicationHelper
|
||||||
@project = original_project
|
@project = original_project
|
||||||
end
|
end
|
||||||
s.html_safe
|
s.html_safe
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_course_nested_lists(courses)
|
||||||
|
s = ''
|
||||||
|
if courses.any?
|
||||||
|
ancestors = []
|
||||||
|
original_course = @course
|
||||||
|
#modified by nie
|
||||||
|
courses.each do |course|
|
||||||
|
# set the project environment to please macros.
|
||||||
|
@course = course
|
||||||
|
if (ancestors.empty? )#|| course.is_descendant_of?(ancestors.last))
|
||||||
|
s << "<ul class=courses'>\n"
|
||||||
|
else
|
||||||
|
ancestors.pop
|
||||||
|
s << "</li>"
|
||||||
|
while (ancestors.any? )#&& !course.is_descendant_of?(ancestors.last))
|
||||||
|
ancestors.pop
|
||||||
|
s << "</ul></li>\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
classes = (ancestors.empty? ? 'root' : 'child')
|
||||||
|
s << "<li class='project-table'><div class='#{classes}'>"
|
||||||
|
|
||||||
|
s << (render :partial => 'courses/course', :locals => {:course => course}).to_s
|
||||||
|
s << "</div>\n"
|
||||||
|
ancestors << course
|
||||||
|
end
|
||||||
|
s << ("</li></ul>\n" * ancestors.size)
|
||||||
|
@course = original_course
|
||||||
|
end
|
||||||
|
s.html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
#added by young
|
#added by young
|
||||||
def render_project_nested_lists_new(projects)
|
def render_project_nested_lists_new(projects)
|
||||||
s = ''
|
s = ''
|
||||||
|
@ -414,7 +473,11 @@ module ApplicationHelper
|
||||||
def principals_check_box_tags_ex(name, principals)
|
def principals_check_box_tags_ex(name, principals)
|
||||||
s = ''
|
s = ''
|
||||||
principals.each do |principal|
|
principals.each do |principal|
|
||||||
s << "<label>#{ check_box_tag name, principal.id, false, :id => nil } #{h principal.userInfo }</label>\n"
|
if principal.has_attribute?(:userInfo)
|
||||||
|
s << "<label>#{ check_box_tag name, principal.id, false, :id => nil } #{h principal.userInfo }</label>\n"
|
||||||
|
else
|
||||||
|
s << "<label>#{ check_box_tag name, principal.id, false, :id => nil } #{h principal}</label>\n"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
s.html_safe
|
s.html_safe
|
||||||
end
|
end
|
||||||
|
@ -1639,9 +1702,9 @@ module ApplicationHelper
|
||||||
main_project_link = link_to l(:label_project_deposit), {:controller => 'welcome', :action => 'index', :host => Setting.project_domain}
|
main_project_link = link_to l(:label_project_deposit), {:controller => 'welcome', :action => 'index', :host => Setting.project_domain}
|
||||||
main_contest_link = link_to l(:label_contest_innovate), {:controller => 'welcome', :action => 'index', :host => Setting.contest_domain}
|
main_contest_link = link_to l(:label_contest_innovate), {:controller => 'welcome', :action => 'index', :host => Setting.contest_domain}
|
||||||
|
|
||||||
course_all_course_link = link_to l(:label_course_all), {:controller => 'projects', :action => 'course', :project_type => 1, :host => Setting.course_domain}
|
course_all_course_link = link_to l(:label_course_all), {:controller => 'courses', :action => 'index'}
|
||||||
course_teacher_all_link = link_to l(:label_teacher_all), {:controller => 'users', :action => 'index', :role => 'teacher', :host => Setting.course_domain}
|
course_teacher_all_link = link_to l(:label_teacher_all), {:controller => 'users', :action => 'index', :role => 'teacher', :host => Setting.course_domain}
|
||||||
courses_link = link_to l(:label_course_practice), {:controller => 'projects', :action => 'course', :project_type => 1, :host => Setting.course_domain}
|
courses_link = link_to l(:label_course_practice), {:controller => 'courses', :action => 'index'}
|
||||||
projects_link = link_to l(:label_project_deposit), {:controller => 'projects', :action => 'index', :project_type => 0, :host => Setting.project_domain}
|
projects_link = link_to l(:label_project_deposit), {:controller => 'projects', :action => 'index', :project_type => 0, :host => Setting.project_domain}
|
||||||
users_link = link_to l(:label_software_user), {:controller => 'users', :action => 'index', :host => Setting.user_domain}
|
users_link = link_to l(:label_software_user), {:controller => 'users', :action => 'index', :host => Setting.user_domain}
|
||||||
contest_link = link_to l(:label_contest_innovate), {:controller => 'contests', :action => 'index'}
|
contest_link = link_to l(:label_contest_innovate), {:controller => 'contests', :action => 'index'}
|
||||||
|
|
|
@ -115,7 +115,7 @@ module AttachmentsHelper
|
||||||
|
|
||||||
s = content_tag('div', attachments_check_box_tags('attachment[attach][]', searched_attach), :id => 'attachments')
|
s = content_tag('div', attachments_check_box_tags('attachment[attach][]', searched_attach), :id => 'attachments')
|
||||||
links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false) {|text, parameters, options|
|
links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false) {|text, parameters, options|
|
||||||
link_to text, attachments_autocomplete_path( parameters.merge(:q => params[:q], :format => 'js')), :remote => true }
|
link_to text, attachments_autocomplete_path( parameters.merge(:project_id=>project.id,:q => params[:q], :format => 'js')), :remote => true }
|
||||||
|
|
||||||
return s + content_tag('div', content_tag('ul', links), :class => 'pagination')
|
return s + content_tag('div', content_tag('ul', links), :class => 'pagination')
|
||||||
|
|
||||||
|
@ -133,6 +133,35 @@ module AttachmentsHelper
|
||||||
# return searched_attach.to_json
|
# return searched_attach.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# add by nwb
|
||||||
|
def render_attachments_for_new_course(course, limit=nil)
|
||||||
|
# 查询条件
|
||||||
|
params[:q] ||= ""
|
||||||
|
filename_condition = params[:q].strip
|
||||||
|
|
||||||
|
attachAll = Attachment.scoped
|
||||||
|
|
||||||
|
# 除去当前课程的所有资源
|
||||||
|
nobelong_attach = Attachment.where("!(container_type = '#{course.class}' and container_id = #{course.id})") unless course.blank?
|
||||||
|
|
||||||
|
# 搜索域确定
|
||||||
|
domain = course.nil? ? attachAll : nobelong_attach
|
||||||
|
|
||||||
|
# 搜索到的资源
|
||||||
|
searched_attach = domain.where("filename LIKE :like ", like:"%#{filename_condition}%").limit(limit).order('created_on desc')
|
||||||
|
searched_attach = private_filter searched_attach
|
||||||
|
searched_attach = paginateHelper(searched_attach, 10)
|
||||||
|
|
||||||
|
#testattach = Attachment.public_attachments
|
||||||
|
|
||||||
|
s = content_tag('div', attachments_check_box_tags('attachment[attach][]', searched_attach), :id => 'attachments')
|
||||||
|
links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false) {|text, parameters, options|
|
||||||
|
link_to text, attachments_autocomplete_path( parameters.merge(:course_id=>course.id,:q => params[:q], :format => 'js')), :remote => true }
|
||||||
|
|
||||||
|
return s + content_tag('div', content_tag('ul', links), :class => 'pagination')
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
def attachments_check_box_tags(name, attachs)
|
def attachments_check_box_tags(name, attachs)
|
||||||
s = ''
|
s = ''
|
||||||
attachs.each do |attach|
|
attachs.each do |attach|
|
||||||
|
@ -144,18 +173,22 @@ module AttachmentsHelper
|
||||||
def private_filter resultSet
|
def private_filter resultSet
|
||||||
result = resultSet.to_a.dup
|
result = resultSet.to_a.dup
|
||||||
|
|
||||||
|
# modify by nwb
|
||||||
|
#添加对课程资源文件的判断
|
||||||
resultSet.map { |res|
|
resultSet.map { |res|
|
||||||
if(res.container.nil? ||
|
if(res.container.nil? ||
|
||||||
(res.container.class.to_s=="Project" && res.container.is_public == false) ||
|
(res.container.class.to_s=="Project" && res.container.is_public == false) ||
|
||||||
(res.container.has_attribute?(:project) && res.container.project.is_public == false) ||
|
(res.container.has_attribute?(:project) && res.container.project && res.container.project.is_public == false) ||
|
||||||
(res.container.class.to_s=="HomeworkAttach" && res.container.bid.reward_type == 3) ||
|
(res.container.class.to_s=="HomeworkAttach" && res.container.bid.reward_type == 3) ||
|
||||||
false
|
(res.container.class.to_s=="Course" && res.container.is_public == false) ||
|
||||||
|
(res.container.has_attribute?(:course) && res.container.course && res.container.course.is_public == false)
|
||||||
)
|
)
|
||||||
result.delete(res)
|
result.delete(res)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
include Redmine::Pagination
|
include Redmine::Pagination
|
||||||
def paginateHelper obj, pre_size=10
|
def paginateHelper obj, pre_size=10
|
||||||
@obj_count = obj.count
|
@obj_count = obj.count
|
||||||
|
|
|
@ -42,7 +42,7 @@ module AvatarHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_avatar?(source)
|
def get_avatar?(source)
|
||||||
if File.exist?(disk_filename(source.class,source.id))
|
if source && File.exist?(disk_filename(source.class,source.id))
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -155,16 +155,6 @@ module BidsHelper
|
||||||
end
|
end
|
||||||
people.include?(User.current)
|
people.include?(User.current)
|
||||||
end
|
end
|
||||||
#当前用户是不是指定课程的学生
|
|
||||||
def is_cur_course_student? course
|
|
||||||
people = []
|
|
||||||
course.members.each do |member|
|
|
||||||
if [5,10].include? member.roles.first.id
|
|
||||||
people << member.user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
people.include?(User.current)
|
|
||||||
end
|
|
||||||
|
|
||||||
# def select_option_helper option
|
# def select_option_helper option
|
||||||
# tmp = Hash.new
|
# tmp = Hash.new
|
||||||
|
|
|
@ -29,6 +29,19 @@ module BoardsHelper
|
||||||
breadcrumb links
|
breadcrumb links
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# add by nwb
|
||||||
|
def course_board_breadcrumb(item)
|
||||||
|
board = item.is_a?(Message) ? item.board : item
|
||||||
|
links = [link_to(l(:label_board_plural), course_boards_path(item.course))]
|
||||||
|
boards = board.ancestors.reverse
|
||||||
|
if item.is_a?(Message)
|
||||||
|
boards << board
|
||||||
|
end
|
||||||
|
links += boards.map {|ancestor| link_to(h(ancestor.name), course_board_path(ancestor.course, ancestor))}
|
||||||
|
breadcrumb links
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def boards_options_for_select(boards)
|
def boards_options_for_select(boards)
|
||||||
options = []
|
options = []
|
||||||
Board.board_tree(boards) do |board, level|
|
Board.board_tree(boards) do |board, level|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
module ContestnotificationsHelper
|
||||||
|
end
|
|
@ -55,8 +55,9 @@ module ContestsHelper
|
||||||
content_tag('div', content, :class => "tabs_enterprise")
|
content_tag('div', content, :class => "tabs_enterprise")
|
||||||
end
|
end
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#huang
|
#huang
|
||||||
def sort_contest(state)
|
def sort_contest(state)
|
||||||
content = ''.html_safe
|
content = ''.html_safe
|
||||||
|
|
|
@ -31,6 +31,39 @@ module CoursesHelper
|
||||||
# searchStudent(project).count
|
# searchStudent(project).count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 判断用户是否是课程的管理员
|
||||||
|
# add by nwb
|
||||||
|
def is_course_manager?(user_id,course_id)
|
||||||
|
@result = false
|
||||||
|
@user_id = CourseInfo.find_by_course_id(course_id)
|
||||||
|
if @user_id == user.id
|
||||||
|
@result = true
|
||||||
|
end
|
||||||
|
return @result
|
||||||
|
end
|
||||||
|
|
||||||
|
# 返回课程设置界面
|
||||||
|
def course_settings_tabs
|
||||||
|
tabs = [{:name => 'info', :action => :edit_course, :partial => 'courses/edit', :label => :label_information_plural},
|
||||||
|
{:name => 'members', :action => :manage_members, :partial => 'courses/settings/members', :label => :label_member_plural}
|
||||||
|
]
|
||||||
|
tabs.select { |tab| User.current.allowed_to?(tab[:action], @course) }
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
#是否启动互评下拉框
|
||||||
|
def is_evaluation_option
|
||||||
|
type = []
|
||||||
|
option1 = []
|
||||||
|
option2 = []
|
||||||
|
option1 << l(:lable_start_mutual_evaluation)
|
||||||
|
option1 << 1
|
||||||
|
option2 << l(:lable_close_mutual_evaluation)
|
||||||
|
option2 << 2
|
||||||
|
type << option1
|
||||||
|
type << option2
|
||||||
|
end
|
||||||
|
|
||||||
# garble count 混淆数量
|
# garble count 混淆数量
|
||||||
# alias projectCountOrigin projectCount
|
# alias projectCountOrigin projectCount
|
||||||
# def projectCount project
|
# def projectCount project
|
||||||
|
@ -38,6 +71,32 @@ module CoursesHelper
|
||||||
# garble count
|
# garble count
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
def homework_type_option
|
||||||
|
type = []
|
||||||
|
option1 = []
|
||||||
|
option2 = []
|
||||||
|
option1 << l(:label_task_submit_form_accessory)
|
||||||
|
option1 << 1
|
||||||
|
option2 << l(:label_task_submit_form_project)
|
||||||
|
option2 << 2
|
||||||
|
type << option1
|
||||||
|
type << option2
|
||||||
|
end
|
||||||
|
|
||||||
|
def proportion_option
|
||||||
|
type = []
|
||||||
|
i = 0
|
||||||
|
while i <= 100
|
||||||
|
option = []
|
||||||
|
option << i.to_s + "%"
|
||||||
|
option << i
|
||||||
|
type << option
|
||||||
|
i = i + 10
|
||||||
|
end
|
||||||
|
type
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
alias teacherCountOrigin teacherCount
|
alias teacherCountOrigin teacherCount
|
||||||
def teacherCount project
|
def teacherCount project
|
||||||
count = teacherCountOrigin project
|
count = teacherCountOrigin project
|
||||||
|
@ -45,11 +104,26 @@ module CoursesHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
alias studentCountOrigin studentCount
|
alias studentCountOrigin studentCount
|
||||||
def studentCount project
|
def studentCount course
|
||||||
count = studentCountOrigin project
|
count = studentCountOrigin course
|
||||||
garble count
|
garble count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def eventToLanguageCourse event_type, course
|
||||||
|
case event_type
|
||||||
|
when "issue-note"
|
||||||
|
l :label_issue
|
||||||
|
when "issue"
|
||||||
|
l :label_issue
|
||||||
|
when "attachment"
|
||||||
|
l :label_attachment
|
||||||
|
when "news"
|
||||||
|
l :label_notification
|
||||||
|
else
|
||||||
|
""
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def garble count
|
def garble count
|
||||||
count = count.round( 1-count.to_s.size ).to_i
|
count = count.round( 1-count.to_s.size ).to_i
|
||||||
return count.to_s if count.to_s.size.eql?(1)
|
return count.to_s if count.to_s.size.eql?(1)
|
||||||
|
@ -82,6 +156,35 @@ module CoursesHelper
|
||||||
members
|
members
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sort_courses(state)
|
||||||
|
content = ''.html_safe
|
||||||
|
case state
|
||||||
|
when 0
|
||||||
|
|
||||||
|
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:courses_sort_type => '1')))
|
||||||
|
content << content_tag('li', link_to(l(:label_sort_by_influence), courses_path(:courses_sort_type => '2')))
|
||||||
|
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:courses_sort_type => '0'), :class=>"selected"), :class=>"selected")
|
||||||
|
when 1
|
||||||
|
|
||||||
|
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:courses_sort_type => '1'), :class=>"selected"), :class=>"selected")
|
||||||
|
content << content_tag('li', link_to(l(:label_sort_by_influence), courses_path(:courses_sort_type => '2')))
|
||||||
|
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:courses_sort_type => '0')))
|
||||||
|
when 2
|
||||||
|
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:courses_sort_type => '1')))
|
||||||
|
content << content_tag('li', link_to(l(:label_sort_by_influence), courses_path(:courses_sort_type => '2'), :class=>"selected"), :class=>"selected")
|
||||||
|
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:courses_sort_type => '0')))
|
||||||
|
end
|
||||||
|
content = content_tag('ul', content)
|
||||||
|
content_tag('div', content, :class => "tabs")
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_course_hierarchy(courses)
|
||||||
|
render_course_nested_lists(courses) do |course|
|
||||||
|
s = link_to_course(course, {}, :class => "#{course.css_classes} #{User.current.member_of?(course) ? 'my-course' : nil}").html_safe
|
||||||
|
s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
#useless
|
#useless
|
||||||
def searchMembersByRole project, role_id
|
def searchMembersByRole project, role_id
|
||||||
members = []
|
members = []
|
||||||
|
@ -93,6 +196,36 @@ module CoursesHelper
|
||||||
members
|
members
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sort_course(state, school_id)
|
||||||
|
content = ''.html_safe
|
||||||
|
case state
|
||||||
|
when 0
|
||||||
|
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0'), :school_id => school_id, :class=>"selected"), :class=>"selected")
|
||||||
|
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id)))
|
||||||
|
content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id)))
|
||||||
|
|
||||||
|
when 1
|
||||||
|
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0', :school_id => school_id)))
|
||||||
|
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id), :class=>"selected"), :class=>"selected")
|
||||||
|
content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id)))
|
||||||
|
|
||||||
|
when 2
|
||||||
|
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0', :school_id => school_id)))
|
||||||
|
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id)))
|
||||||
|
content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id)))
|
||||||
|
|
||||||
|
#gcm
|
||||||
|
when 3
|
||||||
|
content << content_tag('li', link_to(l(:label_sort_by_time), courses_path(:course_sort_type => '0', :school_id => school_id)))
|
||||||
|
content << content_tag('li', link_to(l(:label_sort_by_active), courses_path(:course_sort_type => '1', :school_id => school_id)))
|
||||||
|
content << content_tag('li', link_to(l(:label_sort_by_activity), courses_path(:course_sort_type => '3', :school_id => school_id), :class=>"selected"), :class=>"selected")
|
||||||
|
end
|
||||||
|
#gcmend
|
||||||
|
|
||||||
|
content = content_tag('ul', content)
|
||||||
|
content_tag('div', content, :class => "tabs")
|
||||||
|
end
|
||||||
|
|
||||||
def findCourseTime project
|
def findCourseTime project
|
||||||
str = ""
|
str = ""
|
||||||
begin
|
begin
|
||||||
|
@ -109,8 +242,9 @@ module CoursesHelper
|
||||||
str
|
str
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_course_term project
|
# added by nwb
|
||||||
str = ( project.try(:course_extra).try(:time).to_s << '.' << project.try(:course_extra).try(:term).to_s )
|
def get_course_term course
|
||||||
|
str = ( course.try(:time).to_s << '.' << course.try(:term).to_s )
|
||||||
str[0..-4]
|
str[0..-4]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -122,8 +256,8 @@ module CoursesHelper
|
||||||
people
|
people
|
||||||
end
|
end
|
||||||
# 截至到2014-03-17 这个是最终的判断课程是否过期的方法
|
# 截至到2014-03-17 这个是最终的判断课程是否过期的方法
|
||||||
def course_endTime_timeout? project
|
def course_endTime_timeout? course
|
||||||
end_time_str = Course.find_by_extra(project.try(:identifier)).try(:endup_time)
|
end_time_str = course.try(:endup_time)
|
||||||
begin
|
begin
|
||||||
cTime = Time.parse(end_time_str.to_s)
|
cTime = Time.parse(end_time_str.to_s)
|
||||||
rescue TypeError,ArgumentError
|
rescue TypeError,ArgumentError
|
||||||
|
@ -137,24 +271,121 @@ module CoursesHelper
|
||||||
Course.find_by_extra(try(extra))
|
Course.find_by_extra(try(extra))
|
||||||
end
|
end
|
||||||
#判断制定用户是不是当前课程的老师
|
#判断制定用户是不是当前课程的老师
|
||||||
def is_course_teacher user,course
|
def is_course_teacher (user,course)
|
||||||
people = []
|
course.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and members.user_id = #{user.id}", {:role_id => TeacherRoles}).count != 0
|
||||||
course.members.each do |member|
|
#修改为根据用户是否有发布任务的权限来判断用户是否是课程的老师
|
||||||
role_id = member.roles.first.id
|
#is_teacher = false
|
||||||
if TeacherRoles.include? role_id
|
#@membership = user.memberships.all(:conditions => Project.visible_condition(User.current))
|
||||||
people << member.user
|
#@membership.each do |membership|
|
||||||
end
|
# unless(membership.project.project_type==0)
|
||||||
end
|
# if user.allowed_to?({:controller => "projects", :action => "new_homework"}, membership.project, :global => false)
|
||||||
people.include?(user)
|
# is_teacher = true
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
#end
|
||||||
|
#is_teacher
|
||||||
end
|
end
|
||||||
#当前用户是不是指定课程的学生
|
#当前用户是不是指定课程的学生
|
||||||
def is_cur_course_student? course
|
def is_cur_course_student course
|
||||||
people = []
|
course.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and members.user_id = #{User.current.id}", {:role_id => StudentRoles}).count != 0
|
||||||
course.members.each do |member|
|
#修改:能新建占位且不能新建任务的角色判定为学生
|
||||||
if StudentRoles.include? member.roles.first.id
|
#is_student = false
|
||||||
people << member.user
|
#@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
|
||||||
|
#@membership.each do |membership|
|
||||||
|
# unless(membership.project.project_type==0)
|
||||||
|
# if !User.current.allowed_to?({:controller => "projects", :action => "new_homework"}, membership.project, :global => false) && User.current.allowed_to?({:controller => "homework_attach", :action => "new"}, membership.project, :global => false)
|
||||||
|
# is_student = true
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
#end
|
||||||
|
#is_student
|
||||||
|
end
|
||||||
|
#获取当前用户在指定作业下提交的作业的集合
|
||||||
|
def cur_user_homework_for_bid bid
|
||||||
|
cur_user_homework = HomeworkAttach.where("user_id = ? and bid_id = ?",User.current,bid.id)
|
||||||
|
cur_user_homework
|
||||||
|
end
|
||||||
|
|
||||||
|
#判断当前用户对指定作业是否已经评价过
|
||||||
|
def has_evaluation? homework
|
||||||
|
seem_count = homework.rates(:quality).where("rater_id = ?",User.current).count
|
||||||
|
seem_count > 0
|
||||||
|
end
|
||||||
|
|
||||||
|
#获取指定作业的所有成员
|
||||||
|
def users_for_homework homework
|
||||||
|
homework.nil? ? [] : (homework.users + [homework.user])
|
||||||
|
end
|
||||||
|
|
||||||
|
#获取指定作业的最终评分
|
||||||
|
#最终评分 = 学生评分的平均分 * 0.4 +教师评分 * 0.6
|
||||||
|
def score_for_homework homework
|
||||||
|
if homework.bid.is_evaluation == 1 || homework.bid.is_evaluation == nil
|
||||||
|
return format("%.2f",(homework.bid.proportion * 1.0 / 100) * (teacher_score_for_homework(homework).to_f) + (1 - homework.bid.proportion * 1.0 / 100) * (student_score_for_homework(homework).to_f))
|
||||||
|
else
|
||||||
|
return teacher_score_for_homework homework
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
#获取作业的互评得分
|
||||||
|
def student_score_for_homework homework
|
||||||
|
member = searchPeopleByRoles(homework.bid.courses.first,TeacherRoles).first
|
||||||
|
student_stars = homework.rates(:quality).where("rater_id <> #{member.user_id}").select("stars")
|
||||||
|
student_stars_count = 0
|
||||||
|
student_stars.each do |star|
|
||||||
|
student_stars_count = student_stars_count + star.stars
|
||||||
|
end
|
||||||
|
return format("%.2f",student_stars_count / (student_stars.count == 0 ? 1 : student_stars.count))
|
||||||
|
end
|
||||||
|
|
||||||
|
#获取作业的教师评分
|
||||||
|
def teacher_score_for_homework homework
|
||||||
|
member = searchPeopleByRoles(homework.bid.courses.first,TeacherRoles).first
|
||||||
|
teacher_stars = homework.rates(:quality).where("rater_id = #{member.user_id}").select("stars").first
|
||||||
|
return format("%.2f",teacher_stars == nil ? 0 : teacher_stars.stars)
|
||||||
|
end
|
||||||
|
|
||||||
|
#获取指定项目的得分
|
||||||
|
def project_score project
|
||||||
|
issue_count = project.issues.count
|
||||||
|
issue_journal_count = project.issue_changes.count
|
||||||
|
issue_score = issue_count * 0.2
|
||||||
|
issue_journal_score = issue_journal_count * 0.1
|
||||||
|
finall_issue_score = issue_score + issue_journal_score
|
||||||
|
new_count = project.news.count
|
||||||
|
new_score = new_count * 0.1
|
||||||
|
finall_new_score = new_score
|
||||||
|
document_count = project.documents.count
|
||||||
|
file_score = document_count * 0.1
|
||||||
|
finall_file_score = file_score
|
||||||
|
changeset_count = project.changesets.count
|
||||||
|
code_submit_score = changeset_count * 0.3
|
||||||
|
finall_code_submit_score = code_submit_score
|
||||||
|
board_message_count = 0
|
||||||
|
project.boards.each do |board|
|
||||||
|
board_message_count += board.messages_count
|
||||||
|
end
|
||||||
|
topic_score = board_message_count * 0.1
|
||||||
|
#finall_topic_score = topic_score
|
||||||
|
finall_project_score = finall_issue_score + finall_new_score + finall_file_score + finall_code_submit_score + topic_score
|
||||||
|
format("%.2f",finall_project_score)
|
||||||
|
end
|
||||||
|
|
||||||
|
#获取指定作业的参与人员
|
||||||
|
#返回结果:张三、李四、王五
|
||||||
|
def homework_user_of_homework homework,is_teacher
|
||||||
|
homework_users = ""
|
||||||
|
homework.users.each do |user|
|
||||||
|
homework_users = homework_users + (is_teacher ? user.realname : user.name)
|
||||||
|
if user != homework.users.last
|
||||||
|
homework_users = homework_users + "、"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
people.include?(User.current)
|
return homework_users
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_courses_by_tag(tag_name)
|
||||||
|
Course.tagged_with(tag_name).order('updated_at desc')
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
module HomeworkAttachHelper
|
||||||
|
#判断是否具有删除的权限
|
||||||
|
def attach_delete(project)
|
||||||
|
if User.current.logged? && (User.current.admin? || (!Member.where('user_id = ? and project_id = ?', User.current.id, project.bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, project.bid.courses.first.id).first.roles&Role.where('id = ? or id = ?', 3, 7)).size >0) || project.user_id == User.current.id)
|
||||||
|
true
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
#作业添加、编辑界面的tab页
|
||||||
|
def homework_settings_tabs f
|
||||||
|
@f = f
|
||||||
|
tabs = [{:name => 'info', :partial => 'homework_attach/edit_homework', :label => :label_information_plural},
|
||||||
|
{:name => 'members', :partial => 'homework_attach/homework_member', :label => :label_member_plural}
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
#作业可选成员列表分页
|
||||||
|
def render_new_members_for_homework members
|
||||||
|
#scope = Principal.active.sorted.not_member_of(project).like(params[:q])
|
||||||
|
#scope = project.members
|
||||||
|
#principals = paginateHelper members,10
|
||||||
|
#principals = members
|
||||||
|
#principal_count = members.count
|
||||||
|
#limit = 10
|
||||||
|
#principal_pages = Redmine::Pagination::Paginator.new principal_count, limit, params['page'] #by young
|
||||||
|
#offset ||= principal_pages.offset
|
||||||
|
#principals = members[offset, limit]
|
||||||
|
users = members.map(&:user)
|
||||||
|
s = content_tag('div', member_check_box_tags_ex('membership[user_ids][]', users), :id => 'principals')
|
||||||
|
links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false) {|text, parameters, options|
|
||||||
|
link_to text, get_homework_member_list_homework_attach_index_path( parameters.merge(:q => params[:q], bid_id: params[:id]||@homework)), :remote => true }
|
||||||
|
return s + content_tag('div', content_tag('ul', links), :class => 'pagination_new')
|
||||||
|
end
|
||||||
|
|
||||||
|
#扩展的checkbox生成
|
||||||
|
def member_check_box_tags_ex(name, principals)
|
||||||
|
s = ''
|
||||||
|
principals.each do |member|
|
||||||
|
s << "<label>#{ check_box_tag name, member.id, false, :id => nil } #{h member.name }</label><br/>"
|
||||||
|
end
|
||||||
|
s.html_safe
|
||||||
|
end
|
||||||
|
|
||||||
|
def paginateHelper obj, pre_size=20
|
||||||
|
@obj_count = obj.count
|
||||||
|
@obj_pages = Redmine::Pagination::Paginator.new @obj_count, pre_size, params['page']
|
||||||
|
if obj.kind_of? ActiveRecord::Base or obj.kind_of? ActiveRecord::Relation
|
||||||
|
obj.limit(@obj_pages.per_page).offset(@obj_pages.offset)
|
||||||
|
elsif obj.kind_of? Array
|
||||||
|
obj[@obj_pages.offset, @obj_pages.per_page]
|
||||||
|
else
|
||||||
|
logger.error "[ApplicationController] Error : application_controller#paginateHelper ===> unknow category: #{obj.class}"
|
||||||
|
raise RuntimeError, 'unknow type, Please input you type into this helper.'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def user_projects_option
|
||||||
|
cond = Project.visible_condition(User.current) + " AND projects.project_type <> 1"
|
||||||
|
memberships = User.current.memberships.all(:conditions => cond)
|
||||||
|
projects = memberships.map(&:project)
|
||||||
|
not_have_project = []
|
||||||
|
not_have_project << "<<NULL>>"
|
||||||
|
not_have_project << 0
|
||||||
|
type = []
|
||||||
|
type << not_have_project
|
||||||
|
projects.each do |project|
|
||||||
|
if project != nil
|
||||||
|
option = []
|
||||||
|
option << project.name
|
||||||
|
option << project.id
|
||||||
|
type << option
|
||||||
|
end
|
||||||
|
end
|
||||||
|
type
|
||||||
|
end
|
||||||
|
end
|
|
@ -18,7 +18,7 @@
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
module JournalsHelper
|
module JournalsHelper
|
||||||
def render_notes(issue, journal, options={})
|
def render_links(issue, journal, options={})
|
||||||
content = ''
|
content = ''
|
||||||
editable = User.current.logged? && (User.current.allowed_to?(:edit_issue_notes, issue.project) || (journal.user == User.current && User.current.allowed_to?(:edit_own_issue_notes, issue.project)))
|
editable = User.current.logged? && (User.current.allowed_to?(:edit_issue_notes, issue.project) || (journal.user == User.current && User.current.allowed_to?(:edit_own_issue_notes, issue.project)))
|
||||||
destroyable = User.current.logged? && ((journal.user == User.current) || (issue.author_id == User.current.id) || (User.current.admin == 1))
|
destroyable = User.current.logged? && ((journal.user == User.current) || (issue.author_id == User.current.id) || (User.current.admin == 1))
|
||||||
|
@ -38,11 +38,39 @@ module JournalsHelper
|
||||||
:title => l(:button_delete))
|
:title => l(:button_delete))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
content << content_tag('div', links.join(' ').html_safe, :class => 'contextual', :style => 'margin-top:-25px;') unless links.empty?
|
content << content_tag('div', links.join(' ').html_safe, :class => 'contextual') unless links.empty?
|
||||||
|
#content << textilizable(journal, :notes)
|
||||||
|
#css_classes = "wiki"
|
||||||
|
#css_classes << " editable" if editable
|
||||||
|
#content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes)
|
||||||
|
content.html_safe
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_notes (issue, journal, options={})
|
||||||
|
content = ''
|
||||||
|
editable = User.current.logged? && (User.current.allowed_to?(:edit_issue_notes, issue.project) || (journal.user == User.current && User.current.allowed_to?(:edit_own_issue_notes, issue.project)))
|
||||||
|
destroyable = User.current.logged? && ((journal.user == User.current) || (issue.author_id == User.current.id) || (User.current.admin == 1))
|
||||||
|
links = []
|
||||||
|
if !journal.notes.blank?
|
||||||
|
links << link_to(l(:button_quote),
|
||||||
|
{:controller => 'journals', :action => 'new', :id => issue.id, :journal_id => journal},
|
||||||
|
:remote => true,
|
||||||
|
:method => 'post',
|
||||||
|
:title => l(:button_quote)) if options[:reply_links]
|
||||||
|
links << link_to_in_place_notes_editor(l(:button_edit), "journal-#{journal.id}-notes",
|
||||||
|
{ :controller => 'journals', :action => 'edit', :id => journal, :format => 'js' },
|
||||||
|
:title => l(:button_edit)) if editable
|
||||||
|
#Added by young
|
||||||
|
if destroyable
|
||||||
|
links << link_to(l(:button_delete), { :controller => 'journals', :action => 'destroy', :id => journal, :format => 'js' },
|
||||||
|
:title => l(:button_delete))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
#content << content_tag('div', links.join(' ').html_safe, :class => 'contextual', :style => 'margin-top:-25px;') unless links.empty?
|
||||||
content << textilizable(journal, :notes)
|
content << textilizable(journal, :notes)
|
||||||
css_classes = "wiki"
|
css_classes = "wiki"
|
||||||
css_classes << " editable" if editable
|
css_classes << " editable" if editable
|
||||||
content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes)
|
content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes ,:style => "width:580px")
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_to_in_place_notes_editor(text, field_id, url, options={})
|
def link_to_in_place_notes_editor(text, field_id, url, options={})
|
||||||
|
|
|
@ -33,10 +33,28 @@ module MembersHelper
|
||||||
s + content_tag('div', content_tag('ul', links), :class => 'pagination_new')
|
s + content_tag('div', content_tag('ul', links), :class => 'pagination_new')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# add by nwb
|
||||||
|
# 课程可添加的成员列表
|
||||||
|
def render_principals_for_new_course_members(course)
|
||||||
|
scope = Principal.active.sorted.not_member_of_course(course).like(params[:q])
|
||||||
|
principal_count = scope.count
|
||||||
|
principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page']
|
||||||
|
principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all
|
||||||
|
|
||||||
|
s = content_tag('div', principals_check_box_tags_ex('membership[user_ids][]', principals), :id => 'principals')
|
||||||
|
|
||||||
|
links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options|
|
||||||
|
link_to text, autocomplete_course_memberships_path(course, parameters.merge(:q => params[:q], :format => 'js')), :remote => true
|
||||||
|
}
|
||||||
|
|
||||||
|
s + content_tag('div', content_tag('ul', links), :class => 'pagination_new')
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# 当前申请加入的成员名单
|
# 当前申请加入的成员名单
|
||||||
def render_principals_for_applied_members(project)
|
def render_principals_for_applied_members(project)
|
||||||
scope = Principal.active.sorted.applied_members(project).like(params[:q])
|
scope = Principal.active.sorted.applied_members(project).like(params[:q])
|
||||||
principal_count = scope.count
|
principal_count = scope.count
|
||||||
principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page']
|
principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page']
|
||||||
principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all
|
principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
module NotificationcommentsHelper
|
||||||
|
end
|
|
@ -150,7 +150,6 @@ module ProjectsHelper
|
||||||
{:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural}
|
{:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural}
|
||||||
]
|
]
|
||||||
tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
|
tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
|
||||||
|
|
||||||
end
|
end
|
||||||
#Ended by young
|
#Ended by young
|
||||||
|
|
||||||
|
@ -227,6 +226,19 @@ module ProjectsHelper
|
||||||
type << option2
|
type << option2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#是否启动互评下拉框
|
||||||
|
def is_evaluation_option
|
||||||
|
type = []
|
||||||
|
option1 = []
|
||||||
|
option2 = []
|
||||||
|
option1 << l(:lable_start_mutual_evaluation)
|
||||||
|
option1 << 1
|
||||||
|
option2 << l(:lable_close_mutual_evaluation)
|
||||||
|
option2 << 2
|
||||||
|
type << option1
|
||||||
|
type << option2
|
||||||
|
end
|
||||||
|
|
||||||
# 用来判断用户是否是项目的管理员
|
# 用来判断用户是否是项目的管理员
|
||||||
# added by william
|
# added by william
|
||||||
def is_manager?(user_id,project_id)
|
def is_manager?(user_id,project_id)
|
||||||
|
|
|
@ -4,11 +4,15 @@ def options_from_select_project(user)
|
||||||
@option = []
|
@option = []
|
||||||
@membership.each do |membership|
|
@membership.each do |membership|
|
||||||
unless(membership.project.project_type==1)
|
unless(membership.project.project_type==1)
|
||||||
membership.member_roles.each{|role|
|
#membership.member_roles.each{|role|
|
||||||
if(role.role_id == 3)
|
# if(role.role_id == 3)
|
||||||
|
# @option << membership.project
|
||||||
|
# end
|
||||||
|
#}
|
||||||
|
#拥有编辑项目权限的可操作该项目
|
||||||
|
if user.allowed_to?({:controller => "projects", :action => "edit"}, membership.project, :global => false)
|
||||||
@option << membership.project
|
@option << membership.project
|
||||||
end
|
end
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
options_for_select(@option)
|
options_for_select(@option)
|
||||||
|
|
|
@ -16,6 +16,8 @@ module TagsHelper
|
||||||
@obj = Attachment.find_by_id(obj_id)
|
@obj = Attachment.find_by_id(obj_id)
|
||||||
when '7'
|
when '7'
|
||||||
@obj= Contest.find_by_id(obj_id)
|
@obj= Contest.find_by_id(obj_id)
|
||||||
|
when '9'
|
||||||
|
@obj= Course.find_by_id(obj_id)
|
||||||
else
|
else
|
||||||
raise Exception, '[TagsHelper] ===> tag type unknow.'
|
raise Exception, '[TagsHelper] ===> tag type unknow.'
|
||||||
end
|
end
|
||||||
|
@ -46,6 +48,8 @@ module TagsHelper
|
||||||
if user.id == obj_id
|
if user.id == obj_id
|
||||||
@result = true
|
@result = true
|
||||||
end
|
end
|
||||||
|
when '9'
|
||||||
|
@result = is_course_manager?(user.id,obj_id)
|
||||||
end
|
end
|
||||||
return @result
|
return @result
|
||||||
end
|
end
|
||||||
|
|
|
@ -228,12 +228,21 @@ module UserScoreHelper
|
||||||
isManager = 0
|
isManager = 0
|
||||||
members = Member.where('user_id = ?', user.id)
|
members = Member.where('user_id = ?', user.id)
|
||||||
members.each do |m|
|
members.each do |m|
|
||||||
roles = m.member_roles
|
#roles = m.member_roles
|
||||||
roles.each do |r|
|
#roles.each do |r|
|
||||||
if r.role_id == 3
|
# if r.role_id == 3
|
||||||
|
# isManager = 1
|
||||||
|
# end
|
||||||
|
#end
|
||||||
|
@membership = m.memberships.all(:conditions => Project.visible_condition(User.current))
|
||||||
|
@membership.each do |membership|
|
||||||
|
#拥有编辑项目权限的可操作该项目
|
||||||
|
if m.allowed_to?({:controller => "projects", :action => "edit"}, membership.project, :global => false)
|
||||||
isManager = 1
|
isManager = 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
level = 0
|
level = 0
|
||||||
|
|
|
@ -247,4 +247,15 @@ module UsersHelper
|
||||||
displayed_flag = %w|index|
|
displayed_flag = %w|index|
|
||||||
!displayed_flag.include?(params['action'])
|
!displayed_flag.include?(params['action'])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#获取指定用户的未过期的课程列表
|
||||||
|
def user_courses_list user
|
||||||
|
result = []
|
||||||
|
user.coursememberships.map(&:course).each do |course|
|
||||||
|
if !course_endTime_timeout?(course)
|
||||||
|
result << course
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -67,11 +67,38 @@ module WatchersHelper
|
||||||
|
|
||||||
link_to text, url, :remote => true, :method => method, :class => css
|
link_to text, url, :remote => true, :method => method, :class => css
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# add by nwb
|
||||||
|
# 关注课程
|
||||||
|
def new_course_watcher_link(objects, user, options=[])
|
||||||
|
return '' unless user && user.logged?
|
||||||
|
objects = Array.wrap(objects)
|
||||||
|
|
||||||
|
watched = objects.any? {|object| object.watched_by?(user)}
|
||||||
|
@watch_flag = (objects.first.instance_of?(User) or objects.first.instance_of?(Project) or (objects.first.instance_of?(Contest)))
|
||||||
|
css = @watch_flag ? ([watcher_css(objects), watched ? 'icon ' : 'icon '].join(' ') << options[0].to_s) :
|
||||||
|
([watcher_css(objects), watched ? 'icon icon-fav ' : 'icon icon-fav-off '].join(' ') << options[0].to_s)
|
||||||
|
|
||||||
|
text = @watch_flag ?
|
||||||
|
(watched ? l(:button_unfollow) : l(:button_follow)) : (watched ? l(:button_unwatch) : l(:button_watch))
|
||||||
|
|
||||||
|
url = watch_path(
|
||||||
|
:object_type => objects.first.class.to_s.underscore,
|
||||||
|
:object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort)
|
||||||
|
)
|
||||||
|
method = watched ? 'delete' : 'post'
|
||||||
|
|
||||||
|
link_to text, url, :remote => true, :method => method, :class => css
|
||||||
|
end
|
||||||
|
|
||||||
# added by fq, modify nyan
|
# added by fq, modify nyan
|
||||||
# Somebody may use option params
|
# Somebody may use option params
|
||||||
def join_in_course(course, user, options=[])
|
def join_in_course(course, user, options=[])
|
||||||
return '' unless user && user.logged?
|
return '' unless user && user.logged?
|
||||||
joined = user.member_of?(course)
|
# modify by nwb
|
||||||
|
# 主讲教师不允许退出课程
|
||||||
|
return '' if user.id == course.tea_id
|
||||||
|
joined = user.member_of_course?(course)
|
||||||
text = joined ? l(:label_exit_course) : l(:label_join_course)
|
text = joined ? l(:label_exit_course) : l(:label_join_course)
|
||||||
url_t = join_path(:object_id => course.id)
|
url_t = join_path(:object_id => course.id)
|
||||||
url_f = try_join_path(:object_id => course.id)
|
url_f = try_join_path(:object_id => course.id)
|
||||||
|
@ -82,10 +109,15 @@ module WatchersHelper
|
||||||
link_to text, url_f, :remote => true, :method => method, :id => "#{course.id}", :class => []+options
|
link_to text, url_f, :remote => true, :method => method, :id => "#{course.id}", :class => []+options
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 用户是否允许加入课程判断
|
||||||
|
# add by nwb
|
||||||
def join_in_course_for_list(course, user, options=[])
|
def join_in_course_for_list(course, user, options=[])
|
||||||
return '' unless user && user.logged?
|
return '' unless user && user.logged?
|
||||||
joined = user.member_of?(course)
|
# modify by nwb
|
||||||
|
# 主讲教师不允许退出课程
|
||||||
|
return '' if user.id == course.tea_id
|
||||||
|
joined = user.member_of_course?(course)
|
||||||
text = joined ? l(:label_exit_course) : l(:label_join_course)
|
text = joined ? l(:label_exit_course) : l(:label_join_course)
|
||||||
url_t = join_path(:object_id => course.id)
|
url_t = join_path(:object_id => course.id)
|
||||||
url_f = try_join_path(:object_id => course.id)
|
url_f = try_join_path(:object_id => course.id)
|
||||||
|
|
|
@ -22,6 +22,33 @@ module WelcomeHelper
|
||||||
include CoursesHelper
|
include CoursesHelper
|
||||||
include ProjectsHelper
|
include ProjectsHelper
|
||||||
|
|
||||||
|
def get_timestamp(obj)
|
||||||
|
if obj.respond_to? :updated_on
|
||||||
|
:updated_on
|
||||||
|
elsif obj.respond_to? :updated_at
|
||||||
|
:updated_at
|
||||||
|
elsif obj.respond_to? :created_on
|
||||||
|
:created_on
|
||||||
|
elsif obj.respond_to? :created_at
|
||||||
|
:created_at
|
||||||
|
else
|
||||||
|
Time.now.to_i.to_s.to_sym
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def cache_key_for_project(obj)
|
||||||
|
timestamp = get_timestamp(obj)
|
||||||
|
"welcome_index_project_ul_#{obj.class}_li_#{obj.id}_#{obj.__send__ timestamp}"
|
||||||
|
end
|
||||||
|
def cache_key_for_event(obj)
|
||||||
|
timestamp = get_timestamp(obj)
|
||||||
|
"welcome_index_event_ul_#{obj.class}_li_#{obj.id}_#{obj.__send__ timestamp}"
|
||||||
|
end
|
||||||
|
def cache_key_for_topic(obj)
|
||||||
|
timestamp = get_timestamp(obj)
|
||||||
|
"welcome_index_topic_ul_#{obj.class}_li_#{obj.id}_#{obj.__send__ timestamp}"
|
||||||
|
end
|
||||||
|
|
||||||
def welcome_join_in_course(project, user)
|
def welcome_join_in_course(project, user)
|
||||||
if(user.logged? &&
|
if(user.logged? &&
|
||||||
!(course_endTime_timeout? project) &&
|
!(course_endTime_timeout? project) &&
|
||||||
|
@ -56,7 +83,8 @@ module WelcomeHelper
|
||||||
# # => 前7个项目为新课程,后面三个是参与人数最多的
|
# # => 前7个项目为新课程,后面三个是参与人数最多的
|
||||||
#
|
#
|
||||||
# Returns project&courses array
|
# Returns project&courses array
|
||||||
def find_miracle_course(sum=10, max_rate=7, school_id)
|
# 原来的取课程逻辑
|
||||||
|
def find_miracle_course_base(sum=10, max_rate=7, school_id)
|
||||||
|
|
||||||
if User.current.user_extensions.school.nil? and school_id.nil?
|
if User.current.user_extensions.school.nil? and school_id.nil?
|
||||||
Project.active.visible.course_entities.
|
Project.active.visible.course_entities.
|
||||||
|
@ -106,6 +134,51 @@ module WelcomeHelper
|
||||||
# (c1.take(max)+c2).take(sum)
|
# (c1.take(max)+c2).take(sum)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#获取课程列表
|
||||||
|
# add by nwb
|
||||||
|
def find_miracle_course(sum=10, max_rate=7, school_id)
|
||||||
|
if User.current.user_extensions.school.nil? and school_id.nil?
|
||||||
|
Course.active.visible.
|
||||||
|
joins(:memberships).
|
||||||
|
group('members.course_id').
|
||||||
|
reorder("courses.created_at DESC, COUNT(members.course_id) DESC").take sum
|
||||||
|
else
|
||||||
|
if school_id.nil?
|
||||||
|
Course.active.visible.
|
||||||
|
joins(:memberships).
|
||||||
|
where("#{Course.table_name}.school_id = ?", User.current.user_extensions.school.id).
|
||||||
|
group('members.course_id').
|
||||||
|
reorder("courses.created_at DESC, COUNT(members.course_id) DESC").take sum
|
||||||
|
else
|
||||||
|
if school_id == "0"
|
||||||
|
Course.active.visible.
|
||||||
|
joins(:memberships).
|
||||||
|
group('members.course_id').
|
||||||
|
reorder("courses.created_at DESC, COUNT(members.course_id) DESC").take sum
|
||||||
|
else
|
||||||
|
Course.active.visible.
|
||||||
|
joins(:memberships).
|
||||||
|
where("#{Course.table_name}.school_id = ?", school_id).
|
||||||
|
group('members.course_id').
|
||||||
|
reorder("courses.created_at DESC, COUNT(members.course_id) DESC").take sum
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# else
|
||||||
|
# Project.active.visible.course_entities.
|
||||||
|
# joins(:course_extra).
|
||||||
|
# joins(:memberships).
|
||||||
|
# where("#{Course.table_name}.school_id = ?", school_id).
|
||||||
|
# group('members.project_id').
|
||||||
|
# reorder("courses.time DESC, COUNT(members.project_id) DESC").take sum
|
||||||
|
# end
|
||||||
|
# max = sum*(max_rate.to_f/10)
|
||||||
|
# c1 = find_new_course(sum).to_a.dup
|
||||||
|
# c2 = find_all_hot_course(sum).to_a.dup
|
||||||
|
# c2 = c2 - c1
|
||||||
|
# (c1.take(max)+c2).take(sum)
|
||||||
|
end
|
||||||
|
|
||||||
#查找所有学校按每个学校开设课程数量降序排序
|
#查找所有学校按每个学校开设课程数量降序排序
|
||||||
#page 分页查询开始条数的编号,从0开始
|
#page 分页查询开始条数的编号,从0开始
|
||||||
#limit 分页查询的数量
|
#limit 分页查询的数量
|
||||||
|
@ -131,10 +204,11 @@ module WelcomeHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_miracle_project(sum, max_rate)
|
def find_miracle_project(sum, max_rate)
|
||||||
max = sum*(max_rate.to_f/10)
|
#max = sum*(max_rate.to_f/10)
|
||||||
c1 = find_new_project(sum).to_a.dup
|
#c1 = find_new_project(sum).to_a.dup
|
||||||
c2 = find_all_hot_project(sum).to_a.dup
|
#c2 = find_all_hot_project(sum).to_a.dup
|
||||||
(c2.take(sum-max)+c1.take(max)).take(sum)
|
#(c2.take(sum-max)+c1.take(max)).take(sum)
|
||||||
|
find_all_hot_project(sum).to_a.dup
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_new_course limit=15
|
def find_new_course limit=15
|
||||||
|
@ -154,11 +228,18 @@ module WelcomeHelper
|
||||||
sort_course_by_hot limit
|
sort_course_by_hot limit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# modif by nwb
|
||||||
def find_all_new_hot_course limit = 9 ,school_id = 0
|
def find_all_new_hot_course limit = 9 ,school_id = 0
|
||||||
#sort_project_by_hot_rails 1, 'course_ac_para DESC', limit
|
#sort_project_by_hot_rails 1, 'course_ac_para DESC', limit
|
||||||
time_now = Time.new.strftime("%Y");
|
time_now = Time.new.strftime("%Y");
|
||||||
Project.visible.joins(:project_status).where("#{Project.table_name}.project_type = ? and #{Project.table_name}.created_on like '%#{time_now}%' and #{Project.table_name}.identifier not in
|
if school_id
|
||||||
(select extra from courses where school_id = ?)", 1,school_id).order("course_ac_para DESC").limit(limit).all
|
courses = Course.visible.joins(:course_status).where("#{Course.table_name}.created_at like '%#{time_now}%' and #{Course.table_name}.school_id <>
|
||||||
|
?", school_id).order("course_ac_para DESC").limit(limit).all
|
||||||
|
else
|
||||||
|
courses = Course.visible.joins(:course_status).where("#{Course.table_name}.created_at like '%#{time_now}%' and #{Course.table_name}.school_id is not NULL
|
||||||
|
").order("course_ac_para DESC").limit(limit).all
|
||||||
|
end
|
||||||
|
courses
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_all_hot_bid
|
def find_all_hot_bid
|
||||||
|
@ -207,6 +288,7 @@ module WelcomeHelper
|
||||||
def show_grade project
|
def show_grade project
|
||||||
grade = 0
|
grade = 0
|
||||||
begin
|
begin
|
||||||
|
#ActiveRecord::Base.connection.execute("CALL sp_project_status_cursor();")#执行存储过程速度慢
|
||||||
grade = project.project_status.grade if project && project.project_status
|
grade = project.project_status.grade if project && project.project_status
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
logger.error "Logger.Error [WelcomeHelper] ===> #{e}"
|
logger.error "Logger.Error [WelcomeHelper] ===> #{e}"
|
||||||
|
@ -237,7 +319,7 @@ module WelcomeHelper
|
||||||
content_tag('span', find_all_event_type(event)) <<
|
content_tag('span', find_all_event_type(event)) <<
|
||||||
': '.html_safe <<
|
': '.html_safe <<
|
||||||
link_to(truncate(event.event_title, length: 30, omission:'...'), event.event_url) <<
|
link_to(truncate(event.event_title, length: 30, omission:'...'), event.event_url) <<
|
||||||
link_to((' ['.html_safe+l(:label_downloads_list).to_s << ']'), project_files_path(event.container), :class => "attachments_list_color")
|
link_to((' ['.html_safe+l(:label_downloads_list).to_s << ']'), project_files_path(event.container.project), :class => "attachments_list_color")
|
||||||
else
|
else
|
||||||
str << content_tag("span", "更新了") <<
|
str << content_tag("span", "更新了") <<
|
||||||
content_tag("span", find_all_event_type(event)) <<
|
content_tag("span", find_all_event_type(event)) <<
|
||||||
|
@ -305,7 +387,7 @@ module WelcomeHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
#取得所有活动
|
#取得所有活动
|
||||||
def find_all_activities limit=6
|
def find_all_activities limit=6
|
||||||
# users = []
|
# users = []
|
||||||
# activities = Activity.find_by_sql("select distinct user_id from activities order by id DESC limit #{limit}" )
|
# activities = Activity.find_by_sql("select distinct user_id from activities order by id DESC limit #{limit}" )
|
||||||
# activities.each { |activity|
|
# activities.each { |activity|
|
||||||
|
@ -319,9 +401,10 @@ module WelcomeHelper
|
||||||
"show_documents" => true,
|
"show_documents" => true,
|
||||||
"show_messages" => true,
|
"show_messages" => true,
|
||||||
"show_news" => true,
|
"show_news" => true,
|
||||||
"show_bids" => true
|
"show_bids" => true,
|
||||||
|
"show_contest" => true
|
||||||
}
|
}
|
||||||
activity.scope_select{|t| ['changesets', 'documents', 'memos', 'messages', 'journals_for_messages', 'bids', 'news'].include?(t) ? nil : 'You may think you know what the following code does, may be. but why don"t you close this file and go play with something else, Now?' }
|
activity.scope_select{|t| ['changesets', 'documents', 'memos', 'messages', 'journals_for_messages', 'bids', 'news', 'contestnotification'].include?(t) ? nil : 'You may think you know what the following code does, may be. but why don"t you close this file and go play with something else, Now?' }
|
||||||
activity.events_welcome(nil, nil, {:limit => limit, :types => 'welcome'})
|
activity.events_welcome(nil, nil, {:limit => limit, :types => 'welcome'})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ require "fileutils"
|
||||||
class Attachment < ActiveRecord::Base
|
class Attachment < ActiveRecord::Base
|
||||||
belongs_to :container, :polymorphic => true
|
belongs_to :container, :polymorphic => true
|
||||||
belongs_to :project, foreign_key: 'container_id', conditions: "attachments.container_type = 'Project'"
|
belongs_to :project, foreign_key: 'container_id', conditions: "attachments.container_type = 'Project'"
|
||||||
|
belongs_to :course, foreign_key: 'container_id', conditions: "attachments.container_type = 'Course'"
|
||||||
belongs_to :softapplication, foreign_key: 'container_id', conditions: "attachments.container_type = 'Softapplication'"
|
belongs_to :softapplication, foreign_key: 'container_id', conditions: "attachments.container_type = 'Softapplication'"
|
||||||
belongs_to :author, :class_name => "User", :foreign_key => "author_id"
|
belongs_to :author, :class_name => "User", :foreign_key => "author_id"
|
||||||
belongs_to :attachmentstype, :foreign_key => "attachtype",:primary_key => "id"
|
belongs_to :attachmentstype, :foreign_key => "attachtype",:primary_key => "id"
|
||||||
|
@ -30,12 +31,20 @@ class Attachment < ActiveRecord::Base
|
||||||
validates_length_of :disk_filename, :maximum => 255
|
validates_length_of :disk_filename, :maximum => 255
|
||||||
validates_length_of :description, :maximum => 255
|
validates_length_of :description, :maximum => 255
|
||||||
validate :validate_max_file_size
|
validate :validate_max_file_size
|
||||||
acts_as_taggable
|
|
||||||
|
|
||||||
|
|
||||||
|
acts_as_taggable
|
||||||
acts_as_event :title => :filename,
|
acts_as_event :title => :filename,
|
||||||
:url => Proc.new {|o| {:controller => 'attachments', :action => 'download', :id => o.id, :filename => o.filename}}
|
:url => Proc.new {|o| {:controller => 'attachments', :action => 'download', :id => o.id, :filename => o.filename}}
|
||||||
|
|
||||||
acts_as_activity_provider :type => 'files',
|
#课程资源文件
|
||||||
|
acts_as_activity_provider :type => 'course_files',
|
||||||
|
:permission => :view_files,
|
||||||
|
:author_key => :author_id,
|
||||||
|
:find_options => {:select => "#{Attachment.table_name}.*",
|
||||||
|
:joins => "LEFT JOIN #{Course.table_name} ON ( #{Attachment.table_name}.container_type='Course' AND #{Attachment.table_name}.container_id = #{Course.table_name}.id )"}
|
||||||
|
|
||||||
|
acts_as_activity_provider :type => 'files',
|
||||||
:permission => :view_files,
|
:permission => :view_files,
|
||||||
:author_key => :author_id,
|
:author_key => :author_id,
|
||||||
:find_options => {:select => "#{Attachment.table_name}.*",
|
:find_options => {:select => "#{Attachment.table_name}.*",
|
||||||
|
@ -56,8 +65,109 @@ class Attachment < ActiveRecord::Base
|
||||||
@@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails")
|
@@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails")
|
||||||
|
|
||||||
before_save :files_to_final_location
|
before_save :files_to_final_location
|
||||||
|
before_save :be_user_score # user_score
|
||||||
after_destroy :delete_from_disk
|
after_destroy :delete_from_disk
|
||||||
|
|
||||||
|
# add by nwb
|
||||||
|
# 获取所有可公开的资源文件列表
|
||||||
|
scope :public_attachments, lambda {
|
||||||
|
#joins(Project.table_name).where("container_type = 'Project' and ")
|
||||||
|
joins("LEFT JOIN #{Project.table_name} ON #{Attachment.table_name}.container_type='Project' AND #{Project.table_name}.id = #{Attachment.table_name}.container_id and #{Project.table_name}.is_public=1 " +
|
||||||
|
" LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Project' AND #{Document.table_name}.project_id in "+self.public_project_id +
|
||||||
|
" LEFT JOIN #{Issue.table_name} ON #{Attachment.table_name}.container_type='Project' AND #{Issue.table_name}.project_id in "+self.public_project_id +
|
||||||
|
" LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Project' AND #{Version.table_name}.project_id in "+self.public_project_id +
|
||||||
|
" LEFT JOIN #{WikiPage.table_name} ON #{Attachment.table_name}.container_type='WikiPage' AND #{WikiPage.table_name}.parent_id in "+self.public_wiki_id +
|
||||||
|
" LEFT JOIN #{Message.table_name} ON #{Attachment.table_name}.container_type='Message' AND #{Message.table_name}.parent_id in "+self.public_board_id +
|
||||||
|
" LEFT JOIN #{Course.table_name} ON #{Attachment.table_name}.container_type='Course' AND #{Course.table_name}.is_public=1 " +
|
||||||
|
" LEFT JOIN #{News.table_name} ON #{Attachment.table_name}.container_type='News' AND (#{News.table_name}.project_id in "+self.public_project_id + " OR #{News.table_name}.course_id in " + self.public_course_id + ")" +
|
||||||
|
" LEFT JOIN #{HomeworkAttach.table_name} ON #{Attachment.table_name}.container_type='HomeworkAttach' AND #{HomeworkAttach.table_name}.bid_id in "+self.public_bid_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
# add by nwb
|
||||||
|
# 公开的项目id列表
|
||||||
|
def self.public_project_id
|
||||||
|
idlist = "("
|
||||||
|
projects=Project.all_public
|
||||||
|
count = projects.count
|
||||||
|
for i in 0...count
|
||||||
|
project = projects[i]
|
||||||
|
idlist+="'" + project.id.to_s + "'"
|
||||||
|
if i != count-1
|
||||||
|
idlist+=","
|
||||||
|
end
|
||||||
|
end
|
||||||
|
idlist += ")"
|
||||||
|
idlist
|
||||||
|
end
|
||||||
|
|
||||||
|
# add by nwb
|
||||||
|
# 公开的课程id列表
|
||||||
|
def self.public_course_id
|
||||||
|
idlist = "("
|
||||||
|
courses=Course.all_public
|
||||||
|
count = courses.count
|
||||||
|
for i in 0...count
|
||||||
|
course = courses[i]
|
||||||
|
idlist+="'" + course.id.to_s + "'"
|
||||||
|
if i != count-1
|
||||||
|
idlist = idlist + ","
|
||||||
|
end
|
||||||
|
end
|
||||||
|
idlist += ")"
|
||||||
|
idlist
|
||||||
|
end
|
||||||
|
|
||||||
|
# add by nwb
|
||||||
|
# 公开的wiki id列表
|
||||||
|
def self.public_wiki_id
|
||||||
|
idlist = "("
|
||||||
|
wikis=Wiki.where("project_id in " + public_project_id)
|
||||||
|
count = wikis.count
|
||||||
|
for i in 0...count
|
||||||
|
wiki = wikis[i]
|
||||||
|
idlist+="'" + wiki.id.to_s + "'"
|
||||||
|
if i != count-1
|
||||||
|
idlist = idlist + ","
|
||||||
|
end
|
||||||
|
end
|
||||||
|
idlist += ")"
|
||||||
|
idlist
|
||||||
|
end
|
||||||
|
|
||||||
|
# add by nwb
|
||||||
|
# 公开的board id列表
|
||||||
|
def self.public_board_id
|
||||||
|
idlist = "("
|
||||||
|
boards=Board.where("project_id in " + public_project_id + " or course_id in " + public_course_id)
|
||||||
|
count = boards.count
|
||||||
|
for i in 0...count
|
||||||
|
board = boards[i]
|
||||||
|
idlist+="'" + board.id.to_s + "'"
|
||||||
|
if i != count-1
|
||||||
|
idlist = idlist + ","
|
||||||
|
end
|
||||||
|
end
|
||||||
|
idlist += ")"
|
||||||
|
idlist
|
||||||
|
end
|
||||||
|
|
||||||
|
# add by nwb
|
||||||
|
# 公开的bid id列表
|
||||||
|
def self.public_bid_id
|
||||||
|
idlist = "("
|
||||||
|
bids=Bid.where("reward_type=3")
|
||||||
|
count = bids.count
|
||||||
|
for i in 0...count
|
||||||
|
bid = bids[i]
|
||||||
|
idlist+="'" + bid.id.to_s + "'"
|
||||||
|
if i != count-1
|
||||||
|
idlist = idlist + ","
|
||||||
|
end
|
||||||
|
end
|
||||||
|
idlist += ")"
|
||||||
|
idlist
|
||||||
|
end
|
||||||
|
|
||||||
# Returns an unsaved copy of the attachment
|
# Returns an unsaved copy of the attachment
|
||||||
def copy(attributes=nil)
|
def copy(attributes=nil)
|
||||||
copy = self.class.new
|
copy = self.class.new
|
||||||
|
@ -119,7 +229,7 @@ class Attachment < ActiveRecord::Base
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def filename=(arg)
|
def filename=(arg)
|
||||||
write_attribute :filename, sanitize_filename(arg.to_s)
|
write_attribute :filename, sanitize_filename(arg.to_s)
|
||||||
filename
|
filename
|
||||||
end
|
end
|
||||||
|
@ -169,6 +279,7 @@ class Attachment < ActiveRecord::Base
|
||||||
File.join(self.class.storage_path, disk_directory.to_s, disk_filename.to_s)
|
File.join(self.class.storage_path, disk_directory.to_s, disk_filename.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#标题
|
||||||
def title
|
def title
|
||||||
title = filename.to_s
|
title = filename.to_s
|
||||||
if description.present?
|
if description.present?
|
||||||
|
@ -185,6 +296,10 @@ class Attachment < ActiveRecord::Base
|
||||||
container.try(:project)
|
container.try(:project)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def course
|
||||||
|
container
|
||||||
|
end
|
||||||
|
|
||||||
def visible?(user=User.current)
|
def visible?(user=User.current)
|
||||||
if container_id
|
if container_id
|
||||||
container && container.attachments_visible?(user)
|
container && container.attachments_visible?(user)
|
||||||
|
@ -361,4 +476,17 @@ class Attachment < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
"#{timestamp}_#{ascii}"
|
"#{timestamp}_#{ascii}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# update user score
|
||||||
|
def be_user_score
|
||||||
|
if self.container_id_changed?
|
||||||
|
type = self.container_type
|
||||||
|
types = %w|Document News Version Project Issue Message WikiPage|
|
||||||
|
if types.include?(type)
|
||||||
|
UserScore.project(:push_file, User.current,self, { attachment_id: self.id })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,11 +22,11 @@ class Bid < ActiveRecord::Base
|
||||||
belongs_to :course
|
belongs_to :course
|
||||||
has_many :biding_projects, :dependent => :destroy
|
has_many :biding_projects, :dependent => :destroy
|
||||||
has_many :projects, :through => :biding_projects
|
has_many :projects, :through => :biding_projects
|
||||||
has_many :projects_member, :class_name => 'User', :through => :projects
|
has_many :courses_member, :class_name => 'User', :through => :courses
|
||||||
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
|
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
|
||||||
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
|
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
|
||||||
has_many :homework_for_courses, :dependent => :destroy
|
has_many :homework_for_courses, :dependent => :destroy
|
||||||
has_many :courses, :through => :homework_for_courses, :source => :project
|
has_many :courses, :through => :homework_for_courses, :source => :course
|
||||||
has_many :homeworks, :class_name => 'HomeworkAttach', :dependent => :destroy
|
has_many :homeworks, :class_name => 'HomeworkAttach', :dependent => :destroy
|
||||||
has_many :join_in_contests, :dependent => :destroy
|
has_many :join_in_contests, :dependent => :destroy
|
||||||
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
|
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
class Board < ActiveRecord::Base
|
class Board < ActiveRecord::Base
|
||||||
include Redmine::SafeAttributes
|
include Redmine::SafeAttributes
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
|
belongs_to :course
|
||||||
has_many :topics, :class_name => 'Message', :conditions => "#{Message.table_name}.parent_id IS NULL", :order => "#{Message.table_name}.created_on DESC"
|
has_many :topics, :class_name => 'Message', :conditions => "#{Message.table_name}.parent_id IS NULL", :order => "#{Message.table_name}.created_on DESC"
|
||||||
has_many :messages, :dependent => :destroy, :order => "#{Message.table_name}.created_on DESC"
|
has_many :messages, :dependent => :destroy, :order => "#{Message.table_name}.created_on DESC"
|
||||||
belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id
|
belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id
|
||||||
|
|
|
@ -18,6 +18,9 @@
|
||||||
class Changeset < ActiveRecord::Base
|
class Changeset < ActiveRecord::Base
|
||||||
belongs_to :repository
|
belongs_to :repository
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
|
#after_save :be_user_score # user_score
|
||||||
|
|
||||||
has_many :filechanges, :class_name => 'Change', :dependent => :delete_all
|
has_many :filechanges, :class_name => 'Change', :dependent => :delete_all
|
||||||
# fq
|
# fq
|
||||||
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
|
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
|
||||||
|
@ -60,7 +63,7 @@ class Changeset < ActiveRecord::Base
|
||||||
includes(:repository => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args))
|
includes(:repository => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args))
|
||||||
}
|
}
|
||||||
|
|
||||||
after_create :scan_for_issues
|
after_create :scan_for_issues,:be_user_score # user_score
|
||||||
before_create :before_create_cs
|
before_create :before_create_cs
|
||||||
|
|
||||||
# fq
|
# fq
|
||||||
|
@ -95,7 +98,9 @@ class Changeset < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def project
|
def project
|
||||||
repository.project
|
unless repository.nil?
|
||||||
|
repository.project
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def author
|
def author
|
||||||
|
@ -292,4 +297,14 @@ class Changeset < ActiveRecord::Base
|
||||||
def self.to_utf8(str, encoding)
|
def self.to_utf8(str, encoding)
|
||||||
Redmine::CodesetUtil.to_utf8(str, encoding)
|
Redmine::CodesetUtil.to_utf8(str, encoding)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# update user score
|
||||||
|
def be_user_score
|
||||||
|
UserScore.project(:push_code, self.user,self, { changeset_id: self.id })
|
||||||
|
#更新用户等级
|
||||||
|
UserLevels.update_user_level(self.user)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,6 +13,7 @@ class Contest < ActiveRecord::Base
|
||||||
has_many :join_in_competitions, foreign_key: 'competition_id', :dependent => :destroy
|
has_many :join_in_competitions, foreign_key: 'competition_id', :dependent => :destroy
|
||||||
has_many :join_in_contests, class_name: 'JoinInCompetition', foreign_key: 'competition_id', :dependent => :destroy
|
has_many :join_in_contests, class_name: 'JoinInCompetition', foreign_key: 'competition_id', :dependent => :destroy
|
||||||
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
|
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
|
||||||
|
has_many :contestnotifications, :dependent => :destroy, :include => :author
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,8 +24,9 @@ class Contest < ActiveRecord::Base
|
||||||
|
|
||||||
validates_length_of :name, :maximum => NAME_LENGTH_LIMIT
|
validates_length_of :name, :maximum => NAME_LENGTH_LIMIT
|
||||||
validates_length_of :description, :maximum => DESCRIPTION_LENGTH_LIMIT
|
validates_length_of :description, :maximum => DESCRIPTION_LENGTH_LIMIT
|
||||||
validates_presence_of :author_id, :name, :deadline
|
validates_presence_of :author_id, :name, :budget
|
||||||
validates_format_of :deadline, :with => /^[\d]{4}[-][\d]{1,2}[-][\d]{1,2}$/
|
#validates_format_of :deadline, :with => /^[\d]{4}[-][\d]{1,2}[-][\d]{1,2}$/
|
||||||
|
validates_format_of :deadline, :with =>/^[1-9][0-9]{3}\-0?[1-9]|1[12]\-0?[1-9]|[12]\d|3[01]$/
|
||||||
# validates_format_of :budget, :with => /^(\d+)$|^(\d+).([0-9]{2})|^(\d+).([0-9]{1})$/
|
# validates_format_of :budget, :with => /^(\d+)$|^(\d+).([0-9]{2})|^(\d+).([0-9]{1})$/
|
||||||
validate :validate_user
|
validate :validate_user
|
||||||
after_create :act_as_activity
|
after_create :act_as_activity
|
||||||
|
@ -93,6 +95,17 @@ class Contest < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Closes open and locked project versions that are completed
|
||||||
|
def close_completed_versions_contest
|
||||||
|
Version.transaction do
|
||||||
|
versions.where(:status => %w(open locked)).all.each do |version|
|
||||||
|
if version.completed?
|
||||||
|
version.update_attribute(:status, 'closed')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def set_commit(commit)
|
def set_commit(commit)
|
||||||
self.update_attribute(:commit, commit)
|
self.update_attribute(:commit, commit)
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
class Contestnotification < ActiveRecord::Base
|
||||||
|
#attr_accessible :author_id, :notificationcomments_count, :contest_id, :description, :summary, :title
|
||||||
|
|
||||||
|
include Redmine::SafeAttributes
|
||||||
|
#Contestnotification::Notificationcomment
|
||||||
|
belongs_to :contest
|
||||||
|
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
||||||
|
has_many :notificationcomments, as: :notificationcommented, :dependent => :delete_all, :order => "created_at"
|
||||||
|
# fq
|
||||||
|
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
|
||||||
|
|
||||||
|
validates_presence_of :title, :description
|
||||||
|
validates_length_of :title, :maximum => 60
|
||||||
|
validates_length_of :summary, :maximum => 255
|
||||||
|
|
||||||
|
acts_as_attachable :delete_permission => :manage_contestnotifications
|
||||||
|
acts_as_searchable :columns => ['title', 'summary', "#{table_name}.description"], :include => :contest
|
||||||
|
acts_as_event :url => Proc.new {|o| {:controller => 'contestnotifications', :action => 'show', :id => o.id}}
|
||||||
|
acts_as_activity_provider :find_options => {:include => [:contest, :author]},
|
||||||
|
:author_key => :author_id
|
||||||
|
acts_as_watchable
|
||||||
|
|
||||||
|
after_create :add_author_as_watcher
|
||||||
|
|
||||||
|
after_create :act_as_activity
|
||||||
|
|
||||||
|
|
||||||
|
scope :visible, lambda {|*args|
|
||||||
|
nil
|
||||||
|
#includes(:contest).where(Contest.allowed_to_condition(args.shift || User.current, :view_contestnotifications, *args))
|
||||||
|
}
|
||||||
|
|
||||||
|
safe_attributes 'title', 'summary', 'description'
|
||||||
|
|
||||||
|
def visible?(user=User.current)
|
||||||
|
!user.nil? && user.allowed_to?(:view_contestnotifications, contest)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns true if the news can be commented by user
|
||||||
|
def notificationcommentable?(user=User.current)
|
||||||
|
user.allowed_to?(:notificationcomment_contestnotifications, contest)
|
||||||
|
end
|
||||||
|
|
||||||
|
def recipients
|
||||||
|
#contest.users.select {|user| user.notify_about?(self)}.map(&:mail)
|
||||||
|
end
|
||||||
|
|
||||||
|
# returns latest news for contests visible by user
|
||||||
|
def self.latest(user = User.current, count = 5)
|
||||||
|
visible(user).includes([:author, :contest]).order("#{Contestnotification.table_name}.created_at DESC").limit(count).all
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def add_author_as_watcher
|
||||||
|
#Watcher.create(:watchable => self, :user => author)
|
||||||
|
end
|
||||||
|
## fq
|
||||||
|
def act_as_activity
|
||||||
|
self.acts << Activity.new(:user_id => self.author_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -1,13 +1,47 @@
|
||||||
class Course < ActiveRecord::Base
|
class Course < ActiveRecord::Base
|
||||||
include Redmine::SafeAttributes
|
include Redmine::SafeAttributes
|
||||||
|
|
||||||
|
STATUS_ACTIVE = 1
|
||||||
|
STATUS_CLOSED = 5
|
||||||
|
STATUS_ARCHIVED = 9
|
||||||
|
|
||||||
attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password
|
attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period
|
||||||
belongs_to :project, :class_name => 'Project', :foreign_key => :extra, primary_key: :identifier
|
belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier
|
||||||
belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher,该方法通过tea_id来调用User表
|
belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher,该方法通过tea_id来调用User表
|
||||||
belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school,该方法通过school_id来调用School表
|
belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school,该方法通过school_id来调用School表
|
||||||
has_many :bid
|
has_many :bid
|
||||||
validates_presence_of :password, :term
|
|
||||||
validates_format_of :class_period, :message => "class period can only digital!", :with =>/^[1-9]\d*$/
|
has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}"
|
||||||
|
has_many :memberships, :class_name => 'Member'
|
||||||
|
has_many :member_principals, :class_name => 'Member',
|
||||||
|
:include => :principal,
|
||||||
|
:conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})"
|
||||||
|
has_many :principals, :through => :member_principals, :source => :principal
|
||||||
|
has_many :users, :through => :members
|
||||||
|
has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy
|
||||||
|
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
|
||||||
|
has_many :homework_for_courses, :dependent => :destroy
|
||||||
|
has_many :student, :through => :students_for_courses, :source => :user
|
||||||
|
has_many :course_infos, :class_name => 'CourseInfos',:dependent => :destroy
|
||||||
|
has_many :enabled_modules, :dependent => :delete_all
|
||||||
|
has_many :boards, :dependent => :destroy, :order => "position ASC"
|
||||||
|
#has_many :course_journals_for_messages, :class_name => 'CourseJournalsForMessage', :as => :jour, :dependent => :destroy
|
||||||
|
has_many :news, :dependent => :destroy, :include => :author
|
||||||
|
has_one :course_status, :class_name => "CourseStatus", :dependent => :destroy
|
||||||
|
|
||||||
|
acts_as_taggable
|
||||||
|
acts_as_nested_set :order => 'name', :dependent => :destroy
|
||||||
|
acts_as_attachable :view_permission => :view_files,
|
||||||
|
:delete_permission => :manage_files
|
||||||
|
|
||||||
|
validates_presence_of :password, :term,:name
|
||||||
|
validates_format_of :class_period, :with =>/^[1-9]\d*$/
|
||||||
|
validates_format_of :name,:with =>/^[a-zA-Z0-9_\u4e00-\u9fa5]+$/
|
||||||
|
|
||||||
|
before_save :self_validate
|
||||||
|
after_save :create_board_sync
|
||||||
|
before_destroy :delete_all_members
|
||||||
|
|
||||||
safe_attributes 'extra',
|
safe_attributes 'extra',
|
||||||
'time',
|
'time',
|
||||||
'name',
|
'name',
|
||||||
|
@ -17,12 +51,159 @@ class Course < ActiveRecord::Base
|
||||||
'tea_id',
|
'tea_id',
|
||||||
'password',
|
'password',
|
||||||
'term',
|
'term',
|
||||||
'password'
|
'is_public',
|
||||||
|
'description',
|
||||||
|
'class_period'
|
||||||
|
|
||||||
#自定义验证
|
acts_as_customizable
|
||||||
def validate
|
|
||||||
if !class_period.match([0-9])
|
scope :all_course
|
||||||
errors.add_to_base("class period can only digital")
|
scope :active, lambda { where(:status => STATUS_ACTIVE) }
|
||||||
|
scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) }
|
||||||
|
scope :all_public, lambda { where(:is_public => true) }
|
||||||
|
scope :visible, lambda {|*args| where(Course.visible_condition(args.shift || User.current, *args)) }
|
||||||
|
scope :allowed_to, lambda {|*args|
|
||||||
|
user = User.current
|
||||||
|
permission = nil
|
||||||
|
if args.first.is_a?(Symbol)
|
||||||
|
permission = args.shift
|
||||||
|
else
|
||||||
|
user = args.shift
|
||||||
|
permission = args.shift
|
||||||
|
end
|
||||||
|
where(Course.allowed_to_condition(user, permission, *args))
|
||||||
|
}
|
||||||
|
scope :like, lambda {|arg|
|
||||||
|
if arg.blank?
|
||||||
|
where(nil)
|
||||||
|
else
|
||||||
|
pattern = "%#{arg.to_s.strip.downcase}%"
|
||||||
|
where(" LOWER(name) LIKE :p ", :p => pattern)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
def visible?(user=User.current)
|
||||||
|
user.allowed_to?(:view_course, self)
|
||||||
|
end
|
||||||
|
|
||||||
|
def parent_id_changed?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
# 课程的短描述信息
|
||||||
|
def short_description(length = 255)
|
||||||
|
description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
|
||||||
|
end
|
||||||
|
|
||||||
|
def extra_frozen?
|
||||||
|
errors[:extra].blank? && !(new_record? || extra.blank?)
|
||||||
|
end
|
||||||
|
|
||||||
|
def archived?
|
||||||
|
self.status == STATUS_ARCHIVED
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.visible_condition(user, options={})
|
||||||
|
allowed_to_condition(user, :view_course, options)
|
||||||
|
end
|
||||||
|
|
||||||
|
# 获取课程的资源类型列表
|
||||||
|
def attachmenttypes
|
||||||
|
@attachmenttypes = Attachmentstype.find(:all, :conditions => ["#{Attachmentstype.table_name}.typeId= ?",self.attachmenttype ])
|
||||||
|
end
|
||||||
|
|
||||||
|
# 获取资源后缀名列表
|
||||||
|
def contenttypes
|
||||||
|
attachmenttypes
|
||||||
|
if @attachmenttypes.length >0
|
||||||
|
@attachmenttypes.last().suffixArr
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def active?
|
||||||
|
self.status == STATUS_ACTIVE
|
||||||
|
end
|
||||||
|
|
||||||
|
#课程权限判断
|
||||||
|
def allows_to?(action)
|
||||||
|
if archived?
|
||||||
|
# No action allowed on archived projects
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
unless active? || Redmine::AccessControl.read_action?(action)
|
||||||
|
# No write action allowed on closed projects
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
# No action allowed on disabled modules
|
||||||
|
if action.is_a? Hash
|
||||||
|
allowed_actions.include? "#{action[:controller]}/#{action[:action]}"
|
||||||
|
else
|
||||||
|
allowed_permissions.include? action
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# 课程允许的权限集合
|
||||||
|
def allowed_permissions
|
||||||
|
@allowed_permissions ||= begin
|
||||||
|
module_names = enabled_modules.all(:select => :name).collect {|m| m.name}
|
||||||
|
Redmine::AccessControl.modules_permissions(module_names).collect {|p| p.name}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# 课程允许的动作集合
|
||||||
|
def allowed_actions
|
||||||
|
@actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten
|
||||||
|
end
|
||||||
|
|
||||||
|
# 返回用户组可以访问的课程
|
||||||
|
def users_by_role
|
||||||
|
members.includes(:user, :roles).all.inject({}) do |h, m|
|
||||||
|
m.roles.each do |r|
|
||||||
|
h[r] ||= []
|
||||||
|
h[r] << m.user
|
||||||
|
end
|
||||||
|
h
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
#自定义验证
|
||||||
|
def self_validate
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
# 创建课程讨论区
|
||||||
|
def create_board_sync
|
||||||
|
@board = self.boards.build
|
||||||
|
self.name=" #{l(:label_borad_course) }"
|
||||||
|
@board.name = self.name
|
||||||
|
@board.description = self.name.to_s
|
||||||
|
@board.project_id = -1
|
||||||
|
if @board.save
|
||||||
|
logger.debug "[Course Model] ===> #{@board.to_json}"
|
||||||
|
else
|
||||||
|
logger.error "[Course Model] ===> Auto create board when course saved, because #{@board.full_messages}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# 新增课程留言
|
||||||
|
# add by nwb
|
||||||
|
def self.add_new_jour(user, notes, id, options={})
|
||||||
|
course = Course.find(id)
|
||||||
|
if options.count == 0
|
||||||
|
pjfm = course.journals_for_messages.build(:user_id => user.id, :notes => notes, :reply_id => 0)
|
||||||
|
else
|
||||||
|
pjfm = course.journals_for_messages.build(options)
|
||||||
|
end
|
||||||
|
pjfm.save
|
||||||
|
pjfm
|
||||||
|
end
|
||||||
|
|
||||||
|
# 删除课程所有成员
|
||||||
|
def delete_all_members
|
||||||
|
if self.members && self.members.count > 0
|
||||||
|
me, mr = Member.table_name, MemberRole.table_name
|
||||||
|
connection.delete("DELETE FROM #{mr} WHERE #{mr}.member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.course_id = #{id})")
|
||||||
|
Member.delete_all(['course_id = ?', id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -47,4 +228,54 @@ class Course < ActiveRecord::Base
|
||||||
return time
|
return time
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.allowed_to_condition(user, permission, options={})
|
||||||
|
perm = Redmine::AccessControl.permission(permission)
|
||||||
|
base_statement = (perm && perm.read? ? "#{Course.table_name}.status <> #{Course::STATUS_ARCHIVED}" : "#{Course.table_name}.status = #{Course::STATUS_ACTIVE}")
|
||||||
|
if perm && perm.course_module
|
||||||
|
base_statement << " AND #{Course.table_name}.id IN (SELECT em.course_id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.course_module}')"
|
||||||
|
end
|
||||||
|
|
||||||
|
if options[:course]
|
||||||
|
course_statement = "#{Course.table_name}.id = #{options[:course].id}"
|
||||||
|
course_statement << " OR (#{Course.table_name}.lft > #{options[:course].lft} AND #{Course.table_name}.rgt < #{options[:course].rgt})" if options[:with_subcourses]
|
||||||
|
base_statement = "(#{course_statement}) AND (#{base_statement})"
|
||||||
|
end
|
||||||
|
|
||||||
|
if user.admin?
|
||||||
|
base_statement
|
||||||
|
else
|
||||||
|
statement_by_role = {}
|
||||||
|
unless options[:member]
|
||||||
|
role = user.logged? ? Role.non_member : Role.anonymous
|
||||||
|
if role.allowed_to?(permission)
|
||||||
|
statement_by_role[role] = "#{Course.table_name}.is_public = #{connection.quoted_true}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if user.logged?
|
||||||
|
user.courses_by_role.each do |role, courses|
|
||||||
|
if role.allowed_to?(permission) && courses.any?
|
||||||
|
statement_by_role[role] = "#{Course.table_name}.id IN (#{courses.collect(&:id).join(',')})"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if statement_by_role.empty?
|
||||||
|
"1=0"
|
||||||
|
else
|
||||||
|
if block_given?
|
||||||
|
statement_by_role.each do |role, statement|
|
||||||
|
if s = yield(role, user)
|
||||||
|
statement_by_role[role] = "(#{statement} AND (#{s}))"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
"((#{base_statement}) AND (#{statement_by_role.values.join(' OR ')}))"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
#项目与课程分离后,很多课程的名称等信息为空,这些数据信息存储在项目表中!!就是数据兼容的问题
|
||||||
|
def name
|
||||||
|
read_attribute('name') || Project.find_by_identifier(self.extra).try(:name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class CourseInfos < ActiveRecord::Base
|
||||||
|
attr_accessible :user_id, :course_id
|
||||||
|
belongs_to :user
|
||||||
|
belongs_to :course
|
||||||
|
end
|
|
@ -0,0 +1,7 @@
|
||||||
|
class CourseStatus < ActiveRecord::Base
|
||||||
|
attr_accessible :changesets_count, :course_ac_para, :course_id, :grade, :watchers_count
|
||||||
|
|
||||||
|
belongs_to :course
|
||||||
|
validates_presence_of :course_id
|
||||||
|
validates_uniqueness_of :course_id
|
||||||
|
end
|
|
@ -18,7 +18,12 @@
|
||||||
class Document < ActiveRecord::Base
|
class Document < ActiveRecord::Base
|
||||||
include Redmine::SafeAttributes
|
include Redmine::SafeAttributes
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
|
belongs_to :user
|
||||||
belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id"
|
belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id"
|
||||||
|
|
||||||
|
after_create :be_user_score # user_score
|
||||||
|
|
||||||
|
|
||||||
acts_as_attachable :delete_permission => :delete_documents
|
acts_as_attachable :delete_permission => :delete_documents
|
||||||
|
|
||||||
acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project
|
acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project
|
||||||
|
@ -54,4 +59,9 @@ class Document < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
@updated_on
|
@updated_on
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# update user score
|
||||||
|
def be_user_score
|
||||||
|
UserScore.project(:push_document, self.user,self,{ document_id: self.id })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,7 +9,7 @@ class Forum < ActiveRecord::Base
|
||||||
'memo_count',
|
'memo_count',
|
||||||
'last_memo_id',
|
'last_memo_id',
|
||||||
'creator_id'
|
'creator_id'
|
||||||
validates_presence_of :name, :creator_id
|
validates_presence_of :name, :creator_id, :description
|
||||||
validates_length_of :name, maximum: 50
|
validates_length_of :name, maximum: 50
|
||||||
validates_length_of :description, maximum: 255
|
validates_length_of :description, maximum: 255
|
||||||
validates :name, :uniqueness => true
|
validates :name, :uniqueness => true
|
||||||
|
|
|
@ -7,14 +7,16 @@ class HomeworkAttach < ActiveRecord::Base
|
||||||
belongs_to :bid
|
belongs_to :bid
|
||||||
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
|
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
|
||||||
has_many :homework_users, :dependent => :destroy
|
has_many :homework_users, :dependent => :destroy
|
||||||
|
has_many :users, :through => :homework_users
|
||||||
seems_rateable :allow_update => true, :dimensions => :quality
|
seems_rateable :allow_update => true, :dimensions => :quality
|
||||||
|
belongs_to :project
|
||||||
|
|
||||||
safe_attributes "bid_id",
|
safe_attributes "bid_id",
|
||||||
"user_id"
|
"user_id"
|
||||||
acts_as_attachable
|
acts_as_attachable
|
||||||
|
|
||||||
def addjours user_id,message,status = 0,is_comprehensive_evaluation = 0
|
def addjours user_id,message,status = 0,is_comprehensive_evaluation = 0,reply_id = 0
|
||||||
jfm = self.journals_for_messages.build(:user_id => user_id,:notes =>message,:status => status,:is_comprehensive_evaluation => is_comprehensive_evaluation)
|
jfm = self.journals_for_messages.build(:user_id => user_id,:notes =>message,:status => status,:is_comprehensive_evaluation => is_comprehensive_evaluation,:reply_id => reply_id)
|
||||||
jfm.save
|
jfm.save
|
||||||
jfm
|
jfm
|
||||||
end
|
end
|
||||||
|
@ -29,7 +31,7 @@ class HomeworkAttach < ActiveRecord::Base
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def project
|
def project_for_homework
|
||||||
work = HomeworkForCourse.find_by_bid_id(self.bid_id)
|
work = HomeworkForCourse.find_by_bid_id(self.bid_id)
|
||||||
if work
|
if work
|
||||||
work.project
|
work.project
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
class HomeworkForCourse < ActiveRecord::Base
|
class HomeworkForCourse < ActiveRecord::Base
|
||||||
attr_accessible :bid_id, :project_id
|
attr_accessible :bid_id, :course_id
|
||||||
|
|
||||||
belongs_to :bid
|
belongs_to :bid
|
||||||
belongs_to :project
|
belongs_to :course
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class HomeworkUser < ActiveRecord::Base
|
class HomeworkUser < ActiveRecord::Base
|
||||||
attr_accessible :homework_attach_id, :user_id
|
attr_accessible :homework_attach_id, :user_id
|
||||||
|
|
||||||
belongs_to :homework_attach
|
belongs_to :homework_attach, :foreign_key => :homework_attach_id
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
end
|
end
|
||||||
|
|
|
@ -76,7 +76,9 @@ class Issue < ActiveRecord::Base
|
||||||
attr_reader :current_journal
|
attr_reader :current_journal
|
||||||
|
|
||||||
# fq
|
# fq
|
||||||
after_create :act_as_activity
|
after_create :act_as_activity,:be_user_score_new_issue
|
||||||
|
after_update :be_user_score
|
||||||
|
# after_create :be_user_score
|
||||||
# end
|
# end
|
||||||
|
|
||||||
delegate :notes, :notes=, :private_notes, :private_notes=, :to => :current_journal, :allow_nil => true
|
delegate :notes, :notes=, :private_notes, :private_notes=, :to => :current_journal, :allow_nil => true
|
||||||
|
@ -988,13 +990,9 @@ class Issue < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
"#{tracker} ##{id}: #{subject}"
|
"#{tracker} ##{project_index}: #{subject}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# 缺陷在项目中的序号
|
|
||||||
def inProjectIndex
|
|
||||||
(self.project.issues.index(self).to_i + 1).to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns a string of css classes that apply to the issue
|
# Returns a string of css classes that apply to the issue
|
||||||
def css_classes
|
def css_classes
|
||||||
|
@ -1158,9 +1156,22 @@ class Issue < ActiveRecord::Base
|
||||||
"" << self.project.name.to_s <<
|
"" << self.project.name.to_s <<
|
||||||
"#" << project_index
|
"#" << project_index
|
||||||
end
|
end
|
||||||
|
|
||||||
def project_index
|
def project_index
|
||||||
(self.project.issues.index(self).to_i + 1).to_s
|
if self.project.issues.include?(self)
|
||||||
|
(self.project.issues.index(self).to_i + 1).to_s
|
||||||
|
else
|
||||||
|
issue_index = 1
|
||||||
|
self.project.issues.each do |issue|
|
||||||
|
if self.id == nil
|
||||||
|
issue_index = self.project.issues.count +1
|
||||||
|
break
|
||||||
|
elsif self.id > issue.id
|
||||||
|
issue_index = issue_index+1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
issue_index.to_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -1484,4 +1495,22 @@ class Issue < ActiveRecord::Base
|
||||||
and #{visible_condition(User.current, :project => project)}
|
and #{visible_condition(User.current, :project => project)}
|
||||||
group by s.id, s.is_closed, j.id")
|
group by s.id, s.is_closed, j.id")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# update user score
|
||||||
|
def be_user_score
|
||||||
|
#缺陷完成度更新
|
||||||
|
if self.done_ratio_changed?
|
||||||
|
UserScore.project(:update_issue_ratio, User.current,self,{ issue_id: self.id })
|
||||||
|
end
|
||||||
|
#缺陷状态更改
|
||||||
|
if self.status_id_changed?
|
||||||
|
#协同得分
|
||||||
|
UserScore.joint(:change_issue_status, User.current,nil,self, {issue_id: self.id})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
#发布缺陷
|
||||||
|
def be_user_score_new_issue
|
||||||
|
UserScore.project(:post_issue, User.current,self, { issue_id: self.id })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,7 +29,7 @@ class Journal < ActiveRecord::Base
|
||||||
# end
|
# end
|
||||||
attr_accessor :indice
|
attr_accessor :indice
|
||||||
|
|
||||||
acts_as_event :title =>Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.inProjectIndex}#{status}: #{o.issue.subject}" },
|
acts_as_event :title =>Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.project_index}#{status}: #{o.issue.subject}" },
|
||||||
:description =>:notes,
|
:description =>:notes,
|
||||||
:author => :user,
|
:author => :user,
|
||||||
:group => :issue,
|
:group => :issue,
|
||||||
|
@ -45,9 +45,12 @@ class Journal < ActiveRecord::Base
|
||||||
before_create :split_private_notes
|
before_create :split_private_notes
|
||||||
|
|
||||||
# fq
|
# fq
|
||||||
after_create :act_as_activity
|
after_create :act_as_activity,:be_user_score
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
#before_save :be_user_score
|
||||||
|
#before_destroy :down_user_score
|
||||||
|
|
||||||
scope :visible, lambda {|*args|
|
scope :visible, lambda {|*args|
|
||||||
user = args.shift || User.current
|
user = args.shift || User.current
|
||||||
|
|
||||||
|
@ -151,4 +154,21 @@ class Journal < ActiveRecord::Base
|
||||||
self.acts << Activity.new(:user_id => self.user_id)
|
self.acts << Activity.new(:user_id => self.user_id)
|
||||||
end
|
end
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
# 更新用户分数 -by zjc
|
||||||
|
def be_user_score
|
||||||
|
#新建了缺陷留言且留言不为空,不为空白
|
||||||
|
if !self.notes.nil? && self.notes.gsub(' ','') != ''
|
||||||
|
#协同得分加分
|
||||||
|
UserScore.joint(:post_issue_message, User.current,self.issue.author,self, { message_id: self.id })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# 减少用户分数 -by zjc
|
||||||
|
def down_user_score
|
||||||
|
#删除有效缺陷留言
|
||||||
|
if !self.notes.nil? && self.notes.gsub(' ','') != ''
|
||||||
|
#协同得分减分
|
||||||
|
UserScore.joint(:delete_issue_message, User.current,self.issue.author, { message_id: self.id })
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,9 +15,12 @@ class JournalsForMessage < ActiveRecord::Base
|
||||||
"m_reply_id" # 回复某留言的留言id(a留言回复了b留言,这是b留言的id)
|
"m_reply_id" # 回复某留言的留言id(a留言回复了b留言,这是b留言的id)
|
||||||
acts_as_tree :foreign_key => 'm_parent_id', :counter_cache => :m_reply_count, :order => "#{JournalsForMessage.table_name}.created_on ASC"
|
acts_as_tree :foreign_key => 'm_parent_id', :counter_cache => :m_reply_count, :order => "#{JournalsForMessage.table_name}.created_on ASC"
|
||||||
|
|
||||||
belongs_to :project,
|
belongs_to :project,
|
||||||
:foreign_key => 'jour_id',
|
:foreign_key => 'jour_id',
|
||||||
:conditions => "#{self.table_name}.jour_type = 'Project' "
|
:conditions => "#{self.table_name}.jour_type = 'Project' "
|
||||||
|
belongs_to :course,
|
||||||
|
:foreign_key => 'jour_id',
|
||||||
|
:conditions => "#{self.table_name}.jour_type = 'Course' "
|
||||||
|
|
||||||
belongs_to :jour, :polymorphic => true
|
belongs_to :jour, :polymorphic => true
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
@ -30,18 +33,30 @@ class JournalsForMessage < ActiveRecord::Base
|
||||||
:description => Proc.new{|o| o.notes },
|
:description => Proc.new{|o| o.notes },
|
||||||
:type => Proc.new {|o| o.jour_type },
|
:type => Proc.new {|o| o.jour_type },
|
||||||
:url => Proc.new {|o|
|
:url => Proc.new {|o|
|
||||||
(o.jour.kind_of? Project) ? {:controller => 'projects', :action => 'feedback', :id => o.jour, :r => o.id, :anchor => "word_li_#{o.id}"} : {}
|
if o.jour.kind_of? Project
|
||||||
}#{:controller => 'documents', :action => 'show', :id => o.id}}
|
{:controller => 'projects', :action => 'feedback', :id => o.jour, :r => o.id, :anchor => "word_li_#{o.id}"}
|
||||||
acts_as_activity_provider :author_key => :user_id,
|
elsif o.jour.kind_of? Course
|
||||||
|
{:controller => 'courses', :action => 'feedback', :id => o.jour, :r => o.id, :anchor => "word_li_#{o.id}"}
|
||||||
|
end
|
||||||
|
}
|
||||||
|
acts_as_activity_provider :author_key => :user_id,
|
||||||
:timestamp => "#{self.table_name}.updated_on",
|
:timestamp => "#{self.table_name}.updated_on",
|
||||||
:find_options => {:include => :project }
|
:find_options => {:include => :project }
|
||||||
|
|
||||||
|
acts_as_activity_provider :type => 'course_journals_for_messages',
|
||||||
|
:author_key => :user_id,
|
||||||
|
:timestamp => "#{self.table_name}.updated_on",
|
||||||
|
:find_options => {:include => :course }
|
||||||
|
|
||||||
|
|
||||||
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
|
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
|
||||||
|
|
||||||
validates :notes, presence: true
|
validates :notes, presence: true
|
||||||
after_create :act_as_activity #huang
|
after_create :act_as_activity #huang
|
||||||
after_create :reset_counters!
|
after_create :reset_counters!,:be_user_score
|
||||||
after_destroy :reset_counters!
|
after_destroy :reset_counters!
|
||||||
|
#before_save :be_user_score
|
||||||
|
#before_destroy :down_user_score
|
||||||
|
|
||||||
# default_scope { where('m_parent_id IS NULL') }
|
# default_scope { where('m_parent_id IS NULL') }
|
||||||
|
|
||||||
|
@ -87,6 +102,8 @@ class JournalsForMessage < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
elsif self.jour_type == 'Project'
|
elsif self.jour_type == 'Project'
|
||||||
self.acts << Activity.new(:user_id => self.reply_id)
|
self.acts << Activity.new(:user_id => self.reply_id)
|
||||||
|
elsif self.jour_type == 'Course'
|
||||||
|
self.acts << Activity.new(:user_id => self.reply_id)
|
||||||
else
|
else
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -99,4 +116,30 @@ class JournalsForMessage < ActiveRecord::Base
|
||||||
count = find_all_by_m_parent_id(journals_for_messages.m_parent_id).count #(SELECT COUNT(*) FROM #{JournalsForMessage.table_name} WHERE m_parent_id = #{jfm_id} )
|
count = find_all_by_m_parent_id(journals_for_messages.m_parent_id).count #(SELECT COUNT(*) FROM #{JournalsForMessage.table_name} WHERE m_parent_id = #{jfm_id} )
|
||||||
update_all("m_reply_count = #{count.to_i}", ["id = ?", journals_for_messages.m_parent_id])
|
update_all("m_reply_count = #{count.to_i}", ["id = ?", journals_for_messages.m_parent_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#如果是在项目中留言则返回该项目否则返回nil - zjc
|
||||||
|
def project
|
||||||
|
if self.jour_type == 'Project'
|
||||||
|
Project.find(self.jour_id)
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# 更新用户分数 -by zjc
|
||||||
|
def be_user_score
|
||||||
|
#新建了留言回复
|
||||||
|
if self.reply_id != 0
|
||||||
|
#协同得分加分
|
||||||
|
UserScore.joint(:reply_message, User.current,User.find(self.reply_id),self, { journals_for_messages_id: self.id })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# 更新用户分数 -by zjc
|
||||||
|
def down_user_score
|
||||||
|
#删除了留言回复
|
||||||
|
if self.reply_id != 0
|
||||||
|
#协同得分减分
|
||||||
|
UserScore.joint(:reply_message_delete, User.current,User.find(self.reply_id), { journals_for_messages_id: self.id })
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,26 +46,43 @@ class Mailer < ActionMailer::Base
|
||||||
when :Project
|
when :Project
|
||||||
return -1 if journals_for_message.jour.project_type == Project::ProjectType_project
|
return -1 if journals_for_message.jour.project_type == Project::ProjectType_project
|
||||||
project_feedback_url(journals_for_message.jour, anchor: "word_li_#{journals_for_message.id}")
|
project_feedback_url(journals_for_message.jour, anchor: "word_li_#{journals_for_message.id}")
|
||||||
|
when :Course
|
||||||
|
course_feedback_url(journals_for_message.jour, anchor: "word_li_#{journals_for_message.id}")
|
||||||
when :Contest
|
when :Contest
|
||||||
show_contest_contest_url(journals_for_message.jour, anchor: "word_li_#{journals_for_message.id}")
|
show_contest_contest_url(journals_for_message.jour, anchor: "word_li_#{journals_for_message.id}")
|
||||||
when :User
|
when :User
|
||||||
user_newfeedback_user_url(journals_for_message.jour, anchor: "word_li_#{journals_for_message.id}")
|
user_newfeedback_user_url(journals_for_message.jour, anchor: "word_li_#{journals_for_message.id}")
|
||||||
else
|
else
|
||||||
logger.error "[Builds a Mail::Message ERROR] journalsForMessage's jour is unkown type, journalsForMessage.id = #{journals_for_message.id}"
|
Rails.logger.error "[Builds a Mail::Message ERROR] journalsForMessage's jour is unkown type, journalsForMessage.id = #{journals_for_message.id}"
|
||||||
return -1
|
return -1
|
||||||
end
|
end
|
||||||
#如果是直接留言并且留言对象是Project并且Project类型是课程
|
# modify by nwb
|
||||||
if !journals_for_message.at_user && journals_for_message.jour.class.to_s.to_sym == :Project && journals_for_message.jour.project_type == 1
|
#如果是直接留言并且留言对象是课程
|
||||||
project = journals_for_message.jour
|
if !journals_for_message.at_user && journals_for_message.jour.class.to_s.to_sym == :Course
|
||||||
|
course = journals_for_message.jour
|
||||||
|
@author = journals_for_message.user
|
||||||
#课程的教师
|
#课程的教师
|
||||||
@teachers = searchTeacherAndAssistant journals_for_message.jour
|
@teachers = searchTeacherAndAssistant journals_for_message.jour
|
||||||
#收件人邮箱
|
#收件人邮箱
|
||||||
@recipients ||= []
|
@recipients ||= []
|
||||||
@teachers.each do |teacher|
|
@teachers.each do |teacher|
|
||||||
@recipients << teacher.user.mail
|
if teacher.user.notify_about? journals_for_message
|
||||||
|
@recipients << teacher.user.mail
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
mail :to => @recipients,
|
mail :to => @recipients,
|
||||||
:subject => "#{l(:label_your_course)}#{journals_for_message.jour.name}#{l(:label_have_message)} "
|
:subject => "#{l(:label_your_course)}#{journals_for_message.jour.name}#{l(:label_have_message)} "
|
||||||
|
elsif journals_for_message.jour.class.to_s.to_sym == :Bid
|
||||||
|
if !journals_for_message.jour.author.notify_about? journals_for_message
|
||||||
|
return -1
|
||||||
|
end
|
||||||
|
mail :to => journals_for_message.jour.author.mail, :subject => @title
|
||||||
|
elsif journals_for_message.jour.class.to_s.to_sym == :Contest
|
||||||
|
if !journals_for_message.jour.author.notify_about? journals_for_message
|
||||||
|
return -1
|
||||||
|
end
|
||||||
|
mail :to => journals_for_message.jour.author.mail, :subject => @title
|
||||||
else
|
else
|
||||||
mail :to => @mail.mail, :subject => @title
|
mail :to => @mail.mail, :subject => @title
|
||||||
end
|
end
|
||||||
|
@ -79,8 +96,9 @@ class Mailer < ActionMailer::Base
|
||||||
# issue_add(issue) => Mail::Message object
|
# issue_add(issue) => Mail::Message object
|
||||||
# Mailer.issue_add(issue).deliver => sends an email to issue recipients
|
# Mailer.issue_add(issue).deliver => sends an email to issue recipients
|
||||||
def issue_add(issue)
|
def issue_add(issue)
|
||||||
|
issue_id = issue.project_index
|
||||||
redmine_headers 'Project' => issue.project.identifier,
|
redmine_headers 'Project' => issue.project.identifier,
|
||||||
'Issue-Id' => (issue.project.issues.index(issue).to_i + 1).to_s,
|
'Issue-Id' => issue_id,
|
||||||
'Issue-Author' => issue.author.login
|
'Issue-Author' => issue.author.login
|
||||||
redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
|
redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
|
||||||
message_id issue
|
message_id issue
|
||||||
|
@ -91,7 +109,7 @@ class Mailer < ActionMailer::Base
|
||||||
cc = issue.watcher_recipients - recipients
|
cc = issue.watcher_recipients - recipients
|
||||||
mail :to => recipients,
|
mail :to => recipients,
|
||||||
:cc => cc,
|
:cc => cc,
|
||||||
:subject => "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}"
|
:subject => "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] (#{issue.status.name}) #{issue.subject}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Builds a Mail::Message object used to email recipients of the edited issue.
|
# Builds a Mail::Message object used to email recipients of the edited issue.
|
||||||
|
@ -101,8 +119,9 @@ class Mailer < ActionMailer::Base
|
||||||
# Mailer.issue_edit(journal).deliver => sends an email to issue recipients
|
# Mailer.issue_edit(journal).deliver => sends an email to issue recipients
|
||||||
def issue_edit(journal)
|
def issue_edit(journal)
|
||||||
issue = journal.journalized.reload
|
issue = journal.journalized.reload
|
||||||
|
issue_id = issue.project_index
|
||||||
redmine_headers 'Project' => issue.project.identifier,
|
redmine_headers 'Project' => issue.project.identifier,
|
||||||
'Issue-Id' => (issue.project.issues.index(issue).to_i + 1).to_s,
|
'Issue-Id' => issue_id.to_s,
|
||||||
'Issue-Author' => issue.author.login
|
'Issue-Author' => issue.author.login
|
||||||
redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
|
redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
|
||||||
message_id journal
|
message_id journal
|
||||||
|
@ -111,7 +130,7 @@ class Mailer < ActionMailer::Base
|
||||||
recipients = journal.recipients
|
recipients = journal.recipients
|
||||||
# Watchers in cc
|
# Watchers in cc
|
||||||
cc = journal.watcher_recipients - recipients
|
cc = journal.watcher_recipients - recipients
|
||||||
s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] "
|
s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] "
|
||||||
s << "(#{issue.status.name}) " if journal.new_value_for('status_id')
|
s << "(#{issue.status.name}) " if journal.new_value_for('status_id')
|
||||||
s << issue.subject
|
s << issue.subject
|
||||||
@issue = issue
|
@issue = issue
|
||||||
|
@ -440,10 +459,7 @@ class Mailer < ActionMailer::Base
|
||||||
headers[:to].delete(@author.mail) if headers[:to].is_a?(Array)
|
headers[:to].delete(@author.mail) if headers[:to].is_a?(Array)
|
||||||
headers[:cc].delete(@author.mail) if headers[:cc].is_a?(Array)
|
headers[:cc].delete(@author.mail) if headers[:cc].is_a?(Array)
|
||||||
end
|
end
|
||||||
if !User.current.nil?
|
|
||||||
#不给本人发邮件
|
|
||||||
headers[:to].delete(User.current.mail) if headers[:to].is_a?(Array)
|
|
||||||
end
|
|
||||||
if @author && @author.logged?
|
if @author && @author.logged?
|
||||||
redmine_headers 'Sender' => @author.login
|
redmine_headers 'Sender' => @author.login
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,9 +22,10 @@ class Member < ActiveRecord::Base
|
||||||
has_many :roles, :through => :member_roles
|
has_many :roles, :through => :member_roles
|
||||||
|
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
|
belongs_to :course
|
||||||
|
|
||||||
validates_presence_of :principal, :project
|
validates_presence_of :principal
|
||||||
validates_uniqueness_of :user_id, :scope => :project_id
|
validates_uniqueness_of :user_id, :scope => [:project_id,:course_id]
|
||||||
validate :validate_role
|
validate :validate_role
|
||||||
|
|
||||||
before_destroy :set_issue_category_nil
|
before_destroy :set_issue_category_nil
|
||||||
|
@ -85,7 +86,13 @@ class Member < ActiveRecord::Base
|
||||||
def set_issue_category_nil
|
def set_issue_category_nil
|
||||||
if user
|
if user
|
||||||
# remove category based auto assignments for this member
|
# remove category based auto assignments for this member
|
||||||
IssueCategory.update_all "assigned_to_id = NULL", ["project_id = ? AND assigned_to_id = ?", project.id, user.id]
|
#modify by nwb
|
||||||
|
if project
|
||||||
|
IssueCategory.update_all "assigned_to_id = NULL", ["project_id = ? AND assigned_to_id = ?", project.id, user.id]
|
||||||
|
elsif course
|
||||||
|
#IssueCategory.update_all "assigned_to_id = NULL", ["course_id = ? AND assigned_to_id = ?", course.id, user.id]
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -54,14 +54,16 @@ class MemberRole < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_role_to_subprojects
|
def add_role_to_subprojects
|
||||||
member.project.children.each do |subproject|
|
if member.project
|
||||||
if subproject.inherit_members?
|
member.project.children.each do |subproject|
|
||||||
child_member = Member.find_or_new(subproject.id, member.user_id)
|
if subproject.inherit_members?
|
||||||
child_member.member_roles << MemberRole.new(:role => role, :inherited_from => id)
|
child_member = Member.find_or_new(subproject.id, member.user_id)
|
||||||
child_member.save!
|
child_member.member_roles << MemberRole.new(:role => role, :inherited_from => id)
|
||||||
|
child_member.save!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_inherited_roles
|
def remove_inherited_roles
|
||||||
MemberRole.where(:inherited_from => id).all.group_by(&:member).each do |member, member_roles|
|
MemberRole.where(:inherited_from => id).all.group_by(&:member).each do |member, member_roles|
|
||||||
|
|
|
@ -3,15 +3,16 @@ class Memo < ActiveRecord::Base
|
||||||
belongs_to :forum
|
belongs_to :forum
|
||||||
belongs_to :author, :class_name => "User", :foreign_key => 'author_id'
|
belongs_to :author, :class_name => "User", :foreign_key => 'author_id'
|
||||||
|
|
||||||
validates_presence_of :author_id, :forum_id, :subject
|
validates_presence_of :author_id, :forum_id, :subject,:content
|
||||||
# 若是主题帖,则内容可以是空
|
# 若是主题帖,则内容可以是空
|
||||||
validates :content, presence: true, if: Proc.new{|o| !o.parent_id.nil? }
|
#validates :content, presence: true, if: Proc.new{|o| !o.parent_id.nil? }
|
||||||
validates_length_of :subject, maximum: 50
|
validates_length_of :subject, maximum: 50
|
||||||
validates_length_of :content, maximum: 3072
|
validates_length_of :content, maximum: 3072
|
||||||
validate :cannot_reply_to_locked_topic, :on => :create
|
validate :cannot_reply_to_locked_topic, :on => :create
|
||||||
|
|
||||||
acts_as_tree :counter_cache => :replies_count, :order => "#{Memo.table_name}.created_at ASC"
|
acts_as_tree :counter_cache => :replies_count, :order => "#{Memo.table_name}.created_at ASC"
|
||||||
acts_as_attachable
|
acts_as_attachable
|
||||||
|
has_many :user_score_details, :class_name => 'UserScoreDetails',:as => :score_changeable_obj
|
||||||
belongs_to :last_reply, :class_name => 'Memo', :foreign_key => 'last_reply_id'
|
belongs_to :last_reply, :class_name => 'Memo', :foreign_key => 'last_reply_id'
|
||||||
# acts_as_searchable :column => ['subject', 'content'],
|
# acts_as_searchable :column => ['subject', 'content'],
|
||||||
# #:include => { :forum => :p}
|
# #:include => { :forum => :p}
|
||||||
|
@ -40,13 +41,13 @@ class Memo < ActiveRecord::Base
|
||||||
"parent_id",
|
"parent_id",
|
||||||
"replies_count"
|
"replies_count"
|
||||||
|
|
||||||
after_create :add_author_as_watcher, :reset_counters!
|
after_create :add_author_as_watcher, :reset_counters!,:be_user_score
|
||||||
# after_update :update_memos_forum
|
# after_update :update_memos_forum
|
||||||
after_destroy :reset_counters!
|
after_destroy :reset_counters!
|
||||||
# after_create :send_notification
|
# after_create :send_notification
|
||||||
# after_save :plusParentAndForum
|
# after_save :plusParentAndForum
|
||||||
# after_destroy :minusParentAndForum
|
# after_destroy :minusParentAndForum
|
||||||
|
#before_save :be_user_score
|
||||||
# scope :visible, lambda { |*args|
|
# scope :visible, lambda { |*args|
|
||||||
# includes(:forum => ).where()
|
# includes(:forum => ).where()
|
||||||
# }
|
# }
|
||||||
|
@ -140,5 +141,17 @@ class Memo < ActiveRecord::Base
|
||||||
@forum.topic_count = 0 if @forum.topic_count.to_int < 0
|
@forum.topic_count = 0 if @forum.topic_count.to_int < 0
|
||||||
end
|
end
|
||||||
@forum.save
|
@forum.save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#更新用户分数 -by zjc
|
||||||
|
def be_user_score
|
||||||
|
#新建memo且无parent的为发帖
|
||||||
|
if self.parent_id.nil?
|
||||||
|
UserScore.joint(:post_message, User.current,nil,self ,{ memo_id: self.id })
|
||||||
|
#新建memo且有parent的为回帖
|
||||||
|
elsif !self.parent_id.nil?
|
||||||
|
UserScore.joint(:reply_posting, User.current,self.parent.author,self, { memo_id: self.id })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,6 +31,10 @@ class Message < ActiveRecord::Base
|
||||||
:include => {:board => :project},
|
:include => {:board => :project},
|
||||||
:project_key => "#{Board.table_name}.project_id",
|
:project_key => "#{Board.table_name}.project_id",
|
||||||
:date_column => "#{table_name}.created_on"
|
:date_column => "#{table_name}.created_on"
|
||||||
|
acts_as_searchable :columns => ['subject', 'content'],
|
||||||
|
:include => {:board => :course},
|
||||||
|
:course_key => "#{Board.table_name}.course_id",
|
||||||
|
:date_column => "#{table_name}.created_at"
|
||||||
acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"},
|
acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"},
|
||||||
:description => :content,
|
:description => :content,
|
||||||
:datetime => :updated_on,
|
:datetime => :updated_on,
|
||||||
|
@ -42,6 +46,9 @@ class Message < ActiveRecord::Base
|
||||||
|
|
||||||
acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]},
|
acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]},
|
||||||
:author_key => :author_id
|
:author_key => :author_id
|
||||||
|
acts_as_activity_provider :find_options => {:include => [{:board => :course}, :author]},
|
||||||
|
:type => 'course_messages',
|
||||||
|
:author_key => :author_id
|
||||||
acts_as_watchable
|
acts_as_watchable
|
||||||
|
|
||||||
validates_presence_of :board, :subject, :content
|
validates_presence_of :board, :subject, :content
|
||||||
|
@ -53,13 +60,20 @@ class Message < ActiveRecord::Base
|
||||||
after_destroy :reset_counters!
|
after_destroy :reset_counters!
|
||||||
|
|
||||||
# fq
|
# fq
|
||||||
after_create :act_as_activity
|
after_create :act_as_activity,:be_user_score
|
||||||
|
#before_save :be_user_score
|
||||||
|
#before_destroy :down_user_score
|
||||||
# end
|
# end
|
||||||
|
|
||||||
scope :visible, lambda {|*args|
|
scope :visible, lambda {|*args|
|
||||||
includes(:board => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *args))
|
includes(:board => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *args))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scope :course_visible, lambda {|*args|
|
||||||
|
includes(:board => :course).where(Course.allowed_to_condition(args.shift || User.current, :view_course_messages, *args))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
safe_attributes 'subject', 'content'
|
safe_attributes 'subject', 'content'
|
||||||
safe_attributes 'locked', 'sticky', 'board_id',
|
safe_attributes 'locked', 'sticky', 'board_id',
|
||||||
:if => lambda {|message, user|
|
:if => lambda {|message, user|
|
||||||
|
@ -67,7 +81,11 @@ class Message < ActiveRecord::Base
|
||||||
}
|
}
|
||||||
|
|
||||||
def visible?(user=User.current)
|
def visible?(user=User.current)
|
||||||
!user.nil? && user.allowed_to?(:view_messages, project)
|
if project
|
||||||
|
!user.nil? && user.allowed_to?(:view_messages, project)
|
||||||
|
elsif course
|
||||||
|
!user.nil? && user.allowed_to?(:view_messages, course)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def cannot_reply_to_locked_topic
|
def cannot_reply_to_locked_topic
|
||||||
|
@ -102,6 +120,10 @@ class Message < ActiveRecord::Base
|
||||||
board.project
|
board.project
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def course
|
||||||
|
board.course
|
||||||
|
end
|
||||||
|
|
||||||
def editable_by?(usr)
|
def editable_by?(usr)
|
||||||
usr && usr.logged? && (usr.allowed_to?(:edit_messages, project) || (self.author == usr && usr.allowed_to?(:edit_own_messages, project)))
|
usr && usr.logged? && (usr.allowed_to?(:edit_messages, project) || (self.author == usr && usr.allowed_to?(:edit_own_messages, project)))
|
||||||
end
|
end
|
||||||
|
@ -121,4 +143,25 @@ class Message < ActiveRecord::Base
|
||||||
self.acts << Activity.new(:user_id => self.author_id)
|
self.acts << Activity.new(:user_id => self.author_id)
|
||||||
end
|
end
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
#更新用户分数 -by zjc
|
||||||
|
def be_user_score
|
||||||
|
#新建message且无parent的为发帖
|
||||||
|
if self.parent_id.nil?
|
||||||
|
UserScore.joint(:post_message, User.current,nil,self, { message_id: self.id })
|
||||||
|
#新建message且有parent的为回帖
|
||||||
|
elsif !self.parent_id.nil?
|
||||||
|
UserScore.joint(:reply_posting, User.current,self.parent.author,self, { message_id: self.id })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
#减少用户分数
|
||||||
|
def down_user_score
|
||||||
|
#删除发帖
|
||||||
|
if self.parent_id.nil?
|
||||||
|
UserScore.joint(:delete_message, User.current,nil, { message_id: self.id })
|
||||||
|
#删除留言
|
||||||
|
else
|
||||||
|
UserScore.joint(:reply_deleting, User.current,self.parent.author, { message_id: self.id })
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
class News < ActiveRecord::Base
|
class News < ActiveRecord::Base
|
||||||
include Redmine::SafeAttributes
|
include Redmine::SafeAttributes
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
|
#added by nwb
|
||||||
|
belongs_to :course
|
||||||
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
||||||
has_many :comments, :as => :commented, :dependent => :delete_all, :order => "created_on"
|
has_many :comments, :as => :commented, :dependent => :delete_all, :order => "created_on"
|
||||||
# fq
|
# fq
|
||||||
|
@ -33,6 +35,11 @@ class News < ActiveRecord::Base
|
||||||
acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}}
|
acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}}
|
||||||
acts_as_activity_provider :find_options => {:include => [:project, :author]},
|
acts_as_activity_provider :find_options => {:include => [:project, :author]},
|
||||||
:author_key => :author_id
|
:author_key => :author_id
|
||||||
|
#added by nwb
|
||||||
|
#课程新闻独立于项目
|
||||||
|
acts_as_activity_provider :type => 'course_news',
|
||||||
|
:find_options => {:include => [:course, :author]},
|
||||||
|
:author_key => :author_id
|
||||||
acts_as_watchable
|
acts_as_watchable
|
||||||
|
|
||||||
after_create :add_author_as_watcher
|
after_create :add_author_as_watcher
|
||||||
|
@ -44,6 +51,9 @@ class News < ActiveRecord::Base
|
||||||
includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args))
|
includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scope :course_visible, lambda {|*args|
|
||||||
|
includes(:course).where(Course.allowed_to_condition(args.shift || User.current, :view_course_news, *args))
|
||||||
|
}
|
||||||
safe_attributes 'title', 'summary', 'description'
|
safe_attributes 'title', 'summary', 'description'
|
||||||
|
|
||||||
def visible?(user=User.current)
|
def visible?(user=User.current)
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
class Notificationcomment < ActiveRecord::Base
|
||||||
|
attr_accessible :author_id, :notificationcommented_id, :notificationcommented_type, :notificationcomments
|
||||||
|
|
||||||
|
include Redmine::SafeAttributes
|
||||||
|
belongs_to :notificationcommented, :polymorphic => true#, :counter_cache => true
|
||||||
|
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
||||||
|
|
||||||
|
validates_presence_of :notificationcommented, :author, :notificationcomments
|
||||||
|
|
||||||
|
# safe_attributes 'notificationcomments'
|
||||||
|
end
|
|
@ -2,5 +2,53 @@ class PraiseTread < ActiveRecord::Base
|
||||||
attr_accessible :user_id,:praise_tread_object_id,:praise_tread_object_type,:praise_or_tread
|
attr_accessible :user_id,:praise_tread_object_id,:praise_tread_object_type,:praise_or_tread
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :praise_tread_object, polymorphic: true
|
belongs_to :praise_tread_object, polymorphic: true
|
||||||
|
after_create :be_user_score
|
||||||
|
|
||||||
|
def self.find_object_by_type_and_id(type,id)
|
||||||
|
@obj = nil
|
||||||
|
case type
|
||||||
|
when 'User'
|
||||||
|
@obj = User.find_by_id(id)
|
||||||
|
when 'Issue'
|
||||||
|
@obj = Issue.find_by_id(id)
|
||||||
|
when 'Project'
|
||||||
|
@obj = Project.find_by_id(id)
|
||||||
|
when 'Bid'
|
||||||
|
@obj = Bid.find_by_id(id)
|
||||||
|
when 'Contest'
|
||||||
|
@obj = Contest.find_by_id(id)
|
||||||
|
when 'Memo'
|
||||||
|
@obj = Memo.find_by_id(id)
|
||||||
|
when 'Message'
|
||||||
|
@obj = Message.find_by_id(id)
|
||||||
|
end
|
||||||
|
return @obj
|
||||||
|
end
|
||||||
|
|
||||||
|
# 获取裁定对象为Message时Message所属的项目或课程
|
||||||
|
def project
|
||||||
|
project = nil
|
||||||
|
if self.praise_tread_object_type == 'Message'
|
||||||
|
obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id)
|
||||||
|
project = obj.project
|
||||||
|
end
|
||||||
|
project
|
||||||
|
end
|
||||||
|
|
||||||
|
#更新用户分数 - by zjc
|
||||||
|
def be_user_score
|
||||||
|
#踩贴吧或讨论区帖子
|
||||||
|
if self.praise_or_tread == 0 && (self.praise_tread_object_type == 'Memo' || self.praise_tread_object_type == 'Message')
|
||||||
|
obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id)
|
||||||
|
target_user = obj.author
|
||||||
|
UserScore.skill(:treaded_by_user, User.current,target_user,self, { praise_tread_id: self.id })
|
||||||
|
#顶贴吧或讨论区帖子
|
||||||
|
elsif self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Memo' || self.praise_tread_object_type == 'Message')
|
||||||
|
obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id)
|
||||||
|
target_user = obj.author
|
||||||
|
UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id })
|
||||||
|
#更新用户等级
|
||||||
|
UserLevels.update_user_level(target_user)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,7 +26,10 @@ class Principal < ActiveRecord::Base
|
||||||
|
|
||||||
has_many :members, :foreign_key => 'user_id', :dependent => :destroy
|
has_many :members, :foreign_key => 'user_id', :dependent => :destroy
|
||||||
has_many :memberships, :class_name => 'Member', :foreign_key => 'user_id', :include => [ :project, :roles ], :conditions => "#{Project.table_name}.status<>#{Project::STATUS_ARCHIVED}", :order => "#{Project.table_name}.name"
|
has_many :memberships, :class_name => 'Member', :foreign_key => 'user_id', :include => [ :project, :roles ], :conditions => "#{Project.table_name}.status<>#{Project::STATUS_ARCHIVED}", :order => "#{Project.table_name}.name"
|
||||||
|
has_many :coursememberships, :class_name => 'Member', :foreign_key => 'user_id', :include => [ :course, :roles ], :conditions => "#{Course.table_name}.status<>#{Course::STATUS_ARCHIVED}", :order => "#{Course.table_name}.name"
|
||||||
has_many :projects, :through => :memberships
|
has_many :projects, :through => :memberships
|
||||||
|
#add by nwb
|
||||||
|
has_many :courses, :through => :coursememberships
|
||||||
has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify
|
has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify
|
||||||
|
|
||||||
# Groups and active users
|
# Groups and active users
|
||||||
|
@ -70,6 +73,17 @@ class Principal < ActiveRecord::Base
|
||||||
where("#{Principal.table_name}.id NOT IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids)
|
where("#{Principal.table_name}.id NOT IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scope :not_member_of_course, lambda {|courses|
|
||||||
|
courses = [courses] unless courses.is_a?(Array)
|
||||||
|
if courses.empty?
|
||||||
|
where("1=0")
|
||||||
|
else
|
||||||
|
ids = courses.map(&:id)
|
||||||
|
where("#{Principal.table_name}.id NOT IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE course_id IN (?))", ids)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
scope :sorted, lambda { order(*Principal.fields_for_order_statement)}
|
scope :sorted, lambda { order(*Principal.fields_for_order_statement)}
|
||||||
|
|
||||||
scope :applied_members, lambda {|project|
|
scope :applied_members, lambda {|project|
|
||||||
|
|
|
@ -30,6 +30,7 @@ class Project < ActiveRecord::Base
|
||||||
|
|
||||||
# Specific overidden Activities
|
# Specific overidden Activities
|
||||||
|
|
||||||
|
belongs_to :homework_attach
|
||||||
has_many :time_entry_activities
|
has_many :time_entry_activities
|
||||||
has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}"
|
has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}"
|
||||||
has_many :memberships, :class_name => 'Member'
|
has_many :memberships, :class_name => 'Member'
|
||||||
|
@ -38,9 +39,9 @@ class Project < ActiveRecord::Base
|
||||||
:conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})"
|
:conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})"
|
||||||
has_many :users, :through => :members
|
has_many :users, :through => :members
|
||||||
has_many :principals, :through => :member_principals, :source => :principal
|
has_many :principals, :through => :member_principals, :source => :principal
|
||||||
has_many :enabled_modules, :dependent => :delete_all
|
has_many :enabled_modules, :dependent => :delete_all
|
||||||
has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
|
has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
|
||||||
has_many :issues, :dependent => :destroy, :include => [:status, :tracker]
|
has_many :issues, :dependent => :destroy, :include => [:status, :tracker] , :order => "id ASC"
|
||||||
has_many :issue_changes, :through => :issues, :source => :journals
|
has_many :issue_changes, :through => :issues, :source => :journals
|
||||||
has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC"
|
has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC"
|
||||||
has_many :time_entries, :dependent => :delete_all
|
has_many :time_entries, :dependent => :delete_all
|
||||||
|
@ -112,6 +113,7 @@ class Project < ActiveRecord::Base
|
||||||
|
|
||||||
validates_presence_of :name, :identifier
|
validates_presence_of :name, :identifier
|
||||||
validates_uniqueness_of :identifier
|
validates_uniqueness_of :identifier
|
||||||
|
validates_uniqueness_of :name
|
||||||
validates_associated :repository, :wiki
|
validates_associated :repository, :wiki
|
||||||
# validates_length_of :description, :maximum => 255
|
# validates_length_of :description, :maximum => 255
|
||||||
validates_length_of :name, :maximum => 255
|
validates_length_of :name, :maximum => 255
|
||||||
|
@ -1129,17 +1131,13 @@ class Project < ActiveRecord::Base
|
||||||
# 创建项目后在项目下同步创建一个讨论区
|
# 创建项目后在项目下同步创建一个讨论区
|
||||||
def create_board_sync
|
def create_board_sync
|
||||||
@board = self.boards.build
|
@board = self.boards.build
|
||||||
if project_type == 1
|
self.name=" #{l(:label_borad_course) }"
|
||||||
self.name=" #{l(:label_borad_course) }"
|
|
||||||
else
|
|
||||||
self.name =" #{l(:label_borad_project) }"
|
|
||||||
end
|
|
||||||
@board.name = self.name
|
@board.name = self.name
|
||||||
@board.description = self.name.to_s
|
@board.description = self.name.to_s
|
||||||
if @board.save
|
if @board.save
|
||||||
logger.debug "[Project Model] ===> #{@board.to_json}"
|
logger.debug "[Course Model] ===> #{@board.to_json}"
|
||||||
else
|
else
|
||||||
logger.error "[Project Model] ===> Auto create board when project saved, because #{@board.full_messages}"
|
logger.error "[Course Model] ===> Auto create board when Course saved, because #{@board.full_messages}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ class ProjectInfo < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
validates_presence_of :project_id, :user_id
|
validates_presence_of :project_id, :user_id
|
||||||
validates_uniqueness_of :project_id, :scope => :user_id
|
validates_uniqueness_of :project_id, :scope => :user_id
|
||||||
|
after_save :update_user_level
|
||||||
def self.manager? (user_id, project)
|
def self.manager? (user_id, project)
|
||||||
for project_info in project.project_infos
|
for project_info in project.project_infos
|
||||||
if project_info.user_id == user_id
|
if project_info.user_id == user_id
|
||||||
|
@ -14,4 +14,9 @@ class ProjectInfo < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#更新用户等级
|
||||||
|
def update_user_level
|
||||||
|
UserLevels.update_user_level(self.user)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,11 +38,11 @@ class Repository < ActiveRecord::Base
|
||||||
|
|
||||||
validates_length_of :password, :maximum => 255, :allow_nil => true
|
validates_length_of :password, :maximum => 255, :allow_nil => true
|
||||||
validates_length_of :identifier, :maximum => IDENTIFIER_MAX_LENGTH, :allow_blank => true
|
validates_length_of :identifier, :maximum => IDENTIFIER_MAX_LENGTH, :allow_blank => true
|
||||||
validates_presence_of :identifier, :unless => Proc.new { |r| r.is_default? || r.set_as_default? }
|
validates_presence_of :identifier#, :unless => Proc.new { |r| r.is_default? || r.set_as_default? }
|
||||||
validates_uniqueness_of :identifier, :scope => :project_id, :allow_blank => true
|
validates_uniqueness_of :identifier, :scope => :project_id, :allow_blank => true
|
||||||
validates_exclusion_of :identifier, :in => %w(show entry raw changes annotate diff show stats graph)
|
validates_exclusion_of :identifier, :in => %w(show entry raw changes annotate diff show stats graph)
|
||||||
# donwcase letters, digits, dashes, underscores but not digits only
|
# donwcase letters, digits, dashes, underscores but not digits only
|
||||||
validates_format_of :identifier, :with => /\A(?!\d+$)[a-z0-9\-_]*\z/, :allow_blank => true
|
validates_format_of :identifier, :with => /^[a-zA-Z0-9_\-]+$/, :allow_blank => true
|
||||||
# Checks if the SCM is enabled when creating a repository
|
# Checks if the SCM is enabled when creating a repository
|
||||||
validate :repo_create_validation, :on => :create
|
validate :repo_create_validation, :on => :create
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,7 @@ class Role < ActiveRecord::Base
|
||||||
if action.is_a? Hash
|
if action.is_a? Hash
|
||||||
allowed_actions.include? "#{action[:controller]}/#{action[:action]}"
|
allowed_actions.include? "#{action[:controller]}/#{action[:action]}"
|
||||||
else
|
else
|
||||||
allowed_permissions.include? action
|
allowed_permissions.include? action
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
class StudentsForCourse < ActiveRecord::Base
|
class StudentsForCourse < ActiveRecord::Base
|
||||||
attr_accessible :course_id, :student_id
|
attr_accessible :course_id, :student_id
|
||||||
|
|
||||||
belongs_to :course, :class_name => 'Project', :foreign_key => :course_id
|
belongs_to :course, :class_name => 'Course', :foreign_key => :course_id
|
||||||
|
|
||||||
belongs_to :student, :class_name => 'User', :foreign_key => :student_id
|
belongs_to :student, :class_name => 'User', :foreign_key => :student_id
|
||||||
|
|
||||||
validates_presence_of :course_id, :student_id
|
validates_presence_of :course_id, :student_id
|
||||||
|
|
|
@ -73,7 +73,8 @@ class User < Principal
|
||||||
['none', :label_user_mail_option_none]
|
['none', :label_user_mail_option_none]
|
||||||
]
|
]
|
||||||
|
|
||||||
belongs_to :homework_user
|
has_many :homework_users
|
||||||
|
has_many :homework_attaches, :through => :homework_users
|
||||||
|
|
||||||
has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)},
|
has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)},
|
||||||
:after_remove => Proc.new {|user, group| group.user_removed(user)}
|
:after_remove => Proc.new {|user, group| group.user_removed(user)}
|
||||||
|
@ -86,8 +87,6 @@ class User < Principal
|
||||||
## added by xianbo for delete
|
## added by xianbo for delete
|
||||||
has_many :biding_projects, :dependent => :destroy
|
has_many :biding_projects, :dependent => :destroy
|
||||||
has_many :contesting_projects, :dependent => :destroy
|
has_many :contesting_projects, :dependent => :destroy
|
||||||
has_many :contesting_softapplications, :dependent => :destroy
|
|
||||||
has_many :projecting_softapplications, :dependent => :destroy
|
|
||||||
belongs_to :softapplication, :foreign_key => 'id', :dependent => :destroy
|
belongs_to :softapplication, :foreign_key => 'id', :dependent => :destroy
|
||||||
##ended by xianbo
|
##ended by xianbo
|
||||||
|
|
||||||
|
@ -102,18 +101,21 @@ class User < Principal
|
||||||
has_many :journal_replies, :dependent => :destroy
|
has_many :journal_replies, :dependent => :destroy
|
||||||
has_many :activities, :dependent => :destroy
|
has_many :activities, :dependent => :destroy
|
||||||
has_many :students_for_courses
|
has_many :students_for_courses
|
||||||
has_many :courses, :through => :students_for_courses, :source => :project
|
#has_many :courses, :through => :students_for_courses, :source => :project
|
||||||
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
|
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
|
||||||
has_many :file_commit, :class_name => 'Attachment', :foreign_key => 'author_id', :conditions => "container_type = 'Project' or container_type = 'Version'"
|
has_many :file_commit, :class_name => 'Attachment', :foreign_key => 'author_id', :conditions => "container_type = 'Project' or container_type = 'Version'"
|
||||||
####
|
####
|
||||||
# added by bai
|
# added by bai
|
||||||
has_many :join_in_contests, :dependent => :destroy
|
has_many :join_in_contests, :dependent => :destroy
|
||||||
has_many :news, :foreign_key => 'author_id'
|
has_many :news, :foreign_key => 'author_id'
|
||||||
|
has_many :contestnotification, :foreign_key => 'author_id'
|
||||||
has_many :comments, :foreign_key => 'author_id'
|
has_many :comments, :foreign_key => 'author_id'
|
||||||
|
has_many :notificationcomments, :foreign_key => 'author_id'
|
||||||
has_many :wiki_contents, :foreign_key => 'author_id'
|
has_many :wiki_contents, :foreign_key => 'author_id'
|
||||||
has_many :journals
|
has_many :journals
|
||||||
has_many :messages, :foreign_key => 'author_id'
|
has_many :messages, :foreign_key => 'author_id'
|
||||||
has_one :user_score, :dependent => :destroy
|
has_one :user_score, :dependent => :destroy
|
||||||
|
has_many :documents # 项目中关联的文档再次与人关联
|
||||||
# end
|
# end
|
||||||
|
|
||||||
######added by nie
|
######added by nie
|
||||||
|
@ -122,6 +124,10 @@ class User < Principal
|
||||||
#####
|
#####
|
||||||
has_many :shares ,:dependent => :destroy
|
has_many :shares ,:dependent => :destroy
|
||||||
|
|
||||||
|
# add by zjc
|
||||||
|
has_one :level, :class_name => 'UserLevels', :dependent => :destroy
|
||||||
|
has_many :memos , :foreign_key => 'author_id'
|
||||||
|
#####
|
||||||
scope :logged, lambda { where("#{User.table_name}.status <> #{STATUS_ANONYMOUS}") }
|
scope :logged, lambda { where("#{User.table_name}.status <> #{STATUS_ANONYMOUS}") }
|
||||||
scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) }
|
scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) }
|
||||||
scope :visible, lambda {|*args|
|
scope :visible, lambda {|*args|
|
||||||
|
@ -139,6 +145,7 @@ class User < Principal
|
||||||
has_one :user_extensions,:dependent => :destroy
|
has_one :user_extensions,:dependent => :destroy
|
||||||
## end
|
## end
|
||||||
|
|
||||||
|
# default_scope -> { includes(:user_extensions, :user_score) }
|
||||||
scope :teacher, -> {
|
scope :teacher, -> {
|
||||||
joins(:user_extensions).where('user_extensions.identity = ?', UserExtensions::TEACHER)
|
joins(:user_extensions).where('user_extensions.identity = ?', UserExtensions::TEACHER)
|
||||||
}
|
}
|
||||||
|
@ -157,7 +164,7 @@ class User < Principal
|
||||||
# Prevents unauthorized assignments
|
# Prevents unauthorized assignments
|
||||||
attr_protected :login, :admin, :password, :password_confirmation, :hashed_password
|
attr_protected :login, :admin, :password, :password_confirmation, :hashed_password
|
||||||
|
|
||||||
LOGIN_LENGTH_LIMIT = 60
|
LOGIN_LENGTH_LIMIT = 25
|
||||||
MAIL_LENGTH_LIMIT = 60
|
MAIL_LENGTH_LIMIT = 60
|
||||||
|
|
||||||
validates_presence_of :login, :firstname, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) }
|
validates_presence_of :login, :firstname, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) }
|
||||||
|
@ -195,10 +202,71 @@ class User < Principal
|
||||||
where(nil)
|
where(nil)
|
||||||
else
|
else
|
||||||
pattern = "%#{arg.to_s.strip.downcase}%"
|
pattern = "%#{arg.to_s.strip.downcase}%"
|
||||||
where(" LOWER(concat(lastname, firstname)) LIKE :p ", :p => pattern)
|
#where(" LOWER(concat(lastname, firstname)) LIKE :p ", :p => pattern)
|
||||||
|
where(" LOWER(login) LIKE :p ", :p => pattern)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# ======================================================================
|
||||||
|
# 集中处理 User 扩展表为空的问题
|
||||||
|
# 合并 user_score 属性
|
||||||
|
validate :valid_user_extensions
|
||||||
|
after_save :save_user_extensions
|
||||||
|
|
||||||
|
def extensions
|
||||||
|
self.user_extensions ||= UserExtensions.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def user_score_attr
|
||||||
|
self.user_score ||= UserScore.new
|
||||||
|
end
|
||||||
|
|
||||||
|
alias_method :ori_respond_to?, :respond_to?
|
||||||
|
def respond_to?(m, include_private = false)
|
||||||
|
flag = false
|
||||||
|
flag = ori_respond_to? m.to_sym unless flag
|
||||||
|
flag = UserExtensions.new.respond_to? m.to_sym unless flag
|
||||||
|
flag = UserScore.new.respond_to? m.to_sym unless flag
|
||||||
|
|
||||||
|
flag
|
||||||
|
end
|
||||||
|
|
||||||
|
def method_missing m, *args, &block
|
||||||
|
if extensions.respond_to? m.to_sym
|
||||||
|
self.class.send(:define_method, "_meta_#{m}".to_sym) do |*args, &block|
|
||||||
|
self.extensions.__send__ m.to_sym, *args
|
||||||
|
end
|
||||||
|
__send__ "_meta_#{m}".to_sym, *args, &block
|
||||||
|
|
||||||
|
elsif user_score_attr.respond_to? m.to_sym
|
||||||
|
self.class.send(:define_method, "_meta_#{m}".to_sym) do |*args, &block|
|
||||||
|
self.user_score_attr.__send__ m.to_sym, *args
|
||||||
|
end
|
||||||
|
__send__ "_meta_#{m}".to_sym, *args, &block
|
||||||
|
|
||||||
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid_user_extensions
|
||||||
|
if !self.extensions.valid?
|
||||||
|
self.extensions.errors.messages.each do |key, values|
|
||||||
|
values.each do |value|
|
||||||
|
self.errors.add key, value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def save_user_extensions
|
||||||
|
self.extensions.save
|
||||||
|
self.user_score_attr.save
|
||||||
|
end
|
||||||
|
# 集中处理 User 扩展表为空的问题 < end
|
||||||
|
# ======================================================================
|
||||||
|
|
||||||
#选择项目成员时显示的用户信息文字
|
#选择项目成员时显示的用户信息文字
|
||||||
def userInfo
|
def userInfo
|
||||||
info=self.nickname + ' (' + self.realname + ')';
|
info=self.nickname + ' (' + self.realname + ')';
|
||||||
|
@ -276,6 +344,7 @@ class User < Principal
|
||||||
def reload(*args)
|
def reload(*args)
|
||||||
@name = nil
|
@name = nil
|
||||||
@projects_by_role = nil
|
@projects_by_role = nil
|
||||||
|
@courses_by_role = nil
|
||||||
@membership_by_project_id = nil
|
@membership_by_project_id = nil
|
||||||
base_reload(*args)
|
base_reload(*args)
|
||||||
end
|
end
|
||||||
|
@ -459,6 +528,9 @@ class User < Principal
|
||||||
self.pref[:comments_sorting] == 'desc'
|
self.pref[:comments_sorting] == 'desc'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def wants_notificationcomments_in_reverse_order?
|
||||||
|
self.pref[:notificationcomments_sorting] == 'desc'
|
||||||
|
end
|
||||||
# Return user's RSS key (a 40 chars long string), used to access feeds
|
# Return user's RSS key (a 40 chars long string), used to access feeds
|
||||||
def rss_key
|
def rss_key
|
||||||
if rss_token.nil?
|
if rss_token.nil?
|
||||||
|
@ -505,15 +577,16 @@ class User < Principal
|
||||||
# Find a user account by matching the exact login and then a case-insensitive
|
# Find a user account by matching the exact login and then a case-insensitive
|
||||||
# version. Exact matches will be given priority.
|
# version. Exact matches will be given priority.
|
||||||
#通过用户名查找相应的用户,若没有匹配到,则不区分大小写进行查询
|
#通过用户名查找相应的用户,若没有匹配到,则不区分大小写进行查询
|
||||||
|
#修改:不再匹配不区分大小写情况 -zjc
|
||||||
def self.find_by_login(login)
|
def self.find_by_login(login)
|
||||||
if login.present?
|
if login.present?
|
||||||
login = login.to_s
|
login = login.to_s
|
||||||
# First look for an exact match
|
# First look for an exact match
|
||||||
user = where(:login => login).all.detect {|u| u.login == login}
|
user = where(:login => login).all.detect {|u| u.login == login}
|
||||||
unless user
|
#unless user
|
||||||
# Fail over to case-insensitive if none was found
|
# # Fail over to case-insensitive if none was found
|
||||||
user = where("LOWER(login) = ?", login.downcase).first
|
# user = where("LOWER(login) = ?", login.downcase).first
|
||||||
end
|
#end
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -588,6 +661,15 @@ class User < Principal
|
||||||
@membership_by_project_id[project_id]
|
@membership_by_project_id[project_id]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def coursemembership(course)
|
||||||
|
course_id = course.is_a?(Course) ? course.id : course
|
||||||
|
|
||||||
|
@membership_by_course_id ||= Hash.new {|h, course_id|
|
||||||
|
h[course_id] = coursememberships.where(:course_id => course_id).first
|
||||||
|
}
|
||||||
|
@membership_by_course_id[course_id]
|
||||||
|
end
|
||||||
|
|
||||||
# Return user's roles for project
|
# Return user's roles for project
|
||||||
def roles_for_project(project)
|
def roles_for_project(project)
|
||||||
roles = []
|
roles = []
|
||||||
|
@ -609,11 +691,36 @@ class User < Principal
|
||||||
roles
|
roles
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 用户课程权限判断
|
||||||
|
def roles_for_course(course)
|
||||||
|
roles = []
|
||||||
|
# No role on archived courses
|
||||||
|
return roles if course.nil? || course.archived?
|
||||||
|
if logged?
|
||||||
|
# Find course membership
|
||||||
|
membership = coursemembership(course)
|
||||||
|
if membership
|
||||||
|
roles = membership.roles
|
||||||
|
else
|
||||||
|
@role_non_member ||= Role.non_member
|
||||||
|
roles << @role_non_member
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@role_anonymous ||= Role.anonymous
|
||||||
|
roles << @role_anonymous
|
||||||
|
end
|
||||||
|
roles
|
||||||
|
end
|
||||||
|
|
||||||
# Return true if the user is a member of project
|
# Return true if the user is a member of project
|
||||||
def member_of?(project)
|
def member_of?(project)
|
||||||
projects.to_a.include?(project)
|
projects.to_a.include?(project)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def member_of_course?(course)
|
||||||
|
courses.to_a.include?(course)
|
||||||
|
end
|
||||||
|
|
||||||
# Returns a hash of user's projects grouped by roles
|
# Returns a hash of user's projects grouped by roles
|
||||||
def projects_by_role
|
def projects_by_role
|
||||||
return @projects_by_role if @projects_by_role
|
return @projects_by_role if @projects_by_role
|
||||||
|
@ -634,6 +741,25 @@ class User < Principal
|
||||||
@projects_by_role
|
@projects_by_role
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 课程的角色权限
|
||||||
|
def courses_by_role
|
||||||
|
return @courses_by_role if @courses_by_role
|
||||||
|
|
||||||
|
@courses_by_role = Hash.new([])
|
||||||
|
coursememberships.each do |membership|
|
||||||
|
if membership.course
|
||||||
|
membership.roles.each do |role|
|
||||||
|
@courses_by_role[role] = [] unless @courses_by_role.key?(role)
|
||||||
|
@courses_by_role[role] << membership.course
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@courses_by_role.each do |role, courses|
|
||||||
|
courses.uniq!
|
||||||
|
end
|
||||||
|
|
||||||
|
@courses_by_role
|
||||||
|
end
|
||||||
# Returns true if user is arg or belongs to arg
|
# Returns true if user is arg or belongs to arg
|
||||||
def is_or_belongs_to?(arg)
|
def is_or_belongs_to?(arg)
|
||||||
if arg.is_a?(User)
|
if arg.is_a?(User)
|
||||||
|
@ -645,6 +771,7 @@ class User < Principal
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Return true if the user is allowed to do the specified action on a specific context
|
# Return true if the user is allowed to do the specified action on a specific context
|
||||||
# Action can be:
|
# Action can be:
|
||||||
# * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit')
|
# * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit')
|
||||||
|
@ -667,7 +794,20 @@ class User < Principal
|
||||||
role.allowed_to?(action) &&
|
role.allowed_to?(action) &&
|
||||||
(block_given? ? yield(role, self) : true)
|
(block_given? ? yield(role, self) : true)
|
||||||
}
|
}
|
||||||
elsif context && context.is_a?(Array)
|
#添加课程相关的权限判断
|
||||||
|
elsif context && context.is_a?(Course)
|
||||||
|
return false unless context.allows_to?(action)
|
||||||
|
# Admin users are authorized for anything else
|
||||||
|
return true if admin?
|
||||||
|
|
||||||
|
roles = roles_for_course(context)
|
||||||
|
return false unless roles
|
||||||
|
roles.any? {|role|
|
||||||
|
(context.is_public? || role.member?) &&
|
||||||
|
role.allowed_to?(action) &&
|
||||||
|
(block_given? ? yield(role, self) : true)
|
||||||
|
}
|
||||||
|
elsif context && context.is_a?(Array)
|
||||||
if context.empty?
|
if context.empty?
|
||||||
false
|
false
|
||||||
else
|
else
|
||||||
|
@ -680,6 +820,9 @@ class User < Principal
|
||||||
|
|
||||||
# authorize if user has at least one role that has this permission
|
# authorize if user has at least one role that has this permission
|
||||||
roles = memberships.collect {|m| m.roles}.flatten.uniq
|
roles = memberships.collect {|m| m.roles}.flatten.uniq
|
||||||
|
if roles.count == 0
|
||||||
|
roles = coursememberships.collect {|m| m.roles}.flatten.uniq
|
||||||
|
end
|
||||||
roles << (self.logged? ? Role.non_member : Role.anonymous)
|
roles << (self.logged? ? Role.non_member : Role.anonymous)
|
||||||
roles.any? {|role|
|
roles.any? {|role|
|
||||||
role.allowed_to?(action) &&
|
role.allowed_to?(action) &&
|
||||||
|
@ -748,10 +891,39 @@ class User < Principal
|
||||||
when News
|
when News
|
||||||
# always send to project members except when mail_notification is set to 'none'
|
# always send to project members except when mail_notification is set to 'none'
|
||||||
true
|
true
|
||||||
|
#判定用户是否接受留言提醒邮件
|
||||||
|
when JournalsForMessage
|
||||||
|
##如果是直接留言并且留言对象是Project并且Project类型是课程(课程留言)
|
||||||
|
if !object.at_user && object.jour.class.to_s.to_sym == :Project && object.jour.project_type == 1
|
||||||
|
#根据用户设置邮件接收模式判定当前用户是否接受邮件提醒
|
||||||
|
is_notified_project object.jour
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#用户是否接收project的消息提醒
|
||||||
|
def is_notified_project arg
|
||||||
|
if arg.is_a?(Project)
|
||||||
|
case mail_notification
|
||||||
|
when 'selected'
|
||||||
|
notified_projects_ids.include?(arg.id)
|
||||||
|
when 'only_my_events'
|
||||||
|
projects.include?(arg)
|
||||||
|
when 'only_assigned'
|
||||||
|
false
|
||||||
|
when 'only_owner'
|
||||||
|
course = Course.find_by_extra(arg.identifier)
|
||||||
|
course.teacher == self
|
||||||
|
end
|
||||||
|
#勾选的项目或用户的项目 TODO:需改
|
||||||
|
#notified_projects_ids.include?(arg) || projects.include?(arg)
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.current=(user)
|
def self.current=(user)
|
||||||
Thread.current[:current_user] = user
|
Thread.current[:current_user] = user
|
||||||
end
|
end
|
||||||
|
@ -793,7 +965,6 @@ class User < Principal
|
||||||
errors.add(:password, :too_short, :count => Setting.password_min_length.to_i)
|
errors.add(:password, :too_short, :count => Setting.password_min_length.to_i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def act_as_activity
|
def act_as_activity
|
||||||
|
@ -808,6 +979,7 @@ class User < Principal
|
||||||
substitute = User.anonymous
|
substitute = User.anonymous
|
||||||
Attachment.update_all ['author_id = ?', substitute.id], ['author_id = ?', id]
|
Attachment.update_all ['author_id = ?', substitute.id], ['author_id = ?', id]
|
||||||
Comment.update_all ['author_id = ?', substitute.id], ['author_id = ?', id]
|
Comment.update_all ['author_id = ?', substitute.id], ['author_id = ?', id]
|
||||||
|
Notificationcomment.update_all ['author_id = ?', substitute.id], ['author_id = ?', id]
|
||||||
Issue.update_all ['author_id = ?', substitute.id], ['author_id = ?', id]
|
Issue.update_all ['author_id = ?', substitute.id], ['author_id = ?', id]
|
||||||
Issue.update_all 'assigned_to_id = NULL', ['assigned_to_id = ?', id]
|
Issue.update_all 'assigned_to_id = NULL', ['assigned_to_id = ?', id]
|
||||||
Journal.update_all ['user_id = ?', substitute.id], ['user_id = ?', id]
|
Journal.update_all ['user_id = ?', substitute.id], ['user_id = ?', id]
|
||||||
|
@ -835,6 +1007,8 @@ class User < Principal
|
||||||
Redmine::Utils.random_hex(16)
|
Redmine::Utils.random_hex(16)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class AnonymousUser < User
|
class AnonymousUser < User
|
||||||
|
|
|
@ -2,4 +2,37 @@ class UserGrade < ActiveRecord::Base
|
||||||
# attr_accessible :title, :body
|
# attr_accessible :title, :body
|
||||||
attr_accessible :user_id, :project_id, :grade
|
attr_accessible :user_id, :project_id, :grade
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
|
before_save :correct_score
|
||||||
|
validates_uniqueness_of :user_id, :scope => [:project_id]
|
||||||
|
#validate :my_validation
|
||||||
|
|
||||||
|
#修正分数
|
||||||
|
#分数小于0时修正为0
|
||||||
|
#分数大于等于0时不修正 -by zjc
|
||||||
|
def correct_score
|
||||||
|
if !self.grade.nil? && self.grade < 0
|
||||||
|
self.grade = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
#def self.exit_user_and_project(user,project)
|
||||||
|
# unless user.nil? || project.nil?
|
||||||
|
# if user.class.to_s == 'User' && project.class.to_s == 'Project'
|
||||||
|
# user_grade = UserGrade.find_by_user_id_and_project_id(user.id,project.id)
|
||||||
|
# user_grade
|
||||||
|
# else
|
||||||
|
# nil
|
||||||
|
# end
|
||||||
|
# else
|
||||||
|
# nil
|
||||||
|
# end
|
||||||
|
#end
|
||||||
|
|
||||||
|
#def my_validation
|
||||||
|
# if user_id.nil? || project_id.nil?
|
||||||
|
# errors[:Base] << "用户和项目不能为空"
|
||||||
|
# elsif UserGrade.exit_user_and_project(user_id,project_id)
|
||||||
|
# errors[:Base] << "当前记录已存在"
|
||||||
|
# end
|
||||||
|
#end
|
||||||
end
|
end
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue