Skip to content

Commit

Permalink
Merge remote-tracking branch 'giteaofficial/main'
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
zjjhot committed May 3, 2022
2 parents 6f9a52f + 772ad76 commit 94f1981
Show file tree
Hide file tree
Showing 133 changed files with 365 additions and 163 deletions.
1 change: 0 additions & 1 deletion build.go
Expand Up @@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build vendor
// +build vendor

package main

Expand Down
1 change: 0 additions & 1 deletion build/code-batch-process.go
Expand Up @@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build ignore
// +build ignore

package main

Expand Down
1 change: 0 additions & 1 deletion build/generate-bindata.go
Expand Up @@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build ignore
// +build ignore

package main

Expand Down
1 change: 0 additions & 1 deletion build/generate-emoji.go
Expand Up @@ -4,7 +4,6 @@
// license that can be found in the LICENSE file.

//go:build ignore
// +build ignore

package main

Expand Down
1 change: 0 additions & 1 deletion build/generate-gitignores.go
@@ -1,5 +1,4 @@
//go:build ignore
// +build ignore

package main

Expand Down
1 change: 0 additions & 1 deletion build/generate-licenses.go
@@ -1,5 +1,4 @@
//go:build ignore
// +build ignore

package main

Expand Down
1 change: 0 additions & 1 deletion build/gitea-format-imports.go
Expand Up @@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build ignore
// +build ignore

package main

Expand Down
1 change: 0 additions & 1 deletion build/gocovmerge.go
Expand Up @@ -7,7 +7,6 @@
// merges them into one profile

//go:build ignore
// +build ignore

package main

Expand Down
2 changes: 1 addition & 1 deletion cmd/admin.go
Expand Up @@ -556,7 +556,7 @@ func runCreateUser(c *cli.Context) error {

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

Expand Down
1 change: 0 additions & 1 deletion cmd/embedded.go
Expand Up @@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build bindata
// +build bindata

package cmd

Expand Down
1 change: 0 additions & 1 deletion cmd/embedded_stub.go
Expand Up @@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build !bindata
// +build !bindata

package cmd

Expand Down
3 changes: 3 additions & 0 deletions custom/conf/app.example.ini
Expand Up @@ -2240,6 +2240,9 @@ PATH =
;;
;; Enable/Disable federation capabilities
; ENABLED = true
;;
;; Enable/Disable user statistics for nodeinfo if federation is enabled
; SHARE_USER_STATISTICS = true

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
1 change: 1 addition & 0 deletions docs/content/doc/advanced/config-cheat-sheet.en-us.md
Expand Up @@ -1085,6 +1085,7 @@ Task queue configuration has been moved to `queue.task`. However, the below conf
## Federation (`federation`)

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

## Packages (`packages`)

Expand Down
3 changes: 2 additions & 1 deletion docs/content/doc/installation/from-binary.en-us.md
Expand Up @@ -50,7 +50,8 @@ Of note, configuring `GITEA_WORK_DIR` will tell Gitea where to base its working

### Prepare environment

Check that Git is installed on the server. If it is not, install it first.
Check that Git is installed on the server. If it is not, install it first. Gitea requires Git version >= 2.0.

```sh
git --version
```
Expand Down
4 changes: 4 additions & 0 deletions integrations/api_nodeinfo_test.go
Expand Up @@ -26,6 +26,10 @@ func TestNodeinfo(t *testing.T) {
resp := MakeRequest(t, req, http.StatusOK)
var nodeinfo api.NodeInfo
DecodeJSON(t, resp, &nodeinfo)
assert.True(t, nodeinfo.OpenRegistrations)
assert.Equal(t, "gitea", nodeinfo.Software.Name)
assert.Equal(t, 23, nodeinfo.Usage.Users.Total)
assert.Equal(t, 15, nodeinfo.Usage.LocalPosts)
assert.Equal(t, 2, nodeinfo.Usage.LocalComments)
})
}
24 changes: 24 additions & 0 deletions integrations/api_team_test.go
Expand Up @@ -11,6 +11,7 @@ import (
"testing"

"code.gitea.io/gitea/models/organization"
"code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
Expand Down Expand Up @@ -239,3 +240,26 @@ func TestAPITeamSearch(t *testing.T) {
req = NewRequestf(t, "GET", "/api/v1/orgs/%s/teams/search?q=%s&token=%s", org.Name, "team", token5)
MakeRequest(t, req, http.StatusForbidden)
}

func TestAPIGetTeamRepo(t *testing.T) {
defer prepareTestEnv(t)()

user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 15}).(*user_model.User)
teamRepo := unittest.AssertExistsAndLoadBean(t, &repo.Repository{ID: 24}).(*repo.Repository)
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 5}).(*organization.Team)

