From 8384eff7f2ca9992df4f41c8ba0e045bfd05b622 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Wed, 29 Apr 2015 23:17:24 +0800 Subject: [PATCH 1/5] =?UTF-8?q?delayed=5Fjob=E6=9D=A1=E4=BB=B6=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/mailer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/mailer.rb b/app/models/mailer.rb index a930b5467..d0a928bfa 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -33,7 +33,7 @@ class Mailer < ActionMailer::Base @target = cls end def method_missing(name, *args, &block) - if Setting.delayjob_enabled && Object.const_defined?('Delayed') + if Setting.delayjob_enabled? && Object.const_defined?('Delayed') @target.delay.send(name, *args, &block) else @target.send(name, *args, &block).deliver From dbccf9034dc839da1540d305b0f995146f2d4f55 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Thu, 30 Apr 2015 10:31:06 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/mailer.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/models/mailer.rb b/app/models/mailer.rb index d0a928bfa..7ccee1932 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -143,7 +143,7 @@ class Mailer < ActionMailer::Base @course_journal_messages,@user_journal_messages,@forums,@memos,@attachments,@bids].any? {|o| !o.empty? } - binding.pry if Rails.env.development? + mylogger.debug "Sent activity mail : #{user.mail} - #{has_content}" #有内容才发,没有不发 mail :to => user.mail,:subject => subject if has_content end @@ -818,11 +818,12 @@ class Mailer < ActionMailer::Base end set_language_if_valid @initial_language - super headers do |format| + m = super headers do |format| format.text format.html unless Setting.plain_text_mail? end - + mylogger.debug "Sent a mail from #{m.from} to [#{m.to},#{m.cc}, #{m.bcc if Setting.bcc_recipients?}] subject: #{m.subject}" + m end def initialize(*args) @@ -877,7 +878,11 @@ class Mailer < ActionMailer::Base end def mylogger - Rails.logger + if Setting.delayjob_enabled? + Delayed::Worker.logger + else + Rails.logger + end end def add_attachments(obj) From 119e540373f154b7c9adad3498d005ff5ba2293d Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 30 Apr 2015 11:08:36 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E9=82=80=E8=AF=B7?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E5=B7=B2=E6=B3=A8=E5=86=8C=E7=9A=84=E7=94=A8?= =?UTF-8?q?=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 11 ++++++++++ app/models/mailer.rb | 12 ++++++++++ .../mailer/request_member_to_project.html.erb | 22 +++++++++++++++++++ .../mailer/request_member_to_project.text.erb | 3 +++ config/locales/projects/zh.yml | 4 +++- 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 app/views/mailer/request_member_to_project.html.erb create mode 100644 app/views/mailer/request_member_to_project.text.erb diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 76e136216..2b58f1265 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -344,12 +344,22 @@ 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) + 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) + else + flash[:error] = l(:label_member_of_project, :value => email) + end else flash[:error] = l(:notice_registed_error, :value => email) @is_zhuce = true @@ -358,6 +368,7 @@ class ProjectsController < ApplicationController format.html{redirect_to invite_members_by_mail_project_url(@project)} end end + #发送邮件邀请新用户 def invite_members_by_mail if User.current.member_of?(@project) || User.current.admin? diff --git a/app/models/mailer.rb b/app/models/mailer.rb index e67d042e1..d35374fcf 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -69,6 +69,18 @@ class Mailer < ActionMailer::Base mail :to => email, :subject => @subject end + # 邀请已注册的用户加入项目 + def request_member_to_project(email, project, invitor) + user = User.find_by_mail(email.to_s) + Member.create(:role_ids => [4], :user_id => user.id,:project_id => project.id) + @invitor_name = "#{invitor.name}" + @project_name = "#{project.name}" + @user = user + @token = Token.get_token_from_user(user, 'autologin') + @project_url = url_for(:controller => 'projects', :action => 'show', :id => project.id,:user => user, :token => @token.value) + mail :to => email, :invitor_name => "#{@invitor_name}", :project_name => "#{@project_name}" + end + # author: alan # 根据用户选择发送个人日报或周报 # 发送内容: 项目【缺陷,讨论区,新闻】,课程【通知,留言,新闻】, 贴吧, 个人留言 diff --git a/app/views/mailer/request_member_to_project.html.erb b/app/views/mailer/request_member_to_project.html.erb new file mode 100644 index 000000000..7c0d25dbb --- /dev/null +++ b/app/views/mailer/request_member_to_project.html.erb @@ -0,0 +1,22 @@ + +
+ + +
+
+ + diff --git a/app/views/mailer/request_member_to_project.text.erb b/app/views/mailer/request_member_to_project.text.erb new file mode 100644 index 000000000..ef2f5d130 --- /dev/null +++ b/app/views/mailer/request_member_to_project.text.erb @@ -0,0 +1,3 @@ +<%= @invitor_name %> +<%= @project_name %> +<%= link_to( l(:label_apply_project), @project_url) %> \ No newline at end of file diff --git a/config/locales/projects/zh.yml b/config/locales/projects/zh.yml index 3b125181e..e371296a5 100644 --- a/config/locales/projects/zh.yml +++ b/config/locales/projects/zh.yml @@ -48,11 +48,13 @@ zh: # 左边栏 # label_project_id: "项目ID:" - + + label_agree_join_project: 同意加入 label_apply_project: "+申请加入" label_button_following: "+添加关注" label_exit_project: 退出项目 label_apply_project_waiting: 已处理申请,请等待管理员审核 + label_member_of_project: 该用户已经是项目成员了! label_unapply_project: 取消申请 lable_sure_exit_project: 是否确认退出该项目 label_friend_organization: 圈子模式 From 78c410b1ecd4bb1a2a3518d51186c11c2278e458 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 30 Apr 2015 11:10:41 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=BC=BA=E9=99=B7?= =?UTF-8?q?=E4=B8=AD=E5=A4=9A=E4=BD=99=E7=9A=84=E5=AF=B9=E5=8B=BE=E5=9B=BE?= =?UTF-8?q?=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/stylesheets/project.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/stylesheets/project.css b/public/stylesheets/project.css index 4f9c6ec78..4b26d74aa 100644 --- a/public/stylesheets/project.css +++ b/public/stylesheets/project.css @@ -338,7 +338,7 @@ a:hover.st_add{ color:#ff8e15;} .newpro_box input{ height:26px; float:left; margin-bottom:10px;} .newpro_box textarea{ height:150px; float:left; margin-bottom:10px;} .newpro_box select{ height:29px; float:left; margin-bottom:10px;} -.label{ width:80px; text-align:right; font-size:14 background-image: url(../images/true.png); } +/*.label{ width:80px; text-align:right; font-size:14 background-image: url(../images/true.png); }*/ .icon-reload { background-image: url(../images/reload.png); } .icon { background-position: 0% 50%; From 76b4ae24dac2171c41e6e24de3d5c090b3dc81dd Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 30 Apr 2015 16:30:02 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=82=AE=E4=BB=B6?= =?UTF-8?q?=E9=82=80=E8=AF=B7--=E9=82=AE=E4=BB=B6=E5=90=8D=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=88=90=E7=94=A8=E6=88=B7=E7=82=B9=E5=87=BB=E5=90=8C?= =?UTF-8?q?=E6=84=8F=E6=8C=89=E9=92=AE=E5=90=8E=E6=89=8D=E8=83=BD=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 7 +++---- app/models/mailer.rb | 14 +++++++------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 2b58f1265..96807d2dc 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -247,10 +247,9 @@ class ProjectsController < ApplicationController # 1、自动注册 # 2、加入项目、创建角色 # 3、用户得分 - if params[:login] - # 自动激活用户 - user.status = 1 - user.save + if params[:email] + user = User.find_by_mail(params[:email].to_s) + Member.create(:role_ids => [4], :user_id => user.id,:project_id => @project.id) end if params[:jump] && redirect_to_project_menu_item(@project, params[:jump]) return diff --git a/app/models/mailer.rb b/app/models/mailer.rb index d35374fcf..e2ccb2230 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -71,14 +71,14 @@ class Mailer < ActionMailer::Base # 邀请已注册的用户加入项目 def request_member_to_project(email, project, invitor) + @subject = "#{invitor.name} #{l(:label_invite_project)}: #{project.name} " user = User.find_by_mail(email.to_s) - Member.create(:role_ids => [4], :user_id => user.id,:project_id => project.id) - @invitor_name = "#{invitor.name}" - @project_name = "#{project.name}" - @user = user - @token = Token.get_token_from_user(user, 'autologin') - @project_url = url_for(:controller => 'projects', :action => 'show', :id => project.id,:user => user, :token => @token.value) - mail :to => email, :invitor_name => "#{@invitor_name}", :project_name => "#{@project_name}" + @invitor_name = "#{invitor.name}" + @project_name = "#{project.name}" + @user = user + @token = Token.get_token_from_user(user, 'autologin') + @project_url = url_for(:controller => 'projects', :action => 'show', :id => project.id, :email => email, :token => @token.value) + mail :to => email, :subject => @subject end # author: alan