diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 2a772a949..09ca29178 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -23,6 +23,7 @@ class AttachmentsController < ApplicationController before_filter :delete_authorize, :only => [:destroy] before_filter :authorize_global, :only => [:upload] before_filter :authorize_attachment_download1, :only => [:download] + before_filter :has_login #before_filter :login_without_softapplication, only: [:download] accept_api_auth :show, :download, :upload require 'iconv' @@ -67,6 +68,7 @@ class AttachmentsController < ApplicationController end def direct_download + @attachment.increment_download send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), :type => detect_content_type(@attachment), :disposition => 'attachment' #inline can open in browser @@ -77,7 +79,6 @@ class AttachmentsController < ApplicationController # 下载添加权限设置 candown = attachment_candown @attachment if candown || User.current.admin? || User.current.id == @attachment.author_id - @attachment.increment_download if stale?(:etag => @attachment.digest) if params[:preview] == 'true' convered_file = @attachment.diskfile @@ -511,4 +512,8 @@ private format.js end end + + def has_login + render_403 unless User.current.logged? + end end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index f58d6ea24..524bde9d7 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -343,8 +343,8 @@ class CoursesController < ApplicationController def export_course_member_excel @all_members = student_homework_score(0,0,0,"desc") filename="#{@course.teacher.lastname.to_s + @course.teacher.firstname.to_s }_#{@course.name}_#{@course.time.to_s + @course.term}#{l(:excel_member_list)}"; - # 如果是ie11 需要转码 - if(/rv\:11\.0/.match(request.env["HTTP_USER_AGENT"]) != nil) + # 如果是ie 需要转码 + if(/trident/.match(request.env["HTTP_USER_AGENT"]) != nil) filename= URI::encode(filename) end respond_to do |format| @@ -695,21 +695,28 @@ class CoursesController < ApplicationController # 显示老师和助教的活动 # @authors = searchTeacherAndAssistant(@course) @authors = course_all_member(@course) + Dir.glob("#{Rails.root}/app/models/*.rb").sort.each { |file| require file } events = [] - @authors.each do |author| - @activity = Redmine::Activity::Fetcher.new(User.current, :course => @course, - :with_subprojects => false, - :author => author.user) - - @activity.scope_select {|t| has["show_#{t}"]} - # modify by nwb - # 添加私密性判断 - if User.current.member_of_course?(@course)|| User.current.admin? - events += @activity.events(@days, @course.created_at) - else - events += @activity.events(@days, @course.created_at, :is_public => 1) + key = "course_events_#{@course.id}".to_sym + if Rails.env.production? && Setting.course_cahce_enabled? + events = Rails.cache.read(key) || [] + end + if events.empty? + @authors.each do |author| + @activity = Redmine::Activity::Fetcher.new(User.current, :course => @course, + :with_subprojects => false, + :author => author.user) + + @activity.scope_select {|t| has["show_#{t}"]} + # modify by nwb + # 添加私密性判断 + if User.current.member_of_course?(@course)|| User.current.admin? + events += @activity.events(@days, @course.created_at) + else + events += @activity.events(@days, @course.created_at, :is_public => 1) + end end - + Rails.cache.write(key, events) if Rails.env.production? && Setting.course_cahce_enabled? end else # @author = @course.teacher diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 06bc1fd38..d5e62127d 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -3,6 +3,7 @@ class HomeworkCommonController < ApplicationController 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] before_filter :teacher_of_course, :only => [:new, :create, :edit, :update, :destroy, :start_anonymous_comment, :stop_anonymous_comment, :alert_anonymous_comment] + before_filter :member_of_course, :only => [:index] def index homeworks = @course.homework_commons.order("created_at desc") @@ -203,6 +204,11 @@ class HomeworkCommonController < ApplicationController render_403 unless User.current.allowed_to?(:as_teacher,@course) || User.current.admin? end + #当前用户是不是课程的成员 + def member_of_course + render_403 unless 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] diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb index f6e17593f..aa3a7e0ea 100644 --- a/app/controllers/journals_controller.rb +++ b/app/controllers/journals_controller.rb @@ -56,7 +56,7 @@ class JournalsController < ApplicationController @diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value) respond_to do |format| format.html { - render :layout => 'project_base' + render :layout => 'new_base' } end end diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index a222314ab..d8a9d88c3 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -483,6 +483,24 @@ class PollController < ApplicationController count_row += 1 end end + + sheet1.row(count_row).default_format = blue + sheet1[count_row ,0] = l(:label_bidding_user_studentname) + poll_questions.each_with_index do |poll_question, i| + sheet1[count_row ,i + 1] = poll_question.question_title + end + count_row += 1 + @poll.users.each do |user| + sheet1[count_row ,0] = user.show_name + poll_questions.each_with_index do |poll_question, i| + if poll_question.question_type == 1 || poll_question.question_type == 2 + sheet1[count_row ,i + 1] = user.poll_votes.where(:poll_question_id => poll_question.id).map{|poll_vote| poll_vote.poll_answer.answer_text.gsub(/<\/?.*?>/,"").gsub(/ /," ") if poll_vote.poll_answer}.join(";") + else + sheet1[count_row ,i + 1] = user.poll_votes.where(:poll_question_id => poll_question.id).map{|poll_vote| poll_vote.vote_text.gsub(/<\/?.*?>/,"").gsub(/ /," ")}.join(";") + end + end + count_row += 1 + end book.write xls_report xls_report.string end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index efe5a52ee..6ad450315 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -413,10 +413,11 @@ class ProjectsController < ApplicationController # 2、加入项目、创建角色 # 3、用户得分 if params[:mail] - user = User.find(params[:user_id]) + userid = Token.find_by_value(params[:token]).user_id + user = User.find(userid) user.activate! - Member.create(:role_ids => [4], :user_id => params[:user_id],:project_id => params[:id]) - UserGrade.create(:user_id => params[:user_id], :project_id => params[:id]) + Member.create(:role_ids => [4], :user_id => userid, :project_id => params[:id]) + UserGrade.create(:user_id => userid, :project_id => params[:id]) token = Token.get_token_from_user(user, 'autologin') #user = User.try_to_autologin(token.value) if user @@ -456,7 +457,6 @@ class ProjectsController < ApplicationController end end @members = paginateHelper @members - render :layout => 'base_courses' if @project.project_type == 1 end #判断指定用户是否为课程教师 @@ -675,9 +675,9 @@ class ProjectsController < ApplicationController def memberAccess # 是课程,则判断当前用户是否参加了课程 - return 0 if @project.project_type == Project::ProjectType_project - currentUser = User.current - render_403 unless currentUser.member_of?(@project) + # return 0 if @project.project_type == Project::ProjectType_project + # currentUser = User.current + render_403 unless User.current.member_of?(@project) end def toggleCourse diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 30fd0ff50..c8cbde626 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -2,7 +2,7 @@ class StudentWorkController < ApplicationController layout "base_courses" include StudentWorkHelper require 'bigdecimal' - before_filter :find_homework, :only => [:new, :index, :create] + before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty] before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work] before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score, :praise_student_work] before_filter :author_of_work, :only => [:edit, :update, :destroy] @@ -233,6 +233,25 @@ class StudentWorkController < ApplicationController end end + #评价列表显示 + def student_work_absence_penalty + render_403 unless User.current.allowed_to?(:as_teacher,@course) + order = params[:order] || "desc" + work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")" + @stundet_works = StudentWork.find_by_sql("SELECT *,(all_count - has_count) AS absence FROM( + SELECT * , + (SELECT COUNT(*) FROM `student_works_evaluation_distributions` WHERE user_id = student_works.user_id AND student_work_id IN #{work_ids}) AS all_count, + (SELECT COUNT(*) FROM `student_works_scores` WHERE user_id = student_works.user_id AND student_work_id IN #{work_ids}) AS has_count + FROM `student_works` + WHERE homework_common_id = 213 + ) AS table_1 + ORDER BY absence #{order}") + @order = order == "desc" ? "asc" : "desc" + respond_to do |format| + format.html + end + end + private #获取作业 def find_homework diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 20b855fd8..9ce107f8b 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -219,7 +219,7 @@ class WelcomeController < ApplicationController # 判断网站的入口,是课程 course 则跳过index去渲染 course 方法 def entry_select url = request.original_url.gsub('/','') - if url.include?(Setting.host_course.gsub('/','')) + if url.include?(Setting.url_course.gsub('/','')) if @first_page.show_course == 1 course render :course @@ -228,7 +228,7 @@ class WelcomeController < ApplicationController end return 0 - elsif url.include?(Setting.host_contest.gsub('/','')) + elsif url.include?(Setting.url_contest.gsub('/','')) if @first_page.show_contest == 1 contest render :contest @@ -237,7 +237,7 @@ class WelcomeController < ApplicationController end return 0 - elsif url.include?(Setting.host_user.gsub('/','')) + elsif url.include?(Setting.url_user.gsub('/','')) #redirect_to(:controller => "users", :action => "index") end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5ae70fd7c..5af4e2038 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2330,4 +2330,11 @@ module ApplicationHelper def cur_user_works_for_homework homework homework.student_works.where("user_id = ?",User.current).first end + + def file_preview_tag(file, html_options={}) + if %w(pdf pptx doc docx xls xlsx).any?{|x| file.filename.downcase.end_with?(x)} + link_to '预览', download_named_attachment_path(file.id, file.filename, preview: true),html_options + end + end + end diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index aae150728..e4f9a7a81 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -361,15 +361,16 @@ module IssuesHelper end end + # 之所以注释是因为该功能冗余了 if detail.property == 'attr' && detail.prop_key == 'description' s = l(:text_journal_changed_no_detail, :label => label) - unless no_html - diff_link = link_to l(:label_diff), - {:controller => 'journals', :action => 'diff', :id => detail.journal_id, - :detail_id => detail.id, :only_path => options[:only_path]}, - :title => l(:label_view_diff) - s << " (#{ diff_link })" - end + # unless no_html + # diff_link = link_to l(:label_diff), + # {:controller => 'journals', :action => 'diff', :id => detail.journal_id, + # :detail_id => detail.id, :only_path => options[:only_path]}, + # :title => l(:label_view_diff) + # s << " (#{ diff_link })" + # end s.html_safe elsif detail.value.present? case detail.property diff --git a/app/helpers/student_work_helper.rb b/app/helpers/student_work_helper.rb index 990a563c4..7c85dc5c4 100644 --- a/app/helpers/student_work_helper.rb +++ b/app/helpers/student_work_helper.rb @@ -60,4 +60,14 @@ module StudentWorkHelper def is_praise_homework user_id, obj_id PraiseTread.where("user_id = #{user_id} AND praise_tread_object_id = #{obj_id} AND praise_tread_object_type = 'StudentWork'").empty? end + + #获取指定学生在指定作业内应匿评的数量 + def all_evaluation_count user,homework + StudentWorksEvaluationDistribution.joins(:student_work).where("student_works_evaluation_distributions.user_id = #{user.id} AND student_works.homework_common_id = #{homework.id}").count + end + + #获取指定学生在指定作业内已匿评的数量 + def has_evaluation_count user,homework + StudentWorksScore.joins(:student_work).where("student_works_scores.user_id = #{user.id} AND student_works.homework_common_id = #{homework.id}").count + end end \ No newline at end of file diff --git a/app/models/activity.rb b/app/models/activity.rb index e871ae735..5ec778641 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -5,4 +5,6 @@ class Activity < ActiveRecord::Base validates :act_id, presence: true validates :act_type, presence: true validates :user_id, presence: true + + include Trustie::Cache::ClearCourseEvent end diff --git a/app/models/document.rb b/app/models/document.rb index 6bfb4b8ff..37983d6d4 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -85,7 +85,7 @@ class Document < ActiveRecord::Base # Description 新创建的document要在公共表ForgeActivity中记录 def act_as_forge_activity self.forge_acts << ForgeActivity.new(:user_id => self.user_id, - :project_id => self.project_id) + :project_id => self.project_id) end def send_mail diff --git a/app/models/forge_activity.rb b/app/models/forge_activity.rb index e94a29867..6b75552c0 100644 --- a/app/models/forge_activity.rb +++ b/app/models/forge_activity.rb @@ -19,4 +19,5 @@ class ForgeActivity < ActiveRecord::Base validates :project_id,presence: true validates :forge_act_id,presence: true validates :forge_act_type, presence: true + end diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index ac10b2516..291c14563 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -18,7 +18,7 @@ class HomeworkCommon < ActiveRecord::Base :description => :description, :author => :author, :url => Proc.new {|o| {:controller => 'student_work', :action => 'index', :homework => o.id}} - after_create :act_as_activity + after_create :act_as_activity, :send_mail after_destroy :delete_kindeditor_assets def act_as_activity @@ -28,4 +28,9 @@ class HomeworkCommon < ActiveRecord::Base def delete_kindeditor_assets delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::HOMEWORKCOMMON end + + def send_mail + Mailer.run.homework_added(self) + end + end diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 8488fc1d0..d0ee99421 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -61,8 +61,8 @@ class Mailer < ActionMailer::Base InviteList.create(:user_id => user.id, :project_id => project.id) User.current = user unless User.current.nil? @user = user - - @project_url = url_for(:controller => 'projects', :action => 'member', :id => project.id, :user_id => user.id, :mail => true) + @token = Token.get_token_from_user(user, 'autologin') + @project_url = url_for(:controller => 'projects', :action => 'member', :id => project.id, :mail => true, :token => @token.value) mail :to => email, :subject => @subject end @@ -104,9 +104,14 @@ class Mailer < ActionMailer::Base # 查询user的缺陷,项目中成员都能收到 sql = "select DISTINCT * from members m, issues i where i.project_id = m.project_id and m.user_id='#{user.id}' - and (i.created_on between '#{date_from}' and '#{date_to}') order by i.created_on desc" + and (i.updated_on between '#{date_from}' and '#{date_to}') order by i.updated_on desc" @issues = Issue.find_by_sql(sql) + # issue回复 + @issues_journals = Journal.find_by_sql("select j.* from journals j, members m, projects p, issues i + where m.user_id = '#{user.id}' and p.id = m.project_id and i.project_id = p.id and j.journalized_id = i.id + and j.journalized_type='Issue' and (j.created_on between '#{date_from}' and '#{date_to}') order by created_on desc") + # @bids 查询课程作业,包括老师发布的作业,以及user提交作业 # @attachments查询课程课件更新 @attachments ||= [] @@ -122,6 +127,11 @@ class Mailer < ActionMailer::Base end end + + # 项目附件 + @project_attachments = Attachment.find_by_sql("select DISTINCT a.* from members m, attachments a + where a.container_id = m.project_id and m.user_id='#{user.id}' and container_type = 'Project' and (a.created_on between '#{date_from}' and '#{date_to}') order by a.created_on desc") + # user 提交的作业 # @homeworks = HomeworkAttach.where("user_id=#{user.id} and (created_at between '#{date_from}' and '#{date_to}')").order("created_at desc") @@ -155,13 +165,23 @@ class Mailer < ActionMailer::Base end # wiki - # 查询user在课程中发布的通知,项目中发的新闻 + # 查询user在课程中发布的通知和回复通知 @course_news = (course_ids && !course_ids.empty?) ? News.find_by_sql("select DISTINCT n.* from news n where n.course_id in (#{course_ids}) and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") : [] + + @course_news_comments = Comment.find_by_sql("select cm.* from comments cm, members m, courses c, news n + where m.user_id = '#{user.id}' and c.id = m.course_id and n.course_id = c.id and cm.commented_id = n.id + and cm.commented_type ='News' and (cm.created_on between '#{date_from}' and '#{date_to}') order by created_on desc") + + # 查询user在项目中添加新闻和回复新闻 @project_news = (project_ids && !project_ids.empty?) ? News.find_by_sql("select DISTINCT n.* from news n where n.project_id in (#{project_ids}) and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") : [] + @project_news_comments = Comment.find_by_sql("select c.* from comments c, members m, projects p, news n + where m.user_id = '#{user.id}' and p.id = m.project_id and n.project_id = p.id and c.commented_id = n.id + and c.commented_type ='News' and (c.created_on between '#{date_from}' and '#{date_to}') order by created_on desc") + # 查询user在课程及个人中留言 @course_journal_messages = JournalsForMessage.find_by_sql("select DISTINCT jfm.* from journals_for_messages jfm, members m, courses c where m.user_id = '#{user.id}' and c.id = m.course_id and jfm.jour_id = c.id @@ -179,7 +199,7 @@ class Mailer < ActionMailer::Base @memos = Memo.find_by_sql("select DISTINCT m.* from memos m, forums f where (m.author_id = #{user.id} or (m.forum_id = f.id and f.creator_id = #{user.id})) and (m.created_at between '#{date_from}' and '#{date_to}') order by m.created_at desc") - has_content = [@issues,@course_messages,@project_messages,@course_news,@project_news, + has_content = [@issues,@issues_journals,@course_messages,@project_messages,@course_news,@course_news_comments,@project_news,@project_news_comments,@project_attachments, @course_journal_messages,@user_journal_messages,@project_journal_messages,@forums,@memos,@attachments,@bids,@wiki_contents].any? {|o| !o.empty?} mylogger.debug "Sent activity mail : #{user.mail} - #{has_content}" #有内容才发,没有不发 @@ -497,6 +517,26 @@ class Mailer < ActionMailer::Base end end + # Builds a Mail::Message object used to email recipients of a course when an homework are posted. + # + # Example: + # attachments_added(attachments) => Mail::Message object + # Mailer.attachments_added(attachments).deliver => sends an email to the project's recipients + def homework_added(homework_common) + @homework_common = homework_common + @author = homework_common.user + @homework_common_url = url_for(:controller => "homework_common", :action =>"index", :homework => @homework_common.id) + @homework_author_url = url_for(user_activities_url(@author)) + recipients ||= [] + #将帖子创建者邮箱地址加入数组 + @homework_common.course.members.each do |member| + recipients << member.user.mail + end + mail :to => recipients, + :subject => "[ #{l(:label_user_homework)} : #{homework_common.name} #{l(:label_memo_create_succ)}]", + :filter => true + end + # Builds a Mail::Message object used to email recipients of a news' project when a news item is added. # # Example: diff --git a/app/models/member.rb b/app/models/member.rb index 5b1e277d7..057ea9570 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -129,6 +129,16 @@ class Member < ActiveRecord::Base StudentWork.select("homework_commons.name, student_works.final_score").joins(:homework_common).where("student_works.user_id = #{self.user_id} and homework_commons.course_id = #{self.course_id}") end + #当前课程的作业列表 + def homework_common_list + HomeworkCommon.where(:course_id => self.course_id) + end + + #当前学生在指定作业内的得分 + def homework_common_score homework_common + StudentWork.select("final_score").where(:homework_common_id => homework_common.id,:user_id => self.user_id) + end + def student_work_score_avg StudentWork.joins(:homework_common).where("student_works.user_id = #{self.user_id} and homework_commons.course_id = #{self.course_id}").average(:final_score).try(:round, 2).to_f end diff --git a/app/views/attachments/_form.html.erb b/app/views/attachments/_form.html.erb index 845e2b6a0..3dbc8d8ba 100644 --- a/app/views/attachments/_form.html.erb +++ b/app/views/attachments/_form.html.erb @@ -1,11 +1,13 @@ +
<% if defined?(container) && container && container.saved_attachments %> <% container.attachments.each_with_index do |attachment, i| %> - <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly => 'readonly') %> - <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 254, :placeholder => l(:label_optional_description), :class => 'description', :style => "display: inline-block;") %> - <%= l(:field_is_public) %>: + <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly => 'readonly') %><%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 254, :placeholder => l(:label_optional_description), :class => 'description', :style => "display: inline-block;") %><%= l(:field_is_public) %>: <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public, attachment.is_public == 1 ? true : false, :class => 'is_public') %> <%= if attachment.id.nil? #待补充代码 diff --git a/app/views/bids/edit.html.erb b/app/views/bids/edit.html.erb index 37121d720..da3d19267 100644 --- a/app/views/bids/edit.html.erb +++ b/app/views/bids/edit.html.erb @@ -1,4 +1,4 @@ -<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %> <%= labelled_form_for @bid,:html => { :multipart => true } do |f| %> <%= render :partial => 'new_homework_form', :locals => { :bid => @bid, :bid_id => "edit_bid_#{@bid.id}",:f=>f,:edit_mode => true} %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/boards/_course_show.html.erb b/app/views/boards/_course_show.html.erb index 5beee8601..7eed593d9 100644 --- a/app/views/boards/_course_show.html.erb +++ b/app/views/boards/_course_show.html.erb @@ -66,7 +66,31 @@
@@ -92,7 +116,7 @@
-