diff --git a/.gitignore b/.gitignore index a6ee997aa..ffa4a1bc7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,28 +1,30 @@ -*.swp -/.project -/.idea -/.bundle -*.swp -/config/database.yml -/config/configuration.yml -/files/* -/log/* -/public/tmp/* -/tmp/* -/public/cache/* -.gitignore -/config/newrelic.yml -/public/images/avatars/* -/Gemfile -/Gemfile.lock -/db/schema.rb -/Gemfile.lock -/lib/plugins/acts_as_versioned/test/debug.log -.rbenv-gemsets -.DS_Store -public/api_doc/ -/.metadata -vendor/cache -/files -/public/images/avatars -/public/files +*.swp +/.project +/.idea +/.bundle +*.swp +/config/database.yml +/config/configuration.yml +/config/additional_environment.rb +/files/* +/log/* +/public/tmp/* +/tmp/* +/public/cache/* +.gitignore +/config/newrelic.yml +/public/images/avatars/* +/Gemfile +/Gemfile.lock +/db/schema.rb +/Gemfile.lock +/lib/plugins/acts_as_versioned/test/debug.log +.rbenv-gemsets +.DS_Store +public/api_doc/ +/.metadata +vendor/cache +/files +/public/images/avatars +/public/files +/tags diff --git a/.rspec b/.rspec index 8c18f1abd..83e16f804 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1,2 @@ ---format documentation --color +--require spec_helper diff --git a/Gemfile b/Gemfile index 976184793..fbe74f8dd 100644 --- a/Gemfile +++ b/Gemfile @@ -1,140 +1,83 @@ -source 'http://ruby.taobao.org' -#source 'http://ruby.sdutlinux.org/' - -unless RUBY_PLATFORM =~ /w32/ - # unix-like only - gem 'iconv' -end - -gem 'rubyzip' -gem 'delayed_job_active_record'#, :group => :production -gem 'daemons' -gem 'grape', '~> 0.9.0' -gem 'grape-entity' -gem 'seems_rateable', '~> 1.0.13' -gem "rails", "3.2.13" -gem "jquery-rails", "~> 2.0.2" -gem "i18n", "~> 0.6.0" -gem 'coderay', '~> 1.1.0' -gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby] -gem "builder", "3.0.0" -gem 'acts-as-taggable-on', '2.4.1' -gem 'spreadsheet' -gem 'ruby-ole' -#gem 'email_verifier', path: 'lib/email_verifier' -gem 'rufus-scheduler' -#gem 'dalli', path: 'lib/dalli-2.7.2' -gem 'rails_kindeditor',path:'lib/rails_kindeditor' -group :development do - gem 'grape-swagger' - #gem 'grape-swagger-ui', git: 'https://github.com/guange2015/grape-swagger-ui.git' - gem 'puma' if RbConfig::CONFIG['host_os'] =~ /linux/ - gem 'pry-rails' - if RUBY_VERSION >= '2.0.0' - gem 'pry-byebug' - else - # gem 'pry-debugger' - end - gem 'pry-stack_explorer' - gem 'better_errors', '~> 1.1.0' - gem 'rack-mini-profiler', '~> 0.9.3' -end - -group :test do - gem "shoulda", "~> 3.5.0" - gem "mocha", "~> 1.1.0" - gem 'capybara', '~> 2.4.1' - gem 'nokogiri', '~> 1.6.3' - gem 'factory_girl', '~> 4.4.0' - gem 'selenium-webdriver', '~> 2.42.0' - - gem "faker" - # 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 -end - -# Gems used only for assets and not required -# in production environments by default. -group :assets do - gem 'sass-rails', '~> 3.2.3' - gem 'coffee-rails', '~> 3.2.1' - - # See https://github.com/sstephenson/execjs#readme for more supported runtimes - gem 'therubyracer', :platforms => :ruby - - gem 'uglifier', '>= 1.0.3' -end - -# Optional gem for LDAP authentication -group :ldap do - gem "net-ldap", "~> 0.3.1" -end - - -# Optional gem for OpenID authentication -group :openid do - gem "ruby-openid", "~> 2.1.4", :require => "openid" - gem "rack-openid" -end - -# Optional gem for exporting the gantt to a PNG file, not supported with jruby -platforms :jruby do - # jruby-openssl is bundled with JRuby 1.7.0 - gem "jruby-openssl" if Object.const_defined?(:JRUBY_VERSION) && JRUBY_VERSION < '1.7.0' - gem "activerecord-jdbc-adapter", "1.2.5" -end - -# Include database gems for the adapters found in the database -# configuration file -require 'erb' -require 'yaml' -database_file = File.join(File.dirname(__FILE__), "config/database.yml") -if File.exist?(database_file) - database_config = YAML::load(ERB.new(IO.read(database_file)).result) - adapters = database_config.values.map {|c| c['adapter']}.compact.uniq - if adapters.any? - adapters.each do |adapter| - case adapter - when 'mysql2' - gem "mysql2", "= 0.3.18", :platforms => [:mri, :mingw] - gem "activerecord-jdbcmysql-adapter", :platforms => :jruby - when 'mysql' - gem "mysql", "~> 2.8.1", :platforms => [:mri, :mingw] - gem "activerecord-jdbcmysql-adapter", :platforms => :jruby - when /postgresql/ - gem "pg", ">= 0.11.0", :platforms => [:mri, :mingw] - gem "activerecord-jdbcpostgresql-adapter", :platforms => :jruby - when /sqlite3/ - gem "sqlite3", :platforms => [:mri, :mingw] - gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby - when /sqlserver/ - gem "tiny_tds", "~> 0.5.1", :platforms => [:mri, :mingw] - gem "activerecord-sqlserver-adapter", :platforms => [:mri, :mingw] - else - warn("Unknown database adapter `#{adapter}` found in config/database.yml, use Gemfile.local to load your own database gems") - end - end - else - warn("No adapter found in config/database.yml, please configure it first") - end -else - warn("Please configure your config/database.yml first") -end - -local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local") -if File.exists?(local_gemfile) - puts "Loading Gemfile.local ..." if $DEBUG # `ruby -d` or `bundle -v` - instance_eval File.read(local_gemfile) -end - -# Load plugins' Gemfiles -Dir.glob File.expand_path("../plugins/*/Gemfile", __FILE__) do |file| - puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v` - instance_eval File.read(file) -end +source 'http://ruby.taobao.org' +#source 'http://ruby.sdutlinux.org/' + +unless RUBY_PLATFORM =~ /w32/ + # unix-like only + gem 'iconv' +end + +gem "mysql2", "= 0.3.18" +gem 'redis-rails' +gem 'rubyzip' +gem 'delayed_job_active_record'#, :group => :production +gem 'daemons' +gem 'grape', '~> 0.9.0' +gem 'grape-entity' +gem 'seems_rateable', '~> 1.0.13' +gem "rails", "3.2.13" +gem "jquery-rails", "~> 2.0.2" +gem "i18n", "~> 0.6.0" +gem 'coderay', '~> 1.1.0' +gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby] +gem "builder", "3.0.0" +gem 'acts-as-taggable-on', '2.4.1' +gem 'spreadsheet' +gem 'ruby-ole' +gem 'rails_kindeditor',path:'lib/rails_kindeditor' +gem "rmagick", ">= 2.0.0" + +group :development do + gem 'grape-swagger' + gem 'better_errors', '~> 1.1.0' + gem 'rack-mini-profiler', '~> 0.9.3' +end + +group :development, :test do + unless RUBY_PLATFORM =~ /w32/ + gem 'pry-rails' + if RUBY_VERSION >= '2.0.0' + gem 'pry-byebug' + end + gem 'pry-stack_explorer' + end + + gem 'rspec-rails', '~> 3.0' + gem 'factory_girl_rails' +end + +# Gems used only for assets and not required +# in production environments by default. +group :assets do + gem 'sass-rails', '~> 3.2.3' + gem 'coffee-rails', '~> 3.2.1' + + # See https://github.com/sstephenson/execjs#readme for more supported runtimes + gem 'therubyracer', :platforms => :ruby + + gem 'uglifier', '>= 1.0.3' +end + +# Optional gem for LDAP authentication +group :ldap do + gem "net-ldap", "~> 0.3.1" +end + + +# Optional gem for OpenID authentication +group :openid do + gem "ruby-openid", "~> 2.1.4", :require => "openid" + gem "rack-openid" +end + + +database_file = File.join(File.dirname(__FILE__), "config/database.yml") +if File.exist?(database_file) +else + warn("Please configure your config/database.yml first") +end + +# Load plugins' Gemfiles +Dir.glob File.expand_path("../plugins/*/Gemfile", __FILE__) do |file| + puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v` + instance_eval File.read(file) +end diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 08c7adf10..73d1e357c 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -168,6 +168,30 @@ module Mobile present :status, 0 end + desc "设置教辅" + params do + requires :token,type:String + requires :user_id,type:Integer,desc: '用户id' + requires :course_id,type:Integer,desc:'课程id' + end + get 'set_user_as_assitant' do + cs = CoursesService.new + cs.set_as_assitant_teacher params + present :status, 0 + end + + desc "删除教辅" + params do + requires :token,type:String + requires :user_id,type:Integer,desc: '用户id' + requires :course_id,type:Integer,desc:'课程id' + end + get 'del_user_as_assitant' do + cs = CoursesService.new + cs.del_assitant_teacher params + present :status, 0 + end + desc "返回单个课程" params do requires :id, type: Integer @@ -179,7 +203,7 @@ module Mobile course = cs.show_course(params,(current_user.nil? ? User.find(2):current_user)) #course = Course.find(params[:id]) present :data, course, with: Mobile::Entities::Course - present :status, 0 + { status: 0} end end @@ -228,6 +252,65 @@ module Mobile present :status, 0 end + desc '课程课件' + params do + requires :token, type: String + requires :course_id,type: Integer,desc: '课程id' + optional :name,type:String,desc:'课件名称可能包含的字符' + end + post ":course_id/attachments" do + cs = CoursesService.new + count = cs.course_attachments params + present :data, count, with: Mobile::Entities::Attachment + present :status, 0 + end + + desc '课程学生' + params do + requires :token,type:String + requires :course_id,type:Integer,desc: '课程id' + optional :name,type:String,desc:'学生的姓名或者昵称或者学号可能包含的字符' + end + get ":course_id/members" do + cs = CoursesService.new + count = cs.course_members params + # 我如果在学生当中,那么我将放在第一位 + count.each do |m| + if m.user.id == current_user.id + count.delete m + count.unshift m + end + end + present :data, count, with: Mobile::Entities::Member + present :status, 0 + end + + desc '查看用户历次作业成绩' + params do + requires :token,type:String + requires :member_id,type:Integer,desc:'课程member_id' + optional :homeworkName,type:String,desc:'作业名称以及作业名称可能包含的字符' + end + get '/show_member_score/:member_id' do + cs = CoursesService.new + homeworkscore = cs.show_member_score params + present :data,homeworkscore,with: Mobile::Entities::Homeworkscore + present :status,0 + end + + desc '发布课程通知' + params do + requires :token,type:String + requires :course_id,type:Integer,desc:'课程id' + requires :title,type:String,desc:'通知标题' + requires :desc,type:String,desc:'通知描述' + end + post ':course_id/create_course_notice' do + cs = CoursesService.new + news = cs.create_course_notice params,current_user + present :data,news,with:Mobile::Entities::News + present :status,0 + end end end end diff --git a/app/api/mobile/apis/homeworks.rb b/app/api/mobile/apis/homeworks.rb index 7a8c87987..5bf454e32 100644 --- a/app/api/mobile/apis/homeworks.rb +++ b/app/api/mobile/apis/homeworks.rb @@ -96,6 +96,21 @@ module Mobile present :status, 0 end + desc '创建作业' + params do + requires :token,type:String + requires :work_name,type:String,desc:'作业名称' + requires :work_desc,type:String,desc:'作业描述' + requires :work_deadline,type:String,desc:'截止日期' + requires :is_blind_appr,type:Integer,desc:'是否匿评' + requires :blind_appr_num,type:Integer,desc:'匿评分配数' + requires :course_id,type:Integer,desc: '课程id' + end + post 'create_home_work' do + Homeworks.get_service.create_home_work params,current_user + present :status, 0 + end + end end diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index 063cfafae..fa1856b3d 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -83,6 +83,9 @@ module Mobile params do requires :name, type: String, desc: '用户名关键字' requires :search_by, type: String,desc: '搜索依据:0 昵称,1 用户名,2 邮箱,3 昵称和姓名' + optional :is_search_assitant,type:Integer,desc:'是否搜索注册用户来作为助教' + optional :course_id,type:Integer,desc: '课程id,搜索注册用户不为该课程教师的其他用户' + optional :user_id,type:Integer,desc:'用户id' end get 'search/search_user' do us = UsersService.new @@ -91,6 +94,33 @@ module Mobile present :status, 0 end + desc "用户留言" + params do + requires :token, type: String + requires :user_id, type: Integer,desc: '被留言的用户id' + end + get ':user_id/messages' do + us = UsersService.new + jours = us.get_all_messages params + present :data,jours,with:Mobile::Entities::Jours + present :status,0 + end + + desc "给用户留言或回复用户留言" + params do + requires :token, type: String + requires :user_id, type: Integer,desc: '被留言的用户id' + requires :content,type:String,desc:'留言内容' + requires :ref_user_id,type:Integer,desc:'被回复的用户id' + requires :parent_id,type:Integer,desc:'留言父id' + requires :ref_message_id,type:Integer,desc:'引用消息id' + end + post ':user_id/leave_message' do + us = UsersService.new + jours = us.reply_user_messages params,current_user + present :status,0 + end + end end end diff --git a/app/api/mobile/entities/attachment.rb b/app/api/mobile/entities/attachment.rb index 510db89be..080b24558 100644 --- a/app/api/mobile/entities/attachment.rb +++ b/app/api/mobile/entities/attachment.rb @@ -16,8 +16,11 @@ module Mobile end end end + attachment_expose :id attachment_expose :filename attachment_expose :description + attachment_expose :downloads + attachment_expose :quotes end end end \ No newline at end of file diff --git a/app/api/mobile/entities/course.rb b/app/api/mobile/entities/course.rb index 520f73384..50812b349 100644 --- a/app/api/mobile/entities/course.rb +++ b/app/api/mobile/entities/course.rb @@ -46,6 +46,7 @@ module Mobile course_expose :term course_expose :time course_expose :updated_at + course_expose :course_student_num expose :teacher, using: Mobile::Entities::User do |c, opt| if c.is_a? ::Course c.teacher diff --git a/app/api/mobile/entities/homework_attach.rb b/app/api/mobile/entities/homework_attach.rb index 690ec8e94..2ad11fe36 100644 --- a/app/api/mobile/entities/homework_attach.rb +++ b/app/api/mobile/entities/homework_attach.rb @@ -37,7 +37,6 @@ module Mobile f.send(:attachments) end end - #homework_attach_expose :user end end end \ No newline at end of file diff --git a/app/api/mobile/entities/homeworkscore.rb b/app/api/mobile/entities/homeworkscore.rb new file mode 100644 index 000000000..e0c501c58 --- /dev/null +++ b/app/api/mobile/entities/homeworkscore.rb @@ -0,0 +1,18 @@ +module Mobile + module Entities + class Homeworkscore < Grape::Entity + include Redmine::I18n + include ApplicationHelper + def self.homeworkscore_expose(field) + expose field do |f,opt| + if f.is_a?(Hash) && f.key?(field) + f[field] + end + end + end + + homeworkscore_expose :name + homeworkscore_expose :score + end + end +end \ No newline at end of file diff --git a/app/api/mobile/entities/member.rb b/app/api/mobile/entities/member.rb new file mode 100644 index 000000000..f9dd1e849 --- /dev/null +++ b/app/api/mobile/entities/member.rb @@ -0,0 +1,34 @@ +module Mobile + module Entities + class Member < Grape::Entity + include ApplicationHelper + include ApiHelper + def self.member_expose(f) + expose f do |u,opt| + if u.is_a?(Hash) && u.key?(f) + u[f] + elsif u.is_a?(::Member) + if u.respond_to?(f) + u.send(f) + else + case f + when :student_id + u.user.user_extensions.student_id + end + end + end + + end + end + + expose :user, using: Mobile::Entities::User do |c, opt| + if c.is_a?(::Member) + c.user + end + end + member_expose :student_id + member_expose :score + member_expose :id + end + end +end \ No newline at end of file diff --git a/app/api/mobile/entities/user.rb b/app/api/mobile/entities/user.rb index 6b0064036..aee687dc9 100644 --- a/app/api/mobile/entities/user.rb +++ b/app/api/mobile/entities/user.rb @@ -9,7 +9,7 @@ module Mobile u[f] elsif u.is_a?(::User) if u.respond_to?(f) - u.send(f) + u.send(f) unless u.user_extensions.nil? else case f when :img_url @@ -17,9 +17,9 @@ module Mobile when :gender u.nil? || u.user_extensions.nil? || u.user_extensions.gender.nil? ? 0 : u.user_extensions.gender when :work_unit - get_user_work_unit u + get_user_work_unit u unless u.user_extensions.nil? when :location - get_user_location u + get_user_location u unless u.user_extensions.nil? when :brief_introduction u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.brief_introduction end diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index f8d0f5dd1..7976e1aa4 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -31,9 +31,6 @@ class AccountController < ApplicationController else authenticate_user end - rescue AuthSourceException => e - logger.error "An error occured when authenticating #{params[:username]}: #{e.message}" - render_error :message => e.message end # Log out current user and redirect to welcome page @@ -47,6 +44,10 @@ class AccountController < ApplicationController # display the logout form end + def heartbeat + render :json => session[:user_id] + end + # Lets user choose a new password def lost_password (redirect_to(home_url); return) unless Setting.lost_password? @@ -314,7 +315,7 @@ class AccountController < ApplicationController #根据home_url生产正则表达式 eval("code = " + "/^" + home_url.gsub(/\//,"\\\/") + "\\\/*(welcome)?\\\/*(\\\/index\\\/*.*)?\$/") if (code=~params[:back_url] || params[:back_url].to_s.include?('lost_password')) && last_login_on != '' - redirect_to user_activities_path(user) + redirect_to user_activities_path(user,host: Setting.host_user) else if last_login_on == '' redirect_to my_account_url @@ -329,10 +330,10 @@ class AccountController < ApplicationController end def set_autologin_cookie(user) - token = Token.create(:user => user, :action => 'autologin') + token = Token.get_or_create_permanent_login_token(user) cookie_options = { :value => token.value, - :expires => 1.year.from_now, + :expires => 1.month.from_now, :path => (Redmine::Configuration['autologin_cookie_path'] || '/'), :secure => (Redmine::Configuration['autologin_cookie_secure'] ? true : false), :httponly => true diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 47251cf85..0dc86fb01 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -156,16 +156,16 @@ class ApplicationController < ActionController::Base user end end - def try_to_autologin1 - - # auto-login feature starts a new session - user = User.try_to_autologin(params[:token]) - if user - start_user_session(user) - end - user + def try_to_autologin1 + user = User.try_to_autologin(params[:token]) + if user + logout_user if User.current.id != user.id + start_user_session(user) + end + user end + # Sets the logged in user def logged_user=(user) reset_session @@ -200,7 +200,7 @@ class ApplicationController < ActionController::Base def logout_user if User.current.logged? cookies.delete(autologin_cookie_name) - Token.delete_all(["user_id = ? AND action = ?", User.current.id, 'autologin']) + # Token.delete_all(["user_id = ? AND action = ?", User.current.id, 'autologin']) self.logged_user = nil end end @@ -894,7 +894,6 @@ class ApplicationController < ActionController::Base set_autologin_cookie(user) end call_hook(:controller_account_success_authentication_after, {:user => user }) - - end + end diff --git a/app/controllers/avatar_controller.rb b/app/controllers/avatar_controller.rb index 771a14fe8..afd206c92 100644 --- a/app/controllers/avatar_controller.rb +++ b/app/controllers/avatar_controller.rb @@ -1,82 +1,81 @@ class AvatarController < ApplicationController - - + + include ActionView::Helpers::NumberHelper #before_filter :set_cache_buster include AvatarHelper - + def upload # Make sure that API users get used to set this content type # as it won't trigger Rails' automatic parsing of the request body for parameters unless request.content_type == 'application/octet-stream' - render :nothing => true, :status => 406 - return - end - - unless request.raw_post.nil? - @source_type = params[:source_type] + @source_type = params[:source_type] @source_id = params[:source_id] - @temp_file = request.raw_post - if @temp_file.size > 0 - if @temp_file.respond_to?(:original_filename) - @image_file = @temp_file.original_filename - #image_file.force_encoding("UTF-8") if filename.respond_to?(:force_encoding) - else - @image_file=params[:filename] - end + @temp_file = params[:avatar][:image] + @image_file = @temp_file.original_filename + else + unless request.raw_post.nil? + @source_type = params[:source_type] + @source_id = params[:source_id] + @temp_file = request.raw_post + if @temp_file.size > 0 + if @temp_file.respond_to?(:original_filename) + @image_file = @temp_file.original_filename + #image_file.force_encoding("UTF-8") if filename.respond_to?(:force_encoding) + else + @image_file=params[:filename] + end + end end end + if @temp_file && (@temp_file.size > 0) - diskfile=disk_filename(@source_type,@source_id) - @urlfile='/' << File.join("images","avatars",avatar_directory(@source_type),avatar_filename(@source_id,@image_file)) + if @temp_file.size > Setting.upload_avatar_max_size.to_i + @status = 1 + @msg = l(:error_upload_avatar_to_large, :max_size => number_to_human_size(Setting.upload_avatar_max_size.to_i)) + elsif Trustie::Utils::Image.new(@temp_file.tempfile.path).image? + diskfile=disk_filename(@source_type,@source_id) + @urlfile='/' << File.join("images","avatars",avatar_directory(@source_type),avatar_filename(@source_id,@image_file)) - # 用户头像上传时进行特别处理 - if @source_type == 'User' + # 用户头像上传时进行特别处理 + if @source_type == 'User' diskfile += "temp" @urlfile += "temp" - end + end - logger.info("Saving avatar '#{diskfile}' (#{@temp_file.size} bytes)") - path = File.dirname(diskfile) - unless File.directory?(path) - FileUtils.mkdir_p(path) - end - md5 = Digest::MD5.new - File.open(diskfile, "wb") do |f| - if @temp_file.respond_to?(:read) - buffer = "" - while (buffer = @temp_file.read(8192)) - f.write(buffer) - md5.update(buffer) + logger.info("Saving avatar '#{diskfile}' (#{@temp_file.size} bytes)") + path = File.dirname(diskfile) + unless File.directory?(path) + FileUtils.mkdir_p(path) + end + md5 = Digest::MD5.new + File.open(diskfile, "wb") do |f| + if @temp_file.respond_to?(:read) + buffer = "" + while (buffer = @temp_file.read(8192)) + f.write(buffer) + md5.update(buffer) + end + else + f.write(@temp_file) + md5.update(@temp_file) end - else - f.write(@temp_file) - md5.update(@temp_file) end + + Trustie::Utils::Image.new(diskfile,true).compress(300) + @status = 0 + @msg = '' + else + @status = 2 + @msg = l(:not_valid_image_file) end -# self.digest = md5.hexdigest end @temp_file = nil - # @avatar = Avatar.new(:receive_file => request.raw_post) - # @avatar.source_id = User.current.id - # @avatar.image_file = params[:filename].presence || Redmine::Utils.random_hex(16) - # saved = @avatar.save - begin - f = Magick::ImageList.new(diskfile) - # gif格式不再做大小处理 - if f.format != 'GIF' - width = 300.0 - proportion = (width/f[0].columns) - height = (f[0].rows*proportion) - f.resize_to_fill!(width,height) - f.write(diskfile) - end - - rescue Exception => e - logger.error "[Error] avatar : avatar_controller#upload ===> #{e}" - end - respond_to do |format| + format.json{ + render :inline => {status: @status, message:@msg, url:"#{@urlfile.to_s}?#{Time.now.to_i}"}.to_json,:content_type => 'text/html' + return + } format.js format.api { if saved diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index b1cca68ed..c98df27d3 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -490,7 +490,7 @@ class BidsController < ApplicationController (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1 AND stars IS NOT NULL ORDER BY updated_at DESC limit 0,1) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY s_score DESC,created_at ASC) AS table1 - WHERE table1.t_score IS NULL OR table1.t_score = 0") + WHERE table1.t_score IS NULL") @not_batch_homework = true @cur_type = 1 else diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index bdbbb8e37..4a27f02ff 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -27,27 +27,38 @@ class BoardsController < ApplicationController include SortHelper helper :watchers helper :project_score - + helper :attachments def index #modify by nwb @flag = params[:flag] || false if @project - @boards = @project.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 => false if request.xhr? - elsif @course - if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course))) - @boards = @course.boards.includes(:last_message => :author).all + if !@project.is_public? && !User.current.member_of?(@project) && !User.current.admin? + render_403 + else + @boards = @project.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' + render :layout => false if request.xhr? + end + elsif @course + if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course))) + @boards = @course.boards.includes(:last_message => :author).all + if @course.boards.empty? + @board = @course.boards.build + @board.name = " #{l(:label_borad_course) }" + @board.description = @course.name.to_s + @board.project_id = -1 + if @board.save + @boards = @course.boards.includes(:last_message => :author).all + end + end + unless @course.boards.empty? + @board = @course.boards.first + end + show and return else render_403 end @@ -65,7 +76,7 @@ class BoardsController < ApplicationController 'replies' => "#{Message.table_name}.replies_count", 'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)" - @topic_count = @board.topics.count + @topic_count = @board ? @board.topics.count : 0 if @project @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] @topics = @board.topics. @@ -73,18 +84,17 @@ class BoardsController < ApplicationController includes(:last_reply). limit(@topic_pages.per_page). offset(@topic_pages.offset). - order(sort_clause). + order("last_replies_messages.created_on desc"). preload(:author, {:last_reply => :author}). all elsif @course - board_topics = @board.topics. - reorder("#{Message.table_name}.sticky DESC"). + board_topics = @board ? @board.topics.reorder("#{Message.table_name}.sticky DESC"). includes(:last_reply). # limit(@topic_pages.per_page). # offset(@topic_pages.offset). - order(sort_clause). + order("last_replies_messages.created_on desc"). preload(:author, {:last_reply => :author}). - all + all : [] @topics = paginateHelper board_topics,10 end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index a1e547a84..be69b1777 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -5,6 +5,7 @@ class CoursesController < ApplicationController helper :activities helper :members helper :words + helper :attachments before_filter :auth_login1, :only => [:show, :feedback] menu_item :overview @@ -341,10 +342,15 @@ class CoursesController < ApplicationController def export_course_member_excel @all_members = student_homework_score(0,0,0,"desc") + filename="#{@course.teacher.lastname.to_s + @course.teacher.firstname.to_s }_#{@course.name}_#{@course.time.to_s + @course.term}#{l(:excel_member_list)}"; + # 如果是ie11 需要转码 + if(/rv\:11\.0/.match(request.env["HTTP_USER_AGENT"]) != nil) + filename= URI::encode(filename) + end respond_to do |format| format.xls { send_data(member_to_xls(@all_members,@course.course_groups), :type => "text/excel;charset=utf-8; header=present", - :filename => "#{@course.teacher.lastname.to_s + @course.teacher.firstname.to_s }_#{@course.name}_#{@course.time.to_s + @course.term}#{l(:excel_member_list)}.xls") + :filename => "#{filename}.xls") } end end @@ -851,7 +857,7 @@ class CoursesController < ApplicationController #验证是否显示课程 def can_show_course @first_page = FirstPage.find_by_page_type('project') - if @first_page.show_course == 2 + if @first_page.try(:show_course) == 2 render_404 end end diff --git a/app/controllers/discuss_demos_controller.rb b/app/controllers/discuss_demos_controller.rb new file mode 100644 index 000000000..9a03f3b86 --- /dev/null +++ b/app/controllers/discuss_demos_controller.rb @@ -0,0 +1,42 @@ +class DiscussDemosController < ApplicationController + def index + + @discuss_demo_list = DiscussDemo.where("body is not null").order("created_at desc").page(params[:page] || 1).per(10) + end + + def new + @discuss_demo = DiscussDemo.create + @discuss_demo.save! + @discuss_demo + end + + def create + + end + + def update + @discuss_demo = DiscussDemo.find(params[:id]) + @discuss_demo.update_attributes(:title => params[:discuss_demo][:title],:body => params[:discuss_demo][:body]) + redirect_to :controller=> 'discuss_demos',:action => 'show',:id => params[:id] + end + + def delete + + end + + def destroy + asset = Kindeditor::Asset.find_by_owner_id(params[:id]) + if !asset.nil? + filepath = File.join(Rails.root,"public","files","uploads", + asset[:created_at].to_s.gsub("+0800","").to_datetime.strftime("%Y%m").to_s, + asset[:asset].to_s) + File.delete(filepath) if File.exist?filepath + end + DiscussDemo.destroy(params[:id]) + redirect_to :controller=> 'discuss_demos',:action => 'index' + end + + def show + @discuss_demo = DiscussDemo.find(params[:id]) + end +end diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 69e7105aa..0003f7586 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -23,7 +23,7 @@ class FilesController < ApplicationController before_filter :auth_login1, :only => [:index] before_filter :logged_user_by_apptoken,:only => [:index] before_filter :find_project_by_project_id#, :except => [:getattachtype] - before_filter :authorize, :except => [:getattachtype,:quote_resource_show,:search,:search_project,:quote_resource_show_project,:search_tag_attachment] + before_filter :authorize, :except => [:getattachtype,:quote_resource_show,:search,:searchone4reload,:search_project,:quote_resource_show_project,:search_tag_attachment] helper :sort include SortHelper @@ -46,6 +46,13 @@ class FilesController < ApplicationController @obj_attachments = paginateHelper @all_attachments,10 end + def searchone4reload + attachment = Attachment.find_by_id(params[:fileid]); + respond_to do |format| + format.html{render :layout => nil,:locals=>{:file=>attachment,:course=>@course}} + end + end + def search sort = "" @sort = "" @@ -60,9 +67,7 @@ class FilesController < ApplicationController end sort = "#{@sort} #{@order}" end - # show_attachments [@course] - begin q = "%#{params[:name].strip}%" #(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? @@ -101,14 +106,18 @@ class FilesController < ApplicationController end sort = "#{@sort} #{@order}" end - begin q = "%#{params[:name].strip}%" #(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? if params[:insite] - @result = find_public_attache q,sort - @result = visable_attachemnts_insite @result,@project - @searched_attach = paginateHelper @result,10 + if q == "%%" + @result = [] + @searched_attach = paginateHelper @result,10 + else + @result = find_public_attache q,sort + @result = visable_attachemnts_insite @result,@project + @searched_attach = paginateHelper @result,10 + end else @result = find_project_attache q,@project,sort @result = visable_attachemnts @result diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index ee95277ce..f6b044c63 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -51,7 +51,7 @@ class HomeworkAttachController < ApplicationController order_by = "created_at #{direction}" end all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*, - (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1 AND stars IS NOT NULL AND stars > 0 ORDER BY updated_at DESC limit 0,1) AS t_score, + (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1 AND stars IS NOT NULL ORDER BY updated_at DESC limit 0,1) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY #{order_by}) AS table1 @@ -444,14 +444,16 @@ class HomeworkAttachController < ApplicationController homework = @homework is_teacher = @is_teacher ? 1 : 0 #保存评分@homework.rate(@m_score.to_i,User.current.id,:quality, (@is_teacher ? 1 : 0)) - if @m_score + @is_comprehensive_evaluation = @is_teacher ? 1 : (@is_anonymous_comments ? 2 : 3) #判断当前评论是老师评论?匿评?留言 + if @is_teacher || @is_anonymous_comments + @m_score ||= 0 rate = @homework.rates(:quality).where(:rater_id => User.current.id, :is_teacher_score => is_teacher).first if rate rate.stars = @m_score - rate.save! else - @homework.rates(:quality).new(:stars => @m_score, :rater_id => User.current.id, :is_teacher_score => is_teacher).save! + rate = @homework.rates(:quality).new(:stars => @m_score, :rater_id => User.current.id, :is_teacher_score => is_teacher) end + rate.save! if homework.is_teacher_score == 0 if is_teacher == 1 @@ -469,12 +471,26 @@ class HomeworkAttachController < ApplicationController end end homework.save! - end + end #保存评论 - @is_comprehensive_evaluation = @is_teacher ? 1 : (@is_anonymous_comments ? 2 : 3) #判断当前评论是老师评论?匿评?留言 - if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != "" #有没有留言 - @homework.addjours User.current.id, params[:new_form][:user_message],0,@is_comprehensive_evaluation + if params[:new_form] && params[:new_form][:user_message] #有没有留言 + jour = @homework.journals_for_messages.where("is_comprehensive_evaluation = 1 and user_id = #{User.current.id}").order("created_on DESC").first + if params[:new_form][:user_message] == "" + if @is_teacher + unless jour + jour = @homework.addjours User.current.id, "",0,@is_comprehensive_evaluation + end + end + else + jour = @homework.addjours User.current.id, params[:new_form][:user_message],0,@is_comprehensive_evaluation + end + end + + if jour + jour.save_attachments(params[:attachments]) + render_attachment_warning_if_needed(jour) + jour.save end @teacher_stars = @stars_reates.where("is_teacher_score = 1") #老师评分列表 @@ -487,7 +503,7 @@ class HomeworkAttachController < ApplicationController get_not_batch_homework_list params[:cur_sort] || "s_socre",params[:cur_direction] || "desc",@homework.bid_id elsif @cur_type == "2" #老师已批列表 @result_homework = HomeworkAttach.find_by_sql("SELECT homework_attaches.*, - (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1 AND stars IS NOT NULL AND stars > 0 ORDER BY updated_at DESC limit 0,1) AS t_score, + (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1 AND stars IS NOT NULL ORDER BY updated_at DESC limit 0,1) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE id = #{@homework.id}").first elsif @cur_type == "3" #全部作业列表 @@ -614,7 +630,7 @@ class HomeworkAttachController < ApplicationController (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE bid_id = #{bid_id} ORDER BY #{order_by}) AS table1 - WHERE table1.t_score IS NULL OR table1.t_score = 0 ") + WHERE table1.t_score IS NULL ") @all_homework_list = search_homework_member(@all_homework_list,@search_name.to_s.downcase) if @search_name # @homework_list = paginateHelper @all_homework_list,10 @homework_list = @all_homework_list diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 80be8c5d5..cadff5f15 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -58,7 +58,7 @@ class IssuesController < ApplicationController def index retrieve_query - sort_init(@query.sort_criteria.empty? ? [['updated_on', 'desc']] : @query.sort_criteria) + sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) sort_update(@query.sortable_columns) @query.sort_criteria = sort_criteria.to_a @@ -75,20 +75,19 @@ class IssuesController < ApplicationController else @limit = 10#per_page_option end - + @assign_to_id = params[:assigned_to_id] + @author_id = params[:author_id] + @priority_id = params[:priority_id] + @status_id = params[:status_id] + @subject = params[:subject] @issue_count = @query.issue_count @issue_pages = Paginator.new @issue_count, @limit, params['page'] @offset ||= @issue_pages.offset @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version], - :order => sort_clause, - :offset => @offset, - :limit => @limit) + :order => sort_clause, + :offset => @offset, + :limit => @limit) @issue_count_by_group = @query.issue_count_by_group - - - - - respond_to do |format| format.js format.html { render :template => 'issues/index', :layout => @project_base_tag }#by young @@ -127,10 +126,10 @@ class IssuesController < ApplicationController @edit_allowed = User.current.allowed_to?(:edit_issues, @project) @priorities = IssuePriority.active @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) - + @project_base_tag = (params[:project_id] || @issue.project) ? 'base_projects':'base'#by young @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq - + respond_to do |format| format.html { retrieve_previous_and_next_issue_ids @@ -170,7 +169,7 @@ class IssuesController < ApplicationController attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} redirect_to new_project_issue_url(@issue.project, :issue => attrs) else - redirect_to issue_url(@issue) + redirect_to issue_url(@issue.id) end } format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) } @@ -240,7 +239,8 @@ class IssuesController < ApplicationController flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? respond_to do |format| - format.html { redirect_back_or_default issue_path(@issue) } + + format.html { redirect_to issue_url(@issue.id) } format.api { render_api_ok } end else @@ -383,7 +383,7 @@ class IssuesController < ApplicationController def retrieve_previous_and_next_issue_ids retrieve_query_from_session if @query - sort_init(@query.sort_criteria.empty? ? [['updated_on', 'desc']] : @query.sort_criteria) + sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) sort_update(@query.sortable_columns, 'issues_index_sort') limit = 500 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version]) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 436418430..619f91245 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -93,10 +93,27 @@ class MessagesController < ApplicationController end call_hook(:controller_messages_new_after_save, { :params => params, :message => @message}) render_attachment_warning_if_needed(@message) - redirect_to board_message_url(@board, @message) + if params[:is_board] + if @project + redirect_to project_boards_path(@project) + elsif @course + redirect_to course_boards_path(@course) + end + else + redirect_to board_message_url(@board, @message) + end else - layout_file = @project ? 'base_projects' : 'base_courses' - render :action => 'new', :layout => layout_file + if params[:is_board] + if @project + redirect_to project_boards_path(@project, :flag => true) + elsif @course + redirect_to course_boards_path(@course, :flag => true) + end + else + layout_file = @project ? 'base_projects' : 'base_courses' + render :action => 'new', :layout => layout_file + end + end else respond_to do |format| @@ -111,7 +128,15 @@ class MessagesController < ApplicationController # Reply to a topic def reply if params[:reply][:content] == "" - (redirect_to board_message_url(@board, @topic, :r => @reply), :notice => l(:label_reply_empty);return) + if params[:is_board] + if @project + (redirect_to project_boards_path(@project), :notice => l(:label_reply_empty);return) + elsif @course + (redirect_to course_boards_path(@course), :notice => l(:label_reply_empty);return) + end + else + (redirect_to board_message_url(@board, @topic, :r => @reply), :notice => l(:label_reply_empty);return) + end end @quote = params[:quote][:quote] @reply = Message.new @@ -123,16 +148,24 @@ class MessagesController < ApplicationController #@topic.update_attribute(:updated_on, Time.now) if !@reply.new_record? if params[:asset_id] - ids = params[:asset_id].split(',') - update_kindeditor_assets_owner ids,@reply.id,OwnerTypeHelper::MESSAGE + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids,@reply.id,OwnerTypeHelper::MESSAGE end call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply}) attachments = Attachment.attach_files(@reply, params[:attachments]) render_attachment_warning_if_needed(@reply) - else + else #render file: 'messages#show', layout: 'base_courses' end - redirect_to board_message_url(@board, @topic, :r => @reply) + if params[:is_board] + if @project + redirect_to project_boards_path(@project) + elsif @course + redirect_to course_boards_path(@course) + end + else + redirect_to board_message_url(@board, @topic, :r => @reply) + end end @@ -144,19 +177,36 @@ class MessagesController < ApplicationController else (render_403; return false) unless @message.course_editable_by?(User.current) end + @message.safe_attributes = params[:message] if request.post? && @message.save attachments = Attachment.attach_files(@message, params[:attachments]) render_attachment_warning_if_needed(@message) flash[:notice] = l(:notice_successful_update) @message.reload - redirect_to board_message_url(@message.board, @message.root, :r => (@message.parent_id && @message.id)) + if params[:is_board] + if @project + redirect_to project_boards_path(@project) + elsif @course + redirect_to course_boards_path(@course) + end + else + redirect_to board_message_url(@message.board, @message.root, :r => (@message.parent_id && @message.id)) + end elsif request.get? - respond_to do |format| - format.html { - layout_file = @project ? 'base_projects' : 'base_courses' - render :layout => layout_file - } + if params[:is_board] + if @project + redirect_to project_boards_path(@project) + elsif @course + redirect_to course_boards_path(@course) + end + else + respond_to do |format| + format.html { + layout_file = @project ? 'base_projects' : 'base_courses' + render :layout => layout_file + } + end end end end @@ -172,16 +222,20 @@ class MessagesController < ApplicationController @message.destroy # modify by nwb if @project - if @message.parent - redirect_to board_message_url(@board, @message.parent, :r => r) - else + if params[:is_board] redirect_to project_boards_url(@project) + else + redirect_to board_message_url(@board, @topic, :r => @reply) end elsif @course - if @message.parent - redirect_to board_message_url(@board, @message.parent, :r => r) + if params[:is_board] + redirect_to course_boards_url(@course) else - redirect_to course_board_url(@course, @board) + if @message.parent + redirect_to board_message_url(@board, @message.parent, :r => r) + else + redirect_to course_board_url(@course, @board) + end end end end @@ -202,7 +256,7 @@ class MessagesController < ApplicationController render :partial => 'common/preview' end -private + private def find_message return unless find_board @message = @board.messages.find(params[:id], :include => :parent) diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 7ff015fbc..69d8bc3a6 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -20,7 +20,7 @@ class MyController < ApplicationController # edit before_filter :auth_login1, :only => [:account] # - before_filter :require_login + before_filter :require_login, except: [:change_mail_notification] helper :issues helper :users @@ -75,6 +75,19 @@ class MyController < ApplicationController end end + def change_mail_notification + token = params[:token] + user = try_to_autologin1 + if user + user.mail_notification = params[:mail_notification] + user.save + flash[:notice] = l(:notice_mail_notification_updated) + redirect_to my_account_url + else + redirect_to signin_url + end + end + # Edit user's account def account @user = User.current @@ -82,76 +95,46 @@ class MyController < ApplicationController @pref = @user.pref diskfile = disk_filename('User', @user.id) diskfile1 = diskfile + 'temp' - if request.post? - @user.safe_attributes = params[:user] - @user.pref.attributes = params[:pref] - @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') - @user.login = params[:login] - unless @user.user_extensions.nil? - if @user.user_extensions.identity == 2 - @user.firstname = params[:enterprise_name] - end - end - - @se = @user.extensions - if params[:occupation].to_i.to_s == params[:occupation] - @se.school_id = params[:occupation] - else - @se.occupation = params[:occupation] - end - @se.gender = params[:gender] - @se.location = params[:province] if params[:province] - @se.location_city = params[:city] if params[:city] - @se.identity = params[:identity].to_i if params[:identity] - @se.technical_title = params[:technical_title] if params[:technical_title] - @se.student_id = params[:no] if params[:no] - - if @user.save && @se.save - # 头像保存 - if File.exist?(diskfile1) - if File.exist?(diskfile) - File.delete(diskfile) - end - File.open(diskfile1, "rb") do |f| - buffer = f.read(10) - if buffer != "DELETE" - File.open(diskfile1, "rb") do |f1| - File.open(diskfile, "wb") do |f| - buffer = "" - while (buffer = f1.read(8192)) - f.write(buffer) - end - end - end - - # File.rename(diskfile + 'temp',diskfile); - end + begin + if request.post? + @user.safe_attributes = params[:user] + @user.pref.attributes = params[:pref] + @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') + @user.login = params[:login] + unless @user.user_extensions.nil? + if @user.user_extensions.identity == 2 + @user.firstname = params[:enterprise_name] end end - # 确保文件被删除 - if File.exist?(diskfile1) - File.delete(diskfile1) + @se = @user.extensions + if params[:occupation].to_i.to_s == params[:occupation] + @se.school_id = params[:occupation] + else + @se.occupation = params[:occupation] end + @se.gender = params[:gender] + @se.location = params[:province] if params[:province] + @se.location_city = params[:city] if params[:city] + @se.identity = params[:identity].to_i if params[:identity] + @se.technical_title = params[:technical_title] if params[:technical_title] + @se.student_id = params[:no] if params[:no] - @user.pref.save - @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) - set_language_if_valid @user.language - flash[:notice] = l(:notice_account_updated) - redirect_to user_url(@user) - return - else - # 确保文件被删除 - if File.exist?(diskfile1) - File.delete(diskfile1) + if @user.save && @se.save + # 头像保存 + FileUtils.mv diskfile1, diskfile, force: true if File.exist? diskfile1 + @user.pref.save + @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) + set_language_if_valid @user.language + flash[:notice] = l(:notice_account_updated) + redirect_to user_url(@user) + return + else + @user.login = lg end - @user.login = lg - end - else - # 确保文件被删除 - if File.exist?(diskfile1) - File.delete(diskfile1) end + ensure + File.delete(diskfile1) if File.exist?(diskfile1) end end @@ -187,31 +170,20 @@ class MyController < ApplicationController @user = us.change_password params.merge(:current_user_id => @user.id) if @user.errors.full_messages.count <= 0 flash.now[:notice] = l(:notice_account_password_updated) - redirect_to my_account_url + # 修改完密码,让其重新登录,并更新Token + Token.delete_user_all_tokens(@user) + logout_user + redirect_to signin_url(back_url: my_account_path) + else + flash.now[:error] = l(:notice_account_wrong_password) end end rescue Exception => e if e.message == 'wrong password' flash.now[:error] = l(:notice_account_wrong_password) + else + flash.now[:error] = e.message end - # @user = User.current - # unless @user.change_password_allowed? - # flash.now[:error] = l(:notice_can_t_change_password) - # redirect_to my_account_url - # return - # end - # if request.post? - # if @user.check_password?(params[:password]) - # @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation] - # - # if @user.save - # flash.now[:notice] = l(:notice_account_password_updated) - # redirect_to my_account_url - # end - # else - # flash.now[:error] = l(:notice_account_wrong_password) - # end - # end end # Create a new feeds key diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index d41491349..f71a77ca7 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -152,6 +152,9 @@ class NewsController < ApplicationController end def edit + if @course + render :layout => "base_courses" + end end def update diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 5e67e0a2c..536ea6bba 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -31,7 +31,7 @@ class ProjectsController < ApplicationController 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 :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar] - before_filter :file, :statistics, :watcherlist + before_filter :file, :statistics #:watcherlist # 除非项目内人员,不可查看成员, TODO: 完了写报表里去 before_filter :memberAccess, only: :member @@ -243,18 +243,13 @@ class ProjectsController < ApplicationController # Author lizanle # Description 项目动态展示方法,删除了不必要的代码 def show - - # 试图跳转到请求的按钮 - if params[:login] - login = params[:login] - login = login.sub(/%40/,'@') - mail = params[:login] - password = params[:password] - us = UsersService.new - user = us.register_auto(login,mail, password) - Member.create(:role_ids => [4], :user_id => user.id,:project_id => @project.id) - UserGrade.create(:user_id => user.id, :project_id => @project.id) - User.current = user unless User.current.nil? + # params[:login]为邮箱邀请用户加入,主要功能: + # 1、自动注册 + # 2、加入项目、创建角色 + # 3、用户得分 + if params[:mail] + Member.create(:role_ids => [4], :user_id => params[:user],:project_id => params[:id]) + UserGrade.create(:user_id =>params[:user], :project_id => params[:id]) end if params[:jump] && redirect_to_project_menu_item(@project, params[:jump]) return @@ -348,12 +343,22 @@ class ProjectsController < ApplicationController end + # 两种情况:1、系统外用户;2、系统内用户 (通过邮件判定) def send_mail_to_member if !params[:mail].blank? && User.find_by_mail(params[:mail].to_s).nil? email = params[:mail] Mailer.run.send_invite_in_project(email, @project, User.current) @is_zhuce =false flash[:notice] = l(:notice_email_sent, :value => email) + elsif !User.find_by_mail(params[:mail].to_s).nil? + user = User.find_by_mail(params[:mail].to_s) + if !user.member_of?(@project) + email = params[:mail] + Mailer.run.request_member_to_project(email, @project, User.current) + flash[:notice] = l(:notice_email_sent, :value => email) + else + flash[:error] = l(:label_member_of_project, :value => email) + end else flash[:error] = l(:notice_registed_error, :value => email) @is_zhuce = true @@ -362,6 +367,7 @@ class ProjectsController < ApplicationController format.html{redirect_to invite_members_by_mail_project_url(@project)} end end + #发送邮件邀请新用户 def invite_members_by_mail if User.current.member_of?(@project) || User.current.admin? @@ -411,10 +417,14 @@ class ProjectsController < ApplicationController @members = @project.member_principals.includes(:roles, :principal).all.sort end else - roles = Role.find_all_givable - @subPage_title = l :label_member_list - @members = @project.member_principals.includes(:roles, :principal).joins("LEFT JOIN #{OptionNumber.table_name} ON #{OptionNumber.table_name}.user_id = #{Member.table_name}.user_id and #{OptionNumber.table_name}.score_type = 2 AND #{Member.table_name}.project_id = #{OptionNumber.table_name}.project_id").order("#{OptionNumber.table_name}.total_score DESC").all - @applied_members = appied_project_members(@project, @members) + if !@project.is_public? && !User.current.member_of?(@project) && !User.current.admin? + render_403 + else + roles = Role.find_all_givable + @subPage_title = l :label_member_list + @members = @project.member_principals.includes(:roles, :principal).joins("LEFT JOIN #{OptionNumber.table_name} ON #{OptionNumber.table_name}.user_id = #{Member.table_name}.user_id and #{OptionNumber.table_name}.score_type = 2 AND #{Member.table_name}.project_id = #{OptionNumber.table_name}.project_id").order("#{OptionNumber.table_name}.total_score DESC").all + @applied_members = appied_project_members(@project, @members) + end end @members = paginateHelper @members render :layout => 'base_courses' if @project.project_type == 1 @@ -670,11 +680,13 @@ class ProjectsController < ApplicationController true end - # added by huang - def watcherlist - if @watched - @users -= watched.watcher_users + unless @project.nil? + if !@project.is_public? && !User.current.member_of?(@project) && !User.current.admin? + render_403 + else + @users -= watched.watcher_users if @watched + end end end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index c90cc1cc3..d0af82c8c 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -236,34 +236,20 @@ update end def destroy - @root_path=RepositoriesHelper::ROOT_PATH - @repo_name=User.current.login.to_s+"_"+@repository.identifier.to_s - @repository_name=User.current.login.to_s+"/"+@repository.identifier.to_s+".git" - @middle=User.current.login.to_s+"_"+@repository.identifier.to_s+"-write:" - @repository.destroy if request.delete? + DestroyRepositoryTask.new.destroy(User.current.id, @repository.id) + @repository.hidden = true + @repository.save redirect_to settings_project_url(@project, :tab => 'repositories') - if(@repository.type=="Repository::Git") - logger.info "destory the repository value"+"root path"+@root_path+"repo_name"+@repo_name+ - "repository_name"+@repository_name+"user group"+@middle - system "sed -i /"+@repo_name+"/{d} "+@root_path+"htdocs/user.passwd" - system "sed -i /"+@middle+"/{d} "+@root_path+"htdocs/group.passwd" - system "rm -r "+@root_path+"htdocs/"+@repository_name - # if(@sed_user&&@sed_group&&@remove) - # else - # logger.info "An error occured when destory the repository"+"delete form passwd: \n"+ - # @sed_user+"delete from group"+@sed_group+"delete from file"+@remove - # end - end end def show ## TODO: the below will move to filter, done. - # if !User.current.member_of?(@project) - # if @project.hidden_repo - # render_403 - # return -1 - # end - # end + if !User.current.member_of?(@project) + if @project.hidden_repo + render_403 + return -1 + end + end #if( !User.current.member_of?(@project) || @project.hidden_repo) @repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty? diff --git a/app/controllers/test_controller.rb b/app/controllers/test_controller.rb index 22cf7d1d5..51ff293f1 100644 --- a/app/controllers/test_controller.rb +++ b/app/controllers/test_controller.rb @@ -57,5 +57,98 @@ class TestController < ApplicationController attach.filename end + def mailer() + raise unless Rails.env.development? + @user = User.find(params[:user_id]) + send_for_user_activities(@user, Time.now,1) + render 'mailer/send_for_user_activities' + end + def send_for_user_activities(user, date_to, days) + date_from = date_to - days.days + + subject = "[ #{user.show_name}#{l(:label_day_mail)}]" + @subject = " #{user.show_name}#{l(:label_day_mail)}" + + date_from = "#{date_from} 17:59:59" + date_to = "#{date_to} 17:59:59" + + # 生成token用于直接点击登录 + @user = user + token = Token.new(:user =>user , :action => 'autologin') + token.save + @token = token + + # 查询user参加的项目及课程 + projects = user.projects + courses = user.courses + project_ids = projects.map{|project| project.id}.join(",") + course_ids = courses.map {|course| course.id}.join(",") + + # 查询user的缺陷,包括发布的,跟踪的以及被指派的缺陷 + sql = "select DISTINCT i.* from issues i, watchers w + where (i.assigned_to_id = #{user.id} or i.author_id = #{user.id} + or (w.watchable_type = 'Issue' and w.watchable_id = i.id and w.user_id = #{user.id})) + and (i.created_on between '#{date_from}' and '#{date_to}') order by i.created_on desc" + @issues = Issue.find_by_sql(sql) + + # @bids 查询课程作业,包括老师发布的作业,以及user提交作业 + # @attachments查询课程课件更新 + @attachments ||= [] + + @bids ||= [] # 老师发布的作业 + + unless courses.first.nil? + count = courses.count + count = count - 1 + for i in 0..count do + bids = courses[i].homeworks.where("bids.created_on between '#{date_from}' and '#{date_to}'").order("bids.created_on desc") + attachments = courses[i].attachments.where("attachments.created_on between '#{date_from}' and '#{date_to}'").order('attachments.created_on DESC') + @bids += bids if bids.count > 0 + @attachments += attachments if attachments.count > 0 + end + end + # user 提交的作业 + @homeworks = HomeworkAttach.where("user_id=#{user.id} and (created_at between '#{date_from}' and '#{date_to}')").order("created_at desc") + + # 查询user在课程。项目中发布的讨论帖子 + messages = Message.find_by_sql("select DISTINCT * from messages where author_id = #{user.id} and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") + @course_messages ||= [] + @project_messages ||= [] + unless messages.first.nil? + messages.each do |msg| + if msg.project + @project_messages << msg + elsif msg.course + @course_messages << msg + end + end + end + # 查询user在课程中发布的通知,项目中发的新闻 + @course_news = (course_ids && !course_ids.empty?) ? News.find_by_sql("select DISTINCT n.* from news n + where n.course_id in (#{course_ids}) + and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") : [] + @project_news = (project_ids && !project_ids.empty?) ? News.find_by_sql("select DISTINCT n.* from news n where n.project_id in (#{project_ids}) + and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") : [] + + # 查询user在课程及个人中留言 + @course_journal_messages = JournalsForMessage.find_by_sql("select DISTINCT * from journals_for_messages where + jour_type='Course' and user_id = #{user.id} + and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") + @user_journal_messages = user.journals_for_messages.where("m_parent_id IS NULL and (created_on between '#{date_from}' and '#{date_to}')").order('created_on DESC') + + + # 查询user新建贴吧或发布帖子 + @forums = Forum.find_by_sql("select DISTINCT * from forums where creator_id = #{user.id} and (created_at between '#{date_from}' and '#{date_to}') order by created_at desc") + @memos = Memo.find_by_sql("select DISTINCT m.* from memos m, forums f where (m.author_id = #{user.id} or (m.forum_id = f.id and f.creator_id = #{user.id})) + and (m.created_at between '#{date_from}' and '#{date_to}') order by m.created_at desc") + + + has_content = [@issues,@homeworks,@course_messages,@project_messages,@course_news,@project_news, + @course_journal_messages,@user_journal_messages,@forums,@memos,@attachments,@bids].any? {|o| + !o.empty? + } + #有内容才发,没有不发 + end + -end \ No newline at end of file +end diff --git a/app/controllers/trackers_controller.rb b/app/controllers/trackers_controller.rb index 01bc47a2f..64ad9c83a 100644 --- a/app/controllers/trackers_controller.rb +++ b/app/controllers/trackers_controller.rb @@ -38,12 +38,13 @@ class TrackersController < ApplicationController @tracker ||= Tracker.new(params[:tracker]) @trackers = Tracker.sorted.all @projects = Project.where("project_type = #{Project::ProjectType_project}").all - @courses = Course.all - @course_activity_count=Hash.new - @courses.each do |course| - @course_activity_count[course.id]=0 - end - @course_activity_count=get_course_activity @courses,@course_activity_count + # 去掉原因,这块代码已经没有用到 + # @courses = Course.all + # @course_activity_count=Hash.new + # @courses.each do |course| + # @course_activity_count[course.id]=0 + # end + # @course_activity_count=get_course_activity @courses,@course_activity_count end def create diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 2a10af260..ace4ae903 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -383,6 +383,8 @@ class UsersController < ApplicationController # scope = User.logged.status(@status) # @search_by = params[:search_by] ? params[:search_by][:id] : 0 # scope = scope.like(params[:name],@search_by) if params[:name].present? + @search_by = params[:search_by] ? params[:search_by] : 0 + us = UsersService.new scope = us.search_user params @user_count = scope.count diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index f35210f01..6e067fb83 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -58,12 +58,18 @@ class WelcomeController < ApplicationController else case @first_page.sort_type when 0 + @my_projects = find_my_projects + @other_projects = @my_projects.count < 9 ? find_miracle_project( 9 - @my_projects.count, 3,"score desc") : [] @projects = find_miracle_project(10, 3,"created_on desc") #@projects = @projects_all.order("created_on desc") when 1 + @my_projects = find_my_projects + @other_projects = @my_projects.count < 9 ? find_miracle_project( 9 - @my_projects.count, 3,"score desc") : [] @projects = find_miracle_project(10, 3,"score desc") #@projects = @projects_all.order("grade desc") when 2 + @my_projects = find_my_projects + @other_projects = @my_projects.count < 9 ? find_miracle_project( 9 - @my_projects.count, 3,"score desc") : [] @projects = find_miracle_project(10, 3,"watchers_count desc") #@projects = @projects_all.order("watchers_count desc") diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index 680a13963..cc6c4f47e 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -81,9 +81,13 @@ class WordsController < ApplicationController @journal_destroyed = JournalsForMessage.delete_message(params[:object_id]) if @journal_destroyed.jour_type == "Bid" @bid = Bid.find(@journal_destroyed.jour_id) - end - if @bid @jours_count = @bid.journals_for_messages.where('m_parent_id IS NULL').count + elsif @journal_destroyed.jour_type == "Course" + @course = Course.find @journal_destroyed.jour_id + @jours_count = @course.journals_for_messages.where('m_parent_id IS NULL').count + elsif @journal_destroyed.jour_type == "Principal" + @user = User.find(@journal_destroyed.jour_id) + @jours_count = @user.journals_for_messages.where('m_parent_id IS NULL').count end respond_to do |format| format.js diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index df354f107..06d69f72e 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -188,6 +188,7 @@ class ZipdownController < ApplicationController files_paths.each do |filename| rename_file = File.basename(filename) rename_file = filename_to_real( File.basename(filename)) if is_attachment + begin zipfile.add(rename_file, filename) rescue Exception => e @@ -238,4 +239,4 @@ class ZipdownController < ApplicationController attach = Attachment.find_by_disk_filename(name) attach.filename end -end \ No newline at end of file +end diff --git a/app/helpers/account_helper.rb b/app/helpers/account_helper.rb index 7ad6fe65b..827557a40 100644 --- a/app/helpers/account_helper.rb +++ b/app/helpers/account_helper.rb @@ -47,6 +47,18 @@ module AccountHelper user end + # 自动创建一个新用户,但是初始状态是锁定的 + def automatically_register_lock(user, &block) + user.lock + user.last_login_on = Time.now + if user.save + UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0) + else + yield if block_given? + end + user + end + def administrator_manually__register(user, &block) if user.save UserStatus.create(:user_id => user.id ,:changsets_count => 0, :watchers_count => 0) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 20175dc57..a07ff320d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -118,11 +118,11 @@ module ApplicationHelper end #if user.active? || (User.current.admin? && user.logged?) - # link_to name, {:controller=> 'users', :action => 'show', id: user.id, host: Setting.user_domain}, :class => user.css_classes + # link_to name, {:controller=> 'users', :action => 'show', id: user.id, host: Setting.host_user}, :class => user.css_classes #else # name #end - link_to name, {:controller=> 'users', :action => 'show', id: user.id, host: Setting.user_domain}, :class => user.css_classes + link_to name, {:controller=> 'users', :action => 'show', id: user.id, host: Setting.host_user}, :class => user.css_classes else h(user.to_s) end @@ -131,7 +131,7 @@ module ApplicationHelper def link_to_isuue_user(user, options={}) if user.is_a?(User) name = h(user.name(options[:format])) - link_to name, {:controller=> 'users', :action => 'show', id: user.id, host: Setting.user_domain}, :class => "pro_info_p" + link_to name, {:controller=> 'users', :action => 'show', id: user.id, host: Setting.host_user}, :class => "pro_info_p" else h(user.to_s) end @@ -140,7 +140,7 @@ module ApplicationHelper def link_to_settings_user(user, options={}) if user.is_a?(User) name = h(user.name(options[:format])) - link_to name, {:controller=> 'users', :action => 'show', id: user.id, host: Setting.user_domain}, :class => "w90 c_orange fl" + link_to name, {:controller=> 'users', :action => 'show', id: user.id, host: Setting.host_user}, :class => "w90 c_orange fl" else h(user.to_s) end @@ -155,7 +155,7 @@ module ApplicationHelper else name = user.login end - link_to name, {:controller=> 'users', :action => 'show', id: user.id, host: Setting.user_domain}, :class => options[:class] + link_to name, {:controller=> 'users', :action => 'show', id: user.id, host: Setting.host_user}, :class => options[:class] else h(user.to_s) end @@ -326,14 +326,15 @@ module ApplicationHelper end def thumbnail_issue_tag(attachment) - imagesize = attachment.thumbnail(:size => "50*50") + imagesize = attachment.thumbnail(:size => "200*200") imagepath = named_attachment_path(attachment, attachment.filename) if imagesize - link_to image_tag(imagesize), + link_to image_tag(thumbnail_path(attachment), height: '73', width: '100', class: 'issue_attachment_picture'), imagepath, :title => attachment.filename + else - link_to image_tag(imagepath , height: '73', width: '100'), + link_to image_tag(imagepath , height: '73', width: '100', class: 'issue_attachment_picture'), imagepath, :title => attachment.filename end @@ -592,6 +593,42 @@ module ApplicationHelper Project.project_tree(projects, &block) end + # 项目版本库可见权限判断 + # 条件:1、modules中设置不可见或项目没有版本库;2、如果项目是私有或者项目版本库隐藏则必须是项目成员才可见 + def visible_repository?(project) + @result = false + unless project.enabled_modules.where("name = 'repository'").empty? || project.repositories.count == 0 + if (project.hidden_repo || !project.is_public?) + if User.current.member_of?(project) + @result = true + end + else + @result = true + end + end + return @result + end + + # 判断当前用户是否为项目管理员 + def is_project_manager?(user_id, project_id) + @result = false + mem = Member.where("user_id = ? and project_id = ?",user_id, project_id) + unless mem.blank? + @result = mem.first.roles.to_s.include?("Manager") ? true : false + end + return @result + end + + # 公开项目资源可以引用,admin和管理员和资源上传者拥有设置公开私有权限 + def authority_pubilic_for_files(project, file) + @result = false + if (is_project_manager?(User.current.id, @project.id) && User.current.allowed_to?(:manage_files, project)) || file.author_id == User.current.id || User.current.admin && + project_contains_attachment?(project,file) && file.container_id == project.id && file.container_type == "Project" + @result = true + end + return @result + end + def principals_check_box_tags(name, principals) s = '' principals.each do |principal| @@ -633,7 +670,7 @@ module ApplicationHelper def principals_check_box_tags_li(name, principals) s = '' principals.each do |principal| - s << "
  • #{ check_box_tag name, principal.id, false, :id => nil } #{h link_to principal.userInfo, user_path( principal.id), :class => "c_blue" }
  • \n" + s << "
  • #{ check_box_tag name, principal.id, false, :id => nil } #{h link_to principal.userInfo, user_path( principal.id) }
  • \n" end s.html_safe end @@ -1769,8 +1806,7 @@ module ApplicationHelper def get_memo @new_memo = Memo.new - #@new_memo.subject = "有什么想说的,尽管来咆哮吧~~" - @public_forum = Forum.find(1) + @public_forum = Forum.find(1) rescue ActiveRecord::RecordNotFound end #获取用户未过期的课程 @@ -2065,21 +2101,21 @@ module ApplicationHelper hidden_non_project = Setting.find_by_name("hidden_non_project") visiable = !(hidden_non_project && hidden_non_project.value == "0") - main_course_link = link_to l(:label_course_practice), {:controller => 'welcome', :action => 'index', :host => Setting.course_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_course_link = link_to l(:label_course_practice), {:controller => 'welcome', :action => 'index', :host => Setting.host_course} + main_project_link = link_to l(:label_project_deposit), {:controller => 'welcome', :action => 'index', :host => Setting.host_name} + main_contest_link = link_to l(:label_contest_innovate), {:controller => 'welcome', :action => 'index', :host => Setting.host_contest} # 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.host_course} # courses_link = link_to l(:label_course_practice), {:controller => 'courses', :action => 'index'} - #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.host_user} # contest_link = link_to l(:label_contest_innovate), {:controller => 'contests', :action => 'index'} bids_link = link_to l(:label_requirement_enterprise), {:controller => 'bids', :action => 'index'} forum_link = link_to l(:label_forum_all), {:controller => "forums", :action => "index"} stores_link = link_to l(:label_stores_index), {:controller => 'stores', :action=> 'index'} school_all_school_link = link_to l(:label_school_all), {:controller => 'school', :action => 'index'} - project_new_link = link_to l(:label_project_new), {:controller => 'projects', :action => 'new', :host => Setting.project_domain} - # project_mine_link = link_to l(:label_my_project), {:controller => 'users', :action => 'user_projects', :host => Setting.project_domain} + project_new_link = link_to l(:label_project_new), {:controller => 'projects', :action => 'new', :host => Setting.host_name} + # project_mine_link = link_to l(:label_my_project), {:controller => 'users', :action => 'user_projects', :host => Setting.host_name} #@nav_dispaly_project_label nav_list = Array.new diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 801d98b0b..babd8cb12 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -797,4 +797,17 @@ module CoursesHelper end result end + + def zh_course_role role + if role == "TeachingAsistant" + result = l(:label_TA) + elsif role == "Teacher" + result = l(:label_teacher) + elsif role == "Student" + result = l(:label_student) + elsif role == "Manager" + result = l(:field_admin) + end + result + end end diff --git a/app/helpers/gitlab_helper.rb b/app/helpers/gitlab_helper.rb index ceaaf6d21..836a973a9 100644 --- a/app/helpers/gitlab_helper.rb +++ b/app/helpers/gitlab_helper.rb @@ -11,7 +11,7 @@ module GitlabHelper PROJECT_PATH_CUT = 40 # gitlab版本库所在服务器 # 注意REPO_IP_ADDRESS必须以http://开头,暂时只支持HTTP协议,未支持SSH - #REPO_IP_ADDRESS = "http://" + Setting.repository_domain + #REPO_IP_ADDRESS = "http://" + Setting.host_repository REPO_IP_ADDRESS = "http://192.168.137.100" GITLAB_API = "/api/v3" diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index b72a191db..aae150728 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -67,29 +67,33 @@ module IssuesHelper s.html_safe end - #获取跟踪类型 - #REDO:时间紧需要优化,两个方法可以综合成一个 + #获取跟踪类型及样式 + #REDO:时间紧可以优化. def get_issue_type(value) + issuetype = [] if value == "缺陷" || value == 1 - class_type = "red_btn_cir ml10" + issuetype << "red_btn_cir ml10" + issuetype << "缺陷" elsif value == "功能" || value == 2 - class_type = "blue_btn_cir ml10" + issuetype << "blue_btn_cir ml10" + issuetype << "功能" elsif value == "支持" || value == 3 - class_type = "green_btn_cir ml10" + issuetype << "green_btn_cir ml10" + issuetype << "支持" + elsif value == "任务" || value == 4 + issuetype << "orange_btn_cir ml10" + issuetype << "任务" else - class_type = "orange_btn_cir ml10" + issuetype << "bgreen_btn_cir ml10" + issuetype << "周报" end end - def get_issue_typevalue(value) - if value == "缺陷" || value == 1 - assign = "缺陷" - elsif value == "功能" || value == 2 - assign = "功能" - elsif value == "支持" || value == 3 - assign = "支持" + def principals_options_for_isuue_list(project) + if User.current.member_of?(project) + project.members.order("lower(users.login)").map{|c| [c.name, c.user_id]}.unshift(["<< #{l(:label_me)} >>", User.current.id]).unshift(["指派给", 0]) else - assign = "任务" + project.members.order("lower(users.login)").map{|c| [c.name, c.user_id]}.unshift(["指派给", 0]) end end diff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rb index 34c6dad15..06b154d36 100644 --- a/app/helpers/members_helper.rb +++ b/app/helpers/members_helper.rb @@ -32,7 +32,7 @@ module MembersHelper #获取项目可邀请的成员列表 def render_project_members project - if params[:q] && params[:q] != "" + if params[:q] && params[:q].lstrip.rstrip != "" scope = Principal.active.sorted.not_member_of(project).like(params[:q]) else scope = [] @@ -48,7 +48,7 @@ module MembersHelper # add by nwb # 课程可添加的成员列表 def render_principals_for_new_course_members(course) - if params[:q] && params[:q] != "" + if params[:q] && params[:q].lstrip.rstrip != "" scope = Principal.active.sorted.not_member_of_course(course).like(params[:q]) else scope = [] @@ -63,19 +63,6 @@ module MembersHelper s + content_tag('ul', links,:class => 'wlist',:id => "course_member_pagination_links") end - # 项目配置中添加成员列表 - def render_principals_for_new_project_members(project) - scope = Principal.active.sorted.not_member_of(project).like(params[:q]) - principals = paginateHelper scope,10 - s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :id => 'principals') - - links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true) {|text, parameters, options| - link_to text, appliedproject_project_memberships_path(project, parameters.merge(:q => params[:q], :format => 'js')), :remote => true - } - - s + content_tag('ul', links,:class => 'wlist',:id => "course_member_pagination_links") - end - # 新申请加入项目成员列表 def render_principals_for_applied_members_new project scope = project.applied_projects.map(&:user) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 508e58ba3..12925b0b1 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -65,6 +65,16 @@ module ProjectsHelper content_tag('div', content, :class => "tabs") end + # 判断我的项目中是否有重名项目 + def judge_same_projectname(user, project_name) + result = false + my_projects = user.projects + my_projects.each do |mp| + result = true if mp.name == project_name + end + return result + end + # Added by young def course_settings_tabs tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural, :course=>'1'}, diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb index e1d8c3e12..43d01a5dd 100644 --- a/app/helpers/queries_helper.rb +++ b/app/helpers/queries_helper.rb @@ -243,19 +243,19 @@ module QueriesHelper # Retrieve query from session or build a new query def retrieve_query - if !params[:query_id].blank? - cond = "project_id IS NULL" - cond << " OR project_id = #{@project.id}" if @project - @query = IssueQuery.find(params[:query_id], :conditions => cond) - raise ::Unauthorized unless @query.visible? - @query.project = @project - session[:query] = {:id => @query.id, :project_id => @query.project_id} - sort_clear - elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) + # if !params[:query_id].blank? + # cond = "project_id IS NULL" + # cond << " OR project_id = #{@project.id}" if @project + # @query = IssueQuery.find(params[:query_id], :conditions => cond) + # raise ::Unauthorized unless @query.visible? + # @query.project = @project + # session[:query] = {:id => @query.id, :project_id => @query.project_id} + # sort_clear + # elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) # Give it a name, required to be valid @query = IssueQuery.new(:name => "_") @query.project = @project - params[:f] = %w(subject status_id priority_id author_id assigned_to_id) unless params[:status_id].nil? + params[:f] = %w(subject status_id priority_id author_id assigned_to_id created_on) unless params[:status_id].nil? params[:op] = {'subject' => "~" , 'status_id' => ( params[:status_id] == '0' ? "!":"=" ), 'priority_id' => ( params[:priority_id] == '0' ? "!":"=" ), @@ -266,14 +266,30 @@ module QueriesHelper 'priority_id' => [params[:priority_id]], 'author_id' => [params[:author_id]], 'assigned_to_id' => [params[:assigned_to_id]]} unless params[:status_id].nil? + if(params[:status_id] != nil) + if( params[:issue_create_date_start]!=nil && params[:issue_create_date_start]!='' && + params[:issue_create_date_end]!=nil && params[:issue_create_date_end]!='' ) + params[:op][:created_on]='><' + params[:v][:created_on]=[params[:issue_create_date_start],params[:issue_create_date_end]] + elsif(params[:issue_create_date_start]!=nil && params[:issue_create_date_start]!='') + params[:op][:created_on]='>=' + params[:v][:created_on]=[params[:issue_create_date_start]] + elsif(params[:issue_create_date_end]!=nil && params[:issue_create_date_end]!='') + params[:op][:created_on]='<=' + params[:v][:created_on]=[params[:issue_create_date_end]] + else + params[:op][:created_on]='!' + params[:v][:created_on]='' + end + end @query.build_from_params(params) #session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names} - else - # retrieve from session - @query = IssueQuery.find_by_id(session[:query][:id]) if session[:query][:id] - @query ||= IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) - @query.project = @project - end + # else + # # retrieve from session + # @query = IssueQuery.find_by_id(session[:query][:id]) if session[:query][:id] + # @query ||= IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) + # @query.project = @project + # end end def retrieve_query_from_session diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 3c7123435..5cbc3af5a 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -18,9 +18,13 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. module RepositoriesHelper - ROOT_PATH="/home/pdl/redmine-2.3.2-0/apache2/" + if Rails.env.development? + ROOT_PATH="/tmp/" if Rails.env.development? + else + ROOT_PATH="/home/pdl/redmine-2.3.2-0/apache2/" + end PROJECT_PATH_CUT = 40 - REPO_IP_ADDRESS = Setting.repository_domain + REPO_IP_ADDRESS = Setting.host_repository def format_revision(revision) if revision.respond_to? :format_identifier @@ -228,6 +232,18 @@ module RepositoriesHelper :label => l(:label_git_report_last_commit) )) end + + # 判断项目是否有主版本库 + def judge_main_repository(pro) + if pro.repositories.blank? + return false + else + pro.repositories.sort.each do |rep| + rep.is_default? + return true + end + end + end # def cvs_field_tags(form, repository) # content_tag('p', form.text_field( # :root_url, diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index f6e205e82..4800a949a 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -443,6 +443,10 @@ module WelcomeHelper resultSet.take(limit) end + def find_my_projects + my_projects = User.current.memberships.all(conditions: "projects.project_type = 0") + end + def sort_project_by_hot_rails project_type=0, order_by='score DESC', limit=15 # Project.find_by_sql(" # SELECT p.id, p.name, p.description, p.identifier, t.project_id diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 396501862..239a15881 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -52,11 +52,11 @@ class JournalsForMessage < ActiveRecord::Base :permission => :view_course_journals_for_messages, :timestamp => "#{self.table_name}.updated_on", :find_options => {:include => :course } - + acts_as_attachable has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy - validates :notes, presence: true + validates :notes, presence: true, if: :is_homework_jour? after_create :act_as_activity #huang after_create :reset_counters! after_destroy :reset_counters! @@ -88,6 +88,10 @@ class JournalsForMessage < ActiveRecord::Base self.find(message_id).destroy # self.destroy_all "id = #{message_id}" end + + def is_homework_jour? + self.jour_type != "HomeworkAttach" + end def reference_user User.find(reply_id) diff --git a/app/models/mailer.rb b/app/models/mailer.rb index ce3924119..2c3a94874 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -33,7 +33,7 @@ class Mailer < ActionMailer::Base @target = cls end def method_missing(name, *args, &block) - if Setting.delayjob_enabled && Object.const_defined?('Delayed') + if Setting.delayjob_enabled? && Object.const_defined?('Delayed') @target.delay.send(name, *args, &block) else @target.send(name, *args, &block).deliver @@ -52,8 +52,28 @@ class Mailer < ActionMailer::Base @email = email @subject = "#{invitor.name} #{l(:label_invite_project)} #{project.name} " @password = newpass(6) - @project_url = url_for(:controller => 'projects', :action => 'show', :id => project.id, - :password => @password, :login => email) + + login = email + login = login.sub(/%40/,'@') + us = UsersService.new + # 自动激活用户 + user = us.register_auto(login, @email, @password) + User.current = user unless User.current.nil? + @user = user + @token = Token.get_token_from_user(user, 'autologin') + @project_url = url_for(:controller => 'projects', :action => 'show', :id => project.id, :user => user.id, :mail => true, :token => @token.value) + mail :to => email, :subject => @subject + end + + # 邀请已注册的用户加入项目 + def request_member_to_project(email, project, invitor) + @subject = "#{invitor.name} #{l(:label_invite_project)}: #{project.name} " + user = User.find_by_mail(email.to_s) + @invitor_name = "#{invitor.name}" + @project_name = "#{project.name}" + @user = user + @token = Token.get_token_from_user(user, 'autologin') + @project_url = url_for(:controller => 'projects', :action => 'show', :id => project.id, :user => user.id, :mail => true, :token => @token.value) mail :to => email, :subject => @subject end @@ -63,19 +83,16 @@ class Mailer < ActionMailer::Base def send_for_user_activities(user, date_to, days) date_from = date_to - days.days - subject = "[ #{user.show_name} : #{l(:label_day_mail)}]" - @subject = " #{user.show_name} : #{date_to} #{l(:label_day_mail)}" + subject = "[ #{user.show_name}#{l(:label_day_mail)}]" + @subject = " #{user.show_name}#{l(:label_day_mail)}" date_from = "#{date_from} 17:59:59" date_to = "#{date_to} 17:59:59" # 生成token用于直接点击登录 @user = user - token = Token.new(:user =>user , :action => 'autologin') - token.save - @token = token + @token = Token.get_token_from_user(user, 'autologin') - @user_url = url_for(my_account_url(user,:token => @token.value)) # 查询user参加的项目及课程 projects = user.projects courses = user.courses @@ -145,7 +162,7 @@ class Mailer < ActionMailer::Base @course_journal_messages,@user_journal_messages,@forums,@memos,@attachments,@bids].any? {|o| !o.empty? } - binding.pry if Rails.env.development? + mylogger.debug "Sent activity mail : #{user.mail} - #{has_content}" #有内容才发,没有不发 mail :to => user.mail,:subject => subject if has_content end @@ -255,10 +272,9 @@ class Mailer < ActionMailer::Base @author = issue.author @issue = issue user = User.find_by_mail(recipients) - token = Token.new(:user =>user , :action => 'autologin') - token.save - @token = token - @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id, :token => @token.value) + @user = user + @token = Token.get_token_from_user(user, 'autologin') + @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id, :token => @token.value) # edit @issue_author_url = url_for(user_activities_url(@author,:token => @token.value)) @@ -298,10 +314,8 @@ class Mailer < ActionMailer::Base @author = journal.user user = User.find_by_mail(recipients) - - token = Token.new(:user =>user , :action => 'autologin') - token.save - @token = token + @user = user + @token = Token.get_token_from_user(user, 'autologin') # edit @@ -822,12 +836,13 @@ class Mailer < ActionMailer::Base headers[:references] = @references_objects.collect {|o| "<#{self.class.message_id_for(o)}>"}.join(' ') end - super headers do |format| + set_language_if_valid @initial_language + m = super headers do |format| format.text format.html unless Setting.plain_text_mail? end - - set_language_if_valid @initial_language + mylogger.debug "Sent a mail from #{m.from} to [#{m.to},#{m.cc}, #{m.bcc if Setting.bcc_recipients?}] subject: #{m.subject}" + m end def initialize(*args) @@ -882,7 +897,11 @@ class Mailer < ActionMailer::Base end def mylogger - Rails.logger + if Setting.delayjob_enabled? + Delayed::Worker.logger + else + Rails.logger + end end def add_attachments(obj) diff --git a/app/models/principal.rb b/app/models/principal.rb index dfec5b911..0f0746f78 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -19,6 +19,7 @@ class Principal < ActiveRecord::Base self.table_name = "#{table_name_prefix}users#{table_name_suffix}" # Account statuses + # 0 全部;1 活动的; 2 已注册; 3 锁定 STATUS_ANONYMOUS = 0 STATUS_ACTIVE = 1 STATUS_REGISTERED = 2 diff --git a/app/models/project.rb b/app/models/project.rb index 07854822e..47878dbec 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -51,7 +51,7 @@ class Project < ActiveRecord::Base has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name" has_many :boards, :dependent => :destroy, :order => "position ASC" has_one :repository, :conditions => ["is_default = ?", true] - has_many :repositories, :dependent => :destroy + has_many :repositories, :dependent => :destroy, conditions: "hidden=false" has_many :changesets, :through => :repository #added by xianbo for delete biding_project has_many :biding_projects, :dependent => :destroy @@ -114,7 +114,7 @@ class Project < ActiveRecord::Base validates_presence_of :name, :identifier validates_uniqueness_of :identifier - validates_uniqueness_of :name + # validates_uniqueness_of :name validates_associated :wiki#, :repository # validates_length_of :description, :maximum => 255 validates_length_of :name, :maximum => 255 diff --git a/app/models/token.rb b/app/models/token.rb index 3131bce8d..e0accb59c 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -1,3 +1,4 @@ +#coding=utf-8 # Redmine - project management software # Copyright (C) 2006-2013 Jean-Philippe Lang # @@ -14,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - +# class Token < ActiveRecord::Base belongs_to :user validates_uniqueness_of :value @@ -27,6 +28,24 @@ class Token < ActiveRecord::Base self.value = Token.generate_token_value end + def self.get_or_create_permanent_login_token(user) + token = Token.get_token_from_user(user, 'autologin') + unless token + token = Token.create(:user => user, :action => 'autologin') + else + token.update_attribute(:created_on, Time.now) + end + token + end + + def self.get_token_from_user(user, action) + token = Token.where(:action => action, :user_id => user).first + unless token + token = Token.create(user: user, action: action) + end + token + end + # Return true if token has expired def expired? return Time.now > self.created_on + @@validity_time @@ -34,7 +53,7 @@ class Token < ActiveRecord::Base # Delete all expired tokens def self.destroy_expired - Token.delete_all ["action NOT IN (?) AND created_on < ?", ['feeds', 'api'], Time.now - @@validity_time] + Token.delete_all ["action NOT IN (?) AND created_on < ?", ['feeds', 'api', 'autologin'], Time.now - @@validity_time] end # Returns the active user who owns the key for the given action @@ -72,6 +91,10 @@ class Token < ActiveRecord::Base Redmine::Utils.random_hex(20) end + def self.delete_user_all_tokens(user) + Token.delete_all(user_id: user.id) + end + private # Removes obsolete tokens (same user and action) diff --git a/app/models/user_extensions.rb b/app/models/user_extensions.rb index 09c88e6df..d9a0f520a 100644 --- a/app/models/user_extensions.rb +++ b/app/models/user_extensions.rb @@ -1,86 +1,86 @@ -# encoding: utf-8 -=begin - identity字段含义 - 0 教师教授 - 1 学生 - 2 企业 - 3 开发者 -=end -class UserExtensions < ActiveRecord::Base - validate :school, presence: true - - belongs_to :user - belongs_to :school, :class_name => 'School', :foreign_key => :school_id - attr_accessible :user_id,:birthday,:brief_introduction,:gender,:location,:occupation,:work_experience,:zip_code,:identity, :technical_title,:student_id - TEACHER = 0 - STUDENT = 1 - ENTERPRISE = 2 - DEVELOPER = 3 - #this method was used to update the table user_extensions - def update_user_extensions(birthday=nil,brief_introduction=nil, - gender=nil,location=nil,occupation=nil,work_experience=nil,zip_code=nil) - self.birthday = birthday - self.brief_introduction = brief_introduction - self.gender = gender - self.location = location - self.occupation = occupation - self.work_experience = work_experience - self.zip_code = zip_code - self.save - end - - def get_brief_introduction - return self.brief_introduction - end - - -# added by meng - def show_identity - if User.current.language == 'zh'||User.current.language == '' - case self.identity - when 0 - user_identity = l(:label_account_identity_teacher) - when 1 - user_identity = l(:label_account_identity_student) - when 2 - user_identity = l(:label_account_identity_enterprise) - when 3 - user_identity = l(:label_account_identity_developer) - else - user_identity = '' - end - else - case self.identity - when 0 - user_identity = l(:label_account_identity_teacher) - when 1 - user_identity = l(:label_account_identity_student) - when 2 - user_identity = l(:label_account_identity_enterprise) - when 3 - user_identity = l(:label_account_identity_developer) - else - user_identity = '' - end - end - return user_identity - end -# end - - - def self.introduction(user, message) - unless user.user_extensions.nil? - info = user.user_extensions - info.brief_introduction = message - info.save - else - info = UserExtensions.new - info.user_id = user.id - info.brief_introduction = message - info.save - end - end - - - -end +# encoding: utf-8 +=begin + identity字段含义 + 0 教师教授 + 1 学生 + 2 企业 + 3 开发者 +=end +class UserExtensions < ActiveRecord::Base + validate :school, presence: true + + belongs_to :user + belongs_to :school, :class_name => 'School', :foreign_key => :school_id + attr_accessible :user_id,:birthday,:brief_introduction,:gender,:location,:occupation,:work_experience,:zip_code,:identity, :technical_title,:student_id + TEACHER = 0 + STUDENT = 1 + ENTERPRISE = 2 + DEVELOPER = 3 + #this method was used to update the table user_extensions + def update_user_extensions(birthday=nil,brief_introduction=nil, + gender=nil,location=nil,occupation=nil,work_experience=nil,zip_code=nil) + self.birthday = birthday + self.brief_introduction = brief_introduction + self.gender = gender + self.location = location + self.occupation = occupation + self.work_experience = work_experience + self.zip_code = zip_code + self.save + end + + def get_brief_introduction + return self.brief_introduction + end + + +# added by meng + def show_identity + if User.current.language == 'zh'||User.current.language == '' + case self.identity + when 0 + user_identity = l(:label_account_identity_teacher) + when 1 + user_identity = l(:label_account_identity_student) + when 2 + user_identity = l(:label_account_identity_enterprise) + when 3 + user_identity = l(:label_account_identity_developer) + else + user_identity = '' + end + else + case self.identity + when 0 + user_identity = l(:label_account_identity_teacher) + when 1 + user_identity = l(:label_account_identity_student) + when 2 + user_identity = l(:label_account_identity_enterprise) + when 3 + user_identity = l(:label_account_identity_developer) + else + user_identity = '' + end + end + return user_identity + end +# end + + + def self.introduction(user, message) + unless user.user_extensions.nil? + info = user.user_extensions + info.brief_introduction = message + info.save + else + info = UserExtensions.new + info.user_id = user.id + info.brief_introduction = message + info.save + end + end + + + +end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index e91883bee..26d8df16f 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -86,7 +86,7 @@ class CoursesService gender = m.user.user_extensions.gender.nil? ? 0 : m.user.user_extensions.gender work_unit = get_user_work_unit m.user location = get_user_location m.user - users << {:id => m.user.id, :img_url => img_url, :nickname => m.user.login, :gender => gender, :work_unit => work_unit, :mail => m.user.mail, :location => location, :brief_introduction => m.user.user_extensions.brief_introduction} + users << {:id => m.user.id, :img_url => img_url, :nickname => m.user.login, :gender => gender, :work_unit => work_unit, :mail => m.user.mail, :location => location, :brief_introduction => m.user.user_extensions.brief_introduction,:realname=>m.user.realname} end users end @@ -169,7 +169,7 @@ class CoursesService unless (course.is_public == 1 || current_user.member_of_course?(course) || current_user.admin?) raise '403' end - {:course => course,:work_unit => work_unit, :img_url => url_to_avatar(course),:current_user_is_member => current_user.member_of_course?(course),:current_user_is_teacher => is_course_teacher(current_user,course)} + {:course => course,:work_unit => work_unit, :img_url => url_to_avatar(course),:current_user_is_member => current_user.member_of_course?(course),:current_user_is_teacher => is_course_teacher(current_user,course),:course_student_num => course ? course.student.count.to_s : 0} end #创建课程 @@ -428,7 +428,109 @@ class CoursesService result end + # 课程课件 + def course_attachments params + result = [] + @course = Course.find(params[:course_id]) + @attachments = @course.attachments.order("created_on desc") + if !params[:name].nil? && params[:name] != "" + @attachments.each do |atta| + result << {:filename => atta.filename, + :description => atta.description, + :downloads => atta.downloads, + :quotes => atta.quotes.nil? ? 0 :atta.quotes } if atta.filename.include?(params[:name]) + + end + else + @attachments.each do |atta| + result << {:filename => atta.filename, + :description => atta.description, + :downloads => atta.downloads, + :quotes => atta.quotes.nil? ? 0 :atta.quotes } + + end + end + result + end + + # 课程学生列表 + def course_members params + @all_members = searchmember_by_name(student_homework_score(0,params[:course_id], 10,"desc"),params[:name]) + end + + def show_member_score params + @member_score = Member.find(params[:member_id]) if params[:member_id] + atta = @member_score.student_homework_score[0] + result = [] + atta.each do |t| + if !params[:homeworkName].nil? && params[:homeworkName] != "" + result << {:name=>t[:name],:score=>t[:score]} if t[:name].include?(params[:homeworkName]) + else + result << {:name=>t[:name],:score=>t[:score]} + end + + end + result + end + + # 设置人员为课程教辅 + def set_as_assitant_teacher params + members = [] + #找到课程 + course = Course.find(params[:course_id]) + #新建课程人员 + + member = Member.new(:role_ids =>[7], :user_id => params[:user_id],:course_id=>params[:course_id]) + joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,course.id) + joined.each do |join| + join.delete + end + member.course_group_id = 0 + members << member + course.members << members + #将课程人员设置为教辅 + end + + def del_assitant_teacher params + member = Member.where("user_id = ? and course_id = ?",params[:user_id],params[:course_id]) + member.each do |m| + m.destroy + end + user_admin = CourseInfos.where("user_id = ? and course_id = ?",params[:user_id], params[:course_id]) + if user_admin.size > 0 + user_admin.each do |user| + user.destroy + end + end + joined = StudentsForCourse.where('student_id = ? and course_id = ?', params[:user_id],params[:course_id]) + joined.each do |join| + join.delete + end + end + + def create_course_notice params ,current_user + n = News.new(:course_id =>params[:course_id], :author_id => current_user.id,:title =>params[:title],:description=> params[:desc]) + n.save + {:id => n.id,:title => n.title,:author_name => n.author.name,:author_id => n.author.id, :description => n.description,:created_on => format_time(n.created_on),:comments_count => n.comments_count} + end + private + def searchmember_by_name members, name + #searchPeopleByRoles(project, StudentRoles) + mems = [] + if name != "" + name = name.to_s.downcase + members.each do |m| + username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase + if(m.user[:login].to_s.downcase.include?(name) || m.user.user_extensions[:student_id].to_s.downcase.include?(name) || username.include?(name)) + mems << m + end + end + else + mems = members + end + mems + end def show_homework_info course,bid,current_user,is_course_teacher author_real_name = bid.author.lastname + bid.author.firstname many_times = course.homeworks.index(bid) + 1 @@ -465,5 +567,56 @@ class CoursesService end + def student_homework_score(groupid,course_id, nums, score_sort_by) + #teachers = find_course_teachers(@course) + #start_from = start_from * nums + sql_select = "" + if groupid == 0 + if nums == 0 + sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches + WHERE members.course_id = #{course_id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{course_id}) AND members.user_id = homework_attaches.user_id + AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id}) GROUP BY members.user_id + UNION all + SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{course_id} AND + students_for_courses.course_id = #{course_id} and members.user_id = students_for_courses.student_id AND + members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id} ) + ) + GROUP BY members.user_id ORDER BY score #{score_sort_by}" + else + sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches + WHERE members.course_id = #{course_id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{course_id}) AND members.user_id = homework_attaches.user_id + AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id}) GROUP BY members.user_id + UNION all + SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{course_id} AND + students_for_courses.course_id = #{course_id} and members.user_id = students_for_courses.student_id AND + members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id} ) + ) + GROUP BY members.user_id ORDER BY score #{score_sort_by} " #limit #{start_from}, #{nums}" + + end + else + sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches + WHERE members.course_id = #{course_id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{course_id}) AND members.user_id = homework_attaches.user_id + and members.course_group_id = #{groupid} AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id}) + GROUP BY members.user_id + UNION all + SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{course_id} + and members.course_group_id = #{groupid} AND + students_for_courses.course_id = #{course_id} and members.user_id = students_for_courses.student_id AND + members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id} ) + ) + GROUP BY members.user_id ORDER BY score #{score_sort_by}" + end + sql = ActiveRecord::Base.connection() + homework_scores = Member.find_by_sql(sql_select) + sql.close() + + homework_scores + end + + + + + end \ No newline at end of file diff --git a/app/services/homework_service.rb b/app/services/homework_service.rb index d22c62a5a..2e7f59888 100644 --- a/app/services/homework_service.rb +++ b/app/services/homework_service.rb @@ -231,6 +231,29 @@ class HomeworkService anonymous_repy(jour) end end + + # 发布作业 + def create_home_work params,current_user + @bid = Bid.new + @bid.name = params[:work_name] + @bid.description = params[:work_desc] + # @bid.is_evaluation = params[:is_blind_appr] + @bid.evaluation_num = params[:blind_appr_num] + @bid.open_anonymous_evaluation = params[:is_blind_appr] + @bid.reward_type = 3 + @bid.deadline = params[:work_deadline] + @bid.budget = 0 + @bid.author_id = current_user.id + @bid.commit = 0 + @bid.homework_type = 1 + # @bid. + if @bid.save + HomeworkForCourse.create(:course_id => params[:course_id], :bid_id => @bid.id) + unless @bid.watched_by?(current_user) + @bid.add_watcher(current_user) + end + end + end # 学生匿评列表 def student_jour_list params diff --git a/app/services/users_service.rb b/app/services/users_service.rb index c1f716fd1..a8aacb095 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -4,6 +4,7 @@ class UsersService include AvatarHelper include CoursesHelper include ApiHelper + include WordsHelper #将用户注册的功能函数写这里 #参数约定 #成功返回注册后的User实例,失败直接抛异常 @@ -44,12 +45,14 @@ class UsersService #location = get_user_location @user #{:id => @user.id, :img_url => img_url, :nickname => @user.login, :gender => gender, :work_unit => work_unit, :mail => @user.mail, :location => location, :brief_introduction => @user.user_extensions.brief_introduction} end + + # 自动注册功能 FOR:邮件邀请 def register_auto(login,mail,password) @user = User.new @user.admin = false @user.register @user.login = login - @user.mail =mail + @user.mail = mail password_confirmation = password should_confirmation_password = true if !password.blank? && !password_confirmation.blank? && should_confirmation_password @@ -59,9 +62,7 @@ class UsersService else @user.password = "" end - @user = automatically_register(@user) - if @user.id != nil ue = @user.user_extensions ||= UserExtensions.new ue.user_id = @user.id @@ -69,6 +70,7 @@ class UsersService end @user end + #显示用户 #id用户id def show_user(params) @@ -153,6 +155,34 @@ class UsersService @user end + # 获取某个用户的所有留言信息 + def get_all_messages params + user = User.find(params[:user_id]) + jours = user.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') + 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 + jours + end + + # 回复用户 + def reply_user_messages params,current_user + user = User.find(params[:user_id]) + parent_id = params[:parent_id] + author_id = current_user.id + reply_user_id = params[:ref_user_id] + reply_id = params[:ref_message_id] + content = params[:content] + options = {:user_id => author_id, + :status => true, + :m_parent_id => parent_id, + :m_reply_id => reply_id, + :reply_id => reply_user_id, + :notes => content, + :is_readed => false} + user.add_jour(nil, nil,nil,options) + end @@ -204,10 +234,23 @@ class UsersService "show_changesets" => true } scope = User.logged.status(status) - watcher = User.watched_by(params[:user_id]) - watcher.push(params[:user_id]) - search_by = params[:search_by] ? params[:search_by] : "0" - scope = scope.where("id not in (?)",watcher).like(params[:name],search_by) if params[:name].present? + if params[:is_search_assitant].nil? + #modify by yutao 2015/5/18 没有params[:user_id]参数时去掉"id not in (?)"条件(bug:#2270) start + #say by yutao: params[:user_id]这个是指谁发起的搜索么? 如果是 这个值貌似应该从session获取 怪怪的赶脚-_-! + search_by = params[:search_by] ? params[:search_by] : "0" + if params[:name].present? + if !params[:user_id].nil? + watcher = User.watched_by(params[:user_id]) + watcher.push(params[:user_id]) + scope = scope.where("id not in (?)",watcher) + end + scope = scope.like(params[:name],search_by) + end + #modify by yutao 2015/5/18 没有params[:user_id]参数时去掉"id not in (?)"条件 end + else + teachers = searchTeacherAndAssistant(Course.find(params[:course_id])) + scope = scope.where("id not in (?)",teachers.map{|t| t.user_id}).like(params[:name],search_by) if params[:name].present? + end scope end diff --git a/app/tasks/destroy_repository_task.rb b/app/tasks/destroy_repository_task.rb new file mode 100644 index 000000000..3e434422e --- /dev/null +++ b/app/tasks/destroy_repository_task.rb @@ -0,0 +1,25 @@ +#coding=utf-8 +# + +class DestroyRepositoryTask + def destroy(user_id, rep_id) + user = User.find(user_id) + repository = Repository.find(rep_id) + + Rails.logger.info "start delete repository #{user} #{repository}" + @root_path=RepositoriesHelper::ROOT_PATH + @repo_name=user.login.to_s+"_"+repository.identifier.to_s + @repository_name=user.login.to_s+"/"+repository.identifier.to_s+".git" + @middle=user.login.to_s+"_"+repository.identifier.to_s+"-write:" + repository.destroy + if(repository.type=="Repository::Git") + Rails.logger.info "destory the repository value"+"root path"+@root_path+"repo_name"+@repo_name+ + "repository_name"+@repository_name+"user group"+@middle + system "sed -i /"+@repo_name+"/{d} "+@root_path+"htdocs/user.passwd" + system "sed -i /"+@middle+"/{d} "+@root_path+"htdocs/group.passwd" + system "rm -r "+@root_path+"htdocs/"+@repository_name + end + end + + handle_asynchronously :destroy,:queue => 'repository' +end diff --git a/app/views/account/login.html.erb b/app/views/account/login.html.erb index 4175282b3..bb289eb03 100644 --- a/app/views/account/login.html.erb +++ b/app/views/account/login.html.erb @@ -68,7 +68,7 @@ <% if Setting.autologin? %> <% end %> diff --git a/app/views/attachments/_form.html.erb b/app/views/attachments/_form.html.erb index 7e86b098b..845e2b6a0 100644 --- a/app/views/attachments/_form.html.erb +++ b/app/views/attachments/_form.html.erb @@ -17,8 +17,9 @@ <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> +
    <% end %> - <% container.saved_attachments.each_with_index do |attachment, i| %> + <% container.saved_attachments.each_with_index do |attachment, i| %> <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly => 'readonly') %> <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 254, :placeholder => l(:label_optional_description), :class => 'description', :style => "display: inline-block;") %> @@ -34,18 +35,12 @@ <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> +
    <% end %> <% end %> - <% project = project %> +
    <%#= button_tag "浏览", :type=>"button", :onclick=>"CompatibleSend();" %> diff --git a/app/views/attachments/_form_course.html.erb b/app/views/attachments/_form_course.html.erb index 1e81aaf65..b0ab39b5a 100644 --- a/app/views/attachments/_form_course.html.erb +++ b/app/views/attachments/_form_course.html.erb @@ -1,27 +1,31 @@ - + <% if defined?(container) && container && container.saved_attachments %> <% if isReply %> <% container.saved_attachments.each_with_index do |attachment, i| %> - + + <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly=>'readonly')%> - <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") + - link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %> - <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %> + <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") %> <%= l(:field_is_public)%>: - <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false, :class => 'is_public')%> + <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false, :class => 'is_public_checkbox')%> + + <%= link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %> <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> <% end %> <% else %> <% container.attachments.each_with_index do |attachment, i| %> - + + <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly=>'readonly')%> - <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") + - link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %> - <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %> - <%= l(:field_is_public)%>: - <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false, :class => 'is_public')%> - <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> + <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") %> + <%= l(:field_is_public)%>: + <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false, :class => 'is_public_checkbox')%> + + <%= link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %> + <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %> + + <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> <% end %> <% end %> @@ -38,12 +42,12 @@ <%#= button_tag "浏览", :type=>"button", :onclick=>"CompatibleSend();" %> -<%= button_tag "#{l(:button_browse)}", :type=>"button", :onclick=>"_file.click()",:class =>"sub_btn",:style => ie8? ? 'display:none' : '' %> +<%= button_tag "#{l(:button_browse)}", :type=>"button", :onclick=>"file#{container.id}.click()",:class =>"sub_btn",:style => ie8? ? 'display:none' : '' %> <%= file_field_tag 'attachments[dummy][file]', - :id => '_file', + :id => "file#{container.id}", :class => 'file_selector', :multiple => true, - :onchange => 'addInputFiles(this);', + :onchange => "addInputFiles_board(this, '#{container.id}');", :style => 'display:none', :data => { :max_file_size => Setting.attachment_max_size.to_i.kilobytes, @@ -56,7 +60,9 @@ :file_count => l(:label_file_count), :delete_all_files => l(:text_are_you_sure_all) } %> -<%= l(:label_no_file_uploaded)%> + <% if container.nil? %> + <%= l(:label_no_file_uploaded)%> + <% end %> (<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>) diff --git a/app/views/attachments/_form_project.html.erb b/app/views/attachments/_form_project.html.erb index 9778d3242..d1cdf8cc9 100644 --- a/app/views/attachments/_form_project.html.erb +++ b/app/views/attachments/_form_project.html.erb @@ -1,26 +1,32 @@ - +<% if defined?(container) %> + <% if defined?(container) && container && container.saved_attachments %> <% if isReply %> <% container.saved_attachments.each_with_index do |attachment, i| %> + <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly=>'readonly')%> - <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") + - link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %> - <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %> + <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") %> <%= l(:field_is_public)%>: - <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false, :class => 'is_public')%> - <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> + <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false, :class => 'is_public_checkbox')%> + + <%= link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %> + <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %> + <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> <% end %> <% else %> <% container.attachments.each_with_index do |attachment, i| %> + <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly=>'readonly')%> - <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") + - link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %> - <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %> - <%= l(:field_is_public)%>: - <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false, :class => 'is_public')%> + <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") %> + <%= l(:field_is_public)%>: + <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false, :class => 'is_public_checkbox')%> + + <%= link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), 'data-containerid'=>"#{container.id}",:method => 'delete', :remote => true, :class => 'remove-upload') %> + <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %> + <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> <% end %> @@ -35,15 +41,15 @@ // file.click(); // } - + <%#= button_tag "浏览", :type=>"button", :onclick=>"CompatibleSend();" %> - <%= button_tag "文件浏览", :type=>"button", :onclick=>"_file.click()", :class =>"sub_btn",:style => ie8? ? 'display:none' : '' %> + <%= button_tag "文件浏览", :type=>"button", :onclick=>"_file#{container.id}.click()", :class =>"sub_btn",:style => ie8? ? 'display:none' : '' %> <%= file_field_tag 'attachments[dummy][file]', - :id => '_file', + :id => "_file#{container.id}", :class => 'file_selector', :multiple => true, - :onchange => 'addInputFiles(this);', + :onchange => "addInputFiles_board(this, '#{container.id}');", :style => 'display:none', :data => { :max_file_size => Setting.attachment_max_size.to_i.kilobytes, @@ -54,12 +60,78 @@ :field_is_public => l(:field_is_public), :are_you_sure => l(:text_are_you_sure), :file_count => l(:label_file_count), - :delete_all_files => l(:text_are_you_sure_all) + :delete_all_files => l(:text_are_you_sure_all), + :containerid => "#{container.id}" } %> - <%= l(:label_no_file_uploaded)%> + <%= l(:label_no_file_uploaded)%> +(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>) + +<% else %> + +<% if defined?(container) && container && container.saved_attachments %> + <% if isReply %> + <% container.saved_attachments.each_with_index do |attachment, i| %> + + <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly=>'readonly')%> + <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") + + link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %> + <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %> + <%= l(:field_is_public)%>: + <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false, :class => 'is_public')%> + <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> + + <% end %> + <% else %> + <% container.attachments.each_with_index do |attachment, i| %> + + <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly=>'readonly')%> + <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") + + link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %> + <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %> + <%= l(:field_is_public)%>: + <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false, :class => 'is_public')%> + <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> + + <% end %> + <% end %> +<% end %> + + + +<%#= button_tag "浏览", :type=>"button", :onclick=>"CompatibleSend();" %> + + <%= button_tag "文件浏览", :type=>"button", :onclick=>"_file.click()", :class =>"sub_btn",:style => ie8? ? 'display:none' : '' %> + <%= file_field_tag 'attachments[dummy][file]', + :id => '_file', + :class => 'file_selector', + :multiple => true, + :onchange => 'addInputFiles(this);', + :style => 'display:none', + :data => { + :max_file_size => Setting.attachment_max_size.to_i.kilobytes, + :max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)), + :max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i, + :upload_path => uploads_path(:format => 'js'), + :description_placeholder => l(:label_optional_description), + :field_is_public => l(:field_is_public), + :are_you_sure => l(:text_are_you_sure), + :file_count => l(:label_file_count), + :delete_all_files => l(:text_are_you_sure_all) + } %> + <% if defined?(container) %> + <%= l(:label_no_file_uploaded)%> + <% end %> (<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>) +<% end %> <% content_for :header_tags do %> <%= javascript_include_tag 'attachments' %> <% end %> diff --git a/app/views/attachments/_homework_jour_link.html.erb b/app/views/attachments/_homework_jour_link.html.erb new file mode 100644 index 000000000..8721d41ac --- /dev/null +++ b/app/views/attachments/_homework_jour_link.html.erb @@ -0,0 +1,18 @@ +
    + <% for attachment in attachments %> +
    + <%= link_to_short_attachment attachment, :class => 'link_file', :download => true, :length => 100 -%> +
    + <% if attachment.is_text? %> +
    + <%= link_to image_tag('magnifier.png'), + {:controller => 'attachments', + :action => 'show', + :id => attachment, + :filename => attachment.filename}, + :target => "_blank"%> +
    + <% end %> +
    + <% end %> +
    diff --git a/app/views/attachments/_project_file_links.html.erb b/app/views/attachments/_project_file_links.html.erb index 9a65556d8..fe0e9ab97 100644 --- a/app/views/attachments/_project_file_links.html.erb +++ b/app/views/attachments/_project_file_links.html.erb @@ -1,7 +1,35 @@ + +
    <% is_float ||= false %> <% for attachment in attachments %> -

    +

    +

    <%if is_float%>

    <% end%> @@ -23,9 +51,10 @@ :id => attachment, :filename => attachment.filename%> <% end %> - - <%= h(truncate(" - #{attachment.description}", length: options[:length] ? options[:length]:15, omission: '...')) unless attachment.description.blank? %> - +
    +
    + <%= h(" - #{attachment.description}") unless attachment.description.blank? %> +
    ( <%= number_to_human_size attachment.filesize %>) @@ -64,7 +93,7 @@ <% images = attachments.select(&:thumbnailable?) %> <% if images.any? %> <% images.each do |attachment| %> -
    <%= thumbnail_issue_tag(attachment) %>
    +
    <%= thumbnail_issue_tag(attachment) %>
    <% end %> <% end %> <% end %> diff --git a/app/views/attachments/add_exist_file_to_courses.js.erb b/app/views/attachments/add_exist_file_to_courses.js.erb index eec1e255a..c84a89184 100644 --- a/app/views/attachments/add_exist_file_to_courses.js.erb +++ b/app/views/attachments/add_exist_file_to_courses.js.erb @@ -4,4 +4,5 @@ $("#error_show").html("<%= @message.html_safe %>"); <% else %> closeModal(); + searchone4reload('<%=params[:file_id]%>'); <% end %> diff --git a/app/views/attachments/destroy.js.erb b/app/views/attachments/destroy.js.erb index 4893d22fe..0b6cee0df 100644 --- a/app/views/attachments/destroy.js.erb +++ b/app/views/attachments/destroy.js.erb @@ -1,8 +1,26 @@ -$('#attachments_<%= j params[:attachment_id] %>').remove(); -var count=$('#attachments_fields>span').length; -if(count<=0){ - $("#upload_file_count").text(<%= l(:label_no_file_uploaded)%>); - $(".remove_all").remove(); -}else{ - $("#upload_file_count").html("已上传"+""+count+""+"个文件"); -} \ No newline at end of file +var attachment_html_obj = $('#attachments_<%= j params[:attachment_id] %>'); +//modify by yutao 2015-5-14 当1个页面存在多个上传控件时此块代码存在bug 故改之 start +var containerid=$('.remove-upload',attachment_html_obj).data('containerid'); +if(containerid==undefined){ + $('#attachments_<%= j params[:attachment_id] %>').remove(); + var count=$('#attachments_fields>span').length; + if(count<=0){ + $("#upload_file_count").text('<%= l(:label_no_file_uploaded)%>'); + $(".remove_all").remove(); + }else{ + $("#upload_file_count").html(""+count+""+"个文件"+"已上传"); + } +}else{ + $('#attachments_<%= j params[:attachment_id] %>').remove(); + var count=$('#attachments_fields'+containerid+'>span').length; + if(count<=0){ + $('#upload_file_count'+containerid).text('<%= l(:label_no_file_uploaded)%>'); + var remove_all_html_obj = $(".remove_all").filter(function(index){ + return $(this).data('containerid')==containerid; + }); + remove_all_html_obj.remove(); + }else{ + $('#upload_file_count'+containerid).html(""+count+""+"个文件"+"已上传"); + } +} +//modify by yutao 2015-5-14 当1个页面存在多个上传控件时此块代码存在bug 故改之 end \ No newline at end of file diff --git a/app/views/attachments/upload.js.erb b/app/views/attachments/upload.js.erb index 24256ccab..c3e7fc3ff 100644 --- a/app/views/attachments/upload.js.erb +++ b/app/views/attachments/upload.js.erb @@ -3,14 +3,15 @@ var fileSpan = $('#attachments_<%= j params[:attachment_id] %>'); fileSpan.hide(); alert("<%= escape_javascript @attachment.errors.full_messages.join(', ') %>"); <% else %> -$('', { type: 'hidden', name: 'attachments[<%= j params[:attachment_id] %>][token]' } ).val('<%= j @attachment.token %>').appendTo(fileSpan); fileSpan.find('a.remove-upload') - .attr({ - "data-remote": true, - "data-method": 'delete', - "href": '<%= j attachment_path(@attachment, :attachment_id => params[:attachment_id], :format => 'js') %>' - }) - .off('click'); + .attr({ + "data-remote": true, + "data-method": 'delete', + "href": '<%= j attachment_path(@attachment, :attachment_id => params[:attachment_id], :format => 'js') %>' + }) + .off('click'); +$('', { type: 'hidden', name: 'attachments[<%= j params[:attachment_id] %>][token]' } ).val('<%= j @attachment.token %>').appendTo(fileSpan); + //var divattach = fileSpan.find('div.div_attachments'); //divattach.html('<%= j(render :partial => 'tags/tagEx', :locals => {:obj => @attachment, :object_flag => "6"})%>'); <% end %> diff --git a/app/views/avatar/_avatar_form.html.erb b/app/views/avatar/_avatar_form.html.erb index fef9f7bdb..632ea5d4d 100644 --- a/app/views/avatar/_avatar_form.html.erb +++ b/app/views/avatar/_avatar_form.html.erb @@ -43,11 +43,10 @@
    -<%= link_to l(:button_delete_file),{:controller => :avatar,:action => :delete_image,:remote=>true,:source_type=> source.class,:source_id=>source.id},:confirm => l(:text_are_you_sure), :method => :post, :class => "btn_addPic", :style => "text-decoration:none;" %> +<%#= link_to l(:button_delete_file),{:controller => :avatar,:action => :delete_image,:remote=>true,:source_type=> source.class,:source_id=>source.id},:confirm => l(:text_are_you_sure), :method => :post, :class => "btn_addPic", :style => "text-decoration:none;" %> <%= l(:button_upload_photo) %> - (个人头像建议90*90大小,课程和项目logo建议60*60大小,或者等比图像) <%= file_field_tag 'avatar[image]', @@ -69,8 +68,12 @@ :source_id => source.id.to_s } %> +
    <% content_for :header_tags do %> <%= javascript_include_tag 'avatars' %> <% end %> - \ No newline at end of file + + + + diff --git a/app/views/avatar/_avatar_preview.html.erb b/app/views/avatar/_avatar_preview.html.erb new file mode 100644 index 000000000..f7a014c64 --- /dev/null +++ b/app/views/avatar/_avatar_preview.html.erb @@ -0,0 +1,66 @@ + + +
    + +
    +
    + diff --git a/app/views/avatar/_new_avatar_form.html.erb b/app/views/avatar/_new_avatar_form.html.erb index 8b81ebf66..64abfbc30 100644 --- a/app/views/avatar/_new_avatar_form.html.erb +++ b/app/views/avatar/_new_avatar_form.html.erb @@ -3,16 +3,14 @@ <%#= link_to l(:button_delete_file),{:controller => :avatar,:action => :delete_image,:remote=>true,:source_type=> source.class,:source_id=>source.id},:confirm => l(:text_are_you_sure), :method => :post, :class => "upbtn fl" %> <%= l(:button_upload_photo) %> -(个人头像建议90*90大小,课程和项目logo建议60*60大小,或者等比图像) <%= file_field_tag 'avatar[image]', :id => nil, - :class => 'upload_file ', + :class => 'upload_file', :size => "1", - :multiple => false, - :onchange => 'addInputAvatar(this);', + :multiple => true, :data => { - :max_file_size => Setting.attachment_max_size.to_i.kilobytes, - :max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)), + :max_file_size => Setting.upload_avatar_max_size, + :max_file_size_message => l(:error_upload_avatar_to_large, :max_size => number_to_human_size(Setting.upload_avatar_max_size.to_i)), :max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i, :file_type => Redmine::Configuration['pic_types'].to_s, :type_support_message => l(:error_pic_type), @@ -23,6 +21,6 @@ } %> <% content_for :header_tags do %> - <%= javascript_include_tag 'avatars' %> + <%= javascript_include_tag 'jq-upload/jquery.ui.widget', 'jq-upload/jquery.iframe-transport', 'jq-upload/jquery.fileupload', 'jq-upload/upload' %> <% end %> -
    \ No newline at end of file +
    diff --git a/app/views/avatar/upload.js.erb b/app/views/avatar/upload.js.erb index a7a341f10..1fa90c5a3 100644 --- a/app/views/avatar/upload.js.erb +++ b/app/views/avatar/upload.js.erb @@ -1,4 +1,4 @@ -var imgSpan = $('#avatar_image'); +var imgSpan = jQuery('#avatar_image'); -imgSpan.attr({"src":'<%= @urlfile.to_s << "?" << Time.now.to_s%>'}); +imgSpan.attr({"src":'<%= "#{@urlfile.to_s}?#{Time.now.to_i}" %>'}); diff --git a/app/views/bids/_alert_anonyoms.html.erb b/app/views/bids/_alert_anonyoms.html.erb index 2f1c443f4..4da6e0a10 100644 --- a/app/views/bids/_alert_anonyoms.html.erb +++ b/app/views/bids/_alert_anonyoms.html.erb @@ -66,10 +66,10 @@

    <% end %> diff --git a/app/views/bids/_bid_homework_show.html.erb b/app/views/bids/_bid_homework_show.html.erb index 2f2dbcd07..1ecf8be90 100644 --- a/app/views/bids/_bid_homework_show.html.erb +++ b/app/views/bids/_bid_homework_show.html.erb @@ -1,201 +1,201 @@ - - - - -<% if bids.blank? %> -<%#= l(:label_uncommit_homework) %> -暂无作业! -<% else %> -<% bids.each do |bid|%> - - - - - -
    - <%= link_to(image_tag(url_to_avatar(bid.author), :class => 'avatar'), user_path(bid.author), :class => "avatar") %> - - - - - - - - - - - - - - - - - - -
    - - <%= link_to(bid.author.lastname+bid.author.firstname, user_path(bid.author)) %> - - - <%= l(:label_user_create_project_homework) %> - - - <%= link_to(bid.name, course_for_bid_path(bid), :class => 'bid_path') %> - - - - <% if User.current.logged? && is_cur_course_student(@course) %> - <% cur_user_homework = cur_user_homework_for_bid(bid) %> - - <% if bid.open_anonymous_evaluation == 1 %> - <% case bid.comment_status %> - <% when 0 %> - 未开启匿评 - <% when 1 %> -   匿评中..   - <% when 2 %> -   匿评结束   - <% end %> - <% end%> - - <% if cur_user_homework && cur_user_homework.empty? %> - - <%= link_to l(:label_commit_homework),new_exercise_book_path(bid) %> - - <% else %> - - 已 提 交 - - <% end %> - <% end %> - <% if (User.current.admin?||User.current.allowed_to?(:as_teacher,@course)) %> - <% if bid.open_anonymous_evaluation == 1 && bid.homeworks.count >= 2%> - - <% case bid.comment_status %> - <% when 0 %> - <%= link_to '启动匿评', alert_anonymous_comment_bid_path(bid), id: "#{bid.id}_start_anonymous_comment", remote: true, disable_with: '加载中...' %> - <% when 1 %> - <%= link_to '关闭匿评', alert_anonymous_comment_bid_path(bid), id: "#{bid.id}_stop_anonymous_comment", remote: true %> - <% when 2 %> - 匿评结束 - <% end %> - - <%end%> - - <%= link_to( - l(:button_edit), - {:action => 'edit', :controller=>'bids', :course_id =>@course.id, :bid_id => bid.id} - ) %> - - <%#= link_to( - l(:button_delete), - {:action => 'homework_destroy', :controller=>'bids', :course_id => bid.id}, - :method => :post, - :data => {:confirm => l(:text_are_you_sure)}, - :class => 'icon icon-del' - ) %> - <% end %> - -
    - - <% bidding_project = bid.biding_projects.all - temp = [] - bidding_project.each do |pro| - if pro.project && pro.project.project_status - temp << pro - end - temp - end - %> - <% if bid.homework_type == 1%> - <%= l(:label_x_homework_project, :count => bid.homeworks.count) %> - ( - - <%= link_to bid.homeworks.count, course_for_bid_path(bid.id) %> - ) - <% else %> - <%= l(:label_x_homework_project, :count => temp.count) %> - ( - - <%= link_to temp.count, course_for_bid_path(bid.id) %> - ) - <% end %> - -
    - <% if bid.reward_type.nil? or bid.reward_type == 1 %> - - <%= l(:label_bids_reward_method) %> - - <%= l(:label_call_bonus) %> -   - <%= l(:label_RMB_sign) %> - <%= bid.budget%> - - - <% elsif bid.reward_type == 2 %> - - <%= l(:label_bids_reward_method) %> - - <%= bid.budget%> - - - <% end %> -
    - - <%=h sanitize(bid.description.html_safe) %> - -
    - - <%= l(:label_end_time) %> - :  - <%= bid.deadline %> - - - <% if betweentime(bid.deadline) < 0 %> - - <%= l(:label_commit_limit)%> - - <% else %> - - - - <% end %> - -
    -<% end %> -<% end %> -