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 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 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/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)), 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/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. 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/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/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), 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/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) 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 @@