diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index a7f1589a6..b30715a1f 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -631,6 +631,11 @@ 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 + if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course))) page = params[:page] # Find the page of the requested reply diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index fa2ce04cf..9d5768948 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -137,6 +137,7 @@ class HomeworkCommonController < ApplicationController def edit @user = User.current + @is_in_course = params[:is_in_course] respond_to do |format| format.html{render :layout => 'new_base_user'} end @@ -173,7 +174,11 @@ class HomeworkCommonController < ApplicationController 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) + if params[:is_in_course] == "1" + redirect_to homework_common_index_path(:course => @course.id) + else + redirect_to user_homeworks_user_path(User.current.id) + end end end end @@ -181,7 +186,13 @@ class HomeworkCommonController < ApplicationController def destroy if @homework.destroy respond_to do |format| - format.html {redirect_to user_homeworks_user_path(User.current.id)} + format.html { + if params[:is_in_course] == "1" + redirect_to homework_common_index_path(:course => @course.id) + else + redirect_to user_homeworks_user_path(User.current.id) + end + } end end end @@ -206,6 +217,9 @@ class HomeworkCommonController < ApplicationController end @homework_detail_manual.update_column('comment_status', 2) @statue = 1 + # 匿评开启消息邮件通知 + send_message_anonymous_comment(@homework, m_status = 2) + Mailer.send_mail_anonymous_comment_open(@homework).deliver else @statue = 2 end @@ -224,12 +238,22 @@ class HomeworkCommonController < ApplicationController 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 respond_to do |format| format.js end end + # 开启/关闭匿评消息通知 + def send_message_anonymous_comment(homework, m_status ) + # status 标记匿评状态 1为关闭 0为开启 + course = @homework.course + course.student.each do |st| + @homework.course_messages << CourseMessage.new(:user_id => st.student_id, :course_id => course.id, :viewed => false, :status => m_status) + end + end #提示 def alert_anonymous_comment @cur_size = 0 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index a58906c67..71b852e01 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -33,7 +33,7 @@ class ProjectsController < ApplicationController before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar] before_filter :file, :statistics #:watcherlist # 除非项目内人员,不可查看成员, TODO: 完了写报表里去 - before_filter :memberAccess, only: :member + # before_filter :memberAccess, only: :member # accept_rss_auth :index accept_api_auth :index, :show, :create, :update, :destroy @@ -358,24 +358,57 @@ class ProjectsController < ApplicationController end + # 项目邀请用户加入实现过程 # 两种情况:1、系统外用户;2、系统内用户 (通过邮件判定) def send_mail_to_member + # 该邮箱未注册过 if !params[:mail].blank? && User.find_by_mail(params[:mail].to_s).nil? - email = params[:mail] - Mailer.run.send_invite_in_project(email, @project, User.current) - @is_zhuce = false - flash[:notice] = l(:notice_email_sent, :value => email) + if !User.where("login =?", params[:mail]).first.nil? + # 用户名唯一,用户修改邮箱,未修改用户名,用户名等同邮箱的情况,默认改用户已经注册 + user = User.find_by_login(params[:mail].to_s) + if !user.member_of?(@project) + # 如果已经邀请过该用户,则不重复发送 + if InviteList.where("project_id =? and mail =?", @project.id, params[:mail].to_s).first.nil? + email = params[:mail] + Mailer.request_member_to_project(email, @project, User.current).deliver + flash[:notice] = l(:notice_email_sent, :value => email) + else + flash[:error] = l(:notice_email_invited) + end + else + flash[:error] = l(:label_member_of_project, :value => email) + end + else + email = params[:mail] + Mailer.send_invite_in_project(email, @project, User.current).deliver + @is_zhuce = false + flash[:notice] = l(:notice_email_sent, :value => email) + end + + # 邮箱地址已被注册 elsif !User.find_by_mail(params[:mail].to_s).nil? user = User.find_by_mail(params[:mail].to_s) if !user.member_of?(@project) - email = params[:mail] - Mailer.run.request_member_to_project(email, @project, User.current) - flash[:notice] = l(:notice_email_sent, :value => email) + # 如果已经邀请过该用户,则不重复发送 + invite_list = InviteList.where("project_id =? and mail =?", @project.id, params[:mail].to_s).first + if invite_list.nil? + email = params[:mail] + Mailer.request_member_to_project(email, @project, User.current).deliver + flash[:notice] = l(:notice_email_sent, :value => email) + else + # 已经发送过了,则隔3小时才能再次发送 + if Time.now - invite_list.created_at > 10800 + email = params[:mail] + Mailer.request_member_to_project(email, @project, User.current).deliver + flash[:notice] = l(:notice_email_sent, :value => email) + else + flash[:error] = l(:notice_email_invited) + end + end else flash[:error] = l(:label_member_of_project, :value => email) end else - flash[:error] = l(:notice_registed_error, :value => email) @is_zhuce = true end respond_to do |format| @@ -383,25 +416,26 @@ class ProjectsController < ApplicationController end end - #发送邮件邀请新用户 + # 发送邮件邀请新用户页面对应方法 def invite_members_by_mail if User.current.member_of?(@project) || User.current.admin? - @inviter_lists = InviteList.where(project_id:@project.id).all - @inviters = [] - @waiters = [] - unless @inviter_lists.blank? - @inviter_lists.each do|inviter_list| - unless inviter_list.user.nil? - if inviter_list.user.member_of?(@project) - @inviters << inviter_list.user - @inviters_count = @inviters.size - else - @waiters << inviter_list.user - @waiters_count = @waiters.size - end - end - end - end + @inviter_lists = InviteList.where(project_id:@project.id).order("created_at desc") + + # @inviters = [] + # @waiters = [] + # unless @inviter_lists.blank? + # @inviter_lists.each do|inviter_list| + # unless inviter_list.user.nil? + # if inviter_list.user.member_of?(@project) + # @inviters << inviter_list.user + # @inviters_count = @inviters.size + # else + # @waiters << inviter_list.user + # @waiters_count = @waiters.size + # end + # end + # end + # end @is_zhuce = false respond_to do |format| format.html @@ -413,16 +447,16 @@ class ProjectsController < ApplicationController end # 邀请Trustie注册用户 - def invite_members - if User.current.member_of?(@project) || User.current.admin? - @member ||= @project.members.new - respond_to do |format| - format.html - end - else - render_403 - end - end + # def invite_members + # if User.current.member_of?(@project) || User.current.admin? + # @member ||= @project.members.new + # respond_to do |format| + # format.html + # end + # else + # render_403 + # end + # end def edit end @@ -430,6 +464,10 @@ class ProjectsController < ApplicationController # by young # include CoursesHelper def member + # 消息"同意加入项目" + if params[:message_id] + message_invite(params[:message_id], params[:key]) + end # params[:login]为邮箱邀请用户加入,主要功能: # 1、自动注册 # 2、加入项目、创建角色 @@ -451,6 +489,10 @@ class ProjectsController < ApplicationController flash[:notice] = l(:label_mail_invite_success) end end + # 私有项目非项目成员无法访问成员列表 + unless @project.is_public? + return render_403 unless User.current.member_of?(@project) + end ## 有角色参数的才是课程,没有的就是项目 @render_file = 'project_member_list' # 判断是否课程 @@ -481,6 +523,14 @@ class ProjectsController < ApplicationController @members = paginateHelper @members end + def message_invite(message_id, key) + forge_message = ForgeMessage.find(message_id) + if key == forge_message.secret_key + Member.create(:role_ids => [4], :user_id => forge_message.user_id, :project_id => forge_message.project_id) + UserGrade.create(:user_id => forge_message.user_id, :project_id => forge_message.project_id) + end + end + #判断指定用户是否为课程教师 def isCourseTeacher(id) result = false diff --git a/app/controllers/system_messages_controller.rb b/app/controllers/system_messages_controller.rb index 42291a407..684378e8a 100644 --- a/app/controllers/system_messages_controller.rb +++ b/app/controllers/system_messages_controller.rb @@ -38,14 +38,15 @@ class SystemMessagesController < ApplicationController return end @system_messages = SystemMessage.new - @system_messages.content = params[:system_message][:content] + @system_messages.description = params[:system_message][:description] + @system_messages.subject = params[:system_message][:subject] @system_messages.user_id = User.current.id respond_to do |format| if @system_messages.save - format.html {redirect_to user_message_path(User.current, :type => "system_messages")} + format.html {redirect_to user_system_messages_path(User.current)} flash[:notice] = l(:notice_successful_message) else - if params[:system_message][:content].empty? + if params[:system_messages][:description].empty? flash[:error] = l(:label_content_blank_fail) else flash[:error] = l(:label_admin_message_fail) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index cb6555768..d3921d44a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -40,7 +40,7 @@ class UsersController < ApplicationController :activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index, :activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource, :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction, - :user_import_homeworks,:user_search_homeworks,:user_import_resource] + :user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages] before_filter :auth_user_extension, only: :show #before_filter :rest_user_score, only: :show #before_filter :select_entry, only: :user_projects @@ -101,18 +101,20 @@ class UsersController < ApplicationController end # 记录当前点击按钮的时间 # 考虑到用户未退出刷新消息页面 - if OnclickTime.where("user_id =?", User.current).first.nil? + message_time = OnclickTime.where("user_id =?", User.current).first + if message_time.nil? message_new_time = OnclickTime.new message_new_time.user_id = User.current.id message_new_time.onclick_time = Time.now message_new_time.save else - message_new_time = OnclickTime.where("user_id =?", User.current).first - message_last_time = message_new_time.onclick_time - message_new_time.update_attributes(:onclick_time => Time.now) + # 24小时内显示 + contrast_time = Time.now - 86400 + message_time.update_attributes(:onclick_time => Time.now) end - @user_system_messages = SystemMessage.where("created_at >?", message_last_time).order("created_at desc") + @user_system_messages = SystemMessage.where("created_at >?", contrast_time).order("created_at desc") # 当前用户查看消息,则设置消息为已读 + # DO 待优化,只需查出符合条件的再更新 if params[:viewed] == "all" course_querys = @user.course_messages forge_querys = @user.forge_messages @@ -142,8 +144,8 @@ class UsersController < ApplicationController @message_alls << message_all.message end end - when 'system_messages' - @message_alls = SystemMessage.order("created_at desc").all + # when 'system_messages' + # @message_alls = SystemMessage.order("created_at desc").all when 'apply' @message_alls = ForgeMessage.where("forge_message_type =? and user_id =?" , "AppliedProject", @user).order("created_at desc") when 'homework' @@ -193,6 +195,15 @@ class UsersController < ApplicationController end end + # 系统消息 + def user_system_messages + @sytem_messages = SystemMessage.order("created_at desc").all + @sytem_messages = paginateHelper @sytem_messages, 10 + respond_to do |format| + format.html{render :layout=>'new_base_user'} + end + end + def user_projects_index if User.current.admin? memberships = @user.memberships.all(conditions: "projects.project_type = #{Project::ProjectType_project}").first @@ -622,12 +633,11 @@ class UsersController < ApplicationController redirect_to signin_url return end - # 更新用户留言消息状态 - @user.journals_for_messages.each do |jour_message| - jour_message.user_feedback_messages.each do |userfeedback_message| - if User.current.id == userfeedback_message.user_id - userfeedback_message.update_attributes(:viewed => true) - end + # 自己访问自己的页面才更新消息状态 + if User.current == @user + journals_messages = UserFeedbackMessage.where("user_id =? and journals_for_message_type =? and viewed =?", User.current.id, "JournalsForMessage", 0) + journals_messages.each do |journals_message| + journals_message.update_attributes(:viewed => true) end end # end diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index 53b40942a..1a01ac97b 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -1,4 +1,4 @@ -require 'zip' +require 'zip' class ZipdownController < ApplicationController #查找项目(课程) before_filter :find_project_by_bid_id, :only => [:assort] @@ -7,7 +7,7 @@ class ZipdownController < ApplicationController SAVE_FOLDER = "#{Rails.root}/files" OUTPUT_FOLDER = "#{Rails.root}/files/archiveZip" - #统一下载功能 + #统一下载功能 def download if User.current.logged? begin diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1982542a9..d7fac9a7d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2368,7 +2368,7 @@ module ApplicationHelper end def student_anonymous_comment homework - if homework.homework_type == 1 && homework.homework_detail_manual + if homework.homework_detail_manual case homework.homework_detail_manual.comment_status when 1 "未开启匿评".html_safe @@ -2377,10 +2377,6 @@ module ApplicationHelper when 3 "匿评已结束".html_safe end - elsif homework.homework_type == 0 - "未启用匿评".html_safe - elsif homework.homework_type == 2 - " 编程作业  ".html_safe end end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index c25035fdb..6a865b203 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -76,6 +76,17 @@ module ProjectsHelper return result end +# 被邀请成员的状态 + def status_for_ivitied(ivite_list, project) + if ivite_list.user.member_of?(project) + value = "已经加入了项目!" + elsif ivite_list.user.active? + value = "邀请已发送,等待用户加入!" + else + value = "邀请已发送,等待用户激活账号!" + end + end + # Added by young def course_settings_tabs tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural, :course=>'1'}, diff --git a/app/helpers/student_work_helper.rb b/app/helpers/student_work_helper.rb index 834b8dd61..e1cf3464e 100644 --- a/app/helpers/student_work_helper.rb +++ b/app/helpers/student_work_helper.rb @@ -6,7 +6,7 @@ module StudentWorkHelper def user_projects_option projects = User.current.projects.visible not_have_project = [] - not_have_project << "没有可选项目,请直接为本作品创建一个项目" + not_have_project << "请选择关联项目" not_have_project << 0 type = [] type << not_have_project diff --git a/app/models/forge_message.rb b/app/models/forge_message.rb index 0c8b3384f..0dce57598 100644 --- a/app/models/forge_message.rb +++ b/app/models/forge_message.rb @@ -8,7 +8,7 @@ class ForgeMessage < ActiveRecord::Base TYPE_OF_WIKI_ACT = "Wiki" TYPE_OF_NEWS_ACT = "News" - attr_accessible :forge_message_id, :forge_message_type, :project_id, :user_id, :viewed + attr_accessible :forge_message_id, :forge_message_type, :project_id, :user_id, :viewed, :secret_key belongs_to :forge_message ,:polymorphic => true belongs_to :project diff --git a/app/models/homework_detail_programing.rb b/app/models/homework_detail_programing.rb index e5938d091..f6286a45e 100644 --- a/app/models/homework_detail_programing.rb +++ b/app/models/homework_detail_programing.rb @@ -4,6 +4,6 @@ class HomeworkDetailPrograming < ActiveRecord::Base belongs_to :homework_common def language_name - %W(c c++).at(self.language.to_i - 1) + %W(C C++).at(self.language.to_i - 1) end end diff --git a/app/models/invite_list.rb b/app/models/invite_list.rb index 4868fc3d7..66efc8609 100644 --- a/app/models/invite_list.rb +++ b/app/models/invite_list.rb @@ -1,5 +1,5 @@ class InviteList < ActiveRecord::Base - attr_accessible :project_id, :user_id + attr_accessible :project_id, :user_id, :mail belongs_to :user belongs_to :project diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index c44b1aeee..81ada2f80 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -190,13 +190,45 @@ class JournalsForMessage < ActiveRecord::Base end end - # 课程作品留言消息通知 + # 课程/作品回复 留言消息通知 def act_as_course_message if self.jour_type == 'StudentWorksScore' if self.user_id != self.jour.user_id self.course_messages << CourseMessage.new(:user_id => self.jour.user_id,:course_id => self.jour.student_work.homework_common.course.id, :viewed => false) end end + # 课程留言 + if self.jour_type == 'Course' + receivers = [] + teachers = [] + # 获取课程的老师 + self.jour.members.each do |m| + if m.user.allowed_to?(:as_teacher, self.jour) + teachers << m + end + end + if self.reply_id == 0 # 主留言,即不是回复某条留言 + teachers.each do |teacher| + if teacher.user_id != self.user_id + receivers << teacher.user_id + end + end + else # 留言回复 + reply_to = User.find(self.reply_id) + if self.user_id != self.reply_id # 添加我回复的那个人 + receivers << reply_to.id + end + # 给老师发送。 过滤条件:老师自己给自己发;回复对象为老师则排除改老师 + teachers.each do |teacher| + if teacher.user_id != self.user_id && self.reply_id != teacher.user_id + receivers << teacher.user_id + end + end + end + receivers.each do |r| + self.course_messages << CourseMessage.new(:user_id => r, :course_id => self.jour.id, :viewed => false) + end + end end # 用户留言消息通知 diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 4fe2478d2..07b2a345c 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -47,10 +47,46 @@ class Mailer < ActionMailer::Base MailerProxy.new(self) end + # 作业匿评开启 + def send_mail_anonymous_comment_open(homework_common) + course = homework_common.course + recipients ||= [] + course.student.each do |student| + user = User.find(student.student_id) + @subject = "#{l(:mail_homework)}#{homework_common.name} #{l(:mail_anonymous_comment_open)}" + @token = Token.get_token_from_user(user, 'autologin') + @anonymous_comment_close_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value)) + @anonymous_comment_close_name = homework_common.name + @author = homework_common.user + #收件人邮箱 + recipients << user.mail + end + mail :to => recipients, + :subject => @subject + end + + # 作业匿评关闭 + def send_mail_anonymous_comment_close(homework_common) + course = homework_common.course + recipients ||= [] + course.student.each do |student| + user = User.find(student.student_id) + @subject = "#{l(:mail_homework)}#{homework_common.name} #{l(:mail_anonymous_comment_open)}" + @token = Token.get_token_from_user(user, 'autologin') + @anonymous_comment_close_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value)) + @anonymous_comment_close_name = homework_common.name + @author = homework_common.user + #收件人邮箱 + recipients << user.mail + end + mail :to => recipients, + :subject => @subject + end + # author: alan - # 发送邀请未注册用户加入项目邮件 + # 邀请未注册用户加入项目 # 功能: 在加入项目的同时自动注册用户 - def send_invite_in_project(email, project, invitor) + def send_invite_in_project(email, project, invitor) @email = email @subject = "#{invitor.name} #{l(:label_invite_project)} #{project.name} " @password = newpass(6) @@ -59,8 +95,8 @@ class Mailer < ActionMailer::Base login = login.sub(/%40/,'@') us = UsersService.new # 自动激活用户 - user = us.register_auto(login, @email, @password) - InviteList.create(:user_id => user.id, :project_id => project.id) + user = us.register_auto(login, email, @password) + InviteList.create(:user_id => user.id, :project_id => project.id, :mail =>email) User.current = user unless User.current.nil? @user = user @token = Token.get_token_from_user(user, 'autologin') @@ -76,15 +112,23 @@ class Mailer < ActionMailer::Base @project_name = "#{project.name}" @user = user @project = project - inviter_lists = InviteList.where(project_id:@project.id, user_id:@user.id).all - if inviter_lists.blank? - InviteList.create(:user_id => user.id, :project_id => project.id) + if InviteList.where("project_id= ? and user_id =? and mail =?", project.id, @user.id, email).first.nil? + InviteList.create(:user_id => user.id, :project_id => project.id, :mail => email) end @token = Token.get_token_from_user(user, 'autologin') @project_url = url_for(:controller => 'projects', :action => 'member', :id => project.id, :user_id => user.id, :mail => true, :token => @token.value) + # 发送消息邀请 + send_message_request_member(user,project) + # end mail :to => email, :subject => @subject end + # 邀请信息消息 注:forge_message_id 为邀请人ID(特殊情况) + def send_message_request_member(user, project) + key = newpass(6).to_s + ForgeMessage.create(:user_id => user.id, :project_id => project.id, :forge_message_type => "ProjectInvite",:forge_message_id => User.current.id, :viewed => false, :secret_key =>key) + end + # author: alan # 根据用户选择发送个人日报或周报 # 发送内容: 项目【缺陷,讨论区,新闻】,课程【通知,留言,新闻】, 贴吧, 个人留言 @@ -208,6 +252,20 @@ class Mailer < ActionMailer::Base mail :to => user.mail,:subject => subject if has_content end + # 作业截止时间邮件提醒 + def homework_endtime__added(homework_common, user_id) + user = User.find(user_id) + @subject = "#{l(:mail_homework)}#{homework_common.name}#{l(:mail_homework_endtime)} " + @token = Token.get_token_from_user(user, 'autologin') + @homework_endtime_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value)) + @homework_endtime_name = homework_common.name + @author = homework_common.user + #收件人邮箱 + recipient = user.mail + mail :to => recipient, + :subject => "#{l(:mail_homework)}#{homework_common.name}#{l(:mail_homework_endtime)} " + end + # 公共讨论区发帖、回帖添加邮件发送信息 def forum_message_added(memo) @memo = memo diff --git a/app/models/member.rb b/app/models/member.rb index 292dd2034..655c79895 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -30,6 +30,9 @@ class Member < ActiveRecord::Base validate :validate_role before_destroy :set_issue_category_nil + # 删除项目成员一并删除该成员的邀请记录 + after_destroy :delete_ivite_list + def role end @@ -97,6 +100,16 @@ class Member < ActiveRecord::Base end end + # 删除成员一并删除该成员的邀请信息 + def delete_ivite_list + member_invite_lists = InviteList.where("user_id =? and project_id =?", self.user_id, self.project_id) + unless member_invite_lists.nil? + member_invite_lists.each do |member_invite_list| + member_invite_list.destroy + end + end + end + # Find or initilize a Member with an id, attributes, and for a Principal def self.edit_membership(id, new_attributes, principal=nil) @membership = id.present? ? Member.find(id) : Member.new(:principal => principal) diff --git a/app/models/project.rb b/app/models/project.rb index 0618dd145..0cd6af35b 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -66,8 +66,8 @@ class Project < ActiveRecord::Base # has_many :students_for_courses, :dependent => :destroy has_many :student, :through => :students_for_courses, :source => :user has_one :course_extra, :class_name => 'Course', :foreign_key => :extra,:primary_key => :identifier, :dependent => :destroy - has_many :applied_projects - has_many :invite_lists + has_many :applied_projects, :dependent => :destroy + has_many :invite_lists, :dependent => :destroy has_one :dts # end diff --git a/app/models/student_work.rb b/app/models/student_work.rb index a6d641c0c..cd4d81a32 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -31,9 +31,8 @@ class StudentWork < ActiveRecord::Base else self.system_score = last_test.test_score end - set_final_score self.homework_common,self end - + set_final_score self.homework_common,self end def set_src self.description = last_test.src if last_test diff --git a/app/models/system_message.rb b/app/models/system_message.rb index 92a989cb3..2a810e8b8 100644 --- a/app/models/system_message.rb +++ b/app/models/system_message.rb @@ -1,7 +1,8 @@ class SystemMessage < ActiveRecord::Base - attr_accessible :content, :id, :user_id + attr_accessible :content, :id, :user_id, :description, :subject belongs_to :user - validates :content, presence: true - validates_length_of :content, maximum: 255 + validates :subject, presence: true + # validates :description, presence: true + validates_length_of :description, maximum: 10000 end diff --git a/app/models/user.rb b/app/models/user.rb index 63811cd58..48b269e6e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -140,7 +140,7 @@ class User < Principal has_many :issue_assigns, :class_name => 'ForgeMessage', :conditions => 'viewed=0 and forge_message_type="Issue"' has_many :status_updates, :class_name => 'ForgeMessage', :conditions => 'viewed=0 and forge_message_type="Journal"' # 邮件邀请状态 - # has_many :invite_lists + has_many :invite_lists, :dependent => :destroy # end ######added by nie @@ -213,6 +213,8 @@ class User < Principal # added by fq after_create :act_as_activity, :add_onclick_time # end + # 更新邮箱用户或用户名的同事,同步更新邀请信息 + after_update :update_invite_list scope :in_group, lambda {|group| group_id = group.is_a?(Group) ? group.id : group.to_i @@ -1010,6 +1012,16 @@ class User < Principal end end + # 更新邮箱的同事,更新invite_lists表中的邮箱信息 + def update_invite_list + invite_lists = InviteList.where("user_id =?",self.id).all + unless invite_lists.blank? + invite_lists.each do |invite_list| + invite_list.update_attribute(:mail, self.mail) + end + end + end + # Removes references that are not handled by associations # Things that are not deleted are reassociated with the anonymous user def remove_references_before_destroy diff --git a/app/views/admin/messages.html.erb b/app/views/admin/messages.html.erb index 1d9f0cc10..f87741dd9 100644 --- a/app/views/admin/messages.html.erb +++ b/app/views/admin/messages.html.erb @@ -3,11 +3,17 @@ <%=l(:label_system_message)%>
- <%= form_for(@admin_messages, :html => {:id =>'system_message-form'}) do |f| %> -
- <%= f.kindeditor :content,:width=>'87%',:editor_id=>'system_message_editor' %> + <%= form_for(@admin_messages, :html => {:id =>'system_messages-form'}) do |f| %> +
  • + + +

    +
  • +
  • + + <%= f.kindeditor :description,:width=>'87.5%',:editor_id=>'system_message_editor' %>

    -
  • +

    @@ -19,14 +25,8 @@ diff --git a/app/views/homework_common/edit.html.erb b/app/views/homework_common/edit.html.erb index d6815a00a..5fc11728b 100644 --- a/app/views/homework_common/edit.html.erb +++ b/app/views/homework_common/edit.html.erb @@ -16,6 +16,7 @@
    <%= form_for @homework do |f| %> +
    <%= render :partial => 'users/user_homework_form', :locals => { :homework => @homework,:f => f,:edit_mode => true } %>
    diff --git a/app/views/homework_common/index.html.erb b/app/views/homework_common/index.html.erb index d7723452b..693ddba65 100644 --- a/app/views/homework_common/index.html.erb +++ b/app/views/homework_common/index.html.erb @@ -26,8 +26,8 @@

    <% if @is_teacher%> <%= homework_anonymous_comment(homework)%> - <%= link_to(l(:label_bid_respond_delete), homework_common_path(homework),:method => 'delete', :confirm => l(:text_are_you_sure), :class => "fr mr10 work_edit") %> - <%= link_to(l(:button_edit),edit_homework_common_path(homework), :class => "fr mr10 work_edit") %> + <%= link_to(l(:label_bid_respond_delete), homework_common_path(homework,:is_in_course => 1),:method => 'delete', :confirm => l(:text_are_you_sure), :class => "fr mr10 work_edit") %> + <%= link_to(l(:button_edit),edit_homework_common_path(homework,:is_in_course => 1), :class => "fr mr10 work_edit") %> <% elsif @is_student%> <%= student_anonymous_comment homework %> <%= student_new_homework homework %> diff --git a/app/views/journals/diff.html.erb b/app/views/journals/diff.html.erb index 190459b71..b842d87d0 100644 --- a/app/views/journals/diff.html.erb +++ b/app/views/journals/diff.html.erb @@ -1,8 +1,8 @@

    <%=h @issue.tracker %> #<%= @issue.id %>

    由<%= @journal.user %> 更新于 <%= format_time @journal.created_on %>

    -
    - <%= simple_format_without_paragraph @diff.to_html %> +
    + <%= @diff.to_html.gsub("<","<").gsub(">",">").gsub(""","\"").gsub("&gt;", ">").gsub("&lt;", "<").gsub("&quot;", "\"").html_safe %>

    <%= link_to l(:button_back), issue_path(@issue), :onclick => 'history.back(); return false;' %>

    diff --git a/app/views/layouts/base_projects.html.erb b/app/views/layouts/base_projects.html.erb index 2bcb7f9ef..b7b88c186 100644 --- a/app/views/layouts/base_projects.html.erb +++ b/app/views/layouts/base_projects.html.erb @@ -36,21 +36,6 @@ <%#= render :partial => 'layouts/new_header'%>
    - -
    -
    -

    - - <%= l(:label_projects_community) %> - -

    - -
    -
    -
    @@ -113,9 +98,9 @@
    <% end %> diff --git a/app/views/mailer/homework_endtime__added.html.erb b/app/views/mailer/homework_endtime__added.html.erb new file mode 100644 index 000000000..e639ab51a --- /dev/null +++ b/app/views/mailer/homework_endtime__added.html.erb @@ -0,0 +1,11 @@ +
    +
      +
    • <%= l(:mail_issue_content)%> + +

      <%=link_to @author, user_url(@author) %> 发布的作业:<%=link_to @homework_endtime_name, @homework_endtime_url%> 截止时间快到了!

      +

      如果您还未交作业,请赶紧提交作业!

      +
      +
    • +
    +
    +
    \ No newline at end of file diff --git a/app/views/mailer/homework_endtime__added.text.erb b/app/views/mailer/homework_endtime__added.text.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/mailer/request_member_to_project.html.erb b/app/views/mailer/request_member_to_project.html.erb index 7c0d25dbb..c2da231a3 100644 --- a/app/views/mailer/request_member_to_project.html.erb +++ b/app/views/mailer/request_member_to_project.html.erb @@ -4,9 +4,9 @@
  • <%= l(:mail_issue_content)%> -

    <%= @invitor_name %> 邀请您加入项目:<%= @project_name %>

    +

    <%= @invitor_name %> 邀请您加入项目:<%=link_to @project_name, project_url(@project) %>

    -

    点击“同意加入”按钮,即可快速加入项目!


    +

    点击“同意加入”按钮,即可快速加入项目,查看项目相关信息!


    diff --git a/app/views/mailer/send_invite_in_project.html.erb b/app/views/mailer/send_invite_in_project.html.erb index ec559732f..54435e9ef 100644 --- a/app/views/mailer/send_invite_in_project.html.erb +++ b/app/views/mailer/send_invite_in_project.html.erb @@ -1,7 +1,5 @@ -
      -
    • <%= l(:mail_issue_content)%>

      <%= @subject %>

      @@ -9,13 +7,9 @@

      <%= link_to @project_url, @project_url%>

      您的账号为:<%= @email %>

      密码为: <%= @password %>

      - +

      为了您的账号安全,请勿将邮件信息告知他人!

    • -
    -
    -
    - - +
  • \ No newline at end of file diff --git a/app/views/mailer/send_mail_anonymous_comment_close.html.erb b/app/views/mailer/send_mail_anonymous_comment_close.html.erb new file mode 100644 index 000000000..128f9fae8 --- /dev/null +++ b/app/views/mailer/send_mail_anonymous_comment_close.html.erb @@ -0,0 +1,10 @@ +
    +
      +
    • <%= l(:mail_issue_content)%> + +

      <%=link_to @author, user_url(@author) %> 发布的作业:<%=link_to @anonymous_comment_close_name, @anonymous_comment_close_url%> 已经关闭了匿评!

      +
      +
    • +
    +
    +
    \ No newline at end of file diff --git a/app/views/mailer/send_mail_anonymous_comment_close.text.erb b/app/views/mailer/send_mail_anonymous_comment_close.text.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/mailer/send_mail_anonymous_comment_open.html.erb b/app/views/mailer/send_mail_anonymous_comment_open.html.erb new file mode 100644 index 000000000..5409ade55 --- /dev/null +++ b/app/views/mailer/send_mail_anonymous_comment_open.html.erb @@ -0,0 +1,10 @@ +
    +
      +
    • <%= l(:mail_issue_content)%> + +

      <%=link_to @author, user_url(@author) %> 发布的作业:<%=link_to @anonymous_comment_close_name, @anonymous_comment_close_url%> 已经开启匿评了!

      +
      +
    • +
    +
    +
    \ No newline at end of file diff --git a/app/views/mailer/send_mail_anonymous_comment_open.text.erb b/app/views/mailer/send_mail_anonymous_comment_open.text.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/news/_project_news.html.erb b/app/views/news/_project_news.html.erb index 04fdb6dac..0cd26382b 100644 --- a/app/views/news/_project_news.html.erb +++ b/app/views/news/_project_news.html.erb @@ -1,3 +1,9 @@ + <% btn_tips = l(:label_news_new) label_tips = l(:label_news) diff --git a/app/views/projects/invite_members_by_mail.html.erb b/app/views/projects/invite_members_by_mail.html.erb index 8c951a485..44c571422 100644 --- a/app/views/projects/invite_members_by_mail.html.erb +++ b/app/views/projects/invite_members_by_mail.html.erb @@ -31,9 +31,9 @@ $("#valid_email").text("<%= l(:label_email_format_error)%>"); return false; } - else if(email.split('@')[0].length >= 20) + else if(email.length > 25) { - $("#valid_email").text("邮箱名过长,最长为20个字符"); + $("#valid_email").text("邮箱名过长,最长为25个字符"); return false; } else @@ -85,7 +85,39 @@ <%= l(:label_send_email)%> <% end %> + <%# 邀请用户的状态 %> + <% unless @inviter_lists.blank? %> +
    +
    +
    项目成员邀请状态列表
    +
    +
    + <% @inviter_lists.each do |inviter_list| %> + + + <% if inviter_list.user != nil %> + + + + + + + <% end %> + +
    + <% if inviter_list.user.active? %> + <%=link_to inviter_list.user.name, user_path(inviter_list.user), :class => "c_eblue" %> + <% else %> + <%= inviter_list.user.name %> + <% end %> + <%= status_for_ivitied(inviter_list, @project) %>
    + <% end %> +
    +
    + <% end %> + + <% unless @inviter_lists.blank? %>
    <% unless @inviters_count.nil? %> diff --git a/app/views/student_work/_evaluation_un_work.html.erb b/app/views/student_work/_evaluation_un_work.html.erb index caaaa2775..d3bac240d 100644 --- a/app/views/student_work/_evaluation_un_work.html.erb +++ b/app/views/student_work/_evaluation_un_work.html.erb @@ -57,7 +57,7 @@ - <% score = student_work.respond_to?("score") ? student_work.score : student_work.final_score - student_work.absence_penalty - student_work.late_penalty%> + <% score = student_work.respond_to?("score") ? student_work.score : (student_work.final_score || 0) - student_work.absence_penalty - student_work.late_penalty%>
  • <%= score.nil? ? "--" : format("%.1f",score)%> <% unless score.nil?%> diff --git a/app/views/student_work/index.html.erb b/app/views/student_work/index.html.erb index db704a7de..5398b7084 100644 --- a/app/views/student_work/index.html.erb +++ b/app/views/student_work/index.html.erb @@ -87,13 +87,13 @@
    - <%= link_to "所有作品[共#{@homework.student_works.count}份]".html_safe,student_work_index_path(:homework => @homework.id),:class => "fl f14"%> + <%= link_to "所有作品[共#{@stundet_works.count}份]".html_safe,student_work_index_path(:homework => @homework.id),:class => "fl f14"%> <%if @is_teacher || @homework.homework_detail_manual.comment_status == 3%> -
    - +
    + - +
    <% end%>
    diff --git a/app/views/users/_course_homework.html.erb b/app/views/users/_course_homework.html.erb index 58b29696c..5ba83401c 100644 --- a/app/views/users/_course_homework.html.erb +++ b/app/views/users/_course_homework.html.erb @@ -12,13 +12,38 @@ <% end %> TO <%= link_to activity.course.name.to_s+" | 课程作业", homework_common_index_path(:course => activity.course.id, :host=> Setting.host_course), :class => "newsBlue ml15"%>
    -
    + + <% if activity.homework_detail_manual.comment_status == 1%> + 未开启匿评 + <% elsif activity.homework_detail_manual.comment_status == 2%> + 匿评中 + <% elsif activity.homework_detail_manual.comment_status == 3%> + 匿评已结束 + <% end%>
    - <%= student_work_activity_submit_status(homework: activity) %> + <% is_teacher = User.current.allowed_to?(:as_teacher,activity.course) %> + <%= user_for_homework_common activity,is_teacher %>
    + + <% if activity.homework_type == 2 && is_teacher%> +
    + <%= link_to "模拟答题", new_user_commit_homework_users_path(homework_id: activity.id, is_test: true), class: 'c_blue test-program-btn', title: '教师可以通过模拟答题设置作业的标准答案' %> +
    + <% end %> + <% if activity.homework_type == 2%> +
    + 语言: + <% if activity.homework_detail_programing.language.to_i == 1%> + C + <% elsif activity.homework_detail_programing.language.to_i == 2%> + C++ + <% end%> +
    + <% end %> +
    截止时间:<%= activity.end_time.to_s %>
    diff --git a/app/views/users/_user_homework_list.html.erb b/app/views/users/_user_homework_list.html.erb index c6e827291..e7addad97 100644 --- a/app/views/users/_user_homework_list.html.erb +++ b/app/views/users/_user_homework_list.html.erb @@ -59,10 +59,10 @@
    • - <%= link_to l(:button_edit),edit_homework_common_path(homework_common), :class => "postOptionLink"%> + <%= link_to l(:button_edit),edit_homework_common_path(homework_common,:is_in_course => 0), :class => "postOptionLink"%>
    • - <%= link_to(l(:label_bid_respond_delete), homework_common_path(homework_common),:method => 'delete', :confirm => l(:text_are_you_sure), :class => "postOptionLink") %> + <%= link_to(l(:label_bid_respond_delete), homework_common_path(homework_common,:is_in_course => 0),:method => 'delete', :confirm => l(:text_are_you_sure), :class => "postOptionLink") %>
    • <%= homework_anonymous_comment homework_common %> diff --git a/app/views/users/_user_programing_attr.html.erb b/app/views/users/_user_programing_attr.html.erb index 0bfbd379f..498005010 100644 --- a/app/views/users/_user_programing_attr.html.erb +++ b/app/views/users/_user_programing_attr.html.erb @@ -29,7 +29,7 @@ <% end %>
      - 温馨提示:您可以在发布作业后,在作业“模拟答题”中进行标准代码的检测和提交。 + 温馨提示:您可以在发布作业后,在作业“模拟答题”中进行标准代码的检测。 确  定
      diff --git a/app/views/users/user_messages.html.erb b/app/views/users/user_messages.html.erb index a184a6d7e..a5cc70f99 100644 --- a/app/views/users/user_messages.html.erb +++ b/app/views/users/user_messages.html.erb @@ -1,38 +1,38 @@
      -
      <%= title_for_message(params[:type]) %>
      -
        -
      • -
          -
        • <%= link_to "全部",user_message_path(User.current), :class => "resourcesGrey" %>
        • -
        • <%= link_to "未读消息", user_message_path(User.current, :type => 'unviewed'), :class => "resourcesGrey" %>
        • -
        • <%= link_to "用户申请", user_message_path(User.current, :type => 'apply'), :class => "resourcesGrey" %>
        • - <%# 课程相关消息 %> -
        • <%= link_to "作业消息", user_message_path(User.current, :type => 'homework'), :class => "resourcesGrey" %>
        • -
        • <%= link_to "课程讨论",user_message_path(User.current, :type => 'course_message'), :class => "resourcesGrey" %>
        • -
        • <%= link_to "课程通知",user_message_path(User.current, :type => 'course_news'), :class => "resourcesGrey" %>
        • - - - - - <%# 项目相关消息 %> -
        • <%= link_to "项目任务", user_message_path(User.current, :type => 'issue'), :class => "resourcesGrey" %>
        • - - - - - <%# 项目相关消息 %> -
        • <%= link_to "贴吧帖子", user_message_path(User.current, :type => 'forum'), :class => "resourcesGrey" %>
        • - <%# 系统贴吧 %> -
        • <%= link_to "用户留言",user_message_path(User.current, :type => 'user_feedback'), :class => "resourcesGrey" %>
        • - <%# 系统消息 %> -
        • <%= link_to "系统消息", user_message_path(User.current, :type => 'system_messages'), :class => "resourcesGrey" %>
        • -
        -
      • -
      -
      +
      <%= title_for_message(params[:type]) %>
      +
        +
      • +
          +
        • <%= link_to "全部",user_message_path(User.current), :class => "resourcesGrey" %>
        • +
        • <%= link_to "未读消息", user_message_path(User.current, :type => 'unviewed'), :class => "resourcesGrey" %>
        • +
        • <%= link_to "用户申请", user_message_path(User.current, :type => 'apply'), :class => "resourcesGrey" %>
        • + <%# 课程相关消息 %> +
        • <%= link_to "作业消息", user_message_path(User.current, :type => 'homework'), :class => "resourcesGrey" %>
        • +
        • <%= link_to "课程讨论",user_message_path(User.current, :type => 'course_message'), :class => "resourcesGrey" %>
        • +
        • <%= link_to "课程通知",user_message_path(User.current, :type => 'course_news'), :class => "resourcesGrey" %>
        • + + + + + <%# 项目相关消息 %> +
        • <%= link_to "项目任务", user_message_path(User.current, :type => 'issue'), :class => "resourcesGrey" %>
        • + + + + + <%# 项目相关消息 %> +
        • <%= link_to "贴吧帖子", user_message_path(User.current, :type => 'forum'), :class => "resourcesGrey" %>
        • + <%# 系统贴吧 %> +
        • <%= link_to "用户留言",user_message_path(User.current, :type => 'user_feedback'), :class => "resourcesGrey" %>
        • + <%# 系统消息 %> +
        • <%= link_to "系统消息", user_system_messages_path(User.current), :class => "resourcesGrey" %>
        • +
        +
      • +
      +
  • -<% if @message_alls.count >0 %> +<% if @message_alls.count >0 || @user_system_messages.count >0 %> <% if params[:type].nil? || params[:type] == "unviewed" %>
    有 <%= unviewed_message(@user) %> 条未读 @@ -42,36 +42,42 @@
    <% end %> <%# 系统消息 %> - <% if params[:type] != 'system_messages' %> - <% @user_system_messages.each do |usm| %> - - <% end %> - <% end %> - <%# 课程消息 %> + <% if params[:type] != 'system_messages' %> + <% @user_system_messages.each do |usm| %> +
      +
    • + +
    • +
    • + Trustie平台发布新消息: +
    • + 【系统消息】
    • +
    • + + <%= link_to usm.subject.nil? ? (usm.content.nil? ? usm.description.html_safe : usm.content.html_safe) : usm.subject, user_system_messages_path(User.current), + :id => "content_link_#{usm.id}", + :onmouseover =>"message_titile_show($(this),event);", + :onmouseout => "message_titile_hide($(this));" + %> +
    • + +
    • <%= time_tag(usm.created_at).html_safe %>
    • +
    + <% end %> + <% end %> + <% unless @message_alls.nil? %> <% @message_alls.each do |ma| %> + <%# 课程消息 %> <% if ma.class == CourseMessage %> <% if ma.course_message_type == "News" %>
      @@ -80,7 +86,15 @@
    • <%= link_to ma.course_message.title, {:controller => 'news', :action => 'show', :id => ma.course_message.id }, :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", - :title => "#{ma.course_message.title}" %>
    • + :onmouseover =>"message_titile_show($(this),event)", + :onmouseout => "message_titile_hide($(this))" %> +
    • <%= time_tag(ma.created_at).html_safe %>
    <% end %> @@ -93,18 +107,32 @@ :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", :onmouseover =>"message_titile_show($(this),event)", :onmouseout => "message_titile_hide($(this))" %> -