diff --git a/app/coffeescripts/notifications/NotificationPreferences.js b/app/coffeescripts/notifications/NotificationPreferences.js index e2c427422f5..67b9cd73d53 100644 --- a/app/coffeescripts/notifications/NotificationPreferences.js +++ b/app/coffeescripts/notifications/NotificationPreferences.js @@ -69,6 +69,7 @@ export default class NotificationPreferences { this.channels = this.options.channels || [] this.categories = this.options.categories || [] this.policies = this.options.policies || [] + this.showObservedNames = this.options.show_observed_names // Give each channel a 'name' this.channels.forEach((c) => { @@ -172,6 +173,12 @@ export default class NotificationPreferences { channels: this.channels, eventGroups, buttonData: this.buttonData, + showObservedNames: { + available: this.showObservedNames != null, + name: 'send_observed_names_in_notifications', + on: this.showObservedNames, + label: I18n.t('Show name of observed students in notifications.'), + } })) // Display Bootstrap-like popover tooltip on category names. Allow entire cell to trigger popup. @@ -226,7 +233,7 @@ export default class NotificationPreferences { $notificationPrefs.find('.user-pref-check').on('change', (e) => { const check = $(e.currentTarget) const checkStatus = check.attr('checked') === 'checked' - // Send user prefernce value to server + // Send user preference value to server const data = {user: {}} data.user[check.attr('name')] = checkStatus this.$notificationSaveStatus.disableWhileLoading($.ajaxJSON(this.updateUrl, 'PUT', data, null, () => diff --git a/app/controllers/profile_controller.rb b/app/controllers/profile_controller.rb index a8627e9f37d..8c3899defc8 100644 --- a/app/controllers/profile_controller.rb +++ b/app/controllers/profile_controller.rb @@ -225,6 +225,7 @@ class ProfileController < ApplicationController @context = @user.profile @active_tab = 'notifications' + # Get the list of Notification models (that are treated like categories) that make up the full list of Categories. full_category_list = Notification.dashboard_categories(@user) categories = full_category_list.map do |category| @@ -242,6 +243,7 @@ class ProfileController < ApplicationController :policies => NotificationPolicy.setup_with_default_policies(@user, full_category_list).map { |p| notification_policy_json(p, @user, session).tap { |json| json[:communication_channel_id] = p.communication_channel_id } }, :categories => categories, :update_url => communication_update_profile_path, + :show_observed_names => @user.observer_enrollments.any? || @user.as_observer_observation_links.any? ? @user.send_observed_names_in_notifications? : nil }, :READ_PRIVACY_INFO => @user.preferences[:read_notification_privacy_info], :ACCOUNT_PRIVACY_NOTICE => @domain_root_account.settings[:external_notification_warning] diff --git a/app/helpers/messages/send_student_names_helper.rb b/app/helpers/messages/send_student_names_helper.rb new file mode 100644 index 00000000000..a11c9019faf --- /dev/null +++ b/app/helpers/messages/send_student_names_helper.rb @@ -0,0 +1,22 @@ +# +# Copyright (C) 2018 - present Instructure, Inc. +# +# This file is part of Canvas. +# +# Canvas is free software: you can redistribute it and/or modify it under +# the terms of the GNU Affero General Public License as published by the Free +# Software Foundation, version 3 of the License. +# +# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +# details. +# +# You should have received a copy of the GNU Affero General Public License along +# with this program. If not, see . + +module Messages::SendStudentNamesHelper + def send_student_names(asset, user) + user != asset.user && user.try(:send_observed_names_in_notifications?) + end +end \ No newline at end of file diff --git a/app/messages/assignment_due_date_changed.email.erb b/app/messages/assignment_due_date_changed.email.erb index af61989908b..2e6f2eed60b 100644 --- a/app/messages/assignment_due_date_changed.email.erb +++ b/app/messages/assignment_due_date_changed.email.erb @@ -5,7 +5,7 @@ <% define_content :subject do %> <%= t('assignment_due_date_changed', 'Assignment Due Date Changed: %{assignment_name}, %{course_name}', :assignment_name => asset.title, :course_name => asset.context.name) %> <% end %> - + <%= t('assignment_due_date_changed_sentence', 'The due date for the assignment, %{assignment_name}, for the course, %{course_name}, has changed to:', :assignment_name => asset.title, :course_name => asset.context.name) %> <% if asset.due_at %> diff --git a/app/messages/submission_grade_changed.email.erb b/app/messages/submission_grade_changed.email.erb index 4312b7ce5d8..48ba9535166 100644 --- a/app/messages/submission_grade_changed.email.erb +++ b/app/messages/submission_grade_changed.email.erb @@ -8,7 +8,11 @@ <%= t :subject, "Grade Changed: %{assignment}, %{context}", :assignment => asset.assignment.title, :context => asset.assignment.context.name %> <% end %> -<%= t :body, "The grade on your assignment, %{assignment_title} has been changed.", :assignment_title => asset.assignment.title %> +<% if send_student_names(asset, user) %> +<%= t "The grade on assignment %{assignment_title} has been changed for %{name}.", :assignment_title => asset.assignment.title, name: asset.user.name %> +<% else %> +<%= t :body, "The grade on your assignment %{assignment_title} has been changed.", :assignment_title => asset.assignment.title %> +<% end %> <%= t :regraded_date, "re-graded: %{date}", :date => (datetime_string(force_zone(asset.graded_at)) rescue t(:no_date_set, "No Date Set")) %> <% if user.try(:send_scores_in_emails?, asset.assignment.context.root_account) %> diff --git a/app/messages/submission_grade_changed.email.html.erb b/app/messages/submission_grade_changed.email.html.erb index f09bb99f92f..82c8f3d7b2f 100644 --- a/app/messages/submission_grade_changed.email.html.erb +++ b/app/messages/submission_grade_changed.email.html.erb @@ -12,7 +12,11 @@ <% end %> -

<%= t :body, "The grade on your assignment, %{assignment_title} has been changed.", :assignment_title => asset.assignment.title %>

+<% if send_student_names(asset, user) %> +

<%= t "The grade on assignment %{assignment_title} has been changed for %{name}.", :assignment_title => asset.assignment.title, name: asset.user.name %>

+<% else %> +

<%= t :body, "The grade on your assignment %{assignment_title} has been changed.", :assignment_title => asset.assignment.title %>

+<% end %>

<%= t :regraded_date, "re-graded: %{date}", :date => (datetime_string(force_zone(asset.graded_at)) rescue t(:no_date_set, "No Date Set")) %>

diff --git a/app/messages/submission_grade_changed.sms.erb b/app/messages/submission_grade_changed.sms.erb index b355492b234..7fe7c38905e 100644 --- a/app/messages/submission_grade_changed.sms.erb +++ b/app/messages/submission_grade_changed.sms.erb @@ -1,4 +1,8 @@ -<%= t :body_sms, "Your grade for %{title}, %{context} just changed.", :title => asset.assignment.title, :context => asset.assignment.context.name %> +<% if send_student_names(asset, user) %> +<%= t "The grade for %{title} in %{context} for %{name} just changed.", :title => asset.assignment.title, :context => asset.assignment.context.name, name: asset.user.name %> +<% else %> + <%= t :body_sms, "Your grade for %{title} in %{context} just changed.", :title => asset.assignment.title, :context => asset.assignment.context.name %> +<% end %> <%= t :regraded_date, "re-graded: %{date}", :date => (datetime_string(force_zone(asset.graded_at)) rescue t(:no_date_set, "No Date Set")) %> <% if asset.score && user.try(:send_scores_in_emails?, asset.assignment.context.root_account) %> diff --git a/app/messages/submission_grade_changed.summary.erb b/app/messages/submission_grade_changed.summary.erb index 115b7a829ee..e0f340191d3 100644 --- a/app/messages/submission_grade_changed.summary.erb +++ b/app/messages/submission_grade_changed.summary.erb @@ -6,6 +6,9 @@ <%= t :subject, "Grade Changed: %{title}, %{context}", :title => asset.assignment.title, :context => asset.assignment.context.name %> <% end %> +<% if send_student_names(asset, user) %> + <%= t "For %{name}", name: asset.user.name %> +<% end %> <%= t :regraded_date, "re-graded: %{date}", :date => (datetime_string(force_zone(asset.graded_at)) rescue t(:no_date_set, "No Date Set")) %> <% if asset.score && user.try(:send_scores_in_emails?, asset.assignment.context.root_account) %> <%= t :score, "score: %{score} out of %{total}", :score => asset.score, :total => (asset.assignment.points_possible || t(:not_applicable, "N/A")) %> diff --git a/app/messages/submission_grade_changed.twitter.erb b/app/messages/submission_grade_changed.twitter.erb index ccb6456ae6c..67d41941994 100644 --- a/app/messages/submission_grade_changed.twitter.erb +++ b/app/messages/submission_grade_changed.twitter.erb @@ -1,7 +1,11 @@ <% define_content :link do -%> <%= polymorphic_url([asset.assignment.context, asset.assignment, :submission], id: asset.user) %> <% end -%> -<%= t :tweet, "Canvas Alert - Grade Change: %{date}", :date => (datetime_string(force_zone(asset.graded_at)) rescue t(:no_date_set, "No Date Set")) %> +<% if send_student_names(asset, user) %> + <%= t "Canvas Alert - Grade Change: %{date} for %{name}", :date => (datetime_string(force_zone(asset.graded_at)) rescue t(:no_date_set, "No Date Set")), name: asset.user.name %> +<% else %> + <%= t :tweet, "Canvas Alert - Grade Change: %{date}", :date => (datetime_string(force_zone(asset.graded_at)) rescue t(:no_date_set, "No Date Set")) %> +<% end %> <% if asset.score -%> <%= t :score, "score: %{score} out of %{total}", :score => asset.score, :total => (asset.assignment.points_possible || t(:not_applicable, "N/A")) %> diff --git a/app/messages/submission_graded.email.erb b/app/messages/submission_graded.email.erb index 2dcdcbe791d..a8850cffeca 100644 --- a/app/messages/submission_graded.email.erb +++ b/app/messages/submission_graded.email.erb @@ -8,7 +8,11 @@ <%= t :subject, "Assignment Graded: %{assignment}, %{context}", :assignment => asset.assignment.title, :context => asset.assignment.context.name %> <% end %> -<%= t :body, "Your assignment, %{assignment}, has been graded.", :assignment => asset.assignment.title %> +<% if send_student_names(asset, user) %> +<%= t "%{assignment} has been graded for %{name}.", assignment: asset.assignment.title, name: asset.user.name %> +<% else %> +<%= t :body, "Your assignment %{assignment} has been graded.", :assignment => asset.assignment.title %> +<% end %> <%= t :graded_date, "graded: %{date}", :date => (datetime_string(force_zone(asset.graded_at)) rescue t(:no_date_set, "No Date Set")) %> <% if user.try(:send_scores_in_emails?, asset.assignment.context.root_account) %> diff --git a/app/messages/submission_graded.email.html.erb b/app/messages/submission_graded.email.html.erb index 3da2b651705..25f89d9c192 100644 --- a/app/messages/submission_graded.email.html.erb +++ b/app/messages/submission_graded.email.html.erb @@ -12,7 +12,11 @@ <% end %> -

<%= t :body, "Your assignment, %{assignment}, has been graded.", :assignment => asset.assignment.title %>

+<% if send_student_names(asset, user) %> +

<%= t "%{assignment} has been graded for %{name}.", assignment: asset.assignment.title, name: asset.user.name %>

+<% else %> +

<%= t :body, "Your assignment %{assignment} has been graded.", :assignment => asset.assignment.title %>

+<% end %>

<%= t :graded_date, "graded: %{date}", :date => (datetime_string(force_zone(asset.graded_at)) rescue t(:no_date_set, "No Date Set")) %>

diff --git a/app/messages/submission_graded.sms.erb b/app/messages/submission_graded.sms.erb index be1bd59cdb5..4cbdc8f63db 100644 --- a/app/messages/submission_graded.sms.erb +++ b/app/messages/submission_graded.sms.erb @@ -1,4 +1,8 @@ +<% if send_student_names(asset, user) %> +<%= t "%{assignment}, %{context} has been graded for %{name}.", :assignment => asset.assignment.title, :context => asset.assignment.context.name, name: asset.user.name %> +<% else %> <%= t :sms_body, "%{assignment}, %{context} has been graded.", :assignment => asset.assignment.title, :context => asset.assignment.context.name %> +<% end %> <%= t :graded_date, "graded: %{date}", :date => (datetime_string(force_zone(asset.graded_at)) rescue t(:no_date_set, "No Date Set")) %> <% if asset.score && user.try(:send_scores_in_emails?, asset.assignment.context.root_account) %> diff --git a/app/messages/submission_graded.summary.erb b/app/messages/submission_graded.summary.erb index f224352b305..7e62e0f9c63 100644 --- a/app/messages/submission_graded.summary.erb +++ b/app/messages/submission_graded.summary.erb @@ -6,6 +6,9 @@ <%= t :subject, "Assignment Graded: %{assignment}, %{context}", :assignment => asset.assignment.title, :context => asset.assignment.context.name %> <% end %> +<% if send_student_names(asset, user) %> + <%= t "For %{name}", name: asset.user.name %> +<% end %> <%= t :graded_date, "graded: %{date}", :date => (datetime_string(force_zone(asset.graded_at)) rescue t(:no_date_set, "No Date Set")) %> <% if asset.score && user.try(:send_scores_in_emails?, asset.assignment.context.root_account) %> <%= t :score, "score: %{score} out of %{total}", :score => asset.score, :total => (asset.assignment.points_possible || t(:not_applicable, "N/A")) %> diff --git a/app/messages/submission_graded.twitter.erb b/app/messages/submission_graded.twitter.erb index 538fdcb93eb..84ab48d9572 100644 --- a/app/messages/submission_graded.twitter.erb +++ b/app/messages/submission_graded.twitter.erb @@ -1,7 +1,11 @@ <% define_content :link do -%> <%= polymorphic_url([asset.assignment.context, asset.assignment]) %> <% end -%> -<%= t :tweet, "Canvas Alert - Graded: %{assignment}, %{context}", :assignment => asset.assignment.title, :context => asset.assignment.context.name %> +<% if send_student_names(asset, user) %> + <%= t "Canvas Alert - Graded: %{assignment}, %{context} for %{name}", :assignment => asset.assignment.title, :context => asset.assignment.context.name, name: user.asset.name %> +<% else %> + <%= t :tweet, "Canvas Alert - Graded: %{assignment}, %{context}", :assignment => asset.assignment.title, :context => asset.assignment.context.name %> +<% end %> <%= datetime_string(force_zone(asset.graded_at)) rescue t(:no_date_set, "No Date Set") %> diff --git a/app/models/message.rb b/app/models/message.rb index 5d7a0d1712c..971e786f13e 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -26,6 +26,7 @@ class Message < ActiveRecord::Base include HtmlTextHelper include Workflow include Messages::PeerReviewsHelper + include Messages::SendStudentNamesHelper extend TextHelper diff --git a/app/models/notification_policy.rb b/app/models/notification_policy.rb index 46507ad1bee..56d7e9ed105 100644 --- a/app/models/notification_policy.rb +++ b/app/models/notification_policy.rb @@ -59,10 +59,10 @@ class NotificationPolicy < ActiveRecord::Base bool_val = (value == 'true') # save the preference as a symbol (convert from string) case key.to_sym - when :send_scores_in_emails + when :send_scores_in_emails, :send_observed_names_in_notifications # Only set if a root account and the root account allows the setting. if params[:root_account].settings[:allow_sending_scores_in_emails] != false - user.preferences[:send_scores_in_emails] = bool_val + user.preferences[key.to_sym] = bool_val end when :no_submission_comments_inbox user.preferences[:no_submission_comments_inbox] = bool_val diff --git a/app/models/user.rb b/app/models/user.rb index 4c163884c98..5cee1dd73b9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1460,6 +1460,10 @@ class User < ActiveRecord::Base preferences[:send_scores_in_emails] == true && root_account.settings[:allow_sending_scores_in_emails] != false end + def send_observed_names_in_notifications? + preferences[:send_observed_names_in_notifications] == true + end + def close_announcement(announcement) preferences[:closed_notifications] ||= [] # serialize ids relative to the user diff --git a/app/views/jst/profiles/notification_preferences.handlebars b/app/views/jst/profiles/notification_preferences.handlebars index c853eeb0c35..290b5120fc0 100644 --- a/app/views/jst/profiles/notification_preferences.handlebars +++ b/app/views/jst/profiles/notification_preferences.handlebars @@ -3,6 +3,17 @@ {{title}} {{/each}} +{{#if showObservedNames.available}} +
+ +
+{{/if}} {{#each eventGroups}}