diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index b95e363cb..5e0ef4638 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -564,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 @@ -572,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 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/projects_controller.rb b/app/controllers/projects_controller.rb index 979f2d369..2bdaddb25 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -769,6 +769,14 @@ class ProjectsController < ApplicationController end end + # 配置成员弹框 + def delete_member_pop + @member = Member.find(params[:member].to_i) + respond_to do |format| + format.js + end + end + def close @project.close redirect_to project_url(@project) diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index bfc2ab9f7..ad60f2b70 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -1,9 +1,10 @@ - +# 如果你对改模块任何功能不清楚,请不要随便改 +# @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] + :update_pull_request, :pull_request_comments, :create_pull_request_comment, :compare_pull_request] layout "base_projects" include PullRequestsHelper @@ -46,10 +47,11 @@ class PullRequestsController < ApplicationController end # 主要取源项目和目标项目分支及标识(用户名/版本库名) + # @tip 为空的时候表明发送的pr请求有改动,为1的时候源分支和目标分支没有改动,则不能成功创建 def new # project_menu_type 为了控制base顶部导航 @project_menu_type = 6 - + @tip = params[:show_tip] identifier = get_rep_identifier_by_project @project @source_project_name = "#{get_user_name(@project.user_id)}/#{identifier}" @source_rev = @g.branches(@project.gpid).map{|b| b.name} @@ -84,17 +86,26 @@ class PullRequestsController < ApplicationController description = params[:description] source_branch = params[:source_branch] target_branch = params[:target_branch] + target_project_id = params[:target_project_id] begin - # 如果传送了目标项目ID,则PR请求发至目标项目 - if params[:forked_project_id] && params[:source_project] == "forked_project_name" - 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_pr_message = true if @fork_project_name + # 如果分支有改动 + if compare_pull_request(source_branch, target_project_id, target_branch) + # 如果传送了目标项目ID即向fork源项目发送请求 + if params[:forked_project_id] && params[:source_project] == "forked_project_name" + 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_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) + respond_to do |format| + format.js{redirect_to project_pull_request_path(request.id, :project_id => @project.id)} + end + end else - request = @g.create_merge_request(@project.gpid, title, User.current.gid, :description => description, :source_branch => source_branch, :target_branch => target_branch) + tip = 1 respond_to do |format| - format.js{redirect_to project_pull_request_path(request.id, :project_id => @project.id)} + format.js{redirect_to new_project_pull_request_path(:show_tip => tip)} end end rescue Exception => e @@ -102,8 +113,31 @@ class PullRequestsController < ApplicationController end end + # Compare branch for MR + # 判断源分支和目标分支是否有改动 + # status 为true 表示有改动; false:便是没有改动 + def compare_pull_request source_branch, target_project, target_branch + user_name_source = @project.owner.try(:login) + identifier = @repository.identifier.downcase + git_source_tree = '--git-dir=/home/git/repositories/' + user_name_source + '/' + identifier + '.git' + if target_project + forked_source_project = Project.find(target_project) + user_name_target = forked_source_project.owner.try(:login) + git_target_tree = '--git-dir=/home/git/repositories/' + user_name_target + '/' + identifier + '.git' + git_sourse_commit_id = @g.get_branch_commit_id(@project.gpid, git_source_tree, source_branch) + git_target_commit_id = @g.get_branch_commit_id(forked_source_project.gpid, git_target_tree, target_branch) + else + git_sourse_commit_id = @g.get_branch_commit_id(@project.gpid, git_source_tree, source_branch) + git_target_commit_id = @g.get_branch_commit_id(@project.gpid, git_source_tree, target_branch) + end + status = (git_sourse_commit_id.try(:commit_id) == git_target_commit_id.try(:commit_id) ? false : true) + end + + # @project_menu_type 为了控制base顶部导航 + # merge_when_succeeds def show - # project_menu_type 为了控制base顶部导航 + # compare_pull_request source_project, source_branch, target_project, target_branch + # compare_pull_request @project_menu_type = 6 @type = params[:type] @request = @g.merge_request(@project.gpid, params[:id]) @@ -266,7 +300,7 @@ class PullRequestsController < ApplicationController def find_project_and_repository @project = Project.find(params[:project_id]) render_404 if @project.gpid.blank? - @repository = Repository.where(:project_id => @project.id, :type => "Repository::Gitlab") + @repository = Repository.where(:project_id => @project.id, :type => "Repository::Gitlab").first rescue ActiveRecord::RecordNotFound render_404 end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 0e8ca71c0..29176550a 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -102,7 +102,8 @@ class RepositoriesController < ApplicationController g = Gitlab.client if User.current.gid.nil? begin - g.sync_user(User.current) + s = Trustie::Gitlab::Sync.new + s.sync_user(User.current) ensure logger.error "Synv user failed ==>#{User.current.id}" 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/users_controller.rb b/app/controllers/users_controller.rb index 3265d273b..56b536d30 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -42,7 +42,7 @@ class UsersController < ApplicationController :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] + :sort_project_list,:my_homeworks,:manage_or_receive_homeworks,:search_m_r_homeworks, :cancel_or_collect,:expand_courses,:homepage, :user_issues] before_filter :auth_user_extension, only: :show #before_filter :rest_user_score, only: :show #before_filter :select_entry, only: :user_projects @@ -86,6 +86,60 @@ class UsersController < ApplicationController helper :issues include UsersHelper + # 获取我的任务 + # order 排序条件 + # subject 主题:搜索用(注意:搜索和列表调用同一方法,通过参数或者remote区分) + def user_issues + @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 => 'static_base'} + format.api + format.js + end + end + #展开所有回复 def show_all_replies case params[:type] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 992cfcaf0..c52182b01 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -931,7 +931,10 @@ module ApplicationHelper def allow_pull_request project return 0 if project.gpid.nil? g = Gitlab.client - count = g.user_static(project.gpid, :rev => "master").count + # 之所以这样比较是为了解决gitlab本身的bug + commit_count = g.project(project.gpid).try(:commit_count).to_i + git_commit_cout = g.user_static(project.gpid, :rev => "master").count + count = commit_count > git_commit_cout ? commit_count : git_commit_cout count end @@ -3725,7 +3728,7 @@ end def homework_type_option type = [] option0 = [] - option0 << "请选择" + option0 << "请选择作业类型" option0 << 0 option1 = [] option1 << "普通作业" diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 7012b3dfa..bda7831fe 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -20,6 +20,8 @@ module IssuesHelper include ApplicationHelper include TagsHelper + require 'iconv' + def issue_list(issues, &block) ancestors = [] issues.each do |issue| @@ -119,10 +121,11 @@ module IssuesHelper end def principals_options_for_isuue_list(project) + conv = Iconv.new("GBK", "utf-8") if User.current.member_of?(project) - project.members.includes(:user).order("lower(users.login)").map{|c| [User.find(c.user_id).show_name, c.user_id]}.unshift(["<< #{l(:label_me)} >>", User.current.id]).unshift(["指派给", 0]) + project.members.includes(:user).sort{|x, y| conv.iconv(x.user.lastname) <=> conv.iconv(y.user.lastname)}.map{|c| [User.find(c.user_id).show_name, c.user_id]}.unshift(["<< #{l(:label_me)} >>", User.current.id]).unshift(["指派给", 0]) else - project.members.includes(:user).order("lower(users.login)").map{|c| [User.find(c.user_id).show_name, c.user_id]}.unshift(["指派给", 0]) + project.members.includes(:user).sort{|x, y| conv.iconv(x.user.lastname) <=> conv.iconv(y.user.lastname)}.map{|c| [User.find(c.user_id).show_name, c.user_id]}.unshift(["指派给", 0]) end end @@ -130,7 +133,6 @@ module IssuesHelper versions = Version.where(:project_id => project, :status => "open").map{|version| [version.name, version.id]}.unshift(["里程碑", 0]) end - def render_issue_subject_with_tree(issue) s = '' ancestors = issue.root? ? [] : issue.ancestors.visible.all diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 7ca3ff6b7..3dff9c414 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -264,7 +264,9 @@ 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] versions.each do |version| grouped[version.project.name] << [version.name, version.id] end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 95cd844f3..228e83080 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' diff --git a/app/models/dts.rb b/app/models/dts.rb index 3a9dcbcfb..cf5037eb2 100644 --- a/app/models/dts.rb +++ b/app/models/dts.rb @@ -1,5 +1,5 @@ class Dts < ActiveRecord::Base attr_accessible :Category, :Defect, :Description, :File, :IPLine, :IPLineCode, :Method, :Num, :PreConditions, :Review, :StartLine, :TraceInfo, :Variable, :project_id - belongs_to :project + # belongs_to :project end 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 9c3c8d168..1b47d80cc 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -853,7 +853,8 @@ class Issue < ActiveRecord::Base def assignable_versions return @assignable_versions if @assignable_versions - versions = project.shared_versions.open.all + # versions = project.shared_versions.open.all + versions = Version.where(:project_id => project.id, :status => "open").order("created_on desc") if fixed_version if fixed_version_id_changed? # nothing to do @@ -865,7 +866,7 @@ class Issue < ActiveRecord::Base versions << fixed_version end end - @assignable_versions = versions.uniq.sort + @assignable_versions = versions.uniq end # Returns true if this issue is blocked by another issue that is still open diff --git a/app/models/project.rb b/app/models/project.rb index 0ac10fb2b..8300daf82 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -82,7 +82,7 @@ class Project < ActiveRecord::Base has_one :course_extra, :class_name => 'Course', :foreign_key => :extra,:primary_key => :identifier, :dependent => :destroy has_many :applied_projects, :dependent => :destroy has_many :invite_lists, :dependent => :destroy - has_one :dts + # has_one :dts has_many :organizations,:through => :org_projects # end 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/models/user.rb b/app/models/user.rb index 99b39543e..d6e4eb715 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -323,6 +323,7 @@ class User < Principal # id 转换成 登录名 # 如果是整数就去ID,否则就取login + # 含有特殊符号的则显示ID def to_param (self.login.to_i.to_s == self.login || self.login.include?(".") || self.login.include?("%") || self.login.include?("?")) ? id : login 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/common/403.html b/app/views/common/403.html index 78dc6dae7..dcfeb9f41 100644 --- a/app/views/common/403.html +++ b/app/views/common/403.html @@ -17,7 +17,8 @@ $(function(){ if(window.history.length == 1) { - $("#history_back").css("background","#CCC"); + $("#history_back").css("color","#CCC"); + $("#history_back").css("cursor","default"); } $("#subject").keydown(function(){ var curLength=$("#subject").val().length; @@ -50,7 +51,7 @@ 您没有访问权限,请先获取相应权限。 返回上页>> 给我留言>> - QQ反馈>> + QQ反馈>>