Skip to content

Commit

Permalink
Improvements to Integrations.
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-unwin committed Mar 8, 2024
1 parent 02bdc5d commit d0590a9
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 12 deletions.
27 changes: 24 additions & 3 deletions app/Models/IntegrationsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ public function getLocalDevices($integration)
$instance->user = new \stdClass();
}
if (empty($instance->user->org_list)) {
$instance->user->org_list = $orgs;
$instance->user->org_list = implode(',', $orgs);
}
helper('security');

Expand All @@ -915,7 +915,6 @@ public function getLocalDevices($integration)
}
// Select by Group
if ($integration->attributes->select_internal_type === 'group') {
$instance->user->org_list = implode(',', $orgs);
$device_ids = $groupsModel->execute(intval($integration->attributes->select_internal_attribute), $instance->user);
$dev_ids = array();
foreach ($device_ids as $device) {
Expand All @@ -928,7 +927,7 @@ public function getLocalDevices($integration)
}
// Select by Query
if ($integration->attributes->select_internal_type === 'query') {
$devices = $queriesModel->execute($integration->attributes->select_internal_value, '');
$devices = $queriesModel->execute($integration->attributes->select_internal_attribute, $instance->user);
$dev_ids = array();
foreach ($devices as $device) {
if (!empty($device->attributes->{'devices.id'})) {
Expand Down Expand Up @@ -1090,6 +1089,18 @@ public function includedRead(int $id = 0): array
$devices = $this->db->query($sql)->getResult();
$include['devices'] = format_data($devices, 'devices');
}

$sql = "SELECT `select_internal_type` FROM integrations WHERE id = ?";
$data = array(intval($id));
$type = $this->db->query($sql, [$id])->getResult()[0]->select_internal_type;
if ($type === 'query') {
$queries = model('App\Models\QueriesModel');
$include['queries'] = $queries->listUser();
}
if ($type === 'group') {
$groups = model('App\Models\GroupsModel');
$include['groups'] = $groups->listUser();
}
return $include;
}

Expand Down Expand Up @@ -1367,6 +1378,16 @@ public function read(int $id = 0): array
$query[0]->credentials = json_decode($query[0]->credentials);
}
}
if ($query[0]->select_internal_type === 'group') {
$sql = "SELECT `name` FROM groups WHERE `id` = ?";
$data = array(intval($query[0]->select_internal_attribute));
$query[0]->{'groups.name'} = $this->db->query($sql, $data)->getResult()[0]->name;
}
if ($query[0]->select_internal_type === 'query') {
$sql = "SELECT `name` FROM queries WHERE `id` = ?";
$data = array(intval($query[0]->select_internal_attribute));
$query[0]->{'queries.name'} = $this->db->query($sql, $data)->getResult()[0]->name;
}
return format_data($query, 'integrations');
}

Expand Down
56 changes: 47 additions & 9 deletions app/Views/integrationsRead.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,25 +142,63 @@
<option value="none" <?php if ($resource->select_internal_type === 'none') { ?>selected<?php } ?>><?= __('None') ?></option>
<option value="attribute" <?php if ($resource->select_internal_type === 'attribute') { ?>selected<?php } ?>><?= __('Attribute') ?></option>
<option value="group" <?php if ($resource->select_internal_type === 'group') { ?>selected<?php } ?>><?= __('Group') ?></option>
<option value="value" <?php if ($resource->select_internal_type === 'value') { ?>selected<?php } ?>><?= __('Value') ?></option>
<option value="query" <?php if ($resource->select_internal_type === 'query') { ?>selected<?php } ?>><?= __('Query') ?></option>
</select>
</div>
<div class="form-text form-help pull-right" style="position: absolute; right: 0;" data-attribute="select_internal_type" data-dictionary="<?= $dictionary->columns->select_internal_type ?>"><span><br /></span></div>
</div>
</div>

<?php if ($resource->select_internal_type === 'group') { ?>
<div class="row" style="padding-top:16px;">
<div class="offset-2 col-8" style="position:relative;">
<label for="select_internal_attribute" class="form-label"><?= __('Group') ?></label>
<div class="input-group">
<select class="form-select" id="select_internal_attribute" name="select_internal_attribute" data-original-value="<?= $resource->select_internal_attribute ?>" disabled>
<?php foreach ($included['groups'] as $group) { ?>
<option value="<?= $group->id ?>" <?php if ($resource->select_internal_attribute == $group->id) { ?>selected<?php } ?>><?= $group->attributes->name ?></option>
<?php } ?>
</select>
<?php if ($update) { ?>
<div class="pull-right" style="padding-left:4px;">
<div data-attribute="select_internal_type" class="btn btn-outline-secondary edit"><span style="font-size: 1.2rem;" class="fa fa-pencil"></span></div>
<div data-attribute="select_internal_type" class="btn btn-outline-success submit" style="display: none;"><span style="font-size: 1.2rem;" class="fa fa-check"></span></div>
<div data-attribute="select_internal_type" class="btn btn-outline-danger cancel" style="display: none;"><span style="font-size: 1.2rem;" class="fa fa-remove"></span></div>
<div data-attribute="select_internal_attribute" class="btn btn-outline-secondary edit"><span style="font-size: 1.2rem;" class="fa fa-pencil"></span></div>
<div data-attribute="select_internal_attribute" class="btn btn-outline-success submit" style="display: none;"><span style="font-size: 1.2rem;" class="fa fa-check"></span></div>
<div data-attribute="select_internal_attribute" class="btn btn-outline-danger cancel" style="display: none;"><span style="font-size: 1.2rem;" class="fa fa-remove"></span></div>
</div>
<?php } ?>
</div>
<div class="form-text form-help pull-right" style="position: absolute; right: 0;" data-attribute="select_internal_type" data-dictionary="<?= $dictionary->columns->select_internal_type ?>"><span><br /></span></div>
<div class="form-text form-help pull-right" style="position: absolute; right: 0;" data-attribute="select_internal_attribute" data-dictionary="<?= $dictionary->columns->select_internal_attribute ?>"><span><br /></span></div>
</div>
</div>
<?php } ?>

<?php if ($resource->select_internal_type === 'query') { ?>
<div class="row" style="padding-top:16px;">
<div class="offset-2 col-8" style="position:relative;">
<label for="select_internal_attribute" class="form-label"><?= __('Query') ?></label>
<div class="input-group">
<select class="form-select" id="select_internal_attribute" name="select_internal_attribute" data-original-value="<?= $resource->select_internal_attribute ?>" disabled>
<?php foreach ($included['queries'] as $query) { ?>
<option value="<?= $query->id ?>" <?php if ($resource->select_internal_attribute == $query->id) { ?>selected<?php } ?>><?= $query->attributes->name ?></option>
<?php } ?>
</select>
<?php if ($update) { ?>
<div class="pull-right" style="padding-left:4px;">
<div data-attribute="select_internal_attribute" class="btn btn-outline-secondary edit"><span style="font-size: 1.2rem;" class="fa fa-pencil"></span></div>
<div data-attribute="select_internal_attribute" class="btn btn-outline-success submit" style="display: none;"><span style="font-size: 1.2rem;" class="fa fa-check"></span></div>
<div data-attribute="select_internal_attribute" class="btn btn-outline-danger cancel" style="display: none;"><span style="font-size: 1.2rem;" class="fa fa-remove"></span></div>
</div>
<?php } ?>
</div>
<div class="form-text form-help pull-right" style="position: absolute; right: 0;" data-attribute="select_internal_attribute" data-dictionary="<?= $dictionary->columns->select_internal_attribute ?>"><span><br /></span></div>
</div>
</div>
<?php } ?>



<?= read_field('select_internal_attribute', $resource->{'select_internal_attribute'}, '', $update) ?>
<?= read_field('select_internal_value', $resource->{'select_internal_value'}, '', $update) ?>
<?php if ($resource->select_internal_type === 'attribute') { ?>
<?= read_field('select_internal_attribute', $resource->{'select_internal_attribute'}, '', $update, __('Attribute')) ?>
<?= read_field('select_internal_value', $resource->{'select_internal_value'}, '', $update, __('Value')) ?>
<?php } ?>
</div>
<div class="col-6">
<?= read_select('create_external_from_internal', $resource->create_external_from_internal, $dictionary->columns->create_external_from_internal, $update, __('Create') . ' ' . $resource->type . ' ' . __('Devices from Open-AudIT')) ?>
Expand Down

0 comments on commit d0590a9

Please sign in to comment.