From 7bc0426f973a208281ac126864388e87bca512d8 Mon Sep 17 00:00:00 2001 From: yisaka117 Date: Thu, 11 Sep 2025 17:50:52 +0900 Subject: [PATCH 1/2] add a consistency check when executing workflow actions --- resources/lang/en/exment.php | 1 + resources/lang/ja/exment.php | 1 + src/Controllers/CustomValueController.php | 11 ++++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/resources/lang/en/exment.php b/resources/lang/en/exment.php index 205fc42fc..cca5cdd3d 100644 --- a/resources/lang/en/exment.php +++ b/resources/lang/en/exment.php @@ -1150,6 +1150,7 @@ 'get_by_userinfo_and_action_select' => 'In the same pre-execution status, "Get from execution user information" and "Select by execution user of previous action" cannot be set at the same time.', 'action_execute' => 'Perform the following actions:', 'nextuser_not_found' => 'The following working user does not exist. Please contact the administrator.', + 'status_changed' => 'This action cannot be performed. Another user may have executed the workflow.', ], 'comment_options' => [ diff --git a/resources/lang/ja/exment.php b/resources/lang/ja/exment.php index 07cc6ffe6..3f76af86c 100644 --- a/resources/lang/ja/exment.php +++ b/resources/lang/ja/exment.php @@ -1151,6 +1151,7 @@ 'ignore_work_and_action_select' => '実行可能ユーザーが「前アクションの実行ユーザーが選択」の場合、「特殊なアクション」を設定できません。', 'action_execute' => '以下のアクションを実行します。', 'nextuser_not_found' => '次の作業ユーザーが存在しません。管理者に問い合わせください。', + 'status_changed' => 'このアクションは実行できません。他のユーザーがワークフローを実行した可能性があります。', ], 'comment_options' => [ diff --git a/src/Controllers/CustomValueController.php b/src/Controllers/CustomValueController.php index 8a25edac1..5f36b0823 100644 --- a/src/Controllers/CustomValueController.php +++ b/src/Controllers/CustomValueController.php @@ -717,7 +717,16 @@ public function actionClick(Request $request, $tableKey, $id) $custom_value = $this->custom_table->getValueModel($id); - //TODO:validation + //validation + $workflow_actions = $custom_value->getWorkflowActions(true); + if (!$workflow_actions->contains(function($workflow_action) use($action){ + return $workflow_action->id == $action->id; + })) { + return ([ + 'result' => false, + 'toastr' => sprintf(exmtrans('workflow.message.status_changed')), + ]); + } $action->executeAction($custom_value, [ 'comment' => $request->get('comment'), From 26e185a50fac91e333354b30a14546b7762bcccd Mon Sep 17 00:00:00 2001 From: SuDC Date: Thu, 2 Oct 2025 14:01:04 +0700 Subject: [PATCH 2/2] Enhance login method to handle missing test users and create them if necessary --- tests/Browser/ExmentKitPrepareTrait.php | 4 +-- tests/Browser/ExmentKitTestCase.php | 47 ++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/tests/Browser/ExmentKitPrepareTrait.php b/tests/Browser/ExmentKitPrepareTrait.php index d9d7d2d8d..190c2a444 100644 --- a/tests/Browser/ExmentKitPrepareTrait.php +++ b/tests/Browser/ExmentKitPrepareTrait.php @@ -25,7 +25,7 @@ protected function createCustomRelation($parent_table, $child_table, $relation_t // Create custom relation $this->visit(admin_url("relation/$parent_table/create")) ->submitForm('admin-submit', $data) - ->seePageIs('/admin/relation/' . $parent_table) + ->seePageIs(admin_url('relation/' . $parent_table)) ->seeInElement('td', array_get($row, 'table_view_name')); } @@ -246,7 +246,7 @@ protected function createCustomColumns($table_name, $targets = null) // Create custom column $this->post(admin_url("column/$table_name"), $data); $this->visit(admin_url("column/$table_name")) - ->seePageIs("/admin/column/$table_name") + ->seePageIs(admin_url("column/$table_name")) ->seeInElement('td', array_get($data, 'column_view_name')); } } diff --git a/tests/Browser/ExmentKitTestCase.php b/tests/Browser/ExmentKitTestCase.php index cd7141555..1746e2c45 100644 --- a/tests/Browser/ExmentKitTestCase.php +++ b/tests/Browser/ExmentKitTestCase.php @@ -59,7 +59,30 @@ protected function setUpTraits() */ protected function login($id = null) { - $this->be(LoginUser::find($id?? 1)); + $targetId = $id ?? 1; + $user = LoginUser::find($targetId); + + if (!$user) { + // Try to create a minimal test user if it doesn't exist + try { + $this->createTestUserIfNeeded($targetId); + $user = LoginUser::find($targetId); + } catch (\Exception $e) { + // If we still can't find or create the user, throw an informative error + throw new \RuntimeException( + "Test user with ID " . $targetId . " not found and could not be created. " . + "Please ensure test data is properly seeded. Error: " . $e->getMessage() + ); + } + } + + if (!$user) { + throw new \RuntimeException( + "Test user with ID " . $targetId . " not found. Please ensure test data is properly seeded." + ); + } + + $this->be($user); } @@ -114,4 +137,26 @@ public function containsSelectOptions($element, array $options, $negate = false) { return $this->assertInPage(new Constraints\ContainsSelectOption($element, $options), $negate); } + /** + * Create a minimal test user if needed + * @param int $id + * @return void + */ + private function createTestUserIfNeeded($id) + { + // Check if we have basic custom tables + $userTable = \Exceedone\Exment\Model\CustomTable::getEloquent('user'); + if (!$userTable) { + // Try to seed again + \Artisan::call('db:seed', [ + '--class' => 'Exceedone\\Exment\\Database\\Seeder\\InstallSeeder', + '--force' => true + ]); + \Artisan::call('db:seed', [ + '--class' => 'Exceedone\\Exment\\Database\\Seeder\\TestDataSeeder', + '--force' => true + ]); + } + } + }