canvas-lms/lib/pronouns.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.5 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
#
# 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/>.
Add personal pronouns closes: WOKE-5 Test plan: Preconditions: * go to the settings page for the domain root account * go to your user settings page, click “edit settings” * you should not see anything about “Pronouns” turn on: * you should not see a section about “Pronouns” * go to a root account, enable the “Pronouns” feature flag * go back to the settings page for the domain root account * you should now see a section about “Pronouns” * check the box to enable it * add a couple options * save Pick one for yourself: * go to a user’s profile page, you should see a <select> where you can pick one of the options the school allowed * you should see an Make sure it show up in inbox and stuff * go to conversations and discussions and all the places we started Showing pronouns, they should display your pronouns after where it Shows your name Make sure you can still unset yours after the account turns off the Setting: * go back to the account settings page & turn off the “Enable Personal Pronouns” checkbox * save * go to inbox or somewhere and verify that it still shows your pronouns * go to your user profile page * it should still display that you are “He/Him” (or whatever pronouns You picked above) * click “Edit Settings” * the select box to pick a pronoun should only have an option of “None” * hit save * now your pronouns should not show up on that page nor should They show up anywhere else in the UI Change-Id: I7f51c9ca2ec82cb0a3cbdca3bf37c7bc2a69d4f9 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/215336 Reviewed-by: Matthew Lemon <mlemon@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Tested-by: Jenkins QA-Review: Steven Burnett <sburnett@instructure.com> Product-Review: Steven Burnett <sburnett@instructure.com>
2019-11-04 13:21:37 +08:00
module Pronouns
DEFAULT_PRONOUNS = {
"she_her" => -> { I18n.t("She/Her") },
"he_him" => -> { I18n.t("He/Him") },
"they_them" => -> { I18n.t("They/Them") }
}.freeze
Add personal pronouns closes: WOKE-5 Test plan: Preconditions: * go to the settings page for the domain root account * go to your user settings page, click “edit settings” * you should not see anything about “Pronouns” turn on: * you should not see a section about “Pronouns” * go to a root account, enable the “Pronouns” feature flag * go back to the settings page for the domain root account * you should now see a section about “Pronouns” * check the box to enable it * add a couple options * save Pick one for yourself: * go to a user’s profile page, you should see a <select> where you can pick one of the options the school allowed * you should see an Make sure it show up in inbox and stuff * go to conversations and discussions and all the places we started Showing pronouns, they should display your pronouns after where it Shows your name Make sure you can still unset yours after the account turns off the Setting: * go back to the account settings page & turn off the “Enable Personal Pronouns” checkbox * save * go to inbox or somewhere and verify that it still shows your pronouns * go to your user profile page * it should still display that you are “He/Him” (or whatever pronouns You picked above) * click “Edit Settings” * the select box to pick a pronoun should only have an option of “None” * hit save * now your pronouns should not show up on that page nor should They show up anywhere else in the UI Change-Id: I7f51c9ca2ec82cb0a3cbdca3bf37c7bc2a69d4f9 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/215336 Reviewed-by: Matthew Lemon <mlemon@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Tested-by: Jenkins QA-Review: Steven Burnett <sburnett@instructure.com> Product-Review: Steven Burnett <sburnett@instructure.com>
2019-11-04 13:21:37 +08:00
def self.default_pronouns
DEFAULT_PRONOUNS.values.map(&:call)
end
def clean_pronouns(string)
string&.strip.presence
Add personal pronouns closes: WOKE-5 Test plan: Preconditions: * go to the settings page for the domain root account * go to your user settings page, click “edit settings” * you should not see anything about “Pronouns” turn on: * you should not see a section about “Pronouns” * go to a root account, enable the “Pronouns” feature flag * go back to the settings page for the domain root account * you should now see a section about “Pronouns” * check the box to enable it * add a couple options * save Pick one for yourself: * go to a user’s profile page, you should see a <select> where you can pick one of the options the school allowed * you should see an Make sure it show up in inbox and stuff * go to conversations and discussions and all the places we started Showing pronouns, they should display your pronouns after where it Shows your name Make sure you can still unset yours after the account turns off the Setting: * go back to the account settings page & turn off the “Enable Personal Pronouns” checkbox * save * go to inbox or somewhere and verify that it still shows your pronouns * go to your user profile page * it should still display that you are “He/Him” (or whatever pronouns You picked above) * click “Edit Settings” * the select box to pick a pronoun should only have an option of “None” * hit save * now your pronouns should not show up on that page nor should They show up anywhere else in the UI Change-Id: I7f51c9ca2ec82cb0a3cbdca3bf37c7bc2a69d4f9 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/215336 Reviewed-by: Matthew Lemon <mlemon@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Tested-by: Jenkins QA-Review: Steven Burnett <sburnett@instructure.com> Product-Review: Steven Burnett <sburnett@instructure.com>
2019-11-04 13:21:37 +08:00
end
def translate_pronouns(pronouns)
DEFAULT_PRONOUNS[pronouns]&.call || pronouns
end
Add personal pronouns closes: WOKE-5 Test plan: Preconditions: * go to the settings page for the domain root account * go to your user settings page, click “edit settings” * you should not see anything about “Pronouns” turn on: * you should not see a section about “Pronouns” * go to a root account, enable the “Pronouns” feature flag * go back to the settings page for the domain root account * you should now see a section about “Pronouns” * check the box to enable it * add a couple options * save Pick one for yourself: * go to a user’s profile page, you should see a <select> where you can pick one of the options the school allowed * you should see an Make sure it show up in inbox and stuff * go to conversations and discussions and all the places we started Showing pronouns, they should display your pronouns after where it Shows your name Make sure you can still unset yours after the account turns off the Setting: * go back to the account settings page & turn off the “Enable Personal Pronouns” checkbox * save * go to inbox or somewhere and verify that it still shows your pronouns * go to your user profile page * it should still display that you are “He/Him” (or whatever pronouns You picked above) * click “Edit Settings” * the select box to pick a pronoun should only have an option of “None” * hit save * now your pronouns should not show up on that page nor should They show up anywhere else in the UI Change-Id: I7f51c9ca2ec82cb0a3cbdca3bf37c7bc2a69d4f9 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/215336 Reviewed-by: Matthew Lemon <mlemon@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Tested-by: Jenkins QA-Review: Steven Burnett <sburnett@instructure.com> Product-Review: Steven Burnett <sburnett@instructure.com>
2019-11-04 13:21:37 +08:00
def untranslate_pronouns(pronouns)
pronouns = clean_pronouns(pronouns)
DEFAULT_PRONOUNS.each do |k, v|
return k if pronouns == v.call
end
pronouns
end
Add personal pronouns closes: WOKE-5 Test plan: Preconditions: * go to the settings page for the domain root account * go to your user settings page, click “edit settings” * you should not see anything about “Pronouns” turn on: * you should not see a section about “Pronouns” * go to a root account, enable the “Pronouns” feature flag * go back to the settings page for the domain root account * you should now see a section about “Pronouns” * check the box to enable it * add a couple options * save Pick one for yourself: * go to a user’s profile page, you should see a <select> where you can pick one of the options the school allowed * you should see an Make sure it show up in inbox and stuff * go to conversations and discussions and all the places we started Showing pronouns, they should display your pronouns after where it Shows your name Make sure you can still unset yours after the account turns off the Setting: * go back to the account settings page & turn off the “Enable Personal Pronouns” checkbox * save * go to inbox or somewhere and verify that it still shows your pronouns * go to your user profile page * it should still display that you are “He/Him” (or whatever pronouns You picked above) * click “Edit Settings” * the select box to pick a pronoun should only have an option of “None” * hit save * now your pronouns should not show up on that page nor should They show up anywhere else in the UI Change-Id: I7f51c9ca2ec82cb0a3cbdca3bf37c7bc2a69d4f9 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/215336 Reviewed-by: Matthew Lemon <mlemon@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> Tested-by: Jenkins QA-Review: Steven Burnett <sburnett@instructure.com> Product-Review: Steven Burnett <sburnett@instructure.com>
2019-11-04 13:21:37 +08:00
def match_pronoun(supplied_pronouns_str, account_pronouns_arr)
pronoun = clean_pronouns(supplied_pronouns_str)
account_pronouns_arr.each do |ap|
return ap if ap.casecmp(pronoun) == 0
end
nil
end
end