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,20 +525,23 @@ 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
# 情况:用户收到邀请邮件还没看,但是管理员已经把该用户添加进项目
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) 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) UserGrade.create(:user_id => forge_message.user_id, :project_id => forge_message.project_id)
end end
end end
end
#判断指定用户是否为课程教师 #判断指定用户是否为课程教师
def isCourseTeacher(id) def isCourseTeacher(id)

View File

@ -362,7 +362,7 @@
</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">
@ -377,7 +377,7 @@
<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,