Add settings to disable signature & auto response for students

closes OUT-6300
flag=inbox_settings

Test plan:
- Go to Site Admin->Features and enable Inbox Settings FF
- Go to Account->Settings and verify that when Enable Inbox
Signature Block is not checked, Disable Inbox Signature Block
for Students is locked and cannot be checked
- Verify that when Enable Inbox Signature Block is checked,
Disable Inbox Signature Block for Students is not locked
and can be checked
- Repeat above for Enable Inbox Auto Response and Disable
Inbox Auto Response for Students
- Enable Inbox Signature Block, Inbox Signature Block for
Students, Inbox Auto Response and Disable Inbox Auto Response
for Students
- Create user and course, enroll user as student in that
course, act as user and confirm enrollment, then go to Inbox
- Verify that there is no Inbox Settings button
- Create another course, enroll user as teacher in that
course, act as user and confirm enrollment, then go to Inbox
- Verify that there is Inbox Settings button; click on
that button and in the modal verify that both Auto
Response and Signature settings are available
- Create another user, act as that user and go to Inbox
- Verify that there is no Inbox Settings button
- Start rails console and make the second user Account Admin
account = switch_to_shard! 'shard name'
user = User.find('put user id here')
role = Role.get_built_in_role("AccountAdmin",
root_account_id: account.id)
account.account_users.create!(user:, role:)
- In Canvas, act as that user and go to Inbox
- Verify that there is Inbox Settings button; click on
that button and in the modal verify that both Auto
Response and Signature settings are available
- Add that second user as observer in a course,
then act as user and go to Inbox
- Verify that there is no Inbox Settings button

Change-Id: I3d984730f6c4a52c807b0c6a98d14e9cfb9d7566
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/348208
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Jason Anderson <jason.anderson@instructure.com>
QA-Review: Jason Anderson <jason.anderson@instructure.com>
Product-Review: Chrystal Langston <chrystal.langston@instructure.com>
This commit is contained in:
Martin Yosifov 2024-06-03 11:16:27 -07:00 committed by Chrystal Langston
parent 4a7d0053a3
commit 5c90ce272a
7 changed files with 214 additions and 10 deletions

View File

@ -1955,7 +1955,9 @@ class AccountsController < ApplicationController
{ conditional_release: [:value, :locked] }.freeze,
{ allow_observers_in_appointment_groups: [:value] }.freeze,
:enable_inbox_signature_block,
:disable_inbox_signature_block_for_students,
:enable_inbox_auto_response,
:disable_inbox_auto_response_for_students,
:enable_name_pronunciation,].freeze
def permitted_account_attributes

View File

@ -300,8 +300,13 @@ class ConversationsController < ApplicationController
MAX_GROUP_CONVERSATION_SIZE: Conversation.max_group_conversation_size
}
hash[:INBOX_SIGNATURE_BLOCK_ENABLED] = Account.site_admin.feature_enabled?(:inbox_settings) && @domain_root_account.enable_inbox_signature_block?
hash[:INBOX_AUTO_RESPONSE_ENABLED] = Account.site_admin.feature_enabled?(:inbox_settings) && @domain_root_account.enable_inbox_auto_response?
is_student = inbox_settings_student?(user: @current_user, account: @domain_root_account)
hash[:INBOX_SIGNATURE_BLOCK_ENABLED] = Account.site_admin.feature_enabled?(:inbox_settings) &&
@domain_root_account.enable_inbox_signature_block? &&
(!is_student || (is_student && !@domain_root_account.disable_inbox_signature_block_for_students?))
hash[:INBOX_AUTO_RESPONSE_ENABLED] = Account.site_admin.feature_enabled?(:inbox_settings) &&
@domain_root_account.enable_inbox_auto_response? &&
(!is_student || (is_student && !@domain_root_account.disable_inbox_auto_response_for_students?))
notes_enabled_accounts = @current_user.associated_accounts.having_user_notes_enabled

View File

