diff --git a/Gemfile b/Gemfile index 1305320cf..cbeade2a3 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' diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d14bccc4e..ad0fab173 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -372,7 +372,8 @@ class ApplicationController < ActionController::Base return true end - if allowed + + if allowed || (params[:type] && params[:type] == "wechat" ) true else if @project && @project.archived? diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 5d1345f24..3986acc0a 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -130,7 +130,12 @@ class AttachmentsController < ApplicationController def download # modify by nwb # 下载添加权限设置 - candown = attachment_candown @attachment + if (params[:type] && params[:type] == "wechat" ) + candown = true + else + candown = attachment_candown @attachment + end + if candown || User.current.admin? || User.current.id == @attachment.author_id if stale?(:etag => @attachment.digest) if params[:preview] == 'true' @@ -710,7 +715,7 @@ class AttachmentsController < ApplicationController def has_login unless (@attachment && @attachment.container_type == "Organization").nil? unless (@attachment && @attachment.container_type == "PhoneAppVersion").nil? - render_403 if !User.current.logged? && !(@attachment.container_type == 'OrgSubfield' && @attachment.container.organization.allow_guest_download) && !(@attachment.container_type == 'OrgDocumentComment' && @attachment.container.organization.allow_guest_download) + render_403 if (!User.current.logged? && !(params[:type] && params[:type] == "wechat")) && !(@attachment.container_type == 'OrgSubfield' && @attachment.container.organization.allow_guest_download) && !(@attachment.container_type == 'OrgDocumentComment' && @attachment.container.organization.allow_guest_download) end end end diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index bdbdc7d9c..6fb2868bc 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -132,16 +132,13 @@ class IssuesController < ApplicationController User.current.at_messages.unviewed('Journal', j.id).each {|x| x.viewed!} end - # 缺陷状态更新 - query_journals = @issue.journals - query_journals.each do |query_journal| - query_journal.forge_messages.each do |f| - if User.current.id == f.user_id - f.update_attributes(:viewed => true) - end - end - end - # end + # 缺陷状态消息更新 + query_journals_ids = @issue.journals.map{|journal| journal.id} + if query_journals_ids.length > 0 + query_journals = ForgeMessage.where("user_id =? and forge_message_type =? and forge_message_id in (#{query_journals_ids.join(",")})", User.current.id, "Journal") + query_journals.update_all(:viewed => true) + end + @jour_reply = Journal.new @journals = @issue.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all @journals.each_with_index {|j,i| j.indice = i+1} diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 56ffc77e2..2b31cae13 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -88,7 +88,7 @@ class OrganizationsController < ApplicationController shield_project_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Project'").map(&:shield_id) shield_course_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Course'").map(&:shield_id) project_ids = (@organization.projects.map(&:id) - shield_project_ids) << 0 - course_ids = (@organization.courses.map(&:id) - shield_course_ids) << 0 + course_ids = (@organization.courses.not_deleted.map(&:id) - shield_course_ids) << 0 course_types = "('Message','News','HomeworkCommon','Poll','Course')" @project_acts = get_project_activities_org @organization, project_ids @course_acts = get_course_activities_org @organization, course_ids @@ -140,7 +140,7 @@ class OrganizationsController < ApplicationController shield_project_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Project'").map(&:shield_id) shield_course_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Course'").map(&:shield_id) project_ids = (@organization.projects.map(&:id)-shield_project_ids) << 0 - course_ids = (@organization.courses.map(&:id)-shield_course_ids) << 0 + course_ids = (@organization.courses.not_deleted.map(&:id)-shield_course_ids) << 0 course_types = "('Message','News','HomeworkCommon','Poll','Course')" case params[:type] when nil diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index 365889640..4e522ec73 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -252,7 +252,7 @@ class QualityAnalysisController < ApplicationController unresolved_issue_count = JSON.parse(unresolved_issues)["total"].to_i all_issues = open(@sonar_address + "/api/issues/search?projectKeys=#{@resource_id}&authors=#{email}").read all_issue_count = JSON.parse(all_issues)["total"].to_i - ratio = (changes == 0 ? 0 : format("%0.4f",unresolved_issue_count.to_f/changes.to_f)) + ratio = ((changes == 0 || all_issue_count == 0) ? 0 : format("%0.4f",all_issue_count.to_f/changes.to_f)) @user_quality_infos << {:email => email, :changes => changes, :unresolved_issue_count => unresolved_issue_count, :ratio => ratio, :all_issue_count => all_issue_count} end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e0fa253b3..559f29235 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1691,9 +1691,12 @@ class UsersController < ApplicationController when "current_user" container_type = 'Principal' act_type = 'Principal' + when "all" + container_type = 'all' + act_type = 'all' end end - if container_type != '' && act_type != '' + 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' @@ -1709,69 +1712,19 @@ class UsersController < ApplicationController else if User.current != @user blog_ids = "("+@user.blog.id.to_s+")" - 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}) "+ - "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}))" 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(','))+")" - 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})" + 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 = UserActivity.where("#{sql}").order('updated_at desc').limit(10).offset(@page * 10) - # if params[:type].present? - # case params[:type] - # when "course_homework" - # @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'HomeworkCommon'").order('updated_at desc').limit(10).offset(@page * 10) - # when "course_news" - # @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'News'").order('updated_at desc').limit(10).offset(@page * 10) - # when "course_message" - # @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10) - # when "course_poll" - # @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Poll'").order('updated_at desc').limit(10).offset(@page * 10) - # when "course_journals" - # @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'JournalsForMessage'").order('updated_at desc').limit(10).offset(@page * 10) - # when "project_issue" - # @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Issue'").order('updated_at desc').limit(10).offset(@page * 10) - # when "project_message" - # @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10) - # when "user_journals" - # @user_activities = UserActivity.where("container_type = 'Principal' and act_type= 'JournalsForMessage' and container_id = #{@user.id}").order('updated_at desc').limit(10).offset(@page * 10) - # when "current_user" - # @user_activities = UserActivity.where("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}))").order('updated_at desc').limit(10).offset(@page * 10) - # else - # if @user == User.current - # 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(','))+")" - # else - # blog_ids = "("+@user.blog.id.to_s+")" - # end - # @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 - # else - # # @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})").order('updated_at desc').limit(10).offset(@page * 10) - # # 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(','))+")" - # # 减少数据库交互 - # if @user == User.current - # 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 + ")" - # else - # user_ids = "(" + @user.id.to_s + ")" - # end - # watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}") - # blog_ids = watched_user_blog_ids.empty? ? "(-1)" : "(" + watched_user_blog_ids.map { |blog| 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 - # @user_activities = paginateHelper @user_activities,500 @type = params[:type] respond_to do |format| format.js diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3c125a185..94b0b2c6e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -417,13 +417,13 @@ module ApplicationHelper end # status_id:3、已解决 5、已关闭 if issue.status_id == 3 - s = link_to text, issue_path(issue), :class => "text_line_s", :title => title + s = link_to text, issue_path(issue), :class => "text_line_s fl", :title => title elsif issue.status_id == 5 - s = link_to text, issue_path(issue), :class => "text_line_s del_line", :title => title + s = link_to text, issue_path(issue), :class => "text_line_s del_line fl", :title => title else - s = link_to text, issue_path(issue), :class => "c_blue", :title => title + s = link_to text, issue_path(issue), :class => "c_blue fl", :title => title end - s << h(": #{subject}") if subject + s << h(": #{subject}".html_safe) if subject s = h("#{issue.project} - ") + s if options[:project] s end @@ -652,7 +652,7 @@ module ApplicationHelper s << watcher_link(@project, User.current)#, ['whiteButton']) s << "" end - s << (render :partial => 'projects/project', :locals => {:project => project}).to_s + s << (render :partial => 'projects/tracker_project', :locals => {:project => project}).to_s else s << (render :partial => 'projects/course', :locals => {:project => project}).to_s end @@ -832,9 +832,15 @@ module ApplicationHelper atts.count > 0 ? true :false end - # 必须是项目成,项目必须提交过代码 + # 如果Pull Request数量为0就显示在更多中 + def allow_show_pull_request project + g = Gitlab.client + count = g.merge_requests(project.gpid).count + end + + # 必须是项目成员,项目必须提交过代码 def allow_pull_request project - return false if project.gpid.nil? + return 0 if project.gpid.nil? g = Gitlab.client count = g.user_static(project.gpid, :rev => "master").count count @@ -3420,6 +3426,43 @@ def get_hw_index(hw,is_teacher) return index end +def get_hw_status homework_common + str = "" + if homework_common.homework_detail_manual + if homework_common.homework_detail_manual.comment_status == 0 && homework_common.publish_time.nil? + str += '挂起' + elsif homework_common.homework_detail_manual.comment_status == 0 + str += '未发布' + elsif homework_common.homework_detail_manual.comment_status == 1 + if homework_common.anonymous_comment == 0 + str += '未开启匿评' + else + str += '匿评已禁用' + 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") + str += '作品补交中' + end + elsif homework_common.homework_detail_manual.comment_status == 2 + if homework_common.anonymous_comment == 0 + str += '匿评中' + else + str += '匿评已禁用' + end + str += '教师评阅中' + elsif homework_common.homework_detail_manual.comment_status == 3 + if homework_common.anonymous_comment == 0 + str += '匿评已结束' + else + str += '匿评已禁用' + end + str += '教师评阅中' + end + end + str +end + def get_group_member_names work result = "" unless work.nil? diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 398fb8510..bc52b0002 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -162,17 +162,17 @@ module UsersHelper end def current_time_and_term_resource course - str = "" + str = course.syllabus.title + " · " term = cur_course_term_resource name = course.name if (course.time == course.end_time && course.term == course.end_term) || (course.end_term.nil? && course.end_time.nil?) || course.time > Time.now.year - str = name + "(" + course.time.to_s + course.term.to_s + ")" + str = str + name + "(" + course.time.to_s + course.term.to_s + ")" elsif course.time == Time.now.year && set_term_value(cur_course_term) <= set_term_value(course.term) - str = name + "(" + course.time.to_s + course.term.to_s + ")" + str = str + name + "(" + course.time.to_s + course.term.to_s + ")" elsif course.end_time < Time.now.year || (course.end_time == Time.now.year && set_term_value(cur_course_term) >= set_term_value(course.term)) - str = name + "(" + course.end_time.to_s + course.end_term.to_s + ")" + str = str + name + "(" + course.end_time.to_s + course.end_term.to_s + ")" else - str = name + "(" + Time.now.year.to_s + cur_course_term_resource.to_s + ")" + str = str + name + "(" + Time.now.year.to_s + cur_course_term_resource.to_s + ")" end str end diff --git a/app/views/admin/projects.html.erb b/app/views/admin/projects.html.erb index 5e3a927da..80cc40fb0 100644 --- a/app/views/admin/projects.html.erb +++ b/app/views/admin/projects.html.erb @@ -64,7 +64,6 @@
教师:<%= course_teacher_link teacher_num %> @@ -84,4 +88,12 @@
请将邀请码告诉学生和教辅
+他们可以主动加入班级
+<%= textilizable(project.short_description.strip, :project => project) %>
+