This commit is contained in:
sw 2015-09-21 15:24:08 +08:00
commit 9f0eb937fe
2 changed files with 22 additions and 19 deletions

View File

@ -259,7 +259,8 @@ class ProjectsController < ApplicationController
# Author lizanle # Author lizanle
# Description 项目动态展示方法,删除了不必要的代码 # Description 项目动态展示方法,删除了不必要的代码
def show 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]) if params[:jump] && redirect_to_project_menu_item(@project, params[:jump])
return return
end end
@ -464,12 +465,11 @@ class ProjectsController < ApplicationController
# by young # by young
# include CoursesHelper # include CoursesHelper
def member def member
# 更新消息状态
update_invite_message(User.current, @project)
# 消息"同意加入项目" # 消息"同意加入项目"
if params[:message_id] if params[:message_id]
message_invite(params[:message_id], params[:key]) message_invite(params[:message_id], params[:key])
end end
update_message_status(User.current, @project)
# params[:login]为邮箱邀请用户加入,主要功能: # params[:login]为邮箱邀请用户加入,主要功能:
# 1、自动注册 # 1、自动注册
# 2、加入项目、创建角色 # 2、加入项目、创建角色
@ -525,18 +525,21 @@ class ProjectsController < ApplicationController
@members = paginateHelper @members @members = paginateHelper @members
end end
def update_invite_message(user, project) def update_message_status(user, project)
forge_invite_messages = ForgeMessage.where("user_id =? and project_id =? and forge_message_type =?", user, project, "ProjectInvite") project_invite_messages = ForgeMessage.where("user_id =? and project_id =? and forge_message_type =?", user, project, "ProjectInvite")
forge_invite_messages.each do |forge_invite_messages| project_invite_messages.each do |project_invite_message|
forge_invite_messages.update_attribute(:viewed, true) project_invite_message.update_attribute(:viewed, true)
end end
end end
def message_invite(message_id, key) def message_invite(message_id, key)
forge_message = ForgeMessage.find(message_id) forge_message = ForgeMessage.find(message_id)
if key == forge_message.secret_key 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
end end

View File

@ -362,12 +362,12 @@
</li> </li>
<li class="homepageNewsPubType fl"> <li class="homepageNewsPubType fl">
<%=link_to inviter, user_path(inviter), :class => "newsBlue homepageNewsPublisher" %> <%=link_to inviter, user_path(inviter), :class => "newsBlue homepageNewsPublisher" %>
<span class="<%= ma.viewed == 0 ? "homepageNewsTypeNotRead fl" : "homepageNewsType fl" %>">邀请你加入项目:</span> <span class='<%= ma.viewed == 0 ? 'homepageNewsTypeNotRead fl' : 'homepageNewsType fl' %>'>邀请你加入项目</span>
</li> </li>
<% if ma.user.member_of?(ma.project) %> <% if ma.user.member_of?(ma.project) %>
<li class="homepageNewsContent fl"> <li class="homepageNewsContent fl">
<% else %> <% else %>
<li class="homepageHomeworkContent fl"> <li class="homepageHomeworkContent fl">
<% end %> <% end %>
<%= link_to ma.project, project_path(ma.project), <%= link_to ma.project, project_path(ma.project),
:class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", :class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}",
@ -377,13 +377,13 @@
<div style="display: none" class="message_title_red system_message_style"> <div style="display: none" class="message_title_red system_message_style">
<%= ma.project %> <%= ma.project %>
</div> </div>
<% unless ma.user.member_of?(ma.project) %> <% unless User.current.member_of?(ma.project) %>
<li class="homepageHomeworkContentWarn fl"> <li class="homepageHomeworkContentWarn fl">
<%=link_to "同意加入", {:controller => 'projects', :action => 'member', :id => ma.project_id, :message_id =>ma.id, :key => ma.secret_key}, <%=link_to "同意加入", {:controller => 'projects', :action => 'member', :id => ma.project_id, :message_id =>ma.id, :key => ma.secret_key},
:value => ma.secret_key, :value => ma.secret_key,
:class => "green_btn_cir ml10", :class => "green_btn_cir ml10",
:style => "color:#fff" %> :style => "color:#fff" %>
</li> </li>
<% end %> <% end %>
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li> <li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
</ul> </ul>