Skip to content

Commit 8fe8241

Browse files
authored
Merge branch 'main' into fix-enternal-unit-accessmode-in-owner-and-admin-team
2 parents 028ac24 + b4e9525 commit 8fe8241

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+545
-295
lines changed

models/issues/assignees.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ func IsUserAssignedToIssue(ctx context.Context, issue *Issue, user *user_model.U
6363
}
6464

6565
// ToggleIssueAssignee changes a user between assigned and not assigned for this issue, and make issue comment for it.
66-
func ToggleIssueAssignee(issue *Issue, doer *user_model.User, assigneeID int64) (removed bool, comment *Comment, err error) {
67-
ctx, committer, err := db.TxContext(db.DefaultContext)
66+
func ToggleIssueAssignee(ctx context.Context, issue *Issue, doer *user_model.User, assigneeID int64) (removed bool, comment *Comment, err error) {
67+
ctx, committer, err := db.TxContext(ctx)
6868
if err != nil {
6969
return false, nil, err
7070
}

models/issues/assignees_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ func TestUpdateAssignee(t *testing.T) {
2424
// Assign multiple users
2525
user2, err := user_model.GetUserByID(db.DefaultContext, 2)
2626
assert.NoError(t, err)
27-
_, _, err = issues_model.ToggleIssueAssignee(issue, &user_model.User{ID: 1}, user2.ID)
27+
_, _, err = issues_model.ToggleIssueAssignee(db.DefaultContext, issue, &user_model.User{ID: 1}, user2.ID)
2828
assert.NoError(t, err)
2929

3030
user3, err := user_model.GetUserByID(db.DefaultContext, 3)
3131
assert.NoError(t, err)
32-
_, _, err = issues_model.ToggleIssueAssignee(issue, &user_model.User{ID: 1}, user3.ID)
32+
_, _, err = issues_model.ToggleIssueAssignee(db.DefaultContext, issue, &user_model.User{ID: 1}, user3.ID)
3333
assert.NoError(t, err)
3434

3535
user1, err := user_model.GetUserByID(db.DefaultContext, 1) // This user is already assigned (see the definition in fixtures), so running UpdateAssignee should unassign him
3636
assert.NoError(t, err)
37-
_, _, err = issues_model.ToggleIssueAssignee(issue, &user_model.User{ID: 1}, user1.ID)
37+
_, _, err = issues_model.ToggleIssueAssignee(db.DefaultContext, issue, &user_model.User{ID: 1}, user1.ID)
3838
assert.NoError(t, err)
3939

4040
// Check if he got removed

models/issues/issue.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,8 @@ func ChangeIssueStatus(ctx context.Context, issue *Issue, doer *user_model.User,
743743
}
744744

745745
// ChangeIssueTitle changes the title of this issue, as the given user.
746-
func ChangeIssueTitle(issue *Issue, doer *user_model.User, oldTitle string) (err error) {
747-
ctx, committer, err := db.TxContext(db.DefaultContext)
746+
func ChangeIssueTitle(ctx context.Context, issue *Issue, doer *user_model.User, oldTitle string) (err error) {
747+
ctx, committer, err := db.TxContext(ctx)
748748
if err != nil {
749749
return err
750750
}

models/issues/issue_xref_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func TestXRef_NeuterCrossReferences(t *testing.T) {
8383

8484
d := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
8585
i.Title = "title2, no mentions"
86-
assert.NoError(t, issues_model.ChangeIssueTitle(i, d, title))
86+
assert.NoError(t, issues_model.ChangeIssueTitle(db.DefaultContext, i, d, title))
8787

8888
ref = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{IssueID: itarget.ID, RefIssueID: i.ID, RefCommentID: 0})
8989
assert.Equal(t, issues_model.CommentTypeIssueRef, ref.Type)

models/repo/topic.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,16 @@ func (opts *FindTopicOptions) toConds() builder.Cond {
194194
// FindTopics retrieves the topics via FindTopicOptions
195195
func FindTopics(opts *FindTopicOptions) ([]*Topic, int64, error) {
196196
sess := db.GetEngine(db.DefaultContext).Select("topic.*").Where(opts.toConds())
197+
orderBy := "topic.repo_count DESC"
197198
if opts.RepoID > 0 {
198199
sess.Join("INNER", "repo_topic", "repo_topic.topic_id = topic.id")
200+
orderBy = "topic.name" // when render topics for a repo, it's better to sort them by name, to get consistent result
199201
}
200202
if opts.PageSize != 0 && opts.Page != 0 {
201203
sess = db.SetSessionPagination(sess, opts)
202204
}
203205
topics := make([]*Topic, 0, 10)
204-
total, err := sess.Desc("topic.repo_count").FindAndCount(&topics)
206+
total, err := sess.OrderBy(orderBy).FindAndCount(&topics)
205207
return topics, total, err
206208
}
207209

modules/context/context.go

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ import (
1616
"net/http"
1717
"net/url"
1818
"path"
19-
"regexp"
2019
"strconv"
2120
"strings"
22-
texttemplate "text/template"
2321
"time"
2422

2523
"code.gitea.io/gitea/models/db"
@@ -216,7 +214,7 @@ func (ctx *Context) RedirectToFirst(location ...string) {
216214
ctx.Redirect(setting.AppSubURL + "/")
217215
}
218216

219-
var templateExecutingErr = regexp.MustCompile(`^template: (.*):([1-9][0-9]*):([1-9][0-9]*): executing (?:"(.*)" at <(.*)>: )?`)
217+
const tplStatus500 base.TplName = "status/500"
220218

221219
// HTML calls Context.HTML and renders the template to HTTP response
222220
func (ctx *Context) HTML(status int, name base.TplName) {
@@ -229,34 +227,11 @@ func (ctx *Context) HTML(status int, name base.TplName) {
229227
return strconv.FormatInt(time.Since(tmplStartTime).Nanoseconds()/1e6, 10) + "ms"
230228
}
231229
if err := ctx.Render.HTML(ctx.Resp, status, string(name), templates.BaseVars().Merge(ctx.Data)); err != nil {
232-
if status == http.StatusInternalServerError && name == base.TplName("status/500") {
230+
if status == http.StatusInternalServerError && name == tplStatus500 {
233231
ctx.PlainText(http.StatusInternalServerError, "Unable to find HTML templates, the template system is not initialized, or Gitea can't find your template files.")
234232
return
235233
}
236-
if execErr, ok := err.(texttemplate.ExecError); ok {
237-
if groups := templateExecutingErr.FindStringSubmatch(err.Error()); len(groups) > 0 {
238-
errorTemplateName, lineStr, posStr := groups[1], groups[2], groups[3]
239-
target := ""
240-
if len(groups) == 6 {
241-
target = groups[5]
242-
}
243-
line, _ := strconv.Atoi(lineStr) // Cannot error out as groups[2] is [1-9][0-9]*
244-
pos, _ := strconv.Atoi(posStr) // Cannot error out as groups[3] is [1-9][0-9]*
245-
assetLayerName := templates.AssetFS().GetFileLayerName(errorTemplateName + ".tmpl")
246-
filename := fmt.Sprintf("(%s) %s", assetLayerName, errorTemplateName)
247-
if errorTemplateName != string(name) {
248-
filename += " (subtemplate of " + string(name) + ")"
249-
}
250-
err = fmt.Errorf("failed to render %s, error: %w:\n%s", filename, err, templates.GetLineFromTemplate(errorTemplateName, line, target, pos))
251-
} else {
252-
assetLayerName := templates.AssetFS().GetFileLayerName(execErr.Name + ".tmpl")
253-
filename := fmt.Sprintf("(%s) %s", assetLayerName, execErr.Name)
254-
if execErr.Name != string(name) {
255-
filename += " (subtemplate of " + string(name) + ")"
256-
}
257-
err = fmt.Errorf("failed to render %s, error: %w", filename, err)
258-
}
259-
}
234+
err = fmt.Errorf("failed to render template: %s, error: %s", name, templates.HandleTemplateRenderingError(err))
260235
ctx.ServerError("Render failed", err)
261236
}
262237
}
@@ -324,24 +299,25 @@ func (ctx *Context) serverErrorInternal(logMsg string, logErr error) {
324299
return
325300
}
326301

327-
if !setting.IsProd {
302+
// it's safe to show internal error to admin users, and it helps
303+
if !setting.IsProd || (ctx.Doer != nil && ctx.Doer.IsAdmin) {
328304
ctx.Data["ErrorMsg"] = logErr
329305
}
330306
}
331307

332308
ctx.Data["Title"] = "Internal Server Error"
333-
ctx.HTML(http.StatusInternalServerError, base.TplName("status/500"))
309+
ctx.HTML(http.StatusInternalServerError, tplStatus500)
334310
}
335311

336312
// NotFoundOrServerError use error check function to determine if the error
337313
// is about not found. It responds with 404 status code for not found error,
338314
// or error context description for logging purpose of 500 server error.
339-
func (ctx *Context) NotFoundOrServerError(logMsg string, errCheck func(error) bool, err error) {
340-
if errCheck(err) {
341-
ctx.notFoundInternal(logMsg, err)
315+
func (ctx *Context) NotFoundOrServerError(logMsg string, errCheck func(error) bool, logErr error) {
316+
if errCheck(logErr) {
317+
ctx.notFoundInternal(logMsg, logErr)
342318
return
343319
}
344-
ctx.serverErrorInternal(logMsg, err)
320+
ctx.serverErrorInternal(logMsg, logErr)
345321
}
346322

347323
// PlainTextBytes renders bytes as plain text

modules/indexer/issues/meilisearch.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package issues
66
import (
77
"context"
88
"strconv"
9+
"strings"
910
"sync"
1011
"time"
1112

@@ -120,10 +121,11 @@ func (b *MeilisearchIndexer) Delete(ids ...int64) error {
120121
// Search searches for issues by given conditions.
121122
// Returns the matching issue IDs
122123
func (b *MeilisearchIndexer) Search(ctx context.Context, keyword string, repoIDs []int64, limit, start int) (*SearchResult, error) {
123-
filter := make([][]string, 0, len(repoIDs))
124+
repoFilters := make([]string, 0, len(repoIDs))
124125
for _, repoID := range repoIDs {
125-
filter = append(filter, []string{"repo_id = " + strconv.FormatInt(repoID, 10)})
126+
repoFilters = append(repoFilters, "repo_id = "+strconv.FormatInt(repoID, 10))
126127
}
128+
filter := strings.Join(repoFilters, " OR ")
127129
searchRes, err := b.client.Index(b.indexerName).Search(keyword, &meilisearch.SearchRequest{
128130
Filter: filter,
129131
Limit: int64(limit),

0 commit comments

Comments
 (0)