This commit is contained in:
cxt 2015-09-21 16:21:13 +08:00
commit 7c8f0decc6
2 changed files with 22 additions and 19 deletions

View File

@ -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

View File

@ -362,12 +362,12 @@
</li>
<li class="homepageNewsPubType fl">
<%=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>
<% if ma.user.member_of?(ma.project) %>
<li class="homepageNewsContent fl">
<li class="homepageNewsContent fl">
<% else %>
<li class="homepageHomeworkContent fl">
<li class="homepageHomeworkContent fl">
<% end %>
<%= link_to ma.project, project_path(ma.project),
:class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}",
@ -377,13 +377,13 @@
<div style="display: none" class="message_title_red system_message_style">
<%= ma.project %>
</div>
<% unless ma.user.member_of?(ma.project) %>
<li class="homepageHomeworkContentWarn fl">
<%=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" %>
</li>
<% unless User.current.member_of?(ma.project) %>
<li class="homepageHomeworkContentWarn fl">
<%=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" %>
</li>
<% end %>
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
</ul>