Skip to content

Commit

Permalink
Initial implementation of Matchgrid Settings (CO-1803)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Oct 29, 2019
1 parent 05569cf commit 38c4048
Show file tree
Hide file tree
Showing 13 changed files with 516 additions and 86 deletions.
22 changes: 18 additions & 4 deletions app/config/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@
"id": {},
"description": {},
"table_name": { "type": "string", "size": 128, "notnull": true },
"status": {},
"referenceid_method": { "type": "string", "size": 2 },
"referenceid_start": { "type": "integer" },
"referenceid_prefix": { "type": "string", "size": 32 }
"status": {}
},
"indexes": {
"matchgrids_i1": {
Expand All @@ -51,6 +48,23 @@
"changelog": false
},

"matchgrid_settings": {
"columns": {
"id": {},
"matchgrid_id": {},
"referenceid_method": { "type": "string", "size": 2 },
"referenceid_start": { "type": "integer" },
"referenceid_prefix": { "type": "string", "size": 32 },
"notification_email": { "type": "string", "size": 80 }
},
"indexes": {
"matchgrid_settings_i1": {
"columns": [ "matchgrid_id" ]
}
},
"changelog": false
},

"permissions": {
"columns": {
"id": {},
Expand Down
19 changes: 10 additions & 9 deletions app/src/Controller/Component/AuthorizationComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,19 @@ public function menuPermissions($username, $matchgridId=null) {

return [
// Manage configuration of the current matchgrid
'api_users' => $platformAdmin || $mgAdmin,
'attribute_groups' => $platformAdmin || $mgAdmin,
'attribute_maps' => $platformAdmin || $mgAdmin,
'attributes' => $platformAdmin || $mgAdmin,
'rules' => $platformAdmin || $mgAdmin,
'systems_of_record' => $platformAdmin || $mgAdmin,
'api_users' => $platformAdmin || $mgAdmin,
'attribute_groups' => $platformAdmin || $mgAdmin,
'attribute_maps' => $platformAdmin || $mgAdmin,
'attributes' => $platformAdmin || $mgAdmin,
'matchgrid_settings' => $platformAdmin || $mgAdmin,
'rules' => $platformAdmin || $mgAdmin,
'systems_of_record' => $platformAdmin || $mgAdmin,
// Permissions specific to a matchgrid
'gridroles' => $perms['matchgrids'],
'gridroles' => $perms['matchgrids'],
// Overall permission to manage the matchgrids
'matchgrids' => $platformAdmin,
'matchgrids' => $platformAdmin,
// Overall permission to manage permissions
'permissions' => $platformAdmin
'permissions' => $platformAdmin
];
}
}
101 changes: 101 additions & 0 deletions app/src/Controller/MatchgridSettingsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
/**
* COmanage Matchgrid Settings 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 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 MatchgridSettingsController extends StandardController {
public $paginate = [
'order' => [
'MatchgridSetting.matchgrid_id' => 'asc'
]
];

/**
* Callback run prior to the view rendering.
*
* @since COmanage Match v1.0.0
* @param Event $event Cake Event
*/

public function beforeRender(\Cake\Event\Event $event) {
parent::beforeRender($event);

// Override page title
if($this->request->getParam('action') == 'edit') {
$this->set('vv_title', __("match.op.edit.a", [__("match.ct.matchgrid_settings", 1)]));
}
}

/**
* Handle an index request by checking for an existing CO Setting,
* creating it if not present, and then redirecting to edit.
*
* @since COmanage Match v1.0.0
*/

public function index() {
if(empty($this->cur_mg->id)) {
throw new RuntimeException(__("match.er.mgid"));
}

// Let any exception pass up the stack
$id = $this->MatchgridSettings->getIdForMatchgrid($this->cur_mg->id);

return $this->redirect(['action' => 'edit', $id]);
}

/**
* 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) {
$mgid = isset($this->cur_mg->id) ? $this->cur_mg->id : null;

$platformAdmin = $this->Authorization->isPlatformAdmin($user['username']);

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

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

$this->set('vv_permissions', $p);
return $p[$this->request->getParam('action')];
}
}
6 changes: 4 additions & 2 deletions app/src/Lib/Identifier/Sequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ class Sequence extends ReferenceIdService {
*/

public function generate(\App\Model\Entity\Matchgrid $mgConfig, \ADOConnection $dbc) {
$MatchgridSettings = TableRegistry::get('MatchgridSettings');

// We'll use the matchgrid ID rather than name in the sequence name to avoid
// issues if the matchgrid is renamed for some reason.

$seq = "mg_seq_" . (string)$mgConfig->id;
$prefix = $mgConfig->referenceid_prefix ?: "";
$prefix = $MatchgridSettings->getReferenceIdPrefix($mgConfig->id);

$refId = $prefix . (string)$dbc->genId($seq, $mgConfig->referenceid_start);
$refId = $prefix . (string)$dbc->genId($seq, $MatchgridSettings->getReferenceIdStart($mgConfig->id));

return $refId;
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/Lib/Match/MatchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ public function attachReferenceId(string $sor, string $sorid, AttributeManager $
*/

protected function generateReferenceId() {
if($this->mgConfig->referenceid_method == ReferenceIdEnum::Sequence) {
$MatchgridSettings = TableRegistry::get('MatchgridSettings');

if($MatchgridSettings->getReferenceIdMethod($this->mgConfig->id) == ReferenceIdEnum::Sequence) {
$IdService = new \App\Lib\Identifier\Sequence;
} else {
$IdService = new \App\Lib\Identifier\Uuid;
Expand Down
12 changes: 12 additions & 0 deletions app/src/Locale/en_US/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ msgstr "{0,plural,=1{Attribute Map} other{Attribute Maps}}"
msgid "match.ct.attributes"
msgstr "{0,plural,=1{Attribute} other{Attributes}}"

msgid "match.ct.matchgrid_settings"
msgstr "{0,plural,=1{Matchgrid Settings} other{Matchgrid Settings}}"

msgid "match.ct.matchgrids"
msgstr "{0,plural,=1{Matchgrid} other{Matchgrids}}"

Expand Down Expand Up @@ -293,6 +296,15 @@ msgstr "Label"
msgid "match.fd.name"
msgstr "Name"

msgid "match.fd.notification_email"
msgstr "Notification Email"

msgid "match.fd.notification_email.desc"
msgstr "On potential match, notify this address of the request requiring resolution"

msgid "match.fd.MatchgridSettings.notification_email.desc"
msgstr "On potential match, notify this address of the request requiring resolution (used if no SOR specific value is set)"

msgid "match.fd.null_equivalents"
msgstr "Null Equivalents"

Expand Down
40 changes: 40 additions & 0 deletions app/src/Model/Entity/MatchgridSetting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* COmanage Match Matchgrid Setting Entity
*
* 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 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\Model\Entity;

use Cake\ORM\Entity;

class MatchgridSetting extends Entity {
protected $_accessible = [
'*' => true,
'id' => false,
'slug' => false,
];
}
Loading

0 comments on commit 38c4048

Please sign in to comment.