2021-04-12 16:49:26 +02:00
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2021-04-12 16:49:26 +02:00
|
|
|
|
|
|
|
|
package httpcache
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
"net/http/httptest"
|
Avatar refactor, move avatar code from `models` to `models.avatars`, remove duplicated code (#17123)
Why this refactor
The goal is to move most files from `models` package to `models.xxx` package. Many models depend on avatar model, so just move this first.
And the existing logic is not clear, there are too many function like `AvatarLink`, `RelAvatarLink`, `SizedRelAvatarLink`, `SizedAvatarLink`, `MakeFinalAvatarURL`, `HashedAvatarLink`, etc. This refactor make everything clear:
* user.AvatarLink()
* user.AvatarLinkWithSize(size)
* avatars.GenerateEmailAvatarFastLink(email, size)
* avatars.GenerateEmailAvatarFinalLink(email, size)
And many duplicated code are deleted in route handler, the handler and the model share the same avatar logic now.
2021-10-06 07:25:46 +08:00
|
|
|
"strings"
|
2021-04-12 16:49:26 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
Avatar refactor, move avatar code from `models` to `models.avatars`, remove duplicated code (#17123)
Why this refactor
The goal is to move most files from `models` package to `models.xxx` package. Many models depend on avatar model, so just move this first.
And the existing logic is not clear, there are too many function like `AvatarLink`, `RelAvatarLink`, `SizedRelAvatarLink`, `SizedAvatarLink`, `MakeFinalAvatarURL`, `HashedAvatarLink`, etc. This refactor make everything clear:
* user.AvatarLink()
* user.AvatarLinkWithSize(size)
* avatars.GenerateEmailAvatarFastLink(email, size)
* avatars.GenerateEmailAvatarFinalLink(email, size)
And many duplicated code are deleted in route handler, the handler and the model share the same avatar logic now.
2021-10-06 07:25:46 +08:00
|
|
|
func countFormalHeaders(h http.Header) (c int) {
|
|
|
|
|
for k := range h {
|
|
|
|
|
// ignore our headers for internal usage
|
|
|
|
|
if strings.HasPrefix(k, "X-Gitea-") {
|
|
|
|
|
continue
|
|
|
|
|
}
|
2023-01-14 08:16:30 +01:00
|
|
|
if strings.HasPrefix(k, "X-Forgejo-") {
|
|
|
|
|
continue
|
|
|
|
|
}
|
feat: Customização white-label para DATAWARE Forge e ajustes diversos
[PT-BR]
Este commit implementa a rebranding completa do Forgejo para DATAWARE Forge, integrando as seguintes alterações:
- Atualização de mensagens, textos, variáveis e endpoints em comandos e arquivos de configuração (ex.: dump, serv, app.ini, scripts Docker, serviço systemd) para refletir a nova identidade DATAWARE Forge.
- Modificação dos nomes de temas e das referências a “Forgejo” e “Gitea” para “DATAWARE Forge” em diversos módulos, headers de API, webhooks, e testes (incluindo X-DatawareForge-OTP e X-DatawareForge-Object-Type).
- Ajustes nos modelos de usuário e configurações do sistema para reservar novos nomes (ex.: dataware-actions, DATAWARE Actions) e atualizar emails institucionais.
- Atualização do package-lock.json para refletir o novo nome do projeto.
- Inclusão e adaptação dos temas especiais de acessibilidade (para deuteranopia/protanopia e tritanopia) em light e dark modes.
- Correções diversas em mensagens de log e validações para garantir a consistência com a nova marca.
Esta atualização consolida a customização white-label para uso interno e futura distribuição a clientes, mantendo os créditos e a integridade do código original.
[EN]
This commit implements the complete rebranding from Forgejo to DATAWARE Forge, integrating the following changes:
- Updated messages, text, variables, and endpoints in commands and configuration files (e.g., dump, serv, app.ini, Docker scripts, systemd service) to reflect the new DATAWARE Forge identity.
- Modified theme names and replaced references to “Forgejo” and “Gitea” with “DATAWARE Forge” throughout various modules, API headers, webhooks, and tests (including X-DatawareForge-OTP and X-DatawareForge-Object-Type).
- Adjusted user models and system settings to reserve new names (e.g., dataware-actions, DATAWARE Actions) and update institutional email addresses.
- Updated package-lock.json to reflect the new project name.
- Added and adapted special accessibility themes (for deuteranopia/protanopia and tritanopia) in both light and dark modes.
- Various fixes in log messages and validations to ensure consistency with the new branding.
This update consolidates the white-label customization for internal use and future client distribution while preserving the original credits and code integrity.
Marcos A. Lucas <mlucas@dataware.com.br>
2025-03-09 05:02:32 -03:00
|
|
|
if strings.HasPrefix(k, "X-DatawareForge-") {
|
|
|
|
|
continue
|
|
|
|
|
}
|
Avatar refactor, move avatar code from `models` to `models.avatars`, remove duplicated code (#17123)
Why this refactor
The goal is to move most files from `models` package to `models.xxx` package. Many models depend on avatar model, so just move this first.
And the existing logic is not clear, there are too many function like `AvatarLink`, `RelAvatarLink`, `SizedRelAvatarLink`, `SizedAvatarLink`, `MakeFinalAvatarURL`, `HashedAvatarLink`, etc. This refactor make everything clear:
* user.AvatarLink()
* user.AvatarLinkWithSize(size)
* avatars.GenerateEmailAvatarFastLink(email, size)
* avatars.GenerateEmailAvatarFinalLink(email, size)
And many duplicated code are deleted in route handler, the handler and the model share the same avatar logic now.
2021-10-06 07:25:46 +08:00
|
|
|
c++
|
|
|
|
|
}
|
|
|
|
|
return c
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-12 16:49:26 +02:00
|
|
|
func TestHandleGenericETagCache(t *testing.T) {
|
|
|
|
|
etag := `"test"`
|
|
|
|
|
|
|
|
|
|
t.Run("No_If-None-Match", func(t *testing.T) {
|
|
|
|
|
req := &http.Request{Header: make(http.Header)}
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
|
|
|
|
|
handled := HandleGenericETagCache(req, w, etag)
|
|
|
|
|
|
|
|
|
|
assert.False(t, handled)
|
Avatar refactor, move avatar code from `models` to `models.avatars`, remove duplicated code (#17123)
Why this refactor
The goal is to move most files from `models` package to `models.xxx` package. Many models depend on avatar model, so just move this first.
And the existing logic is not clear, there are too many function like `AvatarLink`, `RelAvatarLink`, `SizedRelAvatarLink`, `SizedAvatarLink`, `MakeFinalAvatarURL`, `HashedAvatarLink`, etc. This refactor make everything clear:
* user.AvatarLink()
* user.AvatarLinkWithSize(size)
* avatars.GenerateEmailAvatarFastLink(email, size)
* avatars.GenerateEmailAvatarFinalLink(email, size)
And many duplicated code are deleted in route handler, the handler and the model share the same avatar logic now.
2021-10-06 07:25:46 +08:00
|
|
|
assert.Equal(t, 2, countFormalHeaders(w.Header()))
|
2021-04-12 16:49:26 +02:00
|
|
|
assert.Contains(t, w.Header(), "Cache-Control")
|
|
|
|
|
assert.Contains(t, w.Header(), "Etag")
|
|
|
|
|
assert.Equal(t, etag, w.Header().Get("Etag"))
|
|
|
|
|
})
|
|
|
|
|
t.Run("Wrong_If-None-Match", func(t *testing.T) {
|
|
|
|
|
req := &http.Request{Header: make(http.Header)}
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
|
|
|
|
|
req.Header.Set("If-None-Match", `"wrong etag"`)
|
|
|
|
|
|
|
|
|
|
handled := HandleGenericETagCache(req, w, etag)
|
|
|
|
|
|
|
|
|
|
assert.False(t, handled)
|
Avatar refactor, move avatar code from `models` to `models.avatars`, remove duplicated code (#17123)
Why this refactor
The goal is to move most files from `models` package to `models.xxx` package. Many models depend on avatar model, so just move this first.
And the existing logic is not clear, there are too many function like `AvatarLink`, `RelAvatarLink`, `SizedRelAvatarLink`, `SizedAvatarLink`, `MakeFinalAvatarURL`, `HashedAvatarLink`, etc. This refactor make everything clear:
* user.AvatarLink()
* user.AvatarLinkWithSize(size)
* avatars.GenerateEmailAvatarFastLink(email, size)
* avatars.GenerateEmailAvatarFinalLink(email, size)
And many duplicated code are deleted in route handler, the handler and the model share the same avatar logic now.
2021-10-06 07:25:46 +08:00
|
|
|
assert.Equal(t, 2, countFormalHeaders(w.Header()))
|
2021-04-12 16:49:26 +02:00
|
|
|
assert.Contains(t, w.Header(), "Cache-Control")
|
|
|
|
|
assert.Contains(t, w.Header(), "Etag")
|
|
|
|
|
assert.Equal(t, etag, w.Header().Get("Etag"))
|
|
|
|
|
})
|
|
|
|
|
t.Run("Correct_If-None-Match", func(t *testing.T) {
|
|
|
|
|
req := &http.Request{Header: make(http.Header)}
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
|
|
|
|
|
req.Header.Set("If-None-Match", etag)
|
|
|
|
|
|
|
|
|
|
handled := HandleGenericETagCache(req, w, etag)
|
|
|
|
|
|
|
|
|
|
assert.True(t, handled)
|
Avatar refactor, move avatar code from `models` to `models.avatars`, remove duplicated code (#17123)
Why this refactor
The goal is to move most files from `models` package to `models.xxx` package. Many models depend on avatar model, so just move this first.
And the existing logic is not clear, there are too many function like `AvatarLink`, `RelAvatarLink`, `SizedRelAvatarLink`, `SizedAvatarLink`, `MakeFinalAvatarURL`, `HashedAvatarLink`, etc. This refactor make everything clear:
* user.AvatarLink()
* user.AvatarLinkWithSize(size)
* avatars.GenerateEmailAvatarFastLink(email, size)
* avatars.GenerateEmailAvatarFinalLink(email, size)
And many duplicated code are deleted in route handler, the handler and the model share the same avatar logic now.
2021-10-06 07:25:46 +08:00
|
|
|
assert.Equal(t, 1, countFormalHeaders(w.Header()))
|
2021-04-12 16:49:26 +02:00
|
|
|
assert.Contains(t, w.Header(), "Etag")
|
|
|
|
|
assert.Equal(t, etag, w.Header().Get("Etag"))
|
|
|
|
|
assert.Equal(t, http.StatusNotModified, w.Code)
|
|
|
|
|
})
|
|
|
|
|
t.Run("Multiple_Wrong_If-None-Match", func(t *testing.T) {
|
|
|
|
|
req := &http.Request{Header: make(http.Header)}
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
|
|
|
|
|
req.Header.Set("If-None-Match", `"wrong etag", "wrong etag "`)
|
|
|
|
|
|
|
|
|
|
handled := HandleGenericETagCache(req, w, etag)
|
|
|
|
|
|
|
|
|
|
assert.False(t, handled)
|
Avatar refactor, move avatar code from `models` to `models.avatars`, remove duplicated code (#17123)
Why this refactor
The goal is to move most files from `models` package to `models.xxx` package. Many models depend on avatar model, so just move this first.
And the existing logic is not clear, there are too many function like `AvatarLink`, `RelAvatarLink`, `SizedRelAvatarLink`, `SizedAvatarLink`, `MakeFinalAvatarURL`, `HashedAvatarLink`, etc. This refactor make everything clear:
* user.AvatarLink()
* user.AvatarLinkWithSize(size)
* avatars.GenerateEmailAvatarFastLink(email, size)
* avatars.GenerateEmailAvatarFinalLink(email, size)
And many duplicated code are deleted in route handler, the handler and the model share the same avatar logic now.
2021-10-06 07:25:46 +08:00
|
|
|
assert.Equal(t, 2, countFormalHeaders(w.Header()))
|
2021-04-12 16:49:26 +02:00
|
|
|
assert.Contains(t, w.Header(), "Cache-Control")
|
|
|
|
|
assert.Contains(t, w.Header(), "Etag")
|
|
|
|
|
assert.Equal(t, etag, w.Header().Get("Etag"))
|
|
|
|
|
})
|
|
|
|
|
t.Run("Multiple_Correct_If-None-Match", func(t *testing.T) {
|
|
|
|
|
req := &http.Request{Header: make(http.Header)}
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
|
|
|
|
|
req.Header.Set("If-None-Match", `"wrong etag", `+etag)
|
|
|
|
|
|
|
|
|
|
handled := HandleGenericETagCache(req, w, etag)
|
|
|
|
|
|
|
|
|
|
assert.True(t, handled)
|
Avatar refactor, move avatar code from `models` to `models.avatars`, remove duplicated code (#17123)
Why this refactor
The goal is to move most files from `models` package to `models.xxx` package. Many models depend on avatar model, so just move this first.
And the existing logic is not clear, there are too many function like `AvatarLink`, `RelAvatarLink`, `SizedRelAvatarLink`, `SizedAvatarLink`, `MakeFinalAvatarURL`, `HashedAvatarLink`, etc. This refactor make everything clear:
* user.AvatarLink()
* user.AvatarLinkWithSize(size)
* avatars.GenerateEmailAvatarFastLink(email, size)
* avatars.GenerateEmailAvatarFinalLink(email, size)
And many duplicated code are deleted in route handler, the handler and the model share the same avatar logic now.
2021-10-06 07:25:46 +08:00
|
|
|
assert.Equal(t, 1, countFormalHeaders(w.Header()))
|
2021-04-12 16:49:26 +02:00
|
|
|
assert.Contains(t, w.Header(), "Etag")
|
|
|
|
|
assert.Equal(t, etag, w.Header().Get("Etag"))
|
|
|
|
|
assert.Equal(t, http.StatusNotModified, w.Code)
|
|
|
|
|
})
|
|
|
|
|
}
|