diff --git a/sql/structure.sql b/sql/structure.sql index bbbab3aa89a052962b2aa9427be6c241c82a2b73..ebad0e53e66703123e624e4d6dd2917f262db845 100755 --- a/sql/structure.sql +++ b/sql/structure.sql @@ -13,22 +13,16 @@ SET search_path = public, pg_catalog; SET default_tablespace = ''; SET default_with_oids = false; -CREATE SEQUENCE actions_id_seq - INCREMENT 1 - MINVALUE 1 - MAXVALUE 9223372036854775807 - START 500 - CACHE 1; - 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, label_action character varying(255), id_status character varying(10), is_system character(1) NOT NULL DEFAULT 'N'::bpchar, enabled character(1) NOT NULL DEFAULT 'Y'::bpchar, action_page character varying(255), + component CHARACTER VARYING (128), history character(1) NOT NULL DEFAULT 'N'::bpchar, origin character varying(255) NOT NULL DEFAULT 'apps'::bpchar, create_id character(1) NOT NULL DEFAULT 'N'::bpchar, diff --git a/src/app/action/controllers/ActionMethodController.php b/src/app/action/controllers/ActionMethodController.php index f5910705aa6ebba056c772330bda083c18dea9b6..0ea75bf7ff4eb3212d9b8c0b6ad359362e22f7a2 100644 --- a/src/app/action/controllers/ActionMethodController.php +++ b/src/app/action/controllers/ActionMethodController.php @@ -25,8 +25,9 @@ class ActionMethodController public static function terminateAction(array $aArgs) { - ValidatorModel::notEmpty($aArgs, ['id', 'resId']); - ValidatorModel::intVal($aArgs, ['id', 'resId']); + ValidatorModel::notEmpty($aArgs, ['id', 'resources']); + ValidatorModel::intVal($aArgs, ['id']); + ValidatorModel::arrayType($aArgs, ['resources']); $set = ['locker_user_id' => null, 'locker_time' => null, 'modification_date' => 'CURRENT_TIMESTAMP']; @@ -37,20 +38,22 @@ class ActionMethodController ResModel::update([ 'set' => $set, - 'where' => ['res_id = ?'], - 'data' => [$aArgs['resId']] + 'where' => ['res_id in (?)'], + 'data' => [$aArgs['resources']] ]); if ($action['history'] == 'Y') { - HistoryController::add([ - 'tableName' => 'actions', - 'recordId' => $aArgs['resId'], - 'eventType' => 'ACTION#' . $aArgs['id'], - 'eventId' => $aArgs['id'], - 'info' => $action['label_action'] - ]); - - //TODO M2M + foreach ($aArgs['resources'] as $resource) { + HistoryController::add([ + 'tableName' => 'actions', + 'recordId' => $resource, + 'eventType' => 'ACTION#' . $resource, + 'eventId' => $aArgs['id'], + 'info' => $action['label_action'] + ]); + + //TODO M2M + } } return true; diff --git a/src/app/resource/controllers/ResourceListController.php b/src/app/resource/controllers/ResourceListController.php index 04c07113475afc56fd73c697746c674273317809..e6c5dce3f920478681bab40b6c12dca93003ee43 100644 --- a/src/app/resource/controllers/ResourceListController.php +++ b/src/app/resource/controllers/ResourceListController.php @@ -582,7 +582,6 @@ class ResourceListController 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']]); $whereClause = PreparedClauseController::getPreparedClause(['clause' => $basket['basket_clause'], 'login' => $user['user_id']]); $resources = ResModel::getOnView([ @@ -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']]); if (empty($action['component'])) { return $response->withStatus(400)->withJson(['errors' => 'Action component does not exist']); @@ -658,7 +671,7 @@ class ResourceListController $locked = 0; $resourcesToLock = []; - foreach ($resources as $key => $resource) { + foreach ($resources as $resource) { $lock = true; if (empty($resource['locker_user_id'] || empty($resource['locker_time']))) { $lock = false;