Skip to content

Commit 94f1981

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Fix some slice problems (incorrect slice length) (go-gitea#19592) Fix sending empty notifications (go-gitea#19589) Handle the error of a missing blob object fix go-gitea#19530 (go-gitea#19552) Remove legacy `+build:` constraint (go-gitea#19582) Federation: return useful statistic information for nodeinfo (go-gitea#19561) Upgrade required git version to 2.0 (go-gitea#19577) add smtp password to install page (go-gitea#17564) ignore DNS error when doing migration allow/block check (go-gitea#19566) [skip ci] Updated translations via Crowdin Dont overwrite err with nil & rename PullCheckingFuncs to reflect there usage (go-gitea#19572) Improve UI on mobile (go-gitea#19546) Add API to check if team has repo access (go-gitea#19540)
2 parents 6f9a52f + 772ad76 commit 94f1981

File tree

133 files changed

+365
-163
lines changed

Some content is hidden

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

133 files changed

+365
-163
lines changed

build.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build vendor
6-
// +build vendor
76

87
package main
98

build/code-batch-process.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build ignore
6-
// +build ignore
76

87
package main
98

build/generate-bindata.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build ignore
6-
// +build ignore
76

87
package main
98

build/generate-emoji.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// license that can be found in the LICENSE file.
55

66
//go:build ignore
7-
// +build ignore
87

98
package main
109

build/generate-gitignores.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build ignore
2-
// +build ignore
32

43
package main
54

build/generate-licenses.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build ignore
2-
// +build ignore
32

43
package main
54

build/gitea-format-imports.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build ignore
6-
// +build ignore
76

87
package main
98

build/gocovmerge.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// merges them into one profile
88

99
//go:build ignore
10-
// +build ignore
1110

1211
package main
1312

cmd/admin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ func runCreateUser(c *cli.Context) error {
556556

557557
// If this is the first user being created.
558558
// Take it as the admin and don't force a password update.
559-
if n := user_model.CountUsers(); n == 0 {
559+
if n := user_model.CountUsers(nil); n == 0 {
560560
changePassword = false
561561
}
562562

cmd/embedded.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build bindata
6-
// +build bindata
76

87
package cmd
98

cmd/embedded_stub.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build !bindata
6-
// +build !bindata
76

87
package cmd
98

custom/conf/app.example.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,9 @@ PATH =
22402240
;;
22412241
;; Enable/Disable federation capabilities
22422242
; ENABLED = true
2243+
;;
2244+
;; Enable/Disable user statistics for nodeinfo if federation is enabled
2245+
; SHARE_USER_STATISTICS = true
22432246

22442247
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22452248
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,7 @@ Task queue configuration has been moved to `queue.task`. However, the below conf
10851085
## Federation (`federation`)
10861086

10871087
- `ENABLED`: **true**: Enable/Disable federation capabilities
1088+
- `SHARE_USER_STATISTICS`: **true**: Enable/Disable user statistics for nodeinfo if federation is enabled
10881089

10891090
## Packages (`packages`)
10901091

docs/content/doc/installation/from-binary.en-us.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ Of note, configuring `GITEA_WORK_DIR` will tell Gitea where to base its working
5050

5151
### Prepare environment
5252

53-
Check that Git is installed on the server. If it is not, install it first.
53+
Check that Git is installed on the server. If it is not, install it first. Gitea requires Git version >= 2.0.
54+
5455
```sh
5556
git --version
5657
```

integrations/api_nodeinfo_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ func TestNodeinfo(t *testing.T) {
2626
resp := MakeRequest(t, req, http.StatusOK)
2727
var nodeinfo api.NodeInfo
2828
DecodeJSON(t, resp, &nodeinfo)
29+
assert.True(t, nodeinfo.OpenRegistrations)
2930
assert.Equal(t, "gitea", nodeinfo.Software.Name)
31+
assert.Equal(t, 23, nodeinfo.Usage.Users.Total)
32+
assert.Equal(t, 15, nodeinfo.Usage.LocalPosts)
33+
assert.Equal(t, 2, nodeinfo.Usage.LocalComments)
3034
})
3135
}

integrations/api_team_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"testing"
1212

1313
"code.gitea.io/gitea/models/organization"
14+
"code.gitea.io/gitea/models/repo"
1415
"code.gitea.io/gitea/models/unit"
1516
"code.gitea.io/gitea/models/unittest"
1617
user_model "code.gitea.io/gitea/models/user"
@@ -239,3 +240,26 @@ func TestAPITeamSearch(t *testing.T) {
239240
req = NewRequestf(t, "GET", "/api/v1/orgs/%s/teams/search?q=%s&token=%s", org.Name, "team", token5)
240241
MakeRequest(t, req, http.StatusForbidden)
241242
}
243+
244+
func TestAPIGetTeamRepo(t *testing.T) {
245+
defer prepareTestEnv(t)()
246+
247+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 15}).(*user_model.User)
248+
teamRepo := unittest.AssertExistsAndLoadBean(t, &repo.Repository{ID: 24}).(*repo.Repository)
249+
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 5}).(*organization.Team)
250+
251+
var results api.Repository
252+
253+
token := getUserToken(t, user.Name)
254+
req := NewRequestf(t, "GET", "/api/v1/teams/%d/repos/%s/?token=%s", team.ID, teamRepo.FullName(), token)
255+
resp := MakeRequest(t, req, http.StatusOK)
256+
DecodeJSON(t, resp, &results)
257+
assert.Equal(t, "big_test_private_4", teamRepo.Name)
258+
259+
// no access if not organization member
260+
user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User)
261+
token5 := getUserToken(t, user5.Name)
262+
263+
req = NewRequestf(t, "GET", "/api/v1/teams/%d/repos/%s/?token=%s", team.ID, teamRepo.FullName(), token5)
264+
MakeRequest(t, req, http.StatusNotFound)
265+
}

