diff --git a/.gitignore b/.gitignore index 38f29a661..0727a920a 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,4 @@ vendor/cache /public/files /tags /config/initializers/gitlab_config.rb -/config/wechat.yml -/config/menu.yml 1234567 diff --git a/Gemfile b/Gemfile index a599613ba..d392c6561 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source 'https://rubygems.org/' +source 'https://ruby.taobao.org/' ### ����ִ��bundle config mirror.https://rubygems.org https://gems.ruby-china.org �л���ruby-chinaԴ unless RUBY_PLATFORM =~ /w32/ diff --git a/app/api/mobile/apis/activities.rb b/app/api/mobile/apis/activities.rb index cbd43bb79..af17e0f44 100644 --- a/app/api/mobile/apis/activities.rb +++ b/app/api/mobile/apis/activities.rb @@ -13,34 +13,18 @@ module Mobile end post do user = UserWechat.find_by_openid(params[:openid]).user -=begin - shield_project_ids = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id) - shield_course_ids = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id) - page = params[:page] ? params[:page] : 0 - user_project_ids = (user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")" - user_course_ids = (user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")" - course_types = "('Message','News','HomeworkCommon','Poll','Course')" - project_types = "('Message','Issue','ProjectCreateInfo')" - principal_types = "JournalsForMessage" - - blog_ids = "("+user.blog.id.to_s+","+((User.watched_by(user.id).count == 0 )? '0' :User.watched_by(user.id).map{|u| u.blog.id}.join(','))+")" - activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + - "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ - "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{user.id}) " + - "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc') -=end shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id) shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id) page = params[:page] ? params[:page] : 0 - user_project_ids = (user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.map{|project| project.id}-shield_project_ids).join(",") + ")" - user_course_ids = (user.courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.map{|course| course.id}-shield_course_ids).join(",") + ")" + user_project_ids = (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).join(",") + ")" + user_course_ids = (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")" course_types = "('Message','News','HomeworkCommon','Poll','Course')" project_types = "('Message','Issue','Project')" principal_types = "JournalsForMessage" watched_user_ids = User.watched_by(user.id).count == 0 ? " " : ("," + User.watched_by(user.id).map{|u| u.id.to_s }.join(',')) user_ids = "(" + user.id.to_s + watched_user_ids + ")" - watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}").map { |blog| blog.id}.join(",") + watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}").count == 0 ? " " :Blog.select("id").where("author_id in #{user_ids}").map { |blog| blog.id}.join(",") blog_ids = "(" + watched_user_blog_ids + ")" activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + diff --git a/app/api/mobile/entities/activity.rb b/app/api/mobile/entities/activity.rb index a90ff323d..9e2a39a5a 100644 --- a/app/api/mobile/entities/activity.rb +++ b/app/api/mobile/entities/activity.rb @@ -98,6 +98,7 @@ module Mobile end expose :act_type #缺陷/作业/讨论区/留言等类型 expose :act_id + expose :id expose :container_type #课程/项目/博客/个人 expose :author, using: Mobile::Entities::User do |a, opt| #用户信息 if a.is_a? ::UserActivity diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 17f62f18c..e421b8c69 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -304,7 +304,7 @@ class CoursesController < ApplicationController @render_file = 'new_member_list' @score_sort_by = "desc" - @sort_type = "score" + @sort_type = params[:sort_type] ? params[:sort_type] : "score" @canShowCode = User.current.allowed_to?(:as_teacher,@course) && params[:role] != '1' @role = params[:role].nil? ? '2':params[:role] @is_remote = true @@ -319,7 +319,7 @@ class CoursesController < ApplicationController if @course.open_student == 1 || User.current.member_of_course?(@course) @subPage_title = l :label_student_list page = params[:page].nil? ? 0 : (params['page'].to_i - 1) - @all_members = student_homework_score(0,page, 10,@score_sort_by) + @all_members = student_homework_score(0,page, 10,@score_sort_by,@sort_type) @members = @all_members else render_403 diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index b1d16debb..8ef399d10 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -304,7 +304,7 @@ class MessagesController < ApplicationController @content = "> #{ll(Setting.default_language, :text_user_wrote, @message.author)}\n> " @temp = Message.new - @temp.content = "
#{ll(Setting.default_language, :text_user_wrote, @message.author)}".html_safe + @temp.content = "
#{@message.content.html_safe}
#{ll(Setting.default_language, :text_user_wrote, @message.author.show_name)}".html_safe end def preview diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 3cbfc8466..a0ef84798 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -563,13 +563,23 @@ class OrganizationsController < ApplicationController # 设置为名师 def set_excellent_teacher @ex_teacher = User.find(params[:user]) - params[:type] == "student" ? @ex_teacher.update_column(:excellent_student, 1) : @ex_teacher.update_column(:excellent_teacher, 1) + @ex_teacher.update_column(:excellent_teacher, 1) end # 取消名师 def reset_excellent_teacher @ex_teacher = User.find(params[:user]) - params[:type] == "student" ? @ex_teacher.update_column(:excellent_student, 0) : @ex_teacher.update_column(:excellent_teacher, 0) + @ex_teacher.update_column(:excellent_teacher, 0) + end + + def set_excellent_student + @ex_student = User.find(params[:user]) + @ex_student.update_column(:excellent_student, 1) + end + + def reset_excellent_student + @ex_student = User.find(params[:user]) + @ex_student.update_column(:excellent_student, 0) end def hide_org_subfield diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index dd178a1ce..10431f01a 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -390,7 +390,7 @@ class StudentWorkController < ApplicationController student_in_group = '(' + group_students.map{|user| user.id}.join(',') + ')' end #开放作品 || 老师 || 超级管理员 || 禁用匿评&&作业截止&&已提交作品 显示所有列表 - if @homework.is_open == 1 || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?) + if (@homework.is_open == 1 && @course.is_public == 1) || (@homework.is_open == 1 && @course.is_public == 0 && User.current.member_of_course?(@course)) || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?) if @order == 'lastname' @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name elsif @order == 'student_id' @@ -456,7 +456,7 @@ class StudentWorkController < ApplicationController @student_work_count = (search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name).count else - if @homework.is_open == 1 || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?) + if (@homework.is_open == 1 &&@course.is_public == 1) || (@homework.is_open == 1 && @course.is_public == 0 && User.current.member_of_course?(@course)) || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?) if @order == 'lastname' @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name elsif @order == 'student_id' diff --git a/app/controllers/sub_document_comments_controller.rb b/app/controllers/sub_document_comments_controller.rb index 80c14f004..d6b335006 100644 --- a/app/controllers/sub_document_comments_controller.rb +++ b/app/controllers/sub_document_comments_controller.rb @@ -1,7 +1,7 @@ class SubDocumentCommentsController < ApplicationController before_filter :find_subdomain_and_subfield, :only => [:new, :create, :show, :index, :destroy, :edit] before_filter :find_subfield_content, :only => [:show, :index] - before_filter :authorize_allowed, :only => [:create, :add_reply] + before_filter :authorize_allowed, :only => [:create] helper :attachments,:organizations layout 'base_sub_domain' diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 52c5f70bc..f5689ef64 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -570,7 +570,7 @@ class UsersController < ApplicationController end if !params[:search].nil? search = "%#{params[:search].to_s.strip.downcase}%" - @course = @user.courses.where("is_delete = 0 and #{Course.table_name}.id != #{homework.course_id} and #{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p",:p=>search).select { |course| @user.allowed_to?(:as_teacher,course)} + @course = @user.courses.where("is_delete = 0 and #{Course.table_name}.id != #{homework.course_id} and (#{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p)",:p=>search).select { |course| @user.allowed_to?(:as_teacher,course)} else @course = @user.courses.where("is_delete = 0 and #{Course.table_name}.id != #{homework.course_id}").select { |course| @user.allowed_to?(:as_teacher,course)} end diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index a37b5aaa2..ef59e0ed4 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -154,12 +154,7 @@ class WechatsController < ActionController::Base end end - - - ### controller method - - module Controllers def get_open_id begin @@ -167,7 +162,6 @@ class WechatsController < ActionController::Base code = params[:code] || session[:wechat_code] openid = get_openid_from_code(code) - raise "无法获取到微信openid" unless openid render :json => {status:0, openid: openid} rescue Exception=>e @@ -194,6 +188,8 @@ class WechatsController < ActionController::Base openid: openid, user: user ) + ws = WechatService.new + ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台", user.login, format_time(Time.now)) render :json => {status:0, msg: "绑定成功"} rescue Exception=>e render :json => {status: -1, msg: e.message} @@ -202,9 +198,25 @@ class WechatsController < ActionController::Base def login session[:wechat_code] = params[:code] if params[:code] + openid = get_openid_from_code(params[:code]) + @wechat_user = user_binded?(openid) + render 'wechats/login', layout: 'base_wechat' end + def user_activities + session[:wechat_code] = params[:code] if params[:code] + code = params[:code] || session[:wechat_code] + openid = get_openid_from_code(code) + @wechat_user = user_binded?(openid) + unless @wechat_user + redirect_to login_wechat_path + return + end + + render 'wechats/user_activities', layout: nil + end + private def get_openid_from_code(code) openid = session[:wechat_openid] @@ -226,37 +238,8 @@ class WechatsController < ActionController::Base uw = UserWechat.where(openid: openid).first end - def user_activity(user) - @user = user - shield_project_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id) - shield_course_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id) - @page = params[:page] ? params[:page].to_i + 1 : 0 - user_project_ids = (@user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")" - user_course_ids = (@user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")" - course_types = "('Message','News','HomeworkCommon','Poll','Course')" - project_types = "('Message','Issue','Project')" - principal_types = "JournalsForMessage" - - blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" - @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + - "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ - "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + - "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10) - end - - def process_activity(user_activity) - act= user_activity.act - case user_activity.container_type.to_s - when 'Course' - when 'Project' - case user_activity.act_type.to_s - when 'Issue' - [act.project.name.to_s+" | 项目问题", act.subject.to_s, url_to_avatar(act.author),"http://wechat.trustie.net/app.html#/issue/#{act.id}"] - end - end - end end diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index 386e5733d..d9a9e1def 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -10,14 +10,14 @@ class ZipdownController < ApplicationController #勿删 before_filter :authorize, :only => [:assort,:download_user_homework] SAVE_FOLDER = "#{Rails.root}/files" OUTPUT_FOLDER = "#{Rails.root}/files/archiveZip" + MAX_PATH = 50 #统一下载功能 def download if User.current.logged? begin if params[:base64file] - file = Base64.decode64(params[:base64file]) - file = file.sub('*', '+') + file = decode64(params[:base64file]) send_file "#{OUTPUT_FOLDER}/#{file}", :filename => filename_for_content_disposition(file), :type => detect_content_type(file) else send_file "#{OUTPUT_FOLDER}/#{params[:file]}", :filename => filename_for_content_disposition(params[:filename]), :type => detect_content_type(params[:file]) @@ -125,7 +125,11 @@ class ZipdownController < ApplicationController end def encode64(str) - Base64.encode64(str).sub('+', '*') + Base64.urlsafe_encode64(str) + end + + def decode64(str) + Base64.urlsafe_decode64(str) end def zip_homework_common homework_common @@ -242,6 +246,12 @@ class ZipdownController < ApplicationController def zipping(zip_name_refer, files_paths, output_path, is_attachment=false, not_exist_file=[]) rename_zipfile = zip_name_refer ||= "#{Time.now.to_i.to_s}.zip" + # 文件名过长 + + if rename_zipfile.size > MAX_PATH + rename_zipfile = rename_zipfile[0,rename_zipfile.size-4][0,MAX_PATH-4] + rename_zipfile[-4,4] + end + zipfile_name = "#{output_path}/#{rename_zipfile}" Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name)) diff --git a/app/helpers/api_helper.rb b/app/helpers/api_helper.rb index 49640d889..fb1231287 100644 --- a/app/helpers/api_helper.rb +++ b/app/helpers/api_helper.rb @@ -182,7 +182,7 @@ module ApiHelper timeIntoFormat = 0 updateAtValue = "" if timePassed < 0 - updateAtValue = "时间有问题" + updateAtValue = "刚刚" elsif timePassed < ONE_MINUTE updateAtValue = "1分钟前" elsif timePassed < ONE_HOUR diff --git a/app/helpers/organizations_helper.rb b/app/helpers/organizations_helper.rb index e6fd7591f..fa0d33f6e 100644 --- a/app/helpers/organizations_helper.rb +++ b/app/helpers/organizations_helper.rb @@ -181,7 +181,7 @@ module OrganizationsHelper if User.current.admin? @organization.org_subfields.order("priority") else - @organization.org_subfields.select { |os| (os.field_type != "Comptec" && os.field_type != "Compstu") }.sort_by {|os| os.priority} + @organization.org_subfields.select { |os| (os.field_type != "Comptec" && os.field_type != "Compstu" && os.field_type != "Comppro" && os.field_type != "Compcou" && os.field_type != "Compact") }.sort_by {|os| os.priority} end end diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb index af21b4f69..05ae02fe2 100644 --- a/app/models/blog_comment.rb +++ b/app/models/blog_comment.rb @@ -21,7 +21,7 @@ class BlogComment < ActiveRecord::Base after_save :add_user_activity after_update :update_activity - after_create :update_parent_time, :blog_wechat_message + after_create :update_parent_time before_destroy :destroy_user_activity scope :like, lambda {|arg| @@ -77,16 +77,16 @@ class BlogComment < ActiveRecord::Base end #博客回复微信模板消息 - def blog_wechat_message - ws = WechatService.new - if self.parent_id.nil? - self.author.watcher_users.each do |watcher| - content = strip_html self.author.try(:realname) + " 发表了博客:" + self.title.html_safe, 200 - ws.message_update_template watcher.id, "blog_comment", self.id, "#{l(:label_new_blog_template)}", content, format_time(self.created_at) - end - else - content = strip_html self.content.html_safe, 200 - ws.comment_template self.parent.author_id, "blog_comment", self.parent_id, "#{l(:label_blog_comment_template)}", self.author.try(:realname), format_time(self.created_at), content - end - end + # def blog_wechat_message + # ws = WechatService.new + # if self.parent_id.nil? + # self.author.watcher_users.each do |watcher| + # content = strip_html self.author.try(:realname) + " 发表了博客:" + self.title.html_safe, 200 + # ws.message_update_template watcher.id, "blog_comment", self.id, "#{l(:label_new_blog_template)}", content, format_time(self.created_at) + # end + # else + # content = strip_html self.content.html_safe, 200 + # ws.comment_template self.parent.author_id, "blog_comment", self.parent_id, "#{l(:label_blog_comment_template)}", self.author.try(:realname), format_time(self.created_at), content + # end + # end end diff --git a/app/models/comment.rb b/app/models/comment.rb index 8632c243a..edb5e472f 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -41,15 +41,15 @@ class Comment < ActiveRecord::Base after_destroy :down_course_score def act_as_system_message - ws = WechatService.new + #ws = WechatService.new if self.commented.course if self.author_id != self.commented.author_id self.course_messages << CourseMessage.new(:user_id => self.commented.author_id, :course_id => self.commented.course.id, :viewed => false) - count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.commented.author_id} and shield_type='Course' and shield_id=#{self.commented.course.id}").count - if count == 0 - content = strip_html self.comments.html_safe, 200 - ws.comment_template self.commented.author_id, "course_notice", self.id, "#{l(:label_notice_comment_template)}", self.author.try(:realname), format_time(self.created_on), content - end + # count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.commented.author_id} and shield_type='Course' and shield_id=#{self.commented.course.id}").count + # if count == 0 + # content = strip_html self.comments.html_safe, 200 + # ws.comment_template self.commented.author_id, "course_notice", self.id, "#{l(:label_notice_comment_template)}", self.author.try(:realname), format_time(self.created_on), content + # end end else # 项目相关 if self.author_id != self.commented.author_id diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index e4426e78f..a915b1545 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -30,7 +30,7 @@ class HomeworkCommon < ActiveRecord::Base :author => :author, :url => Proc.new {|o| {:controller => 'student_work', :action => 'index', :homework => o.id}} after_create :act_as_activity, :send_mail,:act_as_course_message - after_update :update_activity, :wechat_message + after_update :update_activity after_save :act_as_course_activity after_destroy :delete_kindeditor_assets @@ -63,7 +63,7 @@ class HomeworkCommon < ActiveRecord::Base count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count if count == 0 ws = WechatService.new - ws.homework_template(m.user_id, "homework", self.id, "#{l(:label_new_homework_template)}", self.course.name, self.name.html_safe, self.end_time.to_s + " 23:59:59") + ws.homework_message_notice(m.user_id, "homework", self.id, "#{m.user.show_name},#{l(:label_new_homework_template)}:", self.course.name, "新作业:"+ self.name.html_safe, "作业内容请点击“详情”查看。") end # end end @@ -108,15 +108,15 @@ class HomeworkCommon < ActiveRecord::Base end #修改作业后发送微信模板消息 - def wechat_message - self.course.members.each do |member| - count = ShieldWechatMessage.where("container_type='User' and container_id=#{member.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count - if count == 0 - ws = WechatService.new - ws.homework_template(member.user_id, "homework", self.id, "#{l(:label_update_homework_template)}", self.course.name, self.name.html_safe, self.end_time.to_s + " 23:59:59") - end - end - end + # def wechat_message + # self.course.members.each do |member| + # count = ShieldWechatMessage.where("container_type='User' and container_id=#{member.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count + # if count == 0 + # ws = WechatService.new + # ws.homework_template(member.user_id, "homework", self.id, "#{l(:label_update_homework_template)}", self.course.name, self.name.html_safe, self.end_time.to_s + " 23:59:59") + # end + # end + # end delegate :language_name, :language, :to => :homework_detail_programing diff --git a/app/models/issue.rb b/app/models/issue.rb index b5e87feea..4cfea1f43 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -160,27 +160,27 @@ class Issue < ActiveRecord::Base unless self.author_id == self.assigned_to_id self.forge_messages << ForgeMessage.new(:user_id => self.assigned_to_id, :project_id => self.project_id, :viewed => false) end - self.project.members.each do |m| - count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Project' and shield_id=#{self.project_id}").count - if m.user_id != self.author_id && count == 0 - ws = WechatService.new - str = " 有新缺陷了: " - case self.tracker_id - when 1 - str = " 有新缺陷了: " - when 2 - str = " 有新功能了: " - when 3 - str = " 有新支持了: " - when 4 - str = " 有新任务了: " - when 5 - str = " 有新周报了: " - end - content = strip_html self.project.name + str + self.subject.html_safe, 200 - ws.message_update_template m.user_id, "issues", self.id, "#{l(:label_new_issue_template)}", content, format_time(self.created_on) - end - end + # self.project.members.each do |m| + # count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Project' and shield_id=#{self.project_id}").count + # if m.user_id != self.author_id && count == 0 + # ws = WechatService.new + # str = " 有新缺陷了: " + # case self.tracker_id + # when 1 + # str = " 有新缺陷了: " + # when 2 + # str = " 有新功能了: " + # when 3 + # str = " 有新支持了: " + # when 4 + # str = " 有新任务了: " + # when 5 + # str = " 有新周报了: " + # end + # content = strip_html self.project.name + str + self.subject.html_safe, 200 + # ws.message_update_template m.user_id, "issues", self.id, "#{l(:label_new_issue_template)}", content, format_time(self.created_on) + # end + # end if self.tracker_id == 5 self.project.members.each do |m| if m.roles.first.to_s.include?("Manager") && m.user_id != self.author_id && m.user_id != self.assigned_to_id diff --git a/app/models/journal.rb b/app/models/journal.rb index eeaa17dd6..bea273a41 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -55,7 +55,6 @@ class Journal < ActiveRecord::Base # fq after_save :act_as_activity,:be_user_score, :act_as_forge_message, act_as_at_message(:notes, :user_id) - after_create :issue_wechat_message # end #after_destroy :down_user_score #before_save :be_user_score @@ -238,11 +237,11 @@ class Journal < ActiveRecord::Base end #缺陷回复微信模板消息 - def issue_wechat_message - if !self.notes.nil? && self.notes.gsub(' ','') != '' - ws = WechatService.new - content = strip_html self.notes.html_safe, 200 - ws.comment_template self.issue.author_id, "issues", self.journalized_id, "#{l(:label_issue_comment_template)}", self.user.try(:realname), format_time(self.created_on), content - end - end + # def issue_wechat_message + # if !self.notes.nil? && self.notes.gsub(' ','') != '' + # ws = WechatService.new + # content = strip_html self.notes.html_safe, 200 + # ws.comment_template self.issue.author_id, "issues", self.journalized_id, "#{l(:label_issue_comment_template)}", self.user.try(:realname), format_time(self.created_on), content + # end + # end end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index d0113744c..d8819515c 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -259,24 +259,24 @@ class JournalsForMessage < ActiveRecord::Base if self.m_parent_id.nil? if self.user_id != self.jour.user_id self.course_messages << CourseMessage.new(:user_id => self.jour.user_id,:course_id => self.jour.course.id, :viewed => false) - count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.jour.user_id} and shield_type='Course' and shield_id=#{self.jour.course_id}").count - if count == 0 - ws = WechatService.new - #content = truncate(strip_tags(self.notes.to_s), length: 200) - content = strip_html self.notes.html_safe, 200 - ws.comment_template self.jour.user_id, "homework", self.jour_id, "#{l(:label_homework_comment_template)}", self.user.try(:realname), format_time(self.created_on), content - end + # count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.jour.user_id} and shield_type='Course' and shield_id=#{self.jour.course_id}").count + # if count == 0 + # ws = WechatService.new + # #content = truncate(strip_tags(self.notes.to_s), length: 200) + # content = strip_html self.notes.html_safe, 200 + # ws.comment_template self.jour.user_id, "homework", self.jour_id, "#{l(:label_homework_comment_template)}", self.user.try(:realname), format_time(self.created_on), content + # end end else if self.user_id != self.parent.user_id self.course_messages << CourseMessage.new(:user_id => self.parent.user_id,:course_id => self.jour.course.id, :viewed => false) - count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.parent.user_id} and shield_type='Course' and shield_id=#{self.jour.course_id}").count - if count == 0 - ws = WechatService.new - #content = truncate(strip_tags(self.notes.to_s), length: 200) - content = strip_html self.notes.html_safe, 200 - ws.comment_template self.parent.user_id, "homework", self.jour_id, "#{l(:label_new_second_comment_template)}", self.user.try(:realname), format_time(self.created_on), content - end + # count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.parent.user_id} and shield_type='Course' and shield_id=#{self.jour.course_id}").count + # if count == 0 + # ws = WechatService.new + # #content = truncate(strip_tags(self.notes.to_s), length: 200) + # content = strip_html self.notes.html_safe, 200 + # ws.comment_template self.parent.user_id, "homework", self.jour_id, "#{l(:label_new_second_comment_template)}", self.user.try(:realname), format_time(self.created_on), content + # end end end end @@ -293,7 +293,7 @@ class JournalsForMessage < ActiveRecord::Base if self.user_id != self.jour_id # 过滤自己给自己的留言消息 receivers << self.jour content = strip_html self.notes, 200 - ws.message_update_template self.jour_id, "journal_for_message", self.id, "#{l(:label_new_journals_template)}", content, format_time(self.created_on) + ws.journal_notice self.jour_id, "journal_for_message", self.id, "#{l(:label_new_journals_template)}", self.user.show_name, format_time(self.created_on),content end else # 留言回复 reply_to = User.find(self.reply_id) @@ -303,8 +303,8 @@ class JournalsForMessage < ActiveRecord::Base if self.user_id != self.parent.jour_id && self.reply_id != self.parent.jour_id # 给东家发信息,如果回复的对象是东家则不发 receivers << self.parent.jour end - content = strip_html self.notes, 200 - ws.comment_template self.reply_id, "journal_for_message", self.parent.id, "#{l(:label_journals_comment_template)}", self.user.try(:realname), format_time(self.created_on), content + #content = strip_html self.notes, 200 + #ws.comment_template self.reply_id, "journal_for_message", self.parent.id, "#{l(:label_journals_comment_template)}", self.user.try(:realname), format_time(self.created_on), content end receivers.each do |r| self.user_feedback_messages << UserFeedbackMessage.new(:user_id => r.id, :journals_for_message_id => self.id, :journals_for_message_type => "Principal", :viewed => false) diff --git a/app/models/message.rb b/app/models/message.rb index cf9adab4e..393fd3a60 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -258,28 +258,28 @@ class Message < ActiveRecord::Base # 主贴项目成员都能收到 # 回帖:帖子的发布人收到 def act_as_system_message - ws = WechatService.new + #ws = WechatService.new if self.course if self.parent_id.nil? # 主贴 self.course.members.includes(:user).each do |m| if self.author.allowed_to?(:as_teacher, self.course) && m.user_id != self.author_id # 老师 自己的帖子不给自己发送消息 #self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false) - count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course.id}").count - if count == 0 - content = strip_html self.subject, 200 - ws.topic_publish_template m.user_id, "course_discussion", self.id, "#{l(:label_course_topic_template)}", content, self.author.try(:realname), format_time(self.created_on) - end + # count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course.id}").count + # if count == 0 + # content = strip_html self.subject, 200 + # ws.topic_publish_template m.user_id, "course_discussion", self.id, "#{l(:label_course_topic_template)}", content, self.author.try(:realname), format_time(self.created_on) + # end end end else # 回帖 parent_author_id = Message.find(self.parent_id).author_id if parent_author_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息 self.course_messages << CourseMessage.new(:user_id => parent_author_id, :course_id => self.board.course_id, :viewed => false) - count = ShieldWechatMessage.where("container_type='User' and container_id=#{parent_author_id} and shield_type='Course' and shield_id=#{self.board.course_id}").count - if count == 0 - content = strip_html self.content.html_safe, 200 - ws.comment_template parent_author_id, "course_discussion", self.parent_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content - end + # count = ShieldWechatMessage.where("container_type='User' and container_id=#{parent_author_id} and shield_type='Course' and shield_id=#{self.board.course_id}").count + # if count == 0 + # content = strip_html self.content.html_safe, 200 + # ws.comment_template parent_author_id, "course_discussion", self.parent_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content + # end end end elsif self.project # 项目相关 @@ -287,22 +287,22 @@ class Message < ActiveRecord::Base self.project.members.includes(:user).each do |m| if m.user_id != self.author_id #self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.board.project_id, :viewed => false) - count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Project' and shield_id=#{self.project.id}").count - if count == 0 - content = strip_html self.subject, 200 - ws.topic_publish_template m.user_id, "project_discussion", self.id, "#{l(:label_project_topic_template)}", content, self.author.try(:realname), format_time(self.created_on) - end + # count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Project' and shield_id=#{self.project.id}").count + # if count == 0 + # content = strip_html self.subject, 200 + # ws.topic_publish_template m.user_id, "project_discussion", self.id, "#{l(:label_project_topic_template)}", content, self.author.try(:realname), format_time(self.created_on) + # end end end else # 回帖 parent_author_id = Message.find(self.parent_id).author_id if parent_author_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息 self.forge_messages << ForgeMessage.new(:user_id => parent_author_id, :project_id => self.board.project_id, :viewed => false) - count = ShieldWechatMessage.where("container_type='User' and container_id=#{parent_author_id} and shield_type='Project' and shield_id=#{self.board.project_id}").count - if count == 0 - content = strip_html self.content.html_safe, 200 - ws.comment_template parent_author_id, "project_discussion", self.parent_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content - end + # count = ShieldWechatMessage.where("container_type='User' and container_id=#{parent_author_id} and shield_type='Project' and shield_id=#{self.board.project_id}").count + # if count == 0 + # content = strip_html self.content.html_safe, 200 + # ws.comment_template parent_author_id, "project_discussion", self.parent_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content + # end end end end diff --git a/app/models/news.rb b/app/models/news.rb index 0b03dcc48..54f6fce08 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -174,7 +174,7 @@ class News < ActiveRecord::Base if count == 0 ws = WechatService.new content = strip_html self.author.try(:realname) + " 发布了通知:" + self.title.html_safe, 200 - ws.message_update_template m.user_id, "course_notice", self.id, "#{l(:label_new_notice_template)}", content, format_time(self.created_on) + ws.class_notice m.user_id, "course_notice", self.id, "#{l(:label_new_notice_template)}", self.course.name, self.author.show_name, format_time(self.created_on), content, "点击查看通知详情" end end end diff --git a/app/services/wechat_service.rb b/app/services/wechat_service.rb index 6d8c0f234..3169763c4 100644 --- a/app/services/wechat_service.rb +++ b/app/services/wechat_service.rb @@ -110,4 +110,144 @@ class WechatService Rails.logger.info "send over. #{req}" end end + + def two_keys_template(openid, template_id, type, id, first, key1, key2, remark="") + data = { + touser:openid, + template_id:template_id, + url:"#{Setting.protocol}://#{Setting.host_name}/assets/wechat/app.html#/#{type}/#{id}", + topcolor:"#FF0000", + data:{ + first: { + value:first, + color:"#707070" + }, + keyword1:{ + value:key1, + color:"#707070" + }, + keyword2:{ + value:key2, + color:"#707070" + }, + remark:{ + value:remark, + color:"#707070" + } + } + } + data + end + + def four_keys_template(openid, template_id, type, id, first, key1, key2, key3, key4, remark="") + data = { + touser:openid, + template_id:template_id, + url:"#{Setting.protocol}://#{Setting.host_name}/assets/wechat/app.html#/#{type}/#{id}", + topcolor:"#FF0000", + data:{ + first: { + value:first, + color:"#707070" + }, + keyword1:{ + value:key1, + color:"#707070" + }, + keyword2:{ + value:key2, + color:"#707070" + }, + keyword3:{ + value:key3, + color:"#707070" + }, + keyword4:{ + value:key4, + color:"#707070" + }, + remark:{ + value:remark, + color:"#707070" + } + } + } + data + end + + def binding_succ_notice(user_id, first, key1, key2) + uw = UserWechat.where(user_id: user_id).first + unless uw.nil? + data = { + touser:uw.openid, + template_id:Wechat.config.binding_succ_notice, + url:"#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities", + topcolor:"#FF0000", + data:{ + first: { + value:first, + color:"#707070" + }, + keyword1:{ + value:key1, + color:"#707070" + }, + keyword2:{ + value:key2, + color:"#707070" + }, + remark:{ + value:"绑定成功后可使用微信查看Trustie平台最新动态", + color:"#707070" + } + } + } + begin + req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) + rescue Exception => e + Rails.logger.error "[homework] ===> #{e}" + end + Rails.logger.info "send over. #{req}" + end + end + + def journal_notice(user_id, type, id, first, key1, key2, remark="") + uw = UserWechat.where(user_id: user_id).first + unless uw.nil? + data = two_keys_template uw.openid,Wechat.config.journal_notice, type, id, first, key1, key2, remark + begin + req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) + rescue Exception => e + Rails.logger.error "[homework] ===> #{e}" + end + Rails.logger.info "send over. #{req}" + end + end + + def homework_message_notice(user_id, type, id, first, key1, key2, remark="") + uw = UserWechat.where(user_id: user_id).first + unless uw.nil? + data = two_keys_template uw.openid,Wechat.config.homework_message_notice, type, id, first, key1, key2, remark + begin + req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) + rescue Exception => e + Rails.logger.error "[homework] ===> #{e}" + end + Rails.logger.info "send over. #{req}" + end + end + + def class_notice(user_id, type, id, first, key1, key2, key3, key4, remark="") + uw = UserWechat.where(user_id: user_id).first + unless uw.nil? + data = four_keys_template uw.openid,Wechat.config.class_notice, type, id, first, key1, key2, key3, key4, remark + begin + req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) + rescue Exception => e + Rails.logger.error "[homework] ===> #{e}" + end + Rails.logger.info "send over. #{req}" + end + end + end \ No newline at end of file diff --git a/app/views/courses/_course_activity_users.html.erb b/app/views/courses/_course_activity_users.html.erb index a0cac45f7..93e0e7b77 100644 --- a/app/views/courses/_course_activity_users.html.erb +++ b/app/views/courses/_course_activity_users.html.erb @@ -1,6 +1,11 @@ <% unless contributor_course_scor(course.id).count == 0 %>
#{@message.content.html_safe}
本次作业的所有作品将对Trustie平台所有注册用户开放,请问是否确定公开作品?
+ <% elsif @homework.is_open == 0 && @homework.course.is_public == 0 %> ++ 该作业是私有课程的作业,公开作品后本次作业的所有作品将对课程内的所有学生开放,请问是否确定公开作品? +
+ <% elsif @homework.is_open == 1 && @homework.course.is_public == 0 %> ++ 您将取消“公开作品”的功能,该私有作业的作品将只在作业截止后对已提交作品的学生开放,请问是否确定? +
<% else %>diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index a9e859448..c3f3a4a60 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -157,9 +157,9 @@
<%= time_from_now(message.created_on) %><%= link_to message.author.show_name, user_path(message.author), :class => "por_hot_name link-blue", :target => "_blank" %>
<%=render :partial =>"organizations/organization_content_extension", :locals => {:user_activity_id => message.id, :content=> content, :maxheight => 80, :maxwordsnum => 90, :maxwidth => 0, :cl => "por_hot_txt_r"} %><%= time_from_now(news.created_on) %><%= link_to news.author.show_name, user_path(news.author), :class => "por_hot_name link-blue", :target => "_blank" %>
<%=render :partial =>"organizations/organization_content_extension", :locals => {:user_activity_id => news.id, :content=> news.description, :maxheight => 80, :maxwordsnum => 90, :maxwidth => 0, :cl => "por_hot_txt_r"} %>该模块暂时没有相关内容
<% else %> - <% container = containers.first %> -@@ -62,4 +80,7 @@ }) }); - \ No newline at end of file + + + +<% end %> \ No newline at end of file diff --git a/app/views/wechats/user_activities.html.erb b/app/views/wechats/user_activities.html.erb new file mode 100644 index 000000000..b45587ae0 --- /dev/null +++ b/app/views/wechats/user_activities.html.erb @@ -0,0 +1,30 @@ + + +
+\s*<\/p>/g,""); +// range.moveToBookmark(bookmark); +// } + cmd.selection(); }); if (_WEBKIT) { K(doc).click(function(e) { @@ -3824,9 +3837,20 @@ _extend(KEdit, KWidget, { if (!self.designMode) { val = self.html(); self.designMode = true; - self.html(val); + + //self.html(val); + //self.textarea.hide(); + //self.iframe.show(); + //新加 self.textarea.hide(); - self.iframe.show(); + self.html(val); + var iframe = self.iframe; + var height = _removeUnit(self.height); + iframe.height(height - 2); + iframe.show(); + setTimeout(function() { + iframe.height(height); + }, 0); } } else { if (self.designMode) { @@ -3958,7 +3982,7 @@ _extend(KToolbar, KWidget, { }else if(!$("#full",container).is(':hidden')){ pdiv = $("#full",container); } - return (this._itemMap[name] = K('span.ke-icon-' + name, pdiv).parent()); + return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent()); }, select : function(name) { _selectToolbar.call(this, name, function(knode) { @@ -4864,6 +4888,11 @@ KEditor.prototype = { }, loadPlugin : function(name, fn) { var self = this; + //新加 + var _pluginStatus = this._pluginStatus; + if (!_pluginStatus) { + _pluginStatus = this._pluginStatus = {}; + } if (_plugins[name]) { if (!_isFunction(_plugins[name])) { setTimeout(function() { @@ -4871,7 +4900,12 @@ KEditor.prototype = { }, 100); return self; } - _plugins[name].call(self, KindEditor); + //_plugins[name].call(self, KindEditor); + //新加 + if(!_pluginStatus[name]) { + _plugins[name].call(self, KindEditor); + _pluginStatus[name] = 'inited'; + } if (fn) { fn.call(self); } @@ -5510,6 +5544,11 @@ function _create(expr, options) { _each(_plugins, function(name, fn) { if (_isFunction(fn)) { fn.call(editor, KindEditor); + //新加 + if (!editor._pluginStatus) { + editor._pluginStatus = {}; + } + editor._pluginStatus[name] = 'inited'; } }); return editor.create(); @@ -5772,13 +5811,14 @@ _plugin('core', function(K) { click : function() { self.select().exec('formatblock', '<' + key + '>').hideMenu(); //by yk利用html的特性使h1 h2 h3 h4标签之间不能相互包含 并将空的标签去掉 - if (key != "p"){ +// if (key != "p"){ var val = self.select().html(); self.select().html(val); + self.cmd.doc.body.innerHTML = self.cmd.doc.body.innerHTML.replace(/
\s*<\/p>/g,""); val = self.select().html().replace(/(