From b0ccf9037a3997ab40bcb85c95fc69e43cea041a Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 15 Sep 2015 17:39:57 +0800 Subject: [PATCH] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E9=82=80=E8=AF=B7=EF=BC=9A?= =?UTF-8?q?=201=E3=80=81=E4=BF=AE=E6=94=B9=E7=A7=81=E6=9C=89=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E8=B7=B3=E5=85=A5403=E9=97=AE=E9=A2=98=202=E3=80=81?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=90=8C=E4=B8=80=E4=B8=AA=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=8F=8D=E5=A4=8D=E9=82=80=E8=AF=B7=E7=9A=84=E9=82=AE=E7=AE=B1?= =?UTF-8?q?=E6=8F=90=E9=86=92=E3=80=82=203=E3=80=81=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E9=82=AE=E7=AE=B1=E7=9A=84=E5=8F=91=E9=80=81=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 36 ++- app/models/invite_list.rb | 2 +- app/models/mailer.rb | 9 +- app/models/member.rb | 13 + app/models/project.rb | 4 +- app/models/user.rb | 14 +- config/configuration.yml | 8 +- config/locales/zh.yml | 3 +- .../20150915063302_add_mail_to_invite_list.rb | 5 + db/schema.rb | 3 +- public/javascripts/jQuery.autoMail.js | 256 +++++++++--------- 11 files changed, 197 insertions(+), 156 deletions(-) create mode 100644 db/migrate/20150915063302_add_mail_to_invite_list.rb diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 1a8f6a7e2..cdbcc36cb 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 @@ -360,21 +360,27 @@ class ProjectsController < ApplicationController # 两种情况:1、系统外用户;2、系统内用户 (通过邮件判定) def send_mail_to_member # 该邮箱未注册过 - if !params[:mail].blank? && User.find_by_mail(params[:mail].to_s).nil? && User.where("login =?", params[:mail]).first.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) - # 用户名唯一,如果该邮箱被用户作为用户名使用则跳出 - elsif !User.where("login =?", params[:mail]).first.nil? - flash[:error] = l(:notice_email_login_used) - # 已经是系统注册用户 + if !params[:mail].blank? && User.find_by_mail(params[:mail].to_s).nil? + if !User.where("login =?", params[:mail]).first.nil? + # 用户名唯一,如果该邮箱被用户作为用户名使用则跳出 + flash[:error] = l(:notice_email_login_used) + 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) + # 如果已经邀请过该用户,则不重复发送 + 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 @@ -455,6 +461,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' # 判断是否课程 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/mailer.rb b/app/models/mailer.rb index 37a4c9714..c2b66f2a5 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -59,8 +59,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,9 +76,8 @@ 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) 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/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/config/configuration.yml b/config/configuration.yml index af68515eb..5c58c705a 100644 --- a/config/configuration.yml +++ b/config/configuration.yml @@ -224,9 +224,9 @@ development: email_delivery: delivery_method: :smtp smtp_settings: - address: mail.trustie.net + address: smtp.163.com port: 25 - domain: mail.trustie.net + domain: smtp.163.com authentication: :login - user_name: "mail@trustie.net" - password: "loong2010" + user_name: "huang.jingquan@163.com" + password: "xinhu1ji2qu366" diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 3c7aed5b3..19271d93d 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -52,7 +52,8 @@ zh: notice_not_authorized_archived_project: 要访问的项目已经归档。 notice_not_authorized_message: 您访问的消息不存在! notice_email_sent: "邮件已发送至 %{value}" - notice_email_login_used: 该邮箱地址已经有人作为登录名使用! + notice_email_login_used: 无法自动为该邮箱注册新用户,该邮箱地址已经有人作为登录名使用,您可以通过平台的注册功能为该用户注册账号! + notice_email_invited: 已经向该邮箱发送过邀请,正在等待对方的回复! notice_email_error: "发送邮件时发生错误 (%{value})" notice_feeds_access_key_reseted: 您的RSS存取键已被重置。 notice_api_access_key_reseted: 您的API访问键已被重置。 diff --git a/db/migrate/20150915063302_add_mail_to_invite_list.rb b/db/migrate/20150915063302_add_mail_to_invite_list.rb new file mode 100644 index 000000000..800b5abd4 --- /dev/null +++ b/db/migrate/20150915063302_add_mail_to_invite_list.rb @@ -0,0 +1,5 @@ +class AddMailToInviteList < ActiveRecord::Migration + def change + add_column :invite_lists, :mail, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index b162337d3..5eec29135 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150914063751) do +ActiveRecord::Schema.define(:version => 20150915063302) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -685,6 +685,7 @@ ActiveRecord::Schema.define(:version => 20150914063751) do t.integer "user_id" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false + t.string "mail" end create_table "issue_categories", :force => true do |t| diff --git a/public/javascripts/jQuery.autoMail.js b/public/javascripts/jQuery.autoMail.js index bf3519561..949476fcc 100644 --- a/public/javascripts/jQuery.autoMail.js +++ b/public/javascripts/jQuery.autoMail.js @@ -17,137 +17,137 @@ focusColor: "#333" //blurColor: "#999 }; - var settings = $.extend({}, defaults, options || {}); - //页面装载CSS样式 - if(settings.autoClass && $("#mailListAppendCss").size() === 0){ - $('').appendTo($("head")); - } - var cb = settings.boxClass, cl = settings.listClass, cf = settings.focusClass, cm = settings.markCalss; //插件的class变量 - var z = settings.zIndex, newArr = mailArr = settings.mailArr, hint = settings.textHint, text = settings.hintText, fc = settings.focusColor, bc = settings.blurColor; +// var settings = $.extend({}, defaults, options || {}); +// //页面装载CSS样式 +// if(settings.autoClass && $("#mailListAppendCss").size() === 0){ +// $('').appendTo($("head")); +// } +// var cb = settings.boxClass, cl = settings.listClass, cf = settings.focusClass, cm = settings.markCalss; //插件的class变量 +// var z = settings.zIndex, newArr = mailArr = settings.mailArr, hint = settings.textHint, text = settings.hintText, fc = settings.focusColor, bc = settings.blurColor; //创建邮件内部列表内容 - $.createHtml = function(str, arr, cur){ - var mailHtml = ""; - if($.isArray(arr)){ - $.each(arr, function(i, n){ - if(i === cur){ - mailHtml += '
'+str+'@'+arr[i]+'
'; - }else{ - mailHtml += '
'+str+'@'+arr[i]+'
'; - } - }); - } - return mailHtml; - }; +// $.createHtml = function(str, arr, cur){ +// var mailHtml = ""; +// if($.isArray(arr)){ +// $.each(arr, function(i, n){ +// if(i === cur){ +// mailHtml += '
'+str+'@'+arr[i]+'
'; +// }else{ +// mailHtml += '
'+str+'@'+arr[i]+'
'; +// } +// }); +// } +// return mailHtml; +// }; //一些全局变量 var index = -1, s; - $(this).each(function(){ - var that = $(this), i = $(".justForJs").size(); - if(i > 0){ //只绑定一个文本框 - return; - } - var w = that.outerWidth(), h = that.outerHeight(); //获取当前对象(即文本框)的宽高 - //样式的初始化 - that.wrap('') - .before('
'); - var x = $("#mailListBox_" + i), liveValue; //列表框对象 - that.focus(function(){ - //父标签的层级 - $(this).css("color", fc).parent().css("z-index", z); - //提示文字的显示与隐藏 - if(hint && text){ - var focus_v = $.trim($(this).val()); - if(focus_v === text){ - $(this).val(""); - } - } - //键盘事件 - $(this).keyup(function(e){ - s = v = $.trim($(this).val()); - if(/@/.test(v)){ - s = v.replace(/@.*/, ""); - } - if(v.length > 0){ - //如果按键是上下键 - if(e.keyCode === 38){ - //向上 - if(index <= 0){ - index = newArr.length; - } - index--; - }else if(e.keyCode === 40){ - //向下 - if(index >= newArr.length - 1){ - index = -1; - } - index++; - }else if(e.keyCode === 13){ - //回车 - if(index > -1 && index < newArr.length){ - //如果当前有激活列表 - $(this).val($("#mailList_"+index).text()); - } - }else{ - if(/@/.test(v)){ - index = -1; - //获得@后面的值 - //s = v.replace(/@.*/, ""); - //创建新匹配数组 - var site = v.replace(/.*@/, ""); - newArr = $.map(mailArr, function(n){ - var reg = new RegExp(site); - if(reg.test(n)){ - return n; - } - }); - }else{ - newArr = mailArr; - } - } - x.html($.createHtml(s, newArr, index)).css("left", 0); - if(e.keyCode === 13){ - //回车 - if(index > -1 && index < newArr.length){ - //如果当前有激活列表 - x.css("left", "-6000px"); - } - } - }else{ - x.css("left", "-6000px"); - } - }).blur(function(){ - if(hint && text){ - var blur_v = $.trim($(this).val()); - if(blur_v === ""){ - $(this).val(text); - } - } - $(this).css("color", bc).unbind("keyup").parent().css("z-index",0); - x.css("left", "-6000px"); - - }).keydown(function(event){ - if(event.keyCode == 13){ - return false; - } - }); - //鼠标经过列表项事件 - //鼠标经过 - $(".mailHover").on("mouseover", function(){ - index = Number($(this).attr("id").split("_")[1]); - liveValue = $("#mailList_"+index).text(); - x.children("." + cf).removeClass(cf).addClass(cl); - $(this).addClass(cf).removeClass(cl); - }); - $(".mailHover").on("click", function(){ - $("#mail").val($(this).html()); - }); - - - }); - - x.bind("mousedown", function(){ - that.val(liveValue); - }); - }); +// $(this).each(function(){ +// var that = $(this), i = $(".justForJs").size(); +// if(i > 0){ //只绑定一个文本框 +// return; +// } +// var w = that.outerWidth(), h = that.outerHeight(); //获取当前对象(即文本框)的宽高 +// //样式的初始化 +// that.wrap('') +// .before('
'); +// var x = $("#mailListBox_" + i), liveValue; //列表框对象 +// that.focus(function(){ +// //父标签的层级 +// $(this).css("color", fc).parent().css("z-index", z); +// //提示文字的显示与隐藏 +// if(hint && text){ +// var focus_v = $.trim($(this).val()); +// if(focus_v === text){ +// $(this).val(""); +// } +// } +// //键盘事件 +// $(this).keyup(function(e){ +// s = v = $.trim($(this).val()); +// if(/@/.test(v)){ +// s = v.replace(/@.*/, ""); +// } +// if(v.length > 0){ +// //如果按键是上下键 +// if(e.keyCode === 38){ +// //向上 +// if(index <= 0){ +// index = newArr.length; +// } +// index--; +// }else if(e.keyCode === 40){ +// //向下 +// if(index >= newArr.length - 1){ +// index = -1; +// } +// index++; +// }else if(e.keyCode === 13){ +// //回车 +// if(index > -1 && index < newArr.length){ +// //如果当前有激活列表 +// $(this).val($("#mailList_"+index).text()); +// } +// }else{ +// if(/@/.test(v)){ +// index = -1; +// //获得@后面的值 +// //s = v.replace(/@.*/, ""); +// //创建新匹配数组 +// var site = v.replace(/.*@/, ""); +// newArr = $.map(mailArr, function(n){ +// var reg = new RegExp(site); +// if(reg.test(n)){ +// return n; +// } +// }); +// }else{ +// newArr = mailArr; +// } +// } +// x.html($.createHtml(s, newArr, index)).css("left", 0); +// if(e.keyCode === 13){ +// //回车 +// if(index > -1 && index < newArr.length){ +// //如果当前有激活列表 +// x.css("left", "-6000px"); +// } +// } +// }else{ +// x.css("left", "-6000px"); +// } +// }).blur(function(){ +// if(hint && text){ +// var blur_v = $.trim($(this).val()); +// if(blur_v === ""){ +// $(this).val(text); +// } +// } +// $(this).css("color", bc).unbind("keyup").parent().css("z-index",0); +// x.css("left", "-6000px"); +// +// }).keydown(function(event){ +// if(event.keyCode == 13){ +// return false; +// } +// }); +// //鼠标经过列表项事件 +// //鼠标经过 +// $(".mailHover").on("mouseover", function(){ +// index = Number($(this).attr("id").split("_")[1]); +// liveValue = $("#mailList_"+index).text(); +// x.children("." + cf).removeClass(cf).addClass(cl); +// $(this).addClass(cf).removeClass(cl); +// }); +// $(".mailHover").on("click", function(){ +// $("#mail").val($(this).html()); +// }); +// +// +// }); +// +// x.bind("mousedown", function(){ +// that.val(liveValue); +// }); +// }); }; })(jQuery); \ No newline at end of file