Skip to content
Open
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
10 changes: 10 additions & 0 deletions app/src/Model/Table/PersonRolesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ public function validationDefault(Validator $validator): Validator {
$validator->add('status', [
'content' => ['rule' => ['inList', StatusEnum::getConstValues()]]
]);
$validator->requirePresence('status', 'create');
$validator->notEmptyString('status');

$validator->add('ordr', [
Expand Down Expand Up @@ -772,6 +773,10 @@ public function validationDefault(Validator $validator): Validator {
* Attribute Collector; when null a new Role is always created
* @param int|null $couId COU of the Petition; when set it overrides any collected COU
*
* A new Role with no collected status defaults to Active; beforeMarshal() then
* applies AR-PersonRole-4 (Pending Activation for a future Valid From). The status of an
* existing Role is left unchanged.
*
* @return PersonRole The saved Role
* @throws \Cake\Datasource\Exception\RecordNotFoundException If an issue occurs during saving
* @since COmanage Registry v5.1.0
Expand Down Expand Up @@ -799,6 +804,11 @@ public function saveAttributeCollectorPetitionAttributes(int $personId, array $f
return $this->saveOrFail($existingRole);
}

if(empty($role['status'])) {
// Default new Roles to Active; beforeMarshal() applies AR-PersonRole-4
$role['status'] = StatusEnum::Active;
}

return $this->saveOrFail($this->newEntity($role));
}
}