Skip to content

Commit 600e300

Browse files
authored
Merge branch 'main' into previos-blame-link
2 parents 71ccfbd + 9b1b4b5 commit 600e300

Some content is hidden

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

65 files changed

+852
-293
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ Kyle Dumont <[email protected]> (@kdumontnu)
4343
Patrick Schratz <[email protected]> (@pat-s)
4444
Janis Estelmann <[email protected]> (@KN4CK3R)
4545
Steven Kriegler <[email protected]> (@justusbunsi)
46+
Jimmy Praet <[email protected]> (@jpraet)

cmd/convert.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ func runConvert(ctx *cli.Context) error {
2727
return err
2828
}
2929

30-
log.Trace("AppPath: %s", setting.AppPath)
31-
log.Trace("AppWorkPath: %s", setting.AppWorkPath)
32-
log.Trace("Custom path: %s", setting.CustomPath)
33-
log.Trace("Log path: %s", setting.LogRootPath)
30+
log.Info("AppPath: %s", setting.AppPath)
31+
log.Info("AppWorkPath: %s", setting.AppWorkPath)
32+
log.Info("Custom path: %s", setting.CustomPath)
33+
log.Info("Log path: %s", setting.LogRootPath)
3434
setting.InitDBConfig()
3535

3636
if !setting.Database.UseMySQL {

cmd/dump_repo.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var CmdDumpRepository = cli.Command{
6969
cli.StringFlag{
7070
Name: "units",
7171
Value: "",
72-
Usage: `Which items will be migrated, one or more units should be separated as comma.
72+
Usage: `Which items will be migrated, one or more units should be separated as comma.
7373
wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.`,
7474
},
7575
},
@@ -80,10 +80,10 @@ func runDumpRepository(ctx *cli.Context) error {
8080
return err
8181
}
8282

83-
log.Trace("AppPath: %s", setting.AppPath)
84-
log.Trace("AppWorkPath: %s", setting.AppWorkPath)
85-
log.Trace("Custom path: %s", setting.CustomPath)
86-
log.Trace("Log path: %s", setting.LogRootPath)
83+
log.Info("AppPath: %s", setting.AppPath)
84+
log.Info("AppWorkPath: %s", setting.AppWorkPath)
85+
log.Info("Custom path: %s", setting.CustomPath)
86+
log.Info("Log path: %s", setting.LogRootPath)
8787
setting.InitDBConfig()
8888

8989
var (

cmd/migrate.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ func runMigrate(ctx *cli.Context) error {
2828
return err
2929
}
3030

31-
log.Trace("AppPath: %s", setting.AppPath)
32-
log.Trace("AppWorkPath: %s", setting.AppWorkPath)
33-
log.Trace("Custom path: %s", setting.CustomPath)
34-
log.Trace("Log path: %s", setting.LogRootPath)
31+
log.Info("AppPath: %s", setting.AppPath)
32+
log.Info("AppWorkPath: %s", setting.AppWorkPath)
33+
log.Info("Custom path: %s", setting.CustomPath)
34+
log.Info("Log path: %s", setting.LogRootPath)
3535
setting.InitDBConfig()
3636

3737
if err := models.NewEngine(context.Background(), migrations.Migrate); err != nil {

cmd/migrate_storage.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ func runMigrateStorage(ctx *cli.Context) error {
110110
return err
111111
}
112112

113-
log.Trace("AppPath: %s", setting.AppPath)
114-
log.Trace("AppWorkPath: %s", setting.AppWorkPath)
115-
log.Trace("Custom path: %s", setting.CustomPath)
116-
log.Trace("Log path: %s", setting.LogRootPath)
113+
log.Info("AppPath: %s", setting.AppPath)
114+
log.Info("AppWorkPath: %s", setting.AppWorkPath)
115+
log.Info("Custom path: %s", setting.CustomPath)
116+
log.Info("Log path: %s", setting.LogRootPath)
117117
setting.InitDBConfig()
118118

119119
if err := models.NewEngine(context.Background(), migrations.Migrate); err != nil {

cmd/web.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ and it takes care of all the other things for you`,
4747
Value: setting.PIDFile,
4848
Usage: "Custom pid file path",
4949
},
50+
cli.BoolFlag{
51+
Name: "quiet, q",
52+
Usage: "Only display Fatal logging errors until logging is set-up",
53+
},
54+
cli.BoolFlag{
55+
Name: "verbose",
56+
Usage: "Set initial logging to TRACE level until logging is properly set-up",
57+
},
5058
},
5159
}
5260