@ -335,6 +335,32 @@ module ConversationsHelper
end
end
def inbox_settings_student?(user: @current_user, account: @domain_root_account)
admin_user = account.grants_any_right?(user, :manage_account_settings, :manage_site_settings)
active_user_enrollments = Enrollment
.joins(:course)
.where(
user_id: user.id,
root_account_id: account.id,
workflow_state: "active"
)
.where.not(course: { workflow_state: "deleted" })
active_student = active_user_enrollments
.where(type: %w[StudentEnrollment StudentViewEnrollment ObserverEnrollment])
.exists?
active_non_student = active_user_enrollments
.where(type: %w[TeacherEnrollment TaEnrollment DesignerEnrollment])
.exists?
# Not a Student
# - User with active Teacher, TA or Designer Enrollments
# - Admin user without active Student, StudentView or Observer Enrollments
!(active_non_student || (admin_user && !active_student))
end
class Error < StandardError
attr_accessor :message, :status, :attribute

View File

@ -398,7 +398,9 @@ class Account < ActiveRecord::Base
add_setting :enable_name_pronunciation, boolean: true, root_only: true, default: false
add_setting :enable_inbox_signature_block, boolean: true, root_only: true, default: false
add_setting :disable_inbox_signature_block_for_students, boolean: true, root_only: true, default: false
add_setting :enable_inbox_auto_response, boolean: true, root_only: true, default: false
add_setting :disable_inbox_auto_response_for_students, boolean: true, root_only: true, default: false
def settings=(hash)
if hash.is_a?(Hash) || hash.is_a?(ActionController::Parameters)

View File

@ -691,14 +691,34 @@
</div>
<% end %>
<% if !@account.site_admin? && @account.root_account? && Account.site_admin.feature_enabled?(:inbox_settings) %>
<div>
<%= settings.check_box :enable_inbox_signature_block, :checked => @account.enable_inbox_signature_block? %>
<%= settings.label :enable_inbox_signature_block, :en => "Enable Inbox Signature Block" %>
</div>
<div>
<%= settings.check_box :enable_inbox_auto_response, :checked => @account.enable_inbox_auto_response? %>
<%= settings.label :enable_inbox_auto_response, :en => "Enable Inbox Auto Response" %>
</div>
<table>
<% inbox_signature_block_enabled = @account.enable_inbox_signature_block? %>
<tr>
<td colspan="2">
<%= settings.check_box :enable_inbox_signature_block, :checked => inbox_signature_block_enabled %>
<%= settings.label :enable_inbox_signature_block, :en => "Enable Inbox Signature Block" %>
</td>
</tr>
<tr>
<td colspan="2" class="sub_checkbox">
<%= settings.check_box :disable_inbox_signature_block_for_students, :checked => @account.disable_inbox_signature_block_for_students?, :disabled => !inbox_signature_block_enabled %>
<%= settings.label :disable_inbox_signature_block_for_students, :en => "Disable Inbox Signature Block for Students" %>
</td>
</tr>
<% inbox_auto_response_enabled = @account.enable_inbox_auto_response? %>
<tr>
<td colspan="2">
<%= settings.check_box :enable_inbox_auto_response, :checked => inbox_auto_response_enabled %>
<%= settings.label :enable_inbox_auto_response, :en => "Enable Inbox Auto Response" %>
</td>
</tr>
<tr>
<td colspan="2" class="sub_checkbox">
<%= settings.check_box :disable_inbox_auto_response_for_students, :checked => @account.disable_inbox_auto_response_for_students?, :disabled => !inbox_auto_response_enabled %>
<%= settings.label :disable_inbox_auto_response_for_students, :en => "Disable Inbox Auto Response for Students" %>
</td>
</tr>
</table>
<% end %>
<% if !@account.site_admin? && @account.root_account? %>
<div>

View File

