From e658a5426d7ba5bac137fe8c3079e714c471118c Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 24 Feb 2017 17:18:32 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E7=8F=AD=E7=BA=A7=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E9=A2=98=E5=BA=93=EF=BC=8C=E9=A2=98=E5=BA=93?= =?UTF-8?q?=E4=B8=AD=E8=AF=A5=E4=BD=9C=E4=B8=9A=E7=9A=84=E5=BC=95=E7=94=A8?= =?UTF-8?q?=E6=95=B0=E6=98=AF=E9=9B=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_common_controller.rb | 8 ++++++++ app/controllers/users_controller.rb | 1 + app/helpers/application_helper.rb | 2 +- app/models/homework_common.rb | 11 +++++++++++ db/migrate/20170220065632_homework_bank_migration.rb | 2 +- 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 71a8dddf3..031a228ce 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -315,6 +315,14 @@ class HomeworkCommonController < ApplicationController #加入到题库 def add_to_homework_bank if params[:type] && (params[:type].to_i == 1 || params[:type].to_i == 3) + if params[:type].to_i == 3 + old_banks = HomeworkBank.where(:homework_common_id => @homework.id) + unless old_banks.blank? + old_banks.each do |bank| + bank.update_attributes(:quotes => (bank.quotes - 1) > 0 ? (bank.quotes - 1) : 0) + end + end + end homework_bank = add_to_homework_bank_f @homework homework_bank.save @homework.update_attributes(:homework_bank_id => homework_bank.id) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7113d0c98..a0fc10506 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1499,6 +1499,7 @@ class UsersController < ApplicationController if params[:add_to_bank] homework_bank = add_to_homework_bank_f homework homework_bank.save + homework.update_attributes(:homework_bank_id => homework_bank.id) end redirect_to homework_common_index_path(:course => homework.course_id) end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a8c3d2de4..6dd20aceb 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -4119,7 +4119,7 @@ end def add_to_homework_bank_f homework homework_bank = HomeworkBank.new(:name => homework.name, :description => homework.description, :user_id => homework.user_id, :homework_type => homework.homework_type, - :quotes => 0, :is_public => homework.course.is_public, :applicable_syllabus => homework.course.syllabus.title, :homework_common_id => homework.id) + :quotes => 1, :is_public => homework.course.is_public, :applicable_syllabus => homework.course.syllabus.title, :homework_common_id => homework.id) if homework.homework_type == 2 && homework.homework_detail_programing homework_bank.language = homework.homework_detail_programing.language homework.homework_tests.each_with_index do |homework_test| diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 13b076617..92d47bcdc 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -36,6 +36,17 @@ class HomeworkCommon < ActiveRecord::Base after_update :update_activity after_save :act_as_course_activity after_destroy :delete_kindeditor_assets + before_destroy :update_homework_bank_quotes + + #删除时更新题库中的引用数 + def update_homework_bank_quotes + old_banks = HomeworkBank.where(:homework_common_id => self.id) + unless old_banks.blank? + old_banks.each do |bank| + bank.update_attributes(:quotes => (bank.quotes - 1) > 0 ? (bank.quotes - 1) : 0, :homework_common_id => nil) + end + end + end #作业类型 def homework_type_ch diff --git a/db/migrate/20170220065632_homework_bank_migration.rb b/db/migrate/20170220065632_homework_bank_migration.rb index 85a7a69bc..6e47288ae 100644 --- a/db/migrate/20170220065632_homework_bank_migration.rb +++ b/db/migrate/20170220065632_homework_bank_migration.rb @@ -11,7 +11,7 @@ class HomeworkBankMigration < ActiveRecord::Migration course.homework_commons.each do |homework| unless homework.user.homework_banks.select("name").to_s.include?(homework.name) homework_bank = HomeworkBank.create(:user_id => homework.user_id, :name => homework.name, :description => homework.description, :homework_type => homework.homework_type, - :quotes => homework.quotes, :is_public => course.is_public, :applicable_syllabus => course.syllabus.title, :homework_common_id => homework.id, :created_at => homework.created_at) + :quotes => 1, :is_public => course.is_public, :applicable_syllabus => course.syllabus.title, :homework_common_id => homework.id, :created_at => homework.created_at) if homework.homework_type == 2 && homework.homework_detail_programing homework_bank.update_attributes(:language => homework.homework_detail_programing.language, :standard_code => homework.homework_detail_programing.standard_code) homework.homework_tests.each do |test| From 29e22f0c6cfa7fde0e69ab0c20aa9f94169cac66 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 24 Feb 2017 17:42:15 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E5=88=9A=E6=96=B0=E5=BB=BA=E7=9A=84?= =?UTF-8?q?=E7=8F=AD=E7=BA=A7=E4=BD=9C=E4=B8=9A=EF=BC=8C=E8=AF=84=E5=88=86?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=B8=AD=E6=9C=80=E7=BB=88=E5=BE=97=E5=88=86?= =?UTF-8?q?=E2=80=9C=E5=8A=A9=E6=95=99+=E5=8C=BF=E8=AF=84=E2=80=9D?= =?UTF-8?q?=E7=9A=84=E9=BB=98=E8=AE=A4=E6=AF=94=E4=BE=8B=E9=94=99=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_work_controller.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 7c0c7c67c..cd433a450 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -1317,12 +1317,20 @@ class StudentWorkController < ApplicationController @homework.update_column('anonymous_comment', @homework.anonymous_comment == 0 ? 1 : 0) homework_detail_manual = @homework.homework_detail_manual homework_detail_programing = @homework.homework_detail_programing - if homework_detail_programing - homework_detail_manual.update_column('ta_proportion', 0.4) - homework_detail_programing.update_column('ta_proportion', 0.6) + if @homework.anonymous_comment == 1 + homework_detail_manual.ta_proportion = @homework.homework_type == 2 ? 0.4 : 1.0 else - homework_detail_manual.update_column('ta_proportion', 1.0) + homework_detail_manual.ta_proportion = @homework.homework_type == 2 ? 0.3 : 0.6 end + if @homework.homework_type == 2 && homework_detail_programing + if @homework.anonymous_comment == 1 + homework_detail_programing.ta_proportion = 0.6 + else + homework_detail_programing.ta_proportion = 0.5 + end + end + homework_detail_manual.save + homework_detail_programing.save if homework_detail_programing @homework.student_works.each do |student_work| set_final_score @homework,student_work student_work.save From 73f64e80a851d639b96a5a8853eea02c1a443072 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 24 Feb 2017 18:32:09 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E7=8F=AD=E7=BA=A7=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=EF=BC=9A=E6=96=B0=E5=BB=BA=E4=BD=9C=E4=B8=9A=E6=97=B6=E2=80=9C?= =?UTF-8?q?=E4=BB=8E=E9=A2=98=E5=BA=93=E9=80=89=E7=94=A8=E2=80=9D=E7=BC=96?= =?UTF-8?q?=E7=A8=8B=E4=BD=9C=E4=B8=9A=EF=BC=8C=E5=A6=82=E5=9B=BE=E6=8A=A5?= =?UTF-8?q?500?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/_user_programing_attr.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/_user_programing_attr.html.erb b/app/views/users/_user_programing_attr.html.erb index 885013600..e6fb89f8b 100644 --- a/app/views/users/_user_programing_attr.html.erb +++ b/app/views/users/_user_programing_attr.html.erb @@ -4,7 +4,7 @@ 温馨提示:请至少输入一组样例供学生参考。
- <% if edit_mode && homework.is_program_homework? %> + <% if edit_mode && homework.is_program_homework? && homework.homework_samples.count > 0 %> <% homework.homework_samples.each_with_index do |sample, index| %>
From ca706f3df596dd68ad82c19da66863fc9ea85864 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 24 Feb 2017 19:11:29 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=BB=8E=E9=A2=98=E5=BA=93=E9=80=89?= =?UTF-8?q?=E7=94=A8=E4=BD=9C=E4=B8=9A=EF=BC=9A=E7=BC=96=E7=A8=8B=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E5=8F=98=E6=88=90=E6=99=AE=E9=80=9A=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E7=BC=96=E7=A8=8B=E7=9B=B8=E5=85=B3=E7=9A=84?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E8=AE=BE=E7=BD=AE=E8=BF=98=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/user_select_homework.js.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/users/user_select_homework.js.erb b/app/views/users/user_select_homework.js.erb index fd30f6502..7c84183ba 100644 --- a/app/views/users/user_select_homework.js.erb +++ b/app/views/users/user_select_homework.js.erb @@ -15,6 +15,8 @@ homework_description_editor.html("<%= escape_javascript(@homework.description.ht <% elsif @homework_detail_group %> $("#homeworkSetting").removeClass("undis"); $("#homeworkSetting").html("<%=escape_javascript(render :partial => 'users/user_group_attr', :locals => {:edit_mode => true, :homework=>@homework, :not_allow_select => false}) %>"); +<% else %> + $("#homeworkSetting").addClass("undis"); <% end %> document.getElementById("homework_type_option").options[<%=@homework.homework_type %>].selected = true; $("#select_type_nitice").hide(); From 6d3ab4f65138016824b164062645040fcab8d2b3 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 24 Feb 2017 20:00:31 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E5=92=8C=E7=8F=AD=E7=BA=A7=E9=80=9A=E7=9F=A5=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E5=9B=9E=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/comments_controller.rb | 2 +- app/models/news.rb | 13 +++++++++++++ app/services/comment_service.rb | 2 +- app/views/news/_news_all_replies.html.erb | 2 +- app/views/news/_news_replies_detail.html.erb | 2 +- app/views/users/_course_news_post_reply.html.erb | 3 ++- 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 99c9b9af7..1dbaa13e8 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -24,7 +24,7 @@ class CommentsController < ApplicationController before_filter :authorize, :except => [:destroy] def create - raise Unauthorized unless @news.commentable? + #raise Unauthorized unless @news.commentable? if !@news.org_subfield_id.nil? @org_subfield = OrgSubfield.find(@news.org_subfield_id) end diff --git a/app/models/news.rb b/app/models/news.rb index aa04cea08..1b091cf0d 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -103,6 +103,19 @@ class News < ActiveRecord::Base user.allowed_to?(:comment_news, project) end + def news_object + object = self.project + if object == nil && self.has_attribute?('course_id') + object = self.course + if object.nil? && self.has_attribute?('contest_id') + object = self.contest + elsif object.nil? && self.has_attribute?('org_subfield_id') + object = self.org_subfield + end + end + object + end + def recipients project.users.select {|user| user.notify_about?(self)}.map(&:mail) end diff --git a/app/services/comment_service.rb b/app/services/comment_service.rb index 62955905b..9ff00c610 100644 --- a/app/services/comment_service.rb +++ b/app/services/comment_service.rb @@ -8,7 +8,7 @@ class CommentService if @course.nil? raise 'news in unknown course' end - raise Unauthorized unless @news.commentable?(current_user) + #raise Unauthorized unless @news.commentable?(current_user) if current_user.nil? || !(current_user.admin? || @course.is_public == 1 || (@course.is_public == 0 && current_user.member_of_course?(@course))) raise '403' end diff --git a/app/views/news/_news_all_replies.html.erb b/app/views/news/_news_all_replies.html.erb index 4bfad4c96..e704ee703 100644 --- a/app/views/news/_news_all_replies.html.erb +++ b/app/views/news/_news_all_replies.html.erb @@ -13,7 +13,7 @@ <% end %>
-<% if @news.commentable? %> +<% if User.current.admin? || ((object.kind_of? Contest) && User.current.member_of_contest?(object)) || ((object.kind_of? Course) && User.current.member_of_course?(object)) || ((object.kind_of? OrgSubfield) && User.current.member_of_org?(object.organization)) %>
diff --git a/app/views/news/_news_replies_detail.html.erb b/app/views/news/_news_replies_detail.html.erb index 1507b366d..fbac8c96a 100644 --- a/app/views/news/_news_replies_detail.html.erb +++ b/app/views/news/_news_replies_detail.html.erb @@ -41,7 +41,7 @@ :class => 'fr mr20 undis', :data => {:confirm => l(:text_are_you_sure)}, :title => l(:button_delete) - ) if ((object.kind_of? Organization) ? (User.current.admin_of_org?(object) || User.current == comment.author) : (User.current.allowed_to?(:manage_news, object) || User.current == comment.author || User.current.admin_of_contest?(object))) %> + ) if ((object.kind_of? OrgSubfield) ? (User.current.admin_of_org?(object.organization) || User.current == comment.author) : (User.current.allowed_to?(:manage_news, object) || User.current == comment.author || User.current.admin_of_contest?(object))) %>
diff --git a/app/views/users/_course_news_post_reply.html.erb b/app/views/users/_course_news_post_reply.html.erb index df1c51ae3..1b0c29685 100644 --- a/app/views/users/_course_news_post_reply.html.erb +++ b/app/views/users/_course_news_post_reply.html.erb @@ -8,7 +8,8 @@ <%= render :partial => 'users/news_replies', :locals => {:comments => no_children_comments[:no_children_comments], :user_activity_id => user_activity_id, :type => 'News', :activity_id => activity.id} %>
<% end %> -<% if activity.commentable? %> +<% object = activity.news_object %> +<% if User.current.admin? || ((object.kind_of? Contest) && User.current.member_of_contest?(object)) || ((object.kind_of? Course) && User.current.member_of_course?(object)) || ((object.kind_of? OrgSubfield) && User.current.member_of_org?(object.organization)) %>
<%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(User.current), :alt => "用户头像" %>
From b3a62f7325b777a3bd3e63b31ab8557651eda686 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 24 Feb 2017 20:09:51 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E7=8F=AD=E7=BA=A7=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=EF=BC=9A=E5=A6=82=E5=9B=BE=E5=88=86=E7=BB=84=E4=BD=9C=E5=93=81?= =?UTF-8?q?=E2=80=9C=E4=BD=9C=E5=93=81=E6=9C=80=E7=BB=88=E8=AF=84=E5=88=86?= =?UTF-8?q?=E2=80=9D=E6=98=BE=E7=A4=BA=E7=9A=84=E6=98=AF=E6=89=A3=E5=88=86?= =?UTF-8?q?=E5=89=8D=E7=9A=84=E5=88=86=EF=BC=8C=E6=99=AE=E9=80=9A=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E6=98=BE=E7=A4=BA=E7=9A=84=E5=8D=B4=E6=98=AF=E6=89=A3?= =?UTF-8?q?=E5=88=86=E5=90=8E=E7=9A=84=E5=88=86=EF=BC=8C=E5=BB=BA=E8=AE=AE?= =?UTF-8?q?=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/student_work/_evaluation_un_work.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/student_work/_evaluation_un_work.html.erb b/app/views/student_work/_evaluation_un_work.html.erb index adb007219..e61d65bc2 100644 --- a/app/views/student_work/_evaluation_un_work.html.erb +++ b/app/views/student_work/_evaluation_un_work.html.erb @@ -128,8 +128,8 @@ 作品最终评分为 -  <%= score %> 
- 迟交扣分 +  <%= student_work.final_score %> 
+ 迟交扣分   <%= student_work.late_penalty %>  
From 03b7f91ed8956879ab23c057c06c615b9947b928 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 24 Feb 2017 20:28:23 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E7=8F=AD=E7=BA=A7=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=EF=BC=9A=E5=A6=82=E5=9B=BE=E5=88=86=E7=BB=84=E4=BD=9C=E5=93=81?= =?UTF-8?q?=E2=80=9C=E4=BD=9C=E5=93=81=E6=9C=80=E7=BB=88=E8=AF=84=E5=88=86?= =?UTF-8?q?=E2=80=9D=E6=98=BE=E7=A4=BA=E7=9A=84=E6=98=AF=E6=89=A3=E5=88=86?= =?UTF-8?q?=E5=89=8D=E7=9A=84=E5=88=86=EF=BC=8C=E6=99=AE=E9=80=9A=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E6=98=BE=E7=A4=BA=E7=9A=84=E5=8D=B4=E6=98=AF=E6=89=A3?= =?UTF-8?q?=E5=88=86=E5=90=8E=E7=9A=84=E5=88=86=EF=BC=8C=E5=BB=BA=E8=AE=AE?= =?UTF-8?q?=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/student_work/_evaluation_un_work.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/student_work/_evaluation_un_work.html.erb b/app/views/student_work/_evaluation_un_work.html.erb index e61d65bc2..04e48bf7d 100644 --- a/app/views/student_work/_evaluation_un_work.html.erb +++ b/app/views/student_work/_evaluation_un_work.html.erb @@ -129,7 +129,7 @@ 作品最终评分为  <%= student_work.final_score %> 
- 迟交扣分 + 迟交扣分   <%= student_work.late_penalty %>  
From a6bf791358fbffa2d7fc5d156963f7273e0de07c Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 24 Feb 2017 20:38:49 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E8=AE=A8=E8=AE=BA=E5=8C=BA=E5=A6=82?= =?UTF-8?q?=E5=9B=BE=E5=88=86=E9=A1=B5=E5=BD=93=E5=89=8D=E9=A1=B5=E4=B8=BA?= =?UTF-8?q?=E6=9C=80=E5=90=8E=E4=B8=80=E9=A1=B5=EF=BC=8C=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E4=B8=8B=E4=B8=80=E9=A1=B5=E5=BB=BA=E8=AE=AE=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E7=AC=AC=E4=B8=80=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/boards_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index 2f7d66ee0..b8c2c3880 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -199,7 +199,7 @@ class BoardsController < ApplicationController end else respond_to do |format| - format.js + format.js {render "show.js.erb"} format.html { if @project render :action => 'show', :layout => 'base_projects'