@@ -71,6 +79,14 @@ func runHTTPRedirector() {
7179
}
7280

7381
func runWeb(ctx *cli.Context) error {
82+
if ctx.Bool("verbose") {
83+
_ = log.DelLogger("console")
84+
log.NewLogger(0, "console", "console", fmt.Sprintf(`{"level": "trace", "colorize": %t, "stacktraceLevel": "none"}`, log.CanColorStdout))
85+
} else if ctx.Bool("quiet") {
86+
_ = log.DelLogger("console")
87+
log.NewLogger(0, "console", "console", fmt.Sprintf(`{"level": "fatal", "colorize": %t, "stacktraceLevel": "none"}`, log.CanColorStdout))
88+
}
89+
7490
managerCtx, cancel := context.WithCancel(context.Background())
7591
graceful.InitManager(managerCtx)
7692
defer cancel()

custom/conf/app.example.ini

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,9 +651,18 @@ PATH =
651651
;DEFAULT_ALLOW_CREATE_ORGANIZATION = true
652652
;;
653653
;; Either "public", "limited" or "private", default is "public"
654-
;; Limited is for signed user only
655-
;; Private is only for member of the organization
656-
;; Public is for everyone
654+
;; Limited is for users visible only to signed users
655+
;; Private is for users visible only to members of their organizations
656+
;; Public is for users visible for everyone
657+
;DEFAULT_USER_VISIBILITY = public
658+
;;
659+
;; Set whitch visibibilty modes a user can have
660+
;ALLOWED_USER_VISIBILITY_MODES = public,limited,private
661+
;;
662+
;; Either "public", "limited" or "private", default is "public"
663+
;; Limited is for organizations visible only to signed users
664+
;; Private is for organizations visible only to members of the organization
665+
;; Public is for organizations visible to everyone
657666
;DEFAULT_ORG_VISIBILITY = public
658667
;;
659668
;; Default value for DefaultOrgMemberVisible

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ relation to port exhaustion.
512512
- `SHOW_MILESTONES_DASHBOARD_PAGE`: **true** Enable this to show the milestones dashboard page - a view of all the user's milestones
513513
- `AUTO_WATCH_NEW_REPOS`: **true**: Enable this to let all organisation users watch new repos when they are created
514514
- `AUTO_WATCH_ON_CHANGES`: **false**: Enable this to make users watch a repository after their first commit to it
515+
- `DEFAULT_USER_VISIBILITY`: **public**: Set default visibility mode for users, either "public", "limited" or "private".
516+
- `ALLOWED_USER_VISIBILITY_MODES`: **public,limited,private**: Set whitch visibibilty modes a user can have
515517
- `DEFAULT_ORG_VISIBILITY`: **public**: Set default visibility mode for organisations, either "public", "limited" or "private".
516518
- `DEFAULT_ORG_MEMBER_VISIBLE`: **false** True will make the membership of the users visible when added to the organisation.
517519
- `ALLOW_ONLY_INTERNAL_REGISTRATION`: **false** Set to true to force registration only via gitea.

docs/content/doc/usage/command-line.en-us.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ Starts the server:
4646
- `--port number`, `-p number`: Port number. Optional. (default: 3000). Overrides configuration file.
4747
- `--install-port number`: Port number to run the install page on. Optional. (default: 3000). Overrides configuration file.
4848
- `--pid path`, `-P path`: Pidfile path. Optional.
49+
- `--quiet`, `-q`: Only emit Fatal logs on the console for logs emitted before logging set up.
50+
- `--verbose`: Emit tracing logs on the console for logs emitted before logging is set-up.
4951
- Examples:
5052
- `gitea web`
5153
- `gitea web --port 80`

integrations/api_user_search_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,34 @@ func TestAPIUserSearchNotLoggedIn(t *testing.T) {
5959
}
6060
}
6161
}
62+
63+
func TestAPIUserSearchAdminLoggedInUserHidden(t *testing.T) {
64+
defer prepareTestEnv(t)()
65+
adminUsername := "user1"
66+
session := loginUser(t, adminUsername)
67+
token := getTokenForLoggedInUser(t, session)
68+
query := "user31"
69+
req := NewRequestf(t, "GET", "/api/v1/users/search?token=%s&q=%s", token, query)
70+
req.SetBasicAuth(token, "x-oauth-basic")
71+
resp := session.MakeRequest(t, req, http.StatusOK)
72+
73+
var results SearchResults
74+
DecodeJSON(t, resp, &results)
75+
assert.NotEmpty(t, results.Data)
76+
for _, user := range results.Data {
77+
assert.Contains(t, user.UserName, query)
78+
assert.NotEmpty(t, user.Email)
79+
assert.EqualValues(t, "private", user.Visibility)
80+
}
81+
}
82+
83+
func TestAPIUserSearchNotLoggedInUserHidden(t *testing.T) {
84+
defer prepareTestEnv(t)()
85+
query := "user31"
86+
req := NewRequestf(t, "GET", "/api/v1/users/search?q=%s", query)
87+
resp := MakeRequest(t, req, http.StatusOK)
88+
89+
var results SearchResults
90+
DecodeJSON(t, resp, &results)
91+
assert.Empty(t, results.Data)
92+
}

