From 089c4ab490256638cc8cb27a057139829044cf32 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Sun, 6 Sep 2015 16:49:29 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E7=94=A8=E6=88=B7=E5=8F=AA=E5=8F=AF?= =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E8=87=AA=E5=B7=B1=E7=9A=84=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=202=E3=80=81=E5=8F=91=E5=B8=83=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E5=A2=9E=E5=8A=A0=E6=9D=83=E9=99=90=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E5=92=8C=E7=99=BB=E5=BD=95=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 126 +++++++++++++++------------- 1 file changed, 69 insertions(+), 57 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e3480b238..d0b0bd82d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -296,12 +296,16 @@ class UsersController < ApplicationController #用户作业列表 def user_homeworks - @page = params[:page] ? params[:page].to_i + 1 : 0 - user_course_ids = "(" + @user.courses.visible.map{|course| course.id}.join(",") + ")" - @homework_commons = HomeworkCommon.where("course_id in #{user_course_ids}").order("created_at desc").limit(10).offset(@page * 10) - respond_to do |format| - format.js - format.html {render :layout => 'new_base_user'} + if User.current == @user + @page = params[:page] ? params[:page].to_i + 1 : 0 + user_course_ids = "(" + @user.courses.visible.map{|course| course.id}.join(",") + ")" + @homework_commons = HomeworkCommon.where("course_id in #{user_course_ids}").order("created_at desc").limit(10).offset(@page * 10) + respond_to do |format| + format.js + format.html {render :layout => 'new_base_user'} + end + else + render_403 end end @@ -345,16 +349,20 @@ class UsersController < ApplicationController end def new_user_commit_homework - @user = User.current - @homework = HomeworkCommon.find(params[:homework_id]) - @is_test = params[:is_test] == 'true' - @student_work = @homework.student_works.where(user_id: User.current.id).first - if @student_work.nil? - @student_work = StudentWork.new - end - respond_to do |format| - format.js - format.html {render :layout => 'new_base_user'} + if User.current.logged? + @user = User.current + @homework = HomeworkCommon.find(params[:homework_id]) + @is_test = params[:is_test] == 'true' + @student_work = @homework.student_works.where(user_id: User.current.id).first + if @student_work.nil? + @student_work = StudentWork.new + end + respond_to do |format| + format.js + format.html {render :layout => 'new_base_user'} + end + else + render_403 end end @@ -364,53 +372,57 @@ class UsersController < ApplicationController end def user_new_homework - if params[:homework_common] - homework = HomeworkCommon.new - homework.name = params[:homework_common][:name] - homework.description = params[:homework_common][:description] - homework.end_time = params[:homework_common][:end_time] || Time.now - homework.publish_time = Time.now - homework.homework_type = params[:homework_type].to_i || 1 - homework.late_penalty = 2 - homework.user_id = User.current.id - homework.course_id = params[:course_id] + if User.current.logged? + if params[:homework_common] + homework = HomeworkCommon.new + homework.name = params[:homework_common][:name] + homework.description = params[:homework_common][:description] + homework.end_time = params[:homework_common][:end_time] || Time.now + homework.publish_time = Time.now + homework.homework_type = params[:homework_type].to_i || 1 + homework.late_penalty = 2 + homework.user_id = User.current.id + homework.course_id = params[:course_id] - homework.save_attachments(params[:attachments]) - render_attachment_warning_if_needed(homework) + homework.save_attachments(params[:attachments]) + render_attachment_warning_if_needed(homework) - #匿评作业相关属性 - if homework.homework_type == 1 - homework_detail_manual = HomeworkDetailManual.new - homework_detail_manual.ta_proportion = params[:ta_proportion] || 0.6 - homework_detail_manual.comment_status = 1 - homework_detail_manual.evaluation_start = Time.now - homework_detail_manual.evaluation_end = Time.now - homework_detail_manual.evaluation_num = params[:evaluation_num] || 3 - homework_detail_manual.absence_penalty = 2 - homework.homework_detail_manual = homework_detail_manual - else - homework_detail_programing = HomeworkDetailPrograming.new - homework.homework_detail_programing = homework_detail_programing - homework_detail_programing.ta_proportion = params[:ta_proportion] || 0.6 - homework_detail_programing.language = params[:program][:language].to_i + #匿评作业相关属性 + if homework.homework_type == 1 + homework_detail_manual = HomeworkDetailManual.new + homework_detail_manual.ta_proportion = params[:ta_proportion] || 0.6 + homework_detail_manual.comment_status = 1 + homework_detail_manual.evaluation_start = Time.now + homework_detail_manual.evaluation_end = Time.now + homework_detail_manual.evaluation_num = params[:evaluation_num] || 3 + homework_detail_manual.absence_penalty = 2 + homework.homework_detail_manual = homework_detail_manual + else + homework_detail_programing = HomeworkDetailPrograming.new + homework.homework_detail_programing = homework_detail_programing + homework_detail_programing.ta_proportion = params[:ta_proportion] || 0.6 + homework_detail_programing.language = params[:program][:language].to_i - inputs = params[:program][:input] - if Array === inputs - inputs.each_with_index do |val, i| - homework.homework_tests << HomeworkTest.new( - input: val, - output: params[:program][:output][i] - ) + inputs = params[:program][:input] + if Array === inputs + inputs.each_with_index do |val, i| + homework.homework_tests << HomeworkTest.new( + input: val, + output: params[:program][:output][i] + ) + end end - end - - end - if homework.save - homework_detail_manual.save if homework_detail_manual - homework_detail_programing.save if homework_detail_programing - redirect_to user_homeworks_user_path(User.current.id) + end + + if homework.save + homework_detail_manual.save if homework_detail_manual + homework_detail_programing.save if homework_detail_programing + redirect_to user_homeworks_user_path(User.current.id) + end end + else + render_403 end end