From e3d21286f363134b41aa6f0b9345d1b61a7704b4 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 16:37:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=88=97=E8=A1=A8=E7=9A=84?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/exercise.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 606132c27..290032f24 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -60,7 +60,8 @@ class Exercise < ApplicationRecord ex_users = exercise_users group_ids = common_published_ids(user_id) if group_ids.present? - ex_users = ex_users.where(user_id: course.students.where(course_group_id: group_ids).select(:user_id).pluck(:user_id)) + ex_users = ex_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). + where(course_members: {course_group_id: group_ids}) end ex_users end @@ -69,8 +70,9 @@ class Exercise < ApplicationRecord def common_published_ids(user_id) current_user_groups = course.teacher_course_ids(user_id) if unified_setting - un_group_ids = (course.none_group_count > 0) ? [0] : [] - published_group_ids = (current_user_groups + un_group_ids).uniq #统一设置时,为当前用户的分班id及未分班 + # un_group_ids = (course.none_group_count > 0) ? [0] : [] + # published_group_ids = (current_user_groups + un_group_ids).uniq #统一设置时,为当前用户的分班id及未分班 + published_group_ids = current_user_groups else ex_group_setting = exercise_group_settings.select(:course_group_id).pluck("course_group_id").uniq common_all_ids = ex_group_setting & current_user_groups #当前用户有权限的已发布的分班id #非统一设置时,为当前用户有权限的且已发布分班的id