Skip to content

Commit ea232fd

Browse files
committed
add ui notification of bouncing channels
test plan: * add various communication methods to your user * navigate to any page other than your user's settings * using the console, increase the bounce count of all channels: User.find(id).communication_channels.unretired.each do |cc| cc.bounce_count = 100 cc.save end * refresh the page - a notification should show at the top of the page, indicating a potential problem on your settings page - navigating anywhere other than the settings page will cause the notification to persist * navigate to the settings page - the notification should disappear - your communication channels should all indicate a problem with delivering messages to you * removing and re-adding the channels should remove all indicators * navigate to any page other than your user's settings * using the console, increase the bounce count of one channel: cc = User.find(id).communication_channels.unretired.first cc.bounce_count = 100 cc.save * refresh the page - once again, the notification should show at the top of the page fixes CNVS-15255 Change-Id: If45664c1b33d75fbfe8aa3480dfebd8872c6b064 Reviewed-on: https://gerrit.instructure.com/40534 Reviewed-by: Joel Hough <joel@instructure.com> QA-Review: Trevor deHaan <tdehaan@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> Product-Review: Janelle Seegmiller <jseegmiller@instructure.com>
1 parent 0d4ea24 commit ea232fd

5 files changed

Lines changed: 72 additions & 0 deletions

File tree

app/controllers/profile_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ def settings
194194
return unless @user == @current_user || authorized_action(@user, @current_user, :view_statistics)
195195
else
196196
@user = @current_user
197+
@user.dismiss_bouncing_channel_message!
197198
end
198199
@user_data = profile_data(@user.profile, @current_user, session, [])
199200
@channels = @user.communication_channels.unretired

app/models/communication_channel.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class CommunicationChannel < ActiveRecord::Base
4444
validate :uniqueness_of_path
4545
validate :not_otp_communication_channel, :if => lambda { |cc| cc.path_type == TYPE_SMS && cc.retired? && !cc.new_record? }
4646
validates_presence_of :access_token_id, if: lambda { |cc| cc.path_type == TYPE_PUSH }
47+
after_commit :check_if_bouncing_changed
4748

4849
acts_as_list :scope => :user
4950

@@ -386,6 +387,29 @@ def bouncing?
386387
self.bounce_count >= RETIRE_THRESHOLD
387388
end
388389

390+
def was_bouncing?
391+
old_bounce_count = self.previous_changes[:bounce_count].try(:first)
392+
old_bounce_count ||= self.bounce_count
393+
old_bounce_count >= RETIRE_THRESHOLD
394+
end
395+
396+
def was_retired?
397+
old_workflow_state = self.previous_changes[:workflow_state].try(:first)
398+
old_workflow_state ||= self.workflow_state
399+
old_workflow_state.to_s == 'retired'
400+
end
401+
402+
def check_if_bouncing_changed
403+
if retired?
404+
self.user.update_bouncing_channel_message!(self) if !was_retired? && was_bouncing?
405+
else
406+
if (was_retired? && bouncing?) || (was_bouncing? != bouncing?)
407+
self.user.update_bouncing_channel_message!(self)
408+
end
409+
end
410+
end
411+
private :check_if_bouncing_changed
412+
389413
def self.bounce_for_path(path)
390414
Shard.with_each_shard(CommunicationChannel.associated_shards(path)) do
391415
CommunicationChannel.unretired.email.by_path(path).each do |channel|

app/models/user.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,4 +2534,35 @@ def stamp_logout_time!
25342534
def content_exports_visible_to(user)
25352535
self.content_exports.where(user_id: user)
25362536
end
2537+
2538+
def show_bouncing_channel_message!
2539+
self.preferences[:show_bouncing_channel_message] = true
2540+
self.save!
2541+
end
2542+
2543+
def show_bouncing_channel_message?
2544+
!!self.preferences[:show_bouncing_channel_message]
2545+
end
2546+
2547+
def dismiss_bouncing_channel_message!
2548+
self.preferences[:show_bouncing_channel_message] = false
2549+
self.save!
2550+
end
2551+
2552+
def bouncing_channel_message_dismissed?
2553+
self.preferences[:show_bouncing_channel_message] == false
2554+
end
2555+
2556+
def update_bouncing_channel_message!(channel=nil)
2557+
force_set_bouncing = channel && channel.bouncing? && !channel.imported?
2558+
set_bouncing = force_set_bouncing || self.communication_channels.unretired.any? { |cc| cc.bouncing? && !cc.imported? }
2559+
2560+
if force_set_bouncing
2561+
show_bouncing_channel_message!
2562+
elsif set_bouncing
2563+
show_bouncing_channel_message! unless bouncing_channel_message_dismissed?
2564+
else
2565+
dismiss_bouncing_channel_message!
2566+
end
2567+
end
25372568
end

