Skip to content

Conversation

Hafsa-Naeem
Copy link
Contributor

for #11779

Copy link
Contributor

@Vitaliy-1 Vitaliy-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I left a couple of comments

$payload['dateDue'] = $illuminateRequest->input('dateDue');
}

// validation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$template->userGroups()->sync($payload['userGroupIds']);

// store extra template config in settings (non-localized)
DB::table('edit_task_template_settings')->insert([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we have got any settings for the Task Template

return $template->getKey();
});

// serialize with TaskResource
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding Resources, it should have its own resource. You can use task resource as an example: https://github.com/pkp/pkp-lib/blob/main/api/v1/submissions/resources/TaskResource.php

@Hafsa-Naeem Hafsa-Naeem force-pushed the i11779-main-fix branch 2 times, most recently from 95e3d45 to d01209f Compare September 12, 2025 01:36
Copy link
Contributor

@Vitaliy-1 Vitaliy-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Only 2 minor comments, otherwise looks good!

$contextId = Application::get()->getRequest()->getContext()->getId();

return [
'stageId' => ['required', 'integer', 'min:1'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can check if the application has the given stage by Application::getApplicationStages()

'stageId' => ['required', 'integer', 'min:1'],
'title' => ['required', 'string', 'max:255'],
'include' => ['sometimes', 'boolean'],
'emailTemplateId' => ['sometimes', 'nullable', 'integer', Rule::exists('email_templates', 'email_id')],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe specifying the key would be better?
And then we can validate with a custom rule: https://laravel.com/docs/12.x/validation#using-rule-objects. Trying to find all templates by their keys in the given context:

$templates = Repo::emailTemplate()->getCollector()->getMany();

Copy link
Contributor

@Vitaliy-1 Vitaliy-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! A couple of additional comments

$emailTemplateId = null;
if (!empty($validated['emailTemplateKey'])) {
$et = Repo::emailTemplate()->getByKey($context->getId(), $validated['emailTemplateKey']);
$emailTemplateId = $et?->getId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make an additional migration and reference from this column email template key, which also is unique. That's how later we can get either the default template, the customised one or a brand new, created specifically for the task

$template = DB::transaction(function () use ($validated, $context) {
$emailTemplateId = null;
if (!empty($validated['emailTemplateKey'])) {
$et = Repo::emailTemplate()->getByKey($context->getId(), $validated['emailTemplateKey']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use one of the validation hooks instead of the controller for such actions. Not sure but it looks like we can create a method in the class that extends FormRequest for this:

protected function passedValidation() 
{
  // transform data after validation is passed
}

]);
}

public function validated($key = null, $default = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you double check if we need to override this method here? I think we can avoid that...

'userGroupIds' => $this->whenLoaded('userGroups', fn () => $this->userGroups->pluck('user_group_id')->values()->all()),
'userGroups' => $this->whenLoaded('userGroups', fn () => $this->userGroups->map(fn ($ug) => [
'id' => (int) $ug->user_group_id,
'name' => method_exists($ug, 'getLocalizedName') ? $ug->getLocalizedName() : ($ug->name ?? null),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you double check if we need to return an assoc array with data in all locales or just a localized string?

Copy link
Contributor

@Vitaliy-1 Vitaliy-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just minor comments, looks good, thanks!

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class AddEditTaskTemplate extends FormRequest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be renamed just to the AddTaskTemplate to avoid confusion

public function up(): void
{
Schema::table('edit_task_templates', function (Blueprint $table) {
if (!Schema::hasColumn('edit_task_templates', 'email_template_key')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I'd avoid using such checks. That's because of something like this goes wrong, it's better to end the migration and give user the ability to restart it from the backup


// drop FK and old column
Schema::table('edit_task_templates', function (Blueprint $table) {
try { $table->dropForeign(['email_template_id']); } catch (\Throwable $e) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as above

@Vitaliy-1 Vitaliy-1 closed this Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants