Skip to content

Commit b6376b7

Browse files
committed
Merge branch 'main' into bugfix/issue_23738
2 parents a4de58c + fa34951 commit b6376b7

33 files changed

+289
-121
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/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,8 @@ var migrations = []Migration{
483483
NewMigration("Fix incorrect owner team unit access mode", v1_20.FixIncorrectOwnerTeamUnitAccessMode),
484484
// v252 -> v253
485485
NewMigration("Fix incorrect admin team unit access mode", v1_20.FixIncorrectAdminTeamUnitAccessMode),
486+
// v253 -> v254
487+
NewMigration("Fix ExternalTracker and ExternalWiki accessMode in owner and admin team", v1_20.FixExternalTrackerAndExternalWikiAccessModeInOwnerAndAdminTeam),
486488
}
487489

488490
// GetCurrentDBVersion returns the current db version

models/migrations/v1_20/v253.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_20 //nolint
5+
6+
import (
7+
"code.gitea.io/gitea/modules/log"
8+
9+
"xorm.io/xorm"
10+
)
11+
12+
func FixExternalTrackerAndExternalWikiAccessModeInOwnerAndAdminTeam(x *xorm.Engine) error {
13+
type UnitType int
14+
type AccessMode int
15+
16+
type TeamUnit struct {
17+
ID int64 `xorm:"pk autoincr"`
18+
Type UnitType `xorm:"UNIQUE(s)"`
19+
AccessMode AccessMode
20+
}
21+
22+
const (
23+
// AccessModeRead read access
24+
AccessModeRead = 1
25+
26+
// Unit Type
27+
TypeExternalWiki = 6
28+
TypeExternalTracker = 7
29+
)
30+
31+
sess := x.NewSession()
32+
defer sess.Close()
33+
34+
if err := sess.Begin(); err != nil {
35+
return err
36+
}
37+
38+
count, err := sess.Table("team_unit").
39+
Where("type IN (?, ?) AND access_mode > ?", TypeExternalWiki, TypeExternalTracker, AccessModeRead).
40+
Update(&TeamUnit{
41+
AccessMode: AccessModeRead,
42+
})
43+
if err != nil {
44+
return err
45+
}
46+
log.Debug("Updated %d ExternalTracker and ExternalWiki access mode to belong to owner and admin", count)
47+
48+
return sess.Commit()
49+
}

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

modules/timeutil/since.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,25 @@ func timeSincePro(then, now time.Time, lang translation.Locale) string {
114114
return strings.TrimPrefix(timeStr, ", ")
115115
}
116116

117+
func timeSinceUnix(then, now time.Time, lang translation.Locale) template.HTML {
118+
friendlyText := then.Format("2006-01-02 15:04:05 +07:00")
119+
120+
// document: https://github.com/github/relative-time-element
121+
attrs := `tense="past"`
122+
isFuture := now.Before(then)
123+
if isFuture {
124+
attrs = `tense="future"`
125+
}
126+
127+
// declare data-tooltip-content attribute to switch from "title" tooltip to "tippy" tooltip
128+
htm := fmt.Sprintf(`<relative-time class="time-since" prefix="" %s datetime="%s" data-tooltip-content data-tooltip-interactive="true">%s</relative-time>`,
129+
attrs, then.Format(time.RFC3339), friendlyText)
130+
return template.HTML(htm)
131+
}
132+
117133
// TimeSince renders relative time HTML given a time.Time
118134
func TimeSince(then time.Time, lang translation.Locale) template.HTML {
119-
timestamp := then.UTC().Format(time.RFC3339)
120-
// declare data-tooltip-content attribute to switch from "title" tooltip to "tippy" tooltip
121-
return template.HTML(fmt.Sprintf(`<relative-time class="time-since" prefix="%s" datetime="%s" data-tooltip-content data-tooltip-interactive="true">%s</relative-time>`, lang.Tr("on_date"), timestamp, timestamp))
135+
return timeSinceUnix(then, time.Now(), lang)
122136
}
123137

124138
// TimeSinceUnix renders relative time HTML given a TimeStamp

options/locale/locale_en-US.ini

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ never = Never
112112

113113
rss_feed = RSS Feed
114114

115-
on_date = on
116-
117115
[aria]
118116
navbar = Navigation Bar
119117
footer = Footer
@@ -3129,8 +3127,6 @@ starred_repo = starred <a href="%[1]s">%[2]s</a>
31293127
watched_repo = started watching <a href="%[1]s">%[2]s</a>
31303128
31313129
[tool]
3132-
ago = %s ago
3133-
from_now = %s from now
31343130
now = now
31353131
future = future
31363132
1s = 1 second

options/locale/locale_pt-PT.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ buttons.list.task.tooltip=Adicionar uma lista de tarefas
133133
buttons.mention.tooltip=Mencionar um utilizador ou uma equipa
134134
buttons.ref.tooltip=Referenciar uma questão ou um pedido de integração
135135
buttons.switch_to_legacy.tooltip=Usar o editor clássico
136+
buttons.enable_monospace_font=Habilitar tipo de letra mono-espaçado
137+
buttons.disable_monospace_font=Desabilitar tipo de letra mono-espaçado
136138

137139
[filter]
138140
string.asc=A - Z

0 commit comments

Comments
 (0)