From 14acdef0cbf6eee4b17b7d553d6987db0fdfd179 Mon Sep 17 00:00:00 2001 From: huang Date: Mon, 21 Sep 2015 14:28:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=88=97=E8=A1=A8=E4=B8=AD?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9D=83=E9=99=90=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 18 +++++++++++++++--- app/views/users/user_messages.html.erb | 22 +++++++++++++--------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 71b852e01..4d80efdf3 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -259,7 +259,8 @@ class ProjectsController < ApplicationController # Author lizanle # Description 项目动态展示方法,删除了不必要的代码 def show - + # 更新消息为已读 + update_message_status(User.current, @project) if params[:jump] && redirect_to_project_menu_item(@project, params[:jump]) return end @@ -468,6 +469,7 @@ class ProjectsController < ApplicationController if params[:message_id] message_invite(params[:message_id], params[:key]) end + update_message_status(User.current, @project) # params[:login]为邮箱邀请用户加入,主要功能: # 1、自动注册 # 2、加入项目、创建角色 @@ -523,11 +525,21 @@ class ProjectsController < ApplicationController @members = paginateHelper @members end + def update_message_status(user, project) + project_invite_messages = ForgeMessage.where("user_id =? and project_id =? and forge_message_type =?", user, project, "ProjectInvite") + project_invite_messages.each do |project_invite_message| + project_invite_message.update_attribute(:viewed, true) + end + 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) + # 情况:用户收到邀请邮件还没看,但是管理员已经把该用户添加进项目 + if Member.where("user_id =? and project_id =?",forge_message.user_id, forge_message.project_id).first.nil? + 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 end diff --git a/app/views/users/user_messages.html.erb b/app/views/users/user_messages.html.erb index 46964b14d..ac4572b5b 100644 --- a/app/views/users/user_messages.html.erb +++ b/app/views/users/user_messages.html.erb @@ -362,9 +362,13 @@
  • <%=link_to inviter, user_path(inviter), :class => "newsBlue homepageNewsPublisher" %> - ">邀请你加入项目: + '>邀请你加入项目
  • -
  • + <% if ma.user.member_of?(ma.project) %> +
  • + <% else %> +
  • + <% end %> <%= link_to ma.project, project_path(ma.project), :class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", :onmouseover => "message_titile_show($(this),event)", @@ -373,13 +377,13 @@ - <% if User.current == @user %> -
  • - <%=link_to "同意加入", {:controller => 'projects', :action => 'member', :id => ma.project_id, :message_id =>ma.id, :key => ma.secret_key}, - :value => ma.secret_key, - :class => "green_btn_cir ml10", - :style => "color:#fff" %> -
  • + <% unless User.current.member_of?(ma.project) %> +
  • + <%=link_to "同意加入", {:controller => 'projects', :action => 'member', :id => ma.project_id, :message_id =>ma.id, :key => ma.secret_key}, + :value => ma.secret_key, + :class => "green_btn_cir ml10", + :style => "color:#fff" %> +
  • <% end %>
  • <%= time_tag(ma.created_at).html_safe %>