Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
iglocska committed Nov 3, 2023
2 parents fb83ae6 + e39a651 commit be64a18
Show file tree
Hide file tree
Showing 373 changed files with 490,247 additions and 125 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: test

on:
push:
branches: [main, develop]
branches: [main, develop, fix-test-action]
pull_request:
branches: [main, develop]

Expand All @@ -14,9 +14,9 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-20.04]
php: ["7.4"]
php: ["8.2"]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Create config files
run: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ tmp
vendor
webroot/theme/node_modules
webroot/scss/*.css
webroot/js/node_modules/
!webroot/js/node_modules/mermaid/dist/
.vscode
docker/run/
.phpunit.result.cache
Expand Down
34 changes: 34 additions & 0 deletions config/Migrations/20231012000007_SGExtend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);

use Migrations\AbstractMigration;
use Phinx\Db\Adapter\MysqlAdapter;

final class SGExtend extends AbstractMigration
{
public $autoId = false; // turn off automatic `id` column create. We want it to be `int(10) unsigned`

/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change(): void
{
$table = $this->table('sgo');
$exists = $table->hasColumn('extend');
if (!$exists) {
$table
->addColumn('extend', 'boolean', [
'default' => 0,
'null' => false,
])->update();
}
}
}
1 change: 0 additions & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@
*/
'Error' => [
'errorLevel' => E_ALL,
'exceptionRenderer' => ExceptionRenderer::class,
'skipLog' => [],
'log' => true,
'trace' => true,
Expand Down
5 changes: 5 additions & 0 deletions config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@

return $detector->isTablet();
});
ServerRequest::addDetector('csv', [
'accept' => ['text/csv',],
'param' => '_ext',
'value' => 'csv',
]);

