add account pronouns
fixes COMMS-2492 flag=account_pronouns Test Plan: - go to a users profile page with the account pronouns feature flag on - notice you can now select from a list of default pronouns - commits to come where we will start showing them next to users names (inbox ect) Change-Id: I41dd97ea616b0952cf30aed1b4bfcb566869962a Reviewed-on: https://gerrit.instructure.com/212205 Reviewed-by: Landon Gilbert-Bland <lbland@instructure.com> QA-Review: Landon Gilbert-Bland <lbland@instructure.com> Tested-by: Jenkins Product-Review: Steven Burnett <sburnett@instructure.com>
This commit is contained in:
parent
6656959d51
commit
0add882c30
|
@ -1413,7 +1413,7 @@ class AccountsController < ApplicationController
|
|||
PERMITTED_SETTINGS_FOR_UPDATE = [:admins_can_change_passwords, :admins_can_view_notifications,
|
||||
:allow_invitation_previews, :allow_sending_scores_in_emails,
|
||||
:author_email_in_notifications, :canvadocs_prefer_office_online,
|
||||
:consortium_parent_account, :consortium_can_create_own_accounts,
|
||||
:consortium_parent_account, :consortium_can_create_own_accounts, :can_add_pronouns,
|
||||
:shard_per_account, :consortium_autocreate_web_of_trust,
|
||||
:consortium_autocreate_reverse_trust,
|
||||
:default_storage_quota, :default_storage_quota_mb,
|
||||
|
|
|
@ -336,7 +336,7 @@ class ProfileController < ApplicationController
|
|||
respond_to do |format|
|
||||
user_params = params[:user] ? params[:user].
|
||||
permit(:name, :short_name, :sortable_name, :time_zone, :show_user_services, :gender,
|
||||
:avatar_image, :subscribe_to_emails, :locale, :bio, :birthdate)
|
||||
:avatar_image, :subscribe_to_emails, :locale, :bio, :birthdate, :account_pronoun_id)
|
||||
: {}
|
||||
if !@user.user_can_edit_name?
|
||||
user_params.delete(:name)
|
||||
|
|
|
@ -200,6 +200,7 @@ class Account < ActiveRecord::Base
|
|||
add_setting :restrict_quiz_questions, :boolean => true, :root_only => true, :default => false
|
||||
add_setting :no_enrollments_can_create_courses, :boolean => true, :root_only => true, :default => false
|
||||
add_setting :allow_sending_scores_in_emails, :boolean => true, :root_only => true
|
||||
add_setting :can_add_pronouns, :boolean => true, :root_only => true, :default => false
|
||||
|
||||
add_setting :self_enrollment
|
||||
add_setting :equella_endpoint
|
||||
|
@ -303,6 +304,12 @@ class Account < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def pronouns
|
||||
self.shard.activate do
|
||||
AccountPronoun.where(account: [self, nil]).to_a
|
||||
end
|
||||
end
|
||||
|
||||
def mfa_settings
|
||||
settings[:mfa_settings].try(:to_sym) || :disabled
|
||||
end
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
#
|
||||
# Copyright (C) 2019 - 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/>.
|
||||
#
|
||||
#
|
||||
class AccountPronoun < ActiveRecord::Base
|
||||
include Canvas::SoftDeletable
|
||||
belongs_to :account
|
||||
|
||||
DEFAULT_OPTIONS = {
|
||||
:she_her => -> { t('she/her') },
|
||||
:he_him => -> { t('he/him') },
|
||||
:they_them => -> { t('they/them') }
|
||||
}.freeze
|
||||
|
||||
def self.create_defaults
|
||||
DEFAULT_OPTIONS.each_key {|pronoun| self.where(pronoun: pronoun, account_id: nil).first_or_create!}
|
||||
end
|
||||
|
||||
def display_pronoun
|
||||
self.account_id ? self.pronoun : DEFAULT_OPTIONS[self.pronoun.to_sym].call
|
||||
end
|
||||
end
|
|
@ -172,6 +172,7 @@ class User < ActiveRecord::Base
|
|||
has_many :past_lti_ids, class_name: 'UserPastLtiId', inverse_of: :user
|
||||
|
||||
belongs_to :otp_communication_channel, :class_name => 'CommunicationChannel'
|
||||
belongs_to :account_pronoun
|
||||
|
||||
include StickySisFields
|
||||
are_sis_sticky :name, :sortable_name, :short_name
|
||||
|
|
|
@ -213,6 +213,13 @@
|
|||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% if Account.site_admin.feature_enabled?(:account_pronouns) %>
|
||||
<tr>
|
||||
<td colspan="2"><%= settings.check_box :can_add_pronouns, :checked => @domain_root_account.settings[:can_add_pronouns] %>
|
||||
<%= settings.label :can_add_pronouns, en: "Users can add pronouns as an identifier" %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<tr>
|
||||
<td colspan="2"><%= settings.check_box :restrict_quiz_questions, :checked => @account.settings[:restrict_quiz_questions] %>
|
||||
<%= settings.label :restrict_quiz_questions, :en => "Restrict students from viewing quiz questions after course end date" %>
|
||||
|
@ -258,7 +265,6 @@
|
|||
</tr>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= settings.fields_for :restrict_student_past_view do |r| %>
|
||||
<% hash = @account.restrict_student_past_view %>
|
||||
<% disabled = hash[:locked] && hash[:inherited] %>
|
||||
|
|
|
@ -94,6 +94,20 @@
|
|||
<span id="hints_sortable_name" class="edit_or_show_data data_description"><br/><%= t('hints.sortable_name', "This name appears in sorted lists.") %></span>
|
||||
</td>
|
||||
</tr>
|
||||
<% if Account.site_admin.feature_enabled?(:account_pronouns) && @domain_root_account.settings[:can_add_pronouns] %>
|
||||
<tr>
|
||||
<th scope="row"><%= f.blabel :pronoun, :en => "Pronoun" %></th>
|
||||
<td><span id="pronoun" class="<%= editable_name ? 'display_data' : 'edit_or_show_data' %>"><%= @user.account_pronoun&.display_pronoun || t("None") %></span>
|
||||
<select id="pronoun_list_id" name="user[account_pronoun_id]" class="edit_data">
|
||||
<option <%= "selected" if !@user.account_pronoun_id %>><%= t("None") %></option>
|
||||
<% @domain_root_account.pronouns.each do |pronoun| %>
|
||||
<option value="<%= pronoun.id %>" <%= "selected" if pronoun.id == @user.account_pronoun_id%> ><%=pronoun.display_pronoun%></option>
|
||||
<% end %>
|
||||
</select>
|
||||
<span id="hints_sortable_name" class="edit_or_show_data data_description"><br/><%= t("This pronoun appears after last name") %></span>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% active_email_channels = @email_channels.select { |cc| cc.active? } %>
|
||||
<% if active_email_channels.length > 1 %>
|
||||
<tr>
|
||||
|
|
|
@ -9,3 +9,10 @@ assignments_2_student:
|
|||
environments:
|
||||
production:
|
||||
state: disabled
|
||||
|
||||
account_pronouns:
|
||||
state: hidden
|
||||
display_name: Pronouns for users
|
||||
description: Pronouns users can show after their name
|
||||
applies_to: SiteAdmin
|
||||
root_opt_in: true
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
#
|
||||
# Copyright (C) 2019 - 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/>.
|
||||
#
|
||||
|
||||
class CreateAccountPronouns < ActiveRecord::Migration[5.2]
|
||||
tag :predeploy
|
||||
def change
|
||||
create_table :account_pronouns do |t|
|
||||
t.belongs_to :account, foreign_key: true, limit: 8, index: true
|
||||
t.string :pronoun, null: false
|
||||
t.timestamps
|
||||
t.string :workflow_state
|
||||
end
|
||||
AccountPronoun.reset_column_information
|
||||
AccountPronoun.create_defaults
|
||||
end
|
||||
end
|
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
# Copyright (C) 2019 - 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/>.
|
||||
|
||||
class AddAccountPronounToUser < ActiveRecord::Migration[5.2]
|
||||
tag :predeploy
|
||||
|
||||
def change
|
||||
add_column :users, :account_pronoun_id, :int, limit: 8
|
||||
end
|
||||
end
|
|
@ -73,6 +73,9 @@ describe ProfileController do
|
|||
end
|
||||
|
||||
describe "update" do
|
||||
before :each do
|
||||
AccountPronoun.create_defaults
|
||||
end
|
||||
it "should allow changing the default e-mail address and nothing else" do
|
||||
user_session(@user, @pseudonym)
|
||||
expect(@cc.position).to eq 1
|
||||
|
@ -84,6 +87,26 @@ describe ProfileController do
|
|||
expect(@cc.reload.position).to eq 2
|
||||
end
|
||||
|
||||
it "should allow changing pronoun" do
|
||||
user_session(@user, @pseudonym)
|
||||
expect(@user.account_pronoun).to eq nil
|
||||
put 'update', params: {:user => {:account_pronoun_id => AccountPronoun.first.id}}, format: 'json'
|
||||
expect(response).to be_successful
|
||||
@user.reload
|
||||
expect(@user.account_pronoun).to eq AccountPronoun.first
|
||||
end
|
||||
|
||||
it "should allow unsetting pronoun" do
|
||||
user_session(@user, @pseudonym)
|
||||
@user.account_pronoun = AccountPronoun.first
|
||||
@user.save!
|
||||
expect(@user.account_pronoun).to eq AccountPronoun.first
|
||||
put 'update', params: {:user => {:account_pronoun_id => ''}}, format: 'json'
|
||||
expect(response).to be_successful
|
||||
@user.reload
|
||||
expect(@user.account_pronoun).to eq nil
|
||||
end
|
||||
|
||||
it "should clear email cache" do
|
||||
enable_cache do
|
||||
@user.email # prime cache
|
||||
|
|
|
@ -56,6 +56,17 @@ describe Account do
|
|||
# account_model
|
||||
# @a.to_atom.should be_is_a(Atom::Entry)
|
||||
# end
|
||||
#
|
||||
it "should list all account pronouns" do
|
||||
account1 = Account.create!
|
||||
account2 = Account.create!
|
||||
AccountPronoun.create_defaults
|
||||
ap1 = AccountPronoun.create!(pronoun: "account 1 pronoun", account: account1)
|
||||
AccountPronoun.create!(pronoun: "account 2 pronoun", account: account2)
|
||||
expect(account1.pronouns.count).to eq 4
|
||||
expect(account1.pronouns).to include(ap1)
|
||||
expect(account2.pronouns).not_to include(ap1)
|
||||
end
|
||||
|
||||
context "course lists" do
|
||||
before :once do
|
||||
|
|
Loading…
Reference in New Issue