Skip to content

Commit

Permalink
Implement Required (CO-2134) and Crosscheck (CO-1763) on RuleAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Aug 2, 2021
1 parent d772dba commit 1ec6b4d
Show file tree
Hide file tree
Showing 28 changed files with 484 additions and 165 deletions.
9 changes: 7 additions & 2 deletions app/config/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@
"case_sensitive": { "type": "boolean" },
"invalidates": { "type": "boolean" },
"null_equivalents": { "type": "boolean" },
"required": { "type": "boolean" },
"search_distance": { "type": "integer" },
"search_exact": { "type": "boolean" },
"search_substr_from": { "type": "integer" },
Expand Down Expand Up @@ -183,7 +182,9 @@
"id": {},
"rule_id": { "type": "integer", "foreignkey": { "table": "rules", "column": "id" } },
"attribute_id": { "type": "integer", "foreignkey": { "table": "attributes", "column": "id" } },
"search_type": { "type": "string", "size": 2 }
"crosscheck_attribute_id": { "type": "integer", "foreignkey": { "table": "attributes", "column": "id" } },
"search_type": { "type": "string", "size": 2 },
"required": { "type": "boolean" }
},
"indexes": {
"rule_attributes_i1": {
Expand All @@ -192,6 +193,10 @@
"rule_attributes_i2": {
"comment": "We don't really need this index but DBAL will create it anyway, with a random name",
"columns": [ "attribute_id" ]
},
"rule_attributes_i3": {
"comment": "We don't really need this index but DBAL will create it anyway, with a random name",
"columns": [ "crosscheck_attribute_id" ]
}
},
"changelog": false
Expand Down
4 changes: 2 additions & 2 deletions app/src/Controller/ApiUsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link http://www.internet2.edu/comanage COmanage Project
* @link https://www.internet2.edu/comanage COmanage Project
* @package match
* @since COmanage Match v1.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
Expand All @@ -32,7 +32,7 @@
use Cake\Routing\Router;

class ApiUsersController extends StandardController {
public $paginate = [
public $pagination = [
'order' => [
'ApiUsers.username' => 'asc'
]
Expand Down
4 changes: 2 additions & 2 deletions app/src/Controller/AttributeGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link http://www.internet2.edu/comanage COmanage Project
* @link https://www.internet2.edu/comanage COmanage Project
* @package match
* @since COmanage Match v1.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
Expand All @@ -30,7 +30,7 @@
namespace App\Controller;

class AttributeGroupsController extends StandardController {
public $paginate = [
public $pagination = [
'order' => [
'AttributeGroups.name' => 'asc'
]
Expand Down
4 changes: 2 additions & 2 deletions app/src/Controller/AttributeMappingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link http://www.internet2.edu/comanage COmanage Project
* @link https://www.internet2.edu/comanage COmanage Project
* @package match
* @since COmanage Match v1.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
Expand All @@ -30,7 +30,7 @@
namespace App\Controller;

class AttributeMappingsController extends StandardController {
public $paginate = [
public $pagination = [
'order' => [
'AttributeMappings.query' => 'asc',
'AttributeMappings.value' => 'asc'
Expand Down
4 changes: 2 additions & 2 deletions app/src/Controller/AttributeMapsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link http://www.internet2.edu/comanage COmanage Project
* @link https://www.internet2.edu/comanage COmanage Project
* @package match
* @since COmanage Match v1.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
Expand All @@ -30,7 +30,7 @@
namespace App\Controller;

class AttributeMapsController extends StandardController {
public $paginate = [
public $pagination = [
'order' => [
'AttributeMaps.name' => 'asc'
]
Expand Down
4 changes: 2 additions & 2 deletions app/src/Controller/AttributesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link http://www.internet2.edu/comanage COmanage Project
* @link https://www.internet2.edu/comanage COmanage Project
* @package match
* @since COmanage Match v1.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
Expand All @@ -30,7 +30,7 @@
namespace App\Controller;

class AttributesController extends StandardController {
public $paginate = [
public $pagination = [
'order' => [
'Attributes.name' => 'asc'
]
Expand Down
4 changes: 2 additions & 2 deletions app/src/Controller/MatchgridRecordsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link http://www.internet2.edu/comanage COmanage Project
* @link https://www.internet2.edu/comanage COmanage Project
* @package match
* @since COmanage Match v1.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
Expand All @@ -38,7 +38,7 @@
use \App\Lib\Match\MatchService;

class MatchgridRecordsController extends StandardController {
public $paginate = [
public $pagination = [
'order' => [
'sor' => 'asc',
'sorid' => 'asc',
Expand Down
4 changes: 2 additions & 2 deletions app/src/Controller/MatchgridSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link http://www.internet2.edu/comanage COmanage Project
* @link https://www.internet2.edu/comanage COmanage Project
* @package match
* @since COmanage Match v1.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
Expand All @@ -30,7 +30,7 @@
namespace App\Controller;

class MatchgridSettingsController extends StandardController {
public $paginate = [
public $pagination = [
'order' => [
'MatchgridSetting.matchgrid_id' => 'asc'
]
Expand Down
4 changes: 2 additions & 2 deletions app/src/Controller/MatchgridsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link http://www.internet2.edu/comanage COmanage Project
* @link https://www.internet2.edu/comanage COmanage Project
* @package match
* @since COmanage Match v1.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
Expand All @@ -33,7 +33,7 @@
use \App\Lib\Enum\PermissionEnum;

class MatchgridsController extends StandardController {
public $paginate = [
public $pagination = [
'order' => [
'Matchgrids.table_name' => 'asc'
]
Expand Down
9 changes: 7 additions & 2 deletions app/src/Controller/PermissionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link http://www.internet2.edu/comanage COmanage Project
* @link https://www.internet2.edu/comanage COmanage Project
* @package match
* @since COmanage Match v1.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
Expand All @@ -30,10 +30,15 @@
namespace App\Controller;

class PermissionsController extends StandardController {
public $paginate = [
public $pagination = [
'order' => [
'Matchgrids.table_name' => 'asc',
'Permissions.name' => 'asc'
],
// 'sortWhitelist' is renamed 'sortableFields' in Cake 4.1
// 'sortableFields' => [
'sortWhitelist' => [
'Matchgrids.table_name'
]
];

Expand Down
69 changes: 69 additions & 0 deletions app/src/Controller/RuleAttributesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* COmanage Match Rule Attributes Mappings 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 match
* @since COmanage Match v1.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

declare(strict_types = 1);

namespace App\Controller;

class RuleAttributesController extends StandardController {
public $pagination = [
'order' => [
'Attributes.name' => 'asc'
],
// 'sortWhitelist' is renamed 'sortableFields' in Cake 4.1
// 'sortableFields' => [
'sortWhitelist' => [
'Attributes.name'
]
];

/**
* Authorization for this Controller, called by Auth component
* - postcondition: $vv_permissions set with calculated permissions for this Controller
*
* @since COmanage Match v1.0.0
* @param Array $user Array of user data
* @return Boolean True if authorized for the current action, false otherwise
*/

public function isAuthorized(Array $user) {
$platformAdmin = $this->Authorization->isPlatformAdmin($user['username']);

$mgAdmin = $this->Authorization->isMatchAdmin($user['username'], $this->cur_mg->id);

$p = [
'add' => $platformAdmin || $mgAdmin,
'delete' => $platformAdmin || $mgAdmin,
'edit' => $platformAdmin || $mgAdmin,
'index' => $platformAdmin || $mgAdmin,
'view' => false
];

$this->set('vv_permissions', $p);
return $p[$this->request->getParam('action')];
}
}
4 changes: 2 additions & 2 deletions app/src/Controller/RulesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link http://www.internet2.edu/comanage COmanage Project
* @link https://www.internet2.edu/comanage COmanage Project
* @package match
* @since COmanage Match v1.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
Expand All @@ -30,7 +30,7 @@
namespace App\Controller;

class RulesController extends StandardController {
public $paginate = [
public $pagination = [
'order' => [
'Rules.confidence_mode' => 'asc',
'Rules.ordr' => 'asc'
Expand Down
32 changes: 27 additions & 5 deletions app/src/Controller/StandardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
use InvalidArgumentException;

class StandardController extends AppController {
// Pagination defaults should be set in each controller
public $pagination = [];

/**
* Handle an add action for a Standard object.
*
Expand Down Expand Up @@ -223,8 +226,10 @@ public function generateRedirect() {
public function index() {
// $this->name = Models
$modelsName = $this->name;
// $table = the actual table object
$table = $this->$modelsName;
// $tableName = models
$tableName = $this->$modelsName->getTable();
$tableName = $table->getTable();

$query = null;

Expand All @@ -239,10 +244,10 @@ public function index() {
if(!empty($link['linkattr']) && $modelsName != 'MatchgridRecords') {
// If a link attribute is defined but no value is provided, then query
// where the link attribute is NULL
$query = $this->$modelsName->find()->where([$link['linkattr'].' IS' => $this->request->getQuery($link['linkattr'])]);
$query = $table->find()->where([$link['linkattr'].' IS' => $this->request->getQuery($link['linkattr'])]);
} else {
try {
$query = $this->$modelsName->find();
$query = $table->find();
}
catch(\Cake\Database\Exception $e) {
if($modelsName == 'MatchgridRecords' && $e->getCode() == 500) {
Expand All @@ -257,7 +262,17 @@ public function index() {
}
}

$this->set($tableName, $this->Paginator->paginate($query, $this->paginate));
// QueryModificationTrait
if(method_exists($table, "getIndexContains")
&& $table->getIndexContains()) {
$query->contain($table->getIndexContains());
}

// The Cake documents describe $this->paginate (which worked in Cake 2),
// but it doesn't seem to work in Cake 3/4. So we just use $this->pagination
// ourselves here.

$this->set($tableName, $this->Paginator->paginate($query, $this->pagination));
$this->set('vv_tablename', $tableName);
$this->set('vv_modelname', $modelsName);

Expand Down Expand Up @@ -333,9 +348,16 @@ protected function populateAutoViewVars(object $obj=null) {
// XXX also need to check getData()?
if($v) {
$query = $query->find($avv['find'], [$linkFilter => $v]);
$query = $query->where([$linkFilter => $v]);
}
}
} elseif($avv['find'] == 'filterMatchgrid') {
// In many/most cases, filterPrimaryLink is also filterMatchgrid,
// but for indirect models this will force the filter to be on
// the matchgrid instead of the primary link

// For now we only support direct relations to matchgrid
$query->where(['matchgrid_id' => $this->cur_mg->id]);
} else {
// Use the specified finder, if configured
$query = $query->find($avv['find']);
Expand Down
4 changes: 2 additions & 2 deletions app/src/Controller/SystemsOfRecordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link http://www.internet2.edu/comanage COmanage Project
* @link https://www.internet2.edu/comanage COmanage Project
* @package match
* @since COmanage Match v1.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
Expand All @@ -30,7 +30,7 @@
namespace App\Controller;

class SystemsOfRecordController extends StandardController {
public $paginate = [
public $pagination = [
'order' => [
'SystemsOfRecord.label' => 'asc'
]
Expand Down
Loading

0 comments on commit 1ec6b4d

Please sign in to comment.