diff --git a/app/controllers/blog_comments_controller.rb b/app/controllers/blog_comments_controller.rb index f5e3314bb..7220eec27 100644 --- a/app/controllers/blog_comments_controller.rb +++ b/app/controllers/blog_comments_controller.rb @@ -91,8 +91,12 @@ class BlogCommentsController < ApplicationController def edit @article = BlogComment.find(params[:id]) - respond_to do |format| - format.html {render :layout=>'new_base_user'} + if User.current.admin? || User.current.id == @article.author_id + respond_to do |format| + format.html { render :layout => 'new_base_user' } + end + else + render_403 end end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index f06a782bc..24f5fd52c 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -902,10 +902,7 @@ class CoursesController < ApplicationController end def feedback - @course.journals_for_messages.each do |messages| - query = messages.course_messages.where("user_id = ?", User.current.id) - query.update_all(:viewed => true); - end + CourseMessage.where("user_id = ? and course_id = ?", User.current, @course.id).update_all(:viewed => true) if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course))) page = params[:page] diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 9f754a0fc..3532a9e4c 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -1,378 +1,380 @@ -class HomeworkCommonController < ApplicationController - require 'net/http' - require 'json' - require "base64" - layout "base_courses" - - include StudentWorkHelper - before_filter :find_course, :only => [:index,:new,:create] - before_filter :find_homework, :only => [:edit,:update,:alert_anonymous_comment,:start_anonymous_comment,:stop_anonymous_comment,:destroy,:start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works,:open_student_works] - before_filter :teacher_of_course, :only => [:new, :create, :edit, :update, :destroy, :start_anonymous_comment, :stop_anonymous_comment, :alert_anonymous_comment,:start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works,:open_student_works] - before_filter :member_of_course, :only => [:index] - - def index - @new_homework = HomeworkCommon.new - @new_homework.homework_detail_manual = HomeworkDetailManual.new - @new_homework.course = @course - @page = params[:page] ? params[:page].to_i + 1 : 0 - @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) - if @is_teacher - @homeworks = @course.homework_commons.order("updated_at desc").limit(10).offset(@page * 10) - else - @homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("updated_at desc").limit(10).offset(@page * 10) - end - @is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher)) - @is_new = params[:is_new] - - #设置at已读 - @homeworks.each do |homework| - homework.journals_for_messages.each do |j| - User.current.at_messages.unviewed('JournalsForMessage', j.id).each {|x| x.viewed!} - end - end - - respond_to do |format| - format.js - format.html - end - end - - #新建作业,在个人作业列表创建作业 - def new - render_404 - end - - #新建作业,在个人作业列表创建作业 - def create - redirect_to user_homeworks_user_path(User.current.id) - end - - def edit - @user = User.current - @is_in_course = params[:is_in_course].to_i - @course_activity = params[:course_activity].to_i - respond_to do |format| - format.html{render :layout => 'new_base_user'} - end - end - - def update - if params[:homework_common] - @homework.name = params[:homework_common][:name] - @homework.description = params[:homework_common][:description] - if params[:homework_common][:publish_time] == "" - @homework.publish_time = Date.today - else - @homework.publish_time = params[:homework_common][:publish_time] - end - @homework.end_time = params[:homework_common][:end_time] || Time.now - @homework.course_id = params[:course_id] - @homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment] : 0 - - homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new - if @homework.publish_time <= Date.today && homework_detail_manual.comment_status == 0 - homework_detail_manual.comment_status = 1 - end - homework_detail_manual.evaluation_start = params[:evaluation_start].blank? ? @homework.end_time + 7 : params[:evaluation_start] - homework_detail_manual.evaluation_end = params[:evaluation_end].blank? ? homework_detail_manual.evaluation_start + 7 : params[:evaluation_end] - - @homework.save_attachments(params[:attachments]) - render_attachment_warning_if_needed(@homework) - - #编程作业相关属性 - if @homework.homework_type == 2 - @homework.homework_detail_programing ||= HomeworkDetailPrograming.new - @homework_detail_programing = @homework.homework_detail_programing - @homework_detail_programing.language = params[:language_type].to_i - - @homework.homework_tests.delete_all - 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 - - #分组作业 - if @homework.homework_type == 3 - @homework.homework_detail_group ||= HomeworkDetailGroup.new - @homework_detail_group = @homework.homework_detail_group - @homework_detail_group.min_num = params[:min_num].to_i - @homework_detail_group.max_num = params[:max_num].to_i - @homework_detail_group.base_on_project = params[:base_on_project].to_i - end - - if @homework.save - @homework_detail_manual.save if @homework_detail_manual - @homework_detail_programing.save if @homework_detail_programing - @homework_detail_group.save if @homework_detail_group - - if params[:is_in_course] == "1" - redirect_to homework_common_index_path(:course => @course.id) - elsif params[:is_in_course] == "0" - redirect_to user_homeworks_user_path(User.current.id) - elsif params[:is_in_course] == "-1" && params[:course_activity] == "0" - redirect_to user_path(User.current.id) - elsif params[:is_in_course] == "-1" && params[:course_activity] == "1" - redirect_to course_path(@course.id) - end - end - end - end - - def destroy - if @homework.destroy - respond_to do |format| - format.html { - if params[:is_in_course] == "1" - redirect_to homework_common_index_path(:course => @course.id) - elsif params[:is_in_course] == "0" - redirect_to user_homeworks_user_path(User.current.id) - elsif params[:is_in_course] == "-1" && params[:course_activity] == "0" - redirect_to user_path(User.current.id) - elsif params[:is_in_course] == "-1" && params[:course_activity] == "1" - redirect_to course_path(@course.id) - end - } - end - end - end - - #开启匿评 - #statue 1:启动成功,2:启动失败,作业总数大于等于2份时才能启动匿评,3:已开启匿评,请务重复开启,4:没有开启匿评的权限 - def start_anonymous_comment - @statue = 4 and return unless User.current.admin? || User.current.allowed_to?(:as_teacher,@course) - @statue = 5 and return if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") - if @homework_detail_manual.comment_status == 1 - student_works = @homework.student_works - if student_works && student_works.size >= 2 - if @homework.homework_type == 3 - student_work_projects = @homework.student_work_projects.where("student_work_id is not null") - student_work_projects.each_with_index do |pro_work, pro_index| - n = @homework_detail_manual.evaluation_num - n = n < student_works.size ? n : student_works.size - 1 - work_index = -1 - student_works.each_with_index do |stu_work, stu_index| - if stu_work.id.to_i == pro_work.student_work_id.to_i - work_index = stu_index - end - end - assigned_homeworks = get_assigned_homeworks(student_works, n, work_index) - assigned_homeworks.each do |h| - student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: pro_work.user_id, student_work_id: h.id) - student_works_evaluation_distributions.save - end - end - else - student_works.each_with_index do |work, index| - user = work.user - n = @homework_detail_manual.evaluation_num - n = n < student_works.size ? n : student_works.size - 1 - assigned_homeworks = get_assigned_homeworks(student_works, n, index) - assigned_homeworks.each do |h| - student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: user.id, student_work_id: h.id) - student_works_evaluation_distributions.save - end - end - end - @homework_detail_manual.update_column('comment_status', 2) - @homework_detail_manual.update_column('evaluation_start', Date.today) - @statue = 1 - # 匿评开启消息邮件通知 - send_message_anonymous_comment(@homework, m_status = 2) - Mailer.send_mail_anonymous_comment_open(@homework).deliver - else - @statue = 2 - - end - else - @statue = 3 - end - @user_activity_id = params[:user_activity_id].to_i - @is_in_course = params[:is_in_course].to_i - @course_activity = params[:course_activity].to_i - end - - #关闭匿评 - def stop_anonymous_comment - @homework_detail_manual.update_column('comment_status', 3) - @homework_detail_manual.update_column('evaluation_end', Date.today) - #计算缺评扣分 - work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")" - @homework.student_works.each do |student_work| - absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids}").count - student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0 - student_work.save - end - # 匿评关闭消息邮件通知 - send_message_anonymous_comment(@homework, m_status = 3) - Mailer.send_mail_anonymous_comment_close(@homework).deliver - @user_activity_id = params[:user_activity_id].to_i - @is_in_course = params[:is_in_course].to_i - @course_activity = params[:course_activity].to_i - respond_to do |format| - format.js - end - end - - # 开启/关闭匿评消息通知 - def send_message_anonymous_comment(homework, m_status ) - # status 标记匿评状态 1为关闭 0为开启 - course = homework.course - course.members.each do |m| - @homework.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => m_status) - end - end - #提示 - def alert_anonymous_comment - @cur_size = 0 - @totle_size = 0 - if @homework_detail_manual.comment_status == 1 - @totle_size = @course.student.count - @cur_size = @homework.student_works.size - elsif @homework_detail_manual.comment_status == 2 - @homework.student_works.map { |work| @totle_size += work.student_works_evaluation_distributions.count} - @cur_size = 0 - @homework.student_works.map { |work| @cur_size += work.student_works_scores.where(:reviewer_role => 3).count} - end - @percent = format("%.2f",(@cur_size.to_f / ( @totle_size == 0 ? 1 : @totle_size)) * 100) - @user_activity_id = params[:user_activity_id].to_i - @is_in_course = params[:is_in_course].to_i - @course_activity = params[:course_activity].to_i - respond_to do |format| - format.js - end - end - - def alert_forbidden_anonymous_comment - if params[:user_activity_id] - @user_activity_id = params[:user_activity_id] - else - @user_activity_id = -1 - end - @is_in_course = params[:is_in_course] if params[:is_in_course] - @course_activity = params[:course_activity] if params[:course_Activity] - respond_to do |format| - format.js - end - end - - def open_student_works - if @homework.is_open == 0 - @homework.update_attribute(:is_open, 1) - else - @homework.update_attribute(:is_open, 0) - end - @user_activity_id = params[:user_activity_id] - @is_in_course = params[:is_in_course] if params[:is_in_course] - @course_activity = params[:course_activity] if params[:course_Activity] - end - - def alert_open_student_works - if params[:user_activity_id] - @user_activity_id = params[:user_activity_id] - else - @user_activity_id = -1 - end - @is_in_course = params[:is_in_course] if params[:is_in_course] - @course_activity = params[:course_activity] if params[:course_Activity] - respond_to do |format| - format.js - end - end - - def programing_test - test = {language:params[:language],src:Base64.encode64(params[:src]),input:[params[:input]],output:[params[:output]]} - @index = params[:index] - uri = URI('http://192.168.80.21:8080/api/realtime.json') - body = test.to_json - res = Net::HTTP.new(uri.host, uri.port).start do |client| - request = Net::HTTP::Post.new(uri.path) - request.body = body - request["Content-Type"] = "application/json" - client.request(request) - end - result = JSON.parse(res.body) - @err_msg = result["compile_error_msg"] - result["results"].each do |re| - @result = re["status"] - end - end - - #启动匿评参数设置 - def start_evaluation_set - if params[:user_activity_id] - @user_activity_id = params[:user_activity_id] - else - @user_activity_id = -1 - end - @is_in_course = params[:is_in_course] - @course_activity = params[:course_activity].to_i - end - - #设置匿评参数 - def set_evaluation_attr - if @homework_detail_manual - unless params[:evaluation_start].to_s == @homework_detail_manual.evaluation_start.to_s - @homework_detail_manual.evaluation_start = params[:evaluation_start] - end - - unless @homework_detail_manual.evaluation_end.to_s == params[:evaluation_end].to_s - @homework_detail_manual.evaluation_end = params[:evaluation_end] - end - - @homework_detail_manual.evaluation_num = params[:evaluation_num] - @homework_detail_manual.save - @user_activity_id = params[:user_activity_id].to_i - @is_in_course = params[:is_in_course].to_i - @course_activity = params[:course_activity].to_i - end - end - - #评分设置 - def score_rule_set - if params[:user_activity_id] - @user_activity_id = params[:user_activity_id] - else - @user_activity_id = -1 - end - @is_in_course = params[:is_in_course] - @course_activity = params[:course_activity].to_i - end - - private - #获取课程 - def find_course - @course = Course.find params[:course] - rescue - render_404 - end - #获取作业 - def find_homework - @homework = HomeworkCommon.find params[:id] - @homework_detail_manual = @homework.homework_detail_manual - @homework_detail_programing = @homework.homework_detail_programing - @homework_detail_group = @homework.homework_detail_group - @course = @homework.course - rescue - render_404 - end - #是不是课程的老师 - def teacher_of_course - render_403 unless User.current.allowed_to?(:as_teacher,@course) || User.current.admin? - end - - #当前用户是不是课程的成员 - def member_of_course - render_403 unless @course.is_public==1 || User.current.member_of_course?(@course) || User.current.admin? - end - - def get_assigned_homeworks(student_works, n, index) - student_works += student_works - student_works[index + 1 .. index + n] - end -end +class HomeworkCommonController < ApplicationController + require 'net/http' + require 'json' + require "base64" + layout "base_courses" + + include StudentWorkHelper + before_filter :find_course, :only => [:index,:new,:create] + before_filter :find_homework, :only => [:edit,:update,:alert_anonymous_comment,:start_anonymous_comment,:stop_anonymous_comment,:destroy,:start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works,:open_student_works] + before_filter :teacher_of_course, :only => [:new, :create, :edit, :update, :destroy, :start_anonymous_comment, :stop_anonymous_comment, :alert_anonymous_comment,:start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works,:open_student_works] + before_filter :member_of_course, :only => [:index] + + def index + @new_homework = HomeworkCommon.new + @new_homework.homework_detail_manual = HomeworkDetailManual.new + @new_homework.course = @course + @page = params[:page] ? params[:page].to_i + 1 : 0 + @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) + if @is_teacher + @homeworks = @course.homework_commons.order("updated_at desc").limit(10).offset(@page * 10) + else + @homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("updated_at desc").limit(10).offset(@page * 10) + end + @is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher)) + @is_new = params[:is_new] + + #设置at已读 + @homeworks.each do |homework| + homework.journals_for_messages.each do |j| + User.current.at_messages.unviewed('JournalsForMessage', j.id).each {|x| x.viewed!} + end + end + + respond_to do |format| + format.js + format.html + end + end + + #新建作业,在个人作业列表创建作业 + def new + render_404 + end + + #新建作业,在个人作业列表创建作业 + def create + redirect_to user_homeworks_user_path(User.current.id) + end + + def edit + @user = User.current + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i + respond_to do |format| + format.html{render :layout => 'new_base_user'} + end + end + + def update + if params[:homework_common] + @homework.name = params[:homework_common][:name] + @homework.description = params[:homework_common][:description] + if params[:homework_common][:publish_time] == "" + @homework.publish_time = Date.today + else + @homework.publish_time = params[:homework_common][:publish_time] + end + @homework.end_time = params[:homework_common][:end_time] || Time.now + @homework.course_id = params[:course_id] + @homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment] : 0 + + homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new + if @homework.publish_time <= Date.today && homework_detail_manual.comment_status == 0 + homework_detail_manual.comment_status = 1 + end + eval_start = homework_detail_manual.evaluation_start + if eval_start <= @homework.end_time && homework_detail_manual.comment_status <= 1 + homework_detail_manual.evaluation_start = @homework.end_time + 7 + homework_detail_manual.evaluation_end = homework_detail_manual.evaluation_start + 7 + end + @homework.save_attachments(params[:attachments]) + render_attachment_warning_if_needed(@homework) + + #编程作业相关属性 + if @homework.homework_type == 2 + @homework.homework_detail_programing ||= HomeworkDetailPrograming.new + @homework_detail_programing = @homework.homework_detail_programing + @homework_detail_programing.language = params[:language_type].to_i + + @homework.homework_tests.delete_all + 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 + + #分组作业 + if @homework.homework_type == 3 + @homework.homework_detail_group ||= HomeworkDetailGroup.new + @homework_detail_group = @homework.homework_detail_group + @homework_detail_group.min_num = params[:min_num].to_i + @homework_detail_group.max_num = params[:max_num].to_i + @homework_detail_group.base_on_project = params[:base_on_project].to_i + end + + if @homework.save + @homework_detail_manual.save if @homework_detail_manual + @homework_detail_programing.save if @homework_detail_programing + @homework_detail_group.save if @homework_detail_group + + if params[:is_in_course] == "1" + redirect_to homework_common_index_path(:course => @course.id) + elsif params[:is_in_course] == "0" + redirect_to user_homeworks_user_path(User.current.id) + elsif params[:is_in_course] == "-1" && params[:course_activity] == "0" + redirect_to user_path(User.current.id) + elsif params[:is_in_course] == "-1" && params[:course_activity] == "1" + redirect_to course_path(@course.id) + end + end + end + end + + def destroy + if @homework.destroy + respond_to do |format| + format.html { + if params[:is_in_course] == "1" + redirect_to homework_common_index_path(:course => @course.id) + elsif params[:is_in_course] == "0" + redirect_to user_homeworks_user_path(User.current.id) + elsif params[:is_in_course] == "-1" && params[:course_activity] == "0" + redirect_to user_path(User.current.id) + elsif params[:is_in_course] == "-1" && params[:course_activity] == "1" + redirect_to course_path(@course.id) + end + } + end + end + end + + #开启匿评 + #statue 1:启动成功,2:启动失败,作业总数大于等于2份时才能启动匿评,3:已开启匿评,请务重复开启,4:没有开启匿评的权限 + def start_anonymous_comment + @statue = 4 and return unless User.current.admin? || User.current.allowed_to?(:as_teacher,@course) + @statue = 5 and return if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") + if @homework_detail_manual.comment_status == 1 + student_works = @homework.student_works + if student_works && student_works.size >= 2 + if @homework.homework_type == 3 + student_work_projects = @homework.student_work_projects.where("student_work_id is not null") + student_work_projects.each_with_index do |pro_work, pro_index| + n = @homework_detail_manual.evaluation_num + n = n < student_works.size ? n : student_works.size - 1 + work_index = -1 + student_works.each_with_index do |stu_work, stu_index| + if stu_work.id.to_i == pro_work.student_work_id.to_i + work_index = stu_index + end + end + assigned_homeworks = get_assigned_homeworks(student_works, n, work_index) + assigned_homeworks.each do |h| + student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: pro_work.user_id, student_work_id: h.id) + student_works_evaluation_distributions.save + end + end + else + student_works.each_with_index do |work, index| + user = work.user + n = @homework_detail_manual.evaluation_num + n = n < student_works.size ? n : student_works.size - 1 + assigned_homeworks = get_assigned_homeworks(student_works, n, index) + assigned_homeworks.each do |h| + student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: user.id, student_work_id: h.id) + student_works_evaluation_distributions.save + end + end + end + @homework_detail_manual.update_column('comment_status', 2) + @homework_detail_manual.update_column('evaluation_start', Date.today) + @statue = 1 + # 匿评开启消息邮件通知 + send_message_anonymous_comment(@homework, m_status = 2) + Mailer.send_mail_anonymous_comment_open(@homework).deliver + else + @statue = 2 + + end + else + @statue = 3 + end + @user_activity_id = params[:user_activity_id].to_i + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i + end + + #关闭匿评 + def stop_anonymous_comment + @homework_detail_manual.update_column('comment_status', 3) + @homework_detail_manual.update_column('evaluation_end', Date.today) + #计算缺评扣分 + work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")" + @homework.student_works.each do |student_work| + absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids}").count + student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0 + student_work.save + end + # 匿评关闭消息邮件通知 + send_message_anonymous_comment(@homework, m_status = 3) + Mailer.send_mail_anonymous_comment_close(@homework).deliver + @user_activity_id = params[:user_activity_id].to_i + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i + respond_to do |format| + format.js + end + end + + # 开启/关闭匿评消息通知 + def send_message_anonymous_comment(homework, m_status ) + # status 标记匿评状态 1为关闭 0为开启 + course = homework.course + course.members.each do |m| + @homework.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => m_status) + end + end + #提示 + def alert_anonymous_comment + @cur_size = 0 + @totle_size = 0 + if @homework_detail_manual.comment_status == 1 + @totle_size = @course.student.count + @cur_size = @homework.student_works.size + elsif @homework_detail_manual.comment_status == 2 + @homework.student_works.map { |work| @totle_size += work.student_works_evaluation_distributions.count} + @cur_size = 0 + @homework.student_works.map { |work| @cur_size += work.student_works_scores.where(:reviewer_role => 3).count} + end + @percent = format("%.2f",(@cur_size.to_f / ( @totle_size == 0 ? 1 : @totle_size)) * 100) + @user_activity_id = params[:user_activity_id].to_i + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i + respond_to do |format| + format.js + end + end + + def alert_forbidden_anonymous_comment + if params[:user_activity_id] + @user_activity_id = params[:user_activity_id] + else + @user_activity_id = -1 + end + @is_in_course = params[:is_in_course] if params[:is_in_course] + @course_activity = params[:course_activity] if params[:course_Activity] + respond_to do |format| + format.js + end + end + + def open_student_works + if @homework.is_open == 0 + @homework.update_attribute(:is_open, 1) + else + @homework.update_attribute(:is_open, 0) + end + @user_activity_id = params[:user_activity_id] + @is_in_course = params[:is_in_course] if params[:is_in_course] + @course_activity = params[:course_activity] if params[:course_Activity] + end + + def alert_open_student_works + if params[:user_activity_id] + @user_activity_id = params[:user_activity_id] + else + @user_activity_id = -1 + end + @is_in_course = params[:is_in_course] if params[:is_in_course] + @course_activity = params[:course_activity] if params[:course_Activity] + respond_to do |format| + format.js + end + end + + def programing_test + test = {language:params[:language],src:Base64.encode64(params[:src]),input:[params[:input]],output:[params[:output]]} + @index = params[:index] + uri = URI('http://192.168.80.21:8080/api/realtime.json') + body = test.to_json + res = Net::HTTP.new(uri.host, uri.port).start do |client| + request = Net::HTTP::Post.new(uri.path) + request.body = body + request["Content-Type"] = "application/json" + client.request(request) + end + result = JSON.parse(res.body) + @err_msg = result["compile_error_msg"] + result["results"].each do |re| + @result = re["status"] + end + end + + #启动匿评参数设置 + def start_evaluation_set + if params[:user_activity_id] + @user_activity_id = params[:user_activity_id] + else + @user_activity_id = -1 + end + @is_in_course = params[:is_in_course] + @course_activity = params[:course_activity].to_i + end + + #设置匿评参数 + def set_evaluation_attr + if @homework_detail_manual + unless params[:evaluation_start].to_s == @homework_detail_manual.evaluation_start.to_s + @homework_detail_manual.evaluation_start = params[:evaluation_start] + end + + unless @homework_detail_manual.evaluation_end.to_s == params[:evaluation_end].to_s + @homework_detail_manual.evaluation_end = params[:evaluation_end] + end + + @homework_detail_manual.evaluation_num = params[:evaluation_num] + @homework_detail_manual.save + @user_activity_id = params[:user_activity_id].to_i + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i + end + end + + #评分设置 + def score_rule_set + if params[:user_activity_id] + @user_activity_id = params[:user_activity_id] + else + @user_activity_id = -1 + end + @is_in_course = params[:is_in_course] + @course_activity = params[:course_activity].to_i + end + + private + #获取课程 + def find_course + @course = Course.find params[:course] + rescue + render_404 + end + #获取作业 + def find_homework + @homework = HomeworkCommon.find params[:id] + @homework_detail_manual = @homework.homework_detail_manual + @homework_detail_programing = @homework.homework_detail_programing + @homework_detail_group = @homework.homework_detail_group + @course = @homework.course + rescue + render_404 + end + #是不是课程的老师 + def teacher_of_course + render_403 unless User.current.allowed_to?(:as_teacher,@course) || User.current.admin? + end + + #当前用户是不是课程的成员 + def member_of_course + render_403 unless @course.is_public==1 || User.current.member_of_course?(@course) || User.current.admin? + end + + def get_assigned_homeworks(student_works, n, index) + student_works += student_works + student_works[index + 1 .. index + n] + end +end diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index eb78c4c5b..44f0d15f4 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -118,6 +118,9 @@ class IssuesController < ApplicationController end def show + # 打开编辑内容 + @is_edit = true unless params[:edit].nil? + # 当前用户查看指派给他的缺陷消息,则设置消息为已读 query = ForgeMessage.where("forge_message_type =? and user_id =? and forge_message_id =?", "Issue", User.current, @issue).first query.update_attribute(:viewed, true) unless query.nil? @@ -387,6 +390,9 @@ class IssuesController < ApplicationController end def destroy + # 增加删除页面类型,如果是个人主页,则返回该主页,项目动态则返回项目动态页眉 + page_classify = params[:page_classify] unless params[:page_classify].nil? + page_id = params[:page_id] unless params[:page_id].nil? @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f if @hours > 0 case params[:todo] @@ -415,7 +421,11 @@ class IssuesController < ApplicationController end end respond_to do |format| - format.html { redirect_back_or_default _project_issues_path(@project) } + if page_classify + format.html { redirect_back_or_default _project_issues_path(@project, page_classify, page_id) } + else + format.html { redirect_back_or_default _project_issues_path(@project) } + end format.api { render_api_ok } end end diff --git a/app/controllers/org_document_comments_controller.rb b/app/controllers/org_document_comments_controller.rb index f250b46de..d1a8b23dd 100644 --- a/app/controllers/org_document_comments_controller.rb +++ b/app/controllers/org_document_comments_controller.rb @@ -1,6 +1,6 @@ class OrgDocumentCommentsController < ApplicationController before_filter :find_organization, :only => [:new, :create, :show, :index] - helper :attachments + helper :attachments,:organizations layout 'base_org' def new diff --git a/app/controllers/org_subfields_controller.rb b/app/controllers/org_subfields_controller.rb index 9337c5fd2..ba4c1f18f 100644 --- a/app/controllers/org_subfields_controller.rb +++ b/app/controllers/org_subfields_controller.rb @@ -5,9 +5,8 @@ class OrgSubfieldsController < ApplicationController def create if OrgSubfield.where("organization_id=#{params[:organization_id]} and name=?",params[:name]).count == 0 @res = true - @subfield = OrgSubfield.create(:name => params[:name]) @organization = Organization.find(params[:organization_id]) - @organization.org_subfields << @subfield + @subfield = OrgSubfield.create(:name => params[:name], :organization_id => params[:organization_id],:priority => @organization.org_subfields.order("priority").last.priority + 1) if !params[:sub_dir].blank? sql = "select subfield_subdomain_dirs.* from subfield_subdomain_dirs, org_subfields where subfield_subdomain_dirs.org_subfield_id = org_subfields.id "+ "and org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir]}'" @@ -15,7 +14,7 @@ class OrgSubfieldsController < ApplicationController SubfieldSubdomainDir.create(:org_subfield_id => @subfield.id, :name => params[:sub_dir]) end end - @subfield.update_attributes(:priority => @subfield.id, :field_type => params[:field_type]) + @subfield.update_attributes(:field_type => params[:field_type]) else @res = false end @@ -125,6 +124,12 @@ class OrgSubfieldsController < ApplicationController end end + def update_priority + @org_subfield = OrgSubfield.find(params[:id]) + @org_subfield.update_attribute(:priority, params[:priority].to_i) + @organization = @org_subfield.organization + end + def show_attachments obj @attachments = [] obj.each do |container| diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 711663c3d..239253d82 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -317,7 +317,7 @@ class OrganizationsController < ApplicationController @organization = Organization.find(params[:id]) admins = User.where("admin=1") admins.each do |admin| - OrgMessage.create(:user_id => admin.id, :organization_id => @organization.id, :message_type => 'ApplySubdomain', :message_id => @organization.id, :sender_id => User.current.id, :viewed => 0, :content => params[:domain]) + OrgMessage.create(:user_id => admin.id, :organization_id => @organization.id, :message_type => 'ApplySubdomain', :message_id => @organization.id, :sender_id => User.current.id, :viewed => 0, :content => params[:domain].downcase) end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 05c80a9fc..2ced977be 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -300,66 +300,27 @@ class ProjectsController < ApplicationController end # 统计访问量 @project.update_attribute(:visits, @project.visits.to_i + 1) -=begin - cond = @project.project_condition(Setting.display_subprojects_issues?) - has = { - "show_issues" => true , - "show_files" => true, - "show_documents" => true, - "show_messages" => true, - "show_news" => true, - "show_bids" => true, - "show_contests" => true, - "show_wiki_edits"=>true, - "show_journals_for_messages" => true - } - # 读取项目默认展示的动态时间天数 - @days = Setting.activity_days_default.to_i - @date_to ||= Date.today + 1 - # 时间跨度不能太大,不然很慢,所以删掉了-1.years - @date_from = @date_to - @days - @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1') -=end - @author = params[:user_id].blank? ? nil : User.active.find(params[:user_id]) - # 决定显示所用用户或单个用户活动 -=begin - @activity = Redmine::Activity::Fetcher.new(User.current, - :project => @project, - :with_subprojects => @with_subprojects, - :author => @author) - @activity.scope_select {|t| !has["show_#{t}"].nil?} -=end - @page = params[:page] ? params[:page].to_i + 1 : 0 # 根据私密性,取出符合条件的所有数据 if User.current.member_of?(@project) || User.current.admin? case params[:type] when nil - @events_pages = ForgeActivity.where("project_id = ? and forge_act_type in ('Issue', 'Message','News', 'ProjectCreateInfo')",@project).order("updated_at desc").limit(10).offset(@page * 10) + @events_pages = ForgeActivity.where("project_id = ? and forge_act_type in ('Issue', 'Message','News', 'ProjectCreateInfo', 'Attachment')",@project).order("updated_at desc").limit(10).offset(@page * 10) when 'issue' @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Issue'",@project).order("updated_at desc").limit(10).offset(@page * 10) when 'news' @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'News'",@project).order("updated_at desc").limit(10).offset(@page * 10) when 'message' @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Message'",@project).order("updated_at desc").limit(10).offset(@page * 10) + when 'attachment' + @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Attachment'",@project).order("updated_at desc").limit(10).offset(@page * 10) end - - #events = @activity.events(@date_from, @date_to) else @events_pages = ForgeActivity.includes(:project).where("forge_activities.project_id = ? and projects.is_public = ? and forge_act_type != ? ",@project,1, "Document").order("created_at desc") .page(params['page'|| 1]).per(10); - # @events = @activity.events(@date_from, @date_to, :is_public => 1) end - -=begin - @events_pages = Paginator.new events.count, 10, params['page'] - # 总的数据中取出某一页 - events = events.slice(@events_pages.offset,10) - # 按天分组 - @events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)} -=end boards = @project.boards.includes(:last_message => :author).all @topic_count = @project.boards.count # 根据对应的请求,返回对应的数据 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 06b2df862..33b6e8643 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -388,12 +388,12 @@ class UsersController < ApplicationController @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}") end @type = params[:type] - @limit = 15 + @limit = 25 @is_remote = true @hw_count = @homeworks.count @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1 @offset ||= @hw_pages.offset - @homeworks = paginateHelper @homeworks,15 + @homeworks = paginateHelper @homeworks,25 respond_to do |format| format.js format.html {render :layout => 'static_base'} @@ -547,13 +547,13 @@ class UsersController < ApplicationController end @type = params[:type] @property = params[:property] - @limit = 15 + @is_import = params[:is_import] + @limit = params[:is_import].to_i == 1 ? 15 : 25 @is_remote = true @hw_count = @homeworks.count @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1 @offset ||= @hw_pages.offset - @homeworks = paginateHelper @homeworks,15 - @is_import = params[:is_import] + @homeworks = paginateHelper @homeworks,@limit respond_to do |format| format.js end @@ -573,6 +573,7 @@ class UsersController < ApplicationController @r_sort = @b_sort == "desc" ? "asc" : "desc" @user = User.current search = params[:name].to_s.strip.downcase + type_ids = params[:property] ? "(" + params[:property] + ")" : "(1, 2, 3)" if(params[:type].blank? || params[:type] == "1") #全部 visible_course = Course.where("is_public = 1 && is_delete = 0") visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")" @@ -580,24 +581,40 @@ class UsersController < ApplicationController all_user_ids = all_homeworks.map{|hw| hw.user_id} user_str_ids = search_user_by_name all_user_ids, search user_ids = user_str_ids.empty? ? "(-1)" : "(" + user_str_ids.join(",") + ")" - @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%' or user_id in #{user_ids})").order("#{@order} #{@b_sort}") + if @order == "course_name" + sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where homework_type in #{type_ids} and course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%' or homework_commons.user_id in #{user_ids}) order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}" + @homeworks = HomeworkCommon.find_by_sql(sql) + elsif @order == "user_name" + @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and homework_type in #{type_ids} and (name like '%#{search}%' or user_id in #{user_ids})").joins(:user).order("CONVERT (lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, CONVERT (firstname USING gbk) COLLATE gbk_chinese_ci #{@b_sort},login #{@b_sort}") + else + @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and homework_type in #{type_ids} and (name like '%#{search}%' or user_id in #{user_ids})").order("#{@order} #{@b_sort}") + end elsif params[:type] == "2" #课程资源 - @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%')").order("#{@order} #{@b_sort}") + if @order == "course_name" + sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where homework_commons.user_id = #{@user.id} and homework_type in #{type_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%') order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}" + @homeworks = HomeworkCommon.find_by_sql(sql) + elsif @order == "user_name" + @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").joins(:user).order("CONVERT (lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, CONVERT (firstname USING gbk) COLLATE gbk_chinese_ci #{@b_sort},login #{@b_sort}") + else + @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").order("#{@order} #{@b_sort}") + end end +=begin if params[:property] && params[:property] == "1" - @homeworks = @homeworks.where("homework_type = 1").reorder("#{@order} #{@b_sort}") + @homeworks = @homeworks.where("homework_type = 1") elsif params[:property] && params[:property] == "2" - @homeworks = @homeworks.where("homework_type = 2").reorder("#{@order} #{@b_sort}") + @homeworks = @homeworks.where("homework_type = 2") elsif params[:property] && params[:property] == "3" - @homeworks = @homeworks.where("homework_type = 3").reorder("#{@order} #{@b_sort}") + @homeworks = @homeworks.where("homework_type = 3") end +=end @type = params[:type] - @limit = 15 + @limit = params[:is_import].to_i == 1 ? 15 : 25 @is_remote = true @hw_count = @homeworks.count @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1 @offset ||= @hw_pages.offset - @homeworks = paginateHelper @homeworks,15 + @homeworks = paginateHelper @homeworks,@limit @is_import = params[:is_import] @property = params[:property] @search = search diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ca8e0fc28..42911cc33 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1044,9 +1044,9 @@ module ApplicationHelper elsif @organization title << @organization.name elsif @user - title << @user.login + title << @user.try(:realname) else - title << User.current.login + title << User.current.try(:realname) end if first_page.nil? || first_page.web_title.nil? title << Setting.app_title unless Setting.app_title == title.last @@ -2069,7 +2069,7 @@ module ApplicationHelper candown = User.current.member_of?(project) || (project.is_public && attachment_history.is_public == 1) elsif attachment_history.container_type == "OrgSubfield" org = OrgSubfield.find(attachment_history.container_id) - candown = User.current.member_of_org?(org) || (org.organization.is_public && attachment_history.is_public == 1) + candown = User.current.member_of_org?(org) || (org.organization.is_public && attachment_history.is_public == 1 && (User.current.logged? || org.organization.allow_guest_download?)) end end @@ -2943,41 +2943,86 @@ int main(int argc, char** argv){ end def user_url_in_org(user_id) - if Rails.env.development? - return "http://localhost:3000/users/" + user_id.to_s - elsif Rails.env.test? - return "https://www.test.forge.trustie.net/users/" + user_id.to_s - else - return "https://www.trustie.net/users/" + user_id.to_s - end + Setting.protocol + "://" + Setting.host_name + "/users/" + user_id.to_s +end + +def project_issues_url_in_org(project_id) + Setting.protocol + "://" + Setting.host_name + "/projects/" + project_id.to_s + "/issues" +end + +def issue_url_in_org(id) + Setting.protocol + "://" + Setting.host_name + "/issues/" + id.to_s +end + +def project_boards_url_in_org(id) + Setting.protocol + "://" + Setting.host_name + "/projects/" + id.to_s + "/boards" +end + +def board_message_url_in_org(board_id, message_id) + Setting.protocol + "://" + Setting.host_name + "/boards/" + board_id.to_s + "/topics/" + message_id.to_s +end + +def project_url_in_org(id) + Setting.protocol + "://" + Setting.host_name + "/projects/" + id.to_s +end + +def homework_common_index_url_in_org(course_id) + Setting.protocol + "://" + Setting.host_name + "/homework_common?course=" + course_id.to_s +end + +def student_work_index_url_in_org(homework_id) + Setting.protocol + "://" + Setting.host_name + "/student_work?homework=" + homework_id.to_s +end + +def course_url_in_org(course_id) + Setting.protocol + "://" + Setting.host_name + "/courses/" + course_id.to_s +end + +def user_watchlist_url_in_org(id) + Setting.protocol + "://" + Setting.host_name + "/users/" + id.to_s + "/user_watchlist" +end + +def user_fanslist_url_in_org(id) + Setting.protocol + "://" + Setting.host_name + "/users/" + id.to_s + "/user_fanslist" +end + +def user_blogs_url_in_org(user_id) + Setting.protocol + "://" + Setting.host_name + "/users/" + user_id.to_s + "/blogs" +end + +def feedback_url_in_org(user_id) + Setting.protocol + "://" + Setting.host_name + "/users/" + user_id.to_s + "/user_newfeedback" +end + +def user_activities_url_in_org(user_id) + Setting.protocol + "://" + Setting.host_name + "/users/" + user_id.to_s + "/user_activities" +end + +def course_news_index_url_in_org(course_id) + Setting.protocol + "://" + Setting.host_name + "/courses/" + course_id.to_s + "/news" +end + +def news_url_in_org(news_id) + Setting.protocol + "://" + Setting.host_name + "/news/" + news_id.to_s +end + +def course_boards_url_in_org(course_id) + Setting.protocol + "://" + Setting.host_name + "/courses/" + course_id.to_s + "/boards" end def logout_url_without_domain - if Rails.env.development? - return "http://localhost:3000/logout" - elsif Rails.env.test? - return "https://test.forge.trustie.net/logout" - else - return "https://www.trustie.net/logout" - end + Setting.protocol + "://" + Setting.host_name + "/logout" end def signin_url_without_domain - if Rails.env.development? - return "http://localhost:3000/login?login=true" - elsif Rails.env.test? - return "https://test.forge.trustie.net/login?login=true" - else - return "https://www.trustie.net/login?login=true" - end + Setting.protocol + "://" + Setting.host_name + "/login?login=true" end def register_url_without_domain - if Rails.env.development? - return "http://localhost:3000/login?login=false" - elsif Rails.env.test? - return "https://test.forge.trustie.net/login?login=false" - else - return "https://www.trustie.net/login?login=false" - end + Setting.protocol + "://" + Setting.host_name + "/login?login=false" end +#判断是否为默认的组织栏目 +def is_default_field? field + (field.name == 'activity' || field.name == 'course' || field.name == 'project') && field.field_type == 'default' +end + diff --git a/app/helpers/routes_helper.rb b/app/helpers/routes_helper.rb index 15c809964..8d08f22da 100644 --- a/app/helpers/routes_helper.rb +++ b/app/helpers/routes_helper.rb @@ -22,10 +22,18 @@ module RoutesHelper # Returns the path to project issues or to the cross-project # issue list if project is nil def _project_issues_path(project, *args) - if project - project_issues_path(project, *args) + if args[0].to_s.include? '_page' + if args[0].to_s == "user_page" + user_activities_path(args[1].to_i) + else + project_path(project) + end else - issues_path(*args) + if project + project_issues_path(project, *args) + else + issues_path(*args) + end end end diff --git a/app/models/course_activity.rb b/app/models/course_activity.rb index 9c1431d5d..a02eb750c 100644 --- a/app/models/course_activity.rb +++ b/app/models/course_activity.rb @@ -5,7 +5,7 @@ class CourseActivity < ActiveRecord::Base belongs_to :course belongs_to :user has_many :user_acts, :class_name => 'UserAcivity',:as =>:act - after_save :add_user_activity, :add_course_activity + after_save :add_user_activity, :add_org_activity after_create :add_course_lead before_destroy :destroy_user_activity, :destroy_org_activity @@ -31,14 +31,16 @@ class CourseActivity < ActiveRecord::Base end end - def add_course_activity + def add_org_activity org_activity = OrgActivity.where("org_act_type = '#{self.course_act_type.to_s}' and org_act_id = '#{self.course_act_id}'").first if org_activity + org_activity.updated_at = self.updated_at org_activity.save else if self.course_act_type == 'Message' && !self.course_act.parent_id.nil? org_activity = OrgActivity.where("org_act_type = 'Message' and org_act_id = #{self.course_act.parent.id}").first org_activity.created_at = self.created_at + org_activity.updated_at = self.updated_at org_activity.save else OrgActivity.create(:user_id => self.user_id, @@ -66,12 +68,13 @@ class CourseActivity < ActiveRecord::Base # 导语要放置在课程创建信息之后 # 导语 def add_course_lead - if self.course_act_type == "Course" + if self.course_act_type == "Course" and Message.where("id=12440").any? lead_message = Message.find(12440) name = lead_message.subject content = lead_message.content # message的status状态为0为正常,为1表示创建课程时发送的message - message = Message.create(:subject => name, :content => content, :board_id => self.course.boards.first.id, :author_id => self.course.tea_id , :sticky => true, :status => true ) + # author_id 默认为课程使者创建 + message = Message.create(:subject => name, :content => content, :board_id => self.course.boards.first.id, :author_id => 1 , :sticky => true, :status => true ) # 更新的目的是为了排序,因为该条动态的时间可能与课程创建的动态创建时间一直 message.course_acts.first.update_attribute(:updated_at, message.course_acts.first.updated_at + 1) if message.course_acts.first end diff --git a/app/models/forge_activity.rb b/app/models/forge_activity.rb index c98c5475b..c044392a0 100644 --- a/app/models/forge_activity.rb +++ b/app/models/forge_activity.rb @@ -48,7 +48,7 @@ class ForgeActivity < ActiveRecord::Base def add_org_activity org_activity = OrgActivity.where("org_act_type = '#{self.forge_act_type.to_s}' and org_act_id = #{self.forge_act_id}").first if org_activity - org_activity.created_at = self.created_at + org_activity.updated_at = self.updated_at org_activity.save else if self.forge_act_type == 'Message' && !self.forge_act.parent_id.nil? diff --git a/app/models/org_subfield.rb b/app/models/org_subfield.rb index c62cbf4f8..8cec49686 100644 --- a/app/models/org_subfield.rb +++ b/app/models/org_subfield.rb @@ -9,6 +9,7 @@ class OrgSubfield < ActiveRecord::Base has_many :news, :dependent => :destroy acts_as_attachable after_create :create_board_sync + after_destroy :update_priority # 创建资源栏目讨论区 def create_board_sync @board = self.boards.build @@ -25,4 +26,11 @@ class OrgSubfield < ActiveRecord::Base def project end + + def update_priority + OrgSubfield.where("organization_id=? and priority>?", self.organization_id, self.priority).each do |field| + field.decrement(:priority) + field.save + end + end end \ No newline at end of file diff --git a/app/models/organization.rb b/app/models/organization.rb index fcb777fb6..248783a26 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -16,8 +16,8 @@ class Organization < ActiveRecord::Base end def add_default_subfields - OrgSubfield.create(:organization_id => self.id, :name => 'activity', :field_type => 'default') - OrgSubfield.create(:organization_id => self.id, :name => 'course', :field_type => 'default') - OrgSubfield.create(:organization_id => self.id, :name => 'project', :field_type => 'default') + OrgSubfield.create(:organization_id => self.id, :name => 'activity', :field_type => 'default', :priority => 1) + OrgSubfield.create(:organization_id => self.id, :name => 'course', :field_type => 'default', :priority => 2) + OrgSubfield.create(:organization_id => self.id, :name => 'project', :field_type => 'default', :priority => 3) end end diff --git a/app/models/user.rb b/app/models/user.rb index a74c20751..78d823ea7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -116,7 +116,7 @@ class User < Principal has_one :preference, :dependent => :destroy, :class_name => 'UserPreference' has_one :rss_token, :class_name => 'Token', :conditions => "action='feeds'" has_one :blog, :class_name => 'Blog', :foreign_key => "author_id" - has_many :org_document_comments, :dependent =>:destroy + has_many :org_document_comments, :dependent =>:destroy, :foreign_key => "creator_id" has_one :api_token, :class_name => 'Token', :conditions => "action='api'" belongs_to :auth_source has_many :org_members @@ -822,6 +822,9 @@ class User < Principal end def member_of_org?(org) + if !self.logged? + return false + end OrgMember.where("user_id =? and organization_id =?", self.id, org.id).count > 0 end @@ -1064,6 +1067,16 @@ class User < Principal anonymous_user end + # refactor User model find function, + # return anonymous user when can not find user id = user_id + def self.find (*args, &block) + begin + super + rescue + self.anonymous + end + # super + 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/blog_comments/edit.html.erb b/app/views/blog_comments/edit.html.erb index 704342fc0..1e29d0a14 100644 --- a/app/views/blog_comments/edit.html.erb +++ b/app/views/blog_comments/edit.html.erb @@ -1,6 +1,5 @@ -<% if User.current.logged? && User.current.id == @user.id %> - <%= form_for @article, :url =>{:controller=>'blog_comments',:action => 'update',:user_id=>@user.id , :blog_id => @article.id, :is_homepage => params[:is_homepage],:in_act => params[:in_act]},:method=>'PUT', - :html => {:nhname=>'form',:multipart => true, :id => 'message-form'} do |f| %> - <%= render :partial => 'blog_comments/edit', :locals => {:f => f, :article => @article, :edit_mode => true, :user => @user} %> - <% end %> -<% end %> \ No newline at end of file + +<%= form_for @article, :url =>{:controller=>'blog_comments',:action => 'update',:user_id=>@user.id , :blog_id => @article.id, :is_homepage => params[:is_homepage],:in_act => params[:in_act]},:method=>'PUT', + :html => {:nhname=>'form',:multipart => true, :id => 'message-form'} do |f| %> + <%= render :partial => 'blog_comments/edit', :locals => {:f => f, :article => @article, :edit_mode => true, :user => @user} %> +<% end %> diff --git a/app/views/blog_comments/show.html.erb b/app/views/blog_comments/show.html.erb index c80274db4..de7f1647d 100644 --- a/app/views/blog_comments/show.html.erb +++ b/app/views/blog_comments/show.html.erb @@ -38,7 +38,7 @@ <%= link_to image_tag(url_to_avatar(@article.author),:width=>50,:height => 50,:alt=>'图像' ),user_path(@article.author) %>
# <%=time_from_now last_score.created_at %> - <%= link_to last_score.user.show_name, user_activities_path(last_score.user_id), :class => "newsBlue ml5 mr5"%>评阅了作品,优秀排行: + <%= link_to last_score.user.show_name, user_activities_url_in_org(last_score.user_id), :class => "newsBlue ml5 mr5"%>评阅了作品,优秀排行:
分数:<%=format("%.1f",score.to_i<0 ? 0 : score.to_i) %>分
@@ -175,7 +165,7 @@ <% end %> <% end %> <% if student_works.count > 5 %> - <%= link_to "更多>>", student_work_index_path(:homework => activity.id),:class=>'linkGrey2 fl ml50',:style=>'margin-top:60px;'%> + <%= link_to "更多>>", student_work_index_url_in_org(activity.id),:class=>'linkGrey2 fl ml50',:style=>'margin-top:60px;'%> <% end %><%= string %>
- <% end %> - <% end %> -<%= reply.notes.nil? ? "" : reply.notes.html_safe %>
-<%= string %>
+ <% end %> + <% end %> +<%= reply.notes.nil? ? "" : reply.notes.html_safe %>
+