From 7c5240b38653fc597eae9525c3b363f97207d4c1 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Thu, 11 Aug 2016 09:58:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=20=E6=B2=A1=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E5=8A=A8=E6=80=81=E5=9B=9E=E5=A4=8D=E4=BC=9A=E8=B7=B3?= =?UTF-8?q?=E5=88=B0=E7=BB=91=E5=AE=9A=E7=99=BB=E5=BD=95=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=EF=BC=8C=E7=A7=81=E6=9C=89=E5=86=85=E5=AE=B9=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E6=98=AF=E6=88=90=E5=91=98=E6=89=8D=E8=83=BD=E5=9B=9E=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/new_comment.rb | 149 +++++++++++++----- app/api/mobile/apis/newss.rb | 4 +- app/services/courses_service.rb | 36 ++--- app/services/wechat_service.rb | 24 +-- config/wechat.yml.template | 1 - config/wechat.yml.test | 1 - public/assets/wechat/blog_detail.html | 2 +- public/assets/wechat/homework_detail.html | 2 +- public/assets/wechat/login_tip.html | 9 +- public/assets/wechat/reg.html | 2 +- .../javascripts/wechat/controllers/login.js | 10 +- .../wechat/controllers/login_tip..js | 7 + public/javascripts/wechat/controllers/reg.js | 7 +- public/javascripts/wechat/others/factory.js | 20 ++- public/javascripts/wechat/others/routes.js | 1 + 15 files changed, 181 insertions(+), 94 deletions(-) create mode 100644 public/javascripts/wechat/controllers/login_tip..js diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb index 5b7159301..10308774f 100644 --- a/app/api/mobile/apis/new_comment.rb +++ b/app/api/mobile/apis/new_comment.rb @@ -14,66 +14,130 @@ module Mobile requires :token, type: String end post ':id' do - authenticate! + # authenticate! + status = 0 + tip = 0 #0班级1项目 type = params[:type] result = 1 if params[:content]!="" && current_user case type when "HomeworkCommon" homework_common = HomeworkCommon.find(params[:id]) - feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id]) - if (feedback.errors.empty?) - homework_common.update_column(:updated_at, Time.now) - result = 2 + + #如果是私有的 并且不是成员则不能回复 + is_public = homework_common.course.is_public + if is_public == 0 && !current_user.member_of_course?(homework_common.course) + status = -1 + tip = 0 + else + feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id]) + if (feedback.errors.empty?) + homework_common.update_column(:updated_at, Time.now) + result = 2 + end end + when "News" news = News.find(params[:id]) - comment = Comment.new - comment.comments = params[:content] - comment.author = current_user - if news.comments << comment - result = 2 + + if news.project + if news.project.is_public == false && !current_user.member_of?(news.project) + status = -1 + tip = 1 + end + elsif news.course + if news.course.is_public == 0 && !current_user.member_of_course?(news.course) + status = -1 + tip = 0 + end + end + + if status == 0 + comment = Comment.new + comment.comments = params[:content] + comment.author = current_user + if news.comments << comment + result = 2 + end end when "Message" message = Message.find(params[:id]) board = Board.find(message.board_id) - topic = message.root - reply = Message.new - reply.author = current_user - reply.board = board - reply.content = params[:content] - reply.parent_id = params[:id] - reply.subject = "RE: #{topic.subject}" - if topic.children << reply - result = 2 + + if message.project + if message.project.is_public == false && !current_user.member_of?(message.project) + status = -1 + tip = 1 + end + elsif message.course + if message.course.is_public == 0 && !current_user.member_of_course?(message.course) + status = -1 + tip = 0 + end + end + + if status == 0 + topic = message.root + reply = Message.new + reply.author = current_user + reply.board = board + reply.content = params[:content] + reply.parent_id = params[:id] + reply.subject = "RE: #{topic.subject}" + if topic.children << reply + result = 2 + end end when "JournalsForMessage" jour = JournalsForMessage.find params[:id] - parent_id = params[:id] - author_id = current_user.id - reply_user_id = jour.user_id - reply_id = params[:id] - content = params[:content] - options = {:user_id => author_id, - :status => true, - :m_parent_id => parent_id, - :m_reply_id => reply_id, - :reply_id => reply_user_id, - :notes => content, - :is_readed => false} - jfm = jour.user.add_jour(nil, nil, nil, options) - if jfm.errors.empty? - (JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now) - result = 2 + + if jour.jour_type == "Project" + if jour.project.is_public == false && !current_user.member_of?(jour.project) + status = -1 + tip = 1 + end + elsif jour.jour_type == "Course" + if jour.course.is_public == 0 && !current_user.member_of_course?(jour.course) + status = -1 + tip = 0 + end + end + + if status == 0 + parent_id = params[:id] + author_id = current_user.id + reply_user_id = jour.user_id + reply_id = params[:id] + content = params[:content] + options = {:user_id => author_id, + :status => true, + :m_parent_id => parent_id, + :m_reply_id => reply_id, + :reply_id => reply_user_id, + :notes => content, + :is_readed => false} + jfm = jour.user.add_jour(nil, nil, nil, options) + if jfm.errors.empty? + (JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now) + result = 2 + end end when 'Issue' issue = Issue.find params[:id] - is_jour = Journal.new - is_jour.user_id = current_user.id - is_jour.notes = params[:content] - is_jour.journalized = issue - if is_jour.save - result = 2 + + if issue.project.is_public == false && !current_user.member_of?(issue.project) + status = -1 + tip = 1 + end + + if status == 0 + is_jour = Journal.new + is_jour.user_id = current_user.id + is_jour.notes = params[:content] + is_jour.journalized = issue + if is_jour.save + result = 2 + end end when 'BlogComment' blog = BlogComment.find(params[:id]).root @@ -97,7 +161,8 @@ module Mobile result = 3 end present :result, result - present :status, 0 + present :status, status + present :tip, tip end end end diff --git a/app/api/mobile/apis/newss.rb b/app/api/mobile/apis/newss.rb index 907958631..c2e2fcb5c 100644 --- a/app/api/mobile/apis/newss.rb +++ b/app/api/mobile/apis/newss.rb @@ -20,8 +20,8 @@ module Mobile if news.project is_public = news.project.is_public - elsif news.project - is_public = news.project.is_public + elsif news.course + is_public = news.course.is_public end present :data, news, with: Mobile::Entities::News,user: user,type: type,page: page diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 81fe9c5f4..7d574bada 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -537,29 +537,25 @@ class CoursesService count = ShieldWechatMessage.where("container_type='User' and container_id=#{user.id} and shield_type='Course' and shield_id=#{course.id}").count if count == 0 ws = WechatService.new - if role_id == 10 && result == 0 + + role_name = role_id == 7 ? "助教" : role_id == 9 ? "教师" : "学生" + result_name = result == 0 ? "通过" : "被拒绝" + content = "您以"+role_name+"身份加入班级的申请已"+result_name+"。" + + if result == 0 title = "恭喜您加入班级成功。" - ws.join_class_notice user.id, "class", course.id,title, course.syllabus.name,course.name,course.teacher.show_name, "点击查看班级详情。" + remark = "点击查看班级详情。" + uid = 0 + type = "class" else - - role_name = role_id == 7 ? "助教" : "教师" - result_name = result == 0 ? "通过" : "被拒绝" - content = "您以"+role_name+"身份加入班级的申请已"+result_name+"。" - - if result == 0 - title = "恭喜您加入班级成功。" - remark = "点击查看班级详情。" - uid = 0 - type = "class" - else - title = "很遗憾您未能成功加入班级。" - remark = "点击查看申请详情。" - uid = user.id - type = "review_class_member" - end - ws = WechatService.new - ws.class_notice user.id, type, course.id, title, course.name, user.show_name, format_time(Time.now), content, remark,uid + title = "很遗憾您未能成功加入班级。" + remark = "点击查看申请详情。" + uid = user.id + type = "review_class_member" end + ws = WechatService.new + ws.class_notice user.id, type, course.id, title, course.name, user.show_name, format_time(Time.now), content, remark,uid + end end diff --git a/app/services/wechat_service.rb b/app/services/wechat_service.rb index 4b120eaa0..4506bf3e4 100644 --- a/app/services/wechat_service.rb +++ b/app/services/wechat_service.rb @@ -296,18 +296,18 @@ class WechatService end end - def join_class_notice(user_id, type, id, first, key1, key2, key3,remark="") - uw = UserWechat.where(user_id: user_id).first - unless uw.nil? - data = three_keys_template uw.openid,Wechat.config.join_class_notice, type, id, first, key1, key2, key3, remark - begin - req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) - rescue Exception => e - Rails.logger.error "[join_class__notice] ===> #{e}" - end - Rails.logger.info "send over. #{req}" - end - end + # def join_class_notice(user_id, type, id, first, key1, key2, key3,remark="") + # uw = UserWechat.where(user_id: user_id).first + # unless uw.nil? + # data = three_keys_template uw.openid,Wechat.config.join_class_notice, type, id, first, key1, key2, key3, remark + # begin + # req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) + # rescue Exception => e + # Rails.logger.error "[join_class__notice] ===> #{e}" + # end + # Rails.logger.info "send over. #{req}" + # end + # end def create_class_notice(user_id, type, id, first, key1, key2, key3, remark="") uw = UserWechat.where(user_id: user_id).first diff --git a/config/wechat.yml.template b/config/wechat.yml.template index f55640d97..ce3008729 100644 --- a/config/wechat.yml.template +++ b/config/wechat.yml.template @@ -23,7 +23,6 @@ default: &default create_class_notice: "2GtJJGzzNlNy2i0UrsjEDlvfSVIUXQfSo47stpcQAVw" create_project_notice: "jYu0iimbDpgWYZaTLXioZe2lvqoWTdKnUPyphTJ1mxs" project_review_notice: "kdb-8UlMjTc3z51Qcf8g2vY4i_nE4OGKZAucdQma_2E" - join_class_notice: "0V2vhhp5co7drgoyqn3WXUUTQ9xwYrnVcMma7ika6o0" join_project_notice: "TtXvy0XMIQyCgpnXHhoB8t-x0QIfy-78gAJXsGf9afg" production: <<: *default diff --git a/config/wechat.yml.test b/config/wechat.yml.test index a49282c1a..a5339d398 100644 --- a/config/wechat.yml.test +++ b/config/wechat.yml.test @@ -23,7 +23,6 @@ default: &default create_class_notice: "9CDIvHIKiGwPEQWRw_-wieec1o50tMXQPPZIfECKu0I" create_project_notice: "R2ZaQKJfDJgujPcHWPzadKHIRkIyj2CjX2o_qIuRqig" project_review_notice: "ip192wVXTav3qchgUn9_7B6lFfTlCZjwL7A1tncTOuc" - join_class__notice: "umHZyT8n6KPf3emf4sTJ66I8OB_TJTzjYhxDbJUgUis" join_project_notice: "3KnMQEMUCmQWkB5JvzrpmguEwnN8bvUHUdpOTudxv_M" production: diff --git a/public/assets/wechat/blog_detail.html b/public/assets/wechat/blog_detail.html index a4c24e3d4..c1e2fd2fd 100644 --- a/public/assets/wechat/blog_detail.html +++ b/public/assets/wechat/blog_detail.html @@ -73,7 +73,7 @@