Skip to content

Commit

Permalink
Initial commit of Types (CFM-56)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Oct 26, 2021
1 parent be224b8 commit 0be7115
Show file tree
Hide file tree
Showing 18 changed files with 953 additions and 24 deletions.
11 changes: 6 additions & 5 deletions app/config/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,16 @@
"columns": {
"id": {},
"co_id": {},
"attribute": { "type": "string", "size": 32 },
"name": { "type": "string", "size": 32 },
"display_name": { "type": "string", "size": 64 },
"attribute": { "type": "string", "size": 32, "notnull": true },
"display_name": { "type": "string", "size": 64, "notnull": true },
"value": { "type": "string", "size": 32, "notnull": true },
"edupersonaffiliation": { "type": "string", "size": 32 },
"status": {}
},
"indexes": {
"types_i1": { "columns": [ "co_id", "attribute" ] },
"types_i2": { "columns": [ "co_id", "attribute", "name" ] }
"types_i1": { "columns": [ "co_id" ] },
"types_i2": { "columns": [ "co_id", "attribute" ] },
"types_i3": { "columns": [ "co_id", "attribute", "value" ] }
}
},

Expand Down
64 changes: 64 additions & 0 deletions app/resources/locales/en_US/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,40 @@ msgstr "{0,plural,=1{External Identity} other{External Identities}}"
msgid "registry.ct.People"
msgstr "{0,plural,=1{Person} other{People}}"

msgid "registry.ct.Types"
msgstr "{0,plural,=1{Type} other{Types}}"

### Enumerations
msgid "registry.en.BooleanEnum.0"
msgstr "False"

msgid "registry.en.BooleanEnum.1"
msgstr "True"

msgid "registry.en.EduPersonAffiliationEnum.affiliate"
msgstr "Affiliate"

msgid "registry.en.EduPersonAffiliationEnum.alum"
msgstr "Alum"

msgid "registry.en.EduPersonAffiliationEnum.employee"
msgstr "Employee"

msgid "registry.en.EduPersonAffiliationEnum.faculty"
msgstr "Faculty"

msgid "registry.en.EduPersonAffiliationEnum.librarywalkin"
msgstr "Library Walk-In"

msgid "registry.en.EduPersonAffiliationEnum.member"
msgstr "Member"

msgid "registry.en.EduPersonAffiliationEnum.staff"
msgstr "Staff"

msgid "registry.en.EduPersonAffiliationEnum.student"
msgstr "Student"

msgid "registry.en.SetBooleanEnum.0"
msgstr "Not Set"

Expand Down Expand Up @@ -244,6 +271,9 @@ msgstr "When this value is selected, {0} cannot be empty"
msgid "registry.er.input.invalid"
msgstr "Invalid character found"

msgid "registry.er.invalid"
msgstr "Invalid value \"{0}\""

msgid "registry.er.notfound"
msgstr "{0} not found"

Expand Down Expand Up @@ -271,6 +301,12 @@ msgstr "No type defined for table {0} column {1}"
msgid "registry.er.schema.parse"
msgstr "Failed to parse file {0}"

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

msgid "registry.er.unknown"
msgstr "Unknown value \"{0}\""

### Fields
### Keys of the form registry.fd.MyModels.field_name[.desc] will apply only to MyModels.field_name
### Keys of the form registry.fd.field_name[.desc] will apply if no model specific key is found
Expand All @@ -280,12 +316,25 @@ msgstr "Action"
msgid "registry.fd.api_key"
msgstr "API Key"

msgid "registry.fd.attribute"
msgstr "Attribute"

msgid "registry.fd.date_of_birth"
msgstr "Date of Birth"

msgid "registry.fd.description"
msgstr "Description"

msgid "registry.fd.display_name"
msgstr "Display Name"

msgid "registry.fd.edupersonaffiliation"
msgstr "eduPersonAffiliation"

msgid "registry.fd.Types.edupersonaffiliation.desc"
# XXX update link to PE wiki?
msgstr "Map the extended affiliation to this eduPersonAffiliation, see <a href="https://spaces.at.internet2.edu/display/COmanage/Extending+the+Registry+Data+Model#ExtendingtheRegistryDataModel-%7B%7BeduPersonAffiliation%7D%7DandExtendedAffiliations">eduPersonAffiliation and Extended Affiliations</a>"

msgid "registry.fd.family"
msgstr "Family Name"

Expand Down Expand Up @@ -316,6 +365,9 @@ msgstr "Required"
msgid "registry.fd.status"
msgstr "Status"

msgid "registry.fd.Type.status"
msgstr "Suspending a Type will prevent it from being assigned to new attributes, but will not remove it from existing attributes"

msgid "registry.fd.username"
msgstr "Username"

Expand All @@ -340,6 +392,15 @@ msgstr "Leave blank for indefinite validity"
msgid "registry.fd.valid_through.tz"
msgstr "Valid Through ({0})"

msgid "registry.fd.value"
msgstr "Value"

msgid "registry.fd.Types.value"
msgstr "Database Value"

msgid "registry.fd.Types.value.desc"
msgstr "Database value for this type, characters must be alphanumeric, dot, or dash"

msgid "registry.home.collab"
msgstr "Available Collaborations"

Expand Down Expand Up @@ -421,6 +482,9 @@ msgstr "Go To Page"
msgid "registry.op.previous"
msgstr "Previous"

msgid "registry.op.Types.restore"
msgstr "Add/Restore Default Types"

msgid "registry.op.save"
msgstr "Save"

Expand Down
40 changes: 40 additions & 0 deletions app/resources/locales/en_US/defaultType.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# COmanage Registry Localizations (defaultType domain)
#
# 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)