var results api.Repository

token := getUserToken(t, user.Name)
req := NewRequestf(t, "GET", "/api/v1/teams/%d/repos/%s/?token=%s", team.ID, teamRepo.FullName(), token)
resp := MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &results)
assert.Equal(t, "big_test_private_4", teamRepo.Name)

// no access if not organization member
user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User)
token5 := getUserToken(t, user5.Name)

req = NewRequestf(t, "GET", "/api/v1/teams/%d/repos/%s/?token=%s", team.ID, teamRepo.FullName(), token5)
MakeRequest(t, req, http.StatusNotFound)
}
2 changes: 1 addition & 1 deletion models/auth/oauth2.go
Expand Up @@ -245,7 +245,7 @@ func deleteOAuth2Application(sess db.Engine, id, userid int64) error {
"oauth2_authorization_code.grant_id = oauth2_grant.id AND oauth2_grant.application_id = ?", id).Find(&codes); err != nil {
return err
}
codeIDs := make([]int64, 0)
codeIDs := make([]int64, 0, len(codes))
for _, grant := range codes {
codeIDs = append(codeIDs, grant.ID)
}
Expand Down
4 changes: 0 additions & 4 deletions models/error.go
Expand Up @@ -296,7 +296,6 @@ type ErrInvalidCloneAddr struct {
IsProtocolInvalid bool
IsPermissionDenied bool
LocalPath bool
NotResolvedIP bool
}

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

