Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CO-2667_Allow_Normalization_Plugins_to_run_instead_of_DefaultNormalizer #516

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
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
33 changes: 31 additions & 2 deletions app/Config/Schema/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2696,7 +2696,37 @@
<field name="created" type="T" />
<field name="modified" type="T" />
</table>


<table name="co_normalizers">
<field name="id" type="I">
<key />
<autoincrement />
</field>
<field name="co_id" type="I">
<notnull />
<constraint>REFERENCES cm_cos(id)</constraint>
</field>
<field name="description" type="C" size="256" />
<field name="ordr" type="I" />
<field name="plugin" type="C" size="32" />
<field name="status" type="C" size="2" />
<field name="created" type="T" />
<field name="modified" type="T" />
<field name="co_normalizer_id" type="I">
<constraint>REFERENCES cm_normalizers(id)</constraint>
</field>
<field name="revision" type="I" />
<field name="deleted" type="L" />
<field name="actor_identifier" type="C" size="256" />

<index name="co_normalizers_i1">
<col>co_id</col>
</index>
<index name="co_normalizers_i2">
<col>co_normalizer_id</col>
</index>
</table>

<table name="co_terms_and_conditions">
<field name="id" type="I">
<key />
Expand Down Expand Up @@ -3093,7 +3123,6 @@
<field name="group_create_admin_only" type="L" />
<field name="group_validity_sync_window" type="I" />
<field name="garbage_collection_interval" type="I" />
<field name="enable_normalization" type="L" />
<field name="enable_empty_cou" type="L" />
<field name="invitation_validity" type="I" />
<field name="permitted_fields_name" type="C" size="160" />
Expand Down
3 changes: 3 additions & 0 deletions app/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,9 @@ function menuAuth() {
// Manage CO Links?
$p['menu']['conavigationlinks'] = $roles['cmadmin'] || $roles['coadmin'];

// Manage Normalizers?
$p['menu']['conormalizers'] = $roles['cmadmin'] || $roles['coadmin'];

// Manage CO Permissions?
$p['menu']['copipelines'] = $roles['cmadmin'] || $roles['coadmin'];

Expand Down
204 changes: 204 additions & 0 deletions app/Controller/CoNormalizersController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
<?php
/**
* COmanage Registry Normalizers 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 http://www.internet2.edu/comanage COmanage Project
* @package registry
* @since COmanage Registry v4.3.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

App::uses("StandardController", "Controller");

class CoNormalizersController extends StandardController {
// Class name, used by Cake
public $name = "CoNormalizers";

// Establish pagination parameters for HTML views
public $paginate = array(
'limit' => 25,
'order' => array(
'CoNormalizer.description' => 'asc'
)
);

// This controller needs a CO to be set
public $requires_co = true;

/**
* Callback before other controller methods are invoked or views are rendered.
*
* @since COmanage Registry v4.3.0
* @throws InvalidArgumentException
*/

function beforeFilter() {
parent::beforeFilter();

// Pull the set of validators
$plugins = $this->loadAvailablePlugins('normalizer');

$this->set('vv_plugins', $plugins);

// And track which are instantiated
$iPlugins = array();

foreach(array_keys($plugins) as $p) {
// Walk the list of plugins to see which ones are instantiated,
// then create the association. This will pull associated data for the views.

if($this->$p->cmPluginInstantiate) {
$this->CoNormalizer->bindModel(array('hasOne' => array($p)), false);
$iPlugins[$p] = true;
} else {
$iPlugins[$p] = false;
}
}

$this->set('vv_inst_plugins', $iPlugins);
}

/**
* Perform any dependency checks required prior to a delete operation.
* - postcondition: Session flash message updated (HTML) or HTTP status returned (REST)
*
* @since COmanage Registry v4.3.0
* @param Array Current data
* @return boolean true if dependency checks succeed, false otherwise.
*/

function checkDeleteDependencies($curdata) {
// Based on OrgIdentitySourcesController::checkDeleteDependencies,
// which in turn is basically the same logic as CoProvisioningTargetsController.php

// Annoyingly, the read() call in standardController resets the associations made
// by the bindModel() call in beforeFilter(), above. Beyond that, deep down in
// Cake's Model, a find() is called as part of the delete() which also resets the associations.
// So we have to manually delete any dependencies.

// Use the previously obtained list of plugins as a guide

foreach(array_keys($this->viewVars['vv_inst_plugins']) as $plugin) {
if($this->viewVars['vv_inst_plugins'][$plugin]) {
// Plugin is instantiated
$model = $plugin;

if(!empty($curdata[$model]['id'])) {
// (CO-1988)Remove the plugin object from the instance and enforce the creation of a new one
if(!empty(ClassRegistry::getObject($model))) {
ClassRegistry::removeObject($model);
}
$this->loadModel($plugin . "." . $model);
$this->$model->delete($curdata[$model]['id']);
}
}
}

return true;
}

/**
* Authorization for this Controller, called by Auth component
* - precondition: Session.Auth holds data used for authz decisions
* - postcondition: $permissions set with calculated permissions
*
* @since COmanage Registry v4.3.0
* @return Array Permissions
*/

function isAuthorized() {
$roles = $this->Role->calculateCMRoles();

// Construct the permission set for this user, which will also be passed to the view.
$p = array();

// Determine what operations this user can perform

// Add a new Normalizer?
$p['add'] = ($roles['cmadmin'] || $roles['coadmin']);

// Delete an existing Normalizer?
$p['delete'] = ($roles['cmadmin'] || $roles['coadmin']);

// Edit an existing Normalizer?
$p['edit'] = ($roles['cmadmin'] || $roles['coadmin']);

// View all existing Normalizers?
$p['index'] = ($roles['cmadmin'] || $roles['coadmin']);

// View an existing Normalizer?
$p['view'] = ($roles['cmadmin'] || $roles['coadmin']);

// Reorder an existing Normalizer?
$p['reorder'] = ($roles['cmadmin'] || $roles['coadmin']);
$p['order'] = ($roles['cmadmin'] || $roles['coadmin']);

$this->set('permissions', $p);
return $p[$this->action];
}

/**
* For Models that accept a CO ID, find the provided CO ID.
* - precondition: A coid must be provided in $this->request (params or data)
*
* @since COmanage Registry v4.3.0
* @return Integer The CO ID if found, or -1 if not
*/

public function parseCOID($data = NULL) {
if($this->action == 'order'
|| $this->action == 'reorder') {
if(isset($this->request->params['named']['co'])) {
return $this->request->params['named']['co'];
}
}

return parent::parseCOID();
}

/**
* Perform a redirect back to the controller's default view.
* - postcondition: Redirect generated
*
* @since COmanage Registry v4.3.0
*/

function performRedirect() {
if($this->action == 'add'
&& !empty($this->CoNormalizer->data['CoNormalizer']['plugin'])
&& $this->viewVars['vv_inst_plugins'][ $this->CoNormalizer->data['CoNormalizer']['plugin'] ]) {
// Redirect to the appropriate plugin to set up whatever it wants,
// if it is instantiated

$pluginName = $this->CoNormalizer->data['CoNormalizer']['plugin'];
$modelName = $pluginName;

$target = array();
$target['plugin'] = Inflector::underscore($pluginName);
$target['controller'] = Inflector::tableize($modelName);
$target['action'] = 'edit';
$target[] = $this->CoNormalizer->data[$pluginName]['id'];

$this->redirect($target);
} else {
parent::performRedirect();
}
}
}
74 changes: 74 additions & 0 deletions app/Controller/SNOController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* COmanage Registry Standard Normalizers (SNO) 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 http://www.internet2.edu/comanage COmanage Project
* @package registry
* @since COmanage Registry v4.3.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

