Skip to content

Commit

Permalink
Merge branch 'release/4.0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
MintHCM-admin committed May 29, 2024
2 parents 56cc5a7 + 657a498 commit e821f82
Show file tree
Hide file tree
Showing 901 changed files with 68,966 additions and 28,074 deletions.
22 changes: 20 additions & 2 deletions api/app/Controllers/Init/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function getData()
$response_body['menu_modules'] = $modules_menu;
$response_body['modules'] = $modules_data;
$response_body['quick_create'] = $this->getQuickCreate();
$response_body['legacy_views'] = $this->getLegacyViews();
$response_body['legacy_views'] = $this->getLegacyViews($modules_data);
return $response_body;
}

Expand Down Expand Up @@ -159,9 +159,27 @@ private function getQuickCreate()
return $response;
}

private function getLegacyViews()
private function getLegacyViews($modules_data)
{
$legacy_views = include "constants/legacy_views.php";
chdir('../legacy');
foreach($modules_data as $module => $data){
if(
(
!array_key_exists($module, $legacy_views)
|| !isset($legacy_views[$module]['list'])
)
&& (
file_exists('modules/' . $module . '/metadata/eslistviewdefs.php')
|| file_exists('custom/modules/' . $module . '/metadata/eslistviewdefs.php')
)
){
$legacy_views[$module] = [
'list' => false,
];
}
}
chdir('../api');
return $legacy_views;
}

Expand Down
43 changes: 43 additions & 0 deletions api/app/Controllers/Module/ListMassActionsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace MintHCM\Api\Controllers\Module;

use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Exception\HttpForbiddenException;
use Slim\Exception\HttpNotFoundException;
use Slim\Psr7\Response;
use Slim\Routing\RouteContext;
use Slim\Exception\HttpBadRequestException;

class ListMassActionsController
{
public function __invoke(Request $request, Response $response, array $args): Response
{
$action = $request->getAttribute('action');
$ids = $request->getAttribute('ids');

$routeContext = RouteContext::fromRequest($request);
$route = $routeContext->getRoute();
$module = explode('/', $route->getPattern())[1] ?? '';

if (empty($module) || empty($action) || empty($ids)) {
throw new HttpBadRequestException($request);
}

$mass_action_class = 'MintHCM\\Data\\MassActions\\Actions\\' . $action;
if (!class_exists($mass_action_class)) {
throw new HttpNotFoundException($request);
}

$mass_action = new $mass_action_class($module, $ids);

if (!$mass_action->hasAccess()) {
throw new HttpForbiddenException($request);
}

$result = $mass_action->execute();

$response->getBody()->write(json_encode($result));
return $response;
}
}
26 changes: 26 additions & 0 deletions api/app/Routes/modules/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use MintHCM\Api\Controllers\ModuleController;
use MintHCM\Api\Controllers\Module\ListController;
use MintHCM\Api\Controllers\Module\ListInitController;
use MintHCM\Api\Controllers\Module\ListMassActionsController;
use MintHCM\Api\Middlewares\Params\ParamTypes\IntType;
use MintHCM\Api\Middlewares\Params\ParamTypes\ArrayType;
use MintHCM\Api\Middlewares\Params\ParamTypes\StringType;
Expand Down Expand Up @@ -165,4 +166,29 @@
'auth' => true,
),
),
"mass_actions" => array(
"method" => "POST",
"path" => "/MassActions/{action}",
"class" => ListMassActionsController::class,
"desc" => "Mass actions on list of records",
"options" => array(
'auth' => true,
),
"pathParams" => array(
"action" => array(
"type" => StringType::class,
"required" => true,
"desc" => "Action name",
"example" => 'Delete',
),
),
"bodyParams" => array(
"ids" => array(
"type" => ArrayType::class,
"required" => true,
"desc" => "Array of ids",
"example" => '["223dee27-b9e7-432a-8da9-c84cc0770035", "223dee27-b9e7-432a-8da9-c84cc0770035"]',
),
),
),
);
50 changes: 50 additions & 0 deletions api/data/MassActions/Actions/Delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace MintHCM\Data\MassActions\Actions;

use MintHCM\Data\MassActions\MassAction;

class Delete extends MassAction
{
const ICON = 'mdi-delete';
const LABEL = 'LBL_DELETE';

public function execute()
{
$result = [
'success' => false,
'beans_access' => false,
];

if (!$this->hasAccess()) {
return $result;
}

$beans = $this->getBeans();

chdir('../legacy');
foreach ($beans as $bean) {
if (!$bean->ACLAccess('delete')) {
return $result;
}
}

$result['beans_access'] = true;

foreach ($beans as $bean) {
$bean->mark_deleted($bean->id);
}
chdir('../api');

$result['success'] = true;
return $result;
}

public function hasAccess()
{
chdir('../legacy');
$has_access = \ACLController::checkAccess($this->module_name, 'delete', true);
chdir('../api');
return $has_access;
}
}
24 changes: 24 additions & 0 deletions api/data/MassActions/Actions/Export.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace MintHCM\Data\MassActions\Actions;

use MintHCM\Data\MassActions\MassAction;

class Export extends MassAction
{
const ICON = 'mdi-export';
const LABEL = 'LBL_EXPORT';

public function execute()
{
throw new \Exception('Export is implemented in legacy code.');
}

public function hasAccess()
{
chdir('../legacy');
$has_access = \ACLController::checkAccess($this->module_name, 'export', true);
chdir('../api');
return $has_access;
}
}
29 changes: 29 additions & 0 deletions api/data/MassActions/Actions/Merge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace MintHCM\Data\MassActions\Actions;

use MintHCM\Data\MassActions\MassAction;

class Merge extends MassAction
{
const ICON = 'mdi-merge';
const LABEL = 'LBL_MERGE_DUPLICATES';

public function execute()
{
throw new \Exception('Merge is implemented in legacy code.');
}

public function hasAccess()
{
chdir('../legacy');
global $dictionary;
$has_access = (
!empty($dictionary[$this->module_name]['duplicate_merge'])
&& \ACLController::checkAccess($this->module_name, 'edit', true)
&& \ACLController::checkAccess($this->module_name, 'delete', true)
);
chdir('../api');
return $has_access;
}
}
43 changes: 43 additions & 0 deletions api/data/MassActions/MassAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace MintHCM\Data\MassActions;

abstract class MassAction
{
const ICON = '';
const LABEL = '';

protected $module_name;
protected $ids;

public function __construct($module_name, $ids)
{
$this->module_name = $module_name;
$this->ids = $ids;
}

public abstract function execute();
public abstract function hasAccess();

public function getFrontendData()
{
return [
'icon' => static::ICON,
'label' => static::LABEL,
'action' => (new \ReflectionClass($this))->getShortName(),
];
}

protected function getBeans()
{
if (empty($this->ids)) {
return [];
}
chdir('../legacy');
$seed = \BeanFactory::getBean($this->module_name);
$db = \DBManagerFactory::getInstance();
$beans = $seed->get_full_list('', "{$seed->table_name}.id IN ({$db->implodeQuoted($this->ids)})");
chdir('../api');
return $beans ?? [];
}
}
1 change: 0 additions & 1 deletion api/lib/Search/ElasticSearch/Operators/Exists.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@

class Exists extends ElasticOperator
{

public function __construct(array $data)
{
parent::__construct($data);
Expand Down
1 change: 1 addition & 0 deletions assets/InstallView.0f545d5c.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/InstallView.97554e5a.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion assets/InstallView.c3b08d94.js

This file was deleted.

Loading

0 comments on commit e821f82

Please sign in to comment.