diff --git a/Gemfile b/Gemfile index 58ccbc011..34636a914 100644 --- a/Gemfile +++ b/Gemfile @@ -50,10 +50,10 @@ gem 'elasticsearch-model' gem 'elasticsearch-rails' #rails 3.2.22.2 bug - gem "test-unit", "~>3.0" + # gem "test-unit", "~>3.0" ### profile - gem 'oneapm_rpm' + # gem 'oneapm_rpm' group :development do gem 'grape-swagger' @@ -63,22 +63,18 @@ group :development do if RUBY_PLATFORM =~ /w32/ gem 'win32console' end + + if RUBY_PLATFORM =~ /darwin/ + gem 'puma' +end end group :development, :test do - unless RUBY_PLATFORM =~ /w32/ - gem 'pry-rails' if RUBY_VERSION >= '2.0.0' gem 'pry-byebug' + gem "test-unit", "~>3.0" end - gem 'pry-stack_explorer' - if RUBY_PLATFORM =~ /darwin/ - gem 'puma' - end - end - gem 'rspec-rails', '~> 3.0' - gem 'factory_girl_rails' end # Gems used only for assets and not required diff --git a/app/api/mobile/entities/attachment.rb b/app/api/mobile/entities/attachment.rb index 0eda2d1c0..55e4aa555 100644 --- a/app/api/mobile/entities/attachment.rb +++ b/app/api/mobile/entities/attachment.rb @@ -17,17 +17,18 @@ module Mobile end else case field + when :download_url + "attachments/download/#{f.try(:id)}" when :file_dir "attachments/download/" << f.send(:id).to_s << '/' when :attafile_size (number_to_human_size(f.filesize)).gsub("ytes", "").to_s when :coursename - f.course.nil? ? "" : f.course.name + f.try(:course).try(:name) || '' when :syllabus_title - f.course.nil? ? "" : f.course.syllabus.nil? ? "" : f.course.syllabus.title + f.try(:course).try(:syllabus).try(:title) || '' when :course_id - f.course.nil? ? 0 : f.course.id - + f.try(:course).try(:id) || 0 end end end @@ -50,6 +51,8 @@ module Mobile current_user_is_teacher = is_course_teacher(current_user,instance.course) current_user_is_teacher end + + attachment_expose :download_url end end end \ No newline at end of file diff --git a/app/api/mobile/entities/issue.rb b/app/api/mobile/entities/issue.rb index 7f09906b5..2cb6cd87a 100644 --- a/app/api/mobile/entities/issue.rb +++ b/app/api/mobile/entities/issue.rb @@ -180,6 +180,8 @@ module Mobile end end end + + expose :attachments, using: Mobile::Entities::Attachment end end end \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 14d5961cd..88e34d25f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -55,7 +55,7 @@ class ApplicationController < ActionController::Base include Redmine::Search::Controller include Redmine::MenuManager::MenuController helper Redmine::MenuManager::MenuHelper - + def user_agent logger.info "HTTP_USER_AGENT #{request.env["HTTP_USER_AGENT"]}" end @@ -117,6 +117,9 @@ class ApplicationController < ActionController::Base elsif params[:format] == 'atom' && params[:key] && request.get? && accept_rss_auth? # RSS key authentication does not start a session user = User.find_by_rss_key(params[:key]) + elsif session[:wechat_openid] + uw = UserWechat.find_by_openid(session[:wechat_openid]) + user = uw.user if uw end end if user.nil? && Setting.rest_api_enabled? && accept_api_auth? @@ -509,8 +512,7 @@ class ApplicationController < ActionController::Base # render_404 # end - def self. - model_object(model) + def self.model_object(model) self.model_object = model end diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index e7a5d3164..848d85c34 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -72,8 +72,10 @@ class AttachmentsController < ApplicationController def direct_download @attachment.increment_download + file_type = detect_content_type(@attachment) + send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), - :type => detect_content_type(@attachment), + :type => file_type, :disposition => 'attachment' #inline can open in browser end @@ -130,11 +132,7 @@ class AttachmentsController < ApplicationController def download # modify by nwb # 下载添加权限设置 - if (params[:type] && params[:type] == "wechat" ) - candown = true - else - candown = attachment_candown @attachment - end + candown = attachment_candown @attachment if candown || User.current.admin? || User.current.id == @attachment.author_id if stale?(:etag => @attachment.digest) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 5e0ef4638..fe707ac5b 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -32,6 +32,13 @@ class CoursesController < ApplicationController before_filter :require_login, :only => [:join, :unjoin] #before_filter :allow_join, :only => [:join] + # 邀请码停用/启用 + def set_invite_code_halt + if User.current.allowed_to?(:as_teacher, @course) || User.current.admin? + @course.update_attribute('invite_code_halt', @course.invite_code_halt == 0 ? 1 : 0) + end + end + #查找组织 def search_public_orgs_not_in_course condition = '%%' diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 3234d15c0..b7e4b9efd 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -82,6 +82,27 @@ class HomeworkCommonController < ApplicationController @homework.publish_time = params[:homework_common][:publish_time] end homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new + param_end_time = Time.parse(params[:homework_common][:end_time]).strftime("%Y-%m-%d") + homework_end_time = Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") + if homework_end_time != param_end_time + if homework_end_time > param_end_time + @homework.student_works.where("work_status = 1").each do |st| + if param_end_time < Time.parse(st.commit_time.to_s).strftime("%Y-%m-%d") + st.late_penalty = @homework.late_penalty + st.work_status = 2 + st.save + end + end + else + @homework.student_works.where("work_status = 2").each do |st| + if param_end_time >= Time.parse(st.commit_time.to_s).strftime("%Y-%m-%d") + st.late_penalty = 0 + st.work_status = 1 + st.save + end + end + end + end @homework.end_time = params[:homework_common][:end_time] || Time.now @homework.course_id = params[:course_id] if params[:homework_type] && params[:homework_type].to_i != @homework.homework_type diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index c6cb018a5..2f0b1d45e 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -22,9 +22,9 @@ class IssuesController < ApplicationController before_filter :authorize1, :only => [:show] before_filter :find_issue, :only => [:show, :edit, :update,:add_journal, :add_journal_in_org] before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy] - before_filter :find_project, :only => [:new, :create, :update_form] + before_filter :find_project, :only => [:new, :create, :update_form, :issue_commits, :commit_for_issue, :issue_commit_delete] #before_filter :authorize, :except => [:index, :show] - before_filter :authorize, :except => [:index,:add_journal, :add_journal_in_org,:delete_journal,:reply,:add_reply] + before_filter :authorize, :except => [:index,:add_journal, :add_journal_in_org,:delete_journal,:reply,:add_reply, :issue_commits, :commit_for_issue, :issue_commit_delete] before_filter :find_optional_project, :only => [:index] before_filter :check_for_default_issue_status, :only => [:new, :create] @@ -57,6 +57,57 @@ class IssuesController < ApplicationController helper :project_score include ApplicationHelper + # issue和代码提交id关联模块 --> over + # 获取某个项目的commit_ids + def issue_commits + begin + return render_404 if @project.gpid.nil? + @issue_commit_ids = (params[:issue_commit_ids].is_a?(Array) ? params[:issue_commit_ids] : params[:issue_commit_ids].split(",")) unless params[:issue_commit_ids].nil? + search = params[:search].to_s.strip + @type = params[:type] + limit = 15 + g = Gitlab.client + g_project = g.project(@project.gpid) + rev = params[:branch].nil? ? g_project.default_branch : params[:branch] + @project_branches = g.branches(@project.gpid) + @branch_names = @project_branches.map{|b| b.name} + @default_branch = g_project.default_branch + # 搜索的分页需要单独处理,因为搜索不容易获取总数 + if search.present? + @commits = g.commits(@project.gpid, ref_name:rev, :search => search) + @commits_count = @commits.count + @commits_pages = Paginator.new @commits_count, limit, params['page'] || 1 + @offset ||= @commits_pages.offset + @commits = paginateHelper @commits,limit + else + @commits = g.commits(@project.gpid, page:(params[:page].to_i - 1).to_s, ref_name:rev, :search => search) + @commits_count = g.user_static(@project.gpid, :rev => rev).count + @commits_pages = Redmine::Pagination::Paginator.new @commits_count, limit, params[:page] + end + rescue Exception => e + puts e + end + end + + # 选择对应的Commit + def commit_for_issue + history_commit_ids = params[:issue_for_commit_ids].split(",") unless params[:issue_for_commit_ids].nil? + @issue_commit_ids = (history_commit_ids.blank? ? params[:checkbox1] : params[:checkbox1] | history_commit_ids).uniq + end + + def issue_commit_delete + commit_id = params[:commit_id].split(",") + issue_commit_ids = params[:issue_commit_ids] + # issue_id存在则为issue详情或者编辑的时候,否则为新建Issue + # 编辑和详情的时候需要在数据库中删除记录,新建的时候在内存中删除 + if params[:issue_id] + commit_issue = CommitIssues.where(:commit_id => commit_id, :issue_id => params[:issue_id], :project_id => @project.id).first + commit_issue.delete if commit_issue + end + @issue_commit_ids = issue_commit_ids - commit_id + end + # over + def index # 顶部导航 @project_menu_type = 2 @@ -163,14 +214,14 @@ class IssuesController < ApplicationController def show # 顶部导航 @project_menu_type = 2 - # 打开编辑内容 @is_edit = true unless params[:edit].nil? - # 当前用户查看指派给他的缺陷消息,则设置消息为已读 query = ForgeMessage.where("forge_message_type =? and user_id =? and forge_message_id =?", "Issue", User.current, @issue).first query.update_attribute(:viewed, true) unless query.nil? - + # issue 关联的commit + commit_issues = CommitIssues.where(:issue_id => @issue.id, :project_id => @issue.project_id) + @issue_commit_ids = commit_issues.map{|commit_issue| commit_issue.commit_id} # issue 新建的at消息 User.current.at_messages.unviewed('Issue', @issue.id).each {|x| x.viewed!} # 回复的at消息 @@ -238,6 +289,8 @@ class IssuesController < ApplicationController @issue.fixed_version_id = nil if @issue.fixed_version_id == 0 @issue.assigned_to_id = nil if @issue.assigned_to_id == 0 if @issue.save + # 关联commmit + update_issue_commit params[:commit_ids] #params[:issue][:assigned_to_id] = nil if params[:issue][:assigned_to_id].to_i == 0 senduser = User.find(params[:issue][:assigned_to_id]) issue_id = @issue.id @@ -276,6 +329,9 @@ class IssuesController < ApplicationController def edit # 修改实例变量的值 return unless update_issue_from_params + # issue 关联的commit + commit_issues = CommitIssues.where(:issue_id => @issue.id, :project_id => @issue.project_id) + @issue_commit_ids = commit_issues.map{|commit_issue| commit_issue.commit_id} respond_to do |format| format.html {render :layout => 'base_projects' }#added by young @@ -309,9 +365,9 @@ class IssuesController < ApplicationController end end end - - if @saved + # 更新commit关联情况 + update_issue_commit params[:commit_ids] #修改界面增加跟踪者 watcherlist = @issue.watcher_users select_users = [] @@ -356,6 +412,26 @@ class IssuesController < ApplicationController end end + # 保存issue的时候相关的commit操作 + # commit_ids => "9b9845ff,poor56el" + def update_issue_commit commit_ids + # 关联commmit + commit_ids = params[:commit_ids] + unless commit_ids.blank? + commit_ids = commit_ids.split(",").uniq + if params[:action] == "update" + exist_commit_ids = CommitIssues.where(:issue_id => @issue, :project_id => @issue.project_id) + unless exist_commit_ids.blank? + exist_commit_ids = exist_commit_ids.map{|commit| commit.commit_id} + commit_ids = commit_ids - exist_commit_ids + end + end + commit_ids.each do |commit_id| + CommitIssues.create(:commit_id => commit_id, :project_id => @issue.project_id, :issue_id => @issue.id) + end + end + end + def update_user_issue_detail(issue, params) case params[:type] when "status" @@ -794,7 +870,6 @@ class IssuesController < ApplicationController # 更新issue状态时,journal表产生记录,返回@current_journal @issue.init_journal(User.current) - issue_attributes = params[:issue] if issue_attributes && params[:conflict_resolution] case params[:conflict_resolution] @@ -809,18 +884,18 @@ class IssuesController < ApplicationController end end - senduser = User.find(params[:issue][:assigned_to_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 + if params[:action] == "update" + senduser = User.find(params[:issue][:assigned_to_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 end @issue.safe_attributes = issue_attributes - @priorities = IssuePriority.active @allowed_statuses = @issue.new_statuses_allowed_to(User.current) true diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 596775045..f579090e6 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -7,7 +7,7 @@ class StudentWorkController < ApplicationController require "base64" before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:program_test_ex, :set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project, - :search_course_students,:work_canrepeat,:add_group_member] + :search_course_students,:work_canrepeat,:add_group_member,:change_project] before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work,:retry_work,:revise_attachment] before_filter :member_of_course, :only => [:new, :create, :show, :add_score, :praise_student_work] before_filter :author_of_work, :only => [:edit, :update, :destroy] @@ -587,6 +587,14 @@ class StudentWorkController < ApplicationController if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") student_work.late_penalty = @homework.late_penalty student_work.work_status = 2 + # 缺评扣分 + if @homework.homework_detail_manual.no_anon_penalty == 0 && @homework.homework_detail_manual.comment_status == 3 && @homework.anonymous_comment == 0 + work_ids = "(" + @homework.student_works.has_committed.map(&:id).join(",") + ")" + all_dis_eva = StudentWorksEvaluationDistribution.where("student_work_id IN #{work_ids}") + has_sw_count = all_dis_eva.select("distinct user_id").count + anon_count = all_dis_eva.count / has_sw_count + student_work.absence_penalty = @homework.homework_detail_manual.absence_penalty * anon_count + end else student_work.late_penalty = 0 student_work.work_status = 1 @@ -1052,7 +1060,7 @@ class StudentWorkController < ApplicationController end def forbidden_anonymous_comment - @homework.update_column('anonymous_comment', 1) + @homework.update_column('anonymous_comment', @homework.anonymous_comment == 0 ? 1 : 0) homework_detail_manual = @homework.homework_detail_manual homework_detail_programing = @homework.homework_detail_programing if homework_detail_programing @@ -1084,6 +1092,7 @@ class StudentWorkController < ApplicationController respond_to do |format| format.js end + @homework = @work.homework_common end def new_student_work_project @@ -1130,6 +1139,26 @@ class StudentWorkController < ApplicationController end end + # 作品更换关联项目 + def change_project + work = @homework.student_works.has_committed.where("user_id = #{User.current.id}").first + project = Project.find params[:projectName].to_i + if work && project + relate_user_ids = work.student_work_projects.map{|pro| pro.user_id} + member_ids = project.members.map{|mem| mem.user_id} + if (relate_user_ids & member_ids) == relate_user_ids + work.student_work_projects.update_all(:project_id => params[:projectName].to_i) + student_works = @homework.student_works.where("user_id in #{'(' + relate_user_ids.join(',') + ')'}") + student_works.update_all(:project_id => params[:projectName].to_i) + else + @remain_user_ids = relate_user_ids - (relate_user_ids & member_ids) + end + end + respond_to do |format| + format.js + end + end + #查找课程的学生 def search_course_students name = "" diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6539919d1..28f09c482 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1187,10 +1187,18 @@ class UsersController < ApplicationController student_work = StudentWork.where(homework_common_id: homework.id, user_id: User.current.id).first if student_work - #提交作品时,计算是否迟交 + # 提交作品时,计算是否迟交 if Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") student_work.late_penalty = homework.late_penalty student_work.work_status = 2 + # 缺评扣分 + if homework.homework_detail_manual.no_anon_penalty == 0 && homework.homework_detail_manual.comment_status == 3 && homework.anonymous_comment == 0 + work_ids = "(" + homework.student_works.has_committed.map(&:id).join(",") + ")" + all_dis_eva = StudentWorksEvaluationDistribution.where("student_work_id IN #{work_ids}") + has_sw_count = all_dis_eva.select("distinct user_id").count + anon_count = all_dis_eva.count / has_sw_count + student_work.absence_penalty = homework.homework_detail_manual.absence_penalty * anon_count + end else student_work.late_penalty = 0 student_work.work_status = 1 diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index 654f83855..25ce1f83e 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -1,4 +1,6 @@ #coding=utf-8 + +require 'base64' class WechatsController < ActionController::Base wechat_responder @@ -105,6 +107,7 @@ class WechatsController < ActionController::Base end on :event, with: 'unsubscribe' do |request| + unBind(request) request.reply.success # user can not receive this message end @@ -272,12 +275,18 @@ class WechatsController < ActionController::Base end end + def unBind(request) + uw = user_binded?(request[:FromUserName]) + uw.try(:subscribe!) + end + def sendBind(request) tmpurl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{ROOT_URL+'/wechat/user_activities'}&response_type=code&scope=snsapi_base&state=login&connect_redirect=1#wechat_redirect" logger.info "tmpurl!!!!!!!!!!!!!!" logger.info tmpurl news = (1..1).each_with_object([]) { |n, memo| memo << { title: '绑定登录', content: "欢迎使用Trustie创新实践服务平台! -在这里您可以随时了解您的课程和项目动态,随时点赞和回复。 +在这里您可以随时了解您的课程和项目动态,随时点赞和回复。交作业、代码提交等更多功能,请前往 www.trustie.net + 我们将会与微信不断结合,为您提供更有价值的服务。 您还未绑定确实的用户,请先绑定,谢谢!" } } @@ -485,9 +494,33 @@ class WechatsController < ActionController::Base end + # 用于权限跳转 + def auth + state = params[:state] + url = "#{ROOT_URL}/wechat/auth_callback" + authorize_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{url}&response_type=code&scope=snsapi_base&state=#{state}&connect_redirect=1#wechat_redirect" + redirect_to authorize_url + end + + def auth_callback + path = Base64.urlsafe_decode64(params[:state]) + open_id = get_openid_from_code(params[:code]) + unless open_id + render 'wechats/open_wechat', layout: nil and return + end + + redirect_to "/wechat/user_activities##{path}" + end + + private def get_openid_from_code(code) - return 'oCnvgvz8R7QheXE-R9Kkr39j8Ndg' if code =='only-for-test' + if code =='only-for-test' + openid = 'o3ss_wHOOnHkz1khBJxH8RF4SfPY' + session[:wechat_openid] = openid + return openid + end + openid = session[:wechat_openid] unless openid if code diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b8ce07d69..fe8dd50b6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -77,12 +77,36 @@ module ApplicationHelper user.nil? ? User.find(2) : user end + # 通过邮件查找用户,能查到返回用户,否则返回邮件地址 + def user_by_mail mail + user = User.find_by_mail(mail) + user.nil? ? mail : user.try(:show_name) + end + + def link_to_user_mail(mail, css_class) + user = User.find_by_mail(mail) + user = user.nil? ? mail : user + if user.is_a?(User) + name = user.show_name + link_to name, {:controller=> 'users', :action => 'show', id: user.id}, :class => css_class, :target => "_blank" + else + "#{h(user.to_s)}".html_safe + end + end + # 通过系统外部用户名查找用户,如果用户不存在则用邮箱替换 def get_user_by_login_and login user = User.find_by_login(login) (user.nil? || login == "root") ? User.find(2) : user end + # 登录名来自外部系统 + # 通过登录名查找用户,如果用户存在则显示用户姓名,否则显示登录名 + def get_user_by_login login + user = User.find_by_login(login) + user.nil? ? login : user.show_name + end + # 重置user_path,目的是将id转换成用户名 def user_path(resource, parameters = {}) if Fixnum === resource @@ -3741,7 +3765,9 @@ def get_hw_status homework_common end if Time.parse(homework_common.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") str += '作品提交中' - elsif Time.parse(homework_common.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") + elsif Time.parse(homework_common.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && homework_common.anonymous_comment == 1 && User.current.allowed_to?(:as_teacher, homework_common.course) + str += '教师评阅中' + else str += '作品补交中' end elsif homework_common.homework_detail_manual.comment_status == 2 diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index e6603070d..e8cbcadf7 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -27,6 +27,21 @@ module RepositoriesHelper REPO_IP_ADDRESS = Setting.host_repository REPO_GITLAB_ADDRESS = "git.trustie.net" + # 获取某次提交的关联Issue + # REDO:一次关联查询 + # type为true则为详情页面,全部显示 + def get_commit_issues commit_id, project_id, type + commit_issues = CommitIssues.where(:commit_id => commit_id, :project_id => project_id) + unless commit_issues.blank? + if commit_issues.count > 2 && type != 1 + result = commit_issues.map{|commit_issue| commit_issue.issue_id}.first(2) << "more" + else + result = commit_issues.map{|commit_issue| commit_issue.issue_id} + end + end + return result unless result.blank? + end + # 因为gitlab的提交总数不是实时同步的,说以取总数用两种方法 def choise_commit_count git_count, pro_count git_count > pro_count ? git_count : pro_count diff --git a/app/models/attachment.rb b/app/models/attachment.rb index c83a7bf2a..ff87f533c 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -397,7 +397,7 @@ class Attachment < ActiveRecord::Base end def course - container + Course === container ? container : nil end def visible?(user=User.current) diff --git a/app/models/commit_issues.rb b/app/models/commit_issues.rb new file mode 100644 index 000000000..fc56465f9 --- /dev/null +++ b/app/models/commit_issues.rb @@ -0,0 +1,5 @@ +class CommitIssues < ActiveRecord::Base + attr_accessible :commit_id, :issue_id, :project_id + # 之所以没建立关联表,主要是应为commit_id是直接通过api获取的,不存在trustie端 + has_many :issues +end diff --git a/app/models/issue.rb b/app/models/issue.rb index 46a42cb34..b46e29104 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -56,6 +56,8 @@ class Issue < ActiveRecord::Base has_one :praise_tread_cache, as: :object, dependent: :destroy # ForgeMessage虚拟关联(多态) has_many :forge_messages, :class_name => 'ForgeMessage',:as =>:forge_message ,:dependent => :destroy + # 该关联不能关联删除,因为commit记录没有存在Trustie数据库中 + has_many :commit_issueses has_many :at_messages, class_name: 'AtMessage', as: :at_message ,:dependent => :destroy diff --git a/app/models/user_wechat.rb b/app/models/user_wechat.rb index c63411ab3..71221a3d1 100644 --- a/app/models/user_wechat.rb +++ b/app/models/user_wechat.rb @@ -24,4 +24,9 @@ class UserWechat < ActiveRecord::Base BlogComment.where(author_id: old_user).update_all(author_id: u.id) UserActivity.where(user_id: old_user).update_all(user_id: u.id) end + + + def unsubscribe! + self.delete + end end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 43bdf9e09..c1c5f4f9f 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -584,6 +584,8 @@ class CoursesService @state = 2 elsif course[:is_delete] == 1 @state = 11 + elsif course[:invite_code_halt] == 1 + @state = 14 else if current_user.member_of_course?(course) #如果已经是成员 @state = 3 diff --git a/app/views/comments/create.js.erb b/app/views/comments/create.js.erb index 0814b5f50..970fded22 100644 --- a/app/views/comments/create.js.erb +++ b/app/views/comments/create.js.erb @@ -1,8 +1,8 @@ <% if @course %> - $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/course_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>"); + $("#activity_post_reply_<%= @user_activity_id%>").html("<%= escape_javascript(render :partial => 'users/course_news_post_reply', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>"); <% elsif @project %> $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'projects/project_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>"); <% else %> - $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'organizations/org_subfield_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>"); + $("#activity_post_reply_<%= @user_activity_id%>").html("<%= escape_javascript(render :partial => 'organizations/course_news_post_reply', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>"); <% end %> sd_create_editor_from_data('<%= @user_activity_id%>',"","100%", "UserActivity"); diff --git a/app/views/courses/_course_activity.html.erb b/app/views/courses/_course_activity.html.erb index a7f99f2b0..8ad3323f6 100644 --- a/app/views/courses/_course_activity.html.erb +++ b/app/views/courses/_course_activity.html.erb @@ -62,17 +62,17 @@ <% when 'HomeworkCommon' %> <%= render :partial => 'users/course_homework', :locals => {:activity => act, :user_activity_id => activity.id, :hw_status => 2} %> <% when 'News' %> - <%= render :partial => 'users/course_news', :locals => {:activity => act, :user_activity_id => activity.id} %> + <%= render :partial => 'users/course_news', :locals => {:activity => act, :user_activity_id => activity.id, :is_course => 1} %> <% when 'Message' %> <%= render :partial => 'users/course_message', :locals => {:activity => act, :user_activity_id => activity.id,:is_course=>1,:is_board=>0} %> <% when 'Poll' %> - <%= render :partial => 'users/course_poll', :locals => {:activity => act, :user_activity_id => activity.id} %> + <%= render :partial => 'users/course_poll', :locals => {:activity => act, :user_activity_id => activity.id, :is_course => 1} %> <% when 'JournalsForMessage' %> - <%= render :partial => 'users/course_journalsformessage', :locals => {:activity => act, :user_activity_id => activity.id} %> + <%= render :partial => 'users/course_journalsformessage', :locals => {:activity => act, :user_activity_id => activity.id, :is_course => 1} %> <% when 'Attachment' %> <%= render :partial => 'users/course_attachment', :locals => {:activity => act, :user_activity_id => activity.id} %> <% when 'Course' %> - <%= render :partial => 'users/course_create', :locals => {:activity => act, :user_activity_id => activity.id} %> + <%= render :partial => 'users/course_create', :locals => {:activity => act, :user_activity_id => activity.id, :is_course => 1} %> <% end %> <% end %> <% end %> diff --git a/app/views/courses/_course_activity_users.html.erb b/app/views/courses/_course_activity_users.html.erb index cffd383e6..692be98e9 100644 --- a/app/views/courses/_course_activity_users.html.erb +++ b/app/views/courses/_course_activity_users.html.erb @@ -4,9 +4,9 @@
请至少选择一个身份
++ | 修订号 | +描述 | +提交者 | +提交日期 | +
---|---|---|---|---|
+ | + <%= link_to commit.id[0,8], {:controller => 'repositories', :action => 'commit_diff', :id => @project.id, :changeset => commit.id}, :target => "_blank" %> + | +<%= commit.title %> |
+ <%= link_to_user_mail(commit.author_email, "") %> | +<%= format_date(commit.created_at) %> | +
邀 请 码
+
邀 请 码
- <% if User.current.admin? || User.current.member_of_course?(@course) %>
- <%=@course.generate_invite_code %>
+ <% if @course.invite_code_halt == 0 %>
+ <% if User.current.admin? || User.current.member_of_course?(@course) %>
+ <%=@course.generate_invite_code %>
+ <% else %>
+ 请询问老师
+ <% end %>
<% else %>
- 请询问老师
+ 已停用
<% end %>
+ <% if is_teacher && @course.invite_code_halt == 0 %>
+ 停 用
+ <% elsif is_teacher && @course.invite_code_halt == 1 %>
+ 启 用
+ <% end %>
请将邀请码告诉学生和教辅
-他们可以主动加入班级
+<%= @course.invite_code_halt == 0 ? "请将邀请码告诉学生和教辅" : "邀请码已停用,学生和教辅" %>
+<%= @course.invite_code_halt == 0 ? "他们可以主动加入班级" : "不可以主动加入班级了" %>