models/fixtures/user.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,6 @@
508508
num_repos: 0
509509
is_active: true
510510

511-
512511
-
513512
id: 30
514513
lower_name: user30
@@ -525,3 +524,20 @@
525524
avatar_email: [email protected]
526525
num_repos: 2
527526
is_active: true
527+
528+
-
529+
id: 31
530+
lower_name: user31
531+
name: user31
532+
full_name: "user31"
533+
534+
passwd_hash_algo: argon2
535+
passwd: a3d5fcd92bae586c2e3dbe72daea7a0d27833a8d0227aa1704f4bbd775c1f3b03535b76dd93b0d4d8d22a519dca47df1547b # password
536+
type: 0 # individual
537+
salt: ZogKvWdyEx
538+
is_admin: false
539+
visibility: 2
540+
avatar: avatar31
541+
avatar_email: [email protected]
542+
num_repos: 0
543+
is_active: true

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ var migrations = []Migration{
323323
NewMigration("Add new table repo_archiver", addRepoArchiver),
324324
// v186 -> v187
325325
NewMigration("Create protected tag table", createProtectedTagTable),
326+
// v187 -> v188
327+
NewMigration("Drop unneeded webhook related columns", dropWebhookColumns),
326328
}
327329

328330
// GetCurrentDBVersion returns the current db version

models/migrations/v187.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2021 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migrations
6+
7+
import (
8+
"xorm.io/xorm"
9+
)
10+
11+
func dropWebhookColumns(x *xorm.Engine) error {
12+
// Make sure the columns exist before dropping them
13+
type Webhook struct {
14+
Signature string `xorm:"TEXT"`
15+
IsSSL bool `xorm:"is_ssl"`
16+
}
17+
if err := x.Sync2(new(Webhook)); err != nil {
18+
return err
19+
}
20+
21+
type HookTask struct {
22+
Typ string `xorm:"VARCHAR(16) index"`
23+
URL string `xorm:"TEXT"`
24+
Signature string `xorm:"TEXT"`
25+
HTTPMethod string `xorm:"http_method"`
26+
ContentType int
27+
IsSSL bool
28+
}
29+
if err := x.Sync2(new(HookTask)); err != nil {
30+
return err
31+
}
32+
33+
sess := x.NewSession()
34+
defer sess.Close()
35+
if err := sess.Begin(); err != nil {
36+
return err
37+
}
38+
if err := dropTableColumns(sess, "webhook", "signature", "is_ssl"); err != nil {
39+
return err
40+
}
41+
if err := dropTableColumns(sess, "hook_task", "typ", "url", "signature", "http_method", "content_type", "is_ssl"); err != nil {
42+
return err
43+
}
44+
45+
return sess.Commit()
46+
}

models/org.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -455,22 +455,22 @@ func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) {
455455
Find(&orgs)
456456
}
457457

