项目邀请框架 拒绝消息
This commit is contained in:
parent
a8fa4a55e3
commit
c07677ef99
|
@ -1,5 +1,5 @@
|
||||||
class AppliedProjectController < ApplicationController
|
class AppliedProjectController < ApplicationController
|
||||||
|
helper :watchers
|
||||||
#申请加入项目
|
#申请加入项目
|
||||||
def applied_join_project
|
def applied_join_project
|
||||||
@project = Project.find_by_id(params[:object_id])
|
@project = Project.find_by_id(params[:object_id])
|
||||||
|
@ -43,7 +43,7 @@ class AppliedProjectController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# @flage:提示语标志(1:邀请码错误;2:已经是项目成员; 3:角色没有选择; 4:申请成功)
|
# @flage:提示语标志(1:邀请码错误;2:已经是项目成员; 3:角色没有选择; 4:申请成功)
|
||||||
# role:成员角色 => 0(1:管理人员;2:开发人员;3:报告人员)
|
# role:成员角色 => 0(4:管理人员;5:开发人员;6:报告人员)
|
||||||
# 申请成功则发送消息
|
# 申请成功则发送消息
|
||||||
def applied_project_info
|
def applied_project_info
|
||||||
@project = Project.find(params[:project_id])
|
@project = Project.find(params[:project_id])
|
||||||
|
@ -55,7 +55,7 @@ class AppliedProjectController < ApplicationController
|
||||||
@flag = 3
|
@flag = 3
|
||||||
else
|
else
|
||||||
@flag = 4
|
@flag = 4
|
||||||
role = params[:member] == "member_manager" ? 1 : (params[:member] = "member_developer" ? 2 : 3)
|
role = params[:member] == "member_manager" ? 4 : (params[:member] = "member_developer" ? 5 : 6)
|
||||||
applied_project = AppliedProject.create(:user_id => User.current.id, :project_id => params[:project_id], :role => role)
|
applied_project = AppliedProject.create(:user_id => User.current.id, :project_id => params[:project_id], :role => role)
|
||||||
# 申请成功则给项目管理员发送邮件及发送消息
|
# 申请成功则给项目管理员发送邮件及发送消息
|
||||||
Mailer.run.applied_project(applied_project)
|
Mailer.run.applied_project(applied_project)
|
||||||
|
|
|
@ -17,10 +17,11 @@
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class MembersController < ApplicationController
|
class MembersController < ApplicationController
|
||||||
|
helper :users
|
||||||
model_object Member
|
model_object Member
|
||||||
before_filter :find_model_object, :except => [:index, :create, :autocomplete]
|
before_filter :find_model_object, :except => [:index, :create, :autocomplete, :allow_to_join_project, :refused_allow_to_join_project]
|
||||||
#before_filter :find_model_object_contest, :except => [:index, :create, :autocomplete]
|
#before_filter :find_model_object_contest, :except => [:index, :create, :autocomplete]
|
||||||
before_filter :find_project_from_association, :except => [:index, :create, :autocomplete]
|
before_filter :find_project_from_association, :except => [:index, :create, :autocomplete, :allow_to_join_project, :refused_allow_to_join_project]
|
||||||
before_filter :find_project_by_project_id, :only => [:index, :create, :autocomplete]
|
before_filter :find_project_by_project_id, :only => [:index, :create, :autocomplete]
|
||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
accept_api_auth :index, :show, :create, :update, :destroy
|
accept_api_auth :index, :show, :create, :update, :destroy
|
||||||
|
@ -49,6 +50,59 @@ class MembersController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 同意消息中申请加入项目
|
||||||
|
# 之所以role不在参数中传送是考虑到安全问题
|
||||||
|
# status(1:申请的消息;2:已操作过该消息(包括同意或者拒绝,消息状态更新);3:决绝消息;4:被拒人收到消息;5:拒绝者收到消息;6:同意后申请人收到消息;7:同意后批准人收到消息)
|
||||||
|
def allow_to_join_project
|
||||||
|
@applied_message = AppliedMessage.find(params[:applied_message_id])
|
||||||
|
applied_project = @applied_message.applied
|
||||||
|
user = User.find(@applied_message.applied_user_id)
|
||||||
|
project = Project.find(applied_project.project_id)
|
||||||
|
|
||||||
|
# applied_project = AppliedProject.where(:project_id => params[:project_id], :user_id => params[:user_id]).first
|
||||||
|
# @applied_message = AppliedMessage.find(params[:applied_id])
|
||||||
|
if user.member_of?(project)
|
||||||
|
@flash_message = "您已经是项目成员了"
|
||||||
|
@applied_message.update_attribute(:status, 2)
|
||||||
|
else
|
||||||
|
ap_role = applied_project.try(:role)
|
||||||
|
if ap_role
|
||||||
|
begin
|
||||||
|
members = []
|
||||||
|
user_grades = []
|
||||||
|
project_info = []
|
||||||
|
members << Member.new(:role_ids => ["#{ap_role}"], :user_id => params[:user_id])
|
||||||
|
user_grades << UserGrade.new(:user_id => params[:user_id], :project_id => params[:project_id])
|
||||||
|
role = Role.find(ap_role)
|
||||||
|
project_info << ProjectInfo.new(:project_id => params[:project_id], :user_id => params[:user_id]) if role.allowed_to?(:is_manager)
|
||||||
|
project.members << members
|
||||||
|
project.project_infos << project_info
|
||||||
|
project.user_grades << user_grades unless user_grades.first.user_id.nil?
|
||||||
|
# 添加成功后,申请人收到消息
|
||||||
|
AppliedMessage.create(:user_id => params[:send_id], :applied_type => "AppliedProject", :applied_id => applied_project.id ,:status => 6, :viewed => true, :applied_user_id => params[:user_id])
|
||||||
|
# 添加成功后,批准人收到消息
|
||||||
|
AppliedMessage.create(:user_id => params[:user_id], :applied_type => "AppliedProject", :applied_id => applied_project.id ,:status => 7, :viewed => true, :applied_user_id => params[:send_id])
|
||||||
|
rescue Exception => e
|
||||||
|
puts e
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# 同意消息中拒绝加入项目
|
||||||
|
# params[:user_id]为申请者ID
|
||||||
|
# params[:send_id]为拒绝人ID
|
||||||
|
# status(1:申请的消息;2:已操作过该消息(包括同意或者拒绝,消息状态更新);3:拒绝消息;4:被拒人收到消息;5:拒绝者收到消息;6:同意后申请人收到消息;7:同意后批准人收到消息)
|
||||||
|
def refused_allow_to_join_project
|
||||||
|
@applied_message = AppliedMessage.find(params[:applied_message_id])
|
||||||
|
@applied_message.update_attribute(:status, 3)
|
||||||
|
applied_project = @applied_message.applied
|
||||||
|
# 发送消息给被拒者,user_id对应的收到信息的用户
|
||||||
|
AppliedMessage.create(:user_id => @applied_message.applied_user_id, :applied_type => "AppliedProject", :applied_id => applied_project.id ,:status => 4, :viewed => true, :applied_user_id => @applied_message.user_id)
|
||||||
|
# 发送消息给拒绝者
|
||||||
|
AppliedMessage.create(:user_id => @applied_message.user_id, :applied_type => "AppliedProject", :applied_id => applied_project.id ,:status => 5, :viewed => true, :applied_user_id => @applied_message.applied_user_id)
|
||||||
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
if params[:refusal_button]
|
if params[:refusal_button]
|
||||||
members = []
|
members = []
|
||||||
|
|
|
@ -57,15 +57,42 @@ module UsersHelper
|
||||||
# 获取消息角色
|
# 获取消息角色
|
||||||
def applied_project_message_type role
|
def applied_project_message_type role
|
||||||
case role
|
case role
|
||||||
when 1
|
when 4
|
||||||
"管理员"
|
"管理员"
|
||||||
when 2
|
when 5
|
||||||
"开发人员"
|
"开发人员"
|
||||||
when 3
|
when 6
|
||||||
"报告人员"
|
"报告人员"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 判断当前用户能否对消息进行操作
|
||||||
|
def allow_to_show applied_message
|
||||||
|
(User.current.id == applied_message.user_id && applied_message.status == 1) ? true : false
|
||||||
|
end
|
||||||
|
|
||||||
|
# 项目申请消息通过状态判断用户
|
||||||
|
# status(1:申请的消息;2:已操作过该消息(包括同意或者拒绝,消息状态更新);3:拒绝消息;4:被拒人收到消息;5:拒绝者收到消息;6:同意后申请人收到消息;7:同意后批准人收到消息)
|
||||||
|
def applied_project_users applied_message
|
||||||
|
case applied_message.status
|
||||||
|
when 3,2,1,5,4
|
||||||
|
user = User.find(applied_message.applied_user_id)
|
||||||
|
when 6
|
||||||
|
user = User.find(applied_message.user_id)
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# 项目申请消息通过状态判断tip描述
|
||||||
|
def applied_project_tip applied_message
|
||||||
|
case applied_message.status
|
||||||
|
when 4
|
||||||
|
"拒绝申请加入项目:"
|
||||||
|
when 5,3,2,1
|
||||||
|
"申请加入项目:"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def get_resource_origin attach
|
def get_resource_origin attach
|
||||||
type = attach.container_type
|
type = attach.container_type
|
||||||
content = attach.container
|
content = attach.container
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class AppliedMessage < ActiveRecord::Base
|
class AppliedMessage < ActiveRecord::Base
|
||||||
# status: 0表示未批准; status:1表示已批准; status: 2表示已拒绝
|
# status: 0表示未批准; status:1表示已批准; status: 2表示已拒绝
|
||||||
attr_accessible :applied_id, :applied_type, :status, :user_id, :viewed
|
attr_accessible :applied_id, :applied_type, :status, :user_id, :viewed, :applied_user_id
|
||||||
belongs_to :applied ,:polymorphic => true
|
belongs_to :applied ,:polymorphic => true
|
||||||
belongs_to :apply_add_schools
|
belongs_to :apply_add_schools
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
|
@ -10,7 +10,7 @@ class AppliedProject < ActiveRecord::Base
|
||||||
# 仅仅给项目管理人员发送消息
|
# 仅仅给项目管理人员发送消息
|
||||||
def send_appliled_message
|
def send_appliled_message
|
||||||
self.project.managers.each do |member|
|
self.project.managers.each do |member|
|
||||||
self.applied_messages << AppliedMessage.new(:user_id => member.user_id, :status => true, :viewed => false)
|
self.applied_messages << AppliedMessage.new(:user_id => member.user_id, :status => true, :viewed => false, :applied_user_id => self.user_id)
|
||||||
end
|
end
|
||||||
# end
|
# end
|
||||||
end
|
end
|
||||||
|
|
|
@ -919,8 +919,8 @@ class Project < ActiveRecord::Base
|
||||||
CODES = %W(2 3 4 5 6 7 8 9 A B C D E F G H J K L N M O P Q R S T U V W X Y Z)
|
CODES = %W(2 3 4 5 6 7 8 9 A B C D E F G H J K L N M O P Q R S T U V W X Y Z)
|
||||||
def generate_invite_code
|
def generate_invite_code
|
||||||
code = read_attribute(:invite_code)
|
code = read_attribute(:invite_code)
|
||||||
if !code || code.size <5
|
if !code || code.size <6
|
||||||
code = CODES.sample(5).join
|
code = CODES.sample(6).join
|
||||||
return generate_invite_code if Project.where(invite_code: code).present?
|
return generate_invite_code if Project.where(invite_code: code).present?
|
||||||
update_attribute(:invite_code, code)
|
update_attribute(:invite_code, code)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
var htmlvalue = "<%= escape_javascript(render :partial => 'applied_project/applied_project_tip', locals: {:project_id => @project.id}) %>";
|
var htmlvalue = "<%= escape_javascript(render :partial => 'applied_project/applied_project_tip') %>";
|
||||||
pop_box_new(htmlvalue,380,40,50);
|
pop_box_new(htmlvalue,380,40,50);
|
||||||
|
|
||||||
//$("#join_in_project").attr('href','<%#= join_in_project_link(@project, User.current) %>');
|
//$("#join_in_project").attr('href','<%#= join_in_project_link(@project, User.current) %>');
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
<% if @flash_message %>
|
||||||
|
alert("<%= @flash_message %>");
|
||||||
|
<% else%>
|
||||||
|
$("#applied_project_<%= @applied_message.id %>").html('<%= render :partial => "users/user_message_applide_action", :locals =>{:ma => @applied_message} %>');
|
||||||
|
<% end%>
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
$("#applied_project_<%= @applied_message.id %>").html('<%= render :partial => "users/user_message_applide_action", :locals =>{:ma => @applied_message} %>');
|
|
@ -0,0 +1,12 @@
|
||||||
|
<% if allow_to_show(ma) %>
|
||||||
|
:<%= link_to "同意", allow_to_join_project_project_memberships_path(:project_id => ma.applied.project, :applied_message_id => ma.id), :remote => true, :method => :post %> |
|
||||||
|
<%= link_to "拒绝", refused_allow_to_join_project_project_memberships_path(:project_id => ma.applied.project, :applied_message_id => ma.id), :remote => true, :method => :get %>
|
||||||
|
<% elsif ma.status == 4 %>
|
||||||
|
被拒绝
|
||||||
|
<% elsif ma.status == 5 %>
|
||||||
|
您已拒绝
|
||||||
|
<% elsif ma.status == 6 %>
|
||||||
|
已通过
|
||||||
|
<% elsif ma.status == 7 %>
|
||||||
|
您已同意
|
||||||
|
<% end %>
|
|
@ -0,0 +1,2 @@
|
||||||
|
<%=link_to applied_project_users(ma), user_path(applied_project_users(ma)), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %>
|
||||||
|
<span class="homepageNewsType fl"><%= applied_project_tip(ma) %></span>
|
|
@ -20,13 +20,14 @@
|
||||||
<a href="javascript:void(0);"><%=link_to image_tag(url_to_avatar(ma.applied.user), :width => "30", :height => "30"), user_path(ma.applied.user), :target => '_blank' %></a>
|
<a href="javascript:void(0);"><%=link_to image_tag(url_to_avatar(ma.applied.user), :width => "30", :height => "30"), user_path(ma.applied.user), :target => '_blank' %></a>
|
||||||
</li>
|
</li>
|
||||||
<li class="homepageNewsPubType fl">
|
<li class="homepageNewsPubType fl">
|
||||||
<%=link_to ma.applied.user, user_path(ma.applied.user), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %>
|
<%= render :partial => "users/user_message_applide_users", :locals =>{:ma => ma} %>
|
||||||
<span class="<%= ma.viewed == 0 ? "homepageNewsTypeNotRead fl" : "homepageNewsType fl" %>">申请加入项目:</span>
|
|
||||||
</li>
|
</li>
|
||||||
<li class="homepageNewsContent fl"><a href="javascript:void(0);" class="newsGrey">
|
<li class="homepageNewsContent fl"><a href="javascript:void(0);" class="newsGrey">
|
||||||
以“<%= applied_project_message_type(ma.applied.role) %>”身份加入
|
以“<%= applied_project_message_type(ma.applied.role) %>”身份加入
|
||||||
<%= link_to ma.applied.project, settings_project_path(:id => ma.applied.project.id, :tab => "members"), :class => "link-blue", :target => '_blank' %>
|
<%= link_to ma.applied.project, project_path(ma.applied.project), :class => "link-blue", :target => '_blank' %>
|
||||||
:同意 | 拒绝
|
<span id="applied_project_<%= ma.id %>">
|
||||||
|
<%= render :partial => "users/user_message_applide_action", :locals =>{:ma => ma} %>
|
||||||
|
</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
|
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
|
||||||
|
|
|
@ -767,6 +767,8 @@ RedmineApp::Application.routes.draw do
|
||||||
collection do
|
collection do
|
||||||
get 'autocomplete'
|
get 'autocomplete'
|
||||||
get 'appliedproject'
|
get 'appliedproject'
|
||||||
|
post 'allow_to_join_project'
|
||||||
|
get 'refused_allow_to_join_project'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddAppliedUserIdToAppliedMessage < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :applied_messages, :applied_user_id, :integer
|
||||||
|
end
|
||||||
|
end
|
|
@ -1499,6 +1499,7 @@ function pop_box_new(value, Width, Top, Left){
|
||||||
$('#ajax-modal').siblings().remove();
|
$('#ajax-modal').siblings().remove();
|
||||||
$('#ajax-modal').parent().css({"top": Top+"%","left": Left+"%","transform":"translate(-50%,-50%)","padding":"0","border":"none"});
|
$('#ajax-modal').parent().css({"top": Top+"%","left": Left+"%","transform":"translate(-50%,-50%)","padding":"0","border":"none"});
|
||||||
$('#ajax-modal').css({"padding":"0"});
|
$('#ajax-modal').css({"padding":"0"});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 公共提示弹框样式
|
// 公共提示弹框样式
|
||||||
|
|
Loading…
Reference in New Issue