Skip to content

Commit 320cbd8

Browse files
committed
fix account reports query cross-shard
fixes CNVS-33224 test plan: * create an account on a separate shard, but without its own domain * you should still be able to view its settings page following the link from site admin Change-Id: If181662c83cc78e52d17ac372afb2add596dd153 Reviewed-on: https://gerrit.instructure.com/100718 Reviewed-by: Simon Williams <simon@instructure.com> Tested-by: Jenkins QA-Review: Jeremy Putnam <jeremyp@instructure.com> Product-Review: Cody Cutrer <cody@instructure.com>
1 parent cd46dcf commit 320cbd8

2 files changed

Lines changed: 26 additions & 11 deletions

File tree

app/controllers/accounts_controller.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -659,16 +659,18 @@ def settings
659659
if authorized_action(@account, @current_user, :read)
660660
@available_reports = AccountReport.available_reports if @account.grants_right?(@current_user, @session, :read_reports)
661661
if @available_reports
662-
scope = @account.account_reports.where("report_type=name").most_recent
663-
@last_complete_reports = AccountReport.from("unnest('{#{@available_reports.keys.join(',')}}'::text[]) report_types (name),
664-
LATERAL (#{scope.complete.to_sql}) account_reports ").
665-
order("report_types.name").
666-
preload(:attachment).
667-
index_by(&:report_type)
668-
@last_reports = AccountReport.from("unnest('{#{@available_reports.keys.join(',')}}'::text[]) report_types (name),
669-
LATERAL (#{scope.to_sql}) account_reports ").
670-
order("report_types.name").
671-
index_by(&:report_type)
662+
@account.shard.activate do
663+
scope = @account.account_reports.where("report_type=name").most_recent
664+
@last_complete_reports = AccountReport.from("unnest('{#{@available_reports.keys.join(',')}}'::text[]) report_types (name),
665+
LATERAL (#{scope.complete.to_sql}) account_reports ").
666+
order("report_types.name").
667+
preload(:attachment).
668+
index_by(&:report_type)
669+
@last_reports = AccountReport.from("unnest('{#{@available_reports.keys.join(',')}}'::text[]) report_types (name),
670+
LATERAL (#{scope.to_sql}) account_reports ").
671+
order("report_types.name").
672+
index_by(&:report_type)
673+
end
672674
end
673675
load_course_right_side
674676
@account_users = @account.account_users

spec/controllers/accounts_controller_spec.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# with this program. If not, see <http://www.gnu.org/licenses/>.
1717
#
1818

19-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
19+
require File.expand_path(File.dirname(__FILE__) + '/../sharding_spec_helper')
2020

2121
describe AccountsController do
2222
def account_with_admin_logged_in(opts = {})
@@ -540,6 +540,19 @@ def cross_listed_course
540540
expect(assigns[:last_reports].first.last).to eq report
541541
end
542542

543+
context "sharding" do
544+
specs_require_sharding
545+
546+
it "loads even from the wrong shard" do
547+
account_with_admin_logged_in
548+
549+
@shard1.activate do
550+
get 'settings', account_id: @account
551+
expect(response).to be_success
552+
end
553+
end
554+
end
555+
543556
context "external_integration_keys" do
544557
before(:once) do
545558
ExternalIntegrationKey.key_type :external_key0, rights: { write: true }

0 commit comments

Comments
 (0)