mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-25 06:03:40 +09:00
refactor: "install" page (#39400)
1. remove useless options 2. set AppDataPath instead of repo root path 3. make "disable self-registration" default enabled 4. avoid writing corrupted ini file 5. avoid auto-sign-in the existing admin user
This commit is contained in:
@@ -28,15 +28,12 @@ type InstallForm struct {
|
||||
DbPath string `binding:"TrimSpace"`
|
||||
DbSchema string `binding:"TrimSpace"`
|
||||
|
||||
AppName string `binding:"TrimSpace;Required" locale:"install.app_name"`
|
||||
RepoRootPath string `binding:"TrimSpace;Required"`
|
||||
LFSRootPath string `binding:"TrimSpace"`
|
||||
RunUser string `binding:"TrimSpace;Required"`
|
||||
Domain string `binding:"TrimSpace;Required"`
|
||||
SSHPort int
|
||||
HTTPPort string `binding:"TrimSpace;Required"`
|
||||
AppURL string `binding:"TrimSpace;Required"`
|
||||
LogRootPath string `binding:"TrimSpace;Required"`
|
||||
AppName string `binding:"TrimSpace;Required" locale:"install.app_name"`
|
||||
AppDataPath string `binding:"TrimSpace;Required"`
|
||||
RunUser string `binding:"TrimSpace;Required"`
|
||||
SSHPort int
|
||||
HTTPPort string `binding:"TrimSpace;Required"`
|
||||
AppURL string `binding:"TrimSpace;Required"`
|
||||
|
||||
SMTPAddr string `binding:"TrimSpace"`
|
||||
SMTPPort string `binding:"TrimSpace"`
|
||||
@@ -46,24 +43,18 @@ type InstallForm struct {
|
||||
RegisterConfirm bool
|
||||
MailNotify bool
|
||||
|
||||
EnableOpenIDSignIn bool
|
||||
EnableOpenIDSignUp bool
|
||||
DisableRegistration bool
|
||||
AllowOnlyExternalRegistration bool
|
||||
EnableCaptcha bool
|
||||
RequireSignInView bool
|
||||
DefaultKeepEmailPrivate bool
|
||||
DefaultAllowCreateOrganization bool
|
||||
DefaultEnableTimetracking bool
|
||||
EnableUpdateChecker bool
|
||||
NoReplyAddress string `binding:"TrimSpace"`
|
||||
|
||||
PasswordAlgorithm string `binding:"TrimSpace"`
|
||||
|
||||
AdminName string `binding:"TrimSpace;OmitEmpty;Username;MaxSize(30)" locale:"install.admin_name"`
|
||||
AdminPasswd string `binding:"OmitEmpty;MaxSize(255)" locale:"install.admin_password"`
|
||||
AdminName string `binding:"TrimSpace;Username;MaxSize(30)" locale:"install.admin_name"`
|
||||
AdminPasswd string `binding:"MaxSize(255)" locale:"install.admin_password"`
|
||||
AdminConfirmPasswd string
|
||||
AdminEmail string `binding:"TrimSpace;OmitEmpty;MinSize(3);MaxSize(254);Include(@)" locale:"install.admin_email"`
|
||||
AdminEmail string `binding:"TrimSpace;MinSize(3);MaxSize(254);Include(@)" locale:"install.admin_email"`
|
||||
|
||||
// ReinstallConfirmFirst we can not use 1/2/3 or A/B/C here, there is a framework bug, can not parse "reinstall_confirm_1" or "reinstall_confirm_a"
|
||||
ReinstallConfirmFirst bool
|
||||
|
||||
@@ -308,7 +308,7 @@ func searchTokenInHeaders(env *enmime.Envelope) string {
|
||||
if end == -1 || begin > end {
|
||||
break
|
||||
}
|
||||
t := extractToken(references[begin:end], "reply-", "@"+setting.Domain)
|
||||
t := extractToken(references[begin:end], "reply-", "@"+setting.AppDomain)
|
||||
if t != "" {
|
||||
return t
|
||||
}
|
||||
|
||||
@@ -71,8 +71,8 @@ func TestIsAutomaticReply(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSearchTokenInHeadersCaseInsensitive(t *testing.T) {
|
||||
setting.AppDomain = "DoMain.com"
|
||||
setting.IncomingEmail.ReplyToAddress = "InComing+%{token}@ExAmPle.com"
|
||||
setting.Domain = "DoMain.com"
|
||||
mkEnv := func(s string) *enmime.Envelope {
|
||||
env, _ := enmime.ReadEnvelope(strings.NewReader(s + "\r\n\r\n"))
|
||||
return env
|
||||
|
||||
@@ -162,7 +162,7 @@ func fromDisplayName(u *user_model.User) string {
|
||||
err := setting.MailService.FromDisplayNameFormatTemplate.Execute(&buf, map[string]any{
|
||||
"DisplayName": u.DisplayName(),
|
||||
"AppName": setting.AppName,
|
||||
"Domain": setting.Domain,
|
||||
"Domain": setting.AppDomain,
|
||||
})
|
||||
if err == nil {
|
||||
return mime.QEncoding.Encode("utf-8", buf.String())
|
||||
@@ -180,7 +180,7 @@ func fromDisplayName(u *user_model.User) string {
|
||||
func generateMetadataHeaders(repo *repo_model.Repository) map[string]string {
|
||||
return map[string]string{
|
||||
// https://datatracker.ietf.org/doc/html/rfc2919
|
||||
"List-ID": fmt.Sprintf("%s <%s.%s.%s>", repo.FullName(), repo.Name, repo.OwnerName, setting.Domain),
|
||||
"List-ID": fmt.Sprintf("%s <%s.%s.%s>", repo.FullName(), repo.Name, repo.OwnerName, setting.AppDomain),
|
||||
|
||||
// https://datatracker.ietf.org/doc/html/rfc2369
|
||||
"List-Archive": fmt.Sprintf("<%s>", repo.HTMLURL()),
|
||||
|
||||
@@ -188,7 +188,7 @@ func composeIssueCommentMessages(ctx context.Context, comment *mailComment, lang
|
||||
msg.ReplyTo = replyAddress
|
||||
msg.SetHeader("List-Post", fmt.Sprintf("<mailto:%s>", replyAddress))
|
||||
|
||||
references = append(references, fmt.Sprintf("<reply-%s@%s>", token, setting.Domain))
|
||||
references = append(references, fmt.Sprintf("<reply-%s@%s>", token, setting.AppDomain))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ func generateMessageIDForIssue(issue *issues_model.Issue, comment *issues_model.
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Sprintf("<%s/%s/%d%s@%s>", issue.Repo.FullName(), path, issue.Index, extra, setting.Domain)
|
||||
return fmt.Sprintf("<%s/%s/%d%s@%s>", issue.Repo.FullName(), path, issue.Index, extra, setting.AppDomain)
|
||||
}
|
||||
|
||||
func generateAdditionalHeadersForIssue(ctx context.Context, comment *mailComment, reason string, recipient *user_model.User) map[string]string {
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
const tplNewReleaseMail templates.TplName = "mail/repo/release"
|
||||
|
||||
func generateMessageIDForRelease(release *repo_model.Release) string {
|
||||
return fmt.Sprintf("<%s/releases/%d@%s>", release.Repo.FullName(), release.ID, setting.Domain)
|
||||
return fmt.Sprintf("<%s/releases/%d@%s>", release.Repo.FullName(), release.ID, setting.AppDomain)
|
||||
}
|
||||
|
||||
// MailNewRelease send new release notify to all repo watchers.
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestMailNewReleaseFiltersUnauthorizedWatchers(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
defer test.MockVariableValue(&setting.MailService)()
|
||||
defer test.MockVariableValue(&setting.Domain)()
|
||||
defer test.MockVariableValue(&setting.AppDomain)()
|
||||
defer test.MockVariableValue(&setting.AppName)()
|
||||
defer test.MockVariableValue(&setting.AppURL)()
|
||||
|
||||
@@ -29,7 +29,6 @@ func TestMailNewReleaseFiltersUnauthorizedWatchers(t *testing.T) {
|
||||
From: "Gitea",
|
||||
FromEmail: "noreply@example.com",
|
||||
}
|
||||
setting.Domain = "example.com"
|
||||
setting.AppName = "Gitea"
|
||||
setting.AppURL = "https://example.com/"
|
||||
defer mockMailTemplates(string(tplNewReleaseMail), "{{.Subject}}", "<p>{{.Release.TagName}}</p>")()
|
||||
|
||||
@@ -61,7 +61,6 @@ const bodyTpl = `
|
||||
func prepareMailerTest(t *testing.T) (doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, comment *issues_model.Comment) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
setting.MailService = &setting.Mailer{From: "test@gitea.com"}
|
||||
setting.Domain = "localhost"
|
||||
setting.AppURL = "https://try.gitea.io/"
|
||||
|
||||
doer = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
@@ -390,7 +389,7 @@ func TestGenerateMessageIDForIssue(t *testing.T) {
|
||||
issue: issue,
|
||||
actionType: activities_model.ActionCreateIssue,
|
||||
},
|
||||
prefix: fmt.Sprintf("<%s/issues/%d@%s>", issue.Repo.FullName(), issue.Index, setting.Domain),
|
||||
prefix: fmt.Sprintf("<%s/issues/%d@%s>", issue.Repo.FullName(), issue.Index, setting.AppDomain),
|
||||
},
|
||||
{
|
||||
name: "Open Pull",
|
||||
@@ -398,7 +397,7 @@ func TestGenerateMessageIDForIssue(t *testing.T) {
|
||||
issue: pullIssue,
|
||||
actionType: activities_model.ActionCreatePullRequest,
|
||||
},
|
||||
prefix: fmt.Sprintf("<%s/pulls/%d@%s>", issue.Repo.FullName(), issue.Index, setting.Domain),
|
||||
prefix: fmt.Sprintf("<%s/pulls/%d@%s>", issue.Repo.FullName(), issue.Index, setting.AppDomain),
|
||||
},
|
||||
{
|
||||
name: "Comment Issue",
|
||||
@@ -407,7 +406,7 @@ func TestGenerateMessageIDForIssue(t *testing.T) {
|
||||
comment: comment,
|
||||
actionType: activities_model.ActionCommentIssue,
|
||||
},
|
||||
prefix: fmt.Sprintf("<%s/issues/%d/comment/%d@%s>", issue.Repo.FullName(), issue.Index, comment.ID, setting.Domain),
|
||||
prefix: fmt.Sprintf("<%s/issues/%d/comment/%d@%s>", issue.Repo.FullName(), issue.Index, comment.ID, setting.AppDomain),
|
||||
},
|
||||
{
|
||||
name: "Comment Pull",
|
||||
@@ -416,7 +415,7 @@ func TestGenerateMessageIDForIssue(t *testing.T) {
|
||||
comment: comment,
|
||||
actionType: activities_model.ActionCommentPull,
|
||||
},
|
||||
prefix: fmt.Sprintf("<%s/pulls/%d/comment/%d@%s>", issue.Repo.FullName(), issue.Index, comment.ID, setting.Domain),
|
||||
prefix: fmt.Sprintf("<%s/pulls/%d/comment/%d@%s>", issue.Repo.FullName(), issue.Index, comment.ID, setting.AppDomain),
|
||||
},
|
||||
{
|
||||
name: "Close Issue",
|
||||
@@ -518,15 +517,8 @@ func TestFromDisplayName(t *testing.T) {
|
||||
tmpl, err = texttmpl.New("mailFrom").Parse("{{ .DisplayName }} (by {{ .AppName }} on [{{ .Domain }}])")
|
||||
assert.NoError(t, err)
|
||||
setting.MailService = &setting.Mailer{FromDisplayNameFormatTemplate: tmpl}
|
||||
oldAppName := setting.AppName
|
||||
setting.AppName = "Code IT"
|
||||
oldDomain := setting.Domain
|
||||
setting.Domain = "code.it"
|
||||
defer func() {
|
||||
setting.AppName = oldAppName
|
||||
setting.Domain = oldDomain
|
||||
}()
|
||||
|
||||
defer test.MockVariableValue(&setting.AppName, "Code IT")()
|
||||
defer test.MockVariableValue(&setting.AppDomain, "code.it")()
|
||||
assert.Equal(t, "Mister X (by Code IT on [code.it])", fromDisplayName(&user_model.User{FullName: "Mister X", Name: "tmp"}))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo
|
||||
embedded := make(container.Set[string])
|
||||
for _, job := range jobs {
|
||||
icon, class := workflowRunJobStatusPresentation(job.Status)
|
||||
contentID := fmt.Sprintf("%s.actions-run-%d@%s", icon, run.ID, setting.Domain)
|
||||
contentID := fmt.Sprintf("%s.actions-run-%d@%s", icon, run.ID, setting.AppDomain)
|
||||
mailJobs = append(mailJobs, workflowRunMailJob{
|
||||
HTMLURL: fmt.Sprintf("%s/actions/runs/%d/jobs/%d", repo.HTMLURL(ctx), run.ID, job.ID),
|
||||
Name: job.Name,
|
||||
@@ -143,7 +143,7 @@ func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo
|
||||
for key, value := range generateMetadataHeaders(repo) {
|
||||
msg.SetHeader(key, value)
|
||||
}
|
||||
msg.SetHeader("Message-ID", fmt.Sprintf("<%s/actions/runs/%d@%s>", repo.FullName(), run.Index, setting.Domain))
|
||||
msg.SetHeader("Message-ID", fmt.Sprintf("<%s/actions/runs/%d@%s>", repo.FullName(), run.Index, setting.AppDomain))
|
||||
SendAsync(msg)
|
||||
|
||||
return nil
|
||||
|
||||
@@ -56,7 +56,7 @@ func TestWorkflowRunMail(t *testing.T) {
|
||||
translation.InitLocales(t.Context())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
defer test.MockVariableValue(&setting.MailService, &setting.Mailer{FromEmail: "gitea@localhost"})()
|
||||
defer test.MockVariableValue(&setting.Domain, "localhost")()
|
||||
defer test.MockVariableValue(&setting.AppDomain, "localhost")()
|
||||
defer test.MockVariableValue(&setting.AppURL, "http://localhost:3000/")()
|
||||
|
||||
recipient := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
@@ -101,7 +101,7 @@ func (m *Message) generateAutoMessageID() string {
|
||||
}
|
||||
_, _ = h.Write([]byte(m.Subject))
|
||||
_, _ = h.Write([]byte(m.Body))
|
||||
return fmt.Sprintf("<autogen-%d-%016x@%s>", dateMs, h.Sum64(), setting.Domain)
|
||||
return fmt.Sprintf("<autogen-%d-%016x@%s>", dateMs, h.Sum64(), setting.AppDomain)
|
||||
}
|
||||
|
||||
// NewMessageFrom creates new mail message object with custom From header.
|
||||
|
||||
@@ -19,7 +19,6 @@ func TestGenerateMessageID(t *testing.T) {
|
||||
}
|
||||
|
||||
setting.MailService = &mailService
|
||||
setting.Domain = "localhost"
|
||||
|
||||
date := time.Date(2000, 1, 2, 3, 4, 5, 6, time.UTC)
|
||||
m := NewMessageFrom("", "display-name", "from-address", "subject", "body")
|
||||
|
||||
Reference in New Issue
Block a user