app/views/layouts/application.html.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
<noscript><div role="alert" class="ic-flash-static ic-flash-error"><h1><%= t :javascript_required, "You need to have JavaScript enabled in order to access this site." %></h1></div></noscript>
3838
<%= render :partial => 'shared/flash_notices' %>
3939

40+
<% if @current_user.try(:show_bouncing_channel_message?) %>
41+
<div role="alert" class="ic-flash-static ic-flash-warning">
42+
<%= t(:bouncing_communication_channels, "There appears to be a problem with one of your contact methods. Please check your *Settings Page*.", wrapper: link_to('\1', settings_profile_path)) %>
43+
</div>
44+
<% end %>
45+
4046
<div id="header" class="no-print <%= 'no-user' unless @current_user %>">
4147
<div id="header-inner">
4248
<a href="#content" id="skip_navigation_link"><%= t 'links.skip_to_content', "Skip To Content" %></a>

app/views/profile/_ways_to_contact.html.erb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
6262
<a href="#" class="path email_channel" title="<%=h c.path %>"><%= c.path %></a>
6363
</td>
6464
<td class="email_actions hidden_for_single">
65+
<% if c.bouncing? %>
66+
<span class="bouncing-channel" data-tooltip="left" title="<%= t('bouncing_email', 'Canvas was unable to send email to this address. Please ensure the address is correct to continue receiving email from Canvas.') %>" aria-label="<%= t('bouncing_email', 'Canvas was unable to send email to this address. Please ensure the address is correct to continue receiving email from Canvas.') %>">
67+
<i class="text text-warning icon-warning"></i>
68+
</span>
69+
<% end %>
6570
<% if c.state == :unconfirmed && (@user.grants_right?(@current_user, :manage_user_details) || (@real_current_user && @user.grants_right?(@real_current_user, :manage_user_details))) %>
6671
<a href="<%= registration_confirmation_url(c.confirmation_code) %>" class="confirm_channel_link no-hover" aria-label="<%= t('titles.confirm_email_address_aria_label', "Confirm Email Address") %>"><i class="icon-check standalone-icon" alt="<%= t('titles.confirm_email_address_alt', "Confirm Email Address") %>" title="<%= t('titles.confirm_email_address', "Confirm Email Address") %>"></i></a>
6772
<% end %>
@@ -110,6 +115,11 @@
110115
<td><a href="#" class="path"><%= c.path_description %></a></td>
111116
<td><%= c.path_type %></td>
112117
<td style="padding: 0; text-align: center;">
118+
<% if c.bouncing? %>
119+
<span class="bouncing-channel" data-tooltip="left" title="<%= t('bouncing_channel', 'Canvas was unable to send messages to you using this contact method. Please ensure the contact information is correct to continue receiving messages from Canvas.') %>" aria-label="<%= t('bouncing_channel', 'Canvas was unable to send messages to you using this contact method. Please ensure the contact information is correct to continue receiving messages from Canvas.') %>">
120+
<i class="text text-warning icon-warning"></i>
121+
</span>
122+
<% end %>
113123
<% if c.state == :unconfirmed && (@user.grants_right?(@current_user, :manage_user_details) || (@real_current_user && @user.grants_right?(@real_current_user, :manage_user_details))) %>
114124
<a href="<%= registration_confirmation_url(c.confirmation_code) %>" class="confirm_channel_link no-hover"><i class="icon-check standalone-icon" title="<%= t('titles.confirm_email_address', "Confirm Email Address") %>"></i></a>
115125
<% end %>

0 commit comments

Comments
 (0)