Skip to content
Snippets Groups Projects
Verified Commit 9dde3071 authored by Damien's avatar Damien
Browse files

FEAT #9105 lock for setAction + refactoring

parent 6c41866f
No related branches found
No related tags found
No related merge requests found
...@@ -13,22 +13,16 @@ SET search_path = public, pg_catalog; ...@@ -13,22 +13,16 @@ SET search_path = public, pg_catalog;
SET default_tablespace = ''; SET default_tablespace = '';
SET default_with_oids = false; SET default_with_oids = false;
CREATE SEQUENCE actions_id_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 500
CACHE 1;
CREATE TABLE actions CREATE TABLE actions
( (
id integer NOT NULL DEFAULT nextval('actions_id_seq'::regclass), id serial NOT NULL,
keyword character varying(32) NOT NULL DEFAULT ''::bpchar, keyword character varying(32) NOT NULL DEFAULT ''::bpchar,
label_action character varying(255), label_action character varying(255),
id_status character varying(10), id_status character varying(10),
is_system character(1) NOT NULL DEFAULT 'N'::bpchar, is_system character(1) NOT NULL DEFAULT 'N'::bpchar,
enabled character(1) NOT NULL DEFAULT 'Y'::bpchar, enabled character(1) NOT NULL DEFAULT 'Y'::bpchar,
action_page character varying(255), action_page character varying(255),
component CHARACTER VARYING (128),
history character(1) NOT NULL DEFAULT 'N'::bpchar, history character(1) NOT NULL DEFAULT 'N'::bpchar,
origin character varying(255) NOT NULL DEFAULT 'apps'::bpchar, origin character varying(255) NOT NULL DEFAULT 'apps'::bpchar,
create_id character(1) NOT NULL DEFAULT 'N'::bpchar, create_id character(1) NOT NULL DEFAULT 'N'::bpchar,
......
...@@ -25,8 +25,9 @@ class ActionMethodController ...@@ -25,8 +25,9 @@ class ActionMethodController
public static function terminateAction(array $aArgs) public static function terminateAction(array $aArgs)
{ {
ValidatorModel::notEmpty($aArgs, ['id', 'resId']); ValidatorModel::notEmpty($aArgs, ['id', 'resources']);
ValidatorModel::intVal($aArgs, ['id', 'resId']); ValidatorModel::intVal($aArgs, ['id']);
ValidatorModel::arrayType($aArgs, ['resources']);
$set = ['locker_user_id' => null, 'locker_time' => null, 'modification_date' => 'CURRENT_TIMESTAMP']; $set = ['locker_user_id' => null, 'locker_time' => null, 'modification_date' => 'CURRENT_TIMESTAMP'];
...@@ -37,20 +38,22 @@ class ActionMethodController ...@@ -37,20 +38,22 @@ class ActionMethodController
ResModel::update([ ResModel::update([
'set' => $set, 'set' => $set,
'where' => ['res_id = ?'], 'where' => ['res_id in (?)'],
'data' => [$aArgs['resId']] 'data' => [$aArgs['resources']]
]); ]);
if ($action['history'] == 'Y') { if ($action['history'] == 'Y') {
HistoryController::add([ foreach ($aArgs['resources'] as $resource) {
'tableName' => 'actions', HistoryController::add([
'recordId' => $aArgs['resId'], 'tableName' => 'actions',
'eventType' => 'ACTION#' . $aArgs['id'], 'recordId' => $resource,
'eventId' => $aArgs['id'], 'eventType' => 'ACTION#' . $resource,
'info' => $action['label_action'] 'eventId' => $aArgs['id'],
]); 'info' => $action['label_action']
]);
//TODO M2M
//TODO M2M
}
} }
return true; return true;
......
...@@ -582,7 +582,6 @@ class ResourceListController ...@@ -582,7 +582,6 @@ class ResourceListController
return $response->withStatus(400)->withJson(['errors' => 'Action is not linked to this group basket']); return $response->withStatus(400)->withJson(['errors' => 'Action is not linked to this group basket']);
} }
//TODO Check locked ???
$user = UserModel::getById(['id' => $aArgs['userId'], 'select' => ['user_id']]); $user = UserModel::getById(['id' => $aArgs['userId'], 'select' => ['user_id']]);
$whereClause = PreparedClauseController::getPreparedClause(['clause' => $basket['basket_clause'], 'login' => $user['user_id']]); $whereClause = PreparedClauseController::getPreparedClause(['clause' => $basket['basket_clause'], 'login' => $user['user_id']]);
$resources = ResModel::getOnView([ $resources = ResModel::getOnView([
...@@ -601,6 +600,20 @@ class ResourceListController ...@@ -601,6 +600,20 @@ class ResourceListController
} }
} }
foreach ($resources as $resource) {
$lock = true;
if (empty($resource['locker_user_id'] || empty($resource['locker_time']))) {
$lock = false;
} elseif ($resource['locker_user_id'] == $currentUser['id']) {
$lock = false;
} elseif (strtotime($resource['locker_time']) < time()) {
$lock = false;
}
if ($lock) {
return $response->withStatus(403)->withJson(['errors' => 'One of resources is lock']);
}
}
$action = ActionModel::getById(['id' => $aArgs['actionId'], 'select' => ['component']]); $action = ActionModel::getById(['id' => $aArgs['actionId'], 'select' => ['component']]);
if (empty($action['component'])) { if (empty($action['component'])) {
return $response->withStatus(400)->withJson(['errors' => 'Action component does not exist']); return $response->withStatus(400)->withJson(['errors' => 'Action component does not exist']);
...@@ -658,7 +671,7 @@ class ResourceListController ...@@ -658,7 +671,7 @@ class ResourceListController
$locked = 0; $locked = 0;
$resourcesToLock = []; $resourcesToLock = [];
foreach ($resources as $key => $resource) { foreach ($resources as $resource) {
$lock = true; $lock = true;
if (empty($resource['locker_user_id'] || empty($resource['locker_time']))) { if (empty($resource['locker_user_id'] || empty($resource['locker_time']))) {
$lock = false; $lock = false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment