Skip to content

Commit

Permalink
Initial support for Pronouns MVC (CFM-232)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Oct 20, 2022
1 parent e0cd3eb commit 79d29b7
Show file tree
Hide file tree
Showing 20 changed files with 415 additions and 10 deletions.
20 changes: 18 additions & 2 deletions app/config/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"default_email_address_type_id": { "type": "integer", "foreignkey": { "table": "types", "column": "id" } },
"default_identifier_type_id": { "type": "integer", "foreignkey": { "table": "types", "column": "id" } },
"default_name_type_id": { "type": "integer", "foreignkey": { "table": "types", "column": "id" } },
"default_pronoun_type_id": { "type": "integer", "foreignkey": { "table": "types", "column": "id" } },
"default_telephone_number_type_id": { "type": "integer", "foreignkey": { "table": "types", "column": "id" } },
"default_url_type_id": { "type": "integer", "foreignkey": { "table": "types", "column": "id" } },
"permitted_fields_name": { "type": "string", "size": 160 },
Expand All @@ -99,8 +100,9 @@
"co_settings_i3": { "columns": [ "default_email_address_type_id" ] },
"co_settings_i4": { "columns": [ "default_identifier_type_id" ] },
"co_settings_i5": { "columns": [ "default_address_type_id" ] },
"co_settings_i6": { "columns": [ "default_telephone_number_type_id" ] },
"co_settings_i7": { "columns": [ "default_url_type_id" ] }
"co_settings_i6": { "columns": [ "default_pronoun_type_id" ] },
"co_settings_i7": { "columns": [ "default_telephone_number_type_id" ] },
"co_settings_i8": { "columns": [ "default_url_type_id" ] }
}
},

Expand Down Expand Up @@ -392,6 +394,20 @@
"sourced": true
},

"pronouns": {
"columns": {
"id": {},
"pronouns": { "type": "string", "size": 64 },
"language": {},
"type_id": {}
},
"indexes": {
"pronouns_i1": { "columns": [ "type_id" ] }
},
"mvea": [ "person", "external_identity" ],
"sourced": true
},

