diff --git a/.gitignore b/.gitignore index 9d33b264c..601f691a1 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,4 @@ public/javascripts/wechat/node_modules/ .access_token tmux*.log config/wechat.yml +config/oneapm.yml diff --git a/app/controllers/blog_comments_controller.rb b/app/controllers/blog_comments_controller.rb index 148f45d2c..b0475097d 100644 --- a/app/controllers/blog_comments_controller.rb +++ b/app/controllers/blog_comments_controller.rb @@ -40,9 +40,10 @@ class BlogCommentsController < ApplicationController end def show @article = BlogComment.find(params[:id]) - all_comments = [] - @replies = get_all_children(all_comments, @article) + @replies = BlogComment.where("root_id = #{@article.id}").reorder("created_on desc") @reply_count = @replies.count + @replies = get_no_children_comments_all @replies + @limit_count = @replies.count @page = params[:page] ? params[:page].to_i + 1 : 0 @limit = 10 @replies = @replies[@page * @limit..@page * @limit + 9] diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index eeea2d01a..8c6cc4f0c 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -26,7 +26,7 @@ class BlogsController < ApplicationController @type = 2 @topics.each do |topic| - topic[:infocount] = get_praise_num(topic) + (topic.parent ? topic.parent.children.count : topic.children.count) + topic[:infocount] = get_praise_num(topic) + BlogComment.where("root_id = #{topic.id}").count if topic[:infocount] < 0 topic[:infocount] = 0 end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 0bb027153..5e0ef4638 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -23,7 +23,7 @@ class CoursesController < ApplicationController before_filter :can_show_course, :except => [] before_filter :logged_user_by_apptoken,:only => [:show,:feedback] - before_filter :find_course, :except => [ :index, :search, :new,:join,:unjoin, :create, :new_join, :course,:join_private_courses, :join_course_multi_role] + before_filter :find_course, :except => [ :index, :search, :new, :join, :unjoin, :create, :new_join, :course, :join_private_courses, :join_course_multi_role] before_filter :authorize_course, :only => [:show, :settings, :update, :course] before_filter :authorize_course_global, :only => [:new,:create] before_filter :toggleCourse, :only => [:finishcourse, :restartcourse] @@ -303,18 +303,21 @@ class CoursesController < ApplicationController @member = Member.where(:course_id => @course.id, :user_id => params[:user_id]).first @member.course_group_id = params[:course_group_id].to_i @member.save - if params[:group_id] && params[:group_id] != "-1" - @group = CourseGroup.find params[:group_id] - results = student_homework_score(@group.id,0,0,"desc") - @limit = 50 - @page = params[:page].nil? ? 1 : params['page'].to_i - @members_count = results.count - @mem_pages = Paginator.new @members_count, @limit, @page - @results = paginateHelper results, @limit - else - @course_groups = @course.course_groups - @no_group_count = @course.student.count - @course.members.where("course_group_id != 0").count + if params[:group_id] != "0" + if params[:group_id] == "-1" + @group = "-1" + else + @group = CourseGroup.find params[:group_id] + end + # results = student_homework_score(@group.id,0,0,"desc") + # @limit = 50 + # @page = params[:page].nil? ? 1 : params['page'].to_i + # @members_count = results.count + # @mem_pages = Paginator.new @members_count, @limit, @page + # @results = paginateHelper results, @limit end + @course_groups = @course.course_groups + @no_group_count = @course.student.count - @course.members.where("course_group_id != 0").count @canShowCode = isCourseTeacher(User.current.id,@course) respond_to do |format| format.js @@ -561,6 +564,7 @@ class CoursesController < ApplicationController def delete_member member = @course.members.find params[:member_id] student_role = member.member_roles.where("role_id = 10").first + teacher_role = member.member_roles.where("role_id = 7 || role_id = 9").first if member && member.deletable? && student_role user_admin = CourseInfos.where("user_id = ? and course_id = ?", member.user_id, @course.id) if user_admin.size > 0 @@ -569,8 +573,9 @@ class CoursesController < ApplicationController joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,@course.id) joined.destroy_all - if member.member_roles.count > 1 + if member.member_roles.count > 1&& student_role && teacher_role student_role.destroy + teacher_role.update_attribute("is_current", 1) member.update_attribute("course_group_id", 0) else member.destroy @@ -829,11 +834,11 @@ class CoursesController < ApplicationController end if @course #发送微信消息 - # count = ShieldWechatMessage.where("container_type='User' and container_id=#{User.current.id} and shield_type='Course' and shield_id=#{@course.id}").count - # if count == 0 - # ss = SyllabusesService.new - # ss.send_wechat_create_class_notice User.current,@course - # end + count = ShieldWechatMessage.where("container_type='User' and container_id=#{User.current.id} and shield_type='Course' and shield_id=#{@course.id}").count + if count == 0 + ss = SyllabusesService.new + ss.send_wechat_create_class_notice User.current,@course + end respond_to do |format| flash[:notice] = l(:notice_successful_create) format.html {redirect_to course_url(@course)} @@ -1303,6 +1308,21 @@ class CoursesController < ApplicationController redirect_to user_url(User.current) end + #归档班级 + def archive_course + if params[:source] == "1" + @syllabus = @course.syllabus + end + if params[:type] == "0" + @course.delete! + else + @course.update_attribute(:is_delete, false) + end + respond_to do |format| + format.js + end + end + # 恢复已删除的课程 def renew if User.current.admin? diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index e3caaf9fb..02a8400a7 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -374,12 +374,13 @@ class ExerciseController < ApplicationController =end @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? @all_exercises = @course.exercises.where("exercise_status > 1").order("created_at desc") - @exercise_count = @exercise.exercise_users.where('score is not NULL').count - if @is_teacher || (!@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time <= Time.now) - @exercise_users_list = @exercise.exercise_users.where('score is not NULL') + student_id = @course.student.blank? ? "(-1)" : "(" + @course.student.map{|student| student.student_id}.join(",") + ")" + @exercise_count = @exercise.exercise_users.where("score is not NULL and user_id in #{student_id}").count + if @is_teacher || (!@exercise.exercise_users.where("user_id = #{User.current.id} and user_id in #{student_id}").empty? && @exercise.end_time <= Time.now) + @exercise_users_list = @exercise.exercise_users.where("score is not NULL and user_id in #{student_id}") @show_all = true; - elsif !@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time > Time.now - @exercise_users_list = @exercise.exercise_users.where("user_id = ? and score is not NULL",User.current.id) + elsif !@exercise.exercise_users.where("user_id = #{User.current.id} and user_id in #{student_id}").empty? && @exercise.end_time > Time.now + @exercise_users_list = @exercise.exercise_users.where("user_id = ? and score is not NULL and user_id in #{student_id}",User.current.id) else @exercise_users_list = [] end @@ -537,7 +538,7 @@ class ExerciseController < ApplicationController else # 更新提交状态 cur_exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", User.current, @exercise.id).first - cur_exercise_user.update_attributes(:status => 1) + cur_exercise_user.update_attributes(:status => 1, :commit_status => 1) # 答题过程中需要统计完成量 @uncomplete_question = get_uncomplete_question(@exercise, User.current) # 获取改学生的考试得分 @@ -618,6 +619,95 @@ class ExerciseController < ApplicationController score = score1 + score2 + score3 end + #导入试卷的弹框 + def other_exercise + # 查作者是我,或者作者是当前课程的老师,且不在当前课程内的试卷 进行导入 + @order,@b_sort = params[:order] || "created_at",params[:sort] || "desc" + @r_sort = @b_sort == "desc" ? "asc" : "desc" + courses = User.current.courses.not_deleted.select { |course| User.current.allowed_to?(:as_teacher,course)} + course_ids = courses.empty? ? "(-1)" : "(" + courses.map { |course| course.id}.join(',') + ")" + #none_courses = User.current.courses.where("is_delete = 1 or #{Course.table_name}.id = #{params[:course_id].to_i}") + #none_course_ids = none_courses.empty? ? "(-1)" : "(" + none_courses.map { |course| course.id}.join(',') + ")" + @exercises = Exercise.where("(user_id = #{User.current.id} or course_id in #{course_ids}) and course_id != #{params[:course_id].to_i}").order("#{@order} #{@b_sort}") + @course_id = params[:course_id] + @is_remote = true + @ex_count = @exercises.count + @ex_pages = Paginator.new @ex_count, 10, params['page'] || 1 + @offset ||= @ex_pages.offset + @exercises = paginateHelper @exercises,10 + respond_to do |format| + format.js + end + end + + #搜索导入页面的试卷 + def search_exercises + @order,@b_sort = params[:order] || "created_at",params[:sort] || "desc" + @r_sort = @b_sort == "desc" ? "asc" : "desc" + search = params[:name].to_s.strip.downcase + courses = User.current.courses.not_deleted.select { |course| User.current.allowed_to?(:as_teacher,course)} + course_ids = courses.empty? ? "(-1)" : "(" + courses.map { |course| course.id}.join(',') + ")" + @exercises = Exercise.where("(user_id = #{User.current.id} or course_id in #{course_ids}) and course_id != #{params[:course_id].to_i} and exercise_name like '%#{search}%'").order("#{@order} #{@b_sort}") + @is_remote = true + @ex_count = @exercises.count + @ex_pages = Paginator.new @ex_count, 10, params['page'] || 1 + @offset ||= @ex_pages.offset + @exercises = paginateHelper @exercises,10 + @course_id = params[:course_id] + respond_to do |format| + format.js + end + end + + #将选择的试卷导入到班级 + def import_other_exercise + course_id = params[:course_id] + @course = Course.find(course_id) + params[:exercise_id].each_with_index do |ex,i| + exercise = Exercise.find(ex) + option = { + :exercise_name => exercise.exercise_name, + :exercise_status => 1, + :user_id => User.current.id, + :show_result => 1, + :course_id => @course.id, + :time => exercise.time, + :exercise_description => exercise.exercise_description + } + @exercise = Exercise.create option + + exercise.exercise_questions.each do |q| + option = { + :question_title => q[:question_title], + :question_type => q[:question_type] || 1, + :question_number => q[:question_number], + :question_score => q[:question_score] + } + @exercise_question = @exercise.exercise_questions.new option + + for i in 1..q.exercise_choices.count + choice_option = { + :choice_position => i, + :choice_text => q.exercise_choices[i-1][:choice_text] + } + @exercise_question.exercise_choices.new choice_option + end + + for i in 1..q.exercise_standard_answers.count + standard_answer_option = { + :exercise_choice_id => q.exercise_standard_answers[i-1][:exercise_choice_id], + :answer_text => q.exercise_standard_answers[i-1][:answer_text] + } + @exercise_question.exercise_standard_answers.new standard_answer_option + end + end + @exercise.save + end + respond_to do |format| + format.js + end + end + private #测验列表转换为excel def exercise_to_xls items diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index b479fa206..b9a49dbcb 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -261,20 +261,20 @@ class HomeworkCommonController < ApplicationController work_ids = "(" + @homework.student_works.has_committed.map(&:id).join(",") + ")" if @homework.homework_type != 3 @homework.student_works.has_committed.each do |student_work| - absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids}").count + absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids} and reviewer_role = 3").count student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0 student_work.save end else @homework.student_works.has_committed.each do |student_work| - absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids}").count + absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids} and reviewer_role = 3").count student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0 student_work.save pros = student_work.student_work_projects.where("is_leader = 0") user_ids = pros.empty? ? "(-1)" : "(" + pros.map{|stu|stu.user_id}.join(",") + ")" student_works = @homework.student_works.where("user_id in #{user_ids}") student_works.each do |st_work| - absence_penalty_count = st_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - st_work.user.student_works_scores.where("student_work_id IN #{work_ids}").count + absence_penalty_count = st_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - st_work.user.student_works_scores.where("student_work_id IN #{work_ids} and reviewer_role = 3").count st_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0 st_work.save end diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index a137b7cd1..c6cb018a5 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -102,6 +102,7 @@ class IssuesController < ApplicationController @issue_count = @query.issue_count @test = params[:test] @project_sort = 'issues.updated_on desc' + if params[:test] != "0" case @test when "1" @@ -284,11 +285,11 @@ class IssuesController < ApplicationController # 用户编辑更改issue def update - # params[:assigned_to_id] = nil if params[:assigned_to_id].to_i == 0 + # params[:assigned_to_id] = nil if params[:assigned_to_id].to_i == 0 + # params[:fixed_version_id] = nil if params[:fixed_version_id].to_i == 0 if params[:issue_detail] issue = Issue.find(params[:id]) issue = update_user_issue_detail(issue, params) - @issue.assigned_to_id = nil if @issue.assigned_to_id == 0 @saved = update_user_issue_detail(issue, params) return else @@ -296,6 +297,7 @@ class IssuesController < ApplicationController return unless update_issue_from_params @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads])) @issue.assigned_to_id = nil if @issue.assigned_to_id == 0 + @issue.fixed_version_id = nil if @issue.fixed_version_id == 0 saved = false begin @saved = @issue.save_issue_with_child_records(params, @time_entry) @@ -630,7 +632,9 @@ class IssuesController < ApplicationController end end # 搜索结果 - @issues_filter = @query.issues(:order => @project_sort) + # SELECT assigned_to_id, count(*) as ac FROM `issues` where project_id = @project.id group by assigned_to_id order by ac desc; + @issues_filter = @query.issues.sort_by{ |i| Issue.where(:project_id => @project.id , :assigned_to_id => i.assigned_to_id).count }.reverse + # @issues_filter = @query.issues(:order => @project_sort) # if params[:type] == 1 || params[:type].nil? # @results = @issues_filter @@ -668,7 +672,7 @@ class IssuesController < ApplicationController @alltotal[issue.tracker_id.to_i] = @alltotal[issue.tracker_id.to_i] + 1 user_id = issue.assigned_to_id if issue.assigned_to_id.nil? - user_id = issue.author_id + user_id = 0 end if !@results[user_id].nil? @@ -696,7 +700,7 @@ class IssuesController < ApplicationController tmpuser = User.find(user_id) - @results[user_id][:name] = tmpuser.nil? ? " " : tmpuser.show_name + @results[user_id][:name] = tmpuser.nil? ? "" : tmpuser.show_name #所有的 @results[user_id][0] = 1 for i in 1..17 do diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 0c7eb570f..51fcdcc2d 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -50,6 +50,8 @@ class MessagesController < ApplicationController all_comments = [] @replies = Message.where("root_id = #{@topic.id}").reorder("created_on desc") @reply_count = @replies.count + @replies = get_no_children_comments_all @replies + @limit_count = @replies.count @page = params[:page] ? params[:page].to_i + 1 : 0 @limit = 10 @replies = @replies[@page * @limit..@page * @limit + 9] @@ -171,9 +173,6 @@ class MessagesController < ApplicationController @reply.root_id = parent.root_id.nil? ? parent.id : parent.root_id # @reply.reply_id = params[:id] parent.children << @reply - @user_activity_id = params[:user_activity_id] if params[:user_activity_id] - @is_course = params[:is_course] if params[:is_course] - @is_board = params[:is_board] if params[:is_board] else @quote = params[:quote][:quote] @reply = Message.new @@ -207,8 +206,8 @@ class MessagesController < ApplicationController end if params[:user_activity_id] @user_activity_id = params[:user_activity_id] - @is_course = params[:is_course] - @is_board = params[:is_board] + @is_course = params[:is_course] if params[:is_course] + @is_board = params[:is_board] if params[:is_board] respond_to do |format| format.js end @@ -282,8 +281,8 @@ class MessagesController < ApplicationController @message.destroy @topic = Message.find(params[:activity_id].to_i) @user_activity_id = params[:user_activity_id] - @is_course = params[:is_course] - @is_board = params[:is_board] + @is_course = params[:is_course] if params[:is_course] + @is_board = params[:is_board] if params[:is_board] respond_to do |format| format.js end diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index 53afa50aa..aa037b8d5 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -172,6 +172,8 @@ class NewsController < ApplicationController @news = result[:news] @comments = result[:comments] @comments_count = @comments.count + @comments = get_no_children_comments_all @comments + @limit_count = @comments.count @page = params[:page] ? params[:page].to_i + 1 : 0 @limit = 10 @comments = @comments[@page * @limit..@page * @limit + 9] diff --git a/app/controllers/org_document_comments_controller.rb b/app/controllers/org_document_comments_controller.rb index 49e970af7..6b8d11479 100644 --- a/app/controllers/org_document_comments_controller.rb +++ b/app/controllers/org_document_comments_controller.rb @@ -41,8 +41,10 @@ class OrgDocumentCommentsController < ApplicationController @org_subfield = OrgSubfield.where(:id => @document.org_subfield_id).first @subfield_content = @organization.org_subfields.order("priority") all_comments = [] - @replies = get_all_children(all_comments, @document) + @replies = OrgDocumentComment.where("root_id = #{@document.id}").reorder("created_at desc") @reply_count = @replies.count + @replies = get_no_children_comments_all @replies + @limit_count = @replies.count @page = params[:page] ? params[:page].to_i + 1 : 0 @limit = 10 @replies = @replies[@page * @limit..@page * @limit + 9] diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index a0bf28ac1..b9d61e61e 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 # Redmine - project management software # Copyright (C) 2006-2013 Jean-Philippe Lang # @@ -31,7 +32,7 @@ class ProjectsController < ApplicationController before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches,:course] before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches] before_filter :require_admin, :only => [ :copy, :unarchive, :destroy, :calendar] - before_filter :file, :statistics #:watcherlist + before_filter :file # 除非项目内人员,不可查看成员, TODO: 完了写报表里去 # before_filter :memberAccess, only: :member @@ -534,6 +535,23 @@ class ProjectsController < ApplicationController end end + def project_watcherlist + unless @project.nil? + if !@project.is_public? && !User.current.member_of?(@project) && !User.current.admin? + render_403 + else + @users -= watched.watcher_users if @watched + end + @watchers = @project.watcher_users + @limit = 20 + @is_remote = true + @watchers_count = @watchers.count + @watcher_pages = Paginator.new @watchers_count, @limit, params['page'] || 1 + @offset ||= @watcher_pages.offset + @watchers = paginateHelper @watchers, 20 + end + end + # include CoursesHelper def member # 消息"同意加入项目" @@ -600,6 +618,13 @@ class ProjectsController < ApplicationController def member_forked @forked_projects = Project.where(:forked_from_project_id => @project.id) + @limit = 20 + @is_remote = true + @forked_count = @forked_projects.count + @forked_pages = Paginator.new @forked_count, @limit, params['page'] || 1 + @offset ||= @forked_pages.offset + @forked_projects = paginateHelper @forked_projects, @limit + # @forked_members = User.find_by_sql("SELECT u.* FROM `projects` p,`users` u where p.user_id = u.id and p.forked_from_project_id = #{@project.id} ;") end @@ -739,7 +764,7 @@ class ProjectsController < ApplicationController rescue Exception => e puts e end - # 删除Trustie班额本库记录 + # 删除Trustie版本库记录 repoisitory = Repository.where(:project_id => @project.id, :type => GITLABTYPE).first repoisitory.delete @project.update_column(:gpid, nil) @@ -769,7 +794,7 @@ class ProjectsController < ApplicationController end end - #配置成员弹框 + # 配置成员弹框 def delete_member_pop @member = Member.find(params[:member].to_i) respond_to do |format| @@ -799,6 +824,31 @@ class ProjectsController < ApplicationController @project = nil end + REP_TYPE = "Repository::Gitlab" + # Delete @project's repository + def destroy_repository + if is_project_manager?(User.current.id, @project.id) + @gitlab_repository = Repository.where(:project_id => @project, :type => REP_TYPE).first + @is_true = params[:is_true] + if @is_true + begin + g = Gitlab.client + g.delete_project(@project.gpid) + @gitlab_repository.destroy + @gitlab_repository = nil + scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first + @repository = Repository.factory(scm) + @repository.is_default = @project.repository.nil? + @project.update_attribute(:gpid, nil) + rescue Exception => e + puts e + end + end + else + return render_403 + end + end + def show_projects_score respond_to do |format| format.html { render :layout => "base_projects"} @@ -939,16 +989,6 @@ class ProjectsController < ApplicationController true end - def watcherlist - unless @project.nil? - if !@project.is_public? && !User.current.member_of?(@project) && !User.current.admin? - render_403 - else - @users -= watched.watcher_users if @watched - end - end - end - #gcm def desc_sort_course_by_avtivity(activity_count,projects) return projects if activity_count.size<2 @@ -962,5 +1002,7 @@ class ProjectsController < ApplicationController end return projects end + #gcmend end + diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index ad60f2b70..72a1132c9 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -1,15 +1,19 @@ +# encoding: utf-8 # 如果你对改模块任何功能不清楚,请不要随便改 # @Hjqreturn class PullRequestsController < ApplicationController before_filter :authorize_logged before_filter :find_project_and_repository - before_filter :connect_gitlab, :only => [:index, :show, :create, :accept_pull_request, :pull_request_commits, :pull_request_changes, :new, - :update_pull_request, :pull_request_comments, :create_pull_request_comment, :compare_pull_request] + before_filter :connect_gitlab, :only => [:index, :show, :create, :accept_pull_request, :pull_request_commits, :pull_request_changes, :new, :update_pull_request, :pull_request_comments, :create_pull_request_comment, :compare_pull_request] + before_filter :member_allowed, :only => [:new, :create] + before_filter :manager_allowed, :only => [:accept_pull_request] layout "base_projects" include PullRequestsHelper include ApplicationHelper + require 'ostruct' + # 返回json格式 def index # project_menu_type 为了控制base顶部导航 @@ -91,10 +95,11 @@ class PullRequestsController < ApplicationController # 如果分支有改动 if compare_pull_request(source_branch, target_project_id, target_branch) # 如果传送了目标项目ID即向fork源项目发送请求 - if params[:forked_project_id] && params[:source_project] == "forked_project_name" + # if params[:forked_project_id] && params[:source_project] == "forked_project_name" + if !params[:target_project_id].blank? target_project_id = params[:forked_project_id].to_i request = @g.create_merge_request(@project.gpid, title, User.current.gid, :description => description, :source_branch => source_branch, :target_branch => target_branch, :target_project_id => target_project_id) - @fork_project_name = Project.find(@project.forked_from_project_id).try(:name) + @fork_project_name = Project.find(params[:target_project_id]).try(:name) @fork_pr_message = true if @fork_project_name else request = @g.create_merge_request(@project.gpid, title, User.current.gid, :description => description, :source_branch => source_branch, :target_branch => target_branch) @@ -108,8 +113,14 @@ class PullRequestsController < ApplicationController format.js{redirect_to new_project_pull_request_path(:show_tip => tip)} end end + rescue Gitlab::Error::Forbidden => e + @message = l(:label_pull_request_forbidden) + rescue Gitlab::Error::Conflict => e + @message = l(:label_pull_request_conflic) + rescue Gitlab::Error::NotFound => e + @message = l(:label_pull_request_notfound) rescue Exception => e - @message = e.message + puts e end end @@ -226,7 +237,7 @@ class PullRequestsController < ApplicationController # Gets the comments on a merge request. # # @example - # Gitlab.merge_request_comments(5, 1) + # Gitlab.merge_request_comments(5, 1) def pull_request_comments begin @comments = @g.merge_request_comments(@project.gpid, params[:id]).reverse @@ -269,23 +280,57 @@ class PullRequestsController < ApplicationController # id (required) - The ID of a project # merge_request_id (required) - The ID of MR def pull_request_changes - begin + @type = params[:type] @changes = @g.merge_request_changes(@project.gpid, params[:id]).try(:changes) + logger.info("###############################{@changes}") + diff = ActiveSupport::JSON.decode(@changes).first + diff = OpenStruct.new(diff) + diff_file = Trustie::Gitlab::Diff::File.new(diff) + logger.info("##############################") + output = '' + diff_file.diff_lines.each_with_index do |line, index| + type = line.type + last_line = line.new_pos + line_old = line.old_pos.to_s + + + if type == 'match' + ## 表示没有修改,两个都要显示行号 + output += "|#{line_old.center(4)}|#{last_line.to_s.center(4)}|#{line.text}\n" + else + old_line = type == 'new' ? ' '*4: line_old + new_line = type == 'old' ? ' '*4: last_line + output += "|#{old_line.to_s.center(4)}|#{new_line.to_s.center(4)}|#{line.text}\n" + end + end + @changes_count = @changes.count - @limit = 10 @is_remote = true @count = @changes_count @pages = Paginator.new @count, @limit, params['page'] || 1 @offset ||= @pages.offset @changes = paginateHelper @changes, 10 - rescue Exception => e - @message = e.message - end + end private + # post 相关操作权限控制 + # 项目管理员可操作 + def manager_allowed + unless is_project_manager?(User.current.id, @project.id) + return render_403 + end + end + + # 项目成员可操作 + def member_allowed + unless User.current.member_of?(@project) + return render_403 + end + end + def authorize_logged if !User.current.logged? redirect_to signin_path diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 29176550a..af1e2d336 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -49,6 +49,7 @@ class RepositoriesController < ApplicationController helper :repositories include RepositoriesHelper helper :project_score + require 'ostruct' #@root_path = RepositoriesHelper::ROOT_PATH # require 'net/ssh' @@ -582,6 +583,26 @@ update @project_menu_type = 5 @commit_diff = @g.commit_diff(@project.gpid, params[:changeset]) + diff = @commit_diff.first + diff = OpenStruct.new(diff) + logger.info("######################{diff}") + @diff_file = Trustie::Gitlab::Diff::File.new(diff) + + # diff_file.diff_lines.each_with_index do |line, index| + # type = line.type + # last_line = line.new_pos + # line_old = line.old_pos.to_s + # + # + # if type == 'match' + # ## 表示没有修改,两个都要显示行号 + # output += "|#{line_old.center(4)}|#{last_line.to_s.center(4)}|#{line.text}\n" + # else + # old_line = type == 'new' ? ' '*4: line_old + # new_line = type == 'old' ? ' '*4: last_line + # output += "|#{old_line.to_s.center(4)}|#{new_line.to_s.center(4)}|#{line.text}\n" + # end + # end @commit_details = @g.commit(@project.gpid, params[:changeset]) render :layout => 'base_projects' end diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index f788efd3f..fb99f6507 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -988,20 +988,20 @@ class StudentWorkController < ApplicationController work_ids = "(" + @homework.student_works.has_committed.map(&:id).join(",") + ")" if @homework.homework_type != 3 @homework.student_works.has_committed.each do |student_work| - absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids}").count + absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids} and reviewer_role = 3").count student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * homework_detail_manual.absence_penalty : 0 student_work.save end else @homework.student_works.has_committed.each do |student_work| - absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids}").count + absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids} and reviewer_role = 3").count student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * homework_detail_manual.absence_penalty : 0 student_work.save pros = student_work.student_work_projects.where("is_leader = 0") user_ids = pros.empty? ? "(-1)" : "(" + pros.map{|stu|stu.user_id}.join(",") + ")" student_works = @homework.student_works.where("user_id in #{user_ids}") student_works.each do |st_work| - absence_penalty_count = st_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - st_work.user.student_works_scores.where("student_work_id IN #{work_ids}").count + absence_penalty_count = st_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - st_work.user.student_works_scores.where("student_work_id IN #{work_ids} and reviewer_role = 3").count st_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * homework_detail_manual.absence_penalty : 0 st_work.save end diff --git a/app/controllers/syllabuses_controller.rb b/app/controllers/syllabuses_controller.rb index a6b11cfbf..13bacbd4b 100644 --- a/app/controllers/syllabuses_controller.rb +++ b/app/controllers/syllabuses_controller.rb @@ -92,12 +92,14 @@ class SyllabusesController < ApplicationController def destroy if @syllabus && @syllabus.courses.not_deleted.empty? @syllabus.destroy - redirect_to user_courselist_user_path(User.current.id) + redirect_to user_courselist_user_path(User.current) end end - #班级列表 + + #班级列表 list_type: 1 班级列表 2 归档班级列表 def syllabus_courselist + @list_type = params[:list_type].to_i || 0 @order, @c_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1 #确定 sort_type @@ -110,7 +112,7 @@ class SyllabusesController < ApplicationController sort_name = "updated_on" sort_type = @c_sort == 1 ? "asc" : "desc" - @courses = @syllabus.courses.where("is_delete = ?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS #{sort_name}").order("#{sort_name} #{sort_type}") + @courses = @syllabus.courses.where("is_delete = ?", @list_type).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS #{sort_name}").order("#{sort_name} #{sort_type}") #根据 作业+资源数排序 if @order.to_i == 2 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 89accca9e..aebc82b14 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -90,11 +90,51 @@ class UsersController < ApplicationController # order 排序条件 # subject 主题:搜索用(注意:搜索和列表调用同一方法,通过参数或者remote区分) def user_issues - subject = params[:subject] - author_id = params[:author_id] - @issues = Issue.where("author_id =? or assigned_to_id =? and subject like ?", (author_id ? author_id : @user.id) , @user, "%#{subject}%") + @subject = params[:subject] + # author_id = params[:author_id] + params[:assigned_to_id].to_i == 0 ? @assigned_to = nil : @assigned_to = params[:assigned_to_id].to_i + params[:author_id].to_i == 0 ? author_id = nil : author_id = params[:author_id].to_i + params[:project_id].to_i == 0 ? @project_id = nil : @project_id = params[:project_id] + if @project_id.nil? + if @assigned_to.nil? + if author_id.nil? + @issues = Issue.where("(author_id =? or assigned_to_id =? ) and subject like ?", + @user.id , @user.id, "%#{@subject}%").order('updated_on desc') + else + @issues = Issue.where("author_id =? and subject like ?", + author_id , "%#{@subject}%").order('updated_on desc') + end + else + @issues = Issue.where("assigned_to_id =? and subject like ?", @assigned_to, "%#{@subject}%").order('updated_on desc') + end + + else + if @assigned_to.nil? + if author_id.nil? + @issues = Issue.where("(author_id =? or assigned_to_id =? ) and project_id=? and subject like ?", + (author_id ? author_id : @user.id) , @user.id, @project_id, "%#{@subject}%").order('updated_on desc') + else + @issues = Issue.where("author_id =? and project_id=? and subject like ?", + author_id , @project_id, "%#{@subject}%").order('updated_on desc') + end + else + @issues = Issue.where("assigned_to_id =? and project_id=? and subject like ?", + @assigned_to, @project_id, "%#{@subject}%").order('updated_on desc') + end + end + @issues_filter = Issue.where("author_id =? or assigned_to_id =?", (author_id ? author_id : @user.id) , @user).order('updated_on desc') + @issues_assigned_count = Issue.where("assigned_to_id =? and subject like ?", @user.id, "%#{@subject}%").count + @issues_author_count = Issue.where("author_id =? and subject like ?", @user.id, "%#{@subject}%").count + @issue_open_count = Issue.where(" (author_id =? or assigned_to_id =?) and status_id in (1,2,3,4,6)", (author_id ? author_id : @user.id) , @user).count + @issue_close_count = Issue.where("(author_id =? or assigned_to_id =?) and status_id = 5", (author_id ? author_id : @user.id) , @user.id).count + @issue_count = @issues.count + @limit = 10 + @is_remote = true + @issue_pages = Paginator.new @issue_count, @limit, params['page'] || 1 + @offset ||= @issue_pages.offset + @issues = paginateHelper @issues, @limit respond_to do |format| - format.html{render :layout => 'new_base_user'} + format.html{render :layout => 'static_base'} format.api format.js end @@ -105,7 +145,7 @@ class UsersController < ApplicationController case params[:type] when 'JournalsForMessage' @comment = JournalsForMessage.find params[:comment].to_i - when 'Message' + when 'Message','is_project_message' @comment = Message.find params[:comment].to_i when 'BlogComment' @comment = BlogComment.find params[:comment].to_i @@ -113,9 +153,11 @@ class UsersController < ApplicationController @comment = OrgDocumentComment.find params[:comment].to_i when 'Comment' @comment = Comment.find params[:comment].to_i - when 'Journal' + when 'Journal','is_project_issue' @comment = Journal.find params[:comment].to_i end + @user_activity_id = params[:user_activity_id] + @parent_id = params[:parent_id] if params[:parent_id] end #二级回复 @@ -131,7 +173,6 @@ class UsersController < ApplicationController else @user_activity_id = -1 end - @hw_status = params[:hw_status].to_i when 'JournalsForMessage' @reply = JournalsForMessage.find params[:reply_id] @user_activity_id = params[:user_activity_id] @@ -141,15 +182,11 @@ class UsersController < ApplicationController @reply = Message.find params[:reply_id] @user_activity_id = params[:user_activity_id] @activity_id = params[:activity_id] - @is_course = params[:is_course] - @is_board = params[:is_board] @type = 'Message' when 'BlogComment' @reply = BlogComment.find params[:reply_id] @user_activity_id = params[:user_activity_id] @activity_id = params[:activity_id] - @homepage = params[:homepage] - @user_id = params[:user_id] @type = 'BlogComment' when 'OrgDocumentComment' @reply = OrgDocumentComment.find params[:reply_id] @@ -175,6 +212,104 @@ class UsersController < ApplicationController end end + #叠层回复框中的回复 + def reply_to_comment + @type = params[:type] + @reply = get_reply_by_type @type, params[:reply_id] + @parent_id = params[:parent_id] if params[:parent_id] + @user_activity_id = params[:user_activity_id] + @is_project = params[:is_project] if params[:is_project] + respond_to do |format| + format.js + end + end + + #多级回复 + def reply_detail + @type = params[:type] + reply = get_reply_by_type @type, params[:reply_id] + if @type == 'JournalsForMessage' + if reply.jour_type == "HomeworkCommon" + @type = "HomeworkCommon" + elsif reply.jour_type == "Syllabus" + @type = "Syllabus" + end + end + @user_activity_id = params[:user_activity_id] + case @type + when 'HomeworkCommon' + @root = HomeworkCommon.find reply.jour_id + options = {:notes => params[:reply_message], :reply_id => reply.user_id,:user_id => User.current.id,:m_parent_id => params[:reply_id].to_i,:m_reply_id => params[:reply_id].to_i, :root_id => reply.root_id} + comment = HomeworkCommon.add_homework_jour(User.current, params[:reply_message], reply.jour_id, reply.root_id, options) + @root.update_column('updated_at', Time.now) + @is_teacher = User.current.allowed_to?(:as_teacher, @root.course) || User.current.admin? + when 'JournalsForMessage' + options = {:user_id => User.current.id, + :status => true, + :m_parent_id => params[:reply_id], + :m_reply_id => params[:reply_id], + :reply_id => reply.user.id, + :notes => params[:reply_message], + :root_id => reply.root_id, + :is_readed => false} + @root = reply.root + comment = add_reply_adapter(@root, options) + @root.update_attribute(:updated_on,Time.now) + when 'Message' + @root = reply.root + comment = Message.new + comment.author = User.current + comment.board = reply.board + comment.content = params[:reply_message] + comment.subject = "RE: #{@root.subject}" + comment.reply_id = params[:reply_id] + comment.root_id = reply.root_id + reply.children << comment + @is_project = params[:is_project] if params[:is_project] + when 'BlogComment' + @root = reply.root + comment = BlogComment.new + comment.author = User.current + comment.blog = reply.blog + comment.title = "RE: #{@root.title}" + comment.content = params[:reply_message] + comment.reply_id = params[:reply_id] + comment.root_id = reply.root_id + reply.children << comment + when 'OrgDocumentComment' + @root = reply.root + comment = OrgDocumentComment.new(:creator_id => User.current.id, :reply_id => params[:reply_id]) + comment.title = "RE:#{@root.title}" + comment.content = params[:reply_message] + comment.root_id = reply.root_id + reply.children << comment + when 'News','Comment' + @root = News.find reply.commented_id + comment = @root.comments.build(:author_id => User.current.id, :reply_id => params[:reply_id], :comments => params[:reply_message], :parent_id => reply.id) + comment.save + when 'Issue', 'Journal' + @root = reply.issue + comment = @root.journals.build(:user_id => User.current.id, :reply_id => params[:reply_id], :notes => params[:reply_message], :parent_id => reply.id) + comment.save + @is_project = params[:is_project] if params[:is_project] + when 'Syllabus' + @root = Syllabus.find reply.jour_id + options = {:notes => params[:reply_message], :reply_id => reply.user_id,:user_id => User.current.id,:m_parent_id => params[:reply_id].to_i,:m_reply_id => params[:reply_id].to_i, :root_id => reply.root_id} + comment = Syllabus.add_syllabus_jour(User.current, params[:reply_message], reply.jour_id, reply.root_id, options) + @root.update_column('updated_at', Time.now) + @count = @root.journals_for_messages.count + @comments = @root.journals_for_messages.reorder("created_on desc").limit(3) + end + update_course_activity(@root.class.to_s,@root.id) + update_user_activity(@root.class.to_s,@root.id) + update_forge_activity(@root.class.to_s,@root.id) + update_org_activity(@root.class.to_s,@root.id) + update_principal_activity(@root.class.to_s,@root.id) + respond_to do |format| + format.js + end + end + def refresh_changests if !(@user.nil?) && !(@user.memberships.nil?) @user.memberships.each do |member| @@ -390,13 +525,13 @@ class UsersController < ApplicationController member.course_group_id = 0 member.save - CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>1) + CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>1) @msg.update_attributes(:status=>1,:viewed=>1) else members = [] members << Member.new(:role_ids => integer_ids, :user_id => @msg.course_message_id) Course.find(@msg.course_id).members << members - CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>1) + CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>1) @msg.update_attributes(:status=>1,:viewed=>1) if integer_ids.include?(9) @@ -411,7 +546,7 @@ class UsersController < ApplicationController end when 'N' - CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>2) + CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>2) @msg.update_attributes(:status=>2,:viewed=>1) if integer_ids.include?(9) @@ -461,13 +596,13 @@ class UsersController < ApplicationController when 'Y' unless ah.empty? ah.first.update_column('status', 2) - CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>6,:apply_result=>1) + CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>6,:apply_result=>1) @msg.update_attributes(:apply_result=>1,:viewed=>1) end when 'N' unless ah.empty? ah.first.update_column('status', 3) - CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>6,:apply_result=>2) + CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>6,:apply_result=>2) @msg.update_attributes(:apply_result=>2,:viewed=>1) end end @@ -1329,9 +1464,10 @@ class UsersController < ApplicationController @jour = jours.limit(10).offset(@page * 10) @type = params[:type] if User.current == @user - jours.update_all(:is_readed => true, :status => false) - jours.each do |journal| - fetch_user_leaveWord_reply(journal).update_all(:is_readed => true, :status => false) + @jour.update_all(:is_readed => true, :status => false) + @jour.each do |journal| + # fetch_user_leaveWord_reply(journal).update_all(:is_readed => true, :status => false) + journal.delay.set_children_readed_delay end end @state = false @@ -3357,7 +3493,11 @@ class UsersController < ApplicationController @my_syllabuses = @user.syllabuses - my_syllabus_ids = @my_syllabuses.empty? ? "(-1)" : "(" + @my_syllabuses.map{|syllabus| syllabus.id}.join(',') + ")" + if @user == User.current + archive_ids = Course.where("tea_id = #{@user.id} and is_delete = 1 and syllabus_id is NOT NULL").blank? ? "(-1)" : "(" + Course.where("tea_id = #{@user.id} and is_delete = 1 and syllabus_id is NOT NULL").map{|course| course.syllabus_id}.join(",") + ")" + @archive_syllabuses = Syllabus.where("id in #{archive_ids}") + end + 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}") @@ -3429,11 +3569,58 @@ class UsersController < ApplicationController end end + #归档班级列表 + def user_archive_courses + if User.current.logged? + @order, @c_sort, @type = params[:order] || 1, params[:sort] || 1, params[:type] || 1 + + #确定 sort_type + if @order.to_i == @type.to_i + @c_sort = @c_sort.to_i == 1 ? 2 : 1 #1升序 2降序 + else + @c_sort = 2 + end + + @user = User.current + sort_name = "updated_at" + archive_ids = Course.where("tea_id = #{@user.id} and is_delete = 1 and syllabus_id is NOT NULL").blank? ? "(-1)" : "(" + Course.where("tea_id = #{@user.id} and is_delete = 1 and syllabus_id is NOT NULL").map{|course| course.syllabus_id}.join(",") + ")" + @archive_syllabuses = Syllabus.where("id in #{archive_ids}") + + if @order.to_i == 1 #根据 班级更新时间排序 + @archive_syllabuses = syllabus_course_list_sort @archive_syllabuses + @c_sort == 1 ? (@archive_syllabuses = @archive_syllabuses.sort{|x,y| x[:last_update] <=> y[:last_update] }) : (@archive_syllabuses = @archive_syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]}) + @type = 1 + elsif @order.to_i == 2 #根据 作业+资源数排序 + @type = 2 + @archive_syllabuses.each do |syllabus| + count = 0 + courses = syllabus.courses.not_deleted + courses.each do |c| + count += (User.current.admin? || User.current.allowed_to?(:as_teacher,c)) ? (c.homework_commons.count + visable_attachemnts_incourse(c).count) : (c.homework_commons.where("publish_time <= '#{Date.today}'").count + visable_attachemnts_incourse(c).count) + end + syllabus[:infocount] = count + end + @c_sort == 1 ? (@archive_syllabuses = @archive_syllabuses.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@archive_syllabuses = @archive_syllabuses.sort{|x,y| y[:infocount] <=> x[:infocount]}) + @archive_syllabuses = sortby_time_countcommon_nosticky @archive_syllabuses,sort_name + else + @type = 1 + end + respond_to do |format| + format.js + format.html {render :layout => 'new_base_user'} + end + end + end + #展开课程下的班级 def expand_courses @syllabus = Syllabus.where("id = #{params[:syllabus_id]}").first unless @syllabus.nil? - @courses = @syllabus.courses.not_deleted.select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") + if params[:is_delete] && params[:is_delete] == '1' + @courses = @syllabus.courses.where("is_delete = 1").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") + else + @courses = @syllabus.courses.not_deleted.select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") + end respond_to do |format| format.js end @@ -3526,18 +3713,12 @@ class UsersController < ApplicationController if params[:type].present? case params[:type] when 'OrgDocumentComment' - #obj = OrgDocumentComment.where('id = ?', params[:id].to_i).first @user_activity_id = params[:div_id].to_i if params[:div_id] @type = 'OrgDocumentComment' - #comments = [] @journals = OrgDocumentComment.where("root_id = #{params[:id].to_i}").reorder("created_at desc") when 'Message','is_project_message' - #obj = Message.where('id = ?', params[:id].to_i).first @type = 'Message' - @is_course = params[:is_course] - @is_board = params[:is_board] @user_activity_id = params[:div_id].to_i if params[:div_id] - #comments = [] @journals = Message.where("root_id = #{params[:id].to_i}").reorder("created_on desc") when 'News' obj = News.where('id = ?', params[:id].to_i).first @@ -3550,8 +3731,6 @@ class UsersController < ApplicationController @type = 'Syllabus' @user_activity_id = params[:div_id].to_i if params[:div_id] when 'JournalsForMessage' - #obj = JournalsForMessage.where('id = ?', params[:id].to_i).first - #journals = [] @journals = JournalsForMessage.where("root_id = #{params[:id].to_i}").reorder("created_on desc") @type = 'JournalsForMessage' @user_activity_id = params[:div_id].to_i if params[:div_id] @@ -3568,20 +3747,17 @@ class UsersController < ApplicationController when 'BlogComment' obj = BlogComment.where('id = ?', params[:id].to_i).first @user_activity_id = params[:div_id].to_i if params[:div_id] - @homepage = params[:homepage].to_i @type = 'BlogComment' - @user_id = obj.author_id - #comments = [] @journals = BlogComment.where("root_id = #{params[:id].to_i}").reorder("created_on desc") when 'HomeworkCommon' obj = HomeworkCommon.where('id = ?', params[:id].to_i).first @type = 'HomeworkCommon' @journals = obj.journals_for_messages.reorder("created_on desc") - @hw_status = params[:hw_status].to_i if params[:hw_status] @is_teacher = User.current.allowed_to?(:as_teacher,obj.course) @user_activity_id = params[:user_activity_id].to_i if params[:user_activity_id] end end + @journals = get_no_children_comments_all @journals end def homepage diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb index ed9c4638f..7b4695d3c 100644 --- a/app/controllers/versions_controller.rb +++ b/app/controllers/versions_controller.rb @@ -125,7 +125,8 @@ class VersionsController < ApplicationController @issue_pages = Paginator.new @issue_count, @limit, params['page'] || 1 # @offset ||= @issue_pages.offset @issues = paginateHelper @version_issues, @limit - @version_issue_assigned_name = @version_issues.group_by(&:assigned_to_id) + @version_issue_assigned_name = @version_issues.sort_by{ |i| Issue.where(:project_id => @project.id , + :assigned_to_id => i.assigned_to_id, :fixed_version_id => @version.id).count }.reverse.group_by(&:assigned_to_id) format.html { # @issues = @version.fixed_issues.visible. # includes(:status, :tracker, :priority). diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb index da0c5733a..6f0d96dfa 100644 --- a/app/controllers/watchers_controller.rb +++ b/app/controllers/watchers_controller.rb @@ -37,7 +37,9 @@ class WatchersController < ApplicationController @list = query.order("#{Watcher.table_name}.id desc").limit(limit).offset(@obj_pages.offset).all(); @action = 'fans' else - + if params[:target_id] + @user = User.find(params[:target_id]) + end end if params[:object_type] == 'project' @@ -78,6 +80,9 @@ class WatchersController < ApplicationController @list = query.order("#{Watcher.table_name}.id desc").limit(limit).offset(@obj_pages.offset).all(); @action = 'fans' else + if params[:target_id] + @user = User.find(params[:target_id]) + end end if params[:object_type] == 'project' @project = Project.find(params[:object_id]) diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index a082d72ff..654f83855 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -137,7 +137,7 @@ class WechatsController < ActionController::Base on :fallback, respond: 'fallback message' on :click, with: 'FEEDBACK' do |request, key| - request.reply.text "如有问题反馈,请您:\n1、直接切换至输入框,发微信给我们。\n2、加入QQ群:373967360,直接互动。\n\n如您有合作事宜洽谈,请联系:\n王林春 老师\n手机:13467631747\nQQ:494496321" + request.reply.text "如有问题反馈,请您:\n1、直接切换至输入框,发微信给我们。\n2、加入QQ群:373967360,直接互动。\n3、登录网站:www.trustie.net,给我们留言。\n\n如您有合作事宜洽谈,请联系:\n王林春 老师\n手机:13467631747\nQQ:494496321" end on :click, with: 'MY_NEWS' do |request, key| diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index e4b480e2f..2ce505e15 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -116,7 +116,7 @@ class WordsController < ApplicationController else @user_activity_id = -1 end - @hw_status = params[:hw_status].to_i + @hw_status = params[:hw_status].to_i if @is_teacher = User.current.allowed_to?(:as_teacher, @homework.course) || User.current.admin? elsif @journal_destroyed.jour_type == 'Syllabus' @syllabus = Syllabus.find @journal_destroyed.jour_id @@ -315,7 +315,7 @@ class WordsController < ApplicationController respond_to do |format| format.js{ @user_activity_id = params[:user_activity_id].to_i - @hw_status = params[:hw_status].to_i + @hw_status = params[:hw_status].to_i if params[:hw_status] @is_teacher = User.current.allowed_to?(:as_teacher, @homework_common.course) || User.current.admin? } end @@ -349,7 +349,7 @@ class WordsController < ApplicationController respond_to do |format| format.js{ @user_activity_id = params[:user_activity_id].to_i - @hw_status = params[:hw_status].to_i + @hw_status = params[:hw_status].to_i if params[:hw_status] @is_teacher = User.current.allowed_to?(:as_teacher, @homework_common.course) || User.current.admin? } end @@ -454,45 +454,5 @@ class WordsController < ApplicationController end obj end - - def add_reply_adapter obj, options - #modify by nwb - #添加对课程留言的支持 - #留言回复应该不关系其所属的Class,而关心的是其所属的父留言 - case obj.jour_type - when 'Principal' - obj.jour.add_jour(nil, nil, nil, options) - when 'Project' - Project.add_new_jour(nil, nil, obj.jour_id, options) - when 'Course' - Course.add_new_jour(nil, nil, obj.jour_id, options) - when 'Bid' - obj.jour.add_jour(nil, nil, nil, options) - when 'Contest' - obj.jour.add_jour(nil, nil, obj.jour_id, options) - when 'Softapplication' - obj.jour.add_jour(nil, nil, obj.jour_id, options) - when 'HomeworkAttach' - obj.jour.add_jour(nil, nil, obj.jour_id, options) - end - # obj = obj_distinguish_url_origin || User.find_by_id(2) - # if obj.kind_of? User - # obj.add_jour(nil, nil, nil, options) - # elsif obj.kind_of? Project - # Project.add_new_jour(nil, nil, obj.id, options) - # elsif obj.kind_of? Course - # Course.add_new_jour(nil, nil, obj.id, options) - # elsif obj.kind_of? Bid - # obj.add_jour(nil, nil, nil, options) - # elsif obj.kind_of? Contest - # obj.add_jour(nil, nil, obj.id, options) #new added - # elsif obj.kind_of? Softapplication - # obj.add_jour(nil, nil, obj.id, options) #new added - # elsif obj.kind_of? HomeworkAttach - # obj.add_jour(nil, nil, obj.id, options) #new added - # else - # raise "create reply obj unknow type.#{obj.class}" - # end - end #######end of message end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index dff739343..8301407ae 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2837,6 +2837,12 @@ module ApplicationHelper tag_list end + # 获取项目fork成员数 + def project_fork_count + @forked_projects = Project.where(:forked_from_project_id => @project.id) + @forked_count = @forked_projects.count + end + def get_org_subfield_tag_list org_subfield all_attachments = org_subfield.attachments.select{|attachment| attachment.is_public? || (attachment.container_type == "OrgSubfield" && User.current.member_of_org?(org_subfield.organization))|| @@ -3394,6 +3400,63 @@ def secdomain_with_protocol secdomain return Setting.protocol + "://" + secdomain + ".trustie.net" end +#根据回复类型获取回复 +def get_reply_by_type type, reply_id + reply = nil + case type + when 'HomeworkCommon' + reply = JournalsForMessage.find reply_id + when 'JournalsForMessage' + reply = JournalsForMessage.find reply_id + when 'Message' + reply = Message.find reply_id + when 'BlogComment' + reply = BlogComment.find reply_id + when 'OrgDocumentComment' + reply = OrgDocumentComment.find reply_id + when 'News','Comment' + reply = Comment.find reply_id + when 'Issue' + reply = Journal.find reply_id + when 'Journal' + reply = Journal.find reply_id + when 'Syllabus' + reply = JournalsForMessage.find reply_id + end + reply +end + +#获取不包含子节点的回复(前三个) +def get_no_children_comments comments + result = {} + no_children_comments = [] + count = 0 + three_more = false + comments.each do |comment| + if comment.children.blank? + count = count + 1 + if count > 3 + three_more = true + end + break if count > 3 + no_children_comments << comment + end + end + result[:three_more] = three_more + result[:no_children_comments] = no_children_comments + result +end + +#获取不包含子节点的回复(所有) +def get_no_children_comments_all comments + no_children_comments = [] + comments.each do |comment| + if comment.children.blank? + no_children_comments << comment + end + end + no_children_comments +end #获取回复的所有父节点 def get_reply_parents parents_rely, comment @@ -3727,6 +3790,9 @@ end #作业类型 def homework_type_option type = [] + option0 = [] + option0 << "请选择作业类型" + option0 << 0 option1 = [] option1 << "普通作业" option1 << 1 @@ -3736,9 +3802,50 @@ def homework_type_option option3 = [] option3 << "分组作业" option3 << 3 + type << option0 type << option1 type << option2 type << option3 type end +def add_reply_adapter obj, options + #modify by nwb + #添加对课程留言的支持 + #留言回复应该不关系其所属的Class,而关心的是其所属的父留言 + case obj.jour_type + when 'Principal' + obj.jour.add_jour(nil, nil, nil, options) + when 'Project' + Project.add_new_jour(nil, nil, obj.jour_id, options) + when 'Course' + Course.add_new_jour(nil, nil, obj.jour_id, options) + #when 'Bid' + # obj.jour.add_jour(nil, nil, nil, options) + #when 'Contest' + # obj.jour.add_jour(nil, nil, obj.jour_id, options) + #when 'Softapplication' + # obj.jour.add_jour(nil, nil, obj.jour_id, options) + #when 'HomeworkAttach' + # obj.jour.add_jour(nil, nil, obj.jour_id, options) + end + # obj = obj_distinguish_url_origin || User.find_by_id(2) + # if obj.kind_of? User + # obj.add_jour(nil, nil, nil, options) + # elsif obj.kind_of? Project + # Project.add_new_jour(nil, nil, obj.id, options) + # elsif obj.kind_of? Course + # Course.add_new_jour(nil, nil, obj.id, options) + # elsif obj.kind_of? Bid + # obj.add_jour(nil, nil, nil, options) + # elsif obj.kind_of? Contest + # obj.add_jour(nil, nil, obj.id, options) #new added + # elsif obj.kind_of? Softapplication + # obj.add_jour(nil, nil, obj.id, options) #new added + # elsif obj.kind_of? HomeworkAttach + # obj.add_jour(nil, nil, obj.id, options) #new added + # else + # raise "create reply obj unknow type.#{obj.class}" + # end +end + diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 7ca3ff6b7..653afef62 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -264,7 +264,19 @@ module ProjectsHelper # Returns a set of options for a select field, grouped by project. def version_options_for_select(versions, selected=nil) + project_name = versions.blank? ? "" : versions.first.project.name grouped = Hash.new {|h,k| h[k] = []} + grouped[project_name] << ["请选择里程碑", 0] + +=begin + unless selected.nil? + if (params[:action] == "show" ) && Version.find(selected.id).status == "closed" + version_name = Version.find(selected.id).name + grouped[project_name] << [version_name, selected.id] + end + end +=end + versions.each do |version| grouped[version.project.name] << [version.name, version.id] end @@ -300,6 +312,16 @@ module ProjectsHelper type << option2 end + # 判断用户是否为项目管理员 + def is_project_manager?(user_id, project_id) + @result = false + mem = Member.where("user_id = ? and project_id = ?",user_id, project_id) + unless mem.blank? + @result = mem.first.roles.to_s.include?("Manager") ? true : false + end + return @result + end + # 用来判断用户是否是项目的管理员 # added by william def is_manager?(user_id,project_id) diff --git a/app/helpers/pull_requests_helper.rb b/app/helpers/pull_requests_helper.rb index c89a3be0f..fd90e01d1 100644 --- a/app/helpers/pull_requests_helper.rb +++ b/app/helpers/pull_requests_helper.rb @@ -2,12 +2,12 @@ module PullRequestsHelper # 获取diff内容行号 def diff_line_num content - content.scan(/@@ -(\d+),\d+ \+\d+,\d+ @@/).first.nil? ? "" : content.scan(/@@ -(\d+),\d+ \+\d+,\d+ @@/).first.join("").to_i + result = content.scan(/@@ -(\d+),\d+ \+\d+,\d+ @@/).first.nil? ? "" : content.scan(/@@ -(\d+),\d+ \+\d+,\d+ @@/).first.join("").to_i end # 处理内容 def diff_content content - content.gsub!(/.*@@ -\d+,\d+ \+\d+,\d+ @@\n/m,'') + result = content.gsub!(/.*@@.*@@\n/m,'') end def get_user_name user_id @@ -19,6 +19,11 @@ module PullRequestsHelper PullRequest.where(:pull_request_id => pull_request_id).first end + # 通过gitlab项目id获取Trustie项目的用户名 + def find_gitlab_project gitlab_project_id + Project.find_by_gpid(gitlab_project_id).owner.try(:show_name) + end + def get_state state case state when "open","reopened" diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 95cd844f3..4dd3399a3 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -29,6 +29,30 @@ module UsersHelper ["#{l(:status_locked)} (#{user_count_by_status[3].to_i})", '3']], selected.to_s) end + def issue_list(issues, &block) + ancestors = [] + issues.each do |issue| + while (ancestors.any? && !issue.is_descendant_of?(ancestors.last)) + ancestors.pop + end + yield issue, ancestors.size + ancestors << issue unless issue.leaf? + end + end + + # 我的issue 来源 + def options_for_issue_project_list( issues ) + issues = issues.group_by{|issue| issue.project_id} + issues.map{ |issue| [Project.find(issue[0]).name, issue[0]]}.unshift(["来源", 0]) + end + + # 我的issue指派给我 + def options_for_my_issue_list(issues) + # issues = issues.group_by{|issue| issue.assigned_to_id } + # issues.map{ |issue| [User.find(issue[0]).show_name, issue[0]]}.unshift(["指派给", 0]) + + end + def get_resource_type type case type when 'Course' @@ -76,7 +100,7 @@ module UsersHelper def applied_project_users applied_message # case applied_message.status # when 3,2,1,5,4,7,6 - user = User.find(applied_message.applied_user_id) + user = User.find(applied_message.applied_user_id).show_name # end end diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index acece2307..09d9115b4 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -333,6 +333,7 @@ module WatchersHelper return '' unless user && user.logged? objects = Array.wrap(objects) watched = objects.any? {|object| object.watched_by?(user)} + watched = true if user.id == @project.user_id @watch_flag = objects.first.instance_of?(Project) id = watcher_css(objects) text = @watch_flag ? @@ -340,8 +341,13 @@ module WatchersHelper url = watch_path(:object_type => objects.first.class.to_s.underscore, :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort)) method = watched ? 'delete' : 'post' - link_to text, url, :remote => true, :method => method, - :class => "pro_new_topbtn_left fl" ,:id=>id + if user.id != @project.user_id + link_to text, url, :remote => true, :method => method, + :class => "pro_new_topbtn_left fl" ,:id => id + else + link_to "关注", "javascript:void(0)", :remote => true, :method => method, + :class => "pro_new_grey_topbtn_left fl" , :id => id + end end def store_project_link project_id, user_id diff --git a/app/models/exercise_user.rb b/app/models/exercise_user.rb index 2d5da5d95..c675f35a3 100644 --- a/app/models/exercise_user.rb +++ b/app/models/exercise_user.rb @@ -1,4 +1,5 @@ class ExerciseUser < ActiveRecord::Base + #commit_status 0:未交 1:已交 include Redmine::SafeAttributes belongs_to :user diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index c87cd3d42..3690df1f3 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -15,7 +15,7 @@ class HomeworkCommon < ActiveRecord::Base has_one :homework_detail_group, :dependent => :destroy has_many :student_work_projects, :dependent => :destroy has_many :homework_tests, :dependent => :destroy - has_many :student_works, :dependent => :destroy, :conditions => "is_test=0" + has_many :student_works, :dependent => :destroy, :conditions => "is_test=0 and is_delete != 1" has_many :student_works_evaluation_distributions, :through => :student_works #一个作业的分配的匿评列表 has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :apply_homeworks, :dependent => :destroy diff --git a/app/models/issue.rb b/app/models/issue.rb index 1b47d80cc..46a42cb34 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -854,7 +854,8 @@ class Issue < ActiveRecord::Base return @assignable_versions if @assignable_versions # versions = project.shared_versions.open.all - versions = Version.where(:project_id => project.id, :status => "open").order("created_on desc") + # versions = Version.where(:project_id => project.id, :status => "open").order("created_on desc") + versions = Version.where(:project_id => project.id).order("created_on desc") if fixed_version if fixed_version_id_changed? # nothing to do diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 4a9601d07..aa83c2210 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -344,4 +344,9 @@ class JournalsForMessage < ActiveRecord::Base def content_detail self.notes end + + def set_children_readed_delay + # fetch_user_leaveWord_reply(self).update_all(:is_readed => true, :status => false) + end + end diff --git a/app/models/organization.rb b/app/models/organization.rb index 50f62ea11..284754c03 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -9,6 +9,7 @@ class Organization < ActiveRecord::Base has_many :org_subfields, :dependent => :destroy has_many :users, :through => :org_members has_many :files + has_many :org_messages, :class_name => 'OrgMessage', :dependent => :destroy acts_as_attachable validates_uniqueness_of :name after_create :save_as_org_activity, :add_default_subfields diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 9b3124797..794faa774 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -4,7 +4,7 @@ class StudentWork < ActiveRecord::Base belongs_to :homework_common belongs_to :user - has_many :student_work_projects + has_many :student_work_projects, :dependent => :destroy has_many :student_works_evaluation_distributions, :dependent => :destroy has_many :student_works_scores, :dependent => :destroy belongs_to :project diff --git a/app/models/students_for_course.rb b/app/models/students_for_course.rb index 767d65b10..d9bf96770 100644 --- a/app/models/students_for_course.rb +++ b/app/models/students_for_course.rb @@ -9,11 +9,21 @@ class StudentsForCourse < ActiveRecord::Base validates_uniqueness_of :student_id, :scope => :course_id after_destroy :delete_student_works + after_create :recovery_student_works + #退出班级或删除学生时隐藏学生的作品 def delete_student_works course = self.course homework_ids = course.homework_commons.blank? ? "(-1)" : "(" + course.homework_commons.map{|hw| hw.id}.join(",") + ")" student_works = StudentWork.where("user_id = #{self.student_id} && homework_common_id in #{homework_ids}") - student_works.destroy_all + student_works.update_all(:is_delete => 1) + end + + #加入班级时还原作品 + def recovery_student_works + course = self.course + homework_ids = course.homework_commons.blank? ? "(-1)" : "(" + course.homework_commons.map{|hw| hw.id}.join(",") + ")" + student_works = StudentWork.where("user_id = #{self.student_id} && homework_common_id in #{homework_ids}") + student_works.update_all(:is_delete => 0) end end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index f72623d84..43bdf9e09 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -452,12 +452,20 @@ class CoursesService @state = 2 return @state end - @member = Member.where('course_id = ? and user_id = ?', params[:object_id], user.id) - if @member.nil? || @member.count == 0 + @member = Member.where('course_id = ? and user_id = ?', params[:object_id], user.id).first + if @member.nil? @state = 1 return @state end - @member.first.destroy + student_role = @member.member_roles.where("role_id = 10").first + teacher_role = @member.member_roles.where("role_id = 7 || role_id = 9").first + if @member.member_roles.count > 1 && student_role && teacher_role + student_role.destroy + teacher_role.update_attribute("is_current", 1) + @member.update_attribute("course_group_id", 0) + else + @member.destroy + end joined = StudentsForCourse.where('student_id = ? and course_id = ?', user.id, params[:object_id]) joined.each do |join| join.destroy diff --git a/app/views/attachments/_project_file_links.html.erb b/app/views/attachments/_project_file_links.html.erb index cccc8382c..a1a978a48 100644 --- a/app/views/attachments/_project_file_links.html.erb +++ b/app/views/attachments/_project_file_links.html.erb @@ -30,9 +30,9 @@ <% for attachment in attachments %>
博客列表
diff --git a/app/views/blogs/_homepage.html.erb b/app/views/blogs/_homepage.html.erb index 6b40a23da..2b921c7a4 100644 --- a/app/views/blogs/_homepage.html.erb +++ b/app/views/blogs/_homepage.html.erb @@ -45,16 +45,15 @@