models/auth/oauth2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func deleteOAuth2Application(sess db.Engine, id, userid int64) error {
245245
"oauth2_authorization_code.grant_id = oauth2_grant.id AND oauth2_grant.application_id = ?", id).Find(&codes); err != nil {
246246
return err
247247
}
248-
codeIDs := make([]int64, 0)
248+
codeIDs := make([]int64, 0, len(codes))
249249
for _, grant := range codes {
250250
codeIDs = append(codeIDs, grant.ID)
251251
}

models/error.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ type ErrInvalidCloneAddr struct {
296296
IsProtocolInvalid bool
297297
IsPermissionDenied bool
298298
LocalPath bool
299-
NotResolvedIP bool
300299
}
301300

302301
// IsErrInvalidCloneAddr checks if an error is a ErrInvalidCloneAddr.
@@ -306,9 +305,6 @@ func IsErrInvalidCloneAddr(err error) bool {
306305
}
307306

308307
func (err *ErrInvalidCloneAddr) Error() string {
309-
if err.NotResolvedIP {
310-
return fmt.Sprintf("migration/cloning from '%s' is not allowed: unknown hostname", err.Host)
311-
}
312308
if err.IsInvalidPath {
313309
return fmt.Sprintf("migration/cloning from '%s' is not allowed: the provided path is invalid", err.Host)
314310
}

models/issue_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,3 +590,10 @@ func TestLoadTotalTrackedTime(t *testing.T) {
590590

591591
assert.Equal(t, int64(3682), milestone.TotalTrackedTime)
592592
}
593+
594+
func TestCountIssues(t *testing.T) {
595+
assert.NoError(t, unittest.PrepareTestDatabase())
596+
count, err := CountIssues(&IssuesOptions{})
597+
assert.NoError(t, err)
598+
assert.EqualValues(t, 15, count)
599+
}

models/repo_activity.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func GetActivityStatsTopAuthors(ctx context.Context, repo *repo_model.Repository
127127
user.Commits += v.Commits
128128
}
129129
}
130-
v := make([]*ActivityAuthorData, 0)
130+
v := make([]*ActivityAuthorData, 0, len(users))
131131
for _, u := range users {
132132
v = append(v, u)
133133
}

