Skip to content

Commit b8d4abf

Browse files
committed
Merge branch 'master' of github.com:go-gitea/gitea
2 parents e2a6388 + 3a7e3db commit b8d4abf

File tree

22 files changed

+856
-474
lines changed

22 files changed

+856
-474
lines changed

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
292292
- `INTERVAL`: **60**: Garbage Collection interval (sec), for memory cache only.
293293
- `HOST`: **\<empty\>**: Connection string for `redis` and `memcache`.
294294
- Redis: `network=tcp,addr=127.0.0.1:6379,password=macaron,db=0,pool_size=100,idle_timeout=180`
295-
- Memache: `127.0.0.1:9090;127.0.0.1:9091`
295+
- Memcache: `127.0.0.1:9090;127.0.0.1:9091`
296296
- `ITEM_TTL`: **16h**: Time to keep items in cache if not used, Setting it to 0 disables caching.
297297

298298
## Session (`session`)
@@ -521,4 +521,4 @@ Two special environment variables are passed to the render command:
521521

522522
- `SHOW_FOOTER_BRANDING`: **false**: Show Gitea branding in the footer.
523523
- `SHOW_FOOTER_VERSION`: **true**: Show Gitea version information in the footer.
524-
- `SHOW_FOOTER_TEMPLATE_LOAD_TIME`: **true**: Show time of template execution in the footer.
524+
- `SHOW_FOOTER_TEMPLATE_LOAD_TIME`: **true**: Show time of template execution in the footer.

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
302302
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
303303
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
304304
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
305+
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e h1:JKmoR8x90Iww1ks85zJ1lfDGgIiMDuIptTOhJq+zKyg=
305306
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
306307
github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c h1:7lF+Vz0LqiRidnzC1Oq86fpX1q/iEv2KJdrCtttYjT4=
307308
github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
@@ -447,9 +448,11 @@ github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn
447448
github.com/oliamb/cutter v0.2.2 h1:Lfwkya0HHNU1YLnGv2hTkzHfasrSMkgv4Dn+5rmlk3k=
448449
github.com/oliamb/cutter v0.2.2/go.mod h1:4BenG2/4GuRBDbVm/OPahDVqbrOemzpPiG5mi1iryBU=
449450
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
451+
github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
450452
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
451453
github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w=
452454
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
455+
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
453456
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
454457
github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo=
455458
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
@@ -527,6 +530,7 @@ github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d/go.mod h1:AMEsy7v5z
527530
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
528531
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
529532
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
533+
github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 h1:Jpy1PXuP99tXNrhbq2BaPz9B+jNAvH1JPQQpG/9GCXY=
530534
github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
531535
github.com/smartystreets/assertions v1.0.1 h1:voD4ITNjPL5jjBfgR/r8fPIIBrliWrWHeiJApdr3r4w=
532536
github.com/smartystreets/assertions v1.0.1/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM=
@@ -560,6 +564,7 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0
560564
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
561565
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
562566
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
567+
github.com/syndtr/goleveldb v0.0.0-20190203031304-2f17a3356c66 h1:AwmkkZT+TucFotNCL+aNJ/0KCMsRtlXN9fs8uoOMSRk=
563568
github.com/syndtr/goleveldb v0.0.0-20190203031304-2f17a3356c66/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
564569
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
565570
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
@@ -745,6 +750,7 @@ google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9Ywl
745750
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
746751
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
747752
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
753+
google.golang.org/appengine v1.6.0 h1:Tfd7cKwKbFRsI8RMAD3oqqw7JPFRrvFlOsfbgVkjOOw=
748754
google.golang.org/appengine v1.6.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
749755
google.golang.org/appengine v1.6.1 h1:QzqyMA1tlu6CgqCDUtU9V+ZKhLFT2dkJuANu5QaxI3I=
750756
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=

