Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipeline establish Cluster objects (CO-2859) #663

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions app/Config/Schema/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,7 @@
</field>
<field name="sync_status_on_delete" type="C" size="2" />
<field name="sync_identifier_type" type="C" size="32" />
<field name="establish_clusters" type="L" />
<field name="co_enrollment_flow_id" type="I">
<constraint>REFERENCES cm_co_enrollment_flows(id)</constraint>
</field>
Expand Down
8 changes: 8 additions & 0 deletions app/Controller/CoPipelinesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions app/Lib/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
67 changes: 67 additions & 0 deletions app/Model/CoPipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions app/View/CoPipelines/fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,22 @@
?>
</div>
</li>
<?php if(!empty($vv_clusters)): ?>
<li>
<div class="field-name">
<div class="field-title">
<?php print _txt('fd.ef.clusters'); ?>
</div>
<span class="field-desc"><?php print _txt('fd.pi.sync.establish_clusters.desc'); ?></span>
</div>
<div class="field-info checkbox">
<?php print ($e
? $this->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'))); ?>
</div>
</li>
<?php endif ?>
<li>
<div class="field-name">
<div class="field-title"><?php print _txt('fd.pi.sync.role'); ?></div>
Expand Down