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' 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/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/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 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/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)) %>