微信班级项目增加删除和退出功能
This commit is contained in:
parent
b9e9892257
commit
292e778a8c
|
@ -661,6 +661,85 @@ module Mobile
|
|||
|
||||
end
|
||||
|
||||
desc "删除班级成员"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
requires :token, type: String
|
||||
requires :user_id, type: Integer
|
||||
end
|
||||
post ':id/deletemember' do
|
||||
authenticate!
|
||||
|
||||
status = -1
|
||||
|
||||
if(current_user.id != params[:user_id].to_i)
|
||||
#权限
|
||||
c = Course.find("#{params[:id]}")
|
||||
if c.tea_id != params[:user_id].to_i
|
||||
|
||||
my_member = c.member_principals.where("users.id=#{current_user.id}").first
|
||||
|
||||
roles_ids = []
|
||||
my_member.roles.each do |role|
|
||||
roles_ids << role.id
|
||||
end
|
||||
|
||||
if my_member && roles_ids.include?(3)
|
||||
#删除该成员
|
||||
cs = CoursesService.new
|
||||
status = cs.delete_course_member(c,params[:user_id].to_i,current_user)
|
||||
else
|
||||
status = -2
|
||||
end
|
||||
else
|
||||
status = -3
|
||||
end
|
||||
else
|
||||
status = -4
|
||||
end
|
||||
|
||||
out = {status: status}
|
||||
message = case status
|
||||
when 0; "删除成功"
|
||||
when -1; "您还未登录"
|
||||
when -2; "对不起您没有权限"
|
||||
when -3; "不能删除班级管理员"
|
||||
when -4; "不能删除自己"
|
||||
when 1; "该用户不在该班级中"
|
||||
else; "未知错误,请稍后再试"
|
||||
end
|
||||
out.merge(message: message)
|
||||
end
|
||||
|
||||
desc "退出班级"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
requires :token, type: String
|
||||
end
|
||||
post ':id/quit' do
|
||||
authenticate!
|
||||
|
||||
#管理员不能退
|
||||
cs = CoursesService.new
|
||||
c = Course.find("#{params[:id]}")
|
||||
|
||||
user = current_user
|
||||
|
||||
if c.tea_id != user.id
|
||||
status = cs.exit_course({:object_id => params[:id]}, user)
|
||||
else
|
||||
status = 3
|
||||
end
|
||||
out = {status: status}
|
||||
message = case status
|
||||
when 0; "退出成功"
|
||||
when 1; "您不在课程中"
|
||||
when 2; "您还未登录"
|
||||
when 3; "管理员不能退出班级"
|
||||
else; "未知错误,请稍后再试"
|
||||
end
|
||||
out.merge(message: message)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -268,6 +268,79 @@ module Mobile
|
|||
present :status, 0
|
||||
|
||||
end
|
||||
|
||||
desc "删除项目成员"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
requires :token, type: String
|
||||
requires :user_id, type: Integer
|
||||
end
|
||||
post ':id/deletemember' do
|
||||
authenticate!
|
||||
|
||||
status = -1
|
||||
|
||||
if(current_user.id != params[:user_id].to_i)
|
||||
#权限
|
||||
project = Project.find("#{params[:id]}")
|
||||
if project.tea_id != params[:user_id].to_i
|
||||
|
||||
my_member = project.member_principals.where("users.id=#{current_user.id}").first
|
||||
|
||||
roles_ids = []
|
||||
my_member.roles.each do |role|
|
||||
roles_ids << role.id
|
||||
end
|
||||
|
||||
if my_member && roles_ids.include?(3)
|
||||
#删除该成员
|
||||
ps = ProjectsService.new
|
||||
status = ps.project_delete_member(project,params[:user_id].to_i,current_user)
|
||||
else
|
||||
status = -2
|
||||
end
|
||||
else
|
||||
status = -3
|
||||
end
|
||||
else
|
||||
status = -4
|
||||
end
|
||||
|
||||
out = {status: status}
|
||||
message = case status
|
||||
when 0; "退出成功"
|
||||
when 1; "该用户不在该项目中"
|
||||
when -1; "您还未登录"
|
||||
when -2; "您没有权限"
|
||||
when -3; "不能删除项目创建者"
|
||||
when -4; "不能删除自己"
|
||||
else; "未知错误,请稍后再试"
|
||||
end
|
||||
out.merge(message: message)
|
||||
end
|
||||
|
||||
desc "退出项目"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
requires :token, type: String
|
||||
end
|
||||
post ':id/quit' do
|
||||
authenticate!
|
||||
|
||||
ps = ProjectsService.new
|
||||
status = ps.exit_project(params[:id],current_user)
|
||||
|
||||
out = {status: status}
|
||||
message = case status
|
||||
when 0; "退出成功"
|
||||
when -3; "您不在课程中"
|
||||
when -1; "您还未登录"
|
||||
when -2; "项目创建者不能退出项目"
|
||||
else; "未知错误,请稍后再试"
|
||||
end
|
||||
out.merge(message: message)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,6 +35,7 @@ class AtMessage < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
#@的时候发微信模版消息通知被@的人
|
||||
def send_wechat_message
|
||||
shield_type = ""
|
||||
container_id = 0
|
||||
|
@ -57,15 +58,15 @@ class AtMessage < ActiveRecord::Base
|
|||
|
||||
case at_message_type
|
||||
when "Issue"
|
||||
#新建issue
|
||||
shield_type = "Project"
|
||||
container_id = at_message.project.id
|
||||
type = "issues"
|
||||
detail_id = topic.id
|
||||
detail_title = at_message.subject
|
||||
when "Journal"
|
||||
|
||||
#issue回复
|
||||
topic = get_root_parent at_message.journalized
|
||||
|
||||
shield_type = "Project"
|
||||
container_id = at_message.journalized.project.id
|
||||
type = "issues"
|
||||
|
@ -89,10 +90,10 @@ class AtMessage < ActiveRecord::Base
|
|||
end
|
||||
when 'JournalsForMessage'
|
||||
if at_message.jour && at_message.jour.course
|
||||
#作业回复
|
||||
shield_type = "Course"
|
||||
container_id = at_message.jour.course.id
|
||||
type = "homework"
|
||||
|
||||
detail_id = at_message.jour.id
|
||||
detail_title = at_message.jour.name
|
||||
else
|
||||
|
|
|
@ -1284,5 +1284,36 @@ class CoursesService
|
|||
status
|
||||
end
|
||||
|
||||
#删除班级成员
|
||||
def delete_course_member course,user_id,current_user
|
||||
if current_user.nil?
|
||||
state = -1
|
||||
return state
|
||||
end
|
||||
|
||||
member = course.members.where("user_id=?",user_id).first
|
||||
|
||||
if member != nil
|
||||
|
||||
member.destroy
|
||||
user_admin = CourseInfos.where("user_id = ? and course_id = ?", member.user_id, course.id)
|
||||
if user_admin.size > 0
|
||||
user_admin.each do |user|
|
||||
user.destroy
|
||||
end
|
||||
end
|
||||
joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,course.id)
|
||||
joined.each do |join|
|
||||
join.delete
|
||||
end
|
||||
roles = Role.givable.all[3..5]
|
||||
#移出课程发送消息
|
||||
CourseMessage.create(:user_id => member.user_id, :course_id => course.id, :course_message_type => "RemoveFromCourse", :viewed => false, :course_message_id => current_user.id)
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -355,4 +355,67 @@ class ProjectsService
|
|||
end
|
||||
end
|
||||
|
||||
#删除项目成员
|
||||
def project_delete_member project,user_id,current_user
|
||||
if user.nil?
|
||||
state = -1
|
||||
return state
|
||||
end
|
||||
|
||||
member = project.members.where("user_id=?",user_id).first
|
||||
|
||||
if member != nil
|
||||
member.destroy
|
||||
# end
|
||||
user_admin = ProjectInfo.where("user_id = ? and project_id = ?", member.user_id, project.id)
|
||||
if user_admin.size > 0
|
||||
user_admin.each do |user|
|
||||
user.destroy
|
||||
end
|
||||
end
|
||||
user_grade = UserGrade.where("user_id = ? and project_id = ?", member.user_id, project.id)
|
||||
if user_grade.size > 0
|
||||
user_grade.each do |grade|
|
||||
grade.destroy
|
||||
end
|
||||
end
|
||||
# 移出的时候删除申请消息,不需要删除消息,所以不必要关联删除
|
||||
applied_projects = AppliedProject.where(:project_id => project.id, :user_id => member.user_id).first
|
||||
unless applied_projects.nil?
|
||||
applied_projects.delete
|
||||
end
|
||||
#移出项目发送消息
|
||||
ForgeMessage.create(:user_id => member.user_id, :project_id => project.id, :forge_message_type => "RemoveFromProject", :viewed => false, :forge_message_id => current_user.id)
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
def exit_project project,user
|
||||
if user.nil?
|
||||
state = -1
|
||||
return state
|
||||
end
|
||||
|
||||
if project.user_id == user.id
|
||||
state = -2
|
||||
return state
|
||||
end
|
||||
|
||||
members = Member.where(:user_id => user.id, :project_id=>project.id).first
|
||||
if members != nil && members.roles.first.to_s != "Manager"
|
||||
members.destroy
|
||||
# 移出的时候删除申请消息,不需要删除消息,所以不必要关联删除
|
||||
applied_projects = AppliedProject.where(:project_id => project.id, :user_id => members.user_id).first
|
||||
unless applied_projects.nil?
|
||||
applied_projects.delete
|
||||
end
|
||||
state = 0
|
||||
else
|
||||
state = -3
|
||||
end
|
||||
return state
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -325,6 +325,47 @@ app.controller('ClassController', ['$scope', 'config','$http', 'auth','$location
|
|||
rms.save("course",vm.course);
|
||||
// $location.path('/'+type+'/'+act_id);
|
||||
$location.path("/homework").search({id: id});
|
||||
}
|
||||
};
|
||||
|
||||
vm.deleteMember = function(user_id){
|
||||
$http({
|
||||
method: 'POST',
|
||||
url: apiUrl + "courses/deletemember?id=" + courseid,
|
||||
data:{token:auth.token(),user_id:user_id}
|
||||
}).then(function successCallback(response) {
|
||||
console.log(response.data);
|
||||
|
||||
if(response.data.status == 0){
|
||||
vm.alertService.showMessage('提示', response.data.message,function(){
|
||||
//确定
|
||||
|
||||
});
|
||||
}
|
||||
else{
|
||||
vm.alertService.showMessage('提示', response.data.message);
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
vm.quit = function(){
|
||||
$http({
|
||||
method: 'POST',
|
||||
url: apiUrl + "courses/quit?id=" + courseid,
|
||||
data:{token:auth.token()}
|
||||
}).then(function successCallback(response) {
|
||||
console.log(response.data);
|
||||
if(response.data.status == 0){
|
||||
vm.alertService.showMessage('提示', response.data.message,function(){
|
||||
//确定
|
||||
|
||||
});
|
||||
}
|
||||
else{
|
||||
vm.alertService.showMessage('提示', response.data.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
}]);
|
|
@ -253,4 +253,44 @@ app.controller('ProjectController', ['$scope', 'config','$http','$timeout', 'aut
|
|||
$location.path("/project_publishnote").search({id:projectid});
|
||||
};
|
||||
|
||||
vm.deleteMember = function(user_id){
|
||||
$http({
|
||||
method: 'POST',
|
||||
url: apiUrl + "projects/deletemember?id=" + projectid,
|
||||
data:{token:auth.token(),user_id:user_id}
|
||||
}).then(function successCallback(response) {
|
||||
console.log(response.data);
|
||||
|
||||
if(response.data.status == 0){
|
||||
vm.alertService.showMessage('提示', response.data.message,function(){
|
||||
//确定
|
||||
|
||||
});
|
||||
}
|
||||
else{
|
||||
vm.alertService.showMessage('提示', response.data.message);
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
vm.quit = function(){
|
||||
$http({
|
||||
method: 'POST',
|
||||
url: apiUrl + "projects/quit?id=" + projectid,
|
||||
data:{token:auth.token()}
|
||||
}).then(function successCallback(response) {
|
||||
console.log(response.data);
|
||||
if(response.data.status == 0){
|
||||
vm.alertService.showMessage('提示', response.data.message,function(){
|
||||
//确定
|
||||
|
||||
});
|
||||
}
|
||||
else{
|
||||
vm.alertService.showMessage('提示', response.data.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
}]);
|
Loading…
Reference in New Issue