diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index bfd559402..cbf8f4986 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -540,6 +540,7 @@ module Mobile present :status, 0 else present :status, -1 + present :message, "该用户已不在班级中" end end @@ -568,17 +569,26 @@ module Mobile roles_id << 10 end - c = Course.find("#{params[:id]}") - #7教辅 9教师 10学生 - if c.tea_id == params[:user_id] || c.tea_id != current_user.id || roles_id.length <= 0 - present :status, -1 - else + my_member = c.member_principals.where("users.id=#{current_user.id}").first + rolesids = [] + my_member.roles.each do |role| + rolesids << role.id + end + + #7教辅 9教师 10学生 + if c.tea_id == params[:user_id] || roles_id.length <= 0 + present :status, -1 + present :message,"修改失败" + elsif rolesids.include?(3) || rolesids.include?(7) || rolesids.include?(9) cs = CoursesService.new status = cs.modify_user_course_role params,roles_id present :status, status + else + present :status, -1 + present :message,"修改失败" end end @@ -661,6 +671,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) || roles_ids.include?(7) || roles_ids.include?(9) ) + #删除该成员 + 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 diff --git a/app/api/mobile/apis/projects.rb b/app/api/mobile/apis/projects.rb index 2202fbd13..ecd850fd8 100644 --- a/app/api/mobile/apis/projects.rb +++ b/app/api/mobile/apis/projects.rb @@ -127,6 +127,7 @@ module Mobile present :status, 0 else present :status, -1 + present :message, "该用户已不在项目中" end end @@ -268,6 +269,81 @@ 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.user_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! + + project = Project.find("#{params[:id]}") + + ps = ProjectsService.new + status = ps.exit_project(project,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 diff --git a/app/api/mobile/entities/activity.rb b/app/api/mobile/entities/activity.rb index a56deaad3..9deeec58e 100644 --- a/app/api/mobile/entities/activity.rb +++ b/app/api/mobile/entities/activity.rb @@ -73,6 +73,12 @@ module Mobile elsif ac.container_type == "Blog" "发表博客" end + when :course_project_id + if ac.container_type == "Course" + ac.container_id + elsif ac.container_type == "Project" + ac.container_id + end when :activity_type_name if ac.container_type == "Course" case ac.act_type @@ -137,6 +143,7 @@ module Mobile act_expose :subject #标题 act_expose :description #描述 act_expose :latest_update #最新更新时间 + act_expose :course_project_id #课程/项目ID act_expose :course_project_name #课程/项目名字 act_expose :activity_type_name #课程问答区/项目缺陷等 expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| diff --git a/app/api/mobile/entities/project.rb b/app/api/mobile/entities/project.rb index 8da151b42..eef7a9c92 100644 --- a/app/api/mobile/entities/project.rb +++ b/app/api/mobile/entities/project.rb @@ -3,6 +3,7 @@ module Mobile class Project < Grape::Entity expose :name expose :id + expose :is_public expose :user_id expose :invite_code expose :qrcode diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index caf0b4bda..4c9411538 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -589,19 +589,19 @@ class IssuesController < ApplicationController return false end end - @issue.safe_attributes = issue_attributes senduser = User.find(params[:issue][:assigned_to_id]) - if senduser.id != User.current.id + if senduser.id != User.current.id && @issue.assigned_to_id != params[:issue][:assigned_to_id].to_i issue_id = @issue.id issue_title = params[:issue][:subject] priority_id = params[:issue][:priority_id] - ps = ProjectsService.new ps.send_wechat_project_issue_notice senduser,@issue.project,issue_id,issue_title,priority_id end + @issue.safe_attributes = issue_attributes + @priorities = IssuePriority.active @allowed_statuses = @issue.new_statuses_allowed_to(User.current) true diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d0ec28317..3c125a185 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3244,6 +3244,16 @@ def get_all_children result, jour result end +#获取该节点所在的帖子 +def get_root_parent comment + while comment.parent + comment = comment.parent + end + comment +end + + + #将有置顶属性的提到数组前面 def sort_by_sticky topics tmpTopics = [] diff --git a/app/models/at_message.rb b/app/models/at_message.rb index bca2c7ba4..4c3ca9b74 100644 --- a/app/models/at_message.rb +++ b/app/models/at_message.rb @@ -1,6 +1,7 @@ #coding=utf-8 class AtMessage < ActiveRecord::Base + include ApplicationHelper belongs_to :user belongs_to :sender, class_name: "User", foreign_key: "sender_id" attr_accessible :at_message, :container, :viewed, :user_id, :sender_id @@ -10,7 +11,7 @@ class AtMessage < ActiveRecord::Base has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy validates :user_id, :sender_id, :at_message_id, :at_message_type, presence: true - after_create :add_user_message + after_create :add_user_message, :send_wechat_message scope :unviewed, ->(type, id){ where(at_message_type: type, at_message_id:id, viewed: false) @@ -34,6 +35,91 @@ class AtMessage < ActiveRecord::Base end end + #@的时候发微信模版消息通知被@的人 + def send_wechat_message + shield_type = "" + container_id = 0 + status = 0 + type = "" + detail_id = 0 + detail_title = "" + + if defined? at_message.notes + detail_content = strip_html at_message.notes,30 + elsif defined? at_message.content + detail_content = strip_html at_message.content,30 + elsif defined? at_message.description + detail_content = strip_html at_message.description,30 + end + + user = self.user + + topic = get_root_parent at_message + + 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" + detail_id = topic.id + detail_title = at_message.journalized.subject + when 'Message' + if at_message.course + shield_type = "Course" + container_id = at_message.course.id + type = "course_discussion" + detail_id = topic.id + detail_title = at_message.subject + elsif at_message.project + shield_type = "Project" + container_id = at_message.project.id + type = "project_discussion" + detail_id = topic.id + detail_title = at_message.subject + else + status = -1 + 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 + type = "journal_for_message" + detail_id = topic.id + detail_title = at_message.subject + end + else + status = -1 + end + + count = 0 + + detail_title = detail_title.gsub(/RE: /, '') + + if container_id != 0 + count = ShieldWechatMessage.where("container_type='User' and container_id=#{user.id} and shield_type='#{shield_type}' and shield_id=#{container_id}").count + end + if count == 0 && status == 0 + message_title = self.sender.show_name+"@了您" + ws = WechatService.new + ws.at_notice user.id, type, detail_id, message_title, detail_title, format_time(Time.now), detail_content, "点击查看详情。",0 + end + + end + def subject case at_message_type when "Issue" diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 7d574bada..f184fa923 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -79,7 +79,8 @@ class CoursesService else c = Course.find(course) end - if current_user.nil? || !(current_user.admin? || c.is_public == 1 || (c.is_public == 0 && current_user.member_of_course?(c))) + # if current_user.nil? || !(current_user.admin? || c.is_public == 1 || (c.is_public == 0 && current_user.member_of_course?(c))) + if current_user.nil? raise '403' end #@canShowCode = isCourseTeacher(User.current.id,course) && params[:role] != '1' @@ -458,8 +459,8 @@ class CoursesService joined = StudentsForCourse.where('student_id = ? and course_id = ?', user.id, params[:object_id]) joined.each do |join| join.delete - @state = 0 end + @state = 0 @state end @@ -1284,5 +1285,35 @@ 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 diff --git a/app/services/projects_service.rb b/app/services/projects_service.rb index fc7f25d1f..f3679aa22 100644 --- a/app/services/projects_service.rb +++ b/app/services/projects_service.rb @@ -355,4 +355,67 @@ class ProjectsService end end + #删除项目成员 + def project_delete_member project,user_id,current_user + if current_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.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 diff --git a/app/services/wechat_service.rb b/app/services/wechat_service.rb index 423676983..8adc1392f 100644 --- a/app/services/wechat_service.rb +++ b/app/services/wechat_service.rb @@ -432,4 +432,17 @@ class WechatService end end + def at_notice(user_id, type, id, first, key1, key2,key3,remark="",uid=0) + uw = UserWechat.where(user_id: user_id).first + unless uw.nil? + data = three_keys_template uw.openid,Wechat.config.at_notice, type, id, first, key1, key2, key3, remark,uid + begin + req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) + rescue Exception => e + Rails.logger.error "[at_notice] ===> #{e}" + end + Rails.logger.info "send over. #{req}" + end + end + end \ No newline at end of file diff --git a/app/views/news/_project_show.html.erb b/app/views/news/_project_show.html.erb index 1e3a83c9a..26393f7cb 100644 --- a/app/views/news/_project_show.html.erb +++ b/app/views/news/_project_show.html.erb @@ -26,7 +26,11 @@
暂无课件,
- 请登录Trustie网站,在PC浏览器中上传课件。
暂无作业,
- 请登录Trustie网站,在PC浏览器中上传作业。
暂无测验,
- 请登录Trustie网站,在PC浏览器中上传测验。
暂无课件,
+ 请登录Trustie网站,在PC浏览器中上传课件。
暂无作业,
+ 请登录Trustie网站,在PC浏览器中上传作业。
暂无测验,
+ 请登录Trustie网站,在PC浏览器中上传测验。