From c1ec79aeaff6192207e1ed335822c6a20ef1b3e2 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 20 Mar 2024 22:31:32 +0800 Subject: [PATCH 01/17] Fix loadOneBranch panic (#29938) (#29939) Backport #29938 Try to fix #29936 Far from ideal, but still better than panic. (cherry picked from commit b4a6c6fd7a4ed8e018d27fcdb5203fa04becdddb) --- modules/git/repo.go | 2 +- services/repository/branch.go | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/git/repo.go b/modules/git/repo.go index 32f0e7007e..9c72f884df 100644 --- a/modules/git/repo.go +++ b/modules/git/repo.go @@ -248,7 +248,7 @@ type DivergeObject struct { // GetDivergingCommits returns the number of commits a targetBranch is ahead or behind a baseBranch func GetDivergingCommits(ctx context.Context, repoPath, baseBranch, targetBranch string) (do DivergeObject, err error) { cmd := NewCommand(ctx, "rev-list", "--count", "--left-right"). - AddDynamicArguments(baseBranch + "..." + targetBranch) + AddDynamicArguments(baseBranch + "..." + targetBranch).AddArguments("--") stdout, _, err := cmd.RunStdString(&RunOpts{Dir: repoPath}) if err != nil { return do, err diff --git a/services/repository/branch.go b/services/repository/branch.go index 567104d29f..47463519db 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -132,10 +132,7 @@ func loadOneBranch(ctx context.Context, repo *repo_model.Repository, dbBranch *g p := protectedBranches.GetFirstMatched(branchName) isProtected := p != nil - divergence := &git.DivergeObject{ - Ahead: -1, - Behind: -1, - } + var divergence *git.DivergeObject // it's not default branch if repo.DefaultBranch != dbBranch.Name && !dbBranch.IsDeleted { @@ -146,6 +143,11 @@ func loadOneBranch(ctx context.Context, repo *repo_model.Repository, dbBranch *g } } + if divergence == nil { + // tolerate error that we can't get divergence + divergence = &git.DivergeObject{Ahead: -1, Behind: -1} + } + pr, err := issues_model.GetLatestPullRequestByHeadInfo(repo.ID, branchName) if err != nil { return nil, fmt.Errorf("GetLatestPullRequestByHeadInfo: %v", err) From 456a33e8bb770a86341dc883edc6b62264b950a1 Mon Sep 17 00:00:00 2001 From: HEREYUA <37935145+HEREYUA@users.noreply.github.com> Date: Thu, 21 Mar 2024 22:03:01 +0800 Subject: [PATCH 02/17] Solving the issue of UI disruption when the review is deleted without refreshing (#29951) (#29968) backport #29951 (cherry picked from commit 3ff3c5ba780bc1b01004b9d0f8b4d56dd1aa9820) --- web_src/js/features/repo-issue.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js index 0be118db31..ecddbe15a9 100644 --- a/web_src/js/features/repo-issue.js +++ b/web_src/js/features/repo-issue.js @@ -162,7 +162,8 @@ export function initRepoIssueCommentDelete() { _csrf: csrfToken, }).done(() => { const $conversationHolder = $this.closest('.conversation-holder'); - + const $parentTimelineItem = $this.closest('.timeline-item'); + const $parentTimelineGroup = $this.closest('.timeline-item-group'); // Check if this was a pending comment. if ($conversationHolder.find('.pending-label').length) { const $counter = $('#review-box .review-comments-counter'); @@ -185,6 +186,11 @@ export function initRepoIssueCommentDelete() { } $conversationHolder.remove(); } + // Check if there is no review content, move the time avatar upward to avoid overlapping the content below. + if (!$parentTimelineGroup.find('.timeline-item.comment').length && !$parentTimelineItem.find('.conversation-holder').length) { + const $timelineAvatar = $parentTimelineGroup.find('.timeline-avatar'); + $timelineAvatar.removeClass('timeline-avatar-offset'); + } }); } return false; From fccb34c389711fbc639fda04a01a58c793a66823 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 21 Mar 2024 22:30:55 +0800 Subject: [PATCH 03/17] Fix the bug that user may logout if GetUserByID return unknow error (#29964) backport #29962 This PR fixed a bug when the user switching pages too fast, he will logout automatically. The reason is that when the error is context cancelled, the previous code think user hasn't login then the session will be deleted. Now it will return the errors but not think it's not login. Co-authored-by: wxiaoguang (cherry picked from commit c03b1e28544ee60c72f9dc7d9f362753bb3d778c) --- services/auth/session.go | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/services/auth/session.go b/services/auth/session.go index 52cfb8ac21..35d97e42da 100644 --- a/services/auth/session.go +++ b/services/auth/session.go @@ -6,7 +6,6 @@ package auth import ( "net/http" - "code.gitea.io/gitea/models/db" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" ) @@ -29,40 +28,33 @@ func (s *Session) Name() string { // object for that uid. // Returns nil if there is no user uid stored in the session. func (s *Session) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error) { - user := SessionUser(sess) - if user != nil { - return user, nil - } - return nil, nil -} - -// SessionUser returns the user object corresponding to the "uid" session variable. -func SessionUser(sess SessionStore) *user_model.User { if sess == nil { - return nil + return nil, nil } // Get user ID uid := sess.Get("uid") if uid == nil { - return nil + return nil, nil } log.Trace("Session Authorization: Found user[%d]", uid) id, ok := uid.(int64) if !ok { - return nil + return nil, nil } // Get user object - user, err := user_model.GetUserByID(db.DefaultContext, id) + user, err := user_model.GetUserByID(req.Context(), id) if err != nil { if !user_model.IsErrUserNotExist(err) { - log.Error("GetUserById: %v", err) + log.Error("GetUserByID: %v", err) + // Return the err as-is to keep current signed-in session, in case the err is something like context.Canceled. Otherwise non-existing user (nil, nil) will make the caller clear the signed-in session. + return nil, err } - return nil + return nil, nil } log.Trace("Session Authorization: Logged in user %-v", user) - return user + return user, nil } From 7c8f1d7b202eca08ef100b497bbd2cc58d94887a Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sat, 23 Mar 2024 22:56:19 +0800 Subject: [PATCH 04/17] Remove duplicate option in admin screen and now-unused translation keys (#28492) (#30024) Backport #28492 Fix #30019 Co-authored-by: The Magician <142242365+TheMagician23@users.noreply.github.com> (cherry picked from commit 01f736f68c5620957419c609bbf78f8e5ce76359) --- options/locales/gitea_en-US.ini | 1 - templates/admin/config.tmpl | 2 -- 2 files changed, 3 deletions(-) diff --git a/options/locales/gitea_en-US.ini b/options/locales/gitea_en-US.ini index c100318118..a3d154ee40 100644 --- a/options/locales/gitea_en-US.ini +++ b/options/locales/gitea_en-US.ini @@ -3110,7 +3110,6 @@ config.enable_openid_signin = Enable OpenID Sign-In config.show_registration_button = Show Register Button config.require_sign_in_view = Require Sign-In to View Pages config.mail_notify = Enable Email Notifications -config.disable_key_size_check = Disable Minimum Key Size Check config.enable_captcha = Enable CAPTCHA config.active_code_lives = Active Code Lives config.reset_password_code_lives = Recover Account Code Expiry Time diff --git a/templates/admin/config.tmpl b/templates/admin/config.tmpl index d40af66bc4..ce6edf8a97 100644 --- a/templates/admin/config.tmpl +++ b/templates/admin/config.tmpl @@ -151,8 +151,6 @@
{{if .Service.RequireSignInView}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
{{ctx.Locale.Tr "admin.config.mail_notify"}}
{{if .Service.EnableNotifyMail}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
-
{{ctx.Locale.Tr "admin.config.disable_key_size_check"}}
-
{{if .SSH.MinimumKeySizeCheck}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
{{ctx.Locale.Tr "admin.config.enable_captcha"}}
{{if .Service.EnableCaptcha}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
{{ctx.Locale.Tr "admin.config.default_keep_email_private"}}
From b22be0c03fa4814c1b8b892346de5d4547782ce7 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 24 Mar 2024 00:21:57 +0800 Subject: [PATCH 05/17] Escape paths for find file correctly (#30026) (#30031) Backport #30026 (cherry picked from commit 2172b38d505fa9586edf5da0d4aad7307dc92b7d) --- routers/web/repo/find.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/routers/web/repo/find.go b/routers/web/repo/find.go index daefe59c8f..9d03e4b4c9 100644 --- a/routers/web/repo/find.go +++ b/routers/web/repo/find.go @@ -8,6 +8,7 @@ import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/util" ) const ( @@ -17,7 +18,7 @@ const ( // FindFiles render the page to find repository files func FindFiles(ctx *context.Context) { path := ctx.Params("*") - ctx.Data["TreeLink"] = ctx.Repo.RepoLink + "/src/" + path - ctx.Data["DataLink"] = ctx.Repo.RepoLink + "/tree-list/" + path + ctx.Data["TreeLink"] = ctx.Repo.RepoLink + "/src/" + util.PathEscapeSegments(path) + ctx.Data["DataLink"] = ctx.Repo.RepoLink + "/tree-list/" + util.PathEscapeSegments(path) ctx.HTML(http.StatusOK, tplFindFiles) } From 5e5574c7b328e2c500d497517047b8d1fd0ca478 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Sun, 24 Mar 2024 13:38:31 +0800 Subject: [PATCH 06/17] Respect DEFAULT_ORG_MEMBER_VISIBLE setting when adding creator to org (#30013) (#30035) Backport #30013 by @DrMaxNix This PR adds `setting.Service.DefaultOrgMemberVisible` value to dataset of user when the initial org creator is being added to the created org. Fixes #30012. Co-authored-by: DrMaxNix (cherry picked from commit e321b8a849087d736a96275d5960f9b1446c95ba) --- models/organization/org.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/models/organization/org.go b/models/organization/org.go index 260571b4b2..dad6c7f37d 100644 --- a/models/organization/org.go +++ b/models/organization/org.go @@ -319,8 +319,9 @@ func CreateOrganization(org *Organization, owner *user_model.User) (err error) { // Add initial creator to organization and owner team. if err = db.Insert(ctx, &OrgUser{ - UID: owner.ID, - OrgID: org.ID, + UID: owner.ID, + OrgID: org.ID, + IsPublic: setting.Service.DefaultOrgMemberVisible, }); err != nil { return fmt.Errorf("insert org-user relation: %w", err) } From 40fba39dc13101da5f2830e556e4ccd817c90e6d Mon Sep 17 00:00:00 2001 From: Giteabot Date: Mon, 25 Mar 2024 15:22:09 +0800 Subject: [PATCH 07/17] Fix misuse of `TxContext` (#30061) (#30062) Backport #30061 by @wolfogre Help #29999, or its tests cannot pass. Also, add some comments to clarify the usage of `TxContext`. I don't check all usages of `TxContext` because there are too many (almost 140+). It's a better idea to replace them with `WithTx` instead of checking them one by one. However, that may be another refactoring PR. Co-authored-by: Jason Song (cherry picked from commit 78795dd5663b7d8df4620bd50c74a7d71606f1d2) --- models/db/context.go | 10 ++++++++++ models/issues/review.go | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/models/db/context.go b/models/db/context.go index 9f72b43555..fc1fecb0e3 100644 --- a/models/db/context.go +++ b/models/db/context.go @@ -120,6 +120,16 @@ func (c *halfCommitter) Close() error { // TxContext represents a transaction Context, // it will reuse the existing transaction in the parent context or create a new one. +// Some tips to use: +// +// 1 It's always recommended to use `WithTx` in new code instead of `TxContext`, since `WithTx` will handle the transaction automatically. +// 2. To maintain the old code which uses `TxContext`: +// a. Always call `Close()` before returning regardless of whether `Commit()` has been called. +// b. Always call `Commit()` before returning if there are no errors, even if the code did not change any data. +// c. Remember the `Committer` will be a halfCommitter when a transaction is being reused. +// So calling `Commit()` will do nothing, but calling `Close()` without calling `Commit()` will rollback the transaction. +// And all operations submitted by the caller stack will be rollbacked as well, not only the operations in the current function. +// d. It doesn't mean rollback is forbidden, but always do it only when there is an error, and you do want to rollback. func TxContext(parentCtx context.Context) (*Context, Committer, error) { if sess, ok := inTransaction(parentCtx); ok { return newContext(parentCtx, sess, true), &halfCommitter{committer: sess}, nil diff --git a/models/issues/review.go b/models/issues/review.go index 18296c0dda..1bd165e80d 100644 --- a/models/issues/review.go +++ b/models/issues/review.go @@ -622,7 +622,7 @@ func AddReviewRequest(ctx context.Context, issue *Issue, reviewer, doer *user_mo // skip it when reviewer hase been request to review if review != nil && review.Type == ReviewTypeRequest { - return nil, nil + return nil, committer.Commit() // still commit the transaction, or committer.Close() will rollback it, even if it's a reused transaction. } // if the reviewer is an official reviewer, From 90537783ff6eb5571519a6e69e00bd2d49aee207 Mon Sep 17 00:00:00 2001 From: silverwind Date: Tue, 26 Mar 2024 01:10:24 +0100 Subject: [PATCH 08/17] Fix incorrect SVGs (#30087) Just the SVG fixes from https://github.com/go-gitea/gitea/pull/30086 for v1.21 branch. (cherry picked from commit 03f29db46dbaa4cacca875cfe6b1c0b012a93406) --- templates/devtest/flex-list.tmpl | 4 ++-- templates/repo/diff/comment_form.tmpl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/devtest/flex-list.tmpl b/templates/devtest/flex-list.tmpl index c8584c110b..3c6256a59c 100644 --- a/templates/devtest/flex-list.tmpl +++ b/templates/devtest/flex-list.tmpl @@ -25,7 +25,7 @@
diff --git a/templates/repo/diff/comment_form.tmpl b/templates/repo/diff/comment_form.tmpl index 767c2613a0..1528578bdc 100644 --- a/templates/repo/diff/comment_form.tmpl +++ b/templates/repo/diff/comment_form.tmpl @@ -20,7 +20,7 @@ )}}