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)) %>
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/student_work/_evaluation_un_work.html.erb b/app/views/student_work/_evaluation_un_work.html.erb index adb007219..04e48bf7d 100644 --- a/app/views/student_work/_evaluation_un_work.html.erb +++ b/app/views/student_work/_evaluation_un_work.html.erb @@ -128,7 +128,7 @@ 作品最终评分为 -  <%= score %> 
+  <%= student_work.final_score %> 
迟交扣分   <%= student_work.late_penalty %> 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 => "用户头像" %>
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| %>
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(); 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|