-
+
{{template "base/alert" .ctxData}}
diff --git a/templates/admin/user/list.tmpl b/templates/admin/user/list.tmpl index 45fed87a4001..b3e0caa16915 100644 --- a/templates/admin/user/list.tmpl +++ b/templates/admin/user/list.tmpl @@ -68,36 +68,35 @@ {{.locale.Tr "email"}} {{.locale.Tr "admin.users.activated"}} - {{.locale.Tr "admin.users.admin"}} {{.locale.Tr "admin.users.restricted"}} {{.locale.Tr "admin.users.2fa"}} - {{.locale.Tr "admin.users.repos"}} {{.locale.Tr "admin.users.created"}} {{.locale.Tr "admin.users.last_login"}} {{SortArrow "lastlogin" "reverselastlogin" $.SortType false}} - {{.locale.Tr "admin.users.edit"}} {{range .Users}} {{.ID}} - {{.Name}} + + {{.Name}} + {{if .IsAdmin}} + {{$.locale.Tr "admin.users.admin"}} + {{end}} + {{.Email}} {{if .IsActive}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}} - {{if .IsAdmin}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}} {{if .IsRestricted}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}} {{if index $.UsersTwoFaStatus .ID}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}} - {{.NumRepos}} {{DateTime "short" .CreatedUnix}} {{if .LastLoginUnix}} {{DateTime "short" .LastLoginUnix}} {{else}} {{$.locale.Tr "admin.users.never_login"}} {{end}} - {{svg "octicon-pencil"}} {{end}} diff --git a/templates/admin/user/view.tmpl b/templates/admin/user/view.tmpl new file mode 100644 index 000000000000..fd3017607cdc --- /dev/null +++ b/templates/admin/user/view.tmpl @@ -0,0 +1,48 @@ +{{template "admin/layout_head" (dict "ctxData" . "pageClass" "admin view user")}} + +
+
+
+

+ {{.Title}} + +

+
+ {{template "admin/user/view_details" .}} +
+
+
+

+ {{ctx.Locale.Tr "admin.emails"}} +
+ {{.EmailsTotal}} +
+

+
+ {{template "admin/user/view_emails" .}} +
+
+
+

+ {{ctx.Locale.Tr "admin.repositories"}} +
+ {{.ReposTotal}} +
+

+
+ {{template "explore/repo_list" .}} +
+

+ {{ctx.Locale.Tr "settings.organization"}} +
+ {{.OrgsTotal}} +
+

