From 722797fa1c072a83af362ca7d07dea87ba907546 Mon Sep 17 00:00:00 2001 From: poyo Date: Sat, 25 Jul 2026 01:49:16 +0200 Subject: [PATCH] disable anonymous comments --- app/repo-issues.go | 11 ++++++----- views/repo/issues/view_issue.html | 31 ++++++++++++++++++------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/app/repo-issues.go b/app/repo-issues.go index c5f5204..7381b3d 100644 --- a/app/repo-issues.go +++ b/app/repo-issues.go @@ -37,8 +37,7 @@ type repoNewIssueForm struct { } type createIssueCommentForm struct { - Comment string `form:"comment" validate:"required,min=30,max=3000"` - SubmitAnonymously bool `form:"submit_anonymously" validate:"boolean"` + Comment string `form:"comment" validate:"required,min=30,max=3000"` } func (a *App) repoIssueReport(w http.ResponseWriter, r *http.Request) { @@ -154,9 +153,11 @@ func (a *App) repoIssueView(w http.ResponseWriter, r *http.Request) { Comment: form.Comment, } - user, ok := r.Context().Value(lib.UserKey).(*types.User) // make sure user isn't nil. otherwise this will error badly since it can't assign *types.User to nothing. - if ok && !form.SubmitAnonymously { - issueComment.UserID = &user.ID + user, ok := r.Context().Value(lib.UserKey).(*types.User) + if !ok || user == nil { + // needs to be logged in. + http.Redirect(w, r, "/auth/login?RequireAuth", http.StatusSeeOther) + return } err := a.DB.NewIssueComment(&issueComment) diff --git a/views/repo/issues/view_issue.html b/views/repo/issues/view_issue.html index 3a90076..7149941 100644 --- a/views/repo/issues/view_issue.html +++ b/views/repo/issues/view_issue.html @@ -1,17 +1,21 @@ {{ define "content" }} -
- #{{.Issue.IssueID}} - {{.Issue.Title}} - Submitted by {{if .Issue.User}}~{{.Issue.User.Handle}}{{else}} someone anonymous.{{end}} -
-

{{.Issue.Description}}

+
+
+ #{{.Issue.IssueID}} - {{.Issue.Title}} + Submitted by {{if .Issue.User}}~{{.Issue.User.Handle}}{{else}} someone + anonymous.{{end}} +
+

{{.Issue.Description}}

-
- {{range .IssueComments}} -
- {{if .User}}~{{.User.Handle}}{{else}}Anonymous{{end}} on {{.CreatedAtFormatted}} -

{{.Comment}}

+
+ {{range .IssueComments}} +
+ {{if .User}}~{{.User.Handle}}{{else}}Anonymous{{end}} on + {{.CreatedAtFormatted}} +

{{.Comment}}

+
+ {{end}}
- {{end}}
@@ -19,8 +23,9 @@ {{if .loggedIn}} - + + {{else}} +

You need to be logged in in order to contribute to this conversation.

{{end}} -
{{end}} \ No newline at end of file -- 2.54.0