diff --git a/app/Config/Schema/schema.xml b/app/Config/Schema/schema.xml
index 5b9235093..cae06de7d 100644
--- a/app/Config/Schema/schema.xml
+++ b/app/Config/Schema/schema.xml
@@ -1342,6 +1342,7 @@
+
REFERENCES cm_co_enrollment_flows(id)
diff --git a/app/Controller/CoPipelinesController.php b/app/Controller/CoPipelinesController.php
index a5c28dd86..320b7c2a1 100644
--- a/app/Controller/CoPipelinesController.php
+++ b/app/Controller/CoPipelinesController.php
@@ -107,6 +107,14 @@ function beforeRender() {
$args['contain'] = false;
$this->set('vv_linkable_enrollment_flows', $this->CoPipeline->CoEnrollmentFlow->find('list', $args));
+
+ // Provide a list of available clusters.
+ $args = array();
+ $args['conditions']['Cluster.co_id'] = $this->cur_co['Co']['id'];
+ $args['conditions']['Cluster.status'] = SuspendableStatusEnum::Active;
+ $args['contain'] = false;
+
+ $this->set('vv_clusters', $this->CoPipeline->Co->Cluster->find('list', $args));
parent::beforeRender();
}
diff --git a/app/Lib/lang.php b/app/Lib/lang.php
index b267afc58..78f64ddc5 100644
--- a/app/Lib/lang.php
+++ b/app/Lib/lang.php
@@ -1941,6 +1941,7 @@
'fd.pi.sync.del' => 'Sync on Delete',
'fd.pi.sync.del.stat' => 'Role Status on Delete',
'fd.pi.sync.del.stat.desc' => 'When the source record is no longer valid, the corresponding CO Person Role will be set to this status',
+ 'fd.pi.sync.establish_clusters.desc' => 'If enabled, establish cluster accounts when creating new CoPerson records',
'fd.pi.sync.role' => 'Create CO Person Role Record',
'fd.pi.sync.str' => 'Sync Strategy',
'fd.pi.sync.type' => 'Sync Identifier Type',
diff --git a/app/Model/CoPipeline.php b/app/Model/CoPipeline.php
index b639fdcaa..075025551 100644
--- a/app/Model/CoPipeline.php
+++ b/app/Model/CoPipeline.php
@@ -174,8 +174,69 @@ class CoPipeline extends AppModel {
'allowEmpty' => true,
'unfreeze' => 'CO'
)
+ ),
+ 'establish_clusters' => array(
+ 'rule' => 'boolean',
+ 'required' => false,
+ 'allowEmpty' => true
)
);
+
+ /**
+ * Possibly assign cluster accounts. Modeled after method with
+ * the same name on class CoPetition.
+ *
+ * @since COmanage Registry v4.5.0
+ * @param Integer $coPersonId CO Person ID
+ */
+
+ public function assignClusterAccounts($coPersonId) {
+ // Find all active clusters.
+ $args = array();
+ $args['conditions']['Cluster.status'] = SuspendableStatusEnum::Active;
+ $args['contain'] = false;
+
+ $clusters = $this->Co->Cluster->find('all', $args);
+
+ $clusterIds = array();
+
+ foreach($clusters as $c) {
+ $clusterIds[] = $c['Cluster']['id'];
+ }
+
+ if($clusterIds) {
+ $res = $this->Co->Cluster->assign($coPersonId, null, $clusterIds);
+ } else {
+ $res = array();
+ }
+
+ if(!empty($res)) {
+ // Create History Records for any results of interest
+
+ foreach($res as $desc => $result) {
+ $str = false;
+
+ if($result === true) {
+ $str = _txt('rs.cluster.acct.ok', array($desc));
+ } else {
+ $str = $result;
+ }
+
+ if($str !== false) {
+ try {
+ $this->Co->CoPerson->HistoryRecord->record($coPersonId,
+ null,
+ null,
+ null,
+ PetitionActionEnum::ClusterAccountAutoCreated,
+ $str);
+ }
+ catch(Exception $e) {
+ }
+ }
+ }
+ }
+ }
/**
* Create a Petition using the specified Enrollment Flow.
@@ -1512,6 +1573,12 @@ protected function syncOrgIdentityToCoPerson($coPipeline,
// This will return an array describing which, if any, identifiers were assigned,
// but we don't do anything with the result here
$this->Co->CoPerson->Identifier->assign('CoPerson', $coPersonId, $actorCoPersonId, false);
+
+ // Maybe create a UnixCluster object.
+ $establishClusters = $coPipeline['CoPipeline']['establish_clusters'] ?? false;
+ if($establishClusters) {
+ $this->assignClusterAccounts($coPersonId);
+ }
// Trigger provisioning
diff --git a/app/View/CoPipelines/fields.inc b/app/View/CoPipelines/fields.inc
index d0abcae62..efaabc69c 100644
--- a/app/View/CoPipelines/fields.inc
+++ b/app/View/CoPipelines/fields.inc
@@ -439,6 +439,22 @@
?>
+
+
+
+
+ Form->input('establish_clusters', array('onChange' => 'fields_update_gadgets()')) . ' ' .
+ $this->Form->label('establish_clusters', _txt('fd.ef.clusters'))
+ : (isset($co_pipelines[0]['CoPipeline']['establish_clusters']) ? _txt('fd.yes') : _txt('fd.no'))); ?>
+
+
+