models/statistic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type IssueByRepositoryCount struct {
4949
// GetStatistic returns the database statistics
5050
func GetStatistic() (stats Statistic) {
5151
e := db.GetEngine(db.DefaultContext)
52-
stats.Counter.User = user_model.CountUsers()
52+
stats.Counter.User = user_model.CountUsers(nil)
5353
stats.Counter.Org = organization.CountOrganizations()
5454
stats.Counter.PublicKey, _ = e.Count(new(asymkey_model.PublicKey))
5555
stats.Counter.Repo = repo_model.CountRepositories(true)

models/user/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type UserList []*User //revive:disable-line:exported
1717

1818
// GetUserIDs returns a slice of user's id
1919
func (users UserList) GetUserIDs() []int64 {
20-
userIDs := make([]int64, len(users))
20+
userIDs := make([]int64, 0, len(users))
2121
for _, user := range users {
2222
userIDs = append(userIDs, user.ID) // Considering that user id are unique in the list
2323
}

models/user/user.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -744,16 +744,25 @@ func CreateUser(u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err e
744744
return committer.Commit()
745745
}
746746

747-
func countUsers(e db.Engine) int64 {
748-
count, _ := e.
749-
Where("type=0").
750-
Count(new(User))
751-
return count
747+
// CountUserFilter represent optional filters for CountUsers
748+
type CountUserFilter struct {
749+
LastLoginSince *int64
752750
}
753751

754752
// CountUsers returns number of users.
755-
func CountUsers() int64 {
756-
return countUsers(db.GetEngine(db.DefaultContext))
753+
func CountUsers(opts *CountUserFilter) int64 {
754+
return countUsers(db.DefaultContext, opts)
755+
}
756+
757+
func countUsers(ctx context.Context, opts *CountUserFilter) int64 {
758+
sess := db.GetEngine(ctx).Where(builder.Eq{"type": "0"})
759+
760+
if opts != nil && opts.LastLoginSince != nil {
761+
sess = sess.Where(builder.Gte{"last_login_unix": *opts.LastLoginSince})
762+
}
763+
764+
count, _ := sess.Count(new(User))
765+
return count
757766
}
758767

759768
// GetVerifyUser get user by verify code

modules/auth/pam/pam.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build pam
6-
// +build pam
76

87
package pam
98

modules/auth/pam/pam_stub.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build !pam
6-
// +build !pam
76

87
package pam
98

modules/auth/pam/pam_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build pam
2-
// +build pam
32

43
// Copyright 2021 The Gitea Authors. All rights reserved.
54
// Use of this source code is governed by a MIT-style

modules/avatar/identicon/identicon_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build test_avatar_identicon
6-
// +build test_avatar_identicon
76

87
package identicon
98

modules/context/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"code.gitea.io/gitea/models/auth"
1616
repo_model "code.gitea.io/gitea/models/repo"
17+
"code.gitea.io/gitea/modules/cache"
1718
"code.gitea.io/gitea/modules/git"
1819
"code.gitea.io/gitea/modules/log"
1920
"code.gitea.io/gitea/modules/setting"
@@ -247,6 +248,7 @@ func APIContexter() func(http.Handler) http.Handler {
247248
Resp: NewResponse(w),
248249
Data: map[string]interface{}{},
249250
Locale: locale,
251+
Cache: cache.GetCache(),
250252
Repo: &Repository{
251253
PullRequest: &PullRequest{},
252254
},

modules/git/blob_gogit.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// license that can be found in the LICENSE file.
55

66
//go:build gogit
7-
// +build gogit
87

98
package git
109

modules/git/blob_nogogit.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build !gogit
6-
// +build !gogit
76

87
package git
98

modules/git/command_race_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build race
6-
// +build race
76

87
package git
98

modules/git/commit_convert_gogit.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// license that can be found in the LICENSE file.
55

66
//go:build gogit
7-
// +build gogit
87

98
package git
109

modules/git/commit_info_gogit.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build gogit
6-
// +build gogit
76

87
package git
98

modules/git/commit_info_nogogit.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build !gogit
6-
// +build !gogit
76

87
package git
98

0 commit comments

Comments
 (0)