From 2563d717281daab2bd71f5e60d81f380ff9e8033 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Tue, 23 Jul 2024 08:07:41 -0400 Subject: [PATCH 1/9] Enable direnv (#31672) This lets developers who have direnv enabled to load our nix flake automatically when entering it (cherry picked from commit 24f9390f349581e5beb74c54e1f0af1998c8be71) --- .envrc | 1 + .gitignore | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 .envrc diff --git a/.envrc b/.envrc new file mode 100644 index 0000000000..3550a30f2d --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index ebbed981e1..7f40d0ba55 100644 --- a/.gitignore +++ b/.gitignore @@ -115,6 +115,9 @@ prime/ *_source.tar.bz2 .DS_Store +# nix-direnv generated files +.direnv/ + # Make evidence files /.make_evidence From f61873c7e42b613405d367421ad19db80f831053 Mon Sep 17 00:00:00 2001 From: Kemal Zebari <60799661+kemzeb@users.noreply.github.com> Date: Tue, 23 Jul 2024 11:36:32 -0700 Subject: [PATCH 2/9] Properly filter issue list given no assignees filter (#31522) Quick fix #31520. This issue is related to #31337. (cherry picked from commit c0b5a843badf7afa1f1aeb8f41cac87806ee188e) --- modules/indexer/issues/dboptions.go | 7 ++++++- modules/indexer/issues/indexer_test.go | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/indexer/issues/dboptions.go b/modules/indexer/issues/dboptions.go index 50916024af..c1f454eeee 100644 --- a/modules/indexer/issues/dboptions.go +++ b/modules/indexer/issues/dboptions.go @@ -44,6 +44,12 @@ func ToSearchOptions(keyword string, opts *issues_model.IssuesOptions) *SearchOp searchOpt.ProjectID = optional.Some[int64](0) // Those issues with no project(projectid==0) } + if opts.AssigneeID > 0 { + searchOpt.AssigneeID = optional.Some(opts.AssigneeID) + } else if opts.AssigneeID == -1 { // FIXME: this is inconsistent from other places + searchOpt.AssigneeID = optional.Some[int64](0) + } + // See the comment of issues_model.SearchOptions for the reason why we need to convert convertID := func(id int64) optional.Option[int64] { if id > 0 { @@ -57,7 +63,6 @@ func ToSearchOptions(keyword string, opts *issues_model.IssuesOptions) *SearchOp searchOpt.ProjectColumnID = convertID(opts.ProjectColumnID) searchOpt.PosterID = convertID(opts.PosterID) - searchOpt.AssigneeID = convertID(opts.AssigneeID) searchOpt.MentionID = convertID(opts.MentionedID) searchOpt.ReviewedID = convertID(opts.ReviewedID) searchOpt.ReviewRequestedID = convertID(opts.ReviewRequestedID) diff --git a/modules/indexer/issues/indexer_test.go b/modules/indexer/issues/indexer_test.go index e426229f78..0026ac57b3 100644 --- a/modules/indexer/issues/indexer_test.go +++ b/modules/indexer/issues/indexer_test.go @@ -8,6 +8,7 @@ import ( "testing" "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/issues" "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/indexer/issues/internal" "code.gitea.io/gitea/modules/optional" @@ -150,6 +151,11 @@ func searchIssueByID(t *testing.T) { }, expectedIDs: []int64{6, 1}, }, + { + // NOTE: This tests no assignees filtering and also ToSearchOptions() to ensure it will set AssigneeID to 0 when it is passed as -1. + opts: *ToSearchOptions("", &issues.IssuesOptions{AssigneeID: -1}), + expectedIDs: []int64{22, 21, 16, 15, 14, 13, 12, 11, 20, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2}, + }, { opts: SearchOptions{ MentionID: optional.Some(int64(4)), From e465ac854d4c1edee87f0f7998f87c62d41d8dbf Mon Sep 17 00:00:00 2001 From: Stanislas Dolcini Date: Thu, 25 Jul 2024 11:33:02 +0200 Subject: [PATCH 3/9] Use GetDisplayName() instead of DisplayName() to generate rss feeds (#31687) Fixes #31491 The RSS feed converted ignored the setting used in the application. (cherry picked from commit d8f82cbc780d09bb7ad074407a48480f0333b4b3) --- routers/web/feed/convert.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/routers/web/feed/convert.go b/routers/web/feed/convert.go index 9ed57ec48c..0f4334692f 100644 --- a/routers/web/feed/convert.go +++ b/routers/web/feed/convert.go @@ -84,7 +84,7 @@ func feedActionsToFeedItems(ctx *context.Context, actions activities_model.Actio link := &feeds.Link{Href: act.GetCommentHTMLURL(ctx)} // title - title = act.ActUser.DisplayName() + " " + title = act.ActUser.GetDisplayName() + " " var titleExtra template.HTML switch act.OpType { case activities_model.ActionCreateRepo: @@ -260,7 +260,7 @@ func feedActionsToFeedItems(ctx *context.Context, actions activities_model.Actio Description: desc, IsPermaLink: "false", Author: &feeds.Author{ - Name: act.ActUser.DisplayName(), + Name: act.ActUser.GetDisplayName(), Email: act.ActUser.GetEmail(), }, Id: fmt.Sprintf("%v: %v", strconv.FormatInt(act.ID, 10), link.Href), @@ -320,7 +320,7 @@ func releasesToFeedItems(ctx *context.Context, releases []*repo_model.Release) ( Link: link, Created: rel.CreatedUnix.AsTime(), Author: &feeds.Author{ - Name: rel.Publisher.DisplayName(), + Name: rel.Publisher.GetDisplayName(), Email: rel.Publisher.GetEmail(), }, Id: fmt.Sprintf("%v: %v", strconv.FormatInt(rel.ID, 10), link.Href), From 3d1b8f47c0c41242117cc13cc661c94beb6388c9 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Sun, 28 Jul 2024 08:58:59 +0200 Subject: [PATCH 4/9] Use GetDisplayName() instead of DisplayName() to generate rss feeds (followup) The test only exists in Forgejo and the behavior it verifies now require setting.UI.DefaultShowFullName to be true. --- tests/integration/api_feed_plain_text_titles_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/integration/api_feed_plain_text_titles_test.go b/tests/integration/api_feed_plain_text_titles_test.go index a058b7321c..b1247780d8 100644 --- a/tests/integration/api_feed_plain_text_titles_test.go +++ b/tests/integration/api_feed_plain_text_titles_test.go @@ -7,6 +7,8 @@ import ( "net/http" "testing" + "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/tests" "github.com/stretchr/testify/assert" @@ -15,6 +17,7 @@ import ( func TestFeedPlainTextTitles(t *testing.T) { // This test verifies that items' titles in feeds are generated as plain text. // See https://codeberg.org/forgejo/forgejo/pulls/1595 + defer test.MockVariableValue(&setting.UI.DefaultShowFullName, true)() t.Run("Feed plain text titles", func(t *testing.T) { t.Run("Atom", func(t *testing.T) { From d0e52fd641655de8cd7738735b867cc35f988e87 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 25 Jul 2024 19:11:04 +0900 Subject: [PATCH 5/9] Support delete user email in admin panel (#31690) ![QQ_1721784609320](https://github.com/user-attachments/assets/23f08bf3-93f4-44d7-963d-10380ef8c1f1) ![QQ_1721784616403](https://github.com/user-attachments/assets/667cbd1e-5e21-4489-8d18-2a7be85190db) ![QQ_1721784626722](https://github.com/user-attachments/assets/495beb94-dfa2-481c-aa60-d5115cad1ae1) --------- Co-authored-by: Jason Song (cherry picked from commit cc044818c33ff066c4e5869c9e75de9707def6ed) --- models/user/email_address.go | 1 + options/locale/locale_en-US.ini | 4 ++++ routers/web/admin/emails.go | 30 ++++++++++++++++++++++++++++++ routers/web/web.go | 1 + templates/admin/emails/list.tmpl | 18 ++++++++++++++++++ 5 files changed, 54 insertions(+) diff --git a/models/user/email_address.go b/models/user/email_address.go index 50c0cfbfb1..8c6f24e57b 100644 --- a/models/user/email_address.go +++ b/models/user/email_address.go @@ -350,6 +350,7 @@ type SearchEmailOptions struct { // SearchEmailResult is an e-mail address found in the user or email_address table type SearchEmailResult struct { + ID int64 UID int64 Email string IsActivated bool diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 40807f238a..0c462d03ed 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3094,6 +3094,10 @@ emails.not_updated = Failed to update the requested email address: %v emails.duplicate_active = This email address is already active for a different user. emails.change_email_header = Update Email Properties emails.change_email_text = Are you sure you want to update this email address? +emails.delete = Delete Email +emails.delete_desc = Are you sure you want to delete this email address? +emails.deletion_success = The email address has been deleted. +emails.delete_primary_email_error = You can not delete the primary email. orgs.org_manage_panel = Manage organizations orgs.name = Name diff --git a/routers/web/admin/emails.go b/routers/web/admin/emails.go index 2cf4035c6a..f0d8555070 100644 --- a/routers/web/admin/emails.go +++ b/routers/web/admin/emails.go @@ -15,6 +15,7 @@ import ( "code.gitea.io/gitea/modules/optional" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/services/context" + "code.gitea.io/gitea/services/user" ) const ( @@ -150,3 +151,32 @@ func ActivateEmail(ctx *context.Context) { redirect.RawQuery = q.Encode() ctx.Redirect(redirect.String()) } + +// DeleteEmail serves a POST request for delete a user's email +func DeleteEmail(ctx *context.Context) { + u, err := user_model.GetUserByID(ctx, ctx.FormInt64("Uid")) + if err != nil || u == nil { + ctx.ServerError("GetUserByID", err) + return + } + + email, err := user_model.GetEmailAddressByID(ctx, u.ID, ctx.FormInt64("id")) + if err != nil || email == nil { + ctx.ServerError("GetEmailAddressByID", err) + return + } + + if err := user.DeleteEmailAddresses(ctx, u, []string{email.Email}); err != nil { + if user_model.IsErrPrimaryEmailCannotDelete(err) { + ctx.Flash.Error(ctx.Tr("admin.emails.delete_primary_email_error")) + ctx.JSONRedirect("") + return + } + ctx.ServerError("DeleteEmailAddresses", err) + return + } + log.Trace("Email address deleted: %s %s", u.Name, email.Email) + + ctx.Flash.Success(ctx.Tr("admin.emails.deletion_success")) + ctx.JSONRedirect("") +} diff --git a/routers/web/web.go b/routers/web/web.go index 3480a18844..edf0769a4b 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -696,6 +696,7 @@ func registerRoutes(m *web.Route) { m.Group("/emails", func() { m.Get("", admin.Emails) m.Post("/activate", admin.ActivateEmail) + m.Post("/delete", admin.DeleteEmail) }) m.Group("/orgs", func() { diff --git a/templates/admin/emails/list.tmpl b/templates/admin/emails/list.tmpl index 388863df9b..b07c6fcc01 100644 --- a/templates/admin/emails/list.tmpl +++ b/templates/admin/emails/list.tmpl @@ -38,6 +38,7 @@ {{ctx.Locale.Tr "admin.emails.primary"}} {{ctx.Locale.Tr "admin.emails.activated"}} + @@ -59,6 +60,11 @@ {{if .IsActivated}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}} {{end}} + + + {{end}} @@ -95,4 +101,16 @@ + + + {{template "admin/layout_footer" .}} From 94e9cbcd719bbc3a225d0e3000005ee18716a644 Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Thu, 25 Jul 2024 14:06:19 +0200 Subject: [PATCH 6/9] Add return type to GetRawFileOrLFS and GetRawFile (#31680) Document return type for the endpoints that fetch specific files from a repository. This allows the swagger generated code to read the returned data. Co-authored-by: Giteabot (cherry picked from commit bae87dfb0958e6a2920c905e51c2a026b7b71ca6) --- routers/api/v1/repo/file.go | 8 +++++++- templates/swagger/v1_json.tmpl | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go index 34ccc929a5..aae82894c7 100644 --- a/routers/api/v1/repo/file.go +++ b/routers/api/v1/repo/file.go @@ -45,7 +45,7 @@ func GetRawFile(ctx *context.APIContext) { // --- // summary: Get a file from a repository // produces: - // - application/json + // - application/octet-stream // parameters: // - name: owner // in: path @@ -70,6 +70,8 @@ func GetRawFile(ctx *context.APIContext) { // responses: // 200: // description: Returns raw file content. + // schema: + // type: file // "404": // "$ref": "#/responses/notFound" @@ -96,6 +98,8 @@ func GetRawFileOrLFS(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/media/{filepath} repository repoGetRawFileOrLFS // --- // summary: Get a file or it's LFS object from a repository + // produces: + // - application/octet-stream // parameters: // - name: owner // in: path @@ -120,6 +124,8 @@ func GetRawFileOrLFS(ctx *context.APIContext) { // responses: // 200: // description: Returns raw file content. + // schema: + // type: file // "404": // "$ref": "#/responses/notFound" diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index dacec3ed1a..b8b896a00c 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -10867,6 +10867,9 @@ }, "/repos/{owner}/{repo}/media/{filepath}": { "get": { + "produces": [ + "application/octet-stream" + ], "tags": [ "repository" ], @@ -10903,7 +10906,10 @@ ], "responses": { "200": { - "description": "Returns raw file content." + "description": "Returns raw file content.", + "schema": { + "type": "file" + } }, "404": { "$ref": "#/responses/notFound" @@ -13122,7 +13128,7 @@ "/repos/{owner}/{repo}/raw/{filepath}": { "get": { "produces": [ - "application/json" + "application/octet-stream" ], "tags": [ "repository" @@ -13160,7 +13166,10 @@ ], "responses": { "200": { - "description": "Returns raw file content." + "description": "Returns raw file content.", + "schema": { + "type": "file" + } }, "404": { "$ref": "#/responses/notFound" From 41d7521b97ed027b1157dc520888590490970d89 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Fri, 26 Jul 2024 18:00:07 +0800 Subject: [PATCH 7/9] Support `pull_request_target` event for commit status (#31703) Fix [act_runner #573](https://gitea.com/gitea/act_runner/issues/573) Before: ![image](https://github.com/user-attachments/assets/3944bf7f-7a60-4801-bcb3-5e158a180fda) After: ![image](https://github.com/user-attachments/assets/cadac944-40bd-4537-a9d9-e702b8bc1ece) (cherry picked from commit 4b376a0ed934ba77d91ab182215fcff07b13c8df) Conflicts: services/actions/commit_status.go trivial context conflict --- services/actions/commit_status.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/actions/commit_status.go b/services/actions/commit_status.go index bc2905e089..2698059e94 100644 --- a/services/actions/commit_status.go +++ b/services/actions/commit_status.go @@ -12,6 +12,7 @@ import ( "code.gitea.io/gitea/models/db" git_model "code.gitea.io/gitea/models/git" user_model "code.gitea.io/gitea/models/user" + actions_module "code.gitea.io/gitea/modules/actions" "code.gitea.io/gitea/modules/log" api "code.gitea.io/gitea/modules/structs" webhook_module "code.gitea.io/gitea/modules/webhook" @@ -53,7 +54,11 @@ func createCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) er } sha = payload.HeadCommit.ID case webhook_module.HookEventPullRequest, webhook_module.HookEventPullRequestSync: - event = "pull_request" + if run.TriggerEvent == actions_module.GithubEventPullRequestTarget { + event = "pull_request_target" + } else { + event = "pull_request" + } payload, err := run.GetPullRequestEventPayload() if err != nil { return fmt.Errorf("GetPullRequestEventPayload: %w", err) From c55f3bf3c3e5ea72b362bf504aa728c53ae68f75 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Sun, 28 Jul 2024 07:59:09 +0200 Subject: [PATCH 8/9] chore: update .deadcode.out --- .deadcode-out | 1 - 1 file changed, 1 deletion(-) diff --git a/.deadcode-out b/.deadcode-out index 29d3d7c708..f6fc50f150 100644 --- a/.deadcode-out +++ b/.deadcode-out @@ -86,7 +86,6 @@ code.gitea.io/gitea/models/repo WatchRepoMode code.gitea.io/gitea/models/user - IsErrPrimaryEmailCannotDelete ErrUserInactive.Error ErrUserInactive.Unwrap IsErrExternalLoginUserAlreadyExist From f0379489bf2843546942378de280cc2b8c14d6ee Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Sun, 28 Jul 2024 08:19:38 +0200 Subject: [PATCH 9/9] chore(release-notes): weekly cherry-pick week 2024-31 --- release-notes/4716.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 release-notes/4716.md diff --git a/release-notes/4716.md b/release-notes/4716.md new file mode 100644 index 0000000000..e47f43ce16 --- /dev/null +++ b/release-notes/4716.md @@ -0,0 +1,4 @@ +feat: [commit](https://codeberg.org/forgejo/forgejo/commit/8d23433dab08fcbb8043e5d239171fba59c53108): support pull_request_target event for commit status. +fix: [commit](https://codeberg.org/forgejo/forgejo/commit/ee11a263f8c9de33d42fc117443f4054a311c875): add return type to GetRawFileOrLFS and GetRawFile. +feat: [commit](https://codeberg.org/forgejo/forgejo/commit/cb9071bbf433715f0e16e39cb60126b65f8236a0): support delete user email in admin panel. +fix: [commit](https://codeberg.org/forgejo/forgejo/commit/f61873c7e42b613405d367421ad19db80f831053): properly filter issue list given no assignees filter.