7
7
* Copyright (c) 2025 John Willinsky
8
8
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
9
9
*
10
- * @class AddEditTaskTemplates
10
+ * @class AddEditTaskTemplate
11
11
*
12
12
* @brief Handle API requests validation for adding editorial template operations.
13
13
*
16
16
namespace PKP \API \v1 \editTaskTemplates \formRequests ;
17
17
18
18
use APP \core \Application ;
19
+ use APP \facades \Repo ;
19
20
use Illuminate \Foundation \Http \FormRequest ;
20
21
use Illuminate \Validation \Rule ;
21
22
@@ -29,12 +30,20 @@ public function authorize(): bool
29
30
public function rules (): array
30
31
{
31
32
$ contextId = Application::get ()->getRequest ()->getContext ()->getId ();
32
-
33
+ $ stageIds = array_keys (Application::getApplicationStages ());
34
+ $ emailKeys = Repo::emailTemplate ()
35
+ ->getCollector ($ contextId )
36
+ ->getMany ()
37
+ ->map (fn ($ t ) => $ t ->getData ('key ' ))
38
+ ->filter ()
39
+ ->values ()
40
+ ->all ();
41
+
33
42
return [
34
- 'stageId ' => ['required ' , 'integer ' , ' min:1 ' ],
43
+ 'stageId ' => ['required ' , 'integer ' , Rule:: in ( $ stageIds ) ],
35
44
'title ' => ['required ' , 'string ' , 'max:255 ' ],
36
- 'include ' => ['sometimes ' , ' boolean ' ],
37
- 'emailTemplateId ' => ['sometimes ' , 'nullable ' , 'integer ' , Rule:: exists ( ' email_templates ' , ' email_id ' )],
45
+ 'include ' => ['boolean ' ],
46
+ 'emailTemplateKey ' => ['sometimes ' , 'nullable ' , 'string ' , ' max:255 ' , Rule:: in ( $ emailKeys )],
38
47
'userGroupIds ' => ['required ' , 'array ' , 'min:1 ' ],
39
48
'userGroupIds.* ' => [
40
49
'integer ' ,
@@ -61,7 +70,7 @@ public function validated($key = null, $default = null)
61
70
'stageId ' => (int ) $ data ['stageId ' ],
62
71
'title ' => $ data ['title ' ],
63
72
'include ' => $ data ['include ' ] ?? false ,
64
- 'emailTemplateId ' => $ data ['emailTemplateId ' ] ?? null ,
73
+ 'emailTemplateKey ' => $ data ['emailTemplateKey ' ] ?? null ,
65
74
'userGroupIds ' => $ data ['userGroupIds ' ],
66
75
];
67
76
}
0 commit comments