+
+ {{template "explore/user_list" .}} +
+
+ +{{template "admin/layout_footer" .}} diff --git a/templates/admin/user/view_details.tmpl b/templates/admin/user/view_details.tmpl new file mode 100644 index 000000000000..ceb3b9a05509 --- /dev/null +++ b/templates/admin/user/view_details.tmpl @@ -0,0 +1,65 @@ +
+
+
+ {{ctx.AvatarUtils.Avatar .User 48}} +
+
+
+ {{template "shared/user/name" .User}} + {{if .User.IsAdmin}} + {{ctx.Locale.Tr "admin.users.admin"}} + {{end}} +
+
+ {{ctx.Locale.Tr "admin.users.auth_source"}}: + {{if eq .LoginSource.ID 0}} + {{ctx.Locale.Tr "admin.users.local"}} + {{else}} + {{.LoginSource.Name}} + {{end}} +
+
+ {{ctx.Locale.Tr "admin.users.activated"}}: + {{if .User.IsActive}} + {{svg "octicon-check"}} + {{else}} + {{svg "octicon-x"}} + {{end}} +
+
+ {{ctx.Locale.Tr "admin.users.restricted"}}: + {{if .User.IsRestricted}} + {{svg "octicon-check"}} + {{else}} + {{svg "octicon-x"}} + {{end}} +
+
+ {{ctx.Locale.Tr "settings.visibility"}}: + {{if .User.Visibility.IsLimited}}{{ctx.Locale.Tr "settings.visibility.limited"}}{{end}} + {{if .User.Visibility.IsPrivate}}{{ctx.Locale.Tr "settings.visibility.private"}}{{end}} +
+
+ {{ctx.Locale.Tr "admin.users.2fa"}}: + {{if .TwoFactorEnabled}} + {{svg "octicon-check"}} + {{else}} + {{svg "octicon-x"}} + {{end}} +
+ {{if .User.Location}} +
+ {{svg "octicon-location"}}{{.User.Location}} +
+ {{end}} + {{if .User.Website}} +
+ + {{svg "octicon-link"}} + {{.User.Website}} + +
+ {{end}} +
+
+
diff --git a/templates/admin/user/view_emails.tmpl b/templates/admin/user/view_emails.tmpl new file mode 100644 index 000000000000..22ce305a88bc --- /dev/null +++ b/templates/admin/user/view_emails.tmpl @@ -0,0 +1,19 @@ +
+ {{range .Emails}} +
+
+
+ {{.Email}} + {{if .IsPrimary}} +
{{ctx.Locale.Tr "settings.primary"}}
+ {{end}} + {{if .IsActivated}} +
{{ctx.Locale.Tr "settings.activated"}}
+ {{else}} +
{{ctx.Locale.Tr "settings.requires_activation"}}
+ {{end}} +
+
+
+ {{end}} +
diff --git a/templates/explore/user_list.tmpl b/templates/explore/user_list.tmpl new file mode 100644 index 000000000000..cf6a2933b0fe --- /dev/null +++ b/templates/explore/user_list.tmpl @@ -0,0 +1,31 @@ +
+ {{range .Users}} +
+
+ {{ctx.AvatarUtils.Avatar . 48}} +
+
+
+ {{template "shared/user/name" .}} + {{if .Visibility.IsPrivate}} + {{ctx.Locale.Tr "repo.desc.private"}} + {{end}} +
+
+ {{if .Location}} + {{svg "octicon-location"}}{{.Location}} + {{end}} + {{if and .Email (or (and $.ShowUserEmail $.IsSigned (not .KeepEmailPrivate)) $.PageIsAdminUsers)}} + + {{svg "octicon-mail"}} + {{.Email}} + + {{end}} + {{svg "octicon-calendar"}}{{ctx.Locale.Tr "user.joined_on" (DateTime "short" .CreatedUnix) | Safe}} +
+
+
+ {{else}} +
{{ctx.Locale.Tr "explore.user_no_results"}}
+ {{end}} +
diff --git a/templates/explore/users.tmpl b/templates/explore/users.tmpl index 1280f4add664..7e15ae3d47f4 100644 --- a/templates/explore/users.tmpl +++ b/templates/explore/users.tmpl @@ -4,37 +4,7 @@
{{template "explore/search" .}} -
- {{range .Users}} -
-
- {{ctx.AvatarUtils.Avatar . 48}} -
-
-
- {{template "shared/user/name" .}} - {{if .Visibility.IsPrivate}} - {{$.locale.Tr "repo.desc.private"}} - {{end}} -
-
- {{if .Location}} - {{svg "octicon-location"}}{{.Location}} - {{end}} - {{if and $.ShowUserEmail .Email $.IsSigned (not .KeepEmailPrivate)}} - - {{svg "octicon-mail"}} - {{.Email}} - - {{end}} - {{svg "octicon-calendar"}}{{$.locale.Tr "user.joined_on" (DateTime "short" .CreatedUnix) | Safe}} -
-
-
- {{else}} -
{{$.locale.Tr "explore.user_no_results"}}
- {{end}} -
+ {{template "explore/user_list" .}} {{template "base/paginate" .}}
diff --git a/tests/integration/admin_user_test.go b/tests/integration/admin_user_test.go index dd6b9ccbbeb8..669060c787d4 100644 --- a/tests/integration/admin_user_test.go +++ b/tests/integration/admin_user_test.go @@ -51,8 +51,8 @@ func testSuccessfullEdit(t *testing.T, formData user_model.User) { func makeRequest(t *testing.T, formData user_model.User, headerCode int) { session := loginUser(t, "user1") - csrf := GetCSRF(t, session, "/admin/users/"+strconv.Itoa(int(formData.ID))) - req := NewRequestWithValues(t, "POST", "/admin/users/"+strconv.Itoa(int(formData.ID)), map[string]string{ + csrf := GetCSRF(t, session, "/admin/users/"+strconv.Itoa(int(formData.ID))+"/edit") + req := NewRequestWithValues(t, "POST", "/admin/users/"+strconv.Itoa(int(formData.ID))+"/edit", map[string]string{ "_csrf": csrf, "user_name": formData.Name, "login_name": formData.LoginName, @@ -72,7 +72,7 @@ func TestAdminDeleteUser(t *testing.T) { session := loginUser(t, "user1") - csrf := GetCSRF(t, session, "/admin/users/8") + csrf := GetCSRF(t, session, "/admin/users/8/edit") req := NewRequestWithValues(t, "POST", "/admin/users/8/delete", map[string]string{ "_csrf": csrf, }) diff --git a/web_src/css/admin.css b/web_src/css/admin.css index fecae5f2bf98..e6866b27a688 100644 --- a/web_src/css/admin.css +++ b/web_src/css/admin.css @@ -42,3 +42,10 @@ .admin .table th { white-space: nowrap; } + +.admin-responsive-columns { + display: flex; + flex-wrap: wrap; + gap: 1rem; + margin-bottom: 1rem; +} From d5703d4a1bab58234c9e8e0e0e78c0cd26a90dce Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 31 Aug 2023 18:49:53 +0800 Subject: [PATCH 48/68] Remove "TODO" tasks from CSS file (#26835) 1. Use `gt-invisible` instead of `invisible`. 2. Use `gt-word-break` instead of `dont-break-out` (there is a slight different "hyphens", but I think it won't affect too much since it is only used for the "full name"). 3. Remove `.small.button:has(svg)` , now our buttons could layout SVG correctly, and actually I didn't see this CSS class is used in code. --- templates/repo/diff/section_split.tmpl | 8 ++++---- templates/repo/diff/section_unified.tmpl | 2 +- .../issue/labels/labels_selector_field.tmpl | 6 +++--- templates/repo/issue/new_form.tmpl | 2 +- .../repo/issue/view_content/sidebar.tmpl | 6 +++--- web_src/css/base.css | 20 ------------------- web_src/js/features/repo-diff.js | 4 ++-- web_src/js/features/repo-issue.js | 6 +++--- web_src/js/features/repo-legacy.js | 6 +++--- 9 files changed, 20 insertions(+), 40 deletions(-) diff --git a/templates/repo/diff/section_split.tmpl b/templates/repo/diff/section_split.tmpl index a1a5f5ba5699..c543a2a061d9 100644 --- a/templates/repo/diff/section_split.tmpl +++ b/templates/repo/diff/section_split.tmpl @@ -47,7 +47,7 @@ {{/* */}}{{if and $.root.SignedUserID $.root.PageIsPullFiles}}{{/* - */}}{{/* */}}{{end}}{{/* @@ -62,7 +62,7 @@ {{if $match.RightIdx}}{{end}} {{/* */}}{{if and $.root.SignedUserID $.root.PageIsPullFiles}}{{/* - */}}{{/* */}}{{end}}{{/* @@ -79,7 +79,7 @@ {{if $line.LeftIdx}}{{end}} {{/* */}}{{if and $.root.SignedUserID $.root.PageIsPullFiles (not (eq .GetType 2))}}{{/* - */}}{{/* */}}{{end}}{{/* @@ -94,7 +94,7 @@ {{if $line.RightIdx}}{{end}} {{/* */}}{{if and $.root.SignedUserID $.root.PageIsPullFiles (not (eq .GetType 3))}}{{/* - */}}{{/* */}}{{end}}{{/* diff --git a/templates/repo/diff/section_unified.tmpl b/templates/repo/diff/section_unified.tmpl index 98e382a0cb0e..f59832548fab 100644 --- a/templates/repo/diff/section_unified.tmpl +++ b/templates/repo/diff/section_unified.tmpl @@ -52,7 +52,7 @@ {{else}} {{/* */}}{{if and $.root.SignedUserID $.root.PageIsPullFiles}}{{/* - */}}{{/* */}}{{end}}{{/* diff --git a/templates/repo/issue/labels/labels_selector_field.tmpl b/templates/repo/issue/labels/labels_selector_field.tmpl index bdec96e6ac57..f8d38d035fd9 100644 --- a/templates/repo/issue/labels/labels_selector_field.tmpl +++ b/templates/repo/issue/labels/labels_selector_field.tmpl @@ -21,18 +21,18 @@
{{end}} {{$previousExclusiveScope = $exclusiveScope}} - {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}  {{RenderLabel $.Context .}} + {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}  {{RenderLabel $.Context .}} {{if .Description}}
{{.Description | RenderEmoji $.Context}}{{end}}
{{end}}
- {{$previousExclusiveScope := "_no_scope"}} + {{$previousExclusiveScope = "_no_scope"}} {{range .OrgLabels}} {{$exclusiveScope := .ExclusiveScope}} {{if and (ne $previousExclusiveScope "_no_scope") (ne $previousExclusiveScope $exclusiveScope)}}
{{end}} {{$previousExclusiveScope = $exclusiveScope}} - {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}  {{RenderLabel $.Context .}} + {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}  {{RenderLabel $.Context .}} {{if .Description}}
{{.Description | RenderEmoji $.Context}}{{end}}
{{end}} {{else}} diff --git a/templates/repo/issue/new_form.tmpl b/templates/repo/issue/new_form.tmpl index ca1ff287d043..fc1a3d087f02 100644 --- a/templates/repo/issue/new_form.tmpl +++ b/templates/repo/issue/new_form.tmpl @@ -158,7 +158,7 @@
{{.locale.Tr "repo.issues.new.clear_assignees"}}
{{range .Assignees}} - + {{svg "octicon-check"}} {{ctx.AvatarUtils.Avatar . 28 "gt-mr-3"}}{{template "repo/search_name" .}} diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index ff4239bbb77e..63a6a14a23af 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -20,7 +20,7 @@ {{range .Reviewers}} {{if .User}} - {{svg "octicon-check"}} + {{svg "octicon-check"}} {{ctx.AvatarUtils.Avatar .User 28 "gt-mr-3"}}{{template "repo/search_name" .User}} @@ -33,7 +33,7 @@ {{range .TeamReviewers}} {{if .Team}} - {{svg "octicon-check" 16}} + {{svg "octicon-check" 16}} {{svg "octicon-people" 16 "gt-ml-4 gt-mr-2"}}{{$.Issue.Repo.OwnerName}}/{{.Team.Name}} @@ -229,7 +229,7 @@ {{$checked = true}} {{end}} {{end}} - {{svg "octicon-check"}} + {{svg "octicon-check"}} {{ctx.AvatarUtils.Avatar . 20 "gt-mr-3"}}{{template "repo/search_name" .}} diff --git a/web_src/css/base.css b/web_src/css/base.css index 7c65b6aaf170..20ddf01486d8 100644 --- a/web_src/css/base.css +++ b/web_src/css/base.css @@ -506,13 +506,6 @@ a.label, border-right-color: var(--color-primary); } -/* fix button enlarged vertically by svg icon */ -/* TODO: change to just `.small.button:has(svg)` but may have global side effects */ -.ui.action.input .small.button:has(svg) { - padding-top: 7px !important; - padding-bottom: 7px !important; -} - .ui.menu, .ui.vertical.menu { background: var(--color-menu); @@ -953,14 +946,6 @@ img.ui.avatar, filter: saturate(2); } -/* TODO: use gt-word-break instead */ -.dont-break-out { - overflow-wrap: break-word; - word-wrap: break-word; - word-break: break-all; - hyphens: auto; -} - .full.height { flex-grow: 1; padding-bottom: 80px; @@ -2014,11 +1999,6 @@ a.ui.basic.label:hover { margin-left: 0; } -/* TODO: replace it with gt-invisible */ -.invisible { - visibility: hidden; -} - .ui.segment, .ui.segments, .ui.attached.segment { diff --git a/web_src/js/features/repo-diff.js b/web_src/js/features/repo-diff.js index b79ca0f5b154..864b28a3bb8b 100644 --- a/web_src/js/features/repo-diff.js +++ b/web_src/js/features/repo-diff.js @@ -64,9 +64,9 @@ function initRepoDiffConversationForm() { $form.closest('.conversation-holder').replaceWith($newConversationHolder); if ($form.closest('tr').data('line-type') === 'same') { - $(`[data-path="${path}"] .add-code-comment[data-idx="${idx}"]`).addClass('invisible'); + $(`[data-path="${path}"] .add-code-comment[data-idx="${idx}"]`).addClass('gt-invisible'); } else { - $(`[data-path="${path}"] .add-code-comment[data-side="${side}"][data-idx="${idx}"]`).addClass('invisible'); + $(`[data-path="${path}"] .add-code-comment[data-side="${side}"][data-idx="${idx}"]`).addClass('gt-invisible'); } $newConversationHolder.find('.dropdown').dropdown(); initCompReactionSelector($newConversationHolder); diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js index 194ffca57c4a..4f4103bb2135 100644 --- a/web_src/js/features/repo-issue.js +++ b/web_src/js/features/repo-issue.js @@ -110,7 +110,7 @@ export function initRepoIssueSidebarList() { } filteredResponse.results.push({ name: `#${issue.number} ${htmlEscape(issue.title) - }
${htmlEscape(issue.repository.full_name)}
`, + }
${htmlEscape(issue.repository.full_name)}
`, value: issue.id, }); }); @@ -178,9 +178,9 @@ export function initRepoIssueCommentDelete() { const idx = $conversationHolder.data('idx'); const lineType = $conversationHolder.closest('tr').data('line-type'); if (lineType === 'same') { - $(`[data-path="${path}"] .add-code-comment[data-idx="${idx}"]`).removeClass('invisible'); + $(`[data-path="${path}"] .add-code-comment[data-idx="${idx}"]`).removeClass('gt-invisible'); } else { - $(`[data-path="${path}"] .add-code-comment[data-side="${side}"][data-idx="${idx}"]`).removeClass('invisible'); + $(`[data-path="${path}"] .add-code-comment[data-side="${side}"][data-idx="${idx}"]`).removeClass('gt-invisible'); } $conversationHolder.remove(); } diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index 3b25c3653867..51edf0bd1204 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -150,7 +150,7 @@ export function initRepoCommentForm() { if ($(this).hasClass('checked')) { $(this).removeClass('checked'); - $(this).find('.octicon-check').addClass('invisible'); + $(this).find('.octicon-check').addClass('gt-invisible'); if (hasUpdateAction) { if (!($(this).data('id') in items)) { items[$(this).data('id')] = { @@ -164,7 +164,7 @@ export function initRepoCommentForm() { } } else { $(this).addClass('checked'); - $(this).find('.octicon-check').removeClass('invisible'); + $(this).find('.octicon-check').removeClass('gt-invisible'); if (hasUpdateAction) { if (!($(this).data('id') in items)) { items[$(this).data('id')] = { @@ -215,7 +215,7 @@ export function initRepoCommentForm() { $(this).parent().find('.item').each(function () { $(this).removeClass('checked'); - $(this).find('.octicon-check').addClass('invisible'); + $(this).find('.octicon-check').addClass('gt-invisible'); }); if (selector === 'select-reviewers-modify' || selector === 'select-assignees-modify') { From 3cae50e841bf1551d82fe9ae3fe5c88627029c24 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Thu, 31 Aug 2023 17:36:25 +0200 Subject: [PATCH 49/68] Redirect from `{repo}/issues/new` to `{repo}/issues/new/choose` when blank issues are disabled (#26813) You can currently visit `{repo}/issues/new` and create a blank issue, even if it's disabled. This PR fixes this, Fixes https://codeberg.org/forgejo/forgejo/issues/1356 Co-authored-by: Giteabot --- routers/web/repo/issue.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index b8b5a2dff26d..f5e8f80ddfe2 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -902,9 +902,17 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleFiles // NewIssue render creating issue page func NewIssue(ctx *context.Context) { + issueConfig, _ := issue_service.GetTemplateConfigFromDefaultBranch(ctx.Repo.Repository, ctx.Repo.GitRepo) + hasTemplates := issue_service.HasTemplatesOrContactLinks(ctx.Repo.Repository, ctx.Repo.GitRepo) + if !issueConfig.BlankIssuesEnabled && hasTemplates { + // The "issues/new" and "issues/new/choose" share the same query parameters "project" and "milestone", if blank issues are disabled, just redirect to the "issues/choose" page with these parameters. + ctx.Redirect(fmt.Sprintf("%s/issues/new/choose?%s", ctx.Repo.Repository.Link(), ctx.Req.URL.RawQuery), http.StatusSeeOther) + return + } + ctx.Data["Title"] = ctx.Tr("repo.issues.new") ctx.Data["PageIsIssueList"] = true - ctx.Data["NewIssueChooseTemplate"] = issue_service.HasTemplatesOrContactLinks(ctx.Repo.Repository, ctx.Repo.GitRepo) + ctx.Data["NewIssueChooseTemplate"] = hasTemplates ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes title := ctx.FormString("title") ctx.Data["TitleQuery"] = title From c0ab7070e56f1de390d2e7d6a95083137041a572 Mon Sep 17 00:00:00 2001 From: Jack Hay Date: Thu, 31 Aug 2023 12:26:13 -0400 Subject: [PATCH 50/68] Update team invitation email link (#26550) Co-authored-by: Kyle D Co-authored-by: Jonathan Tran --- routers/web/auth/auth.go | 11 + services/auth/middleware.go | 4 +- services/mailer/mail_team_invite.go | 19 ++ templates/mail/team_invite.tmpl | 3 +- tests/integration/org_team_invite_test.go | 319 +++++++++++++++++++++- 5 files changed, 346 insertions(+), 10 deletions(-) diff --git a/routers/web/auth/auth.go b/routers/web/auth/auth.go index 3bf133f56222..c20a45ebc972 100644 --- a/routers/web/auth/auth.go +++ b/routers/web/auth/auth.go @@ -398,6 +398,11 @@ func SignUp(ctx *context.Context) { // Show Disabled Registration message if DisableRegistration or AllowOnlyExternalRegistration options are true ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration || setting.Service.AllowOnlyExternalRegistration + redirectTo := ctx.FormString("redirect_to") + if len(redirectTo) > 0 { + middleware.SetRedirectToCookie(ctx.Resp, redirectTo) + } + ctx.HTML(http.StatusOK, tplSignUp) } @@ -729,6 +734,12 @@ func handleAccountActivation(ctx *context.Context, user *user_model.User) { } ctx.Flash.Success(ctx.Tr("auth.account_activated")) + if redirectTo := ctx.GetSiteCookie("redirect_to"); len(redirectTo) > 0 { + middleware.DeleteRedirectToCookie(ctx.Resp) + ctx.RedirectToFirst(redirectTo) + return + } + ctx.Redirect(setting.AppSubURL + "/") } diff --git a/services/auth/middleware.go b/services/auth/middleware.go index d1955a4c9001..4a0b613fa662 100644 --- a/services/auth/middleware.go +++ b/services/auth/middleware.go @@ -120,9 +120,9 @@ func VerifyAuthWithOptions(options *VerifyOptions) func(ctx *context.Context) { } } - // Redirect to dashboard if user tries to visit any non-login page. + // Redirect to dashboard (or alternate location) if user tries to visit any non-login page. if options.SignOutRequired && ctx.IsSigned && ctx.Req.URL.RequestURI() != "/" { - ctx.Redirect(setting.AppSubURL + "/") + ctx.RedirectToFirst(ctx.FormString("redirect_to")) return } diff --git a/services/mailer/mail_team_invite.go b/services/mailer/mail_team_invite.go index b6f47ee9215b..1403923c7954 100644 --- a/services/mailer/mail_team_invite.go +++ b/services/mailer/mail_team_invite.go @@ -6,6 +6,8 @@ package mailer import ( "bytes" "context" + "fmt" + "net/url" org_model "code.gitea.io/gitea/models/organization" user_model "code.gitea.io/gitea/models/user" @@ -33,6 +35,22 @@ func MailTeamInvite(ctx context.Context, inviter *user_model.User, team *org_mod locale := translation.NewLocale(inviter.Language) + // check if a user with this email already exists + user, err := user_model.GetUserByEmail(ctx, invite.Email) + if err != nil && !user_model.IsErrUserNotExist(err) { + return err + } else if user != nil && user.ProhibitLogin { + return fmt.Errorf("login is prohibited for the invited user") + } + + inviteRedirect := url.QueryEscape(fmt.Sprintf("/org/invite/%s", invite.Token)) + inviteURL := fmt.Sprintf("%suser/sign_up?redirect_to=%s", setting.AppURL, inviteRedirect) + + if err == nil && user != nil { + // user account exists + inviteURL = fmt.Sprintf("%suser/login?redirect_to=%s", setting.AppURL, inviteRedirect) + } + subject := locale.Tr("mail.team_invite.subject", inviter.DisplayName(), org.DisplayName()) mailMeta := map[string]any{ "Inviter": inviter, @@ -40,6 +58,7 @@ func MailTeamInvite(ctx context.Context, inviter *user_model.User, team *org_mod "Team": team, "Invite": invite, "Subject": subject, + "InviteURL": inviteURL, // helper "locale": locale, "Str2html": templates.Str2html, diff --git a/templates/mail/team_invite.tmpl b/templates/mail/team_invite.tmpl index 835789526539..d21b7843ec78 100644 --- a/templates/mail/team_invite.tmpl +++ b/templates/mail/team_invite.tmpl @@ -4,10 +4,9 @@ -{{$invite_url := printf "%sorg/invite/%s" AppUrl (QueryEscape .Invite.Token)}}

{{.locale.Tr "mail.team_invite.text_1" (DotEscape .Inviter.DisplayName) (DotEscape .Team.Name) (DotEscape .Organization.DisplayName) | Str2html}}

-

{{.locale.Tr "mail.team_invite.text_2"}}

{{$invite_url}}

+

{{.locale.Tr "mail.team_invite.text_2"}}

{{.InviteURL}}

{{.locale.Tr "mail.link_not_working_do_paste"}}

{{.locale.Tr "mail.team_invite.text_3" .Invite.Email}}

diff --git a/tests/integration/org_team_invite_test.go b/tests/integration/org_team_invite_test.go index 4d848dfc6034..919769a61a25 100644 --- a/tests/integration/org_team_invite_test.go +++ b/tests/integration/org_team_invite_test.go @@ -6,6 +6,8 @@ package integration import ( "fmt" "net/http" + "net/url" + "strings" "testing" "code.gitea.io/gitea/models/db" @@ -37,9 +39,9 @@ func TestOrgTeamEmailInvite(t *testing.T) { session := loginUser(t, "user1") - url := fmt.Sprintf("/org/%s/teams/%s", org.Name, team.Name) - csrf := GetCSRF(t, session, url) - req := NewRequestWithValues(t, "POST", url+"/action/add", map[string]string{ + teamURL := fmt.Sprintf("/org/%s/teams/%s", org.Name, team.Name) + csrf := GetCSRF(t, session, teamURL) + req := NewRequestWithValues(t, "POST", teamURL+"/action/add", map[string]string{ "_csrf": csrf, "uid": "1", "uname": user.Email, @@ -56,9 +58,9 @@ func TestOrgTeamEmailInvite(t *testing.T) { session = loginUser(t, user.Name) // join the team - url = fmt.Sprintf("/org/invite/%s", invites[0].Token) - csrf = GetCSRF(t, session, url) - req = NewRequestWithValues(t, "POST", url, map[string]string{ + inviteURL := fmt.Sprintf("/org/invite/%s", invites[0].Token) + csrf = GetCSRF(t, session, inviteURL) + req = NewRequestWithValues(t, "POST", inviteURL, map[string]string{ "_csrf": csrf, }) resp = session.MakeRequest(t, req, http.StatusSeeOther) @@ -69,3 +71,308 @@ func TestOrgTeamEmailInvite(t *testing.T) { assert.NoError(t, err) assert.True(t, isMember) } + +// Check that users are redirected to accept the invitation correctly after login +func TestOrgTeamEmailInviteRedirectsExistingUser(t *testing.T) { + if setting.MailService == nil { + t.Skip() + return + } + + defer tests.PrepareTestEnv(t)() + + org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3}) + team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 2}) + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}) + + isMember, err := organization.IsTeamMember(db.DefaultContext, team.OrgID, team.ID, user.ID) + assert.NoError(t, err) + assert.False(t, isMember) + + // create the invite + session := loginUser(t, "user1") + + teamURL := fmt.Sprintf("/org/%s/teams/%s", org.Name, team.Name) + req := NewRequestWithValues(t, "POST", teamURL+"/action/add", map[string]string{ + "_csrf": GetCSRF(t, session, teamURL), + "uid": "1", + "uname": user.Email, + }) + resp := session.MakeRequest(t, req, http.StatusSeeOther) + req = NewRequest(t, "GET", test.RedirectURL(resp)) + session.MakeRequest(t, req, http.StatusOK) + + // get the invite token + invites, err := organization.GetInvitesByTeamID(db.DefaultContext, team.ID) + assert.NoError(t, err) + assert.Len(t, invites, 1) + + // accept the invite + inviteURL := fmt.Sprintf("/org/invite/%s", invites[0].Token) + req = NewRequest(t, "GET", fmt.Sprintf("/user/login?redirect_to=%s", url.QueryEscape(inviteURL))) + resp = MakeRequest(t, req, http.StatusOK) + + doc := NewHTMLParser(t, resp.Body) + req = NewRequestWithValues(t, "POST", "/user/login", map[string]string{ + "_csrf": doc.GetCSRF(), + "user_name": "user5", + "password": "password", + }) + for _, c := range resp.Result().Cookies() { + req.AddCookie(c) + } + + resp = MakeRequest(t, req, http.StatusSeeOther) + assert.Equal(t, inviteURL, test.RedirectURL(resp)) + + // complete the login process + ch := http.Header{} + ch.Add("Cookie", strings.Join(resp.Header()["Set-Cookie"], ";")) + cr := http.Request{Header: ch} + + session = emptyTestSession(t) + baseURL, err := url.Parse(setting.AppURL) + assert.NoError(t, err) + session.jar.SetCookies(baseURL, cr.Cookies()) + + // make the request + req = NewRequestWithValues(t, "POST", test.RedirectURL(resp), map[string]string{ + "_csrf": GetCSRF(t, session, test.RedirectURL(resp)), + }) + resp = session.MakeRequest(t, req, http.StatusSeeOther) + req = NewRequest(t, "GET", test.RedirectURL(resp)) + session.MakeRequest(t, req, http.StatusOK) + + isMember, err = organization.IsTeamMember(db.DefaultContext, team.OrgID, team.ID, user.ID) + assert.NoError(t, err) + assert.True(t, isMember) +} + +// Check that newly signed up users are redirected to accept the invitation correctly +func TestOrgTeamEmailInviteRedirectsNewUser(t *testing.T) { + if setting.MailService == nil { + t.Skip() + return + } + + defer tests.PrepareTestEnv(t)() + + org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3}) + team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 2}) + + // create the invite + session := loginUser(t, "user1") + + teamURL := fmt.Sprintf("/org/%s/teams/%s", org.Name, team.Name) + req := NewRequestWithValues(t, "POST", teamURL+"/action/add", map[string]string{ + "_csrf": GetCSRF(t, session, teamURL), + "uid": "1", + "uname": "doesnotexist@example.com", + }) + resp := session.MakeRequest(t, req, http.StatusSeeOther) + req = NewRequest(t, "GET", test.RedirectURL(resp)) + session.MakeRequest(t, req, http.StatusOK) + + // get the invite token + invites, err := organization.GetInvitesByTeamID(db.DefaultContext, team.ID) + assert.NoError(t, err) + assert.Len(t, invites, 1) + + // accept the invite + inviteURL := fmt.Sprintf("/org/invite/%s", invites[0].Token) + req = NewRequest(t, "GET", fmt.Sprintf("/user/sign_up?redirect_to=%s", url.QueryEscape(inviteURL))) + resp = MakeRequest(t, req, http.StatusOK) + + doc := NewHTMLParser(t, resp.Body) + req = NewRequestWithValues(t, "POST", "/user/sign_up", map[string]string{ + "_csrf": doc.GetCSRF(), + "user_name": "doesnotexist", + "email": "doesnotexist@example.com", + "password": "examplePassword!1", + "retype": "examplePassword!1", + }) + for _, c := range resp.Result().Cookies() { + req.AddCookie(c) + } + + resp = MakeRequest(t, req, http.StatusSeeOther) + assert.Equal(t, inviteURL, test.RedirectURL(resp)) + + // complete the signup process + ch := http.Header{} + ch.Add("Cookie", strings.Join(resp.Header()["Set-Cookie"], ";")) + cr := http.Request{Header: ch} + + session = emptyTestSession(t) + baseURL, err := url.Parse(setting.AppURL) + assert.NoError(t, err) + session.jar.SetCookies(baseURL, cr.Cookies()) + + // make the redirected request + req = NewRequestWithValues(t, "POST", test.RedirectURL(resp), map[string]string{ + "_csrf": GetCSRF(t, session, test.RedirectURL(resp)), + }) + resp = session.MakeRequest(t, req, http.StatusSeeOther) + req = NewRequest(t, "GET", test.RedirectURL(resp)) + session.MakeRequest(t, req, http.StatusOK) + + // get the new user + newUser, err := user_model.GetUserByName(db.DefaultContext, "doesnotexist") + assert.NoError(t, err) + + isMember, err := organization.IsTeamMember(db.DefaultContext, team.OrgID, team.ID, newUser.ID) + assert.NoError(t, err) + assert.True(t, isMember) +} + +// Check that users are redirected correctly after confirming their email +func TestOrgTeamEmailInviteRedirectsNewUserWithActivation(t *testing.T) { + if setting.MailService == nil { + t.Skip() + return + } + + // enable email confirmation temporarily + defer func(prevVal bool) { + setting.Service.RegisterEmailConfirm = prevVal + }(setting.Service.RegisterEmailConfirm) + setting.Service.RegisterEmailConfirm = true + + defer tests.PrepareTestEnv(t)() + + org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3}) + team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 2}) + + // create the invite + session := loginUser(t, "user1") + + teamURL := fmt.Sprintf("/org/%s/teams/%s", org.Name, team.Name) + req := NewRequestWithValues(t, "POST", teamURL+"/action/add", map[string]string{ + "_csrf": GetCSRF(t, session, teamURL), + "uid": "1", + "uname": "doesnotexist@example.com", + }) + resp := session.MakeRequest(t, req, http.StatusSeeOther) + req = NewRequest(t, "GET", test.RedirectURL(resp)) + session.MakeRequest(t, req, http.StatusOK) + + // get the invite token + invites, err := organization.GetInvitesByTeamID(db.DefaultContext, team.ID) + assert.NoError(t, err) + assert.Len(t, invites, 1) + + // accept the invite + inviteURL := fmt.Sprintf("/org/invite/%s", invites[0].Token) + req = NewRequest(t, "GET", fmt.Sprintf("/user/sign_up?redirect_to=%s", url.QueryEscape(inviteURL))) + inviteResp := MakeRequest(t, req, http.StatusOK) + + doc := NewHTMLParser(t, resp.Body) + req = NewRequestWithValues(t, "POST", "/user/sign_up", map[string]string{ + "_csrf": doc.GetCSRF(), + "user_name": "doesnotexist", + "email": "doesnotexist@example.com", + "password": "examplePassword!1", + "retype": "examplePassword!1", + }) + for _, c := range inviteResp.Result().Cookies() { + req.AddCookie(c) + } + + resp = MakeRequest(t, req, http.StatusOK) + + user, err := user_model.GetUserByName(db.DefaultContext, "doesnotexist") + assert.NoError(t, err) + + ch := http.Header{} + ch.Add("Cookie", strings.Join(resp.Header()["Set-Cookie"], ";")) + cr := http.Request{Header: ch} + + session = emptyTestSession(t) + baseURL, err := url.Parse(setting.AppURL) + assert.NoError(t, err) + session.jar.SetCookies(baseURL, cr.Cookies()) + + activateURL := fmt.Sprintf("/user/activate?code=%s", user.GenerateEmailActivateCode("doesnotexist@example.com")) + req = NewRequestWithValues(t, "POST", activateURL, map[string]string{ + "password": "examplePassword!1", + }) + + // use the cookies set by the signup request + for _, c := range inviteResp.Result().Cookies() { + req.AddCookie(c) + } + + resp = session.MakeRequest(t, req, http.StatusSeeOther) + // should be redirected to accept the invite + assert.Equal(t, inviteURL, test.RedirectURL(resp)) + + req = NewRequestWithValues(t, "POST", test.RedirectURL(resp), map[string]string{ + "_csrf": GetCSRF(t, session, test.RedirectURL(resp)), + }) + resp = session.MakeRequest(t, req, http.StatusSeeOther) + req = NewRequest(t, "GET", test.RedirectURL(resp)) + session.MakeRequest(t, req, http.StatusOK) + + isMember, err := organization.IsTeamMember(db.DefaultContext, team.OrgID, team.ID, user.ID) + assert.NoError(t, err) + assert.True(t, isMember) +} + +// Test that a logged-in user who navigates to the sign-up link is then redirected using redirect_to +// For example: an invite may have been created before the user account was created, but they may be +// accepting the invite after having created an account separately +func TestOrgTeamEmailInviteRedirectsExistingUserWithLogin(t *testing.T) { + if setting.MailService == nil { + t.Skip() + return + } + + defer tests.PrepareTestEnv(t)() + + org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3}) + team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 2}) + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}) + + isMember, err := organization.IsTeamMember(db.DefaultContext, team.OrgID, team.ID, user.ID) + assert.NoError(t, err) + assert.False(t, isMember) + + // create the invite + session := loginUser(t, "user1") + + teamURL := fmt.Sprintf("/org/%s/teams/%s", org.Name, team.Name) + req := NewRequestWithValues(t, "POST", teamURL+"/action/add", map[string]string{ + "_csrf": GetCSRF(t, session, teamURL), + "uid": "1", + "uname": user.Email, + }) + resp := session.MakeRequest(t, req, http.StatusSeeOther) + req = NewRequest(t, "GET", test.RedirectURL(resp)) + session.MakeRequest(t, req, http.StatusOK) + + // get the invite token + invites, err := organization.GetInvitesByTeamID(db.DefaultContext, team.ID) + assert.NoError(t, err) + assert.Len(t, invites, 1) + + // note: the invited user has logged in + session = loginUser(t, "user5") + + // accept the invite (note: this uses the sign_up url) + inviteURL := fmt.Sprintf("/org/invite/%s", invites[0].Token) + req = NewRequest(t, "GET", fmt.Sprintf("/user/sign_up?redirect_to=%s", url.QueryEscape(inviteURL))) + resp = session.MakeRequest(t, req, http.StatusSeeOther) + assert.Equal(t, inviteURL, test.RedirectURL(resp)) + + // make the request + req = NewRequestWithValues(t, "POST", test.RedirectURL(resp), map[string]string{ + "_csrf": GetCSRF(t, session, test.RedirectURL(resp)), + }) + resp = session.MakeRequest(t, req, http.StatusSeeOther) + req = NewRequest(t, "GET", test.RedirectURL(resp)) + session.MakeRequest(t, req, http.StatusOK) + + isMember, err = organization.IsTeamMember(db.DefaultContext, team.OrgID, team.ID, user.ID) + assert.NoError(t, err) + assert.True(t, isMember) +} From 9b76df53dc5c03b059bef784f15eaa96342ab63c Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 31 Aug 2023 23:28:45 +0200 Subject: [PATCH 51/68] Minor dashboard tweaks, fix flex-list margins (#26829) Some small dashboard tweaks: - Remove margin-bottom from divider so first item does not appear to have un-equal margins - Restore previous icon color - Add slight margin-right to icon Before: Screenshot 2023-08-31 at 00 10 28 After: Screenshot 2023-08-31 at 00 10 08 --------- Co-authored-by: wxiaoguang --- templates/devtest/flex-list.tmpl | 13 +++++++++++-- templates/package/shared/list.tmpl | 6 ++++-- templates/package/shared/versionlist.tmpl | 6 ++++-- templates/repo/actions/runs_list.tmpl | 2 +- templates/repo/settings/deploy_keys.tmpl | 2 +- templates/shared/issuelist.tmpl | 2 +- templates/user/dashboard/feeds.tmpl | 2 +- templates/user/profile.tmpl | 4 +--- templates/user/settings/keys_gpg.tmpl | 2 +- templates/user/settings/keys_ssh.tmpl | 2 +- web_src/css/dashboard.css | 7 ------- web_src/css/shared/flex-list.css | 14 +++++++++++++- 12 files changed, 39 insertions(+), 23 deletions(-) diff --git a/templates/devtest/flex-list.tmpl b/templates/devtest/flex-list.tmpl index cbc263213937..80cd22440d48 100644 --- a/templates/devtest/flex-list.tmpl +++ b/templates/devtest/flex-list.tmpl @@ -2,7 +2,8 @@
-

Flex List (standalone)

+

Flex List (standalone)

+
@@ -85,7 +86,7 @@
-
+

Flex List (with "ui segment")

@@ -101,6 +102,14 @@
item 2
+ +

If parent provides the padding/margin space:

+
+
+
item 1 (no padding top)
+
item 2 (no padding bottom)
+
+
{{template "base/footer" .}} diff --git a/templates/package/shared/list.tmpl b/templates/package/shared/list.tmpl index 7cc11b073e13..afa360fd93d1 100644 --- a/templates/package/shared/list.tmpl +++ b/templates/package/shared/list.tmpl @@ -12,8 +12,9 @@
-
+
{{range .PackageDescriptors}} +
@@ -34,6 +35,7 @@
+
{{else}} {{if not .HasPackages}}
@@ -46,7 +48,7 @@

{{.locale.Tr "packages.empty.documentation" "https://docs.gitea.com/usage/packages/overview/" | Safe}}

{{else}} -

{{.locale.Tr "packages.filter.no_result"}}

+

{{.locale.Tr "packages.filter.no_result"}}

{{end}} {{end}} {{template "base/paginate" .}} diff --git a/templates/package/shared/versionlist.tmpl b/templates/package/shared/versionlist.tmpl index 897f4d716ae8..e8043b9abba3 100644 --- a/templates/package/shared/versionlist.tmpl +++ b/templates/package/shared/versionlist.tmpl @@ -18,8 +18,9 @@
-
+
{{range .PackageDescriptors}} +
{{.Version.LowerVersion}} @@ -28,8 +29,9 @@
+
{{else}} -

{{.locale.Tr "packages.filter.no_result"}}

+

{{.locale.Tr "packages.filter.no_result"}}

{{end}} {{template "base/paginate" .}}
diff --git a/templates/repo/actions/runs_list.tmpl b/templates/repo/actions/runs_list.tmpl index 1a45733b77ca..d8e27fab52ab 100644 --- a/templates/repo/actions/runs_list.tmpl +++ b/templates/repo/actions/runs_list.tmpl @@ -1,4 +1,4 @@ -
+
{{if eq (len .Runs) 0}}
{{svg "octicon-no-entry" 48}} diff --git a/templates/repo/settings/deploy_keys.tmpl b/templates/repo/settings/deploy_keys.tmpl index 10e79f6b82ac..a9e540bc65d6 100644 --- a/templates/repo/settings/deploy_keys.tmpl +++ b/templates/repo/settings/deploy_keys.tmpl @@ -11,7 +11,7 @@
-
+
{{.CsrfTokenHtml}}
diff --git a/templates/shared/issuelist.tmpl b/templates/shared/issuelist.tmpl index 72cf1dd6c829..2cd0fb92ac5f 100644 --- a/templates/shared/issuelist.tmpl +++ b/templates/shared/issuelist.tmpl @@ -1,4 +1,4 @@ -
+
{{$approvalCounts := .ApprovalCounts}} {{range .Issues}}
diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl index 6bfd8b12be71..bf697634741a 100644 --- a/templates/user/dashboard/feeds.tmpl +++ b/templates/user/dashboard/feeds.tmpl @@ -116,7 +116,7 @@
{{TimeSince .GetCreate $.locale}}
- {{svg (printf "octicon-%s" (ActionIcon .GetOpType)) 32}} + {{svg (printf "octicon-%s" (ActionIcon .GetOpType)) 32 "text grey gt-mr-2"}}
{{end}} diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 396d9ebcd470..2b81a2349287 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -17,9 +17,7 @@
{{end}} {{template "user/heatmap" .}} -
- {{template "user/dashboard/feeds" .}} -
+ {{template "user/dashboard/feeds" .}} {{else if eq .TabName "stars"}}
{{template "explore/repo_search" .}} diff --git a/templates/user/settings/keys_gpg.tmpl b/templates/user/settings/keys_gpg.tmpl index 5ab96eb63ada..e7a66de23f72 100644 --- a/templates/user/settings/keys_gpg.tmpl +++ b/templates/user/settings/keys_gpg.tmpl @@ -5,7 +5,7 @@
-
+
{{.CsrfTokenHtml}} diff --git a/templates/user/settings/keys_ssh.tmpl b/templates/user/settings/keys_ssh.tmpl index 0d2916d30cd5..30c4133b6e33 100644 --- a/templates/user/settings/keys_ssh.tmpl +++ b/templates/user/settings/keys_ssh.tmpl @@ -7,7 +7,7 @@
-
+
{{.CsrfTokenHtml}}
diff --git a/web_src/css/dashboard.css b/web_src/css/dashboard.css index 6dcf73e2a772..0168ee0bd70a 100644 --- a/web_src/css/dashboard.css +++ b/web_src/css/dashboard.css @@ -95,10 +95,3 @@ position: static; } } - -.feeds code { - padding: 2px 4px; - border-radius: var(--border-radius); - background-color: var(--color-markup-code-block); - word-break: break-all; -} diff --git a/web_src/css/shared/flex-list.css b/web_src/css/shared/flex-list.css index 1489983cfdcb..27f9bc2d69e8 100644 --- a/web_src/css/shared/flex-list.css +++ b/web_src/css/shared/flex-list.css @@ -91,11 +91,23 @@ border-top: 1px solid var(--color-secondary); } -/* Fomantic UI segment has default "padding: 1em", so here it removes the padding-top and padding-bottom accordingly */ +/* Fomantic UI segment has default "padding: 1em", so here it removes the padding-top and padding-bottom accordingly. +Developers could also use "flex-space-fitted" class to remove the first item's padding-top and the last item's padding-bottom */ +.flex-list.flex-space-fitted > .flex-item:first-child, .ui.segment > .flex-list:first-child > .flex-item:first-child { padding-top: 0; } +.flex-list.flex-space-fitted > .flex-item:last-child, .ui.segment > .flex-list:last-child > .flex-item:last-child { padding-bottom: 0; } + +/* If there is a divider besides the flex-list, some padding/margin are not needs */ +.divider + .flex-list > .flex-item:first-child { + padding-top: 0; +} + +.flex-list + .divider { + margin-top: 0; +} From 3ff81d38d87b88de004d666816e0ece46ea8bf65 Mon Sep 17 00:00:00 2001 From: GiteaBot Date: Fri, 1 Sep 2023 00:24:05 +0000 Subject: [PATCH 52/68] [skip ci] Updated translations via Crowdin --- options/locale/locale_ja-JP.ini | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/options/locale/locale_ja-JP.ini b/options/locale/locale_ja-JP.ini index e83060986b41..51480b7e62ba 100644 --- a/options/locale/locale_ja-JP.ini +++ b/options/locale/locale_ja-JP.ini @@ -1777,6 +1777,19 @@ milestones.filter_sort.most_complete=消化率の高い順 milestones.filter_sort.most_issues=イシューの多い順 milestones.filter_sort.least_issues=イシューの少ない順 +signing.will_sign=このコミットは鍵 "%s" で署名されます。 +signing.wont_sign.error=コミットの署名可否を確認中にエラーが発生しました。 +signing.wont_sign.nokey=このコミットに署名するための鍵がありません。 +signing.wont_sign.never=コミットが署名されることはありません。 +signing.wont_sign.always=コミットは常に署名されます。 +signing.wont_sign.pubkey=アカウントに公開鍵が登録されていないため、コミットは署名されません。 +signing.wont_sign.twofa=コミットに署名するには、2要素認証を有効にする必要があります。 +signing.wont_sign.parentsigned=親コミットが署名されていないため、このコミットも署名されません。 +signing.wont_sign.basesigned=ベース側のコミットが署名されていないため、マージは署名されません。 +signing.wont_sign.headsigned=HEADコミットが署名されていないため、マージは署名されません。 +signing.wont_sign.commitssigned=関連するコミットすべてが署名されていないため、マージは署名されません。 +signing.wont_sign.approved=PRが未承認のため、マージは署名されません。 +signing.wont_sign.not_signed_in=サインインしていません。 ext_wiki=外部Wikiへのアクセス ext_wiki.desc=外部Wikiへのリンク。 @@ -1906,7 +1919,9 @@ settings.mirror_settings.docs.disabled_push_mirror.info=プッシュ方式のミ settings.mirror_settings.docs.no_new_mirrors=このリポジトリは他のリポジトリと変更をミラーリングしています。 現時点では新しいミラーを作成することはできないことに留意してください。 settings.mirror_settings.docs.can_still_use=既存ミラーを変更したりミラーを新規に作成することはできませんが、既存ミラーを利用することは可能です。 settings.mirror_settings.docs.pull_mirror_instructions=プル方式のミラーを設定するには、次を参照: +settings.mirror_settings.docs.more_information_if_disabled=プッシュミラーとプルミラーの詳細は、こちらをご覧ください: settings.mirror_settings.docs.doc_link_title=リポジトリをミラーリングするには? +settings.mirror_settings.docs.doc_link_pull_section=ドキュメントの「リモートリポジトリからのプル」セクション。 settings.mirror_settings.docs.pulling_remote_title=リモートリポジトリからのプル settings.mirror_settings.mirrored_repository=同期するリポジトリ settings.mirror_settings.direction=方向 @@ -1986,6 +2001,7 @@ settings.transfer.rejected=リポジトリの移転は拒否されました。 settings.transfer.success=リポジトリの移転が成功しました。 settings.transfer_abort=転送をキャンセル settings.transfer_abort_invalid=存在しないリポジトリの移転はキャンセルできません。 +settings.transfer_abort_success=%s へのリポジトリ移転は正常にキャンセルされました。 settings.transfer_desc=別のユーザーやあなたが管理者権限を持っている組織にリポジトリを移転します。 settings.transfer_form_title=確認のためリポジトリ名を入力: settings.transfer_in_progress=現在進行中の移転があります。このリポジトリを別のユーザーに移転したい場合はキャンセルしてください。 @@ -2261,11 +2277,17 @@ settings.matrix.room_id=ルーム ID settings.matrix.message_type=メッセージ種別 settings.archive.button=アーカイブ settings.archive.header=このリポジトリをアーカイブ +settings.archive.text=リポジトリをアーカイブするとリポジトリ全体が読み出し専用となります。 ダッシュボードにも表示されなくなります。 新たなコミット、あるいは、イシューやプルリクエストの作成は、誰もできなくなります (あなたでさえも!)。 settings.archive.success=リポジトリをアーカイブしました。 settings.archive.error=リポジトリのアーカイブ設定でエラーが発生しました。 詳細はログを確認してください。 settings.archive.error_ismirror=ミラーのリポジトリはアーカイブできません。 settings.archive.branchsettings_unavailable=ブランチ設定は、アーカイブリポジトリでは使用できません。 settings.archive.tagsettings_unavailable=タグ設定は、アーカイブリポジトリでは使用できません。 +settings.unarchive.button=アーカイブ解除 +settings.unarchive.header=このリポジトリをアーカイブ解除 +settings.unarchive.text=リポジトリのアーカイブを解除すると、コミット、プッシュ、新規のイシューやプルリクエストを受け付ける機能が復活します。 +settings.unarchive.success=リポジトリのアーカイブを解除しました。 +settings.unarchive.error=リポジトリのアーカイブ解除でエラーが発生しました。 詳細はログを確認してください。 settings.update_avatar_success=リポジトリのアバターを更新しました。 settings.lfs=LFS settings.lfs_filelist=このリポジトリに含まれているLFSファイル @@ -2388,6 +2410,7 @@ release.edit_release=リリースを更新 release.delete_release=リリースを削除 release.delete_tag=タグを削除 release.deletion=リリースの削除 +release.deletion_desc=リリースの削除は、Giteaからの削除だけを行います。 Gitタグやリポジトリの内容、履歴には影響しません。 続行しますか? release.deletion_success=リリースを削除しました。 release.deletion_tag_desc=リポジトリからこのタグを削除します。 リポジトリの内容と履歴はそのまま残ります。 続行しますか? release.deletion_tag_success=タグを削除しました。 @@ -2408,6 +2431,7 @@ branch.already_exists=ブランチ "%s" は既に存在します。 branch.delete_head=削除 branch.delete=ブランチ "%s" の削除 branch.delete_html=ブランチ削除 +branch.delete_desc=ブランチの削除は恒久的です。 実際に削除されるまでの短い期間、ブランチが存在したままになることもありますが、たいていは元に戻すことはできません。 続行しますか? branch.deletion_success=ブランチ "%s" を削除しました。 branch.deletion_failed=ブランチ "%s" の削除に失敗しました。 branch.delete_branch_has_new_commits=マージ後に新しいコミットが追加されているため、ブランチ "%s" を削除できません。 @@ -2573,6 +2597,7 @@ teams.all_repositories_helper=チームはすべてのリポジトリにアク teams.all_repositories_read_permission_desc=このチームはすべてのリポジトリ読み取りアクセス権を持ちます: メンバーはリポジトリの閲覧とクローンが可能です。 teams.all_repositories_write_permission_desc=このチームはすべてのリポジトリ書き込みアクセス権を持ちます: メンバーはリポジトリの読み取りとプッシュが可能です。 teams.all_repositories_admin_permission_desc=このチームはすべてのリポジトリ管理者アクセス権を持ちます: メンバーはリポジトリの読み取り、プッシュ、共同作業者の追加が可能です。 +teams.invite.title=あなたは組織 %[2]s 内のチーム %[1]s への参加に招待されました。 teams.invite.by=%s からの招待 teams.invite.description=下のボタンをクリックしてチームに参加してください。 @@ -2602,11 +2627,13 @@ dashboard.clean_unbind_oauth=関連付けられていないOAuth接続を削除 dashboard.clean_unbind_oauth_success=関連付けられていないOAuth接続をすべて削除しました。 dashboard.task.started=タスクを開始しました: %[1]s dashboard.task.process=タスク: %[1]s +dashboard.task.cancelled=タスク: %[1]s をキャンセル: %[3]s dashboard.task.error=タスクでエラー: %[1]s: %[3]s dashboard.task.finished=タスク: %[2]s が開始したタスク %[1]s が完了 dashboard.task.unknown=不明なタスクです: %[1]s dashboard.cron.started=Cronを開始しました: %[1]s dashboard.cron.process=Cron: %[1]s +dashboard.cron.cancelled=Cron: %[1]s をキャンセル: %[3]s dashboard.cron.error=Cronでエラー: %s: %[3]s dashboard.cron.finished=Cron: %[1]s が完了 dashboard.delete_inactive_accounts=アクティベートされていないアカウントをすべて削除 @@ -3295,14 +3322,17 @@ settings.delete.success=パッケージを削除しました。 settings.delete.error=パッケージの削除に失敗しました。 owner.settings.cargo.title=Cargoレジストリ インデックス owner.settings.cargo.initialize=インデックスを初期化 +owner.settings.cargo.initialize.description=Cargoレジストリを使用するには、インデックス用の特別なgitリポジトリが必要です。 このオプションを使用するとそのリポジトリを(再)作成し、自動的に構成します。 owner.settings.cargo.initialize.error=Cargoインデックスの初期化に失敗しました: %v owner.settings.cargo.initialize.success=Cargoインデックスは正常に作成されました。 owner.settings.cargo.rebuild=インデックスを再構築 +owner.settings.cargo.rebuild.description=インデックスが格納されているCargoパッケージと同期していない場合は、再構築すると良いでしょう。 owner.settings.cargo.rebuild.error=Cargoインデックスの再構築に失敗しました: %v owner.settings.cargo.rebuild.success=Cargoインデックスは正常に再構築されました。 owner.settings.cleanuprules.title=クリーンアップルールの管理 owner.settings.cleanuprules.add=クリーンアップルールを追加 owner.settings.cleanuprules.edit=クリーンアップルールを編集 +owner.settings.cleanuprules.none=クリーンアップルールはありません。 ドキュメントを参照してください。 owner.settings.cleanuprules.preview=クリーンアップルールをプレビュー owner.settings.cleanuprules.preview.overview=%d パッケージが削除される予定です。 owner.settings.cleanuprules.preview.none=クリーンアップルールと一致するパッケージがありません。 @@ -3321,6 +3351,7 @@ owner.settings.cleanuprules.success.update=クリーンアップルールが更 owner.settings.cleanuprules.success.delete=クリーンアップルールが削除されました。 owner.settings.chef.title=Chefレジストリ owner.settings.chef.keypair=キーペアを生成 +owner.settings.chef.keypair.description=Chefレジストリの認証にはキーペアが必要です。 すでにキーペアを生成していた場合、新しいキーペアを生成すると古いキーペアは破棄されます。 [secrets] secrets=シークレット From fcb4941d47217f3a369148d98b07e27205f385b8 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 1 Sep 2023 14:59:38 +0800 Subject: [PATCH 53/68] Remove some unused CSS styles (#26852) 1. `icons`: globally searched, no use in templates. 2. toast's `display: inline-block;`: there is a `display: flex` below. --- web_src/css/base.css | 13 +------------ web_src/css/modules/toast.css | 1 - 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/web_src/css/base.css b/web_src/css/base.css index 20ddf01486d8..4330fb1df0d0 100644 --- a/web_src/css/base.css +++ b/web_src/css/base.css @@ -1647,10 +1647,6 @@ img.ui.avatar, margin-top: 1px; } -i.icons .icon:first-child { - margin-right: 0; -} - .ui.label { padding: 0.3em 0.5em; transition: none; @@ -1686,14 +1682,6 @@ a.ui.active.label:hover { color: var(--color-label-text); } -.ui.label > .detail .icons { - margin-right: 0.25em; -} - -.ui.label > .detail .icons .icon { - margin-right: 0; -} - .lines-blame-btn { padding-left: 10px; padding-right: 10px; @@ -2099,6 +2087,7 @@ table th[data-sortt-desc] .svg { vertical-align: -0.15em; } +/* for the jquery.minicolors plugin */ .minicolors-panel { background: var(--color-secondary-dark-1) !important; } diff --git a/web_src/css/modules/toast.css b/web_src/css/modules/toast.css index 0bfaa5be4155..2a9f78e01756 100644 --- a/web_src/css/modules/toast.css +++ b/web_src/css/modules/toast.css @@ -28,7 +28,6 @@ border-radius: var(--border-radius); background: transparent; border: none; - display: inline-block; display: flex; width: 30px; height: 30px; From e8aae43f56fedd6f7b04affd378c2c4ed2af9d78 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 1 Sep 2023 19:26:07 +0800 Subject: [PATCH 54/68] Move web/api context related testing function into a separate package (#26859) Just like `models/unittest`, the testing helper functions should be in a separate package: `contexttest` And complete the TODO: > // TODO: move this function to other packages, because it depends on "models" package --- .../{test => contexttest}/context_tests.go | 9 ++- routers/api/v1/misc/markup_test.go | 10 +-- routers/api/v1/repo/hook_test.go | 10 +-- routers/api/v1/repo/repo_test.go | 14 ++-- routers/web/admin/users_test.go | 12 ++-- routers/web/org/projects_test.go | 6 +- routers/web/repo/editor_test.go | 22 +++--- routers/web/repo/issue_label_test.go | 43 +++++------ routers/web/repo/projects_test.go | 8 +-- routers/web/repo/release_test.go | 18 ++--- routers/web/repo/setting/settings_test.go | 54 +++++++------- routers/web/repo/wiki_test.go | 52 +++++++------- routers/web/user/home_test.go | 22 +++--- routers/web/user/setting/account_test.go | 8 +-- services/markup/processorhelper_test.go | 4 +- services/repository/archiver/archiver_test.go | 8 +-- services/repository/files/content_test.go | 70 +++++++++--------- services/repository/files/diff_test.go | 22 +++--- services/repository/files/file_test.go | 12 ++-- services/repository/files/tree_test.go | 12 ++-- tests/integration/repofiles_change_test.go | 72 +++++++++---------- 21 files changed, 244 insertions(+), 244 deletions(-) rename modules/{test => contexttest}/context_tests.go (94%) diff --git a/modules/test/context_tests.go b/modules/contexttest/context_tests.go similarity index 94% rename from modules/test/context_tests.go rename to modules/contexttest/context_tests.go index 83e6117bcf33..f8fb0859e3c6 100644 --- a/modules/test/context_tests.go +++ b/modules/contexttest/context_tests.go @@ -1,7 +1,8 @@ // Copyright 2017 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -package test +// Package contexttest provides utilities for testing Web/API contexts with models. +package contexttest import ( gocontext "context" @@ -22,7 +23,7 @@ import ( "code.gitea.io/gitea/modules/translation" "code.gitea.io/gitea/modules/web/middleware" - chi "github.com/go-chi/chi/v5" + "github.com/go-chi/chi/v5" "github.com/stretchr/testify/assert" ) @@ -40,7 +41,6 @@ func mockRequest(t *testing.T, reqPath string) *http.Request { } // MockContext mock context for unit tests -// TODO: move this function to other packages, because it depends on "models" package func MockContext(t *testing.T, reqPath string) (*context.Context, *httptest.ResponseRecorder) { resp := httptest.NewRecorder() req := mockRequest(t, reqPath) @@ -58,7 +58,6 @@ func MockContext(t *testing.T, reqPath string) (*context.Context, *httptest.Resp } // MockAPIContext mock context for unit tests -// TODO: move this function to other packages, because it depends on "models" package func MockAPIContext(t *testing.T, reqPath string) (*context.APIContext, *httptest.ResponseRecorder) { resp := httptest.NewRecorder() req := mockRequest(t, reqPath) @@ -123,7 +122,7 @@ func LoadRepoCommit(t *testing.T, ctx gocontext.Context) { } } -// LoadUser load a user into a test context. +// LoadUser load a user into a test context func LoadUser(t *testing.T, ctx gocontext.Context, userID int64) { doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID}) switch ctx := ctx.(type) { diff --git a/routers/api/v1/misc/markup_test.go b/routers/api/v1/misc/markup_test.go index bab06b3e6626..ec8f8f47b704 100644 --- a/routers/api/v1/misc/markup_test.go +++ b/routers/api/v1/misc/markup_test.go @@ -10,10 +10,10 @@ import ( "strings" "testing" + "code.gitea.io/gitea/modules/contexttest" "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/modules/web" "github.com/stretchr/testify/assert" @@ -34,7 +34,7 @@ func testRenderMarkup(t *testing.T, mode, filePath, text, responseBody string, r Wiki: true, FilePath: filePath, } - ctx, resp := test.MockAPIContext(t, "POST /api/v1/markup") + ctx, resp := contexttest.MockAPIContext(t, "POST /api/v1/markup") web.SetForm(ctx, &options) Markup(ctx) assert.Equal(t, responseBody, resp.Body.String()) @@ -50,7 +50,7 @@ func testRenderMarkdown(t *testing.T, mode, text, responseBody string, responseC Context: Repo, Wiki: true, } - ctx, resp := test.MockAPIContext(t, "POST /api/v1/markdown") + ctx, resp := contexttest.MockAPIContext(t, "POST /api/v1/markdown") web.SetForm(ctx, &options) Markdown(ctx) assert.Equal(t, responseBody, resp.Body.String()) @@ -162,7 +162,7 @@ func TestAPI_RenderSimple(t *testing.T) { Text: "", Context: Repo, } - ctx, resp := test.MockAPIContext(t, "POST /api/v1/markdown") + ctx, resp := contexttest.MockAPIContext(t, "POST /api/v1/markdown") for i := 0; i < len(simpleCases); i += 2 { options.Text = simpleCases[i] web.SetForm(ctx, &options) @@ -174,7 +174,7 @@ func TestAPI_RenderSimple(t *testing.T) { func TestAPI_RenderRaw(t *testing.T) { setting.AppURL = AppURL - ctx, resp := test.MockAPIContext(t, "POST /api/v1/markdown") + ctx, resp := contexttest.MockAPIContext(t, "POST /api/v1/markdown") for i := 0; i < len(simpleCases); i += 2 { ctx.Req.Body = io.NopCloser(strings.NewReader(simpleCases[i])) MarkdownRaw(ctx) diff --git a/routers/api/v1/repo/hook_test.go b/routers/api/v1/repo/hook_test.go index b43a22cd55f8..94a71e20ad70 100644 --- a/routers/api/v1/repo/hook_test.go +++ b/routers/api/v1/repo/hook_test.go @@ -9,7 +9,7 @@ import ( "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/webhook" - "code.gitea.io/gitea/modules/test" + "code.gitea.io/gitea/modules/contexttest" "github.com/stretchr/testify/assert" ) @@ -17,11 +17,11 @@ import ( func TestTestHook(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockAPIContext(t, "user2/repo1/wiki/_pages") + ctx, _ := contexttest.MockAPIContext(t, "user2/repo1/wiki/_pages") ctx.SetParams(":id", "1") - test.LoadRepo(t, ctx, 1) - test.LoadRepoCommit(t, ctx) - test.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadRepoCommit(t, ctx) + contexttest.LoadUser(t, ctx, 2) TestHook(ctx) assert.EqualValues(t, http.StatusNoContent, ctx.Resp.Status()) diff --git a/routers/api/v1/repo/repo_test.go b/routers/api/v1/repo/repo_test.go index 7593a87c2c0b..29e2d1f21d9a 100644 --- a/routers/api/v1/repo/repo_test.go +++ b/routers/api/v1/repo/repo_test.go @@ -9,8 +9,8 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" + "code.gitea.io/gitea/modules/contexttest" api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/modules/web" "github.com/stretchr/testify/assert" @@ -19,9 +19,9 @@ import ( func TestRepoEdit(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockAPIContext(t, "user2/repo1") - test.LoadRepo(t, ctx, 1) - test.LoadUser(t, ctx, 2) + ctx, _ := contexttest.MockAPIContext(t, "user2/repo1") + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadUser(t, ctx, 2) ctx.Repo.Owner = ctx.Doer description := "new description" website := "http://wwww.newwebsite.com" @@ -65,9 +65,9 @@ func TestRepoEdit(t *testing.T) { func TestRepoEditNameChange(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockAPIContext(t, "user2/repo1") - test.LoadRepo(t, ctx, 1) - test.LoadUser(t, ctx, 2) + ctx, _ := contexttest.MockAPIContext(t, "user2/repo1") + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadUser(t, ctx, 2) ctx.Repo.Owner = ctx.Doer name := "newname" opts := api.EditRepoOption{ diff --git a/routers/web/admin/users_test.go b/routers/web/admin/users_test.go index 19d6d7294da6..560ee70ea04c 100644 --- a/routers/web/admin/users_test.go +++ b/routers/web/admin/users_test.go @@ -8,9 +8,9 @@ import ( "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/contexttest" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/services/forms" @@ -19,7 +19,7 @@ import ( func TestNewUserPost_MustChangePassword(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "admin/users/new") + ctx, _ := contexttest.MockContext(t, "admin/users/new") u := unittest.AssertExistsAndLoadBean(t, &user_model.User{ IsAdmin: true, @@ -56,7 +56,7 @@ func TestNewUserPost_MustChangePassword(t *testing.T) { func TestNewUserPost_MustChangePasswordFalse(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "admin/users/new") + ctx, _ := contexttest.MockContext(t, "admin/users/new") u := unittest.AssertExistsAndLoadBean(t, &user_model.User{ IsAdmin: true, @@ -93,7 +93,7 @@ func TestNewUserPost_MustChangePasswordFalse(t *testing.T) { func TestNewUserPost_InvalidEmail(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "admin/users/new") + ctx, _ := contexttest.MockContext(t, "admin/users/new") u := unittest.AssertExistsAndLoadBean(t, &user_model.User{ IsAdmin: true, @@ -123,7 +123,7 @@ func TestNewUserPost_InvalidEmail(t *testing.T) { func TestNewUserPost_VisibilityDefaultPublic(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "admin/users/new") + ctx, _ := contexttest.MockContext(t, "admin/users/new") u := unittest.AssertExistsAndLoadBean(t, &user_model.User{ IsAdmin: true, @@ -161,7 +161,7 @@ func TestNewUserPost_VisibilityDefaultPublic(t *testing.T) { func TestNewUserPost_VisibilityPrivate(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "admin/users/new") + ctx, _ := contexttest.MockContext(t, "admin/users/new") u := unittest.AssertExistsAndLoadBean(t, &user_model.User{ IsAdmin: true, diff --git a/routers/web/org/projects_test.go b/routers/web/org/projects_test.go index 08a97b7d2dee..8053ab4cf93f 100644 --- a/routers/web/org/projects_test.go +++ b/routers/web/org/projects_test.go @@ -7,7 +7,7 @@ import ( "testing" "code.gitea.io/gitea/models/unittest" - "code.gitea.io/gitea/modules/test" + "code.gitea.io/gitea/modules/contexttest" "code.gitea.io/gitea/routers/web/org" "github.com/stretchr/testify/assert" @@ -15,8 +15,8 @@ import ( func TestCheckProjectBoardChangePermissions(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/-/projects/4/4") - test.LoadUser(t, ctx, 2) + ctx, _ := contexttest.MockContext(t, "user2/-/projects/4/4") + contexttest.LoadUser(t, ctx, 2) ctx.ContextUser = ctx.Doer // user2 ctx.SetParams(":id", "4") ctx.SetParams(":boardID", "4") diff --git a/routers/web/repo/editor_test.go b/routers/web/repo/editor_test.go index 52dded68b793..67fb277d5c2b 100644 --- a/routers/web/repo/editor_test.go +++ b/routers/web/repo/editor_test.go @@ -7,8 +7,8 @@ import ( "testing" "code.gitea.io/gitea/models/unittest" + "code.gitea.io/gitea/modules/contexttest" "code.gitea.io/gitea/modules/git" - "code.gitea.io/gitea/modules/test" "github.com/stretchr/testify/assert" ) @@ -41,12 +41,12 @@ func TestCleanUploadName(t *testing.T) { func TestGetUniquePatchBranchName(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1") + ctx, _ := contexttest.MockContext(t, "user2/repo1") ctx.SetParams(":id", "1") - test.LoadRepo(t, ctx, 1) - test.LoadRepoCommit(t, ctx) - test.LoadUser(t, ctx, 2) - test.LoadGitRepo(t, ctx) + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadRepoCommit(t, ctx) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadGitRepo(t, ctx) defer ctx.Repo.GitRepo.Close() expectedBranchName := "user2-patch-1" @@ -56,12 +56,12 @@ func TestGetUniquePatchBranchName(t *testing.T) { func TestGetClosestParentWithFiles(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1") + ctx, _ := contexttest.MockContext(t, "user2/repo1") ctx.SetParams(":id", "1") - test.LoadRepo(t, ctx, 1) - test.LoadRepoCommit(t, ctx) - test.LoadUser(t, ctx, 2) - test.LoadGitRepo(t, ctx) + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadRepoCommit(t, ctx) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadGitRepo(t, ctx) defer ctx.Repo.GitRepo.Close() repo := ctx.Repo.Repository diff --git a/routers/web/repo/issue_label_test.go b/routers/web/repo/issue_label_test.go index e29582f9687f..e0d49e44e186 100644 --- a/routers/web/repo/issue_label_test.go +++ b/routers/web/repo/issue_label_test.go @@ -10,6 +10,7 @@ import ( issues_model "code.gitea.io/gitea/models/issues" "code.gitea.io/gitea/models/unittest" + "code.gitea.io/gitea/modules/contexttest" "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/modules/web" @@ -32,9 +33,9 @@ func int64SliceToCommaSeparated(a []int64) string { func TestInitializeLabels(t *testing.T) { unittest.PrepareTestEnv(t) assert.NoError(t, repository.LoadRepoConfig()) - ctx, _ := test.MockContext(t, "user2/repo1/labels/initialize") - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, 2) + ctx, _ := contexttest.MockContext(t, "user2/repo1/labels/initialize") + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, 2) web.SetForm(ctx, &forms.InitializeLabelsForm{TemplateName: "Default"}) InitializeLabels(ctx) assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) @@ -57,9 +58,9 @@ func TestRetrieveLabels(t *testing.T) { {1, "leastissues", []int64{2, 1}}, {2, "", []int64{}}, } { - ctx, _ := test.MockContext(t, "user/repo/issues") - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, testCase.RepoID) + ctx, _ := contexttest.MockContext(t, "user/repo/issues") + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, testCase.RepoID) ctx.Req.Form.Set("sort", testCase.Sort) RetrieveLabels(ctx) assert.False(t, ctx.Written()) @@ -75,9 +76,9 @@ func TestRetrieveLabels(t *testing.T) { func TestNewLabel(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/labels/edit") - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, 1) + ctx, _ := contexttest.MockContext(t, "user2/repo1/labels/edit") + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, 1) web.SetForm(ctx, &forms.CreateLabelForm{ Title: "newlabel", Color: "#abcdef", @@ -93,9 +94,9 @@ func TestNewLabel(t *testing.T) { func TestUpdateLabel(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/labels/edit") - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, 1) + ctx, _ := contexttest.MockContext(t, "user2/repo1/labels/edit") + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, 1) web.SetForm(ctx, &forms.CreateLabelForm{ ID: 2, Title: "newnameforlabel", @@ -114,9 +115,9 @@ func TestUpdateLabel(t *testing.T) { func TestDeleteLabel(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/labels/delete") - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, 1) + ctx, _ := contexttest.MockContext(t, "user2/repo1/labels/delete") + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, 1) ctx.Req.Form.Set("id", "2") DeleteLabel(ctx) assert.EqualValues(t, http.StatusOK, ctx.Resp.Status()) @@ -127,9 +128,9 @@ func TestDeleteLabel(t *testing.T) { func TestUpdateIssueLabel_Clear(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/issues/labels") - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, 1) + ctx, _ := contexttest.MockContext(t, "user2/repo1/issues/labels") + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, 1) ctx.Req.Form.Set("issue_ids", "1,3") ctx.Req.Form.Set("action", "clear") UpdateIssueLabel(ctx) @@ -152,9 +153,9 @@ func TestUpdateIssueLabel_Toggle(t *testing.T) { {"toggle", []int64{1, 2}, 2, true}, } { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/issues/labels") - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, 1) + ctx, _ := contexttest.MockContext(t, "user2/repo1/issues/labels") + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, 1) ctx.Req.Form.Set("issue_ids", int64SliceToCommaSeparated(testCase.IssueIDs)) ctx.Req.Form.Set("action", testCase.Action) ctx.Req.Form.Set("id", strconv.Itoa(int(testCase.LabelID))) diff --git a/routers/web/repo/projects_test.go b/routers/web/repo/projects_test.go index e2797772a8f6..6698d47028b2 100644 --- a/routers/web/repo/projects_test.go +++ b/routers/web/repo/projects_test.go @@ -7,16 +7,16 @@ import ( "testing" "code.gitea.io/gitea/models/unittest" - "code.gitea.io/gitea/modules/test" + "code.gitea.io/gitea/modules/contexttest" "github.com/stretchr/testify/assert" ) func TestCheckProjectBoardChangePermissions(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/projects/1/2") - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, 1) + ctx, _ := contexttest.MockContext(t, "user2/repo1/projects/1/2") + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, 1) ctx.SetParams(":id", "1") ctx.SetParams(":boardID", "2") diff --git a/routers/web/repo/release_test.go b/routers/web/repo/release_test.go index 07e349811e39..54118fb6b3e4 100644 --- a/routers/web/repo/release_test.go +++ b/routers/web/repo/release_test.go @@ -8,7 +8,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" - "code.gitea.io/gitea/modules/test" + "code.gitea.io/gitea/modules/contexttest" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/services/forms" @@ -47,10 +47,10 @@ func TestNewReleasePost(t *testing.T) { } { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/releases/new") - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, 1) - test.LoadGitRepo(t, ctx) + ctx, _ := contexttest.MockContext(t, "user2/repo1/releases/new") + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadGitRepo(t, ctx) web.SetForm(ctx, &testCase.Form) NewReleasePost(ctx) unittest.AssertExistsAndLoadBean(t, &repo_model.Release{ @@ -67,10 +67,10 @@ func TestNewReleasePost(t *testing.T) { func TestNewReleasesList(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo-release/releases") - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, 57) - test.LoadGitRepo(t, ctx) + ctx, _ := contexttest.MockContext(t, "user2/repo-release/releases") + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, 57) + contexttest.LoadGitRepo(t, ctx) t.Cleanup(func() { ctx.Repo.GitRepo.Close() }) Releases(ctx) diff --git a/routers/web/repo/setting/settings_test.go b/routers/web/repo/setting/settings_test.go index 6f7c844ce7a0..51d127bfc2b3 100644 --- a/routers/web/repo/setting/settings_test.go +++ b/routers/web/repo/setting/settings_test.go @@ -15,8 +15,8 @@ import ( "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/contexttest" "code.gitea.io/gitea/modules/setting" - "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/services/forms" @@ -42,10 +42,10 @@ func TestAddReadOnlyDeployKey(t *testing.T) { } unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/settings/keys") + ctx, _ := contexttest.MockContext(t, "user2/repo1/settings/keys") - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, 2) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, 2) addKeyForm := forms.AddKeyForm{ Title: "read-only", @@ -71,10 +71,10 @@ func TestAddReadWriteOnlyDeployKey(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/settings/keys") + ctx, _ := contexttest.MockContext(t, "user2/repo1/settings/keys") - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, 2) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, 2) addKeyForm := forms.AddKeyForm{ Title: "read-write", @@ -94,10 +94,10 @@ func TestAddReadWriteOnlyDeployKey(t *testing.T) { func TestCollaborationPost(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/issues/labels") - test.LoadUser(t, ctx, 2) - test.LoadUser(t, ctx, 4) - test.LoadRepo(t, ctx, 1) + ctx, _ := contexttest.MockContext(t, "user2/repo1/issues/labels") + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadUser(t, ctx, 4) + contexttest.LoadRepo(t, ctx, 1) ctx.Req.Form.Set("collaborator", "user4") @@ -129,10 +129,10 @@ func TestCollaborationPost(t *testing.T) { func TestCollaborationPost_InactiveUser(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/issues/labels") - test.LoadUser(t, ctx, 2) - test.LoadUser(t, ctx, 9) - test.LoadRepo(t, ctx, 1) + ctx, _ := contexttest.MockContext(t, "user2/repo1/issues/labels") + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadUser(t, ctx, 9) + contexttest.LoadRepo(t, ctx, 1) ctx.Req.Form.Set("collaborator", "user9") @@ -152,10 +152,10 @@ func TestCollaborationPost_InactiveUser(t *testing.T) { func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/issues/labels") - test.LoadUser(t, ctx, 2) - test.LoadUser(t, ctx, 4) - test.LoadRepo(t, ctx, 1) + ctx, _ := contexttest.MockContext(t, "user2/repo1/issues/labels") + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadUser(t, ctx, 4) + contexttest.LoadRepo(t, ctx, 1) ctx.Req.Form.Set("collaborator", "user4") @@ -193,9 +193,9 @@ func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) { func TestCollaborationPost_NonExistentUser(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/issues/labels") - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, 1) + ctx, _ := contexttest.MockContext(t, "user2/repo1/issues/labels") + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, 1) ctx.Req.Form.Set("collaborator", "user34") @@ -215,7 +215,7 @@ func TestCollaborationPost_NonExistentUser(t *testing.T) { func TestAddTeamPost(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "org26/repo43") + ctx, _ := contexttest.MockContext(t, "org26/repo43") ctx.Req.Form.Set("team", "team11") @@ -255,7 +255,7 @@ func TestAddTeamPost(t *testing.T) { func TestAddTeamPost_NotAllowed(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "org26/repo43") + ctx, _ := contexttest.MockContext(t, "org26/repo43") ctx.Req.Form.Set("team", "team11") @@ -295,7 +295,7 @@ func TestAddTeamPost_NotAllowed(t *testing.T) { func TestAddTeamPost_AddTeamTwice(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "org26/repo43") + ctx, _ := contexttest.MockContext(t, "org26/repo43") ctx.Req.Form.Set("team", "team11") @@ -336,7 +336,7 @@ func TestAddTeamPost_AddTeamTwice(t *testing.T) { func TestAddTeamPost_NonExistentTeam(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "org26/repo43") + ctx, _ := contexttest.MockContext(t, "org26/repo43") ctx.Req.Form.Set("team", "team-non-existent") @@ -369,7 +369,7 @@ func TestAddTeamPost_NonExistentTeam(t *testing.T) { func TestDeleteTeam(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "org3/team1/repo3") + ctx, _ := contexttest.MockContext(t, "org3/team1/repo3") ctx.Req.Form.Set("id", "2") diff --git a/routers/web/repo/wiki_test.go b/routers/web/repo/wiki_test.go index e1284fad6707..ae050df967a5 100644 --- a/routers/web/repo/wiki_test.go +++ b/routers/web/repo/wiki_test.go @@ -11,8 +11,8 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" + "code.gitea.io/gitea/modules/contexttest" "code.gitea.io/gitea/modules/git" - "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/services/forms" wiki_service "code.gitea.io/gitea/services/wiki" @@ -78,9 +78,9 @@ func assertPagesMetas(t *testing.T, expectedNames []string, metas any) { func TestWiki(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/wiki/?action=_pages") + ctx, _ := contexttest.MockContext(t, "user2/repo1/wiki/?action=_pages") ctx.SetParams("*", "Home") - test.LoadRepo(t, ctx, 1) + contexttest.LoadRepo(t, ctx, 1) Wiki(ctx) assert.EqualValues(t, http.StatusOK, ctx.Resp.Status()) assert.EqualValues(t, "Home", ctx.Data["Title"]) @@ -90,8 +90,8 @@ func TestWiki(t *testing.T) { func TestWikiPages(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/wiki/?action=_pages") - test.LoadRepo(t, ctx, 1) + ctx, _ := contexttest.MockContext(t, "user2/repo1/wiki/?action=_pages") + contexttest.LoadRepo(t, ctx, 1) WikiPages(ctx) assert.EqualValues(t, http.StatusOK, ctx.Resp.Status()) assertPagesMetas(t, []string{"Home", "Page With Image", "Page With Spaced Name", "Unescaped File"}, ctx.Data["Pages"]) @@ -100,9 +100,9 @@ func TestWikiPages(t *testing.T) { func TestNewWiki(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/wiki/?action=_new") - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, 1) + ctx, _ := contexttest.MockContext(t, "user2/repo1/wiki/?action=_new") + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, 1) NewWiki(ctx) assert.EqualValues(t, http.StatusOK, ctx.Resp.Status()) assert.EqualValues(t, ctx.Tr("repo.wiki.new_page"), ctx.Data["Title"]) @@ -115,9 +115,9 @@ func TestNewWikiPost(t *testing.T) { } { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/wiki/?action=_new") - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, 1) + ctx, _ := contexttest.MockContext(t, "user2/repo1/wiki/?action=_new") + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, 1) web.SetForm(ctx, &forms.NewWikiForm{ Title: title, Content: content, @@ -133,9 +133,9 @@ func TestNewWikiPost(t *testing.T) { func TestNewWikiPost_ReservedName(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/wiki/?action=_new") - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, 1) + ctx, _ := contexttest.MockContext(t, "user2/repo1/wiki/?action=_new") + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, 1) web.SetForm(ctx, &forms.NewWikiForm{ Title: "_edit", Content: content, @@ -150,10 +150,10 @@ func TestNewWikiPost_ReservedName(t *testing.T) { func TestEditWiki(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/wiki/Home?action=_edit") + ctx, _ := contexttest.MockContext(t, "user2/repo1/wiki/Home?action=_edit") ctx.SetParams("*", "Home") - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, 1) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, 1) EditWiki(ctx) assert.EqualValues(t, http.StatusOK, ctx.Resp.Status()) assert.EqualValues(t, "Home", ctx.Data["Title"]) @@ -166,10 +166,10 @@ func TestEditWikiPost(t *testing.T) { "New/", } { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/wiki/Home?action=_new") + ctx, _ := contexttest.MockContext(t, "user2/repo1/wiki/Home?action=_new") ctx.SetParams("*", "Home") - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, 1) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, 1) web.SetForm(ctx, &forms.NewWikiForm{ Title: title, Content: content, @@ -188,9 +188,9 @@ func TestEditWikiPost(t *testing.T) { func TestDeleteWikiPagePost(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/wiki/Home?action=_delete") - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, 1) + ctx, _ := contexttest.MockContext(t, "user2/repo1/wiki/Home?action=_delete") + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, 1) DeleteWikiPagePost(ctx) assert.EqualValues(t, http.StatusOK, ctx.Resp.Status()) assertWikiNotExists(t, ctx.Repo.Repository, "Home") @@ -207,10 +207,10 @@ func TestWikiRaw(t *testing.T) { } { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1/wiki/raw/"+url.PathEscape(filepath)) + ctx, _ := contexttest.MockContext(t, "user2/repo1/wiki/raw/"+url.PathEscape(filepath)) ctx.SetParams("*", filepath) - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, 1) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, 1) WikiRaw(ctx) if filetype == "" { assert.EqualValues(t, http.StatusNotFound, ctx.Resp.Status(), "filepath: %s", filepath) diff --git a/routers/web/user/home_test.go b/routers/web/user/home_test.go index 634a91545e9c..0be9790548da 100644 --- a/routers/web/user/home_test.go +++ b/routers/web/user/home_test.go @@ -9,8 +9,8 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" + "code.gitea.io/gitea/modules/contexttest" "code.gitea.io/gitea/modules/setting" - "code.gitea.io/gitea/modules/test" "github.com/stretchr/testify/assert" ) @@ -20,8 +20,8 @@ func TestArchivedIssues(t *testing.T) { setting.UI.IssuePagingNum = 1 assert.NoError(t, unittest.LoadFixtures()) - ctx, _ := test.MockContext(t, "issues") - test.LoadUser(t, ctx, 30) + ctx, _ := contexttest.MockContext(t, "issues") + contexttest.LoadUser(t, ctx, 30) ctx.Req.Form.Set("state", "open") // Assume: User 30 has access to two Repos with Issues, one of the Repos being archived. @@ -53,8 +53,8 @@ func TestIssues(t *testing.T) { setting.UI.IssuePagingNum = 1 assert.NoError(t, unittest.LoadFixtures()) - ctx, _ := test.MockContext(t, "issues") - test.LoadUser(t, ctx, 2) + ctx, _ := contexttest.MockContext(t, "issues") + contexttest.LoadUser(t, ctx, 2) ctx.Req.Form.Set("state", "closed") Issues(ctx) assert.EqualValues(t, http.StatusOK, ctx.Resp.Status()) @@ -69,8 +69,8 @@ func TestPulls(t *testing.T) { setting.UI.IssuePagingNum = 20 assert.NoError(t, unittest.LoadFixtures()) - ctx, _ := test.MockContext(t, "pulls") - test.LoadUser(t, ctx, 2) + ctx, _ := contexttest.MockContext(t, "pulls") + contexttest.LoadUser(t, ctx, 2) ctx.Req.Form.Set("state", "open") Pulls(ctx) assert.EqualValues(t, http.StatusOK, ctx.Resp.Status()) @@ -82,8 +82,8 @@ func TestMilestones(t *testing.T) { setting.UI.IssuePagingNum = 1 assert.NoError(t, unittest.LoadFixtures()) - ctx, _ := test.MockContext(t, "milestones") - test.LoadUser(t, ctx, 2) + ctx, _ := contexttest.MockContext(t, "milestones") + contexttest.LoadUser(t, ctx, 2) ctx.SetParams("sort", "issues") ctx.Req.Form.Set("state", "closed") ctx.Req.Form.Set("sort", "furthestduedate") @@ -101,8 +101,8 @@ func TestMilestonesForSpecificRepo(t *testing.T) { setting.UI.IssuePagingNum = 1 assert.NoError(t, unittest.LoadFixtures()) - ctx, _ := test.MockContext(t, "milestones") - test.LoadUser(t, ctx, 2) + ctx, _ := contexttest.MockContext(t, "milestones") + contexttest.LoadUser(t, ctx, 2) ctx.SetParams("sort", "issues") ctx.SetParams("repo", "1") ctx.Req.Form.Set("state", "closed") diff --git a/routers/web/user/setting/account_test.go b/routers/web/user/setting/account_test.go index ba840db28894..6742c382e97e 100644 --- a/routers/web/user/setting/account_test.go +++ b/routers/web/user/setting/account_test.go @@ -8,8 +8,8 @@ import ( "testing" "code.gitea.io/gitea/models/unittest" + "code.gitea.io/gitea/modules/contexttest" "code.gitea.io/gitea/modules/setting" - "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/services/forms" @@ -83,9 +83,9 @@ func TestChangePassword(t *testing.T) { t.Run(req.OldPassword+"__"+req.NewPassword, func(t *testing.T) { unittest.PrepareTestEnv(t) setting.PasswordComplexity = req.PasswordComplexity - ctx, _ := test.MockContext(t, "user/settings/security") - test.LoadUser(t, ctx, 2) - test.LoadRepo(t, ctx, 1) + ctx, _ := contexttest.MockContext(t, "user/settings/security") + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadRepo(t, ctx, 1) web.SetForm(ctx, &forms.ChangePasswordForm{ OldPassword: req.OldPassword, diff --git a/services/markup/processorhelper_test.go b/services/markup/processorhelper_test.go index d83e10903fdc..ef8f56224517 100644 --- a/services/markup/processorhelper_test.go +++ b/services/markup/processorhelper_test.go @@ -13,7 +13,7 @@ import ( "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/user" gitea_context "code.gitea.io/gitea/modules/context" - "code.gitea.io/gitea/modules/test" + "code.gitea.io/gitea/modules/contexttest" "github.com/stretchr/testify/assert" ) @@ -42,7 +42,7 @@ func TestProcessorHelper(t *testing.T) { assert.NoError(t, err) base, baseCleanUp := gitea_context.NewBaseContext(httptest.NewRecorder(), req) defer baseCleanUp() - giteaCtx := gitea_context.NewWebContext(base, &test.MockRender{}, nil) + giteaCtx := gitea_context.NewWebContext(base, &contexttest.MockRender{}, nil) assert.True(t, ProcessorHelper().IsUsernameMentionable(giteaCtx, userPublic)) assert.False(t, ProcessorHelper().IsUsernameMentionable(giteaCtx, userPrivate)) diff --git a/services/repository/archiver/archiver_test.go b/services/repository/archiver/archiver_test.go index 4b6fb7446da2..aa4140d3ec21 100644 --- a/services/repository/archiver/archiver_test.go +++ b/services/repository/archiver/archiver_test.go @@ -10,7 +10,7 @@ import ( "time" "code.gitea.io/gitea/models/unittest" - "code.gitea.io/gitea/modules/test" + "code.gitea.io/gitea/modules/contexttest" "github.com/stretchr/testify/assert" ) @@ -24,11 +24,11 @@ func TestMain(m *testing.M) { func TestArchive_Basic(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - ctx, _ := test.MockContext(t, "user27/repo49") + ctx, _ := contexttest.MockContext(t, "user27/repo49") firstCommit, secondCommit := "51f84af23134", "aacbdfe9e1c4" - test.LoadRepo(t, ctx, 49) - test.LoadGitRepo(t, ctx) + contexttest.LoadRepo(t, ctx, 49) + contexttest.LoadGitRepo(t, ctx) defer ctx.Repo.GitRepo.Close() bogusReq, err := NewRequest(ctx.Repo.Repository.ID, ctx.Repo.GitRepo, firstCommit+".zip") diff --git a/services/repository/files/content_test.go b/services/repository/files/content_test.go index 8ff96822c9a9..3e4c1e2c7039 100644 --- a/services/repository/files/content_test.go +++ b/services/repository/files/content_test.go @@ -9,9 +9,9 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" + "code.gitea.io/gitea/modules/contexttest" "code.gitea.io/gitea/modules/git" api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/modules/test" "github.com/stretchr/testify/assert" ) @@ -54,12 +54,12 @@ func getExpectedReadmeContentsResponse() *api.ContentsResponse { func TestGetContents(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1") + ctx, _ := contexttest.MockContext(t, "user2/repo1") ctx.SetParams(":id", "1") - test.LoadRepo(t, ctx, 1) - test.LoadRepoCommit(t, ctx) - test.LoadUser(t, ctx, 2) - test.LoadGitRepo(t, ctx) + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadRepoCommit(t, ctx) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadGitRepo(t, ctx) defer ctx.Repo.GitRepo.Close() treePath := "README.md" @@ -82,12 +82,12 @@ func TestGetContents(t *testing.T) { func TestGetContentsOrListForDir(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1") + ctx, _ := contexttest.MockContext(t, "user2/repo1") ctx.SetParams(":id", "1") - test.LoadRepo(t, ctx, 1) - test.LoadRepoCommit(t, ctx) - test.LoadUser(t, ctx, 2) - test.LoadGitRepo(t, ctx) + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadRepoCommit(t, ctx) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadGitRepo(t, ctx) defer ctx.Repo.GitRepo.Close() treePath := "" // root dir @@ -117,12 +117,12 @@ func TestGetContentsOrListForDir(t *testing.T) { func TestGetContentsOrListForFile(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1") + ctx, _ := contexttest.MockContext(t, "user2/repo1") ctx.SetParams(":id", "1") - test.LoadRepo(t, ctx, 1) - test.LoadRepoCommit(t, ctx) - test.LoadUser(t, ctx, 2) - test.LoadGitRepo(t, ctx) + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadRepoCommit(t, ctx) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadGitRepo(t, ctx) defer ctx.Repo.GitRepo.Close() treePath := "README.md" @@ -145,12 +145,12 @@ func TestGetContentsOrListForFile(t *testing.T) { func TestGetContentsErrors(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1") + ctx, _ := contexttest.MockContext(t, "user2/repo1") ctx.SetParams(":id", "1") - test.LoadRepo(t, ctx, 1) - test.LoadRepoCommit(t, ctx) - test.LoadUser(t, ctx, 2) - test.LoadGitRepo(t, ctx) + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadRepoCommit(t, ctx) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadGitRepo(t, ctx) defer ctx.Repo.GitRepo.Close() repo := ctx.Repo.Repository @@ -176,12 +176,12 @@ func TestGetContentsErrors(t *testing.T) { func TestGetContentsOrListErrors(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1") + ctx, _ := contexttest.MockContext(t, "user2/repo1") ctx.SetParams(":id", "1") - test.LoadRepo(t, ctx, 1) - test.LoadRepoCommit(t, ctx) - test.LoadUser(t, ctx, 2) - test.LoadGitRepo(t, ctx) + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadRepoCommit(t, ctx) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadGitRepo(t, ctx) defer ctx.Repo.GitRepo.Close() repo := ctx.Repo.Repository @@ -207,11 +207,11 @@ func TestGetContentsOrListErrors(t *testing.T) { func TestGetContentsOrListOfEmptyRepos(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user30/empty") + ctx, _ := contexttest.MockContext(t, "user30/empty") ctx.SetParams(":id", "52") - test.LoadRepo(t, ctx, 52) - test.LoadUser(t, ctx, 30) - test.LoadGitRepo(t, ctx) + contexttest.LoadRepo(t, ctx, 52) + contexttest.LoadUser(t, ctx, 30) + contexttest.LoadGitRepo(t, ctx) defer ctx.Repo.GitRepo.Close() repo := ctx.Repo.Repository @@ -225,11 +225,11 @@ func TestGetContentsOrListOfEmptyRepos(t *testing.T) { func TestGetBlobBySHA(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1") - test.LoadRepo(t, ctx, 1) - test.LoadRepoCommit(t, ctx) - test.LoadUser(t, ctx, 2) - test.LoadGitRepo(t, ctx) + ctx, _ := contexttest.MockContext(t, "user2/repo1") + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadRepoCommit(t, ctx) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadGitRepo(t, ctx) defer ctx.Repo.GitRepo.Close() sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d" diff --git a/services/repository/files/diff_test.go b/services/repository/files/diff_test.go index 0346e0e9e9b7..91c878e50532 100644 --- a/services/repository/files/diff_test.go +++ b/services/repository/files/diff_test.go @@ -8,8 +8,8 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" + "code.gitea.io/gitea/modules/contexttest" "code.gitea.io/gitea/modules/json" - "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/services/gitdiff" "github.com/stretchr/testify/assert" @@ -17,12 +17,12 @@ import ( func TestGetDiffPreview(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1") + ctx, _ := contexttest.MockContext(t, "user2/repo1") ctx.SetParams(":id", "1") - test.LoadRepo(t, ctx, 1) - test.LoadRepoCommit(t, ctx) - test.LoadUser(t, ctx, 2) - test.LoadGitRepo(t, ctx) + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadRepoCommit(t, ctx) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadGitRepo(t, ctx) defer ctx.Repo.GitRepo.Close() branch := ctx.Repo.Repository.DefaultBranch @@ -139,12 +139,12 @@ func TestGetDiffPreview(t *testing.T) { func TestGetDiffPreviewErrors(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1") + ctx, _ := contexttest.MockContext(t, "user2/repo1") ctx.SetParams(":id", "1") - test.LoadRepo(t, ctx, 1) - test.LoadRepoCommit(t, ctx) - test.LoadUser(t, ctx, 2) - test.LoadGitRepo(t, ctx) + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadRepoCommit(t, ctx) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadGitRepo(t, ctx) defer ctx.Repo.GitRepo.Close() branch := ctx.Repo.Repository.DefaultBranch diff --git a/services/repository/files/file_test.go b/services/repository/files/file_test.go index d14a049438eb..4e67ad141085 100644 --- a/services/repository/files/file_test.go +++ b/services/repository/files/file_test.go @@ -7,10 +7,10 @@ import ( "testing" "code.gitea.io/gitea/models/unittest" + "code.gitea.io/gitea/modules/contexttest" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/modules/test" "github.com/stretchr/testify/assert" ) @@ -98,12 +98,12 @@ func getExpectedFileResponse() *api.FileResponse { func TestGetFileResponseFromCommit(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1") + ctx, _ := contexttest.MockContext(t, "user2/repo1") ctx.SetParams(":id", "1") - test.LoadRepo(t, ctx, 1) - test.LoadRepoCommit(t, ctx) - test.LoadUser(t, ctx, 2) - test.LoadGitRepo(t, ctx) + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadRepoCommit(t, ctx) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadGitRepo(t, ctx) defer ctx.Repo.GitRepo.Close() repo := ctx.Repo.Repository diff --git a/services/repository/files/tree_test.go b/services/repository/files/tree_test.go index 51a2190e8f44..528ef500df24 100644 --- a/services/repository/files/tree_test.go +++ b/services/repository/files/tree_test.go @@ -7,19 +7,19 @@ import ( "testing" "code.gitea.io/gitea/models/unittest" + "code.gitea.io/gitea/modules/contexttest" api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/modules/test" "github.com/stretchr/testify/assert" ) func TestGetTreeBySHA(t *testing.T) { unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1") - test.LoadRepo(t, ctx, 1) - test.LoadRepoCommit(t, ctx) - test.LoadUser(t, ctx, 2) - test.LoadGitRepo(t, ctx) + ctx, _ := contexttest.MockContext(t, "user2/repo1") + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadRepoCommit(t, ctx) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadGitRepo(t, ctx) defer ctx.Repo.GitRepo.Close() sha := ctx.Repo.Repository.DefaultBranch diff --git a/tests/integration/repofiles_change_test.go b/tests/integration/repofiles_change_test.go index 765a44689aec..e0edf07299b5 100644 --- a/tests/integration/repofiles_change_test.go +++ b/tests/integration/repofiles_change_test.go @@ -12,10 +12,10 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" + "code.gitea.io/gitea/modules/contexttest" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/modules/test" files_service "code.gitea.io/gitea/services/repository/files" "github.com/stretchr/testify/assert" @@ -245,12 +245,12 @@ func getExpectedFileResponseForRepofilesUpdate(commitID, filename, lastCommitSHA func TestChangeRepoFilesForCreate(t *testing.T) { // setup onGiteaRun(t, func(t *testing.T, u *url.URL) { - ctx, _ := test.MockContext(t, "user2/repo1") + ctx, _ := contexttest.MockContext(t, "user2/repo1") ctx.SetParams(":id", "1") - test.LoadRepo(t, ctx, 1) - test.LoadRepoCommit(t, ctx) - test.LoadUser(t, ctx, 2) - test.LoadGitRepo(t, ctx) + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadRepoCommit(t, ctx) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadGitRepo(t, ctx) defer ctx.Repo.GitRepo.Close() repo := ctx.Repo.Repository @@ -282,12 +282,12 @@ func TestChangeRepoFilesForCreate(t *testing.T) { func TestChangeRepoFilesForUpdate(t *testing.T) { // setup onGiteaRun(t, func(t *testing.T, u *url.URL) { - ctx, _ := test.MockContext(t, "user2/repo1") + ctx, _ := contexttest.MockContext(t, "user2/repo1") ctx.SetParams(":id", "1") - test.LoadRepo(t, ctx, 1) - test.LoadRepoCommit(t, ctx) - test.LoadUser(t, ctx, 2) - test.LoadGitRepo(t, ctx) + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadRepoCommit(t, ctx) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadGitRepo(t, ctx) defer ctx.Repo.GitRepo.Close() repo := ctx.Repo.Repository @@ -316,12 +316,12 @@ func TestChangeRepoFilesForUpdate(t *testing.T) { func TestChangeRepoFilesForUpdateWithFileMove(t *testing.T) { // setup onGiteaRun(t, func(t *testing.T, u *url.URL) { - ctx, _ := test.MockContext(t, "user2/repo1") + ctx, _ := contexttest.MockContext(t, "user2/repo1") ctx.SetParams(":id", "1") - test.LoadRepo(t, ctx, 1) - test.LoadRepoCommit(t, ctx) - test.LoadUser(t, ctx, 2) - test.LoadGitRepo(t, ctx) + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadRepoCommit(t, ctx) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadGitRepo(t, ctx) defer ctx.Repo.GitRepo.Close() repo := ctx.Repo.Repository @@ -367,12 +367,12 @@ func TestChangeRepoFilesForUpdateWithFileMove(t *testing.T) { func TestChangeRepoFilesWithoutBranchNames(t *testing.T) { // setup onGiteaRun(t, func(t *testing.T, u *url.URL) { - ctx, _ := test.MockContext(t, "user2/repo1") + ctx, _ := contexttest.MockContext(t, "user2/repo1") ctx.SetParams(":id", "1") - test.LoadRepo(t, ctx, 1) - test.LoadRepoCommit(t, ctx) - test.LoadUser(t, ctx, 2) - test.LoadGitRepo(t, ctx) + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadRepoCommit(t, ctx) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadGitRepo(t, ctx) defer ctx.Repo.GitRepo.Close() repo := ctx.Repo.Repository @@ -403,12 +403,12 @@ func TestChangeRepoFilesForDelete(t *testing.T) { func testDeleteRepoFiles(t *testing.T, u *url.URL) { // setup unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1") + ctx, _ := contexttest.MockContext(t, "user2/repo1") ctx.SetParams(":id", "1") - test.LoadRepo(t, ctx, 1) - test.LoadRepoCommit(t, ctx) - test.LoadUser(t, ctx, 2) - test.LoadGitRepo(t, ctx) + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadRepoCommit(t, ctx) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadGitRepo(t, ctx) defer ctx.Repo.GitRepo.Close() repo := ctx.Repo.Repository doer := ctx.Doer @@ -442,12 +442,12 @@ func TestChangeRepoFilesForDeleteWithoutBranchNames(t *testing.T) { func testDeleteRepoFilesWithoutBranchNames(t *testing.T, u *url.URL) { // setup unittest.PrepareTestEnv(t) - ctx, _ := test.MockContext(t, "user2/repo1") + ctx, _ := contexttest.MockContext(t, "user2/repo1") ctx.SetParams(":id", "1") - test.LoadRepo(t, ctx, 1) - test.LoadRepoCommit(t, ctx) - test.LoadUser(t, ctx, 2) - test.LoadGitRepo(t, ctx) + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadRepoCommit(t, ctx) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadGitRepo(t, ctx) defer ctx.Repo.GitRepo.Close() repo := ctx.Repo.Repository @@ -472,12 +472,12 @@ func testDeleteRepoFilesWithoutBranchNames(t *testing.T, u *url.URL) { func TestChangeRepoFilesErrors(t *testing.T) { // setup onGiteaRun(t, func(t *testing.T, u *url.URL) { - ctx, _ := test.MockContext(t, "user2/repo1") + ctx, _ := contexttest.MockContext(t, "user2/repo1") ctx.SetParams(":id", "1") - test.LoadRepo(t, ctx, 1) - test.LoadRepoCommit(t, ctx) - test.LoadUser(t, ctx, 2) - test.LoadGitRepo(t, ctx) + contexttest.LoadRepo(t, ctx, 1) + contexttest.LoadRepoCommit(t, ctx) + contexttest.LoadUser(t, ctx, 2) + contexttest.LoadGitRepo(t, ctx) defer ctx.Repo.GitRepo.Close() repo := ctx.Repo.Repository From f01bed2443c32b8017a8dc31ca0161bd76bf3251 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 1 Sep 2023 20:01:36 +0800 Subject: [PATCH 55/68] Avoid double-unescaping of form value (#26853) 1. The old `prepareQueryArg` did double-unescaping of form value. 2. By the way, remove the unnecessary `ctx.Flash = ...` in `MockContext`. Co-authored-by: Giteabot --- modules/context/utils.go | 25 ++++--------------------- modules/contexttest/context_tests.go | 1 - tests/integration/api_issue_test.go | 2 +- tests/integration/issue_test.go | 2 +- 4 files changed, 6 insertions(+), 24 deletions(-) diff --git a/modules/context/utils.go b/modules/context/utils.go index c0f619aa237e..293750fee16f 100644 --- a/modules/context/utils.go +++ b/modules/context/utils.go @@ -4,29 +4,18 @@ package context import ( - "net/url" "strings" "time" ) // GetQueryBeforeSince return parsed time (unix format) from URL query's before and since func GetQueryBeforeSince(ctx *Base) (before, since int64, err error) { - qCreatedBefore, err := prepareQueryArg(ctx, "before") + before, err = parseFormTime(ctx, "before") if err != nil { return 0, 0, err } - qCreatedSince, err := prepareQueryArg(ctx, "since") - if err != nil { - return 0, 0, err - } - - before, err = parseTime(qCreatedBefore) - if err != nil { - return 0, 0, err - } - - since, err = parseTime(qCreatedSince) + since, err = parseFormTime(ctx, "since") if err != nil { return 0, 0, err } @@ -34,7 +23,8 @@ func GetQueryBeforeSince(ctx *Base) (before, since int64, err error) { } // parseTime parse time and return unix timestamp -func parseTime(value string) (int64, error) { +func parseFormTime(ctx *Base, name string) (int64, error) { + value := strings.TrimSpace(ctx.FormString(name)) if len(value) != 0 { t, err := time.Parse(time.RFC3339, value) if err != nil { @@ -46,10 +36,3 @@ func parseTime(value string) (int64, error) { } return 0, nil } - -// prepareQueryArg unescape and trim a query arg -func prepareQueryArg(ctx *Base, name string) (value string, err error) { - value, err = url.PathUnescape(ctx.FormString(name)) - value = strings.TrimSpace(value) - return value, err -} diff --git a/modules/contexttest/context_tests.go b/modules/contexttest/context_tests.go index f8fb0859e3c6..ea91bc50013e 100644 --- a/modules/contexttest/context_tests.go +++ b/modules/contexttest/context_tests.go @@ -50,7 +50,6 @@ func MockContext(t *testing.T, reqPath string) (*context.Context, *httptest.Resp base.Locale = &translation.MockLocale{} ctx := context.NewWebContext(base, &MockRender{}, nil) - ctx.Flash = &middleware.Flash{Values: url.Values{}} chiCtx := chi.NewRouteContext() ctx.Base.AppendContextValue(chi.RouteCtxKey, chiCtx) diff --git a/tests/integration/api_issue_test.go b/tests/integration/api_issue_test.go index 5f4c1e6a4786..5d4b9725dd44 100644 --- a/tests/integration/api_issue_test.go +++ b/tests/integration/api_issue_test.go @@ -234,7 +234,7 @@ func TestAPISearchIssues(t *testing.T) { DecodeJSON(t, resp, &apiIssues) assert.Len(t, apiIssues, expectedIssueCount) - since := "2000-01-01T00%3A50%3A01%2B00%3A00" // 946687801 + since := "2000-01-01T00:50:01+00:00" // 946687801 before := time.Unix(999307200, 0).Format(time.RFC3339) query.Add("since", since) query.Add("before", before) diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go index 58577a37ff28..560f569513b3 100644 --- a/tests/integration/issue_test.go +++ b/tests/integration/issue_test.go @@ -368,7 +368,7 @@ func TestSearchIssues(t *testing.T) { DecodeJSON(t, resp, &apiIssues) assert.Len(t, apiIssues, expectedIssueCount) - since := "2000-01-01T00%3A50%3A01%2B00%3A00" // 946687801 + since := "2000-01-01T00:50:01+00:00" // 946687801 before := time.Unix(999307200, 0).Format(time.RFC3339) query := url.Values{} query.Add("since", since) From 9eb4a9e601c16174306d81ec4d73ffa5a0adc788 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 1 Sep 2023 21:02:49 +0800 Subject: [PATCH 56/68] feat(API): add secret deletion functionality for repository (#26808) - Modify the `CreateOrUpdateSecret` function in `api.go` to include a `Delete` operation for the secret - Modify the `DeleteOrgSecret` function in `action.go` to include a `DeleteSecret` operation for the organization - Modify the `DeleteSecret` function in `action.go` to include a `DeleteSecret` operation for the repository - Modify the `v1_json.tmpl` template file to update the `operationId` and `summary` for the `deleteSecret` operation in both the organization and repository sections --------- Signed-off-by: Bo-Yi Wu --- routers/api/v1/api.go | 5 ++-- routers/api/v1/org/action.go | 8 +++-- routers/api/v1/repo/action.go | 54 ++++++++++++++++++++++++++++++++++ templates/swagger/v1_json.tmpl | 44 +++++++++++++++++++++++++++ 4 files changed, 107 insertions(+), 4 deletions(-) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 32e5a10bbe78..15bf820a6937 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -935,7 +935,8 @@ func Routes() *web.Route { }, reqToken()) m.Group("/actions/secrets", func() { m.Combo("/{secretname}"). - Put(reqToken(), reqOwner(), bind(api.CreateOrUpdateSecretOption{}), repo.CreateOrUpdateSecret) + Put(reqToken(), reqOwner(), bind(api.CreateOrUpdateSecretOption{}), repo.CreateOrUpdateSecret). + Delete(reqToken(), reqOwner(), repo.DeleteSecret) }) m.Group("/hooks/git", func() { m.Combo("").Get(repo.ListGitHooks) @@ -1306,7 +1307,7 @@ func Routes() *web.Route { m.Get("", reqToken(), reqOrgOwnership(), org.ListActionsSecrets) m.Combo("/{secretname}"). Put(reqToken(), reqOrgOwnership(), bind(api.CreateOrUpdateSecretOption{}), org.CreateOrUpdateSecret). - Delete(reqToken(), reqOrgOwnership(), org.DeleteOrgSecret) + Delete(reqToken(), reqOrgOwnership(), org.DeleteSecret) }) m.Group("/public_members", func() { m.Get("", org.ListPublicMembers) diff --git a/routers/api/v1/org/action.go b/routers/api/v1/org/action.go index 0bf741e8256d..a04058be1974 100644 --- a/routers/api/v1/org/action.go +++ b/routers/api/v1/org/action.go @@ -125,8 +125,8 @@ func CreateOrUpdateSecret(ctx *context.APIContext) { ctx.Status(http.StatusNoContent) } -// DeleteOrgSecret delete one secret of the organization -func DeleteOrgSecret(ctx *context.APIContext) { +// DeleteSecret delete one secret of the organization +func DeleteSecret(ctx *context.APIContext) { // swagger:operation DELETE /orgs/{org}/actions/secrets/{secretname} organization deleteOrgSecret // --- // summary: Delete a secret in an organization @@ -151,6 +151,10 @@ func DeleteOrgSecret(ctx *context.APIContext) { // "403": // "$ref": "#/responses/forbidden" secretName := ctx.Params(":secretname") + if err := actions.NameRegexMatch(secretName); err != nil { + ctx.Error(http.StatusBadRequest, "DeleteSecret", err) + return + } err := secret_model.DeleteSecret( ctx, ctx.Org.Organization.ID, 0, secretName, ) diff --git a/routers/api/v1/repo/action.go b/routers/api/v1/repo/action.go index 015c731a75d2..b7642b6af9f8 100644 --- a/routers/api/v1/repo/action.go +++ b/routers/api/v1/repo/action.go @@ -73,3 +73,57 @@ func CreateOrUpdateSecret(ctx *context.APIContext) { ctx.Status(http.StatusNoContent) } + +// DeleteSecret delete one secret of the repository +func DeleteSecret(ctx *context.APIContext) { + // swagger:operation DELETE /repos/{owner}/{repo}/actions/secrets/{secretname} repository deleteRepoSecret + // --- + // summary: Delete a secret in a repository + // consumes: + // - application/json + // produces: + // - application/json + // parameters: + // - name: owner + // in: path + // description: owner of the repository + // type: string + // required: true + // - name: repo + // in: path + // description: name of the repository + // type: string + // required: true + // - name: secretname + // in: path + // description: name of the secret + // type: string + // required: true + // responses: + // "204": + // description: delete one secret of the organization + // "403": + // "$ref": "#/responses/forbidden" + + owner := ctx.Repo.Owner + repo := ctx.Repo.Repository + + secretName := ctx.Params(":secretname") + if err := actions.NameRegexMatch(secretName); err != nil { + ctx.Error(http.StatusBadRequest, "DeleteSecret", err) + return + } + err := secret_model.DeleteSecret( + ctx, owner.ID, repo.ID, secretName, + ) + if secret_model.IsErrSecretNotFound(err) { + ctx.NotFound(err) + return + } + if err != nil { + ctx.Error(http.StatusInternalServerError, "DeleteSecret", err) + return + } + + ctx.Status(http.StatusNoContent) +} diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 78491de2e102..699653d29c09 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -3287,6 +3287,50 @@ "$ref": "#/responses/forbidden" } } + }, + "delete": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "Delete a secret in a repository", + "operationId": "deleteRepoSecret", + "parameters": [ + { + "type": "string", + "description": "owner of the repository", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repository", + "name": "repo", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the secret", + "name": "secretname", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "delete one secret of the organization" + }, + "403": { + "$ref": "#/responses/forbidden" + } + } } }, "/repos/{owner}/{repo}/activities/feeds": { From 4ab8e56c9197135a85300542d736a556203752a6 Mon Sep 17 00:00:00 2001 From: Earl Warren <109468362+earl-warren@users.noreply.github.com> Date: Fri, 1 Sep 2023 15:45:22 +0200 Subject: [PATCH 57/68] restrict certificate type for builtin SSH server (#26789) - While doing some sanity checks over OpenSSH's code for how they handle certificates authentication. I stumbled on an condition that checks the certificate type is really an user certificate on the server-side authentication. This checks seems to be a formality and just for the sake of good domain seperation, because an user and host certificate don't differ in their generation, verification or flags that can be included. - Add this check to the builtin SSH server to stay close to the unwritten SSH specification. - This is an breaking change for setups where the builtin SSH server is being used and for some reason host certificates were being used for authentication. - (cherry picked from commit de35b141b79a3d6efe2127ed2c73fd481515e481) Refs: https://codeberg.org/forgejo/forgejo/pulls/1172 ## :warning: BREAKING :warning: Like OpenSSH, the built-in SSH server will now only accept SSH user certificates, not server certificates. Co-authored-by: Gusted Co-authored-by: Giteabot --- modules/ssh/ssh.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/ssh/ssh.go b/modules/ssh/ssh.go index a5af5c129b8b..37624ab679c8 100644 --- a/modules/ssh/ssh.go +++ b/modules/ssh/ssh.go @@ -191,6 +191,12 @@ func publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) bool { return false } + if cert.CertType != gossh.UserCert { + log.Warn("Certificate Rejected: Not a user certificate") + log.Warn("Failed authentication attempt from %s", ctx.RemoteAddr()) + return false + } + // look for the exact principal principalLoop: for _, principal := range cert.ValidPrincipals { From 327a7ad5185ea532389ff54b5faf91a8cf0429f3 Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 1 Sep 2023 16:07:37 +0200 Subject: [PATCH 58/68] Use case-insensitive regex for all webpack assets (#26867) Previously, only some of these regex had the `i` flag and while we can likely ensure case for our files, these regexes are also used for third-party files, so it's better to always match insensitively. --- webpack.config.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 95749611162e..497aca9224c7 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -41,10 +41,10 @@ const filterCssImport = (url, ...args) => { if (cssFile.includes('fomantic')) { if (/brand-icons/.test(importedFile)) return false; - if (/(eot|ttf|otf|woff|svg)$/.test(importedFile)) return false; + if (/(eot|ttf|otf|woff|svg)$/i.test(importedFile)) return false; } - if (cssFile.includes('katex') && /(ttf|woff)$/.test(importedFile)) { + if (cssFile.includes('katex') && /(ttf|woff)$/i.test(importedFile)) { return false; } @@ -117,12 +117,12 @@ export default { module: { rules: [ { - test: /\.vue$/, + test: /\.vue$/i, exclude: /node_modules/, loader: 'vue-loader', }, { - test: /\.js$/, + test: /\.js$/i, exclude: /node_modules/, use: [ { @@ -151,12 +151,12 @@ export default { ], }, { - test: /\.svg$/, + test: /\.svg$/i, include: fileURLToPath(new URL('public/assets/img/svg', import.meta.url)), type: 'asset/source', }, { - test: /\.(ttf|woff2?)$/, + test: /\.(ttf|woff2?)$/i, type: 'asset/resource', generator: { filename: 'fonts/[name].[contenthash:8][ext]', From 02efd990102481e8d6bd577d4feb874187a00182 Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 1 Sep 2023 16:42:33 +0200 Subject: [PATCH 59/68] Move licenses.txt to /assets directory (#26866) Now that we have the `/assets` directory, we can put`licenses.txt` directly into it instead of incorrect `/js` path which was previously only done to avoid reserving a username. --------- Co-authored-by: Giteabot --- .gitignore | 1 + templates/base/footer_content.tmpl | 2 +- webpack.config.js | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 6b699e08700f..e3b9c3c43eb3 100644 --- a/.gitignore +++ b/.gitignore @@ -75,6 +75,7 @@ cpu.out /public/assets/js /public/assets/css /public/assets/fonts +/public/assets/licenses.txt /public/assets/img/webpack /vendor /web_src/fomantic/node_modules diff --git a/templates/base/footer_content.tmpl b/templates/base/footer_content.tmpl index 3b87f25d6378..cf647f1cc60e 100644 --- a/templates/base/footer_content.tmpl +++ b/templates/base/footer_content.tmpl @@ -23,7 +23,7 @@ {{end}}
- {{.locale.Tr "licenses"}} + {{.locale.Tr "licenses"}} {{if .EnableSwagger}}API{{end}} {{template "custom/extra_links_footer" .}}
diff --git a/webpack.config.js b/webpack.config.js index 497aca9224c7..c6b28068f059 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -188,7 +188,7 @@ export default { filename: 'js/monaco-[name].[contenthash:8].worker.js', }), isProduction ? new LicenseCheckerWebpackPlugin({ - outputFilename: 'js/licenses.txt', + outputFilename: 'licenses.txt', outputWriter: ({dependencies}) => { const line = '-'.repeat(80); const goJson = readFileSync('assets/go-licenses.json', 'utf8'); @@ -211,7 +211,7 @@ export default { }, emitError: true, allow: '(Apache-2.0 OR BSD-2-Clause OR BSD-3-Clause OR MIT OR ISC OR CPAL-1.0 OR Unlicense OR EPL-1.0 OR EPL-2.0)', - }) : new AddAssetPlugin('js/licenses.txt', `Licenses are disabled during development`), + }) : new AddAssetPlugin('licenses.txt', `Licenses are disabled during development`), ], performance: { hints: false, @@ -239,7 +239,7 @@ export default { entrypoints: false, excludeAssets: [ /^js\/monaco-language-.+\.js$/, - !isProduction && /^js\/licenses.txt$/, + !isProduction && /^licenses.txt$/, ].filter(Boolean), groupAssetsByChunk: false, groupAssetsByEmitStatus: false, From 04771b5ff79152a47aecce4b2b445daa4a96da33 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Fri, 1 Sep 2023 23:35:38 +0800 Subject: [PATCH 60/68] Allow users with write permissions for issues to add attachments with API (#26837) Fixes #24944 Since a user with write permissions for issues can add attachments to an issue via the the web interface, the user should also be able to add attachments via the API --- routers/api/v1/repo/issue_attachment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/repo/issue_attachment.go b/routers/api/v1/repo/issue_attachment.go index ad83c206d9c6..c689e70a085b 100644 --- a/routers/api/v1/repo/issue_attachment.go +++ b/routers/api/v1/repo/issue_attachment.go @@ -344,7 +344,7 @@ func getIssueAttachmentSafeRead(ctx *context.APIContext, issue *issues_model.Iss } func canUserWriteIssueAttachment(ctx *context.APIContext, issue *issues_model.Issue) bool { - canEditIssue := ctx.IsSigned && (ctx.Doer.ID == issue.PosterID || ctx.IsUserRepoAdmin() || ctx.IsUserSiteAdmin()) && ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) + canEditIssue := ctx.IsSigned && (ctx.Doer.ID == issue.PosterID || ctx.IsUserRepoAdmin() || ctx.IsUserSiteAdmin() || ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)) if !canEditIssue { ctx.Error(http.StatusForbidden, "", "user should have permission to write issue") return false From 9881b8a4e24bc81b1acd80b51c5c2541b063149e Mon Sep 17 00:00:00 2001 From: Jack Hay Date: Fri, 1 Sep 2023 12:15:39 -0400 Subject: [PATCH 61/68] Add more descriptive error on forgot password page (#26848) ## Changes - Forces flashed error to render immediately when forgot password code is incorrect or has expired. - Adds a link back to the `forgot_password` page so that the user can restart the process (in the event that their link has expired) --- options/locale/locale_en-US.ini | 1 + routers/web/auth/password.go | 7 ++++--- templates/user/auth/reset_passwd.tmpl | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 401692388e5d..66f67d4896a5 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -379,6 +379,7 @@ email_not_associate = The email address is not associated with any account. send_reset_mail = Send Account Recovery Email reset_password = Account Recovery invalid_code = Your confirmation code is invalid or has expired. +invalid_code_forgot_password = Your confirmation code is invalid or has expired. Click here to start a new session. invalid_password = Your password does not match the password that was used to create the account. reset_password_helper = Recover Account reset_password_wrong_user = You are signed in as %s, but the account recovery link is meant for %s diff --git a/routers/web/auth/password.go b/routers/web/auth/password.go index b34a1d8fce16..1432338e7083 100644 --- a/routers/web/auth/password.go +++ b/routers/web/auth/password.go @@ -5,6 +5,7 @@ package auth import ( "errors" + "fmt" "net/http" "code.gitea.io/gitea/models/auth" @@ -108,14 +109,14 @@ func commonResetPassword(ctx *context.Context) (*user_model.User, *auth.TwoFacto } if len(code) == 0 { - ctx.Flash.Error(ctx.Tr("auth.invalid_code")) + ctx.Flash.Error(ctx.Tr("auth.invalid_code_forgot_password", fmt.Sprintf("%s/user/forgot_password", setting.AppSubURL)), true) return nil, nil } // Fail early, don't frustrate the user u := user_model.VerifyUserActiveCode(code) if u == nil { - ctx.Flash.Error(ctx.Tr("auth.invalid_code")) + ctx.Flash.Error(ctx.Tr("auth.invalid_code_forgot_password", fmt.Sprintf("%s/user/forgot_password", setting.AppSubURL)), true) return nil, nil } @@ -134,7 +135,7 @@ func commonResetPassword(ctx *context.Context) (*user_model.User, *auth.TwoFacto ctx.Data["user_email"] = u.Email if nil != ctx.Doer && u.ID != ctx.Doer.ID { - ctx.Flash.Error(ctx.Tr("auth.reset_password_wrong_user", ctx.Doer.Email, u.Email)) + ctx.Flash.Error(ctx.Tr("auth.reset_password_wrong_user", ctx.Doer.Email, u.Email), true) return nil, nil } diff --git a/templates/user/auth/reset_passwd.tmpl b/templates/user/auth/reset_passwd.tmpl index ac6eb35f1d03..d7734bc57f59 100644 --- a/templates/user/auth/reset_passwd.tmpl +++ b/templates/user/auth/reset_passwd.tmpl @@ -57,7 +57,7 @@ {{end}}
{{else}} -

{{.locale.Tr "auth.invalid_code"}}

+

{{.locale.Tr "auth.invalid_code_forgot_password" (printf "%s/user/forgot_password" AppSubUrl) | Str2html}}

{{end}}
From 5743d7cb5bcd85c88ad7d128e0162893a074418b Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Fri, 1 Sep 2023 18:59:24 +0200 Subject: [PATCH 62/68] Improve opengraph previews (#26851) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add more useful Open Graph metadata for commit and file URLs: - Set `og:title` to the page title, which is a concise summary in both cases (` · ` and ` at `, respectively) - Set `og:description` to the commit message body, if available - Set `og:url` to the relevant URLs instead of the repo URL Also move the relevant meta tags into a separate template as they now take up the majority of the base head template. --- templates/base/head.tmpl | 37 +------------------------- templates/base/head_opengraph.tmpl | 42 ++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 36 deletions(-) create mode 100644 templates/base/head_opengraph.tmpl diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index 8eebaebd704e..c3645209cd60 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -25,42 +25,7 @@ .ui.secondary.menu .dropdown.item > .menu { margin-top: 0; } -{{if .PageIsUserProfile}} - - - - - {{if .ContextUser.Description}} - - {{end}} -{{else if .Repository}} - {{if .Issue}} - - - {{if .Issue.Content}} - - {{end}} - {{else}} - - - {{if .Repository.Description}} - - {{end}} - {{end}} - - {{if (.Repository.AvatarLink ctx)}} - - {{else}} - - {{end}} -{{else}} - - - - - -{{end}} - + {{template "base/head_opengraph" .}} {{template "base/head_style" .}} {{template "custom/header" .}} diff --git a/templates/base/head_opengraph.tmpl b/templates/base/head_opengraph.tmpl new file mode 100644 index 000000000000..fc3958b6b6d5 --- /dev/null +++ b/templates/base/head_opengraph.tmpl @@ -0,0 +1,42 @@ +{{if .PageIsUserProfile}} + + + + + {{if .ContextUser.Description}} + + {{end}} +{{else if .Repository}} + {{if .Issue}} + + + {{if .Issue.Content}} + + {{end}} + {{else if or .PageIsDiff .IsViewFile}} + + + {{if and .PageIsDiff (IsMultilineCommitMessage .Commit.Message)}} + + {{end}} + {{else}} + + + {{if .Repository.Description}} + + {{end}} + {{end}} + + {{if (.Repository.AvatarLink ctx)}} + + {{else}} + + {{end}} +{{else}} + + + + + +{{end}} + From a625f3a76198bed3c857f5c00f238bf9516ca950 Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 1 Sep 2023 19:32:39 +0200 Subject: [PATCH 63/68] Enable djlint H008 and fix issues (#26869) Enable `H008 | Attributes should be double quoted` and fix issues. --- pyproject.toml | 2 +- templates/repo/issue/view_content/attachments.tmpl | 4 ++-- templates/repo/issue/view_content/comments.tmpl | 4 ++-- templates/user/dashboard/navbar.tmpl | 2 +- templates/user/notification/notification_div.tmpl | 8 ++++---- templates/user/overview/header.tmpl | 8 ++++---- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 549a8cb2b0e2..f4cd2e67445d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,4 +12,4 @@ djlint = "1.32.1" [tool.djlint] profile="golang" -ignore="H005,H006,H008,H013,H016,H020,H021,H030,H031" +ignore="H005,H006,H013,H016,H020,H021,H030,H031" diff --git a/templates/repo/issue/view_content/attachments.tmpl b/templates/repo/issue/view_content/attachments.tmpl index 2eb0fcf61ceb..b74b6ce918f9 100644 --- a/templates/repo/issue/view_content/attachments.tmpl +++ b/templates/repo/issue/view_content/attachments.tmpl @@ -6,7 +6,7 @@ {{- range .Attachments -}}
- + {{if FilenameIsImage .Name}} {{if not (StringUtils.Contains $.Content .UUID)}} {{$hasThumbnails = true}} @@ -31,7 +31,7 @@ {{if FilenameIsImage .Name}} {{if not (StringUtils.Contains $.Content .UUID)}} - {{.Name}} + {{.Name}} {{end}} {{end}} diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 8c99973827a4..d43979ff59bd 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -111,9 +111,9 @@ {{template "shared/user/authorlink" .Poster}} {{$link := printf "%s/commit/%s" $.Repository.Link ($.Issue.PullRequest.MergedCommitID|PathEscape)}} {{if eq $.Issue.PullRequest.Status 3}} - {{$.locale.Tr "repo.issues.comment_manually_pull_merged_at" (printf "%[2]s" ($link|Escape) (ShortSha $.Issue.PullRequest.MergedCommitID)) (printf "%[1]s" ($.BaseTarget|Escape)) $createdStr | Safe}} + {{$.locale.Tr "repo.issues.comment_manually_pull_merged_at" (printf `%[2]s` ($link|Escape) (ShortSha $.Issue.PullRequest.MergedCommitID)) (printf "%[1]s" ($.BaseTarget|Escape)) $createdStr | Safe}} {{else}} - {{$.locale.Tr "repo.issues.comment_pull_merged_at" (printf "%[2]s" ($link|Escape) (ShortSha $.Issue.PullRequest.MergedCommitID)) (printf "%[1]s" ($.BaseTarget|Escape)) $createdStr | Safe}} + {{$.locale.Tr "repo.issues.comment_pull_merged_at" (printf `%[2]s` ($link|Escape) (ShortSha $.Issue.PullRequest.MergedCommitID)) (printf "%[1]s" ($.BaseTarget|Escape)) $createdStr | Safe}} {{end}}
diff --git a/templates/user/dashboard/navbar.tmpl b/templates/user/dashboard/navbar.tmpl index 0c185807c1f0..ee9e7e60adc0 100644 --- a/templates/user/dashboard/navbar.tmpl +++ b/templates/user/dashboard/navbar.tmpl @@ -97,7 +97,7 @@ {{end}} diff --git a/templates/user/notification/notification_div.tmpl b/templates/user/notification/notification_div.tmpl index 3cc9d31d52c3..415051ae957e 100644 --- a/templates/user/notification/notification_div.tmpl +++ b/templates/user/notification/notification_div.tmpl @@ -15,7 +15,7 @@
{{$.CsrfTokenHtml}}
-
@@ -74,7 +74,7 @@ {{$.CsrfTokenHtml}} -
{{end}} {{else}} - + {{svg "octicon-rss"}} {{.locale.Tr "user.activity"}} {{if not .DisableStars}} - + {{svg "octicon-star"}} {{.locale.Tr "user.starred"}} {{if .ContextUser.NumStars}}
{{.ContextUser.NumStars}}
{{end}}
{{else}} - + {{svg "octicon-eye"}} {{.locale.Tr "user.watched"}} {{end}} From 79f73299710fe8596b6ea31c0fa0ab97ab3dc801 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sat, 2 Sep 2023 05:10:41 +0200 Subject: [PATCH 64/68] Make it posible to customize nav text color via css var (#26807) --- *Sponsored by Kithara Software GmbH* --- web_src/css/base.css | 1 + web_src/css/modules/navbar.css | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/web_src/css/base.css b/web_src/css/base.css index 4330fb1df0d0..53c6f7820699 100644 --- a/web_src/css/base.css +++ b/web_src/css/base.css @@ -245,6 +245,7 @@ --color-tooltip-bg: #000000f0; --color-nav-bg: #ffffff; --color-nav-hover-bg: #ebebeb; + --color-nav-text: var(--color-text); --color-label-text: #232323; --color-label-bg: #cacaca5b; --color-label-hover-bg: #cacacaa0; diff --git a/web_src/css/modules/navbar.css b/web_src/css/modules/navbar.css index de25ea681158..61dffb3c80e1 100644 --- a/web_src/css/modules/navbar.css +++ b/web_src/css/modules/navbar.css @@ -34,6 +34,10 @@ justify-content: center; } +#navbar > .menu > .item { + color: var(--color-nav-text); +} + #navbar .dropdown .item { justify-content: stretch; } From 9a3de436f452144933888fb1e4f336efeb93293a Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 2 Sep 2023 16:59:07 +0200 Subject: [PATCH 65/68] Reorder blocks in vue SFCs (#26874) The [recommended order](https://vuejs.org/guide/scaling-up/sfc.html) for SFC blocks is script -> template -> style, which we were violating because template and script were swapped. I do find script first also easier to read because the imports are on top, letting me immideatly see a component's dependencies. This is a pure cut-paste refactor with some removal of some empty lines. --------- Co-authored-by: Lauris BH --- web_src/js/components/ActionRunStatus.vue | 21 +- web_src/js/components/ActivityHeatmap.vue | 28 +- web_src/js/components/ContextPopup.vue | 49 ++- web_src/js/components/DashboardRepoList.vue | 298 +++++++++--------- web_src/js/components/DiffCommitSelector.vue | 143 +++++---- web_src/js/components/DiffFileList.vue | 43 ++- web_src/js/components/DiffFileTree.vue | 19 +- web_src/js/components/DiffFileTreeItem.vue | 46 ++- .../js/components/PullRequestMergeForm.vue | 156 +++++---- web_src/js/components/RepoActionView.vue | 241 +++++++------- .../js/components/RepoActivityTopAuthors.vue | 101 +++--- .../js/components/RepoBranchTagSelector.vue | 146 +++++---- .../components/ScopedAccessTokenSelector.vue | 49 ++- 13 files changed, 661 insertions(+), 679 deletions(-) diff --git a/web_src/js/components/ActionRunStatus.vue b/web_src/js/components/ActionRunStatus.vue index 1955decc1e40..51a774543179 100644 --- a/web_src/js/components/ActionRunStatus.vue +++ b/web_src/js/components/ActionRunStatus.vue @@ -2,17 +2,6 @@ Please also update the template file above if this vue is modified. action status accepted: success, skipped, waiting, blocked, running, failure, cancelled, unknown --> - - + diff --git a/web_src/js/components/ActivityHeatmap.vue b/web_src/js/components/ActivityHeatmap.vue index 1b083ed134cb..96a6e680123c 100644 --- a/web_src/js/components/ActivityHeatmap.vue +++ b/web_src/js/components/ActivityHeatmap.vue @@ -1,17 +1,3 @@ - + diff --git a/web_src/js/components/ContextPopup.vue b/web_src/js/components/ContextPopup.vue index b6852655f6c4..303e6d0c8912 100644 --- a/web_src/js/components/ContextPopup.vue +++ b/web_src/js/components/ContextPopup.vue @@ -1,28 +1,3 @@ - - + diff --git a/web_src/js/components/DashboardRepoList.vue b/web_src/js/components/DashboardRepoList.vue index 898362776beb..5b8075f07a06 100644 --- a/web_src/js/components/DashboardRepoList.vue +++ b/web_src/js/components/DashboardRepoList.vue @@ -1,152 +1,3 @@ - - +