-
Notifications
You must be signed in to change notification settings - Fork 468
pkp/pkp-lib#11885 Implemented edit, delete, and search endpoints for task templates and fixed stageId on add #11968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
8b2614a to
ae0f9f1
Compare
Vitaliy-1
left a comment
There was a problem hiding this 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. Can you also do a rebase, this would also require additional modifications because of a recent merge.
| $id = (int) $request->route('templateId'); | ||
|
|
||
| $template = Template::query() | ||
| ->where('context_id', $contextId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use scope here as we avoid using column names besides the Model itself
|
|
||
| $template = Template::query() | ||
| ->where('context_id', $contextId) | ||
| ->findOrFail($id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would need the explicit response error code (404) and message
| if (array_key_exists('stageId', $data)) $updates['stage_id'] = (int) $data['stageId']; | ||
| if (array_key_exists('title', $data)) $updates['title'] = $data['title']; | ||
| if (array_key_exists('include', $data)) $updates['include'] = (bool) $data['include']; | ||
| if (array_key_exists('emailTemplateKey', $data)) $updates['email_template_key'] = $data['emailTemplateKey']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just removed the email template key association. The current idea is to hard code the message into the template using description attribute
|
|
||
| DB::transaction(function () use ($template, $data) { | ||
| $updates = []; | ||
| if (array_key_exists('stageId', $data)) $updates['stage_id'] = (int) $data['stageId']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need these checks and go directly to the update
| if ($updates) { | ||
| $template->update($updates); | ||
| } | ||
| if (array_key_exists('userGroupIds', $data)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like the following would be better:
$userGroupIds = Arr::pull($data, 'userGroupIds');
$template->update($data);
$template->userGroups()->sync($userGroupIds);| $stages = Application::getApplicationStages(); | ||
| $stageIds = array_values(array_unique(array_filter( | ||
| array_map('intval', array_merge(array_keys((array)$stages), array_values((array)$stages))), | ||
| fn ($id) => $id > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably we don't need this check
| 'title' => ['required', 'string', 'max:255'], | ||
| 'include' => ['boolean'], | ||
| 'emailTemplateKey' => ['sometimes', 'nullable', 'string', 'max:255', Rule::in($emailKeys)], | ||
| 'type' => ['required','integer','in:1,2'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can re-use our EditorialTaskType enum here instead of plain numbers
| $stages = Application::getApplicationStages(); | ||
| $stageIds = array_values(array_unique(array_filter( | ||
| array_map('intval', array_merge(array_keys((array)$stages), array_values((array)$stages))), | ||
| fn ($id) => $id > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably this check isn't needed
| ))); | ||
|
|
||
| // Context-scoped email keys | ||
| $emailKeys = \APP\facades\Repo::emailTemplate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed as we don't rely on email templates anymore
classes/editorialTask/Template.php
Outdated
|
|
||
| public $timestamps = true; | ||
|
|
||
| public const TYPE_DISCUSSION = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just re-use EdirotialTaskType enum
6b7fc8b to
754ce24
Compare
Vitaliy-1
left a comment
There was a problem hiding this 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
|
|
||
| DB::transaction(function () use ($template, $data) { | ||
| $userGroupIds = Arr::pull($data, 'userGroupIds'); | ||
| $updates = collect($data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not anything critical but this should already be done during validation
| use PKP\editorialTask\enums\EditorialTaskDueInterval; | ||
| use PKP\editorialTask\enums\EditorialTaskType; | ||
|
|
||
| class UpdateTaskTemplate extends FormRequest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this class and AddTaskTemplate could have a common parent to avoid code duplication. Or AddTaskTemplate could extend this class. Or have a common trait...
|
|
||
| class UpdateTaskTemplate extends FormRequest | ||
| { | ||
| public function authorize(): bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work as we haven't yet integrated/adopted Laravel auth policies (it uses Laravel gates and policies according to the documentation: https://laravel.com/docs/12.x/validation#authorizing-form-requests)
| } | ||
|
|
||
| $tokens = preg_split('/\s+/', $phrase) ?: []; | ||
| $tokens = array_values(array_filter($tokens, fn ($t) => $t !== '')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also should do a special treatment for the task or discussion keyword within search phrase. E.g., the search phrase
task ethics
The code should perform the search by the keyword ethics within the tasks only.
| return $query; | ||
| } | ||
|
|
||
| $tokens = preg_split('/\s+/', $phrase) ?: []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure but maybe we already got a helper to break the phrase onto tokens somewhere in our codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Vitaliy-1 I checked the PKP codebase for existing helpers around tokenizing search phrases, but didn't find a reusable helper for this. Other search-related code appears to split phrases inline in a similar way.
For now I've kept the simple preg_split('/\s+/', ...) implementation here to stay consistent. If we later introduce a shared helper for free-text search tokens, I can switch this scope to use it.
|
@bozana, could you take a look at the search implementation for task templates? I'm not much familiar with our patterns and best practices, e.g., breaking the string into tokens/keywords. Also, should we use vocabulary for this? The idea is to search matches in the title and description/headnote. Ideally grouping and showing matches in the title first. |
bozana
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Hafsa-Naeem and @Vitaliy-1,
I went through the changes and left some comments.
Thanks!
classes/editorialTask/Template.php
Outdated
| $outer->where(function (Builder $q) use ($like, $settingsTable, $pk, $selfTable) { | ||
| $q->whereRaw('LOWER(title) LIKE ?', [$like]) | ||
| ->orWhereRaw('LOWER(description) LIKE ?', [$like]) | ||
| ->orWhereExists(function ($sub) use ($like, $settingsTable, $pk, $selfTable) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Builder $sub -- type Builder?
|
Hi @Vitaliy-1, oh I first now see your message above. |
edc8132 to
bc76e6f
Compare
api/v1/editTaskTemplates/formRequests/TaskTemplateRequestTrait.php
Outdated
Show resolved
Hide resolved
bc76e6f to
3e43e9a
Compare
Vitaliy-1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small comment but not a showstopper
| protected function getStageIds(): array | ||
| { | ||
| $stages = Application::getApplicationStages(); | ||
| return array_map('intval', array_values($stages)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that there already was a comment regarding this, do we need array_values and array_map here. I mean Application::getApplicationStages() already returns non-associative array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Vitaliy-1 Yes! I'll update this accordingly.
3e43e9a to
65de0c3
Compare
…plates and fixed stageId on add
…ding in template search
65de0c3 to
2ccae7e
Compare
for #11885