diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 95e90d416..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_invite_message(User.current, @project) + # 更新消息为已读 + update_message_status(User.current, @project) if params[:jump] && redirect_to_project_menu_item(@project, params[:jump]) return end @@ -464,12 +465,11 @@ class ProjectsController < ApplicationController # by young # include CoursesHelper def member - # 更新消息状态 - update_invite_message(User.current, @project) # 消息"同意加入项目" if params[:message_id] message_invite(params[:message_id], params[:key]) end + update_message_status(User.current, @project) # params[:login]为邮箱邀请用户加入,主要功能: # 1、自动注册 # 2、加入项目、创建角色 @@ -525,18 +525,21 @@ class ProjectsController < ApplicationController @members = paginateHelper @members end - def update_invite_message(user, project) - forge_invite_messages = ForgeMessage.where("user_id =? and project_id =? and forge_message_type =?", user, project, "ProjectInvite") - forge_invite_messages.each do |forge_invite_messages| - forge_invite_messages.update_attribute(:viewed, true) + 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 6445215d5..ac4572b5b 100644 --- a/app/views/users/user_messages.html.erb +++ b/app/views/users/user_messages.html.erb @@ -362,12 +362,12 @@
  • <%=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"}", @@ -377,13 +377,13 @@ - <% unless ma.user.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" %> -
  • + <% 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 %>