Skip to content

Commit

Permalink
HistoricPetitionViewer and Transmogrification adjucstments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Nov 19, 2025
1 parent b5a4505 commit de5f836
Show file tree
Hide file tree
Showing 15 changed files with 432 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ public function bootstrap(PluginApplicationInterface $app): void
public function routes(RouteBuilder $routes): void
{
$routes->plugin(
'HistoryPetitionViewer',
'HistoricPetitionViewer',
['path' => '/historic-petition-viewer'],
function (RouteBuilder $builder) {
// Add custom routes here
// Your snippet goes here, using $builder instead of $routes
$builder->setRouteClass(DashedRoute::class);

$builder->fallbacks();
// Add your plugin routes here if needed, then:
$builder->fallbacks(DashedRoute::class);
}
);
parent::routes($routes);
Expand Down
25 changes: 17 additions & 8 deletions app/plugins/HistoricPetitionViewer/config/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@
"columns": {
"id": { "type": "integer", "autoincrement": true, "primarykey": true },
"petition_id": { "type": "integer", "foreignkey": { "table": "petitions", "column": "id" } },
"historic_petition_viewer_id": {
"type": "integer",
"foreignkey": { "table": "historic_petition_viewers", "column": "id" },
"notnull": false
},

"attribute": { "type": "string", "size": 128 },
"value": { "type": "text" },
"created": { "type": "datetime" },
"modified": { "type": "datetime" },
"historic_petition_attribute_id": { "type": "integer", "foreignkey": { "table": "petition_hist_attrs", "column": "id" } },
"petition_hist_attr_id": { "type": "integer", "foreignkey": { "table": "petition_hist_attrs", "column": "id" } },
"revision": { "type": "integer" },
"deleted": { "type": "boolean" },
"actor_identifier": { "type": "string", "size": 256 }
},
"indexes": {
"petition_hist_attrs_i1": { "columns": [ "petition_id" ] },
"petition_hist_attrs_i2": { "columns": [ "attribute" ] },
"petition_hist_attrs_i3": { "columns": [ "historic_petition_attribute_id" ] }
"petition_hist_attrs_i3": { "columns": [ "petition_hist_attr_id" ] }
},
"timestamps": false,
"changelog": false
Expand All @@ -32,6 +38,12 @@
"columns": {
"id": { "type": "integer", "autoincrement": true, "primarykey": true },
"petition_id": { "type": "integer", "foreignkey": { "table": "petitions", "column": "id" } },
"enrollment_flow_id": { "type": "integer", "foreignkey": { "table": "enrollment_flows", "column": "id" }},
"historic_petition_viewer_id": {
"type": "integer",
"foreignkey": { "table": "historic_petition_viewers", "column": "id" },
"notnull": false
},

"enrollee_org_identity_id": { "type": "integer" },
"archived_org_identity_id": { "type": "integer" },
Expand Down Expand Up @@ -60,17 +72,14 @@
"timestamps": false,
"changelog": false
},
"historic_petition_step_links": {
"comment": "Associates a Petition’s historic data to a specific Enrollment Flow Step for read-only viewing",
"historic_petition_viewers": {
"comment": "Enrollment Flow Step for historic petition data",
"columns": {
"id": { "type": "integer", "autoincrement": true, "primarykey": true },
"petition_id": { "type": "integer", "foreignkey": { "table": "petitions", "column": "id" } },
"enrollment_flow_step_id": { "type": "integer", "foreignkey": { "table": "enrollment_flow_steps", "column": "id" } }
},
"indexes": {
"historic_petition_step_links_i1": { "columns": [ "petition_id" ] },
"historic_petition_step_links_i2": { "columns": [ "enrollment_flow_step_id" ] },
"historic_petition_step_links_u1": { "columns": [ "petition_id", "enrollment_flow_step_id" ] }
"historic_petition_step_links_i1": { "columns": [ "enrollment_flow_step_id" ] }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* COmanage Registry Historic Petition Viewers 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-plugins
* @since COmanage Registry v5.2.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

declare(strict_types=1);

namespace HistoricPetitionViewer\Controller;

use App\Controller\StandardPluginController;

class HistoricPetitionViewersController extends StandardPluginController {
protected array $paginate = [
'order' => [
'HistoricPetitionViewers.id' => 'asc'
]
];
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Historic Petition Step Link plugin Entity.
* Historic Petition Viewer plugin Entity.
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
Expand Down Expand Up @@ -31,7 +31,7 @@

use Cake\ORM\Entity;

class HistoricPetitionStepLink extends Entity
class HistoricPetitionViewer extends Entity
{
use \App\Lib\Traits\EntityMetaTrait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ class HistoricPetitionAttributesTable extends Table {
use \App\Lib\Traits\TableMetaTrait;
use \App\Lib\Traits\TabTrait;
use \App\Lib\Traits\ValidationTrait;
use \App\Lib\Traits\CoLinkTrait;


public function initialize(array $config): void {
parent::initialize($config);

// Map model to shorter physical table name
$this->setTable('petition_hist_attrs');
$this->setPrimaryKey('id');
$this->setDisplayField('id');

$this->addBehavior('Changelog');
$this->addBehavior('Log');
Expand All @@ -56,12 +60,13 @@ public function initialize(array $config): void {

// Define associations
$this->belongsTo('Petitions');
$this->belongsTo('HistoricPetitionViewers');

$this->setDisplayField('attribute');

$this->setPrimaryLink('petition_id');
$this->setRequiresCO(false);
// $this->setAllowLookupPrimaryLink(['dispatch', 'display']);
$this->setAllowLookupPrimaryLink(['display']);

$this->setPermissions([
// Actions that operate over an entity (ie: require an $id)
Expand Down Expand Up @@ -106,11 +111,11 @@ public function validationDefault(Validator $validator): Validator {
// value (text, optional)
$validator->allowEmptyString('value');

// historic_petition_attribute_id (self-referential changelog FK, optional)
$validator->add('historic_petition_attribute_id', [
// petition_hist_attr_id (self-referential changelog FK, optional)
$validator->add('petition_hist_attr_id', [
'content' => ['rule' => 'isInteger']
]);
$validator->allowEmptyString('historic_petition_attribute_id');
$validator->allowEmptyString('petition_hist_attr_id');

// revision (optional integer)
$validator->add('revision', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Cake\Validation\Validator;

class HistoricPetitionMetadataRecordsTable extends Table {
use \App\Lib\Traits\CoLinkTrait;
use \App\Lib\Traits\LabeledLogTrait;
use \App\Lib\Traits\LayoutTrait;
use \App\Lib\Traits\PermissionsTrait;
Expand All @@ -47,6 +48,8 @@ public function initialize(array $config): void {

// Map model to shorter physical table name
$this->setTable('petition_meta_hist_recs');
$this->setPrimaryKey('id');
$this->setDisplayField('id');

$this->addBehavior('Changelog');
$this->addBehavior('Log');
Expand All @@ -56,11 +59,13 @@ public function initialize(array $config): void {

// Define associations
$this->belongsTo('Petitions');
$this->belongsTo('HistoricPetitionViewers');
$this->belongsTo('EnrollmentFlows');

$this->setDisplayField('petition_id');

$this->setRequiresCO(false);
$this->setAllowLookupPrimaryLink(['dispatch', 'display']);
$this->setAllowLookupPrimaryLink(['display']);

$this->setPermissions([
// Actions that operate over an entity (ie: require an $id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
use Cake\ORM\Table;
use Cake\Validation\Validator;

class HistoricPetitionStepLinksTable extends Table {
class HistoricPetitionViewersTable extends Table {
use \App\Lib\Traits\CoLinkTrait;
use \App\Lib\Traits\LabeledLogTrait;
use \App\Lib\Traits\LayoutTrait;
use \App\Lib\Traits\PermissionsTrait;
Expand All @@ -59,20 +60,20 @@ public function initialize(array $config): void {

$this->setPrimaryLink('enrollment_flow_step_id');
$this->setRequiresCO(false);
$this->setAllowLookupPrimaryLink(['dispatch', 'display']);
$this->setAllowLookupPrimaryLink(['display']);

// All the tabs share the same configuration in the ModelTable file
$this->setTabsConfig(
[
// Ordered list of Tabs
'tabs' => ['EnrollmentFlowSteps', 'HistoricPetitionViewer.HistoricPetitionStepLinks'],
'tabs' => ['EnrollmentFlowSteps', 'HistoricPetitionViewer.HistoricPetitionViewers'],
// What actions will include the subnavigation header
'action' => [
// If a model renders in a subnavigation mode in edit/view mode, it cannot
// render in index mode for the same use case/context
// XXX edit should go first.
'EnrollmentFlowSteps' => ['view'],
'HistoricPetitionViewer.HistoricPetitionStepLinks' => ['view']
'HistoricPetitionViewer.HistoricPetitionViewers' => ['view']
]
]
);
Expand All @@ -83,7 +84,7 @@ public function initialize(array $config): void {
'delete' => false,
'dispatch' => false,
'display' => true,
'edit' => false,
'edit' => true,
'view' => ['platformAdmin', 'coAdmin']
],
// Actions that operate over a table (ie: do not require an $id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,11 @@

declare(strict_types=1);

namespace CoreEnroller\View\Cell;
namespace HistoricPetitionViewer\View\Cell;

use Cake\View\Cell;

/**
* BasicAttributeCollectors cell
*/
class HistoricPetitionStepLinksCell extends Cell
class HistoricPetitionViewersCell extends Cell
{
/**
* @var mixed
Expand Down Expand Up @@ -85,21 +82,38 @@ public function initialize(): void
*/
public function display(int $petitionId): void
{
// Fetch historic metadata rows for this petition (could be zero or more)
$historicMetadataRecords = $this->fetchTable('HistoricPetitionViewer.HistoricPetitionMetadataRecords')
->find()
// Latest (current) metadata record for this petition
$metaTable = $this->fetchTable('HistoricPetitionViewer.HistoricPetitionMetadataRecords');
$latestMeta = $metaTable->find()
->applyOptions(['archived' => false])
->where(['petition_id' => $petitionId])
->orderBy(['id' => 'DESC'])
->limit(1)
->all();

// Fetch historic attributes rows for this petition (could be zero or more)
$historicAttributes = $this->fetchTable('HistoricPetitionViewer.HistoricPetitionAttributes')
->find()
// Current attributes for this petition, deduplicated to latest row per attribute
$attrTable = $this->fetchTable('HistoricPetitionViewer.HistoricPetitionAttributes');

// Subquery: max(id) per attribute for the petition
$sub = $attrTable->find()
->select([
'max_id' => $attrTable->find()->func()->max('id'),
])
->applyOptions(['archived' => false])
->where(['petition_id' => $petitionId])
->group('attribute');

$latestAttrs = $attrTable->find()
->applyOptions(['archived' => false])
->where(function ($exp) use ($sub) {
// id IN (SELECT max(id) ...) for the petition, one per attribute
return $exp->in('HistoricPetitionAttributes.id', $sub);
})
->orderBy(['attribute' => 'ASC', 'id' => 'ASC'])
->all();

$this->set('vv_historic_petition_metadata_records', $historicMetadataRecords);
$this->set('vv_historic_petition_attributes', $historicAttributes);
$this->set('vv_historic_petition_metadata_records', $latestMeta); // array with at most 1 record
$this->set('vv_historic_petition_attributes', $latestAttrs); // deduped by attribute
$this->set('vv_obj', $this->vv_obj);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* COmanage Registry Historic Petition Viewers Fields
*
* 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.2.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

// This view does currently not support read-only
$this->Field->disableFormEditMode();

// There are currently no configurable options for the SSH Key Authenticator
print $this->element('notify/banner', ['info' => __d('information', 'plugin.config.none')]);
Loading

0 comments on commit de5f836

Please sign in to comment.