show notifications for active account memberships

fixes CNVS-39695

test plan
 - have two accounts and enrollment in each
 - a notification from account two should show on
   account one dashboard

Change-Id: I22e59fa7a1a04e00ff97d4a15333565ef70d4fed
Reviewed-on: https://gerrit.instructure.com/128037
Tested-by: Jenkins
Reviewed-by: Cody Cutrer <cody@instructure.com>
Product-Review: Rob Orton <rob@instructure.com>
QA-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
Rob Orton 2017-10-02 00:21:22 -06:00
parent 373bf484d7
commit d1227ce121
2 changed files with 20 additions and 4 deletions

View File

@ -39,7 +39,12 @@ class AccountNotification < ActiveRecord::Base
if account.site_admin?
current = self.for_account(account)
else
sub_account_ids = UserAccountAssociation.where(user: user).joins(:account).where('COALESCE(accounts.root_account_id,accounts.id)=?', account).pluck(:account_id)
sub_account_ids = user.enrollments.active.shard(user).
joins(:course).where(courses: {workflow_state: 'available'}).
distinct.pluck(:account_id, :root_account_id).flatten.uniq
sub_account_ids += user.account_users.active.shard(user).
joins(:account).where(accounts: {workflow_state: 'active'}).
distinct.pluck(:account_id).uniq
current = self.for_account(account, sub_account_ids)
end

View File

@ -154,20 +154,31 @@ describe AccountNotification do
end
end
it "scopes sub-accounts to the root account" do
it "scopes to active enrollment accounts" do
sub_announcement = sub_account_notification(subject: 'blah', account: @sub_account)
course_with_student(user: @user, account: @sub_account, active_all: true)
other_root_account = Account.create!
other_announcement = account_notification(account: other_root_account)
course_with_student(user: @user, account: other_root_account, active_all: true)
nother_root_account = Account.create!(name: 'nother account')
nother_announcement = account_notification(account: nother_root_account)
# not an active course and will be excluded
course_with_student(user: @user, account: nother_root_account)
notes = AccountNotification.for_user_and_account(@user, Account.default)
expect(notes).to include sub_announcement
expect(notes).not_to include other_announcement
expect(notes).to include other_announcement
expect(notes).not_to include nother_announcement
other_notes = AccountNotification.for_user_and_account(@user, other_root_account)
expect(other_notes).not_to include sub_announcement
expect(other_notes).to include sub_announcement
expect(other_notes).to include other_announcement
expect(other_notes).not_to include nother_announcement
nother_notes = AccountNotification.for_user_and_account(@user, nother_root_account)
expect(nother_notes).to include sub_announcement
expect(nother_notes).to include other_announcement
expect(nother_notes).to include nother_announcement
end
end