458-
// HasOrgVisible tells if the given user can see the given org
459-
func HasOrgVisible(org, user *User) bool {
460-
return hasOrgVisible(x, org, user)
458+
// HasOrgOrUserVisible tells if the given user can see the given org or user
459+
func HasOrgOrUserVisible(org, user *User) bool {
460+
return hasOrgOrUserVisible(x, org, user)
461461
}
462462

463-
func hasOrgVisible(e Engine, org, user *User) bool {
463+
func hasOrgOrUserVisible(e Engine, orgOrUser, user *User) bool {
464464
// Not SignedUser
465465
if user == nil {
466-
return org.Visibility == structs.VisibleTypePublic
466+
return orgOrUser.Visibility == structs.VisibleTypePublic
467467
}
468468

469-
if user.IsAdmin {
469+
if user.IsAdmin || orgOrUser.ID == user.ID {
470470
return true
471471
}
472472

473-
if (org.Visibility == structs.VisibleTypePrivate || user.IsRestricted) && !org.hasMemberWithUserID(e, user.ID) {
473+
if (orgOrUser.Visibility == structs.VisibleTypePrivate || user.IsRestricted) && !orgOrUser.hasMemberWithUserID(e, user.ID) {
474474
return false
475475
}
476476
return true
@@ -483,7 +483,7 @@ func HasOrgsVisible(orgs []*User, user *User) bool {
483483
}
484484

485485
for _, org := range orgs {
486-
if HasOrgVisible(org, user) {
486+
if HasOrgOrUserVisible(org, user) {
487487
return true
488488
}
489489
}

models/org_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,9 @@ func TestHasOrgVisibleTypePublic(t *testing.T) {
586586
assert.NoError(t, CreateOrganization(org, owner))
587587
org = AssertExistsAndLoadBean(t,
588588
&User{Name: org.Name, Type: UserTypeOrganization}).(*User)
589-
test1 := HasOrgVisible(org, owner)
590-
test2 := HasOrgVisible(org, user3)
591-
test3 := HasOrgVisible(org, nil)
589+
test1 := HasOrgOrUserVisible(org, owner)
590+
test2 := HasOrgOrUserVisible(org, user3)
591+
test3 := HasOrgOrUserVisible(org, nil)
592592
assert.True(t, test1) // owner of org
593593
assert.True(t, test2) // user not a part of org
594594
assert.True(t, test3) // logged out user
@@ -609,9 +609,9 @@ func TestHasOrgVisibleTypeLimited(t *testing.T) {
609609
assert.NoError(t, CreateOrganization(org, owner))
610610
org = AssertExistsAndLoadBean(t,
611611
&User{Name: org.Name, Type: UserTypeOrganization}).(*User)
612-
test1 := HasOrgVisible(org, owner)
613-
test2 := HasOrgVisible(org, user3)
614-
test3 := HasOrgVisible(org, nil)
612+
test1 := HasOrgOrUserVisible(org, owner)
613+
test2 := HasOrgOrUserVisible(org, user3)
614+
test3 := HasOrgOrUserVisible(org, nil)
615615
assert.True(t, test1) // owner of org
616616
assert.True(t, test2) // user not a part of org
617617
assert.False(t, test3) // logged out user
@@ -632,9 +632,9 @@ func TestHasOrgVisibleTypePrivate(t *testing.T) {
632632
assert.NoError(t, CreateOrganization(org, owner))
633633
org = AssertExistsAndLoadBean(t,
634634
&User{Name: org.Name, Type: UserTypeOrganization}).(*User)
635-
test1 := HasOrgVisible(org, owner)
636-
test2 := HasOrgVisible(org, user3)
637-
test3 := HasOrgVisible(org, nil)
635+
test1 := HasOrgOrUserVisible(org, owner)
636+
test2 := HasOrgOrUserVisible(org, user3)
637+
test3 := HasOrgOrUserVisible(org, nil)
638638
assert.True(t, test1) // owner of org
639639
assert.False(t, test2) // user not a part of org
640640
assert.False(t, test3) // logged out user

models/repo.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,7 @@ func (repo *Repository) getReviewers(e Engine, doerID, posterID int64) ([]*User,
585585

586586
var users []*User
587587

588-
if repo.IsPrivate ||
589-
(repo.Owner.IsOrganization() && repo.Owner.Visibility == api.VisibleTypePrivate) {
588+
if repo.IsPrivate || repo.Owner.Visibility == api.VisibleTypePrivate {
590589
// This a private repository:
591590
// Anyone who can read the repository is a requestable reviewer
592591
if err := e.

models/repo_permission.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ func getUserRepoPermission(e Engine, repo *Repository, user *User) (perm Permiss
176176
return
177177
}
178178

179-
// Prevent strangers from checking out public repo of private orginization
180-
// Allow user if they are collaborator of a repo within a private orginization but not a member of the orginization itself
181-
if repo.Owner.IsOrganization() && !hasOrgVisible(e, repo.Owner, user) && !isCollaborator {
179+
// Prevent strangers from checking out public repo of private orginization/users
180+
// Allow user if they are collaborator of a repo within a private user or a private organization but not a member of the organization itself
181+
if !hasOrgOrUserVisible(e, repo.Owner, user) && !isCollaborator {
182182
perm.AccessMode = AccessModeNone
183183
return
184184
}

0 commit comments

Comments
 (0)