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/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 6f245a92b..b6fdd1fee 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -38,12 +38,12 @@ class PullRequestsController < ApplicationController @requests_merged_count = merge_requests.select{|request| request.state == "merged"}.count @requests_closed_count = merge_requests.select{|request| request.state == "closed"}.count - @limit = 10 + @limit = 20 @is_remote = true @count = type_count(type, @requests_opened_count, @requests_merged_count, @requests_closed_count) @pages = Paginator.new @count, @limit, params['page'] || 1 @offset ||= @pages.offset - @requests = paginateHelper @requests, 10 + @requests = paginateHelper @requests, 20 respond_to do |format| format.html format.js 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 da7cfd849..ed3148e6f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -35,14 +35,14 @@ class UsersController < ApplicationController # before_filter :can_show_course, :only => [:user_courses,:user_homeworks] - before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses, + before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses, :unsolved_issues_list, :user_homeworks,:student_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index, :activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index, :activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource, :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction, :user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist,:user_projectlist,:sort_syllabus_list, - :sort_project_list,:my_homeworks,:manage_or_receive_homeworks,:search_m_r_homeworks, :cancel_or_collect,:expand_courses,:homepage, :user_issues] + :sort_project_list,:my_homeworks,:manage_or_receive_homeworks,:search_m_r_homeworks, :cancel_or_collect,:expand_courses,:homepage, :user_issues, :course_community, :project_community] before_filter :auth_user_extension, only: :show #before_filter :rest_user_score, only: :show #before_filter :select_entry, only: :user_projects @@ -433,7 +433,8 @@ class UsersController < ApplicationController render_404 return end - @message_alls = paginateHelper @message_alls,25 + + @message_alls = paginateHelper @message_alls, 25 respond_to do |format| format.html{render :layout=>'new_base_user'} end @@ -1186,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 @@ -1806,22 +1815,197 @@ class UsersController < ApplicationController end def show - #更新用户申请成为课程老师或教辅消息的状态 + if is_current_user + # 自己的主页显示消息 + # 系统消息为管理员发送,我的消息中包含有系统消息 + @message_alls = [] + messages = MessageAll.where("(user_id =? and message_type !=?) or message_type =?" ,@user.id, "SystemMessage", "SystemMessage").includes(:message).order("created_at desc") + messages.each do |message_all| + mess = message_all.message + unless (message_all.message_type == 'CourseMessage' && mess && mess.course && mess.course.is_delete == 1) + @message_alls << mess + end + end + @message_count = @message_alls.count + @message_alls = paginateHelper @message_alls, 20 + # 用户待解决的issue +=begin + @unsolved_issues = Issue.where(:assigned_to_id => @user.id, :status_id => [1, 2, 4, 6]).includes(:author, :project).order("updated_on desc") + @unsolved_issues_count = @unsolved_issues.count + @unsolved_issue_pages = Paginator.new @unsolved_issues_count, 20, params['page'] || 1 + @unsolved_issues = paginateHelper @unsolved_issues, 20 +=end + @unsolved_issues_count = Issue.where(:assigned_to_id => @user.id, :status_id => [1, 2, 4, 6]).includes(:author, :project).order("updated_on desc").count + # 用户待完成的作业 + my_course_ids = StudentsForCourse.where(:student_id => @user.id).blank? ? "(-1)" : "(" + StudentsForCourse.where(:student_id => @user.id).map{|sc| sc.course_id}.join(",") + ")" + homeworks = HomeworkCommon.where("course_id in #{my_course_ids} and publish_time <= '#{Date.today}'") + homework_ids = homeworks.blank? ? "(-1)" : "(" + homeworks.map{|homework| homework.id}.join(",") + ")" + student_works = StudentWork.where("user_id = #{@user.id} and homework_common_id in #{homework_ids} and work_status != 0") + @unfinished_homework_count = homeworks.count - student_works.count + # 用户待完成的测验 + exercises = Exercise.where("course_id in #{my_course_ids} and exercise_status = 2") + exercise_ids = exercises.blank? ? "(-1)" : "(" + exercises.map{|ex| ex.id}.join(",") + ")" + exercise_users = ExerciseUser.where("user_id = #{@user.id} and exercise_id in #{exercise_ids}") + @unfinished_test_count = exercises.count - exercise_users.count + # 用户待完成的问卷 + polls = Poll.where("polls_type = 'Course' and polls_group_id in #{my_course_ids} and polls_status = 2") + poll_ids = polls.blank? ? "(-1)" : "(" + polls.map{|poll| poll.id}.join(",") + ")" + poll_users = PollUser.where("user_id = #{@user.id} and poll_id in #{poll_ids}") + @unfinished_poll_count = polls.count - poll_users.count + # 用户待匿评的作品 + student_work_evaluations = @user.student_works_evaluation_distributions + student_work_ids = student_work_evaluations.blank? ? "(-1)" : "(" + student_work_evaluations.map{|st| st.student_work_id}.join(",") + ")" + student_work_scores = @user.student_works_scores.where("student_work_id in #{student_work_ids} and reviewer_role = 3") + @anonymous_evaluation_count = student_work_evaluations.count - student_work_scores.count + # 待评阅的作业 暂不做 + @unreview_homework = 1 + # 待审批的作业 + @unapproval_homework = 1 + else + # 看别人的主页显示动态 + #更新用户申请成为课程老师或教辅消息的状态 + if params[:course_id] != nil + join_course_messages = CourseMessage.where("course_id =? and course_message_type =? and user_id =? and course_message_id =? and viewed =?", + params[:course_id], 'JoinCourseRequest', User.current.id, @user.id, false) + join_course_messages.update_all(:viewed => true) + 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].to_i + 1 : 0 + user_project_ids = (@user.favorite_projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.favorite_projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")" + user_course_ids = (@user.favorite_courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.favorite_courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")" + course_types = "('Message','News','HomeworkCommon','Poll','Course','JournalsForMessage')" + project_types = "('Message','Issue','Project')" + principal_types = "JournalsForMessage" + container_type = '' + act_type = '' + # 他的动态 + sql = "user_id = #{@user.id} and ((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}))" + if params[:type].present? + case params[:type] + when "course_homework" + container_type = 'Course' + act_type = 'HomeworkCommon' + when "course_news" + container_type = 'Course' + act_type = 'News' + when "course_message" + container_type = 'Course' + act_type = 'Message' + when "course_poll" + container_type = 'Course' + act_type = 'Poll' + when "course_journals" + container_type = 'Course' + act_type = 'JournalsForMessage' + when "project_issue" + container_type = 'Project' + act_type = 'Issue' + when "project_message" + container_type = 'Project' + act_type = 'Message' + when "user_journals" + container_type = 'Principal' + act_type = 'JournalsForMessage' + when "current_user" + container_type = 'Principal' + act_type = 'Principal' + when "all" + container_type = 'all' + act_type = 'all' + end + end + if container_type != '' && container_type != 'all' + if container_type == 'Course' + sql = "container_type = '#{container_type}' and container_id in #{user_course_ids} and act_type = '#{act_type}'" + elsif container_type == 'Project' + sql = "container_type = '#{container_type}' and container_id in #{user_project_ids} and act_type = '#{act_type}'" + elsif container_type == 'Principal' && act_type == 'JournalsForMessage' + sql = "container_type = '#{container_type}' and act_type= '#{act_type}' and container_id = #{@user.id}" + elsif container_type == 'Principal' && act_type == 'Principal' + sql = "user_id = #{@user.id} and ((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}))" + end + if User.current != @user + sql += " and user_id = #{@user.id}" + end + else + if User.current != @user + blog_ids = "("+@user.blog.id.to_s+")" + else + 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(','))+")" + end + sql = "(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})" + if container_type != 'all' && User.current != @user + sql = "user_id = #{@user.id} and(" + sql + ")" + end + end + @user_activities_count = UserActivity.where("#{sql}").order('updated_at desc').count + @user_activities = UserActivity.where("#{sql}").order('updated_at desc').limit(10).offset(@page * 10) + @type = params[:type] + end + respond_to do |format| + format.js + format.html {render :layout => 'new_base_user'} + end + end + + # 待解决的Issue + def unsolved_issues_list + @unsolved_issues = Issue.where(:assigned_to_id => @user.id, :status_id => [1, 2, 4, 6]).includes(:author, :project).order("updated_on desc") + @unsolved_issues_count = @unsolved_issues.count + @limit = 20 + @is_remote = true + @unsolved_issues_pages = Paginator.new @unsolved_issues_count, @limit, params['page'] || 1 + @offset ||= @unsolved_issues_pages.offset + @unsolved_issues = paginateHelper @unsolved_issues, @limit + respond_to do |format| + format.js + end + end + + # 待完成的作业 + def unfinished_homework_list + + end + + # 待完成的测验 + def unfinished_test_list + + end + + # 待完成的问卷 + def unfinished_poll_list + + end + + # 待匿评的作业 + def anonymous_evaluation_list + + end + + # 待审批的申请 + def unapproval_homework_list + + end + + # 课程社区 + def course_community if params[:course_id] != nil join_course_messages = CourseMessage.where("course_id =? and course_message_type =? and user_id =? and course_message_id =? and viewed =?", params[:course_id], 'JoinCourseRequest', User.current.id, @user.id, false) join_course_messages.update_all(:viewed => true) 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].to_i + 1 : 0 - user_project_ids = (@user.favorite_projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.favorite_projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")" user_course_ids = (@user.favorite_courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.favorite_courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")" course_types = "('Message','News','HomeworkCommon','Poll','Course','JournalsForMessage')" - project_types = "('Message','Issue','Project')" principal_types = "JournalsForMessage" container_type = '' act_type = '' + if params[:type].present? case params[:type] when "course_homework" @@ -1839,6 +2023,63 @@ class UsersController < ApplicationController when "course_journals" container_type = 'Course' act_type = 'JournalsForMessage' + when "user_journals" + container_type = 'Principal' + act_type = 'JournalsForMessage' + when "current_user" + container_type = 'Principal' + act_type = 'Principal' + when "all" + container_type = 'all' + act_type = 'all' + end + end + if container_type != '' && container_type != 'all' + if container_type == 'Course' + sql = "container_type = '#{container_type}' and container_id in #{user_course_ids} and act_type = '#{act_type}'" + elsif container_type == 'Principal' && act_type == 'JournalsForMessage' + sql = "container_type = '#{container_type}' and act_type= '#{act_type}' and container_id = #{@user.id}" + elsif container_type == 'Principal' && act_type == 'Principal' + sql = "user_id = #{@user.id} and (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})" + end + if User.current != @user + sql += " and user_id = #{@user.id}" + end + else + if User.current != @user + blog_ids = "("+@user.blog.id.to_s+")" + else + 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(','))+")" + end + sql = "(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})" + if container_type != 'all' && User.current != @user + sql = "user_id = #{@user.id} and(" + sql + ")" + end + end + @user_activities_count = UserActivity.where("#{sql}").order('updated_at desc').count + @user_activities = UserActivity.where("#{sql}").order('updated_at desc').limit(10).offset(@page * 10) + @type = params[:type] + respond_to do |format| + format.js + format.html {render :layout => 'base_course_community'} + end + end + + # 项目社区 + def project_community + # 看别人的主页显示动态 + #更新用户申请成为课程老师或教辅消息的状态 + shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id) + @page = params[:page] ? params[:page].to_i + 1 : 0 + user_project_ids = (@user.favorite_projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.favorite_projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")" + project_types = "('Message','Issue','Project')" + principal_types = "JournalsForMessage" + container_type = '' + act_type = '' + if params[:type].present? + case params[:type] when "project_issue" container_type = 'Project' act_type = 'Issue' @@ -1857,14 +2098,12 @@ class UsersController < ApplicationController end end if container_type != '' && container_type != 'all' - if container_type == 'Course' - sql = "container_type = '#{container_type}' and container_id in #{user_course_ids} and act_type = '#{act_type}'" - elsif container_type == 'Project' + if container_type == 'Project' sql = "container_type = '#{container_type}' and container_id in #{user_project_ids} and act_type = '#{act_type}'" elsif container_type == 'Principal' && act_type == 'JournalsForMessage' sql = "container_type = '#{container_type}' and act_type= '#{act_type}' and container_id = #{@user.id}" elsif container_type == 'Principal' && act_type == 'Principal' - sql = "user_id = #{@user.id} and ((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}))" + sql = "user_id = #{@user.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}))" end if User.current != @user sql += " and user_id = #{@user.id}" @@ -1876,19 +2115,18 @@ class UsersController < ApplicationController 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(','))+")" end sql = "(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})" if container_type != 'all' && User.current != @user sql = "user_id = #{@user.id} and(" + sql + ")" end end - + @user_activities_count = UserActivity.where("#{sql}").order('updated_at desc').count @user_activities = UserActivity.where("#{sql}").order('updated_at desc').limit(10).offset(@page * 10) @type = params[:type] respond_to do |format| format.js - format.html {render :layout => 'new_base_user'} + format.html {render :layout => 'base_project_community'} end end @@ -3539,7 +3777,7 @@ class UsersController < ApplicationController # @syllabus = paginateHelper @syllabus,@limit respond_to do |format| - format.html {render :layout => 'new_base_user'} + format.html {render :layout => 'base_course_community'} end end @@ -3683,7 +3921,7 @@ class UsersController < ApplicationController @my_joined_projects_count = @my_joined_projects.count respond_to do |format| - format.html {render :layout => 'new_base_user'} + format.html {render :layout => 'base_project_community'} end end 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 02bdde103..73b5e9b5f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -37,11 +37,21 @@ module ApplicationHelper # super # end + # 获取多种类型的user用户名 + def user_message_username user + user.try(:show_name) + end + # 超出1w后用k+形式显示 def switch_integer_into_k number number > 10000 ? (number.to_f / 1000).round.to_s + "k" : number end + # 判断某个课程是否包含仅对自己可见的作业 + def course_has_score_open_common_homework course + course.homework_commons.select{|hc| hc.score_open == 0}.count > 0 ? true : false + end + # 隐藏项目以外的信息 # return: true 显示,false 不显示 def hidden_unproject_infos @@ -72,12 +82,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 @@ -2786,6 +2820,37 @@ module ApplicationHelper end technical_title end + # 用户项目总数 + def user_project_count + @my_projects = @user.projects.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS updatetime").order("updatetime DESC") + @my_project_total = @my_projects.count + end + + # 用户的课程总数 + def user_course_count + @my_course_count = @user.syllabuses.count + + sy_courses = @user.courses.visible.not_deleted + syllabus_ids = sy_courses.empty? ? '(-1)' : "(" + sy_courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")" + syllabus_members = SyllabusMember.where("user_id = #{@user.id}") + syllabus_member_ids = syllabus_members.empty? ? "(-1)" : "(" + syllabus_members.map{|syl_mem| syl_mem.syllabus_id}.join(',') + ")" + @join_syllabuses = Syllabus.where("(id in #{syllabus_ids} or id in #{syllabus_member_ids}) and user_id != #{@user.id}") + @my_joined_course_count = @join_syllabuses.count + + @user_course_total = @my_joined_course_count + @my_course_count + end + + # 用户发布的issue数 + def issues_author_is_self_count + @issues = Issue.where( :author_id => @user.id ) + @issues_author_is_self_count = @issues.count + end + + # 用户收到的issue数 + def issues_assigned_is_self_count + @issues = Issue.where( :assigned_to_id => @user.id ) + @issues_assigned_is_self_count = @issues.count + end def get_user_roll user technical_title = "" @@ -3705,7 +3770,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/helpers/users_helper.rb b/app/helpers/users_helper.rb index 98024954d..879a7bb3c 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -94,13 +94,13 @@ module UsersHelper def pull_request_message_status ma case ma.status when 1 - "创建了PullRequest:" + "创建了PullRequest:" when 2 - "接受了PullRequest:" + "接受了PullRequest:" when 3 - "重新打开了PullRequest:" + "重新打开了PullRequest:" when 4 - "关闭了PullRequest:" + "关闭了PullRequest:" end end @@ -135,11 +135,11 @@ module UsersHelper def applied_project_tip applied_message case applied_message.status when 4 - "拒绝申请加入项目:" + "拒绝申请加入:" when 5,3,2,1,7 - "申请加入项目:" + "申请加入:" when 6 - "同意申请加入项目" + "同意申请加入:" end end @@ -159,6 +159,10 @@ module UsersHelper end end + def is_current_user + is_current_user = (User.current == @user) + end + def applied_project_tip_header applied_message case applied_message.status when 4 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..6fdd978f3 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 @@ -133,6 +135,10 @@ class Issue < ActiveRecord::Base after_save :after_create_from_copy after_destroy :update_parent_attributes + def user + self.author + end + #动态的更新 def update_activity update_user_activity(self.class, self.id) diff --git a/app/models/message.rb b/app/models/message.rb index 1d76c8ef6..309291183 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -106,6 +106,10 @@ class Message < ActiveRecord::Base end } + def description + self.content + end + def topic? parent_id.nil? end 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 @@
<%= student_score.score<0 ? 0 : student_score.score.to_i %>
++ <% if !(User.current.allowed_to?(:as_teacher, @course) || User.current.admin?) && User.current.id != student_score.user.id && course_has_score_open_common_homework(@course) %> + <%= "**" %> + <% else %> + <%= student_score.score<0 ? 0 : student_score.score.to_i %> + <% end %> +
请至少选择一个身份
++ | 修订号 | +描述 | +提交者 | +提交日期 | +
---|---|---|---|---|
+ | + <%= 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 ? "他们可以主动加入班级" : "不可以主动加入班级了" %>