Compare commits

..

22 Commits

Author SHA1 Message Date
Giteabot 0f23219ee4 fix: http content file render (#37850) (#37856)
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
PR RC Release / Build RC Release (pull_request) Successful in 2s
Backport #37850

Fix #37849

Signed-off-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: TheFox0x7 <thefox0x7@gmail.com>
2026-05-26 12:54:37 -05:00
jmiller bc475c91f6 Merge pull request 'feat: login notification via email and ntfy' (#209) from feat/login-notifications into dev
Branch Policy Check / Verify merge target (pull_request) Successful in 2s
PR RC Release / Build RC Release (pull_request) Successful in 21s
2026-05-26 16:40:51 +00:00
Jonathan Miller 25268d7dd7 feat: login notification via email and ntfy on successful sign-in
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
PR RC Release / Build RC Release (pull_request) Successful in 2s
When a user signs in, sends notifications with username, IP address,
user agent, and timestamp. Notifications go through:
- Email to the user's registered address
- ntfy push to the configured topic

Enabled by default, configurable via app.ini:
  [login_notification]
  ENABLED = true

The notification fires asynchronously (goroutine) so it doesn't
block the login redirect. Hooks into handleSignInFull which is the
single choke point for all auth methods (password, 2FA, OAuth).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-26 11:39:44 -05:00
jmiller c7193abc0c Merge pull request 'fix: help link in footer, login logo on signin page' (#205) from fix/help-footer-login-logo into dev
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
PR RC Release / Build RC Release (pull_request) Successful in 22s
2026-05-26 04:52:00 +00:00
Jonathan Miller e6a4dfccf0 fix(ui): add help link to footer, show login logo on signin page
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
PR RC Release / Build RC Release (pull_request) Successful in 2s
- Help link added to footer right-links (next to API and Licenses)
- Login logo (login-logo.png) now shown on the signin page, not just
  the home page. Hidden via onerror when not uploaded.
- Landing page is set to 'login' so home.tmpl never renders — the
  logo needed to be on signin_inner.tmpl instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-25 23:51:37 -05:00
jmiller a5c805b0f6 Merge pull request 'fix(ui): show help link for all users' (#204) from fix/help-link-always-visible into dev
Branch Policy Check / Verify merge target (pull_request) Successful in 2s
PR RC Release / Build RC Release (pull_request) Successful in 24s
2026-05-26 04:45:56 +00:00
Jonathan Miller 46ce0a7e32 fix(ui): show help link in navbar for all users, not just anonymous
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
PR RC Release / Build RC Release (pull_request) Successful in 2s
The help link was wrapped in {{if not .IsSigned}} which hid it for
logged-in users. Removed the condition so it's always visible.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-25 23:45:49 -05:00
jmiller c236c4e018 Merge pull request 'fix(ui): replace missing octicon-dashboard icon' (#202) from fix/missing-dashboard-icon into dev
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
PR RC Release / Build RC Release (pull_request) Successful in 20s
2026-05-26 04:39:00 +00:00
Jonathan Miller b79b48b760 fix(ui): replace missing octicon-dashboard with octicon-meter
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
PR RC Release / Build RC Release (pull_request) Successful in 2s
octicon-dashboard doesn't exist in Gitea's SVG set, causing the
icon to render as raw text. octicon-meter is the equivalent gauge icon.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-25 23:38:53 -05:00
jmiller 22a529dfd8 Merge pull request 'rc: admin nav CSS fix' (#201) from rc/05.03.05 into main 2026-05-26 04:30:31 +00:00
jmiller 09dc64eef0 Merge pull request 'fix(ui): admin sidebar left-align CSS' (#200) from fix/admin-nav-css into dev
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
PR RC Release / Build RC Release (pull_request) Successful in 22s
2026-05-26 04:30:13 +00:00
Jonathan Miller d541a07263 fix(ui): left-align admin sidebar — fix justify-content and text-align
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
PR RC Release / Build RC Release (pull_request) Successful in 2s
Changed details.toggleable-item summary from justify-content:
space-between to gap + margin-left: auto on the chevron. Added
.flex-container-nav .item rule to force left alignment on all
menu items including standalone links.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-25 23:29:52 -05:00
jmiller 2eee4bbf1c Merge pull request 'rc: admin nav left align' (#199) from rc/05.03.04 into main 2026-05-26 03:57:55 +00:00
jmiller 2dea95a431 Merge pull request 'fix(ui): force left-align admin sidebar' (#198) from fix/admin-nav-left-align into dev
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
PR RC Release / Build RC Release (pull_request) Successful in 21s
2026-05-26 03:57:36 +00:00
Jonathan Miller f69212859a fix(ui): force left-align on admin sidebar menu via inline style
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
PR RC Release / Build RC Release (pull_request) Successful in 2s
The compiled CSS bundle doesn't pick up the flexcontainer.css change.
Use inline style with !important on the menu container to override
Fomantic UI's default center alignment.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-25 22:57:30 -05:00
jmiller 3828411311 Merge pull request 'rc: admin nav alignment' (#197) from rc/05.03.03 into main 2026-05-26 03:48:02 +00:00
jmiller 447a45ec15 Merge pull request 'fix(ui): left-align admin sidebar menu items' (#196) from fix/admin-nav-alignment into dev
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
PR RC Release / Build RC Release (pull_request) Successful in 25s
2026-05-26 03:47:43 +00:00
Jonathan Miller f19fd9683f fix(ui): left-align all admin sidebar menu items
Branch Policy Check / Verify merge target (pull_request) Successful in 2s
PR RC Release / Build RC Release (pull_request) Successful in 2s
Fomantic UI's vertical menu centers text by default. Added
text-align: left to .flex-container-nav menu items so all
admin sidebar entries align consistently.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-25 22:47:36 -05:00
jmiller 039ab896cc Merge pull request 'rc: per-file checksums + login logo fix' (#195) from rc/05.03.02 into main 2026-05-26 03:37:00 +00:00
jmiller 65660863d6 Merge pull request 'fix: per-file sha256 checksums' (#194) from fix/checksum-per-file into dev
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
PR RC Release / Build RC Release (pull_request) Successful in 21s
2026-05-26 03:36:45 +00:00
Jonathan Miller 198ae92579 fix: generate per-file [filename].sha256 instead of single manifest
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
PR RC Release / Build RC Release (pull_request) Successful in 2s
Each release attachment now gets its own .sha256 checksum file
(e.g. asset.zip.sha256) instead of a single checksums.sha256 manifest.
Old .sha256 files are cleaned up before regenerating.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-25 22:35:51 -05:00
jmiller bc4eae2e0f Merge pull request 'rc: login logo default none' (#193) from rc/05.03.01 into main 2026-05-26 03:28:57 +00:00
12 changed files with 160 additions and 37 deletions
+14 -2
View File
@@ -63,7 +63,7 @@ func TestFile(t *testing.T) {
{
name: "tags.py",
code: "<>",
want: lines(`<span class="o">&lt;</span><span class="o">&gt;</span>`),
want: lines(`<span class="o">&lt;&gt;</span>`),
lexerName: "Python",
},
{
@@ -102,7 +102,7 @@ c=2
<span class="n">def</span><span class="p">:</span>\n
<span class="n">a</span><span class="o">=</span><span class="mi">1</span>\n
\n
<span class="n">b</span><span class="o">=</span><span class="sa"></span><span class="s1">&#39;</span><span class="s1">&#39;</span>\n
<span class="n">b</span><span class="o">=</span><span class="s1">&#39;&#39;</span>\n
\n
<span class="n">c</span><span class="o">=</span><span class="mi">2</span>`,
),
@@ -114,6 +114,18 @@ c=2
want: []template.HTML{"<span class=\"c1\">--\n</span>", `<span class="k">SELECT</span>`},
lexerName: "SQL",
},
{
name: "test.http",
code: `HTTP/1.0 400 Bad request
Content-Type: text/html
<html></html>`,
want: lines(`<span class="kr">HTTP</span><span class="o">/</span><span class="m">1.0</span> <span class="m">400</span> <span class="ne">Bad request</span>\n
<span class="n">Content-Type</span><span class="o">:</span> <span class="l">text/html</span>\n
\n
<span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;&lt;/</span><span class="nt">html</span><span class="p">&gt;</span>`),
lexerName: "HTTP",
},
}
for _, tt := range tests {
+4 -4
View File
@@ -288,24 +288,24 @@ func detectChromaLexerWithAnalyze(fileName, lang string, code []byte) chroma.Lex
// if lang is provided, and it matches a lexer, use it directly
if byLang {
return lexer
return chroma.Coalesce(lexer)
}
// if a lexer is detected and there is no conflict for the file extension, use it directly
fileExt := path.Ext(fileName)
_, hasConflicts := chromaLexers().conflictingExtLangMap[fileExt]
if !hasConflicts && lexer != lexers.Fallback {
return lexer
return chroma.Coalesce(lexer)
}
// try to detect language by content, for best guessing for the language
// when using "code" to detect, analyze.GetCodeLanguage is slow, it iterates many rules to detect language from content
analyzedLanguage := analyze.GetCodeLanguage(fileName, code)
lexer = DetectChromaLexerByFileName(fileName, analyzedLanguage)
lexer, _ = detectChromaLexerByFileName(fileName, analyzedLanguage)
if lexer == lexers.Fallback {
if analyzedLanguage != enry.OtherLanguage {
log.Warn("No chroma lexer found for enry detected language: %s (file: %s), need to fix the language mapping between enry and chroma.", analyzedLanguage, fileName)
}
}
return lexer
return chroma.Coalesce(lexer)
}
+13
View File
@@ -39,6 +39,13 @@ var (
Channel: "stable",
}
// LoginNotification configuration for sign-in alerts
LoginNotification = struct {
Enabled bool
}{
Enabled: true,
}
// IsInTesting indicates whether the testing is running (unit test or integration test). It can be used for:
// * Skip nonsense error logs during testing caused by unreliable code (TODO: this is only a temporary solution, we should make the test code more reliable)
// * Panic in dev or testing mode to make the problem more obvious and easier to debug
@@ -171,6 +178,7 @@ func loadCommonSettingsFrom(cfg ConfigProvider) error {
loadOtherFrom(cfg)
loadUpdateCheckerFrom(cfg)
loadNtfyFrom(cfg)
loadLoginNotificationFrom(cfg)
return nil
}
@@ -181,6 +189,11 @@ func loadUpdateCheckerFrom(cfg ConfigProvider) {
UpdateChecker.Channel = sec.Key("CHANNEL").MustString(UpdateChecker.Channel)
}
func loadLoginNotificationFrom(cfg ConfigProvider) {
sec := cfg.Section("login_notification")
LoginNotification.Enabled = sec.Key("ENABLED").MustBool(true)
}
func loadRunModeFrom(rootCfg ConfigProvider) {
rootSec := rootCfg.Section("")
RunUser = rootSec.Key("RUN_USER").MustString(user.CurrentUsername())
+3
View File
@@ -440,6 +440,9 @@ func handleSignInFull(ctx *context.Context, u *user_model.User, remember bool) {
ctx.ServerError("UpdateUser", err)
return
}
// Send login notification (email + ntfy)
go mailer.SendLoginNotification(u, ctx.RemoteAddr(), ctx.Req.UserAgent())
}
// extractUserNameFromOAuth2 tries to extract a normalized username from the given OAuth2 user.
+84
View File
@@ -0,0 +1,84 @@
// Copyright 2026 Moko Consulting <hello@mokoconsulting.tech>
// SPDX-License-Identifier: GPL-3.0-or-later
package mailer
import (
"bytes"
"fmt"
"io"
"net/http"
"time"
user_model "git.mokoconsulting.tech/MokoConsulting/MokoGitea/models/user"
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/log"
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/setting"
sender_service "git.mokoconsulting.tech/MokoConsulting/MokoGitea/services/mailer/sender"
)
// SendLoginNotification sends email and ntfy notifications when a user signs in.
func SendLoginNotification(u *user_model.User, ip, userAgent string) {
if !setting.LoginNotification.Enabled {
return
}
timestamp := time.Now().UTC().Format("2006-01-02 15:04:05 UTC")
subject := fmt.Sprintf("[%s] New sign-in: %s", setting.AppName, u.Name)
body := fmt.Sprintf(`New sign-in detected
Account: %s (%s)
IP Address: %s
Browser: %s
Time: %s
Instance: %s
If this wasn't you, change your password immediately and review your active sessions.
— %s`, u.Name, u.Email, ip, userAgent, timestamp, setting.AppURL, setting.AppName)
// Email notification
if setting.MailService != nil && u.Email != "" {
msg := sender_service.NewMessage(u.EmailTo(), subject, body)
msg.Info = fmt.Sprintf("Login notification for %s", u.Name)
SendAsync(msg)
log.Debug("Login notification email sent to %s", u.Email)
}
// ntfy push notification
if setting.Ntfy.Enabled && setting.Ntfy.ServerURL != "" {
go sendLoginNtfy(subject, u.Name, ip, timestamp)
}
}
func sendLoginNtfy(title, username, ip, timestamp string) {
body := fmt.Sprintf("User: %s\nIP: %s\nTime: %s", username, ip, timestamp)
url := fmt.Sprintf("%s/%s", setting.Ntfy.ServerURL, setting.Ntfy.DefaultTopic)
req, err := http.NewRequest("POST", url, bytes.NewBufferString(body))
if err != nil {
log.Error("ntfy login: create request: %v", err)
return
}
req.Header.Set("Title", title)
req.Header.Set("Priority", "default")
req.Header.Set("Tags", "key,login")
req.Header.Set("Click", setting.AppURL+"-/admin")
if setting.Ntfy.Token != "" {
req.Header.Set("Authorization", "Bearer "+setting.Ntfy.Token)
}
client := &http.Client{Timeout: 10 * time.Second}
resp, err := client.Do(req)
if err != nil {
log.Error("ntfy login: send: %v", err)
return
}
defer resp.Body.Close()
io.Copy(io.Discard, resp.Body)
if resp.StatusCode >= 300 {
log.Error("ntfy login: status %d", resp.StatusCode)
}
}
+24 -25
View File
@@ -9,6 +9,7 @@ import (
"crypto/sha256"
"fmt"
"io"
"strings"
repo_model "git.mokoconsulting.tech/MokoConsulting/MokoGitea/models/repo"
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/log"
@@ -17,9 +18,8 @@ import (
)
// GenerateReleaseChecksums computes SHA256 checksums for all attachments
// on a release and adds a checksums.sha256 manifest file as an attachment.
// on a release and creates a [filename].sha256 file for each one.
func GenerateReleaseChecksums(ctx context.Context, rel *repo_model.Release) error {
// Load attachments into rel.Attachments
if err := repo_model.GetReleaseAttachments(ctx, rel); err != nil {
return fmt.Errorf("GetReleaseAttachments: %w", err)
}
@@ -28,20 +28,19 @@ func GenerateReleaseChecksums(ctx context.Context, rel *repo_model.Release) erro
return nil
}
// Remove existing checksums file if present
// Remove existing .sha256 files
for _, a := range rel.Attachments {
if a.Name == "checksums.sha256" {
if strings.HasSuffix(a.Name, ".sha256") {
if err := repo_model.DeleteAttachment(ctx, a, true); err != nil {
log.Warn("Failed to delete old checksums.sha256: %v", err)
log.Warn("Failed to delete old %s: %v", a.Name, err)
}
break
}
}
// Compute SHA256 for each attachment
var manifest bytes.Buffer
// Compute SHA256 for each non-checksum attachment and create individual .sha256 files
created := 0
for _, a := range rel.Attachments {
if a.Name == "checksums.sha256" {
if strings.HasSuffix(a.Name, ".sha256") {
continue
}
@@ -59,24 +58,24 @@ func GenerateReleaseChecksums(ctx context.Context, rel *repo_model.Release) erro
}
fr.Close()
fmt.Fprintf(&manifest, "%x %s\n", h.Sum(nil), a.Name)
checksumContent := fmt.Sprintf("%x %s\n", h.Sum(nil), a.Name)
checksumReader := bytes.NewBufferString(checksumContent)
checksumAttach := &repo_model.Attachment{
RepoID: rel.RepoID,
ReleaseID: rel.ID,
Name: a.Name + ".sha256",
}
if _, err := attachment_service.NewAttachment(ctx, checksumAttach, checksumReader, int64(len(checksumContent))); err != nil {
log.Warn("Failed to create %s: %v", checksumAttach.Name, err)
continue
}
created++
}
if manifest.Len() == 0 {
return nil
if created > 0 {
log.Info("Generated %d .sha256 checksum files for release %s (repo %d)", created, rel.TagName, rel.RepoID)
}
// Create the checksums.sha256 attachment
checksumAttach := &repo_model.Attachment{
RepoID: rel.RepoID,
ReleaseID: rel.ID,
Name: "checksums.sha256",
}
if _, err := attachment_service.NewAttachment(ctx, checksumAttach, &manifest, int64(manifest.Len())); err != nil {
return fmt.Errorf("create checksums.sha256 attachment: %w", err)
}
log.Info("Generated checksums.sha256 for release %s (repo %d)", rel.TagName, rel.RepoID)
return nil
}
+2 -2
View File
@@ -1,12 +1,12 @@
<div class="flex-container-nav">
<div class="ui fluid vertical menu">
<div class="ui fluid vertical menu" style="text-align: left !important;">
<div class="header item">{{ctx.Locale.Tr "admin.settings"}}</div>
<details class="item toggleable-item" {{if or .PageIsAdminDashboard .PageIsAdminSelfCheck}}open{{end}}>
<summary>{{svg "octicon-tools" 16}} {{ctx.Locale.Tr "admin.maintenance"}}</summary>
<div class="menu">
<a class="{{if .PageIsAdminDashboard}}active {{end}}item" href="{{AppSubUrl}}/-/admin">
{{svg "octicon-dashboard" 16}} {{ctx.Locale.Tr "admin.dashboard"}}
{{svg "octicon-meter" 16}} {{ctx.Locale.Tr "admin.dashboard"}}
</a>
<a class="{{if .PageIsAdminSelfCheck}}active {{end}}item" href="{{AppSubUrl}}/-/admin/self_check">
{{svg "octicon-check-circle" 16}} {{ctx.Locale.Tr "admin.self_check"}}
+1
View File
@@ -36,6 +36,7 @@
</div>
<a href="{{AssetUrlPrefix}}/licenses.txt">{{ctx.Locale.Tr "licenses"}}</a>
{{if .EnableSwagger}}<a href="{{AppSubUrl}}/api/swagger">API</a>{{end}}
<a href="{{HelpURL}}" target="_blank">{{ctx.Locale.Tr "help"}}</a>
{{template "custom/extra_links_footer" .}}
</div>
</footer>
+1 -3
View File
@@ -35,9 +35,7 @@
{{template "custom/extra_links" .}}
{{if not .IsSigned}}
<a class="item" target="_blank" href="{{HelpURL}}">{{ctx.Locale.Tr "help"}}</a>
{{end}}
<a class="item" target="_blank" href="{{HelpURL}}">{{ctx.Locale.Tr "help"}}</a>
</div>
<!-- the full dropdown menus -->
+3
View File
@@ -1,4 +1,7 @@
<div class="ui container fluid">
<div class="tw-text-center tw-mb-4">
<img src="{{AssetUrlPrefix}}/img/login-logo.png" style="max-width: 220px; max-height: 80px; object-fit: contain;" onerror="this.style.display='none'">
</div>
{{if or (not .LinkAccountMode) (and .LinkAccountMode .LinkAccountModeSignIn)}}
{{template "base/alert" .}}
{{end}}
+4
View File
@@ -11,6 +11,10 @@
width: 240px;
}
.flex-container-nav .ui.menu .item {
text-align: left;
}
/* wide sidebar on the right, used in frontpage */
.flex-container-sidebar {
width: 35%;
+7 -1
View File
@@ -9,8 +9,8 @@ details.toggleable-item .menu {
details.toggleable-item summary {
display: flex;
justify-content: space-between;
align-items: center;
gap: 0.5em;
padding: 0.92857143em 1.14285714em;
}
@@ -20,6 +20,7 @@ details.toggleable-item summary::-webkit-details-marker /* Safari */ {
}
details.toggleable-item summary::after {
margin-left: auto;
transition: transform 0.25s ease;
content: "";
width: 14px;
@@ -35,3 +36,8 @@ details.toggleable-item summary::after {
details.toggleable-item[open] summary::after {
transform: rotate(90deg);
}
.flex-container-nav .ui.menu .item {
text-align: left !important;
justify-content: flex-start !important;
}