/*
* You can set whether the ORM uses immutable or mutable Time types.
Expand Down
2 changes: 1 addition & 1 deletion config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
/** @var \Cake\Routing\RouteBuilder $routes */
$routes->setRouteClass(DashedRoute::class);
$routes->scope('/', function (RouteBuilder $builder) {
$builder->setExtensions(['json']);
$builder->setExtensions(['json', 'csv']);
// Register scoped middleware for in scopes.
$builder->registerMiddleware('csrf', new CsrfProtectionMiddleware([
'httponly' => true,
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<testsuite name="api">
<directory>./tests/TestCase/Api</directory>
</testsuite>
<testsuite name="e2e">
<directory>./tests/TestCase/Integration</directory>
</testsuite>
</testsuites>

<extensions>
Expand Down
2 changes: 1 addition & 1 deletion plugins/Tags/src/View/Helper/TagHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function tag($tag, array $options = [])
$deleteButton = $this->Bootstrap->button([
'size' => 'sm',
'icon' => 'times',
'class' => ['ms-1', 'border-0', "text-${textColour}"],
'class' => ['ms-1', 'border-0', "text-$textColour"],
'variant' => 'text',
'title' => __('Delete tag'),
'onclick' => sprintf('deleteTag(\'%s\', \'%s\', this)',
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ImporterCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private function marshalData($table, $data, $config, $primary_key=null)
$entity = null;
if (isset($item[$primary_key])) {
$query = $table->find('all')
->where(["${primary_key}" => $item[$primary_key]]);
->where(["$primary_key" => $item[$primary_key]]);
$entity = $query->first();
}
if (is_null($entity)) {
Expand Down
1 change: 0 additions & 1 deletion src/Controller/AuditLogsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ public function filtering()
{
$this->CRUD->filtering();
}

}
4 changes: 3 additions & 1 deletion src/Controller/Component/ACLComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,16 @@ public function initialize(array $config): void
'viewTags' => ['*']
],
'Instance' => [
'downloadTopology' => ['perm_admin'],
'home' => ['*'],
'migrate' => ['perm_admin'],
'migrationIndex' => ['perm_admin'],
'rollback' => ['perm_admin'],
'saveSetting' => ['perm_admin'],
'searchAll' => ['*'],
'settings' => ['perm_admin'],
'status' => ['*']
'status' => ['*'],
'topology' => ['perm_admin'],
],
'LocalTools' => [
'action' => ['perm_admin'],
Expand Down
33 changes: 23 additions & 10 deletions src/Controller/Component/CRUDComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

class CRUDComponent extends Component
{
public $components = ['RestResponse'];
public $components = ['RestResponse', 'APIRearrange'];

public function initialize(array $config): void
{
Expand Down Expand Up @@ -102,12 +102,12 @@ public function index(array $options): void

if (!$this->Controller->ParamHandler->isRest()) {
$this->setRequestedEntryAmount();
} else if (!empty($this->request->getQuery('limit'))) {
} else if (empty($this->request->getQuery('limit'))) {
$this->Controller->paginate['limit'] = PHP_INT_MAX; // Make sure to download the entire filtered table
}
$data = $this->Controller->paginate($query, $this->Controller->paginate ?? []);
$totalCount = $this->Controller->getRequest()->getAttribute('paging')[$this->TableAlias]['count'];
if ($this->Controller->ParamHandler->isRest()) {
if ($this->Controller->ParamHandler->isRest() || $this->request->is('csv')) {
if (isset($options['hidden'])) {
$data->each(function($value, $key) use ($options) {
$hidden = is_array($options['hidden']) ? $options['hidden'] : [$options['hidden']];
Expand Down Expand Up @@ -138,9 +138,21 @@ public function index(array $options): void
return $this->attachMetaTemplatesIfNeeded($value, $metaTemplates);
});
}
$this->Controller->restResponsePayload = $this->RestResponse->viewData($data, 'json', false, false, false, [
'X-Total-Count' => $totalCount,
]);
if ($this->request->is('csv')) {
require_once(ROOT . '/src/Lib/Tools/CsvConverter.php');
$rearranged = $this->APIRearrange->rearrangeForAPI($data, ['smartFlattenMetafields' => true]);
$rearranged = $rearranged->map(function($e) {
return $e->toArray();
})->toList();
$data = \App\Lib\Tools\CsvConverter::flattenJSON($rearranged, []);
$this->Controller->restResponsePayload = $this->RestResponse->viewData($data, 'csv', false, false, false, [
'X-Total-Count' => $totalCount,
]);
} else {
$this->Controller->restResponsePayload = $this->RestResponse->viewData($data, 'json', false, false, false, [
'X-Total-Count' => $totalCount,
]);
}
} else {
$this->Controller->setResponse($this->Controller->getResponse()->withHeader('X-Total-Count', $totalCount));
if (isset($options['afterFind'])) {
Expand Down Expand Up @@ -281,7 +293,7 @@ public function getFilterFieldsName(): array
*/
public function getResponsePayload()
{
if ($this->Controller->ParamHandler->isRest()) {
if ($this->Controller->ParamHandler->isRest() || $this->request->is('csv')) {
return $this->Controller->restResponsePayload;
} else if ($this->Controller->ParamHandler->isAjax() && $this->request->is(['post', 'put'])) {
return $this->Controller->ajaxResponsePayload;
Expand Down Expand Up @@ -1305,6 +1317,7 @@ protected function setFilters($params, \Cake\ORM\Query $query, array $options):
}
$query = $this->setMetaFieldFilters($query, $filteringMetaFields);
}
$activeFilters['_here'] = $this->request->getRequestTarget();

$this->Controller->set('activeFilters', $activeFilters);
return $query;
Expand Down Expand Up @@ -1489,7 +1502,7 @@ private function prefixConditions(string $prefix, array $conditions)
{
$prefixedConditions = [];
foreach ($conditions as $condField => $condValue) {
$prefixedConditions["${prefix}.${condField}"] = $condValue;
$prefixedConditions["$prefix.$condField"] = $condValue;
}
return $prefixedConditions;
}
Expand Down Expand Up @@ -1613,13 +1626,13 @@ private function getFilteringContextFromField($field)
[sprintf('%s.id = %s.%s', $this->Table->getAlias(), $associatedTable->getAlias(), $association->getForeignKey())]
)
->where([
["${field} IS NOT" => NULL]
["$field IS NOT" => NULL]
]);
} else if ($associationType == 'manyToOne') {
$fieldToExtract = sprintf('%s.%s', Inflector::singularize(strtolower($model)), $subField);
$query = $this->Table->find()->contain($model);
} else {
throw new Exception("Association ${associationType} not supported in CRUD Component");
throw new Exception("Association $associationType not supported in CRUD Component");
}
} else {
$fieldToExtract = $field;
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/Component/Navigation/OrgGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class OrgGroupsNavigation extends BaseNavigation
public function addLinks()
{
$controller = 'OrgGroups';
if (empty($this->viewVars['canEdit'])) {
if (empty($this->viewVars['canEditDefinition'])) {
$this->bcf->removeLink($controller, 'view', $controller, 'edit');
$this->bcf->removeLink($controller, 'edit', $controller, 'edit');
}
Expand All @@ -17,9 +17,10 @@ public function addLinks()
public function addActions()
{
$controller = 'OrgGroups';
if (empty($this->viewVars['canEdit'])) {
if (empty($this->viewVars['canEditDefinition'])) {
$this->bcf->removeAction($controller, 'view', $controller, 'delete');
$this->bcf->removeAction($controller, 'edit', $controller, 'delete');
$this->bcf->removeAction($controller, 'view', $controller, 'add');
}
}
}
5 changes: 5 additions & 0 deletions src/Controller/Component/Navigation/sidemenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ public function get(): array
'label' => __('Instance'),
'icon' => $this->iconTable['Instance'],
'children' => [
'Topology' => [
'label' => __('Topology'),
'url' => '/instance/topology',
'icon' => 'project-diagram',
],
'Settings' => [
'label' => __('Settings'),
'url' => '/instance/settings',
Expand Down
3 changes: 2 additions & 1 deletion src/Controller/Component/RestResponseComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Cake\Controller\Component;
use Cake\Core\Configure;
use Cake\Utility\Hash;
use Cake\Utility\Inflector;

class RestResponseComponent extends Component
Expand Down Expand Up @@ -390,7 +391,7 @@ public function getApiInfo($relative_path)
return '[]';
}

public function saveFailResponse($controller, $action, $id = false, $validationErrors, $format = false)
public function saveFailResponse($controller, $action, $id, $validationErrors, $format = false)
{
$this->autoRender = false;
$response = array();
Expand Down
17 changes: 17 additions & 0 deletions src/Controller/InstanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,21 @@ public function saveSetting()
}
}
}

public function topology()
{
$this->set('title', __('Topology'));
$this->set('description', __('A list of all instances and local tools connected .'));
$this->set('data', $this->Instance->getTopology());
}

public function downloadTopology()
{
$topologyMd = $this->Instance->getTopology();
$response = $this->response;
$response = $response->withStringBody($topologyMd);
$response = $response->withType('text/markdown');
$response = $response->withDownload('topology.md');
return $response;
}
}
10 changes: 10 additions & 0 deletions src/Controller/OrgGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function view($id)
return $responsePayload;
}
$this->set('canEdit', $this->canEdit($id));
$this->set('canEditDefinition', $this->canEditDefinition($id));
}

public function edit($id)
Expand Down Expand Up @@ -136,6 +137,15 @@ private function canEdit($groupId): bool
return false;
}

private function canEditDefinition($groupId): bool
{
$currentUser = $this->ACL->getUser();
if ($currentUser['role']['perm_admin']) {
return true;
}
return false;
}

// Listing should be available to all, it's purely informational
public function listAdmins($groupId)
{
Expand Down
20 changes: 13 additions & 7 deletions src/Controller/SharingGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use \Cake\Database\Expression\QueryExpression;
use Cake\Error\Debugger;
use Cake\Http\Exception\NotFoundException;
use Cake\ORM\TableRegistry;

class SharingGroupsController extends AppController
{
Expand Down Expand Up @@ -171,9 +172,13 @@ public function addOrg($id)
$input['organisation_id'] = [$input['organisation_id']];
}
$result = true;
$this->SGO = TableRegistry::getTableLocator()->get('SGOs');
foreach ($input['organisation_id'] as $org_id) {
$org = $this->SharingGroups->SharingGroupOrgs->get($org_id);
$result &= (bool)$this->SharingGroups->SharingGroupOrgs->link($sharingGroup, [$org]);
$additional_data = [];
if (!empty($input['extend'])) {
$additional_data['extend'] = $input['extend'];
}
$result &= $this->SGO->attach($sharingGroup['id'], $org_id, $additional_data);
}
if ($result) {
$message = __('Organisation(s) added to the sharing group.');
Expand Down Expand Up @@ -216,8 +221,8 @@ public function removeOrg($id, $org_id)
throw new NotFoundException(__('Invalid SharingGroup.'));
}
if ($this->request->is('post')) {
$org = $this->SharingGroups->SharingGroupOrgs->get($org_id);
$result = (bool)$this->SharingGroups->SharingGroupOrgs->unlink($sharingGroup, [$org]);
$this->SGO = TableRegistry::getTableLocator()->get('SGOs');
$result = (bool)$this->SharingGroups->SharingGroupOrgs->unlink($sharingGroup['id'], $org_id);
if ($result) {
$message = __('Organisation(s) removed from the sharing group.');
} else {
Expand Down Expand Up @@ -253,9 +258,10 @@ public function removeOrg($id, $org_id)

public function listOrgs($id)
{
$sharingGroup = $this->SharingGroups->get($id, [
'contain' => 'SharingGroupOrgs'
]);
$sharingGroup = $this->SharingGroups->find()->where(['id' => $id])->contain(['SharingGroupOrgs'])->first();
foreach ($sharingGroup['sharing_group_orgs'] as $k => $org) {
$sharingGroup['sharing_group_orgs'][$k]['extend'] = $org['_joinData']['extend'];
}
$params = $this->ParamHandler->harvestParams(['quickFilter']);
if (!empty($params['quickFilter'])) {
foreach ($sharingGroup['sharing_group_orgs'] as $k => $org) {
Expand Down
Loading

0 comments on commit be64a18

Please sign in to comment.