Skip to content

Commit

Permalink
Fix generic cover title not shown on error
Browse files Browse the repository at this point in the history
  • Loading branch information
svera authored Jan 17, 2025
1 parent fb66553 commit da2ec98
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions internal/webserver/controller/user/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (u *Controller) Update(c *fiber.Ctx) error {
}

func (u *Controller) updateUserData(c *fiber.Ctx, user *model.User, session model.Session) error {
user.Name = c.FormValue("name")
user.Name = strings.TrimSpace(c.FormValue("name"))
user.Username = strings.ToLower(c.FormValue("username"))
user.Email = c.FormValue("email")
user.SendToEmail = c.FormValue("send-to-email")
Expand Down Expand Up @@ -120,7 +120,7 @@ func (u *Controller) validate(c *fiber.Ctx, user *model.User, session model.Sess
func (u *Controller) usernameExists(c *fiber.Ctx, session model.Session) (bool, error) {
user, err := u.repository.FindByUsername(c.FormValue("username"))
if err != nil {
return true, fiber.ErrInternalServerError
return true, err
}
if user != nil && (session.Role == model.RoleAdmin && user.Uuid == c.FormValue("id")) {
return false, nil
Expand Down
4 changes: 4 additions & 0 deletions internal/webserver/embedded/css/display.css
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,7 @@ a.collapse-control.collapsed:after {
.zoomable img:hover {
transform: scale(1.1);
}

.zoomable + .card-img-overlay {
bottom: auto !important;
}
3 changes: 2 additions & 1 deletion internal/webserver/embedded/js/cover.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
document.querySelectorAll(".cover").forEach(function(elem) {
elem.addEventListener("error", () => {
elem.onerror = null
const coverTitleId = elem.getAttribute("data-cover-title-id")
elem.parentNode.children[0].srcset = elem.src
elem.parentNode.parentNode.children[1].classList.remove('d-none')
document.getElementById(coverTitleId).classList.remove('d-none')
})
})
4 changes: 2 additions & 2 deletions internal/webserver/embedded/views/partials/cover.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<div class="zoomable">{{end}}
<picture>
<source srcset="/documents/{{.Document.Slug}}/cover" alt='{{t .Lang "\"%s\" cover" .Document.Title}}' />
<img src="/images/generic.jpg" loading="lazy" class="cover img-fluid" alt='{{t .Lang "\"%s\" cover" .Document.Title}}'>
<img src="/images/generic.jpg" loading="lazy" class="cover img-fluid" alt='{{t .Lang "\"%s\" cover" .Document.Title}}' data-cover-title-id="cover-title-{{.Document.Slug}}" />
</picture>
{{if not .DisableCoverMainLink}}</div>{{end}}
<div class="card-img-overlay card-body d-none">
<div class="card-img-overlay card-body d-none" id="cover-title-{{.Document.Slug}}">
<h5 class="card-title text-center text-truncate">{{.Document.Title}}</h5>
{{if .Document.Authors}}
<p class="card-text text-center text-truncate">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="row border-bottom mb-3">
<div class="row border-bottom mb-3 d-flex align-items-center">
<div class="col-9">
<h2>{{t .Lang "Your highlights" }}</h2>
</div>
Expand Down
11 changes: 8 additions & 3 deletions internal/webserver/user_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestUserManagement(t *testing.T) {
mustReturnStatus(response, fiber.StatusOK, t)

newUserData := url.Values{
"name": {"New user"},
"name": {"New user "}, // Extra spaces to test trimming
"username": {"new"},
"email": {"[email protected]"},
"send-to-email": {"[email protected]"},
Expand All @@ -123,7 +123,12 @@ func TestUserManagement(t *testing.T) {
mustRedirectToUsersList(response, t)

var totalUsers int64
db.Take(&[]model.User{}).Count(&totalUsers)
var user model.User
db.Last(&user).Count(&totalUsers)

if user.Name != "New user" {
t.Errorf("Expected name to be 'New user', got %s", user.Name)
}

if totalUsers != 3 {
t.Errorf("Expected 3 users in the users list, got %d", totalUsers)
Expand Down Expand Up @@ -234,7 +239,7 @@ func TestUserManagement(t *testing.T) {
t.Run("Try to update the user in session", func(t *testing.T) {
reset()

regularUserData.Set("name", "Updated regular user")
regularUserData.Set("name", "Updated regular user ") // Extra spaces to test trimming
regularUserData.Set("id", regularUser.Uuid)

response, err := getRequest(regularUserCookie, app, fmt.Sprintf("/users/%s", regularUser.Username), t)
Expand Down

0 comments on commit da2ec98

Please sign in to comment.