Fix incorre check on template deletion.

This commit is contained in:
Kailash Nadh 2021-05-16 15:26:38 +05:30
parent 9fe78d6247
commit aa5eff915d
5 changed files with 8 additions and 16 deletions

View File

@ -1,7 +1,6 @@
package main
import (
"database/sql"
"errors"
"fmt"
"net/http"
@ -222,23 +221,15 @@ func handleDeleteTemplate(c echo.Context) error {
if id < 1 {
return echo.NewHTTPError(http.StatusBadRequest, app.i18n.T("globals.messages.invalidID"))
} else if id == 1 {
return echo.NewHTTPError(http.StatusBadRequest,
app.i18n.T("templates.cantDeleteDefault"))
}
var delID int
err := app.queries.DeleteTemplate.Get(&delID, id)
if err != nil {
if err == sql.ErrNoRows {
return c.JSON(http.StatusOK, okResp{true})
}
return echo.NewHTTPError(http.StatusInternalServerError,
app.i18n.Ts("globals.messages.errorCreating",
app.i18n.Ts("globals.messages.errorDeleting",
"name", "{globals.terms.template}", "error", pqErrMsg(err)))
}
if delID == 0 {
return echo.NewHTTPError(http.StatusBadRequest,
app.i18n.T("templates.cantDeleteDefault"))

View File

@ -1,5 +1,5 @@
{
"baseUrl": "http://localhost:9000",
"baseUrl": "http://localhost:8080",
"env": {
"server_init_command": "pkill -9 listmonk | cd ../ && ./listmonk --install --yes && ./listmonk > /dev/null 2>/dev/null &",
"username": "listmonk",

View File

@ -26,7 +26,7 @@ describe('Templates', () => {
cy.get('input[name=name]').clear().type('edited');
cy.get('textarea[name=body]').clear().type('<span>test</span> {{ template "content" . }}',
{ parseSpecialCharSequences: false, delay: 0 });
cy.get('footer.modal-card-foot button.is-primary').click();
cy.get('.modal-card-foot button.is-primary').click();
cy.wait(250);
cy.get('tbody td[data-label="Name"] a').contains('edited');
});
@ -40,7 +40,7 @@ describe('Templates', () => {
cy.get('span').first().contains('test');
cy.get('p').first().contains('Hi there');
});
cy.get('footer.modal-card-foot button').click();
cy.get('.modal-card-foot button').click();
// Cloned one should have the full template.
cy.get('tbody [data-cy=btn-preview').eq(1).click();
@ -49,7 +49,7 @@ describe('Templates', () => {
cy.get('.wrap p').first().contains('Hi there');
cy.get('.footer a').first().contains('Unsubscribe');
});
cy.get('footer.modal-card-foot button').click();
cy.get('.modal-card-foot button').click();
});
it('Sets default', () => {
@ -69,6 +69,7 @@ describe('Templates', () => {
it('Deletes template', () => {
cy.wait(250);
cy.get('tbody td.actions [data-cy=btn-delete]').first().click();
cy.get('.modal button.is-primary').click();
cy.wait(250);

View File

@ -244,7 +244,7 @@ section {
padding: 15px 10px;
border-color: $grey-lightest;
}
.actions a {
.actions a, .actions .a {
margin: 0 10px;
display: inline-block;
}

View File

@ -17,7 +17,7 @@
</b-field>
<b-field :label="$t('templates.rawHTML')" label-position="on-border">
<b-input v-model="form.body" type="textarea" required />
<b-input v-model="form.body" type="textarea" name="body" required />
</b-field>
<p class="is-size-7">