Skip to content

Keep the name of a message template out of the edit form - #1087

Merged
KrzysztofPajak merged 2 commits into
developfrom
fix/message-template-name
Nov 23, 2026
Merged

KrzysztofPajak merged 2 commits into
developfrom
fix/message-template-name

Conversation

@KrzysztofPajak

@KrzysztofPajak KrzysztofPajak commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Type: bugfix

Issue

On the message template edit form the name is shown as read-only text, but it was posted back through a hidden input and model.ToEntity(messageTemplate) copied it onto the stored template.

The name is the key messages are sent by (GetMessageTemplateByName). A changed name made the notification it belonged to stop being sent, or made the template stand in for another one. Applies to Admin and to the Store panel (on a store's own templates), which share BaseMessageTemplateController.

To reproduce: edit any template, change the hidden Name input in the browser dev tools and save — the list shows the new name.

Solution

  • BaseMessageTemplateController.Edit(POST) keeps the stored name after mapping; the name is set on create only.
  • The hidden Name input is removed from the edit form; when the form is shown again after a validation error the name comes from the stored template.
  • When the create or edit form is shown again after a validation error, the Has attached download switch stays as posted; it used to be switched back on from AttachedDownloadId, so a resubmit kept an attachment the user had turned off.

Breaking changes

None. The name was never editable on the edit form.

Testing

  1. Admin → Content management → Message templates, open any template, change its subject and save: the subject changes, the name stays.
  2. Repeat after adding <input name="Name" value="Other.Name"> to the form in the dev tools: the name still stays.
  3. Clear the subject and save: the validation error is shown and the name is still displayed.
  4. Same in the Store panel on a template limited to that store.
  5. Turn off Has attached download on a template with an attachment, clear the subject and save: the error is shown and the switch is still off.
  6. dotnet test src/Tests/Grand.Web.Admin.Tests --filter BaseMessageTemplateControllerTests passes.

The name is read-only on the edit form, but it was posted back through a
hidden input and mapped onto the template. The name is the key a template
is sent by, so a changed name stopped the notification it belonged to.
The edit now keeps the stored name; it is set on create only.
Copilot AI balanced review requested due to automatic review settings November 22, 2026 18:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

After a failed validation the create and edit actions set
HasAttachedDownload from the posted AttachedDownloadId, so a switch the
user had just turned off came back on and a resubmit kept the attachment.
The form now shows the switch as it was posted.
var result = await controller.Edit(model, false) as ViewResult;

Assert.IsNotNull(result);
Assert.IsFalse(((MessageTemplateModel)result.Model).HasAttachedDownload);
@KrzysztofPajak
KrzysztofPajak merged commit 9cc716f into develop Nov 23, 2026
9 checks passed
@KrzysztofPajak
KrzysztofPajak deleted the fix/message-template-name branch November 25, 2026 09:10
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