diff --git a/1234567 b/1234567 deleted file mode 100644 index 08de77ab4..000000000 --- a/1234567 +++ /dev/null @@ -1 +0,0 @@ -{"access_token":"bFlabz0uBcoIBfWL7nBJkgpl26aOWDy-dyCOvH_MjUo_hMOOKG83WV1cCL1MG6H-AE-6eMI0iyLoOoAMv9Y3pFFsLYD-GAGr3UH9fT8OqeHMDlFhXyRTvHv9l2QPHGpcARUcCGANEH","expires_in":7200,"got_token_at":1462934760} \ No newline at end of file diff --git a/Gemfile.lock~ b/Gemfile.lock~ new file mode 100644 index 000000000..7d6563465 --- /dev/null +++ b/Gemfile.lock~ @@ -0,0 +1,386 @@ +GIT + remote: http://github.com/guange2015/wechat.git + revision: a18c3d6603cb1aa7bd1fe887b17f67426be01f35 + specs: + wechat (0.7.1) + activerecord (>= 3.2, < 5.1.x) + http (~> 1.0, >= 1.0.1) + nokogiri (>= 1.6.0) + thor + +PATH + remote: lib/gitlab-cli + specs: + gitlab (3.2.0) + httparty + terminal-table + +PATH + remote: lib/grack + specs: + grack (2.0.2) + rack (~> 1.4.5) + +PATH + remote: lib/rails_kindeditor + specs: + rails_kindeditor (0.4.5) + carrierwave + mini_magick + +GEM + remote: https://ruby.taobao.org/ + specs: + actionmailer (3.2.22.2) + actionpack (= 3.2.22.2) + mail (~> 2.5.4) + actionpack (3.2.22.2) + activemodel (= 3.2.22.2) + activesupport (= 3.2.22.2) + builder (~> 3.0.0) + erubis (~> 2.7.0) + journey (~> 1.0.4) + rack (~> 1.4.5) + rack-cache (~> 1.2) + rack-test (~> 0.6.1) + sprockets (~> 2.2.1) + activemodel (3.2.22.2) + activesupport (= 3.2.22.2) + builder (~> 3.0.0) + activerecord (3.2.22.2) + activemodel (= 3.2.22.2) + activesupport (= 3.2.22.2) + arel (~> 3.0.2) + tzinfo (~> 0.3.29) + activeresource (3.2.22.2) + activemodel (= 3.2.22.2) + activesupport (= 3.2.22.2) + activesupport (3.2.22.2) + i18n (~> 0.6, >= 0.6.4) + multi_json (~> 1.0) + acts-as-taggable-on (2.4.1) + rails (>= 3, < 5) + addressable (2.4.0) + ansi (1.5.0) + arel (3.0.3) + axiom-types (0.1.1) + descendants_tracker (~> 0.0.4) + ice_nine (~> 0.11.0) + thread_safe (~> 0.3, >= 0.3.1) + better_errors (1.1.0) + coderay (>= 1.0.0) + erubis (>= 2.6.6) + binding_of_caller (0.7.2) + debug_inspector (>= 0.0.1) + builder (3.0.0) + byebug (8.2.2) + carrierwave (0.10.0) + activemodel (>= 3.2.0) + activesupport (>= 3.2.0) + json (>= 1.7) + mime-types (>= 1.16) + chinese_pinyin (1.0.0) + climate_control (0.0.3) + activesupport (>= 3.0) + cocaine (0.5.8) + climate_control (>= 0.0.3, < 1.0) + coderay (1.1.1) + coercible (1.0.0) + descendants_tracker (~> 0.0.1) + coffee-rails (3.2.2) + coffee-script (>= 2.2.0) + railties (~> 3.2.0) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.10.0) + daemons (1.2.3) + debug_inspector (0.0.2) + delayed_job (4.1.1) + activesupport (>= 3.0, < 5.0) + delayed_job_active_record (4.1.0) + activerecord (>= 3.0, < 5) + delayed_job (>= 3.0, < 5) + descendants_tracker (0.0.4) + thread_safe (~> 0.3, >= 0.3.1) + diff-lcs (1.2.5) + domain_name (0.5.20160216) + unf (>= 0.0.5, < 1.0.0) + elasticsearch (1.0.15) + elasticsearch-api (= 1.0.15) + elasticsearch-transport (= 1.0.15) + elasticsearch-api (1.0.15) + multi_json + elasticsearch-model (0.1.8) + activesupport (> 3) + elasticsearch (> 0.4) + hashie + elasticsearch-rails (0.1.8) + elasticsearch-transport (1.0.15) + faraday + multi_json + equalizer (0.0.11) + erubis (2.7.0) + execjs (2.6.0) + factory_girl (4.5.0) + activesupport (>= 3.0.0) + factory_girl_rails (4.6.0) + factory_girl (~> 4.5.0) + railties (>= 3.0.0) + faraday (0.9.2) + multipart-post (>= 1.2, < 3) + fastercsv (1.5.5) + grape (0.9.0) + activesupport + builder + hashie (>= 2.1.0) + multi_json (>= 1.3.2) + multi_xml (>= 0.5.2) + rack (>= 1.3.0) + rack-accept + rack-mount + virtus (>= 1.0.0) + grape-entity (0.4.8) + activesupport + multi_json (>= 1.3.2) + grape-swagger (0.10.4) + grape (>= 0.8.0) + grape-entity (< 0.5.0) + hashie (3.4.3) + hike (1.2.3) + htmlentities (4.3.4) + http (1.0.2) + addressable (~> 2.3) + http-cookie (~> 1.0) + http-form_data (~> 1.0.1) + http_parser.rb (~> 0.6.0) + http-cookie (1.0.2) + domain_name (~> 0.5) + http-form_data (1.0.1) + http_parser.rb (0.6.0) + httparty (0.13.7) + json (~> 1.8) + multi_xml (>= 0.5.2) + i18n (0.6.11) + ice_nine (0.11.2) + iconv (1.0.4) + journey (1.0.4) + jquery-rails (2.0.3) + railties (>= 3.1.0, < 5.0) + thor (~> 0.14) + json (1.8.3) + kaminari (0.16.3) + actionpack (>= 3.0.0) + activesupport (>= 3.0.0) + libv8 (3.16.14.13) + mail (2.5.4) + mime-types (~> 1.16) + treetop (~> 1.4.8) + method_source (0.8.2) + mime-types (1.25.1) + mini_magick (4.4.0) + mini_portile2 (2.0.0) + multi_json (1.11.2) + multi_xml (0.5.5) + multipart-post (2.0.0) + mysql2 (0.3.18) + net-ldap (0.3.1) + netrc (0.11.0) + nokogiri (1.6.7.2) + mini_portile2 (~> 2.0.0.rc2) + paperclip (3.5.4) + activemodel (>= 3.0.0) + activesupport (>= 3.0.0) + cocaine (~> 0.5.3) + mime-types + polyglot (0.3.5) + pry (0.10.3) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + pry-byebug (3.3.0) + byebug (~> 8.0) + pry (~> 0.10) + pry-rails (0.3.4) + pry (>= 0.9.10) + pry-stack_explorer (0.4.9.2) + binding_of_caller (>= 0.7) + pry (>= 0.9.11) + rack (1.4.7) + rack-accept (0.4.5) + rack (>= 0.4) + rack-cache (1.6.1) + rack (>= 0.4) + rack-cors (0.4.0) + rack-mount (0.8.3) + rack (>= 1.0.0) + rack-openid (1.4.2) + rack (>= 1.1.0) + ruby-openid (>= 2.1.8) + rack-raw-upload (1.1.1) + multi_json + rack-ssl (1.3.4) + rack + rack-test (0.6.3) + rack (>= 1.0) + rails (3.2.22.2) + actionmailer (= 3.2.22.2) + actionpack (= 3.2.22.2) + activerecord (= 3.2.22.2) + activeresource (= 3.2.22.2) + activesupport (= 3.2.22.2) + bundler (~> 1.0) + railties (= 3.2.22.2) + railties (3.2.22.2) + actionpack (= 3.2.22.2) + activesupport (= 3.2.22.2) + rack-ssl (~> 1.3.2) + rake (>= 0.8.7) + rdoc (~> 3.4) + thor (>= 0.14.6, < 2.0) + rake (10.5.0) + rdoc (3.12.2) + json (~> 1.4) + redis (3.2.2) + redis-actionpack (3.2.4) + actionpack (~> 3.2.0) + redis-rack (~> 1.4.4) + redis-store (~> 1.1.4) + redis-activesupport (3.2.5) + activesupport (~> 3.2.0) + redis-store (~> 1.1.0) + redis-rack (1.4.4) + rack (~> 1.4.0) + redis-store (~> 1.1.4) + redis-rails (3.2.4) + redis-actionpack (~> 3.2.4) + redis-activesupport (~> 3.2.4) + redis-store (~> 1.1.4) + redis-store (1.1.7) + redis (>= 2.2) + ref (2.0.0) + rest-client (1.8.0) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 3.0) + netrc (~> 0.7) + rich (1.4.6) + jquery-rails + kaminari + mime-types + paperclip + rack-raw-upload + rails (>= 3.2.0) + sass-rails + rspec-core (3.4.3) + rspec-support (~> 3.4.0) + rspec-expectations (3.4.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.4.0) + rspec-mocks (3.4.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.4.0) + rspec-rails (3.4.2) + actionpack (>= 3.0, < 4.3) + activesupport (>= 3.0, < 4.3) + railties (>= 3.0, < 4.3) + rspec-core (~> 3.4.0) + rspec-expectations (~> 3.4.0) + rspec-mocks (~> 3.4.0) + rspec-support (~> 3.4.0) + rspec-support (3.4.1) + ruby-ole (1.2.12) + ruby-openid (2.1.8) + rubyzip (1.2.0) + sass (3.4.21) + sass-rails (3.2.6) + railties (~> 3.2.0) + sass (>= 3.1.10) + tilt (~> 1.3) + seems_rateable (1.0.13) + jquery-rails + rails + slop (3.6.0) + spreadsheet (1.1.1) + ruby-ole (>= 1.0) + sprockets (2.2.3) + hike (~> 1.2) + multi_json (~> 1.0) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + terminal-table (1.5.2) + therubyracer (0.12.2) + libv8 (~> 3.16.14.0) + ref + thor (0.19.1) + thread_safe (0.3.5) + tilt (1.4.1) + treetop (1.4.15) + polyglot + polyglot (>= 0.3.1) + tzinfo (0.3.46) + uglifier (2.7.2) + execjs (>= 0.3.0) + json (>= 1.8.0) + unf (0.1.4) + unf_ext + unf_ext (0.0.7.2) + virtus (1.0.5) + axiom-types (~> 0.1) + coercible (~> 1.0) + descendants_tracker (~> 0.0, >= 0.0.3) + equalizer (~> 0.0, >= 0.0.9) + +PLATFORMS + ruby + +DEPENDENCIES + acts-as-taggable-on (= 2.4.1) + ansi + better_errors (~> 1.1.0) + binding_of_caller + builder (= 3.0.0) + chinese_pinyin + coderay (~> 1.1.0) + coffee-rails (~> 3.2.1) + daemons + delayed_job_active_record + elasticsearch-model + elasticsearch-rails + factory_girl_rails + fastercsv (~> 1.5.0) + gitlab! + grack! + grape (~> 0.9.0) + grape-entity + grape-swagger + htmlentities + i18n (~> 0.6.0) + iconv + jquery-rails (~> 2.0.2) + kaminari + mysql2 (= 0.3.18) + net-ldap (~> 0.3.1) + paperclip (~> 3.5.4) + pry-byebug + pry-rails + pry-stack_explorer + rack-cors + rack-openid + rails (~> 3.2) + rails_kindeditor! + redis-rails + rest-client + rich (= 1.4.6) + rspec-rails (~> 3.0) + ruby-ole + ruby-openid (~> 2.1.4) + rubyzip + sass-rails (~> 3.2.3) + seems_rateable (~> 1.0.13) + spreadsheet + therubyracer + uglifier (>= 1.0.3) + wechat! + +BUNDLED WITH + 1.10.6 diff --git a/Gemfile~ b/Gemfile~ new file mode 100644 index 000000000..24869e72b --- /dev/null +++ b/Gemfile~ @@ -0,0 +1,112 @@ +source 'http://rubygems.org/' +### 这里执行bundle config mirror.https://rubygems.org https://gems.ruby-china.org 切换到ruby-china源 + +unless RUBY_PLATFORM =~ /w32/ + # unix-like only + gem 'iconv' +end + +gem 'certified' + +gem 'wechat',path: 'lib/wechat' +gem 'grack', path:'lib/grack' +gem 'gitlab', path: 'lib/gitlab-cli' +gem 'rest-client' +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 'rack-cors', :require => 'rack/cors' +gem 'seems_rateable', '~> 1.0.13' +gem 'rails', '~> 3.2' +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" +gem 'binding_of_caller' +gem 'chinese_pinyin' +# gem 'sunspot_rails', '~> 1.3.3' +# gem 'sunspot_solr' +# gem 'sunspot' +# gem 'progress_bar' +gem 'ansi' + +gem 'kaminari' +gem 'elasticsearch-model' +gem 'elasticsearch-rails' + + +### profile +#gem 'oneapm_rpm' + +group :development do + gem 'grape-swagger' + gem 'better_errors', '~> 1.1.0' + # gem "query_reviewer" + # gem 'rack-mini-profiler', '~> 0.9.3' + if RUBY_PLATFORM =~ /w32/ + gem 'win32console' + end +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' + if RUBY_PLATFORM =~ /darwin/ + gem 'puma' + end + 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/entities/activity.rb b/app/api/mobile/entities/activity.rb index 3eab332a7..3ba82bcb9 100644 --- a/app/api/mobile/entities/activity.rb +++ b/app/api/mobile/entities/activity.rb @@ -84,7 +84,7 @@ module Mobile elsif ac.container_type == "Project" case ac.act_type when "Issue" - "椤圭洰缂洪櫡" + "椤圭洰闂" when "Message" "椤圭洰璁ㄨ鍖" when "Project" diff --git a/app/controllers/at_controller.rb b/app/controllers/at_controller.rb index fe16385f4..5b29565ad 100644 --- a/app/controllers/at_controller.rb +++ b/app/controllers/at_controller.rb @@ -68,7 +68,7 @@ class AtController < ApplicationController end def find_project(id) - return [] if id<0 + return [] if id.to_i<0 at_persons = Project.find(id).users at_persons.delete_if { |u| u.id == User.current.id } end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 1478bceae..17f62f18c 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -341,7 +341,7 @@ class CoursesController < ApplicationController def export_course_member_excel @all_members = student_homework_score(0,0,0,"desc") - @homeworks = @course.homework_commons.order("created_at asc") + @homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at asc") filename="#{@course.teacher.lastname.to_s + @course.teacher.firstname.to_s }_#{@course.name}_#{@course.time.to_s + @course.term}#{l(:excel_member_list)}"; respond_to do |format| @@ -1177,7 +1177,7 @@ class CoursesController < ApplicationController AND homework_commons.course_id = #{@course.id} AND student_works.user_id = members.user_id ) AS score,(SELECT (message_num*2 + message_reply_num*1 + news_reply_num*1 + news_num*1 + - resource_num*5 + journal_num*1 + homework_journal_num*1 ) FROM `course_contributor_scores` AS ccs WHERE ccs.course_id = 577 AND ccs.user_id = members.user_id + resource_num*5 + journal_num*1 + homework_journal_num*1 ) FROM `course_contributor_scores` AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id ) AS act_score FROM members JOIN students_for_courses @@ -1191,7 +1191,7 @@ class CoursesController < ApplicationController AND homework_commons.course_id = #{@course.id} AND student_works.user_id = members.user_id ) AS score,(SELECT (message_num*2 + message_reply_num*1 + news_reply_num*1 + news_num*1 + - resource_num*5 + journal_num*1 + homework_journal_num*1 ) FROM `course_contributor_scores` AS ccs WHERE ccs.course_id = 577 AND ccs.user_id = members.user_id + resource_num*5 + journal_num*1 + homework_journal_num*1 ) FROM `course_contributor_scores` AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id ) AS act_score FROM members JOIN students_for_courses diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index cf94da8d9..7ec796b61 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -256,6 +256,13 @@ class FilesController < ApplicationController @order = "" @is_remote = false if params[:project_id] + # 鏇存柊璧勬簮鐢宠娑堟伅涓哄凡璇 + # ar_ids = ApplyResource.where("user_id =? and container_id =? and container_type =?", User.current.id, params[:project_id].to_i, "Project").map{|ar| ar.id} + # cms = CourseMessage.where("course_message_type =? and user_id =? and course_message_id in (#{ar_ids.empty? ? '0': ar_ids.join(',')})", "ApplyResource", User.current.id) + # cms.each do |cm| + # cm.update_column(:viewed, true) + # end + # over @page = params[:page] ? params[:page].to_i + 1 : 2 @container_type = 0 if params[:sort] diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 9da4b90b9..376f8d5c2 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -14,6 +14,7 @@ class HomeworkCommonController < ApplicationController #unless params[:page] # update_homework_time(@course.homework_commons) #end + search = "%#{params[:search].to_s.strip.downcase}%" @new_homework = HomeworkCommon.new @new_homework.homework_detail_manual = HomeworkDetailManual.new @new_homework.course = @course @@ -21,10 +22,10 @@ class HomeworkCommonController < ApplicationController @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) if @is_teacher #@homeworks = @course.homework_commons.order("created_at desc").limit(10).offset(@page * 10) - @homework_commons = @course.homework_commons.order("created_at desc") + @homework_commons = @course.homework_commons.where("name like '%#{search}%'").order("created_at desc") else #@homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at desc").limit(10).offset(@page * 10) - @homework_commons = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at desc") + @homework_commons = @course.homework_commons.where("name like '%#{search}%' and publish_time <= '#{Date.today}'").order("created_at desc") end @is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher)) @is_new = params[:is_new] diff --git a/app/controllers/org_document_comments_controller.rb b/app/controllers/org_document_comments_controller.rb index c6047d227..02e74237a 100644 --- a/app/controllers/org_document_comments_controller.rb +++ b/app/controllers/org_document_comments_controller.rb @@ -102,13 +102,15 @@ class OrgDocumentCommentsController < ApplicationController end def destroy - @org_document_comment = OrgDocumentComment.find(params[:id]) - org = @org_document_comment.organization - if @org_document_comment.id == org.home_id - org.update_attributes(:home_id => nil) - end - if @org_document_comment.destroy - end + @org_document_comment = SubDocumentComment.find(params[:id]) + @sub_domain = @org_document_comment.sub_domain + @org_subfield = @sub_domain.org_subfield + # org = @org_document_comment.organization + # if @org_document_comment.id == org.home_id + # org.update_attributes(:home_id => nil) + # end + @org_document_comment.destroy + # end respond_to do |format| format.js end diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 1946378ef..3ab62bbea 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -164,7 +164,7 @@ class OrganizationsController < ApplicationController return end q = params[:search].nil? ? "" : "#{params[:search].strip}" - @field = OrgSubfield.find(params[:org_subfield_id]) + @field = params[:org_subfield_id].nil? ? OrgSubfield.where("organization_id =? and field_type =?", params[:id].to_i, "Comptec").first : OrgSubfield.find(params[:org_subfield_id]) @type = params[:type] if @type == "courses" || @type.nil? @org_teachers = User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 1d7b4117d..e4cf31f55 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -423,9 +423,13 @@ class PollController < ApplicationController # 灏嗗叾浠栧湴鏂圭殑闂嵎瀵煎嚭鏉 def other_poll # 鏌ヤ綔鑰呮槸鎴戯紝鎴栬呬綔鑰呮槸褰撳墠璇剧▼鐨勮佸笀锛屼笖涓嶅湪褰撳墠璇剧▼鍐呯殑闂嵎 杩涜瀵煎叆 - tea_ids = '(' - tea_ids << Course.find(params[:polls_group_id]).tea_id.to_s << ','<< User.current.id.to_s << ')' - @polls = Poll.where("user_id in #{tea_ids} and polls_type = 'course' and polls_group_id != #{params[:polls_group_id]}") + courses = User.current.courses.select { |course| User.current.allowed_to?(:as_teacher,course)} + course_ids = courses.empty? ? "(-1)" : "(" + courses.map { |course| course.id}.join(',') + ")" + none_courses = User.current.courses.where("is_delete = 1 or #{Course.table_name}.id = #{params[:polls_group_id].to_i}") + none_course_ids = none_courses.empty? ? "(-1)" : "(" + none_courses.map { |course| course.id}.join(',') + ")" + #tea_ids = '(' + #tea_ids << Course.find(params[:polls_group_id]).tea_id.to_s << ','<< User.current.id.to_s << ')' + @polls = Poll.where("(user_id = #{User.current.id} or polls_group_id in #{course_ids}) and polls_type = 'course' and polls_group_id not in #{none_course_ids}") @polls_group_id = params[:polls_group_id] respond_to do |format| format.js diff --git a/app/controllers/praise_tread_controller.rb b/app/controllers/praise_tread_controller.rb index 96eeab884..0c665341a 100644 --- a/app/controllers/praise_tread_controller.rb +++ b/app/controllers/praise_tread_controller.rb @@ -25,14 +25,14 @@ class PraiseTreadController < ApplicationController return end @horizontal = params[:horizontal].downcase == "false" ? false:true if params[:horizontal] - if @obj.respond_to?("author_id") - author_id = @obj.author_id - elsif @obj.respond_to?("user_id") - author_id = @obj.user_id - end - unless author_id == User.current.id - praise_tread_plus(@obj_type,@obj_id,1) - end + # if @obj.respond_to?("author_id") + # author_id = @obj.author_id + # elsif @obj.respond_to?("user_id") + # author_id = @obj.user_id + # end + # unless author_id == User.current.id + praise_tread_plus(@obj_type,@obj_id,1) + # end respond_to do |format| format.js end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 4a148bb8b..531f0cb90 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -362,6 +362,8 @@ update # project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT # ip = RepositoriesHelper::REPO_IP_ADDRESS gitlab_address = Redmine::Configuration['gitlab_address'] + # REDO:闇浼樺寲锛屼粎娴嬭瘯鐢 + @zip_path = gitlab_address.to_s + "/api/v3/projects/" + @project.gpid.to_s + "/repository/archive?&private_token=YTyCv4978MXmdL2B9C62" if @repository.type.to_s == "Repository::Gitlab" @repos_url = gitlab_address.to_s+"/"+@project.owner.to_s+"/"+@repository.identifier+"."+"git" else diff --git a/app/controllers/ssos_controller.rb b/app/controllers/ssos_controller.rb index 1e1bd932b..9a5042c50 100644 --- a/app/controllers/ssos_controller.rb +++ b/app/controllers/ssos_controller.rb @@ -27,8 +27,10 @@ class SsosController < ApplicationController ## 鍔犲叆缁勭粐 @organization = Organization.find(82) unless @organization.org_members.exists?(user_id: sso.user_id) - member = OrgMember.new(:user_id => sso.user_id) + member = OrgMember.create(:user_id => sso.user_id, :created_at => Time.now) + # member = OrgMember.new(:user_id => sso.user_id) @organization.org_members << member + OrgMemberRole.create(:org_member_id => member.id, :role_id => 12) end ## 閫夋嫨鎬ц烦杞 @@ -55,10 +57,7 @@ class SsosController < ApplicationController end def parse(auth) - crypted_str = Base64.decode64(base64_safe(auth)) - pkey = OpenSSL::PKey::RSA.new(File.new(File.join(Rails.root,"config/private.key"))) - content = pkey.private_decrypt(crypted_str,OpenSSL::PKey::RSA::PKCS1_PADDING) - # content = pkey.private_decrypt(crypted_str) + content = decrypt(auth) ActiveSupport::JSON.decode(content) end @@ -68,4 +67,20 @@ class SsosController < ApplicationController sso end + def decrypt(auth) + crypted_str = Base64.decode64(base64_safe(auth)) + pkey = OpenSSL::PKey::RSA.new(File.new(File.join(Rails.root,"config/private.key"))) + + #to large + max_dec_len = 1024/8 + size = (crypted_str.size + max_dec_len-1) / max_dec_len + + content = '' + size.times do |time| + tmps = crypted_str[time*max_dec_len, max_dec_len] + content += pkey.private_decrypt(tmps,OpenSSL::PKey::RSA::PKCS1_PADDING) + end + content + end + end diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index c3d7dbbc6..dd178a1ce 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -81,6 +81,7 @@ class StudentWorkController < ApplicationController #鏍规嵁浼犲叆鐨則Index纭畾鏄鍑犳娴嬭瘯 #涔嬪悗濡傛灉瑙夊緱寰堝崱 鍙互鏀规垚灏嗙粨鏋滀紶鍥濲S鍐嶄互鍙傛暟褰㈠紡浼犲洖鏉 def program_test_ex + tStarttime = Time.now is_test = params[:is_test] == 'true' @@ -106,106 +107,123 @@ class StudentWorkController < ApplicationController tEndtime = Time.now tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000 logger.debug "program_test_ex user wait time = #{tUsedtime} 姣" - - #status 0:绛旀姝g‘ -3http瓒呮椂 -2:缂栬瘧閿欒 -1:绛旀閿欒 2:绋嬪簭杩愯瓒呮椂 + #status 0:绛旀姝g‘ -5program_test_ex 鍑芥暟鍑洪敊 -4judge浠g爜鍑洪敊 -3http瓒呮椂 -2:缂栬瘧閿欒 -1:绛旀閿欒 2:绋嬪簭杩愯瓒呮椂 + resultObj[:status] = -3 CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>-3,:wait_time=>tUsedtime,:student_work_id=>student_work.id) - - end - if result["status"].to_i != -2 - #result["results"].first['output'] = result["results"].first['output'].gsub(" ","鈻") - #result["results"].first['result'] = result["results"].first['result'].gsub(" ","鈻") - space_replace_1(result["results"].first['output']) - space_replace_1(result["results"].first['result']) + rescue + #-4 judge浠g爜 鍑洪敊 + logger.debug "program_test_error 1" + resultObj[:status] = -4 + tmpstatus = -4 + CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>tmpstatus,:time_used=>0,:wait_time=>0,:student_work_id=>student_work.id) end - logger.debug result + begin + if resultObj[:status] != -3 && resultObj[:status] != -4 + if result["status"].to_i != -2 + #result["results"].first['output'] = result["results"].first['output'].gsub(" ","鈻") + #result["results"].first['result'] = result["results"].first['result'].gsub(" ","鈻") + space_replace_1(result["results"].first['output']) + space_replace_1(result["results"].first['result']) + end - #-1 榛樿鍊 0鍏ㄩ儴姝g‘骞剁粨鏉 2 瓒呮椂 -2 缂栬瘧閿欒 - resultObj[:status] = -1 - resultObj[:results] = result["results"].first #鏈娴嬭瘯缁撴灉 - result["error_msg"] = result["error_msg"][0..2047] - resultObj[:error_msg] = result["error_msg"] #缂栬瘧閿欒鏃剁殑淇℃伅 + logger.debug result - #璇ョ姸鎬佺敤浜庡瓨鍏odeTests - tmpstatus = -1 - if result["status"].to_i == -2 #缂栬瘧閿欒 - resultObj[:results] = result["error_msg"] - resultObj[:status] = -2 - tmpstatus = -2 - elsif result["results"][0]["status"].to_i == 2 - resultObj[:status] = 2 - tmpstatus = 2 - end + #-1 榛樿鍊 0鍏ㄩ儴姝g‘骞剁粨鏉 2 瓒呮椂 -2 缂栬瘧閿欒 + resultObj[:status] = -1 + resultObj[:results] = result["results"].first #鏈娴嬭瘯缁撴灉 + if result["status"].to_i == -2 #缂栬瘧閿欒 + result["error_msg"] = result["error_msg"][0..2047] + end + resultObj[:error_msg] = result["error_msg"] #缂栬瘧閿欒鏃剁殑淇℃伅 - if result["status"] == 0 - tmpstatus = 0 - end + #璇ョ姸鎬佺敤浜庡瓨鍏odeTests + tmpstatus = -1 + if result["status"].to_i == -2 #缂栬瘧閿欒 + resultObj[:results] = result["error_msg"] + resultObj[:status] = -2 + tmpstatus = -2 + elsif result["results"][0]["status"].to_i == 2 + resultObj[:status] = 2 + tmpstatus = 2 + end - unless student_work.save - resultObj[:status] = 200 - else - student_work.name = params[:title] - student_work.description = params[:src] + if result["status"] == 0 + tmpstatus = 0 + end - if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") - student_work.late_penalty = @homework.late_penalty - else - student_work.late_penalty = 0 - end + unless student_work.save + resultObj[:status] = 200 + else + student_work.name = params[:title] + student_work.description = params[:src] - #姣忔浠庢暟鎹簱鍙栧嚭涓婃鐨勭粨鏋滃姞涓婃湰娆$殑缁撴灉鍐嶅瓨鍏ユ暟鎹簱 - if result["status"].to_i != -2 - result["results"].first['user_wait'] = tUsedtime + if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") + student_work.late_penalty = @homework.late_penalty + else + student_work.late_penalty = 0 + end - if result["results"][0]["status"].to_i == 2 - result["status"] = 2 + #姣忔浠庢暟鎹簱鍙栧嚭涓婃鐨勭粨鏋滃姞涓婃湰娆$殑缁撴灉鍐嶅瓨鍏ユ暟鎹簱 + if result["status"].to_i != -2 + result["results"].first['user_wait'] = tUsedtime + + if result["results"][0]["status"].to_i == 2 + result["status"] = 2 + end + end + + status = result["status"] + if index == 1 + student_work_test = student_work.student_work_tests.build(status: status, + results: [resultObj[:results]],src: params[:src]) + student_work_test.save! + resultObj[:testid] = student_work_test.id + else + #鍏堜粠鏁版嵁搴撳彇鍑簉esult + student_work_test = StudentWorkTest.find(params[:testid]) + results = student_work_test.results + results << resultObj[:results] + student_work_test.results = results + student_work_test.status = (result["status"] != 0 ? result["status"] : student_work_test.status) + student_work_test.save! + status = student_work_test.status + resultObj[:testid] = student_work_test.id + end + + #瓒呮椂鎴栫紪璇戦敊璇垯鐩存帴杩斿洖浜嗗苟瀛樺叆鏁版嵁搴 + if resultObj[:status] == 2 || resultObj[:status] == -2 || index == @homework.homework_tests.size + if status == 0 + resultObj[:status] = 0 + end + student_work.save! + resultObj[:time] = student_work_test.created_at.to_s(:db) + resultObj[:index] = student_work.student_work_tests.count + end + + #灏嗘瘡娆$敤鎴风瓑寰呮椂闂撮兘瀛樿捣鏉ヤ互渚跨鐞嗙晫闈㈡樉绀虹敤 + tEndtime = Time.now + tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000 + logger.debug "program_test_ex user wait time = #{tUsedtime} 姣" + + time_used = 0 + if result["status"].to_i != -2 + #鑷冲皯涓姣 + time_used = result["results"].first['time_used'] == 0 ? 1:result["results"].first['time_used'] + end + #0:绛旀姝g‘ -3http瓒呮椂 -2:缂栬瘧閿欒 -1:绛旀閿欒 2:绋嬪簭杩愯瓒呮椂 + CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>tmpstatus,:time_used=>time_used,:wait_time=>tUsedtime,:student_work_id=>student_work.id) end end - - status = result["status"] - if index == 1 - student_work_test = student_work.student_work_tests.build(status: status, - results: [resultObj[:results]],src: params[:src]) - student_work_test.save! - resultObj[:testid] = student_work_test.id - else - #鍏堜粠鏁版嵁搴撳彇鍑簉esult - student_work_test = StudentWorkTest.find(params[:testid]) - results = student_work_test.results - results << resultObj[:results] - student_work_test.results = results - student_work_test.status = (result["status"] != 0 ? result["status"] : student_work_test.status) - student_work_test.save! - status = student_work_test.status - resultObj[:testid] = student_work_test.id - end - - #瓒呮椂鎴栫紪璇戦敊璇垯鐩存帴杩斿洖浜嗗苟瀛樺叆鏁版嵁搴 - if resultObj[:status] == 2 || resultObj[:status] == -2 || index == @homework.homework_tests.size - if status == 0 - resultObj[:status] = 0 - end - student_work.save! - resultObj[:time] = student_work_test.created_at.to_s(:db) - resultObj[:index] = student_work.student_work_tests.count - end - - #灏嗘瘡娆$敤鎴风瓑寰呮椂闂撮兘瀛樿捣鏉ヤ互渚跨鐞嗙晫闈㈡樉绀虹敤 - tEndtime = Time.now - tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000 - logger.debug "program_test_ex user wait time = #{tUsedtime} 姣" - - time_used = 0 - if result["status"].to_i != -2 - #鑷冲皯涓姣 - time_used = result["results"].first['time_used'] == 0 ? 1:result["results"].first['time_used'] - end - #0:绛旀姝g‘ -3http瓒呮椂 -2:缂栬瘧閿欒 -1:绛旀閿欒 2:绋嬪簭杩愯瓒呮椂 - CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>tmpstatus,:time_used=>time_used,:wait_time=>tUsedtime,:student_work_id=>student_work.id) - - #娓叉煋杩斿洖缁撴灉 - render :json => resultObj + rescue + #-5 program_test_ex 鍑芥暟鍑洪敊 + logger.debug "program_test_error 2" + resultObj[:status] = -5 + tmpstatus = -5 + CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>tmpstatus,:time_used=>0,:wait_time=>0,:student_work_id=>student_work.id) end + #娓叉煋杩斿洖缁撴灉 + render :json => resultObj end end end @@ -356,8 +374,9 @@ class StudentWorkController < ApplicationController end end ################################################################################################################## - @order,@b_sort,@name,@group = params[:order] || "score",params[:sort] || "desc",params[:name] || "",params[:group] + @order,@b_sort,@name,@group = params[:order] || "score",params[:sort] || "desc",params[:name].to_s.strip || "",params[:group] @homework_commons = @course.homework_commons.where("publish_time <= ?",Time.now.strftime("%Y-%m-%d")).order("created_at desc") + @all_homework_commons = @course.homework_commons.order("created_at desc") @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? @is_evaluation = @homework.homework_detail_manual && @homework.homework_detail_manual.comment_status == 2 && !@is_teacher #鏄笉鏄尶璇 @show_all = false diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6f3aa6b18..1a6bc4f1b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -311,6 +311,28 @@ class UsersController < ApplicationController end end + # 澶勭悊璧勬簮寮曠敤璇锋眰 + # status + def deal_with_apply_resource + @msg = CourseMessage.find(params[:msg_id]) + ar = ApplyResource.where("id = ?", @msg.course_message_id).first + unless ar.nil? + case params[:agree] + when 'Y' + ar.update_column('status', 2) + @msg.update_attributes(:apply_result => 1, :viewed => 1) + ar.course_messages << CourseMessage.new(:user_id => ar.user_id, :course_id => -1, :viewed => false, :apply_result => 2, :status => 1) + when 'N' + ar.update_column('status', 3) + @msg.update_attributes(:apply_result => 2, :viewed => 1) + ar.course_messages << CourseMessage.new(:user_id => ar.user_id, :course_id => -1, :viewed => false, :apply_result => 3, :status => 1) + end + end + respond_to do |format| + format.js + end + end + #澶勭悊寮曠敤浣滀笟鐨勮姹 #status 1 鍚屾剰 2 鎷掔粷 def dealwith_apply_homework @@ -419,6 +441,19 @@ class UsersController < ApplicationController end # end + # 璧勬簮鍒嗕韩璇锋眰寮规 + def apply_resource + if User.current.logged? + @attachment = Attachment.find params[:attachment_id] + @state = 2 + else + @state = 1 + end + respond_to do |format| + format.js + end + end + #寮曠敤浣滀笟璇锋眰寮规 def apply_homework if User.current.logged? @@ -432,6 +467,27 @@ class UsersController < ApplicationController end end + # 鐢宠寮曠敤璧勬簮 + def apply_for_resource + if User.current.logged? + @attachment = Attachment.where("id =?", params[:attachment_id].to_i).first + unless @attachment.nil? + ar = ApplyResource.where("user_id = ? and attachment_id = ?", User.current.id, params[:attacment_id].to_i) + if ar.empty? + ApplyResource.create(:user_id => params[:id].to_i, :attachment_id => params[:attachment_id].to_i, :status => true, :container_id => @attachment.container_id, :container_type => @attachment.container_type, :content => params[:content], :apply_user_id => @attachment.author_id) + @state = 2 + else + @state = 3 + end + end + else + @state = 1 + end + respond_to do |format| + format.js + end + end + #鐢宠寮曠敤闈炲叕寮浣滀笟 def apply_for_homework if User.current.logged? @@ -671,21 +727,21 @@ class UsersController < ApplicationController end def show_homework_detail - homework = HomeworkCommon.find params[:homework].to_i - if homework.course.is_public == 0 && !User.current.allowed_to?(:as_teacher,homework.course) && User.current != homework.user - ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", User.current.id, params[:homework].to_i) - if ah.empty? - @status = 2 - @homework = nil - elsif ah.first.status != 2 - @status = ah.first.status - @homework = nil - elsif ah.first.status == 2 - @homework = homework - end - else - @homework = homework - end + @homework = HomeworkCommon.find params[:homework].to_i + # if homework.course.is_public == 0 && !User.current.allowed_to?(:as_teacher,homework.course) && User.current != homework.user + # ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", User.current.id, params[:homework].to_i) + # if ah.empty? + # @status = 2 + # @homework = nil + # elsif ah.first.status != 2 + # @status = ah.first.status + # @homework = nil + # elsif ah.first.status == 2 + # @homework = homework + # end + # else + # @homework = homework + # end @is_import = params[:is_import] respond_to do |format| format.js @@ -1886,7 +1942,7 @@ class UsersController < ApplicationController # 灏嗚祫婧愬彂閫佸埌瀵瑰簲鐨勮绋,鍒嗕负鍙戦佸崟涓紝鎴栬呮壒閲忓彂閫 def add_exist_file_to_course @flag = true - if params[:send_id].present? + if params[:send_id].present? send_id = params[:send_id] @ori = Attachment.find_by_id(send_id) course_ids = params[:course_ids] @@ -1933,14 +1989,14 @@ class UsersController < ApplicationController end send_ids.each do |send_id| quotes = 0 - ori = Attachment.find_by_id(send_id) + @ori = Attachment.find_by_id(send_id) unless course_ids.nil? course_ids.each do |id| quotes = 0 - next if ori.blank? + next if @ori.blank? @exist = false Course.find(id).attachments.each do |att| #濡傛灉璇剧▼涓寘鍚璧勬簮 - if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from + if att.id == @ori.id || (!att.copy_from.nil? && !@ori.copy_from.nil? && att.copy_from == @ori.copy_from) || att.copy_from == @ori.id || att.id == @ori.copy_from att.created_on = Time.now att.save @exist = true @@ -1948,21 +2004,21 @@ class UsersController < ApplicationController end end next if @exist - attach_copied_obj = ori.copy - attach_copied_obj.tag_list.add(ori.tag_list) # tag鍏宠仈 + attach_copied_obj = @ori.copy + attach_copied_obj.tag_list.add(@ori.tag_list) # tag鍏宠仈 attach_copied_obj.container = Course.find(id) attach_copied_obj.created_on = Time.now attach_copied_obj.author_id = User.current.id attach_copied_obj.is_public = 0 - attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #鍙戦佽娣诲姞copy_from + attach_copied_obj.copy_from = @ori.copy_from.nil? ? @ori.id : @ori.copy_from #鍙戦佽娣诲姞copy_from if attach_copied_obj.attachtype == nil attach_copied_obj.attachtype = 4 end if attach_copied_obj.save # 鏇存柊寮曠敤娆℃暟 - quotes = ori.quotes.to_i + 1 - ori.update_attribute(:quotes, quotes) unless ori.nil? - ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) + quotes = @ori.quotes.to_i + 1 + @ori.update_attribute(:quotes, quotes) unless @ori.nil? + @ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) end @save_message = attach_copied_obj.errors.full_messages end @@ -2002,6 +2058,18 @@ class UsersController < ApplicationController # 鍏叡璧勬簮搴擄細鎵鏈夊叕寮璧勬簮鎴栬呮垜涓婁紶鐨勭鏈夎祫婧 @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end + elsif params[:type] == "2" + apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} + if params[:status] == "2" + resource_type = "'Course'" + elsif params[:status] == "3" + resource_type = "'Project'" + elsif params[:status] == "5" + resource_type = "'Principal'" + else + resource_type = "'Project','OrgSubfield','Principal','Course'" + end + @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) end @type = params[:type] @limit = 25 @@ -2143,6 +2211,18 @@ class UsersController < ApplicationController # 鍏叡璧勬簮搴擄細鎵鏈夊叕寮璧勬簮鎴栬呮垜涓婁紶鐨勭鏈夎祫婧 @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end + elsif params[:type] == "2" + apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} + if params[:status] == "2" + resource_type = "'Course'" + elsif params[:status] == "3" + resource_type = "'Project'" + elsif params[:status] == "5" + resource_type = "'Principal'" + else + resource_type = "'Project','OrgSubfield','Principal','Course'" + end + @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) end @status = params[:status] @type = params[:type] @@ -2272,6 +2352,18 @@ class UsersController < ApplicationController # 鍏叡璧勬簮搴擄細鎵鏈夊叕寮璧勬簮鎴栬呮垜涓婁紶鐨勭鏈夎祫婧 @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end + elsif params[:type] == "2" + apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} + if params[:status] == "2" + resource_type = "'Course'" + elsif params[:status] == "3" + resource_type = "'Project'" + elsif params[:status] == "5" + resource_type = "'Principal'" + else + resource_type = "'Project','OrgSubfield','Principal','Course'" + end + @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) end @type = params[:type] @limit = 25 @@ -2608,19 +2700,16 @@ class UsersController < ApplicationController # 鑾峰彇鍏叡璧勬簮 def get_public_resources user_course_ids, user_project_ids, order, score - attachments = Attachment.where("(is_publish = 1 and is_public =1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) ").order("#{order.nil? ? 'created_on' : order} #{score}") + attachments = Attachment.where("(is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) ").order("#{order.nil? ? 'created_on' : order} #{score}") end # 鑾峰彇鍏叡璧勬簮鎼滅储 def get_public_resources_search user_course_ids, user_project_ids, order, score, search - attachments = Attachment.where("is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course') and (filename like :p)" ,:p => search).order("#{order.nil? ? 'created_on' : order} #{score}") + attachments = Attachment.where("is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course') and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") end # 鑾峰彇鎴戠殑璧勬簮 def get_my_resources author_id, user_course_ids, user_project_ids, order, score - unless author_id.to_i.to_s == author_id - author_id = User.find_by_login(author_id).id - end attachments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('OrgSubfield','Principal','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" + "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)" ).order("#{order.nil? ? 'created_on' : order} #{score}") @@ -2628,7 +2717,6 @@ class UsersController < ApplicationController # 鑾峰彇鎴戠殑璧勬簮鏌ヨ缁撴灉 def get_my_resources_search (author_id, user_course_ids, user_project_ids, order, score, search) - author_id = User.find_by_login(author_id).id @attachments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" + "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("#{order.nil? ? 'created_on' : order} #{score}") @@ -2636,15 +2724,23 @@ class UsersController < ApplicationController # 鑾峰彇鎴戠殑璇剧▼璧勬簮 def get_course_resources author_id, user_course_ids, order, score - author_id = User.find_by_login(author_id).id attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Course')"+ "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" ).order("#{order.nil? ? 'created_on' : order} #{score}") end + # 鑾峰彇鎴戠殑绉佹湁璧勬簮鍒嗕韩缁撴灉 + def get_my_private_resources apply_ids, resource_type, order, score + attachments = Attachment.where("id in (#{apply_ids.empty? ? '0': apply_ids.join(',')}) and container_type in(#{resource_type})").order("#{order.nil? ? 'created_on' : order} #{score}") + end + + # 鑾峰彇鎴戠殑绉佹湁璧勬簮鍒嗕韩鎼滅储缁撴灉 + def get_my_private_resources_search apply_ids, resource_type, order, score, search + attachments = Attachment.where("id in (#{apply_ids.empty? ? '0': apply_ids.join(',')}) and container_type in(#{resource_type}) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") + end + # 鑾峰彇鎴戠殑璇剧▼璧勬簮涓悳绱㈢粨鏋 def get_course_resources_search author_id, user_course_ids, order, score, search - author_id = User.find_by_login(author_id).id attchments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Course')"+ "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") @@ -2652,17 +2748,16 @@ class UsersController < ApplicationController # 鑾峰彇鍏叡璧勬簮涓绋嬭祫婧 def get_course_resources_public user_course_ids, order, score - attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1)").order("#{order.nil? ? 'created_on' : order} #{score}") + attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1)").order("#{order.nil? ? 'created_on' : order} #{score}") end # 鑾峰彇鍏叡璧勬簮涓绋嬭祫婧愭悳绱㈢粨鏋 def get_course_resources_public_search user_course_ids, order, score, search - attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") + attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") end # 鑾峰彇鎴戠殑椤圭洰璧勬簮 def get_project_resources author_id, user_project_ids, order, score - author_id = User.find_by_login(author_id).id attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Project') "+ "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)").order("#{order.nil? ? 'created_on' : order} #{score}") @@ -2670,7 +2765,6 @@ class UsersController < ApplicationController # 鑾峰彇鎴戠殑椤圭洰璧勬簮鎼滅储 def get_project_resources_search author_id, user_project_ids, order, score, search - author_id = User.find_by_login(author_id).id attchments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Project') "+ "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") @@ -2678,24 +2772,22 @@ class UsersController < ApplicationController # 鑾峰彇鍏叡璧勬簮鐨勯」鐩祫婧 def get_project_resources_public user_project_ids, order, score - attchments = Attachment.where("container_type = 'Project' and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}") + attchments = Attachment.where("container_type = 'Project' and container_id is not null").order("#{order.nil? ? 'created_on' : order} #{score}") end # 鑾峰彇鍏叡璧勬簮鐨勯」鐩祫婧愭悳绱 def get_project_resources_public_search user_project_ids, order, score, search - attchments = Attachment.where("(container_type = 'Project' and container_id is not null and is_public =1) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") + attchments = Attachment.where("(container_type = 'Project' and container_id is not null) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") end # 鑾峰彇鎴戜笂浼犵殑闄勪欢 def get_attch_resources author_id, order, score - author_id = User.find_by_login(author_id).id attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue', 'Document','Message','News','StudentWorkScore','HomewCommon'))").order("#{order.nil? ? 'created_on' : order} #{score}") end # 鑾峰彇鎴戜笂浼犵殑闄勪欢鎼滅储缁撴灉 def get_attch_resources_search author_id, order, score, search - author_id = User.find_by_login(author_id).id attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue', 'Document','Message','News','StudentWorkScore','HomewCommon')) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") end @@ -2703,35 +2795,33 @@ class UsersController < ApplicationController # 鑾峰彇鍏叡璧勬簮涓垜涓婁紶鐨勯檮浠 def get_attch_resources_public order, score attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal') - and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}") + and container_id is not null").order("#{order.nil? ? 'created_on' : order} #{score}") end # 鑾峰彇鍏叡璧勬簮涓垜涓婁紶鐨勯檮浠 def get_attch_resources_public_search order, score, search attchments = Attachment.where("(container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal') - and container_id is not null and is_public =1) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") + and container_id is not null) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") end # 鑾峰彇鎴戠殑鐢ㄦ埛绫诲瀷璧勬簮 def get_principal_resources author_id, order, score - author_id = User.find_by_login(author_id).id attchments = Attachment.where("author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal'").order("#{order.nil? ? 'created_on' : order} #{score}") end # 鑾峰彇鎴戠殑鐢ㄦ埛绫诲瀷璧勬簮鎼滅储 def get_principal_resources_search author_id, order, score, search - author_id = User.find_by_login(author_id).id attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal') and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") end # 鑾峰彇鎴戠殑鐢ㄦ埛绫诲瀷璧勬簮 def get_principal_resources_public order, score - attchments = Attachment.where("container_type = 'Principal'and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}") + attchments = Attachment.where("container_type = 'Principal' and container_id is not null").order("#{order.nil? ? 'created_on' : order} #{score}") end # 鑾峰彇鎴戠殑鐢ㄦ埛绫诲瀷璧勬簮 def get_principal_resources_public_search order, score, search - attchments = Attachment.where("(container_type = 'Principal'and container_id is not null and is_public =1) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") + attchments = Attachment.where("(container_type = 'Principal'and container_id is not null) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") end # 璧勬簮搴 鍒嗕负鍏ㄩ儴 璇剧▼璧勬簮 椤圭洰璧勬簮 闄勪欢 @@ -2746,7 +2836,7 @@ class UsersController < ApplicationController user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } # user_org_ids = User.current.organizations.map {|o| o.id} - if(params[:type].blank? || params[:type] == "1") # 鎴戠殑璧勬簮 + if( params[:type] == "1") # 鎴戠殑璧勬簮 # 淇锛氭垜鐨勮祫婧愬簱鐨勮瘽锛岄偅涔堝簲璇ユ槸鎴戜笂浼犵殑鎵鏈夎祫婧愬姞涓婏紝鎴戝姞鍏ョ殑璇剧▼銆侀」鐩佺粍缁囩殑鎵鏈夎祫婧 if params[:status] == "2" @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) @@ -2760,7 +2850,7 @@ class UsersController < ApplicationController # 鍏叡璧勬簮搴擄細鎵鏈夊叕寮璧勬簮鎴栬呮垜涓婁紶鐨勭鏈夎祫婧 @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) end - elsif params[:type] == "6" # 鍏叡璧勬簮 + elsif (params[:type].blank? || params[:type] == "6") # 鍏叡璧勬簮 if params[:status] == "2" @attachments = get_course_resources_public( user_course_ids, @order, @score) elsif params[:status] == "3" @@ -2773,6 +2863,18 @@ class UsersController < ApplicationController # 鍏叡璧勬簮搴擄細鎵鏈夊叕寮璧勬簮鎴栬呮垜涓婁紶鐨勭鏈夎祫婧 @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end + elsif params[:type] == "2" # 绉佹湁璧勬簮 + apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} + if params[:status] == "2" + resource_type = "'Course'" + elsif params[:status] == "3" + resource_type = "'Project'" + elsif params[:status] == "5" + resource_type = "'Principal'" + else + resource_type = "'Project','OrgSubfield','Principal','Course'" + end + @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) end @status = params[:status] @type = params[:type] @@ -2792,8 +2894,7 @@ class UsersController < ApplicationController # 瀵煎叆璧勬簮 def import_resources # 鍒汉鐨勮祫婧愬簱鏄病鏈夋潈闄愬幓鐪嬬殑 - @user = User.find_by_login(params[:id]) - if User.current != @user + if User.current.id != params[:id].to_i render_403 return end @@ -2953,6 +3054,19 @@ class UsersController < ApplicationController # 鍏叡璧勬簮搴擄細鎵鏈夊叕寮璧勬簮鎴栬呮垜涓婁紶鐨勭鏈夎祫婧 @attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search) end + elsif params[:type] == "2" # 绉佹湁璧勬簮 + apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} + if params[:status] == "2" + resource_type = "'Course'" + elsif params[:status] == "3" + resource_type = "'Project'" + elsif params[:status] == "5" + resource_type = "'Principal'" + else + resource_type = "'Project','OrgSubfield','Principal','Course'" + end + @attachments = get_my_private_resources_search(apply_ids, resource_type, @order, @score, search) + @attachments end @status = params[:status] @type = params[:type] diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index a9e4771e8..39be9cef3 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -166,7 +166,7 @@ class WechatsController < ActionController::Base raise "闈炴硶鎿嶄綔, code涓嶅瓨鍦" unless params[:code] openid = get_openid_from_code(params[:code]) raise "鏃犳硶鑾峰彇鍒皁penid" unless openid - raise "姝ゅ井淇″彿宸茬粦瀹氱敤鎴, 涓嶈兘寰楀缁戝畾" if user_binded?(openid) + raise "姝ゅ井淇″彿宸茬粦瀹氱敤鎴, 涓嶈兘閲嶅缁戝畾" if user_binded?(openid) user, last_login_on = User.try_to_login(params[:username], params[:password]) raise "鐢ㄦ埛鍚嶆垨瀵嗙爜閿欒,璇烽噸鏂扮櫥褰" unless user diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cda3ce53c..8d9c9733e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -34,13 +34,6 @@ module ApplicationHelper def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter - def user_path(resource, parameters = {}) - if Fixnum === resource - resource = User.find(resource) - end - super - end - # def user_blogs_path(resource,parameters={}) # super # end @@ -56,6 +49,21 @@ module ApplicationHelper return result end + # 鍒ゆ柇鏌愪釜璧勬簮鏄惁鍙互鐢宠 + def attach_show_allow attach_id + attachment = Attachment.find(attach_id) + case attachment.container_type + when "Project" + User.current.member_of?(attachment.container) ? true : false + when "Course" + User.current.member_of_course?(attachment.container) ? true : false + when "OrgSubfield" + User.current.member_of_org?(attachment.container) ? true : false + when "Principal" + User.current.id == attachment.author_id ? true : false + end + end + # Time 2015-03-24 15:27:29 # Author lizanle # Description 浠庣‖鐩樹笂鍒犻櫎瀵瑰簲鐨勮祫婧愭枃浠 @@ -95,11 +103,13 @@ module ApplicationHelper # 鑾峰彇缁勭粐鎴愬憳涓枃鍚嶅瓧 def get_org_member_role_name member - case member.roles[0].name - when 'orgManager' - '绠$悊浜哄憳' - when 'orgMember' - '缁勭粐鎴愬憳' + unless member.roles[0].nil? + case member.roles[0].name + when 'orgManager' + '绠$悊浜哄憳' + when 'orgMember' + '缁勭粐鎴愬憳' + end end end @@ -3094,6 +3104,10 @@ def host_with_protocol return Setting.protocol + "://" + Setting.host_name end +def secdomain_with_protocol secdomain + return Setting.protocol + "://" + secdomain + ".trustie.net" +end + #鑾峰彇鍥炲鐨勬墍鏈夌埗鑺傜偣 def get_reply_parents parents_rely, comment diff --git a/app/models/apply_resource.rb b/app/models/apply_resource.rb new file mode 100644 index 000000000..df646166c --- /dev/null +++ b/app/models/apply_resource.rb @@ -0,0 +1,19 @@ +class ApplyResource < ActiveRecord::Base + # status锛1. 绛夊緟鍥炲 2.瀹℃牳閫氳繃 3.宸叉嫆缁 + attr_accessible :attachment_id, :status, :user_id, :container_type, :container_id, :apply_user_id, :content + belongs_to :user + belongs_to :attachment + has_many :course_messages, :class_name => 'CourseMessage', :as => :course_message, :dependent => :destroy + after_create :act_as_apply_resource_message + + def act_as_apply_resource_message + self.course_messages << CourseMessage.new(:user_id => self.apply_user_id, :course_id => -1, :viewed => false, :status => 0, ) + # REDO:鍙戦侀偖浠 + # Mailer.run.apply_for_resource_request(self.container_id, User.current) + end + + def find_attachment attachment_id + Attachment.find(attachment_id) + end + +end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index b3f5ce4ed..b7ec264fd 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -35,6 +35,7 @@ class Attachment < ActiveRecord::Base # end include UserScoreHelper has_many :attachment_histories + has_many :apply_resources, :dependent => :destroy validates :filename, presence: true, length: {maximum: 254} validates :author, presence: true @@ -139,6 +140,11 @@ class Attachment < ActiveRecord::Base } ) end + + def get_apply_resource_status attachment_id, author_id + ApplyResource.where("attachment_id =? and apply_user_id =?", attachment_id, author_id).first.try(:status) + end + # add by nwb # 鍏紑鐨勯」鐩甶d鍒楄〃 def self.public_project_id @@ -536,6 +542,11 @@ class Attachment < ActiveRecord::Base end end + # 鑾峰彇璧勬簮鐢宠鐘舵 + def get_status_by_attach user_id + ApplyResource.where("user_id =? and attachment_id =?", user_id, self.id).first.try(:status) + end + private # Physically deletes the file from the file system diff --git a/app/models/course_message.rb b/app/models/course_message.rb index 703da936b..59fcfe456 100644 --- a/app/models/course_message.rb +++ b/app/models/course_message.rb @@ -1,5 +1,7 @@ class CourseMessage < ActiveRecord::Base # status璇存槑锛 status鍦ㄨ绋嬩笉鍚岀殑绫诲瀷锛屽尯鍒嗕笉鍚岀殑鍔熻兘 status = 9 浣滃搧鐨勬彁浜よ褰 + # ApplyResource status: + # 0: 鍙戦佺敵璇 1锛氬洖澶嶅厑璁哥敵璇 2锛氭嫆缁濈敵璇锋秷鎭 # HomeworkCommon锛歴tatus锛 # nil锛氬彂甯冧簡浣滀笟锛 1锛氫綔涓氭埅姝㈡椂闂村埌浜嗘彁閱掞紒锛2:寮鍚尶璇勶紱 3锛氬叧闂尶璇勶紱 4锛氬尶璇勫紑濮嬪け璐ワ紱 5锛氱敵璇峰紩鐢ㄤ綔涓, 6:鐢宠缁撴灉 # apply_user_id: 鐢宠鑰呯殑鐢ㄦ埛id diff --git a/app/models/news.rb b/app/models/news.rb index 1544faf61..a411ccaca 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -174,7 +174,7 @@ class News < ActiveRecord::Base if count == 0 ws = WechatService.new content = strip_html self.author.try(:realname) + " 鍙戝竷浜嗛氱煡锛" + self.title.html_safe, 200 - ws.message_update_template m.user_id, "course_notice", self.id, "#{l(:label_new_notice_template)}", self.author.try(:realname) + " 鍙戝竷浜嗛氱煡锛" + content, format_time(self.created_on) + ws.message_update_template m.user_id, "course_notice", self.id, "#{l(:label_new_notice_template)}", content, format_time(self.created_on) end end end diff --git a/app/models/organization.rb b/app/models/organization.rb index 311a37bf8..c35d0591d 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -30,4 +30,8 @@ class Organization < ActiveRecord::Base def allow_set_teachers self.allow_teacher.to_i == 1 ? true : false end + + def secdomain_name + Secdomain.where("sub_type=2 and pid=?", self.id).first.try(:subname) + end end diff --git a/app/models/sso.rb b/app/models/sso.rb index c6b57cd2d..c987ff933 100644 --- a/app/models/sso.rb +++ b/app/models/sso.rb @@ -1,3 +1,7 @@ +#coding=utf-8 + +require 'base64' + class Sso < ActiveRecord::Base belongs_to :user attr_accessible :email, :name, :openid, :password, :school, :sex, :user, :user_id diff --git a/app/models/user.rb b/app/models/user.rb index 035aff625..44ef54c95 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -109,6 +109,7 @@ class User < Principal has_many :student_works_scores, :dependent => :destroy has_many :student_work_projects, :dependent => :destroy has_many :apply_homeworks, :dependent => :destroy + has_many :apply_resources, :dependent => :destroy #end has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)}, @@ -1103,9 +1104,6 @@ class User < Principal # super end - def to_param - login - end # Salts all existing unsalted passwords # It changes password storage scheme from SHA1(password) to SHA1(salt + SHA1(password)) # This method is used in the SaltPasswords migration and is to be kept as is diff --git a/app/views/admin/code_work_tests.html.erb b/app/views/admin/code_work_tests.html.erb index 64c3a41e1..2013bd322 100644 --- a/app/views/admin/code_work_tests.html.erb +++ b/app/views/admin/code_work_tests.html.erb @@ -24,8 +24,8 @@