Skip to content

Commit

Permalink
Initial implementation of BasicAttributeCollector (CFM-415) (COmanage…
Browse files Browse the repository at this point in the history
…#231)

Co-authored-by: Benn Oshrin <boshrin@users.noreply.github.com>
  • Loading branch information
2 people authored and arlen committed Dec 19, 2024
1 parent 22e3bc3 commit 89f15c0
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* COmanage Registry Basic Petition Attribute Set 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 https://www.internet2.edu/comanage COmanage Project
* @package registry-plugins
* @since COmanage Registry v5.1.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

declare(strict_types=1);

namespace CoreEnroller\Model\Entity;

use Cake\ORM\Entity;

class BasicPetitionAttributeSet extends Entity {
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
* be mass assigned. For security purposes, it is advised to set '*' to false
* (or remove it), and explicitly make individual fields accessible as needed.
*
* @var array<string, bool>
*/
protected $_accessible = [
'*' => true,
'id' => false,
'slug' => false,
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php
/**
* COmanage Registry Basic Petition Attribute Sets Table
*
* 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.1.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

declare(strict_types=1);

namespace CoreEnroller\Model\Table;

use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;

class BasicPetitionAttributeSetsTable extends Table {
use \App\Lib\Traits\CoLinkTrait;
use \App\Lib\Traits\PermissionsTrait;
use \App\Lib\Traits\PrimaryLinkTrait;
use \App\Lib\Traits\TableMetaTrait;
use \App\Lib\Traits\ValidationTrait;

/**
* Perform Cake Model initialization.
*
* @since COmanage Registry v5.1.0
* @param array $config Configuration options passed to constructor
*/

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

$this->addBehavior('Changelog');
$this->addBehavior('Log');
$this->addBehavior('Timestamp');

$this->setTableType(\App\Lib\Enum\TableTypeEnum::Artifact);

// Define associations
$this->belongsTo('CoreEnroller.BasicAttributeCollectors');
$this->belongsTo('Petition');

$this->setDisplayField('mail');

$this->setPrimaryLink('petition_id');
$this->setRequiresCO(true);

$this->setPermissions([
// Actions that operate over an entity (ie: require an $id)
'entity' => [
'delete' => false,
'edit' => false,
'view' => ['platformAdmin', 'coAdmin']
],
// Actions that operate over a table (ie: do not require an $id)
'table' => [
'add' => false,
'index' => ['platformAdmin', 'coAdmin']
]
]);
}

/**
* Set validation rules.
*
* @since COmanage Registry v5.1.0
* @param Validator $validator Validator
* @return Validator Validator
*/

public function validationDefault(Validator $validator): Validator {
$schema = $this->getSchema();

$validator->add('petition_id', [
'content' => ['rule' => 'isInteger']
]);
$validator->notEmptyString('petition_id');

$validator->add('basic_attribute_collector_id', [
'content' => ['rule' => 'isInteger']
]);
$validator->notEmptyString('basic_attribute_collector_id');

// For now we allow any attribute to be empty and rely on upsert and the UI to
// enforce requirements.
foreach(['honorific', 'given', 'middle', 'family', 'suffix'] as $f) {
$validator->add($f, [
'size' => ['rule' => ['validateMaxLength', ['column' => $schema->getColumn($f)]],
'provider' => 'table'],
'filter' => ['rule' => ['validateInput'],
'provider' => 'table']
]);
$validator->allowEmptyString($f);
}

$this->registerStringValidation($validator, $schema, 'mail', false);
$validator->add('mail', [
'content' => ['rule' => ['email'],
'message' => __d('error', 'input.invalid.email')]
]);

return $validator;
}
}

0 comments on commit 89f15c0

Please sign in to comment.