Skip to content

Commit

Permalink
Initial implementation of HistoryRecords (CFM-76)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Feb 3, 2022
1 parent 347e2cb commit 9d68e80
Show file tree
Hide file tree
Showing 27 changed files with 839 additions and 54 deletions.
18 changes: 18 additions & 0 deletions app/config/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,24 @@
},
"mvea": [ "person", "external_identity" ],
"sourced": true
},

"history_records": {
"comment": "XXX not all foreign keys are defined yet",

"columns": {
"id": {},
"action": { "type": "string", "size": 4 },
"comment": { "type": "string", "size": 256 },
"person_id": {},
"external_identity_id": {},
"actor_person_id": { "type": "integer", "foreignkey": { "table": "people", "column": "id" } }
},
"indexes": {
"history_records_i1": { "columns": [ "person_id" ] },
"history_records_i2": { "columns": [ "external_identity_id" ] },
"history_records_i3": { "columns": [ "actor_person_id" ] }
}
}
},

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 @@ -45,6 +45,9 @@ msgstr "{0,plural,=1{Email Address} other{Email Addresses}}"
msgid "ExternalIdentities"
msgstr "{0,plural,=1{External Identity} other{External Identities}}"

msgid "HistoryRecords"
msgstr "{0,plural,=1{History Record} other{History Records}}"

msgid "Identifiers"
msgstr "{0,plural,=1{Identifier} other{Identifiers}}"

Expand Down
12 changes: 12 additions & 0 deletions app/resources/locales/en_US/field.po
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@
msgid "action"
msgstr "Action"

msgid "actor"
msgstr "Actor"

msgid "api_key"
msgstr "API Key"

msgid "attribute"
msgstr "Attribute"

msgid "comment"
msgstr "Comment"

msgid "CoSettings.address_required_fields"
msgstr "Address Required Fields"

Expand All @@ -53,6 +59,9 @@ msgstr "Name Permitted Fields"
msgid "CoSettings.name_required_fields"
msgstr "Name Required Fields"

msgid "created"
msgstr "Created"

msgid "date_of_birth"
msgstr "Date of Birth"

Expand All @@ -65,6 +74,9 @@ msgstr "Display Name"
msgid "edupersonaffiliation"
msgstr "eduPersonAffiliation"

msgid "id"
msgstr "ID"

msgid "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>"
Expand Down
2 changes: 1 addition & 1 deletion app/resources/locales/en_US/operation.po
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Operations (Commands)

msgid "add.a"
msgstr "Add New {0}"
msgstr "Add a New {0}"

msgid "api.key.generate"
msgstr "Generate API Key"
Expand Down
9 changes: 9 additions & 0 deletions app/resources/locales/en_US/result.po
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,21 @@

# Results

msgid "added.mvea"
msgstr "{0} {1} Added: {2}"

msgid "deleted"
msgstr "Deleted"

msgid "deleted.a"
msgstr "{0} Deleted"

msgid "deleted.mvea"
msgstr "{0} {1} Deleted: {2}"

msgid "edited.mvea"
msgstr "{0} {1} Edited: {2}"

msgid "saved"
msgstr "Saved"

Expand Down
14 changes: 14 additions & 0 deletions app/src/Command/TransmogrifyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,20 @@ class TransmogrifyCommand extends Command {
'co_department_id' => null,
'organization_id' => null
]
],
'history_records' => [
'source' => 'cm_history_records',
'displayField' => 'id',
'fieldMap' => [
'co_person_id' => 'person_id',
'org_identity_id' => 'external_identity_id',
'actor_co_person_id' => 'actor_person_id',
// XXX temporary until tables are migrated
'co_person_role_id' => null,
'co_group_id' => null,
'co_email_list_id' => null,
'co_service_id' => null
]
]
];

Expand Down
2 changes: 1 addition & 1 deletion app/src/Controller/ApiV2Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public function index() {

// We automatically allow API calls to be filtered on primary link
if(!empty($link->attr) && !empty($link->value)) {
$query = $query->where([$link->attr => $link->value]);
$query = $query->where([$table->getAlias().'.'.$link->attr => $link->value]);
}

// This magically makes REST calls paginated... can use eg direction=,
Expand Down
42 changes: 42 additions & 0 deletions app/src/Controller/HistoryRecordsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* COmanage Registry History Records 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 HistoryRecordsController extends MVEAController {
public $pagination = [
'order' => [
'HistoryRecords.id' => 'desc'
]
];
}
29 changes: 17 additions & 12 deletions app/src/Controller/StandardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public function index() {
if(!empty($link->attr)) {
// If a link attribute is defined but no value is provided, then query
// where the link attribute is NULL
$query = $table->find()->where([$link->attr => $link->value]);
$query = $table->find()->where([$table->getAlias().'.'.$link->attr => $link->value]);
} else {
$query = $table->find();
}
Expand Down Expand Up @@ -523,7 +523,7 @@ protected function populateAutoViewVars(object $obj=null) {
// to PrimaryLinkTrait and call it there?
if($v) {
$query = $query->where([$linkFilter => $v]);
$query = $query->where([$table->getAlias().'.'.$linkFilter => $v]);
}
}
} else {
Expand Down Expand Up @@ -567,11 +567,10 @@ public function view($id = null) {
// query modifications via traits
$query = $table->findById($id);

// AssociationTrait
/*
// QueryModificationTrait
if(method_exists($table, "getViewContains")) {
$query = $query->contain($table->getViewContains());
}*/
}

try {
// Pull the current record
Expand All @@ -581,7 +580,7 @@ public function view($id = null) {
// findById throws Cake\Datasource\Exception\RecordNotFoundException

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

$this->set('vv_obj', $obj);
Expand All @@ -593,13 +592,19 @@ public function view($id = null) {
// We still used this in view() to map select values
$this->populateAutoViewVars($obj);

// Default view title is view object display field
$field = $table->getDisplayField();

if(!empty($obj->$field)) {
$this->set('vv_title', __d('operation', 'view.ai', $obj->$field, $id));
if(method_exists($table, 'generateDisplayField')) {
// We don't use a trait for this since each table will implement different logic

$this->set('vv_title', __d('operation', 'view.ai', $table->generateDisplayField($obj), $id));
} else {
$this->set('vv_title', __d('operation', 'view.ai', __d('controller', $modelsName, [1]), $id));
// Default view title is the object display field
$field = $table->getDisplayField();

if(!empty($obj->$field)) {
$this->set('vv_title', __d('operation', 'view.ai', $obj->$field, $id));
} else {
$this->set('vv_title', __d('operation', 'view.ai', __d('controller', $modelsName, [1]), $id));
}
}

// Let the view render
Expand Down
40 changes: 40 additions & 0 deletions app/src/Lib/Enum/ActionEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* COmanage Registry Action Enum
*
* 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\Lib\Enum;

class ActionEnum extends StandardEnum {
// Codes beginning with 'X' (eg: 'XABC') are reserved for local use
// Codes beginning with a lowercase 'p' (eg: 'pABC') are reserved for plugin use
const CommentAdded = 'CMNT';
const MVEAAdded = 'AMVE';
const MVEADeleted = 'DMVE';
const MVEAEdited = 'EMVE';
const NamePrimary = 'PNAM';
}
Loading

0 comments on commit 9d68e80

Please sign in to comment.