@ -0,0 +1,129 @@
# frozen_string_literal: true
#
# Copyright (C) 2024 - 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 <http://www.gnu.org/licenses/>.
#
describe ConversationsHelper do
include ConversationsHelper
let(:account) { Account.default }
let(:account_admin) { account_admin_user(account:) }
let(:site_admin) { site_admin_user(account:) }
let(:course) { course_factory(account:, active_all: true) }
let(:user) { user_factory }
let(:user_student) { course.enroll_student(user_factory, enrollment_state: "active").user }
let(:user_teacher) { course.enroll_teacher(user_factory, enrollment_state: "active").user }
let(:user_ta) { course.enroll_ta(user_factory, enrollment_state: "active").user }
let(:user_designer) { course.enroll_designer(user_factory, enrollment_state: "active").user }
let(:user_observer) do
observer = user_factory
observer_enrollment = course.enroll_user(observer, "ObserverEnrollment")
observer_enrollment.update_attribute(:associated_user_id, user_student.id)
observer
end
let(:account_admin_student) { course.enroll_student(account_admin_user(account:), enrollment_state: "active").user }
let(:account_admin_teacher) { course.enroll_teacher(account_admin_user(account:), enrollment_state: "active").user }
let(:account_admin_ta) { course.enroll_ta(account_admin_user(account:), enrollment_state: "active").user }
let(:account_admin_designer) { course.enroll_designer(account_admin_user(account:), enrollment_state: "active").user }
let(:account_admin_observer) do
admin_observer = account_admin_user(account:)
observer_enrollment = course.enroll_user(admin_observer, "ObserverEnrollment")
observer_enrollment.update_attribute(:associated_user_id, user_student.id)
admin_observer
end
let(:site_admin_student) { course.enroll_student(site_admin_user(account:), enrollment_state: "active").user }
let(:site_admin_teacher) { course.enroll_teacher(site_admin_user(account:), enrollment_state: "active").user }
let(:site_admin_ta) { course.enroll_ta(site_admin_user(account:), enrollment_state: "active").user }
let(:site_admin_designer) { course.enroll_designer(site_admin_user(account:), enrollment_state: "active").user }
let(:site_admin_observer) do
siteadmin_observer = site_admin_user(account:)
observer_enrollment = course.enroll_user(siteadmin_observer, "ObserverEnrollment")
observer_enrollment.update_attribute(:associated_user_id, user_student.id)
siteadmin_observer
end
describe "inbox_settings_student?" do
context "returns false for users considered non-students for inbox settings" do
it "user who is active teacher" do
expect(inbox_settings_student?(user: user_teacher, account:)).to be false
end
it "user who is active teaching assistant" do
expect(inbox_settings_student?(user: user_ta, account:)).to be false
end
it "user who is active designer" do
expect(inbox_settings_student?(user: user_designer, account:)).to be false
end
it "account admin who is active teacher" do
expect(inbox_settings_student?(user: account_admin_teacher, account:)).to be false
end
it "account admin who is active teaching assistant" do
expect(inbox_settings_student?(user: account_admin_ta, account:)).to be false
end
it "account admin who is active designer" do
expect(inbox_settings_student?(user: account_admin_designer, account:)).to be false
end
it "site admin who is active teacher" do
expect(inbox_settings_student?(user: site_admin_teacher, account:)).to be false
end
it "site admin who is active teaching assistant" do
expect(inbox_settings_student?(user: site_admin_ta, account:)).to be false
end
it "site admin who is active designer" do
expect(inbox_settings_student?(user: site_admin_designer, account:)).to be false
end
end
context "returns true for users considered students for inbox settings" do
it "user who is not enrolled" do
expect(inbox_settings_student?(user:, account:)).to be true
end
it "user who is active student" do
expect(inbox_settings_student?(user: user_student, account:)).to be true
end
it "user who is active observer" do
expect(inbox_settings_student?(user: user_observer, account:)).to be true
end
it "account admin who is active student" do
expect(inbox_settings_student?(user: account_admin_student, account:)).to be true
end
it "account admin who is active observer" do
expect(inbox_settings_student?(user: account_admin_observer, account:)).to be true
end
it "site admin who is active student" do
expect(inbox_settings_student?(user: site_admin_student, account:)).to be true
end
it "site admin who is active observer" do
expect(inbox_settings_student?(user: site_admin_observer, account:)).to be true
end
end
end
end

View File

@ -643,6 +643,26 @@ $(document).ready(function () {
onTermsTypeChange()
}
$('#account_settings_enable_inbox_signature_block').click(event => {
const lockbox = $('#account_settings_disable_inbox_signature_block_for_students')
if (event.target.checked) {
lockbox.prop('disabled', false)
} else {
lockbox.prop('checked', false)
lockbox.prop('disabled', true)
}
})
$('#account_settings_enable_inbox_auto_response').click(event => {
const lockbox = $('#account_settings_disable_inbox_auto_response_for_students')
if (event.target.checked) {
lockbox.prop('disabled', false)
} else {
lockbox.prop('checked', false)
lockbox.prop('disabled', true)
}
})
window.addEventListener('popstate', () => {
const openTab = window.location.hash
if (openTab) {