2015-04-07 13:47:39 +08:00
|
|
|
|
class AppliedProjectController < ApplicationController
|
2016-07-29 14:49:37 +08:00
|
|
|
|
helper :watchers
|
2015-04-07 13:47:39 +08:00
|
|
|
|
#申请加入项目
|
|
|
|
|
def applied_join_project
|
2016-07-29 20:31:24 +08:00
|
|
|
|
if params[:object_id]
|
|
|
|
|
@project = Project.find_by_id(params[:object_id])
|
|
|
|
|
end
|
2016-10-21 19:58:02 +08:00
|
|
|
|
if params[:is_teacher]
|
|
|
|
|
@is_teacher = 1
|
|
|
|
|
end
|
2016-07-26 08:55:07 +08:00
|
|
|
|
# @user_id = params[:user_id]
|
|
|
|
|
# if params[:project_join]
|
|
|
|
|
# if @project
|
|
|
|
|
# user = User.find @user_id
|
|
|
|
|
# if user.member_of?(@project)
|
|
|
|
|
# @status = 3
|
|
|
|
|
# else
|
|
|
|
|
# @applieds = AppliedProject.where("user_id = ? and project_id = ?", params[:user_id],params[:project_id])
|
|
|
|
|
# if @applieds.count == 0
|
|
|
|
|
# appliedproject = AppliedProject.create(:user_id => params[:user_id], :project_id => params[:project_id])
|
|
|
|
|
# Mailer.run.applied_project(appliedproject)
|
|
|
|
|
# @status = 2
|
|
|
|
|
# else
|
|
|
|
|
# @status = 1
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
# else
|
|
|
|
|
# @status = 0
|
|
|
|
|
# end
|
|
|
|
|
# respond_to do |format|
|
|
|
|
|
# format.js
|
|
|
|
|
# end
|
|
|
|
|
# return
|
|
|
|
|
# end
|
|
|
|
|
#
|
|
|
|
|
# @applieds = AppliedProject.where("user_id = ? and project_id = ?", params[:user_id],params[:project_id])
|
|
|
|
|
# if @applieds.count == 0
|
|
|
|
|
# appliedproject = AppliedProject.create(:user_id => params[:user_id], :project_id => params[:project_id])
|
|
|
|
|
# Mailer.run.applied_project(appliedproject)
|
|
|
|
|
# end
|
|
|
|
|
#
|
|
|
|
|
# #redirect_to project_path(params[:project_id])
|
|
|
|
|
# #redirect_to_referer_or {render :text => ( 'applied success.'), :layout => true}
|
|
|
|
|
# respond_to do |format|
|
|
|
|
|
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
|
|
|
|
# format.js { render :partial => 'set_applied'}
|
|
|
|
|
# end
|
2015-04-07 13:47:39 +08:00
|
|
|
|
end
|
|
|
|
|
|
2016-07-28 16:22:33 +08:00
|
|
|
|
# @flage:提示语标志(1:邀请码错误;2:已经是项目成员; 3:角色没有选择; 4:申请成功)
|
2016-08-05 16:35:22 +08:00
|
|
|
|
# role:成员角色 => 0(3:管理人员;4:开发人员;5:报告人员)
|
2016-07-28 10:18:35 +08:00
|
|
|
|
# 申请成功则发送消息
|
|
|
|
|
def applied_project_info
|
2016-07-29 20:31:24 +08:00
|
|
|
|
if params[:project_id].nil?
|
|
|
|
|
@project = Project.where(:invite_code => params[:invite_code]).first
|
|
|
|
|
else
|
|
|
|
|
@project = Project.find(params[:project_id])
|
|
|
|
|
end
|
2016-08-09 17:06:50 +08:00
|
|
|
|
if !@project || params[:invite_code].strip.upcase.to_s != @project.invite_code
|
2016-07-28 10:18:35 +08:00
|
|
|
|
@flag = 1
|
|
|
|
|
elsif User.current.member_of?(@project)
|
|
|
|
|
@flag = 2
|
2016-07-28 14:42:36 +08:00
|
|
|
|
elsif params[:member].nil?
|
2016-07-28 10:18:35 +08:00
|
|
|
|
@flag = 3
|
2016-08-01 09:50:05 +08:00
|
|
|
|
elsif !AppliedProject.where(:project_id => @project.id, :user_id => User.current.id).first.nil?
|
|
|
|
|
@flag = 5
|
2016-08-05 16:35:22 +08:00
|
|
|
|
elsif params[:member] == "member_reporter" && params[:invite_code].upcase.to_s == @project.invite_code
|
|
|
|
|
# 项目报告人员直接加入项目
|
|
|
|
|
@flag = 6
|
|
|
|
|
members = []
|
|
|
|
|
user_grades = []
|
|
|
|
|
project_info = []
|
|
|
|
|
members << Member.new(:role_ids => ["5"], :user_id => User.current.id)
|
|
|
|
|
user_grades << UserGrade.new(:user_id => User.current.id, :project_id => @project.id)
|
|
|
|
|
role = Role.find(5)
|
|
|
|
|
project_info << ProjectInfo.new(:project_id => @project.id, :user_id => User.current.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?
|
|
|
|
|
|
2016-08-11 11:22:42 +08:00
|
|
|
|
ps = ProjectsService.new
|
|
|
|
|
ps.send_wechat_join_project_notice User.current,@project,5,0
|
2016-07-28 10:18:35 +08:00
|
|
|
|
else
|
|
|
|
|
@flag = 4
|
2016-07-29 22:58:24 +08:00
|
|
|
|
role = params[:member] == "member_manager" ? 3 : (params[:member] == "member_developer" ? 4 :5)
|
2016-07-29 20:31:24 +08:00
|
|
|
|
applied_project = AppliedProject.create(:user_id => User.current.id, :project_id => @project.id, :role => role)
|
2016-07-28 14:42:36 +08:00
|
|
|
|
# 申请成功则给项目管理员发送邮件及发送消息
|
2016-07-29 23:37:31 +08:00
|
|
|
|
# Mailer.run.applied_project(applied_project)
|
2016-07-28 10:18:35 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-07 13:47:39 +08:00
|
|
|
|
#取消申请
|
|
|
|
|
def unapplied_join_project
|
|
|
|
|
@project = Project.find(params[:project_id])
|
|
|
|
|
#@applied = AppliedProject.find(params[:id])
|
|
|
|
|
#@applied.destroy
|
|
|
|
|
|
|
|
|
|
AppliedProject.deleteappiled(params[:user_id], params[:project_id])
|
|
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
|
|
|
|
format.js { render :partial => 'set_applied' }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|