# Labels for default types when a new CO is created

msgid "Names.alternate"
msgstr "Alternate"

msgid "Names.author"
msgstr "Author"

msgid "Names.fka"
msgstr "Formerly Known As"

msgid "Names.official"
msgstr "Official"

msgid "Names.preferred"
msgstr "Preferred"
29 changes: 25 additions & 4 deletions app/src/Command/TransmogrifyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ class TransmogrifyCommand extends Command {
'source' => 'cm_co_extended_types',
'displayField' => 'display_name',
'fieldMap' => [
'attribute' => '&map_extended_type',
'name' => 'value',
// For some reason, cm_co_extended_types never had created/modified metadata
'created' => '&map_now',
'modified' => '&map_now'
],
'cache' => [ [ 'co_id', 'attribute', 'name' ] ]
'cache' => [ [ 'co_id', 'attribute', 'value' ] ]
],
'api_users' => [
'source' => 'cm_api_users',
Expand Down Expand Up @@ -162,7 +164,7 @@ protected function cacheResults(string $table, array $row) {
$key = "";

foreach($field as $subfield) {
// eg: co_id+attribute+name+
// eg: co_id+attribute+value+
$label .= $subfield . "+";

// eg: 2+Identifier.type+eppn+
Expand Down Expand Up @@ -422,6 +424,25 @@ protected function mapFields(string $table, array &$row) {
}
}

/**
* Map an Extended Type attribute name for model name changes.
*
* @since COmanage Registry v5.0.0
* @param array $row Row of table data
* @return string Updated attribute name
*/

protected function map_extended_type(array $row) {
switch($row['attribute']) {
case 'CoDepartment.type':
return 'Department.type';
case 'CoPersonRole.affiliation':
return 'PersonRole.affiliation';
}

return $row['attribute'];
}

/**
* Map an identifier type string to a foreign key.
*
Expand Down Expand Up @@ -535,10 +556,10 @@ protected function map_type(array $row, string $type, $coId) {

$key = $coId . "+" . $type . "+" . $row['type'] . "+";

if(empty($this->cache['types']['co_id+attribute+name+'][$key])) {
if(empty($this->cache['types']['co_id+attribute+value+'][$key])) {
throw new \InvalidArgumentException("Type not found for " . $key);
}

return $this->cache['types']['co_id+attribute+name+'][$key];
return $this->cache['types']['co_id+attribute+value+'][$key];
}
}
5 changes: 5 additions & 0 deletions app/src/Controller/DashboardsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public function configuration() {
'icon' => 'people_outline',
'controller' => 'cous',
'action' => 'index'
],
__('registry.ct.Types', [99]) => [
'icon' => 'widgets',
'controller' => 'types',
'action' => 'index'
]
];

Expand Down
26 changes: 18 additions & 8 deletions app/src/Controller/StandardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function add() {
if($table->save($obj)) {
$this->Flash->success(__('registry.rs.saved'));

return $this->generateRedirect($obj->id);
return $this->generateRedirect(null);
}

$errors = $obj->getErrors();
Expand Down Expand Up @@ -256,7 +256,11 @@ public function delete($id) {
}

// Return to index since there is no delete view
return $this->generateRedirect();
return $this->generateRedirect(null);
}
catch(\Cake\ORM\Exception\PersistenceFailedException $e) {
// deleteOrFail throws Cake\ORM\Exception\PersistenceFailedException
$this->Flash->error($e->getMessage());
}
catch(\Exception $e) {
// findById throws Cake\Datasource\Exception\RecordNotFoundException
Expand All @@ -276,10 +280,10 @@ public function delete($id) {
} else {
$this->Flash->error($e->getMessage());
}

// The record is still valid, so redirect back to it
return $this->redirect(['action' => 'edit', $id]);
}

// The record is still valid, so redirect back to it
return $this->redirect(['action' => 'edit', $id]);
}

/**
Expand Down Expand Up @@ -340,7 +344,7 @@ public function edit($id) {
if($table->save($obj)) {
$this->Flash->success(__('registry.rs.saved'));

return $this->generateRedirect();
return $this->generateRedirect($obj->id);
}

$errors = $obj->getErrors();
Expand All @@ -358,7 +362,7 @@ public function edit($id) {
// findById throws Cake\Datasource\Exception\RecordNotFoundException

$this->Flash->error($e->getMessage());
return $this->generateRedirect();
return $this->generateRedirect(null);
}

$this->set('vv_obj', $obj);
Expand Down Expand Up @@ -395,7 +399,7 @@ public function edit($id) {
public function generateRedirect(?int $id) {
$redirect = [];

if($this->request->getParam('action') == 'add' && $id) {
if(in_array($this->request->getParam('action'), ['add', 'edit']) && $id) {
// Redirect to the edit view of the record just added
// (if the user has add permission, they probably have edit permission)

Expand Down Expand Up @@ -515,6 +519,12 @@ protected function populateAutoViewVars(object $obj=null) {
&& $table->getAutoViewVars()) {
foreach($table->getAutoViewVars() as $vvar => $avv) {
switch($avv['type']) {
case 'array':
// Use the provided array of values. By default, we use the values
// for the keys as well, to generate HTML along the lines of
// <option value="Foo">"Foo"</option>
$this->set($vvar, array_combine($avv['array'], $avv['array']));
break;
case 'enum':
// We just want the localized text strings for the defined constants
$class = '\\App\\Lib\\Enum\\'.$avv['class'];
Expand Down
Loading

0 comments on commit 0be7115

Please sign in to comment.