integrations/api_team_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,32 @@ func checkTeamBean(t *testing.T, id int64, name, description string, permission
107107
assert.NoError(t, team.GetUnits(), "GetUnits")
108108
checkTeamResponse(t, convert.ToTeam(team), name, description, permission, units)
109109
}
110+
111+
type TeamSearchResults struct {
112+
OK bool `json:"ok"`
113+
Data []*api.Team `json:"data"`
114+
}
115+
116+
func TestAPITeamSearch(t *testing.T) {
117+
prepareTestEnv(t)
118+
119+
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
120+
org := models.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)
121+
122+
var results TeamSearchResults
123+
124+
session := loginUser(t, user.Name)
125+
req := NewRequestf(t, "GET", "/api/v1/orgs/%s/teams/search?q=%s", org.Name, "_team")
126+
resp := session.MakeRequest(t, req, http.StatusOK)
127+
DecodeJSON(t, resp, &results)
128+
assert.NotEmpty(t, results.Data)
129+
assert.Equal(t, 1, len(results.Data))
130+
assert.Equal(t, "test_team", results.Data[0].Name)
131+
132+
// no access if not organization member
133+
user5 := models.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
134+
session = loginUser(t, user5.Name)
135+
req = NewRequestf(t, "GET", "/api/v1/orgs/%s/teams/search?q=%s", org.Name, "team")
136+
resp = session.MakeRequest(t, req, http.StatusForbidden)
137+
138+
}

models/org_team.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"code.gitea.io/gitea/modules/setting"
1616

1717
"github.com/go-xorm/xorm"
18+
"xorm.io/builder"
1819
)
1920

2021
const ownerTeamName = "Owners"
@@ -34,6 +35,67 @@ type Team struct {
3435
Units []*TeamUnit `xorm:"-"`
3536
}
3637

38+
// SearchTeamOptions holds the search options
39+
type SearchTeamOptions struct {
40+
UserID int64
41+
Keyword string
42+
OrgID int64
43+
IncludeDesc bool
44+
PageSize int
45+
Page int
46+
}
47+
48+
// SearchTeam search for teams. Caller is responsible to check permissions.
49+
func SearchTeam(opts *SearchTeamOptions) ([]*Team, int64, error) {
50+
if opts.Page <= 0 {
51+
opts.Page = 1
52+
}
53+
if opts.PageSize == 0 {
54+
// Default limit
55+
opts.PageSize = 10
56+
}
57+
58+
var cond = builder.NewCond()
59+
60+
if len(opts.Keyword) > 0 {
61+
lowerKeyword := strings.ToLower(opts.Keyword)
62+
var keywordCond builder.Cond = builder.Like{"lower_name", lowerKeyword}
63+
if opts.IncludeDesc {
64+
keywordCond = keywordCond.Or(builder.Like{"LOWER(description)", lowerKeyword})
65+
}
66+
cond = cond.And(keywordCond)
67+
}
68+
69+
cond = cond.And(builder.Eq{"org_id": opts.OrgID})
70+
71+
sess := x.NewSession()
72+
defer sess.Close()
73+
74+
count, err := sess.
75+
Where(cond).
76+
Count(new(Team))
77+
78+
if err != nil {
79+
return nil, 0, err
80+
}
81+
82+
sess = sess.Where(cond)
83+
if opts.PageSize == -1 {
84+
opts.PageSize = int(count)
85+
} else {
86+
sess = sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize)
87+
}
88+
89+
teams := make([]*Team, 0, opts.PageSize)
90+
if err = sess.
91+
OrderBy("lower_name").
92+
Find(&teams); err != nil {
93+
return nil, 0, err
94+
}
95+
96+
return teams, count, nil
97+
}
98+
3799
// ColorFormat provides a basic color format for a Team
38100
func (t *Team) ColorFormat(s fmt.State) {
39101
log.ColorFprintf(s, "%d:%s (OrgID: %d) %-v",

models/repo.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,6 +1720,12 @@ func UpdateRepository(repo *Repository, visibilityChanged bool) (err error) {
17201720
return sess.Commit()
17211721
}
17221722

1723+
// UpdateRepositoryUpdatedTime updates a repository's updated time
1724+
func UpdateRepositoryUpdatedTime(repoID int64, updateTime time.Time) error {
1725+
_, err := x.Exec("UPDATE repository SET updated_unix = ? WHERE id = ?", updateTime.Unix(), repoID)
1726+
return err
1727+
}
1728+
17231729
// UpdateRepositoryUnits updates a repository's units
17241730
func UpdateRepositoryUnits(repo *Repository, units []RepoUnit) (err error) {
17251731
sess := x.NewSession()

0 commit comments

Comments
 (0)