"telephone_numbers": {
"columns": {
"id": {},
Expand Down
2 changes: 1 addition & 1 deletion app/resources/locales/en_US/command.po
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Command Line text

msgid "db.noop"
msgstr "SQL NOT EXECUTED"
msgstr "== SQL NOT EXECUTED =="

msgid "db.ok"
msgstr "Database schema update successful"
Expand Down
3 changes: 3 additions & 0 deletions app/resources/locales/en_US/controller.po
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ msgstr "{0,plural,=1{Person} other{People}}"
msgid "PersonRoles"
msgstr "{0,plural,=1{Person Role} other{Person Roles}}"

msgid "Pronouns"
msgstr "{0,plural,=1{Pronoun Preference} other{Pronouns}}"

msgid "TelephoneNumbers"
msgstr "{0,plural,=1{Telephone Number} other{Telephone Numbers}}"

Expand Down
3 changes: 3 additions & 0 deletions app/resources/locales/en_US/defaultType.po
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ msgstr "Staff"
msgid "PersonRoles.student"
msgstr "Student"

msgid "Pronouns.default"
msgstr "Default"

msgid "Urls.official"
msgstr "Official"

Expand Down
5 changes: 4 additions & 1 deletion app/resources/locales/en_US/error.po
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,14 @@ msgid "save"
msgstr "Save Failed ({0})"

msgid "schema.column"
msgstr "No type defined for table {0} column {1}"
msgstr "No type defined for table \"{0}\" column \"{1}\""

msgid "schema.parse"
msgstr "Failed to parse file {0}"

msgid "setup.co.comanage"
msgstr "Failed to setup COmanage CO"

msgid "Types.inuse"
msgstr "Type {0} is in use and cannot be deleted"

Expand Down
6 changes: 6 additions & 0 deletions app/resources/locales/en_US/field.po
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ msgstr "Default Identifier Type"
msgid "CoSettings.default_name_type_id"
msgstr "Default Name Type"

msgid "CoSettings.default_pronoun_type_id"
msgstr "Default Pronoun Type"

msgid "CoSettings.default_telephone_number_type_id"
msgstr "Default Telephone Number Type"

Expand Down Expand Up @@ -260,6 +263,9 @@ msgstr "Primary Name"
msgid "privileged"
msgstr "Privileged"

msgid "pronouns"
msgstr "Preferred Pronouns"

msgid "ApiUsers.privileged.desc"
msgstr "A privileged API user has full access to the CO. Unprivileged API users may be granted specific permissions where supported."

Expand Down
2 changes: 1 addition & 1 deletion app/src/Command/DatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public function execute(Arguments $args, ConsoleIo $io) {
}

if(!$doSQL) {
$io->out(__d('registry', 'db.noop'));
$io->out(__d('command', 'db.noop'));
} else {
$io->out(__d('command', 'db.ok'));
}
Expand Down
18 changes: 18 additions & 0 deletions app/src/Command/TransmogrifyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class TransmogrifyCommand extends Command {
'types' => [
'source' => 'cm_co_extended_types',
'displayField' => 'display_name',
'postTable' => 'insertPronounTypes',
'fieldMap' => [
'attribute' => '&map_extended_type',
'name' => 'value',
Expand Down Expand Up @@ -792,6 +793,23 @@ protected function insertDefaultSettings() {
}
}

/**
* Insert default Pronoun types.
*
* @since COmanage Registry v5.0.0
*/

protected function insertPronounTypes() {
// Since the Pronoun MVEA didn't exist in v4, we'll need to create the
// default types for all COs.

$Types = TableRegistry::getTableLocator()->get('Types');

foreach(array_keys($this->cache['cos']['id']) as $coId) {
$Types->addDefault($coId, 'Pronouns.type');
}
}

/**
* Map fields that have been renamed from Registry Classic to Registry PE.
*
Expand Down
42 changes: 42 additions & 0 deletions app/src/Controller/PronounsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* COmanage Registry Pronouns Controller
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link https://www.internet2.edu/comanage COmanage Project
* @package registry
* @since COmanage Registry v5.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

declare(strict_types = 1);

namespace App\Controller;

// XXX not doing anything with Log yet
use Cake\Log\Log;
use Cake\ORM\TableRegistry;

class PronounsController extends MVEAController {
public $pagination = [
'order' => [
'Pronouns.pronouns' => 'asc'
]
];
}
44 changes: 44 additions & 0 deletions app/src/Model/Entity/Pronoun.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* COmanage Registry Pronoun Entity
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link https://www.internet2.edu/comanage COmanage Project
* @package registry
* @since COmanage Registry v5.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

declare(strict_types = 1);

namespace App\Model\Entity;

use Cake\ORM\Entity;

// Strictly speaking, this should probably be "Pronouns", but it's easier not to fight inflection
class Pronoun extends Entity {
use \App\Lib\Traits\ReadOnlyEntityTrait;
use \App\Lib\Traits\MVETrait;

protected $_accessible = [
'*' => true,
'id' => false,
'slug' => false,
];
}
14 changes: 14 additions & 0 deletions app/src/Model/Table/CoSettingsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public function initialize(array $config): void {
->setClassName('Types')
->setForeignKey('default_name_type_id')
->setProperty('default_name_type');
$this->belongsTo('DefaultPronounTypes')
->setClassName('Types')
->setForeignKey('default_pronoun_type_id')
->setProperty('default_pronoun_type');
$this->belongsTo('DefaultTelephoneNumberTypes')
->setClassName('Types')
->setForeignKey('default_telephone_number_type_id')
Expand Down Expand Up @@ -124,6 +128,10 @@ public function initialize(array $config): void {
'type' => 'type',
'attribute' => 'Names.type'
],
'defaultPronounTypes' => [
'type' => 'type',
'attribute' => 'Pronouns.type'
],
'defaultTelephoneNumberTypes' => [
'type' => 'type',
'attribute' => 'TelephoneNumbers.type'
Expand Down Expand Up @@ -185,6 +193,7 @@ public function addDefaults(int $coId): int {
'default_email_address_type_id' => null,
'default_identifier_type_id' => null,
'default_name_type_id' => null,
'default_pronoun_type_id' => null,
'default_telephone_number_type_id' => null,
'default_url_type_id' => null,
'permitted_fields_name' => PermittedNameFieldsEnum::HGMFS,
Expand Down Expand Up @@ -294,6 +303,11 @@ public function validationDefault(Validator $validator): Validator {
]);
$validator->allowEmptyString('default_name_type_id');

$validator->add('default_pronoun_type_id', [
'content' => ['rule' => 'isInteger']
]);
$validator->allowEmptyString('default_pronoun_type_id');

$validator->add('default_telephone_number_type_id', [
'content' => ['rule' => 'isInteger']
]);
Expand Down
2 changes: 2 additions & 0 deletions app/src/Model/Table/ExternalIdentitiesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public function initialize(array $config): void {
->setDependent(true);
$this->hasMany('Identifiers')
->setDependent(true);
$this->hasMany('Pronouns')
->setDependent(true);
$this->hasMany('TelephoneNumbers')
->setDependent(true);
$this->hasMany('Urls')
Expand Down
2 changes: 2 additions & 0 deletions app/src/Model/Table/PeopleTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public function initialize(array $config): void {
->setDependent(true);
$this->hasMany('PersonRoles')
->setDependent(true);
$this->hasMany('Pronouns')
->setDependent(true);
$this->hasMany('TelephoneNumbers')
->setDependent(true);
$this->hasMany('Urls')
Expand Down
Loading

0 comments on commit 79d29b7

Please sign in to comment.