Skip to content

Commit 38d132b

Browse files
author
Tyson Brown
committed
Adds Global Announcements to sub accounts
refs PFS-3588 TEST PLAN * verify Global Announcements can be made from sub account settings page * admins and users should see on notification what account its from (bottom of each notification) * verify that users receive the correct announcements based on account and role - sub account notifications should only go to users with an enrollment or admin role somewhere within the sub account hierarchy - if the sub account notification has specified roles, only users with those roles within the sub account hierarchy should see them * verify Global Announcement permission can be made for sub accounts * on sub accounts the Add/Edit forms should not display 'Unenrolled users' checkbox Change-Id: I087acba0504a04595244062b8dfc41f340fc2f1a Reviewed-on: https://gerrit.instructure.com/72343 Reviewed-by: Cody Cutrer <cody@instructure.com> Tested-by: Jenkins QA-Review: Jahnavi Yetukuri <jyetukuri@instructure.com> Product-Review: Allison Weiss <allison@instructure.com>
1 parent d770ab6 commit 38d132b

10 files changed

Lines changed: 330 additions & 219 deletions

app/controllers/account_notifications_controller.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ def create
223223
# "end_at": "2014-02-01T00:00:00Z",
224224
# "message": "This is a global notification"
225225
# }
226-
227226
def update
228227
account_notification = @account.announcements.find(params[:id])
229228
if account_notification
@@ -269,12 +268,7 @@ def destroy
269268

270269
protected
271270
def require_account_admin
272-
get_context
273-
if !@account || @account.parent_account_id
274-
flash[:notice] = t(:permission_denied_notice, "You cannot create announcements for that account")
275-
redirect_to account_settings_path(params[:account_id])
276-
return false
277-
end
271+
require_account_context
278272
return false unless authorized_action(@account, @current_user, :manage_alerts)
279273
end
280274

app/helpers/account_notification_helper.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,12 @@ def accessible_message_icon_text(icon_type)
7878
I18n.t('#global_message_icons.warning', "warning")
7979
end
8080
end
81+
82+
def roles_message(account)
83+
if account.root_account?
84+
t "(If none are selected, send to everyone in the entire account)"
85+
else
86+
t "(If none are selected, send to everyone in the entire sub-account)"
87+
end
88+
end
8189
end

app/models/account_notification.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ def validate_dates
2323
end
2424

2525
def self.for_user_and_account(user, account)
26-
current = self.for_account(account)
26+
if account.site_admin?
27+
current = self.for_account(account)
28+
else
29+
sub_account_ids = UserAccountAssociation.where(user: user).pluck(:account_id)
30+
current = self.for_account(account, sub_account_ids)
31+
end
2732

2833
user_role_ids = {}
2934

@@ -89,16 +94,21 @@ def self.for_user_and_account(user, account)
8994
current
9095
end
9196

92-
def self.for_account(account)
97+
def self.for_account(account, sub_account_ids=nil)
9398
# Refreshes every 10 minutes at the longest
9499
Rails.cache.fetch(['account_notifications3', account].cache_key, expires_in: 10.minutes) do
95100
now = Time.now.utc
96101
# we always check the given account for the flag, even if the announcement is from the site_admin account
97102
# this allows us to make a global announcement that is filtered to only accounts with this flag
98103
enabled_flags = ACCOUNT_SERVICE_NOTIFICATION_FLAGS & account.allowed_services_hash.keys.map(&:to_s)
104+
account_ids = account.account_chain(include_site_admin: true).map(&:id)
105+
if sub_account_ids
106+
account_ids += sub_account_ids
107+
account_ids.uniq!
108+
end
99109

100-
Shard.partition_by_shard(account.account_chain(include_site_admin: true).reverse) do |accounts|
101-
AccountNotification.where("account_id IN (?) AND start_at <? AND end_at>?", accounts, now, now).
110+
Shard.partition_by_shard(account_ids) do |a|
111+
AccountNotification.where("account_id IN (?) AND start_at <? AND end_at>?", a, now, now).
102112
where("required_account_service IS NULL OR required_account_service IN (?)", enabled_flags).
103113
order('start_at DESC').
104114
preload(:account, account_notification_roles: :role)

app/models/role_override.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ def self.enrollment_type_labels
604604
},
605605
:manage_alerts => {
606606
:label => lambda { t('permissions.manage_announcements', "Manage global announcements") },
607-
:account_only => :root,
607+
:account_only => true,
608608
:true_for => %w(AccountAdmin),
609609
:available_to => %w(AccountAdmin AccountMembership),
610610
},

app/stylesheets/components/_alerts.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,15 @@ $ic-notification-border-thickness: 2px;
330330
margin-left: $ic-sp;
331331
margin-bottom: $ic-sp/2;
332332
}
333+
334+
.notification_account_content {
335+
width: 100%;
336+
background-color: $ic-color-neutral;
337+
}
338+
339+
.notification_account_content_text {
340+
font-size: 0.8em;
341+
font-weight: 300;
342+
padding-left: 12px;
343+
line-height: 22px;
344+
}

app/views/accounts/_edit_account_notification.html.erb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<div class="ic-Form-control">
4949
<div class="ic-Label" id="aria-announcements-send-to-group">
5050
<%= t "Send to" %>
51-
<span><%= t "(will send to everyone if no selections are made)" %></span>
51+
<%= roles_message(@account) %>
5252
</div>
5353
<div class="grid-row">
5454
<div class="col-xs-12 col-lg-4">
@@ -67,16 +67,18 @@
6767
</label>
6868
</div>
6969
<% end %>
70-
<% nil_role_checked = role_ids.include? nil %>
71-
<div class="ic-Form-control ic-Form-control--checkbox">
72-
<%= check_box_tag "account_notification_roles[]", "NilEnrollment", nil_role_checked, { :class => "account_notification_role_cbx", :id => "account_notification_role_NilEnrollment_cbx_#{announcement.id}" } %>
73-
<label class="ic-Label" for="<%= "account_notification_role_NilEnrollment_cbx_#{announcement.id}" %>">
74-
<%= t "Unenrolled users" %>
75-
<span class="screenreader-only">
76-
<%=t "Send this announcement to unenrolled users" %>
77-
</span>
78-
</label>
79-
</div>
70+
<% if @account.root_account? %>
71+
<% nil_role_checked = role_ids.include? nil %>
72+
<div class="ic-Form-control ic-Form-control--checkbox">
73+
<%= check_box_tag "account_notification_roles[]", "NilEnrollment", nil_role_checked, { :class => "account_notification_role_cbx", :id => "account_notification_role_NilEnrollment_cbx_#{announcement.id}" } %>
74+
<label class="ic-Label" for="<%= "account_notification_role_NilEnrollment_cbx_#{announcement.id}" %>">
75+
<%= t "Unenrolled users" %>
76+
<span class="screenreader-only">
77+
<%=t "Send this announcement to unenrolled users" %>
78+
</span>
79+
</label>
80+
</div>
81+
<% end %>
8082
</div>
8183
</div>
8284
<div class="col-xs-12 col-lg-4">

0 commit comments

Comments
 (0)