App::uses("StandardController", "Controller");

class SNOController extends StandardController {
public $requires_co = true;

/**
* Callback before views are rendered.
*
* @since COmanage Registry v4.3.0
*/

public function beforeRender() {
parent::beforeRender();

// Get a pointer to our model names
$req = $this->modelClass;
$modelpl = Inflector::tableize($req);

// Find the ID of our parent
$noid = -1;

if(!empty($this->params->named['noid'])) {
$noid = filter_var($this->params->named['noid'],FILTER_SANITIZE_SPECIAL_CHARS);
} elseif(!empty($this->viewVars[$modelpl][0][$req])) {
$noid = $this->viewVars[$modelpl][0][$req]['co_normalizer_id'];
}

$this->set('vv_noid', $noid);
}

/**
* Perform a redirect back to the controller's default view.
* - postcondition: Redirect generated
*
* @since COmanage Registry v4.3.0
*/

public function performRedirect() {
$target = array();
$target['plugin'] = null;
$target['controller'] = "co_normalizers";
$target['action'] = 'index';
$target['co'] = $this->cur_co['Co']['id'];

$this->redirect($target);
}
}
5 changes: 4 additions & 1 deletion app/Lib/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@
'ct.cos.pl' => 'COs',
'ct.cous.1' => 'COU',
'ct.cous.pl' => 'COUs',
'ct.co_normalizers.1' => 'Normalizer',
'ct.co_normalizers.pl' => 'Normalizers',
'ct.data_filters.1' => 'Data Filter',
'ct.data_filters.pl' => 'Data Filters',
'ct.dictionaries.1' => 'Dictionary',
Expand Down Expand Up @@ -1757,7 +1759,6 @@
'fd.not.res.subject' => 'Resolution Email Subject',
'fd.not.for' => 'Notifications for %1$s (%2$s, %3$s)',
'fd.not.last' => 'Last Notification',
'fd.nr.enable' => 'Enable Normalizations',
'fd.null' => 'Null',
'fd.o' => 'Organization',
'fd.ois.eppn.suffix' => 'EPPN Suffix',
Expand Down Expand Up @@ -2059,6 +2060,7 @@
'in.idval.plugins' => 'There are no Identifier Validator plugins currently installed.',
'in.inv.exp.resent' => 'The confirmation link you clicked expired. A new link has been sent to your email address.',
'in.login.last' => 'Your last login as %1$s was at %2$s from %3$s',
'in.norm.plugins' => 'There are no Normalizer plugins currently installed.',
'in.co_email_lists.none' => 'No email lists',
'in.co_group.email_lists' => 'Group Email Lists',
'in.co_group.ids.none' => 'No group identifiers',
Expand Down Expand Up @@ -2297,6 +2299,7 @@
// XXX replace these?
'op.order.attr' => 'Reorder Attributes',
'op.order.link' => 'Reorder Links',
'op.order.normalizers' => 'Reorder Normalizers',
'op.orgid.add.ois' => 'Add New Org Identity From Source',
'op.orgid.edit.ois' => 'This Organizational Identity was created from an Organizational Identity Source (%1$s) and therefore cannot be edited.',
'op.orgid.petition.ois' => 'Add New Org Identity From Source and Link To Petition',
Expand Down
Loading