func (err *ErrInvalidCloneAddr) Error() string {
if err.NotResolvedIP {
return fmt.Sprintf("migration/cloning from '%s' is not allowed: unknown hostname", err.Host)
}
if err.IsInvalidPath {
return fmt.Sprintf("migration/cloning from '%s' is not allowed: the provided path is invalid", err.Host)
}
Expand Down
7 changes: 7 additions & 0 deletions models/issue_test.go
Expand Up @@ -590,3 +590,10 @@ func TestLoadTotalTrackedTime(t *testing.T) {

assert.Equal(t, int64(3682), milestone.TotalTrackedTime)
}

func TestCountIssues(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
count, err := CountIssues(&IssuesOptions{})
assert.NoError(t, err)
assert.EqualValues(t, 15, count)
}
2 changes: 1 addition & 1 deletion models/repo_activity.go
Expand Up @@ -127,7 +127,7 @@ func GetActivityStatsTopAuthors(ctx context.Context, repo *repo_model.Repository
user.Commits += v.Commits
}
}
v := make([]*ActivityAuthorData, 0)
v := make([]*ActivityAuthorData, 0, len(users))
for _, u := range users {
v = append(v, u)
}
Expand Down
2 changes: 1 addition & 1 deletion models/statistic.go
Expand Up @@ -49,7 +49,7 @@ type IssueByRepositoryCount struct {
// GetStatistic returns the database statistics
func GetStatistic() (stats Statistic) {
e := db.GetEngine(db.DefaultContext)
stats.Counter.User = user_model.CountUsers()
stats.Counter.User = user_model.CountUsers(nil)
stats.Counter.Org = organization.CountOrganizations()
stats.Counter.PublicKey, _ = e.Count(new(asymkey_model.PublicKey))
stats.Counter.Repo = repo_model.CountRepositories(true)
Expand Down
2 changes: 1 addition & 1 deletion models/user/list.go
Expand Up @@ -17,7 +17,7 @@ type UserList []*User //revive:disable-line:exported

// GetUserIDs returns a slice of user's id
func (users UserList) GetUserIDs() []int64 {
userIDs := make([]int64, len(users))
userIDs := make([]int64, 0, len(users))
for _, user := range users {
userIDs = append(userIDs, user.ID) // Considering that user id are unique in the list
}
Expand Down
23 changes: 16 additions & 7 deletions models/user/user.go
Expand Up @@ -744,16 +744,25 @@ func CreateUser(u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err e
return committer.Commit()
}

func countUsers(e db.Engine) int64 {
count, _ := e.
Where("type=0").
Count(new(User))
return count
// CountUserFilter represent optional filters for CountUsers
type CountUserFilter struct {
LastLoginSince *int64
}

// CountUsers returns number of users.
func CountUsers() int64 {
return countUsers(db.GetEngine(db.DefaultContext))
func CountUsers(opts *CountUserFilter) int64 {
return countUsers(db.DefaultContext, opts)
}

func countUsers(ctx context.Context, opts *CountUserFilter) int64 {
sess := db.GetEngine(ctx).Where(builder.Eq{"type": "0"})

if opts != nil && opts.LastLoginSince != nil {
sess = sess.Where(builder.Gte{"last_login_unix": *opts.LastLoginSince})
}

count, _ := sess.Count(new(User))
return count
}

// GetVerifyUser get user by verify code
Expand Down
1 change: 0 additions & 1 deletion modules/auth/pam/pam.go
Expand Up @@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build pam
// +build pam

package pam

Expand Down
1 change: 0 additions & 1 deletion modules/auth/pam/pam_stub.go
Expand Up @@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build !pam
// +build !pam

package pam

Expand Down
1 change: 0 additions & 1 deletion modules/auth/pam/pam_test.go
@@ -1,5 +1,4 @@
//go:build pam
// +build pam

// Copyright 2021 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
Expand Down
1 change: 0 additions & 1 deletion modules/avatar/identicon/identicon_test.go
Expand Up @@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build test_avatar_identicon
// +build test_avatar_identicon

package identicon

Expand Down
2 changes: 2 additions & 0 deletions modules/context/api.go
Expand Up @@ -14,6 +14,7 @@ import (

"code.gitea.io/gitea/models/auth"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
Expand Down Expand Up @@ -247,6 +248,7 @@ func APIContexter() func(http.Handler) http.Handler {
Resp: NewResponse(w),
Data: map[string]interface{}{},
Locale: locale,
Cache: cache.GetCache(),
Repo: &Repository{
PullRequest: &PullRequest{},
},
Expand Down
1 change: 0 additions & 1 deletion modules/git/blob_gogit.go
Expand Up @@ -4,7 +4,6 @@
// license that can be found in the LICENSE file.

//go:build gogit
// +build gogit

package git

Expand Down
1 change: 0 additions & 1 deletion modules/git/blob_nogogit.go
Expand Up @@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build !gogit
// +build !gogit

package git

Expand Down
1 change: 0 additions & 1 deletion modules/git/command_race_test.go
Expand Up @@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build race
// +build race

package git

Expand Down
1 change: 0 additions & 1 deletion modules/git/commit_convert_gogit.go
Expand Up @@ -4,7 +4,6 @@
// license that can be found in the LICENSE file.

//go:build gogit
// +build gogit

package git

Expand Down
1 change: 0 additions & 1 deletion modules/git/commit_info_gogit.go
Expand Up @@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build gogit
// +build gogit

package git

Expand Down
1 change: 0 additions & 1 deletion modules/git/commit_info_nogogit.go
Expand Up @@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build !gogit
// +build !gogit

package git

Expand Down

0 comments on commit 94f1981

Please sign in to comment.