Skip to content

Refactor fields.inc to be configuration only - first pass. (CFM-218) #342

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ApiSourcesTable extends Table {
use \App\Lib\Traits\PrimaryLinkTrait;
use \App\Lib\Traits\TableMetaTrait;
use \App\Lib\Traits\ValidationTrait;
use \App\Lib\Traits\TabTrait;

/**
* Perform Cake Model initialization.
Expand Down Expand Up @@ -74,6 +75,24 @@ public function initialize(array $config): void {
$this->setPrimaryLink(['external_identity_source_id']);
$this->setRequiresCO(true);

// All the tabs share the same configuration in the ModelTable file
// XXX Reenable when this doesn't throw an error (same error as https://todos.internet2.edu/browse/CFM-475 )
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I attempted to add the subnavigation for API Sources config similar to File Sources, Sql Sources (etc). When this block is included it throws an error similar to what we see in https://todos.internet2.edu/browse/CFM-475

// $this->setTabsConfig(
// [
// // Ordered list of Tabs
// 'tabs' => ['ExternalIdentitySources', 'ApiConnector.ApiSources', 'ExternalIdentitySources@action.search'],
// // 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.
// 'ExternalIdentitySources' => ['edit', 'view', 'search'],
// 'ApiConnector.ApiSources' => ['edit'],
// 'ExternalIdentitySources@action.search' => [],
// ],
// ]
// );

$this->setPermissions([
// Actions that operate over an entity (ie: require an $id)
'entity' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

// This view does currently not support read-only
if($vv_action == 'edit') {
if(!empty($vv_push_endpoint)) {
print $this->element('notify/banner', [
'info' => __d('api_connector', 'information.endpoint.push', [$vv_push_endpoint])
]);
}

print $this->element('form/listItem', [
'arguments' => [
'fieldName' => 'external_identity_source_id',
]
]);
if(!empty($vv_push_endpoint)) {
// XXX https://todos.internet2.edu/browse/CFM-465 send type - this should be 'information' (not a warning)
$banners = [
__d('api_connector', 'information.endpoint.push', [$vv_push_endpoint])
];
}

$fields = [
'external_identity_source_id'
];

This file was deleted.

20 changes: 14 additions & 6 deletions app/availableplugins/ApiConnector/templates/ApiSources/fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,18 @@
*/

// This view does currently not support read-only
Copy link
Contributor Author

@arlen arlen Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were numerous fields.inc files (particularly in plugins) that locked down the fields exclusively to "edit". Where this test existed, I left it in - returning when $vv_action !== 'edit'.

Do we want to keep these or remove them? This looks like:

// This view only supports edit
if($vv_action !== 'edit') {
  return;
}

if($vv_action == 'edit') {
print '<li class="info-title"><h3>' . __d('api_connector', 'field.ApiSources.push_mode') . '</h3></li>';

print $this->element('notify/banner', [
'info' => __d('information', 'plugin.config.none',)
]);
if($vv_action !== 'edit') {
return;
}

// XXX https://todos.internet2.edu/browse/CFM-465 send type - this should be 'information' (not a warning)
$banners = [
__d('information', 'plugin.config.none')
];

// XXX Revisit this - what's the "Push Mode" text attempting to convey here (with no other information)?
$fields = [
'SUBTITLE' => [
'subtitle' => __d('api_connector', 'field.ApiSources.push_mode')
]
];
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

// This view does currently not support read-only
if($vv_action == 'add' || $vv_action == 'edit') {
print $this->element('form/listItem', [
'arguments' => [
'fieldName' => 'filename',
]
]);
}
$fields = [
'filename'
];
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,10 @@
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

// This view does currently not support read-only
if($vv_action == 'add' || $vv_action == 'edit') {
foreach([
'filename',
'format',
'archivedir',
'threshold_check',
'threshold_override',
] as $field) {
print $this->element('form/listItem', [
'arguments' => [
'fieldName' => $field,
]
]);
}
}
$fields = [
'filename',
'format',
'archivedir',
'threshold_check',
'threshold_override',
];
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,20 @@
* @since COmanage Registry v5.2.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

$fields = [
'source_mode',
'min_length',
'max_length',
'format_crypt_php',
'format_sha1_ldap',
'format_plaintext'
];

?>
<script type="text/javascript">

<script>
// JS specific to these fields

function updateGadgets(isPageLoad) {
// Hide or show gadgets according to current state
var source = document.getElementById('source-mode').value;
Expand All @@ -49,51 +59,14 @@
}
}

function jsLocalOnLoad() {
$(function() {
// run on first load
updateGadgets(true);
}
</script>

<?php
// This view does currently not support read-only, and add is not used
if($vv_action == 'edit') {
print $this->element('form/listItem', [
'arguments' => [
'fieldName' => 'source_mode',
'fieldOptions' => [
'onChange' => 'updateGadgets(false)'
]
]
]);

foreach(['min_length',
'max_length'
] as $field) {
print $this->element('form/listItem', [
'arguments' => [
'fieldName' => $field,
]
]);
}

print $this->element('form/listItem', [
'arguments' => [
'fieldName' => 'format_crypt_php',
'fieldOptions' => [
// When source is Self Select we want crypt to remain checked
// (though this will also be enforced in the backend)
'onChange' => 'updateGadgets(false)'
]
]
]);

foreach(['format_sha1_ldap',
'format_plaintext'
] as $field) {
print $this->element('form/listItem', [
'arguments' => [
'fieldName' => $field,
]
]);
}
}
// register onchange events
// note that underscores in field names above must be represented with hyphens here.
$('#source-mode, #format_crypt_php').change(function() {
updateGadgets();
});
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,20 @@
// We provide the current password status in a banner message since that's all the
// information we really want to display about a password.

print $this->element('notify/banner', ['info' => $vv_status->comment]);
// XXX https://todos.internet2.edu/browse/CFM-465 send type - this should be 'information' (not a warning)
$banners = [
$vv_status->comment
];

if(!$vv_status->locked) {
print $this->element('form/listItem', [
'arguments' => [
'fieldName' => 'password',
]
]);
$fields = [];

print $this->element('form/listItem', [
'arguments' => [
'fieldName' => 'password2',
if(!$vv_status->locked) {
$fields = [
'password',
'password2' => [
'fieldOptions' => [
'type' => 'password'
]
]
]);
}
];
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,18 @@

// There are currently no directly configurable fields for this model.)
$suppress_submit = true;
?>

// Top Links
$topLinks[] = [
'icon' => 'transform',
'order' => 'Default',
'label' => __d('pipeline_toolkit', 'controller.LoginIdentifierTypes', [99]),
'link' => [
'plugin' => 'PipelineToolkit',
'controller' => 'LoginIdentifierTypes',
'action' => 'index',
'identifier_mapper_id' => $vv_obj->id
],
'class' => ''
];
?>
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,7 @@
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

// This view does not support read-only
if($vv_action == 'add' || $vv_action == 'edit') {
foreach (['type_id',
'login'
] as $field) {
print $this->element('form/listItem', [
'arguments' => [
'fieldName' => $field
]]);
}
}
$fields = [
'type_id',
'login'
];
Loading