Skip to content

Commit 8e1e431

Browse files
authored
Merge branch 'main' into fix-scroll
2 parents 80649d8 + 496b8e3 commit 8e1e431

File tree

30 files changed

+510
-164
lines changed

30 files changed

+510
-164
lines changed

Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ else
1717
DIST := dist
1818
DIST_DIRS := $(DIST)/binaries $(DIST)/release
1919
IMPORT := code.gitea.io/gitea
20-
export GO111MODULE=on
2120

2221
GO ?= go
2322
SHASUM ?= shasum -a 256
@@ -363,7 +362,7 @@ test\#%:
363362
coverage:
364363
grep '^\(mode: .*\)\|\(.*:[0-9]\+\.[0-9]\+,[0-9]\+\.[0-9]\+ [0-9]\+ [0-9]\+\)$$' coverage.out > coverage-bodged.out
365364
grep '^\(mode: .*\)\|\(.*:[0-9]\+\.[0-9]\+,[0-9]\+\.[0-9]\+ [0-9]\+ [0-9]\+\)$$' integration.coverage.out > integration.coverage-bodged.out
366-
GO111MODULE=on $(GO) run build/gocovmerge.go integration.coverage-bodged.out coverage-bodged.out > coverage.all || (echo "gocovmerge failed"; echo "integration.coverage.out"; cat integration.coverage.out; echo "coverage.out"; cat coverage.out; exit 1)
365+
$(GO) run build/gocovmerge.go integration.coverage-bodged.out coverage-bodged.out > coverage.all || (echo "gocovmerge failed"; echo "integration.coverage.out"; cat integration.coverage.out; echo "coverage.out"; cat coverage.out; exit 1)
367366

368367
.PHONY: unit-test-coverage
369368
unit-test-coverage:
@@ -754,11 +753,11 @@ update-translations:
754753

755754
.PHONY: generate-license
756755
generate-license:
757-
GO111MODULE=on $(GO) run build/generate-licenses.go
756+
$(GO) run build/generate-licenses.go
758757

759758
.PHONY: generate-gitignore
760759
generate-gitignore:
761-
GO111MODULE=on $(GO) run build/generate-gitignores.go
760+
$(GO) run build/generate-gitignores.go
762761

763762
.PHONY: generate-images
764763
generate-images: | node_modules

cmd/admin_auth_ldap.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ var (
3434
Name: "not-active",
3535
Usage: "Deactivate the authentication source.",
3636
},
37+
cli.BoolFlag{
38+
Name: "active",
39+
Usage: "Activate the authentication source.",
40+
},
3741
cli.StringFlag{
3842
Name: "security-protocol",
3943
Usage: "Security protocol name.",
@@ -117,6 +121,10 @@ var (
117121
Name: "synchronize-users",
118122
Usage: "Enable user synchronization.",
119123
},
124+
cli.BoolFlag{
125+
Name: "disable-synchronize-users",
126+
Usage: "Disable user synchronization.",
127+
},
120128
cli.UintFlag{
121129
Name: "page-size",
122130
Usage: "Search page size.",
@@ -183,9 +191,15 @@ func parseAuthSource(c *cli.Context, authSource *auth.Source) {
183191
if c.IsSet("not-active") {
184192
authSource.IsActive = !c.Bool("not-active")
185193
}
194+
if c.IsSet("active") {
195+
authSource.IsActive = c.Bool("active")
196+
}
186197
if c.IsSet("synchronize-users") {
187198
authSource.IsSyncEnabled = c.Bool("synchronize-users")
188199
}
200+
if c.IsSet("disable-synchronize-users") {
201+
authSource.IsSyncEnabled = !c.Bool("disable-synchronize-users")
202+
}
189203
}
190204

191205
// parseLdapConfig assigns values on config according to command line flags.

cmd/admin_auth_ldap_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,36 @@ func TestUpdateLdapBindDn(t *testing.T) {
858858
},
859859
errMsg: "Invalid authentication type. expected: LDAP (via BindDN), actual: OAuth2",
860860
},
861+
// case 24
862+
{
863+
args: []string{
864+
"ldap-test",
865+
"--id", "24",
866+
"--name", "ldap (via Bind DN) flip 'active' and 'user sync' attributes",
867+
"--active",
868+
"--disable-synchronize-users",
869+
},
870+
id: 24,
871+
existingAuthSource: &auth.Source{
872+
Type: auth.LDAP,
873+
IsActive: false,
874+
IsSyncEnabled: true,
875+
Cfg: &ldap.Source{
876+
Name: "ldap (via Bind DN) flip 'active' and 'user sync' attributes",
877+
Enabled: true,
878+
},
879+
},
880+
authSource: &auth.Source{
881+
Type: auth.LDAP,
882+
Name: "ldap (via Bind DN) flip 'active' and 'user sync' attributes",
883+
IsActive: true,
884+
IsSyncEnabled: false,
885+
Cfg: &ldap.Source{
886+
Name: "ldap (via Bind DN) flip 'active' and 'user sync' attributes",
887+
Enabled: true,
888+
},
889+
},
890+
},
861891
}
862892

863893
for n, c := range cases {
@@ -1221,6 +1251,33 @@ func TestUpdateLdapSimpleAuth(t *testing.T) {
12211251
},
12221252
errMsg: "Invalid authentication type. expected: LDAP (simple auth), actual: PAM",
12231253
},
1254+
// case 20
1255+
{
1256+
args: []string{
1257+
"ldap-test",
1258+
"--id", "20",
1259+
"--name", "ldap (simple auth) flip 'active' attribute",
1260+
"--active",
1261+
},
1262+
id: 20,
1263+
existingAuthSource: &auth.Source{
1264+
Type: auth.DLDAP,
1265+
IsActive: false,
1266+
Cfg: &ldap.Source{
1267+
Name: "ldap (simple auth) flip 'active' attribute",
1268+
Enabled: true,
1269+
},
1270+
},
1271+
authSource: &auth.Source{
1272+
Type: auth.DLDAP,
1273+
Name: "ldap (simple auth) flip 'active' attribute",
1274+
IsActive: true,
1275+
Cfg: &ldap.Source{
1276+
Name: "ldap (simple auth) flip 'active' attribute",
1277+
Enabled: true,
1278+
},
1279+
},
1280+
},
12241281
}
12251282

12261283
for n, c := range cases {

custom/conf/app.example.ini

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,10 @@ ROUTER = console
603603
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
604604
;;
605605
;; The path of git executable. If empty, Gitea searches through the PATH environment.
606-
PATH =
606+
;PATH =
607+
;;
608+
;; The HOME directory for Git
609+
;HOME_PATH = %(APP_DATA_PATH)/home
607610
;;
608611
;; Disables highlight of added and removed changes
609612
;DISABLE_DIFF_HIGHLIGHT = false
@@ -1231,7 +1234,7 @@ PATH =
12311234
;; Define allowed algorithms and their minimum key length (use -1 to disable a type)
12321235
;ED25519 = 256
12331236
;ECDSA = 256
1234-
;RSA = 2048
1237+
;RSA = 2047 ; we allow 2047 here because an otherwise valid 2048 bit RSA key can be reported as having 2047 bit length
12351238
;DSA = -1 ; set to 1024 to switch on
12361239

12371240
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ Define allowed algorithms and their minimum key length (use -1 to disable a type
621621

622622
- `ED25519`: **256**
623623
- `ECDSA`: **256**
624-
- `RSA`: **2048**
624+
- `RSA`: **2047**: We set 2047 here because an otherwise valid 2048 RSA key can be reported as 2047 length.
625625
- `DSA`: **-1**: DSA is now disabled by default. Set to **1024** to re-enable but ensure you may need to reconfigure your SSHD provider
626626

627627
## Webhook (`webhook`)
@@ -948,6 +948,8 @@ Default templates for project boards:
948948
## Git (`git`)
949949

950950
- `PATH`: **""**: The path of Git executable. If empty, Gitea searches through the PATH environment.
951+
- `HOME_PATH`: **%(APP_DATA_PATH)/home**: The HOME directory for Git.
952+
This directory will be used to contain the `.gitconfig` and possible `.gnupg` directories that Gitea's git calls will use. If you can confirm Gitea is the only application running in this environment, you can set it to the normal home directory for Gitea user.
951953
- `DISABLE_DIFF_HIGHLIGHT`: **false**: Disables highlight of added and removed changes.
952954
- `MAX_GIT_DIFF_LINES`: **1000**: Max number of lines allowed of a single file in diff view.
953955
- `MAX_GIT_DIFF_LINE_CHARACTERS`: **5000**: Max character count per line highlighted in diff view.

docs/content/doc/advanced/signing.en-us.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,11 @@ repositories, `SIGNING_KEY=default` could be used to provide different
9797
signing keys on a per-repository basis. However, this is clearly not an
9898
ideal UI and therefore subject to change.
9999

100-
**Since 1.17**, Gitea runs git in its own home directory `[repository].ROOT` and uses its own config `{[repository].ROOT}/.gitconfig`.
100+
**Since 1.17**, Gitea runs git in its own home directory `[git].HOME_PATH` (default to `%(APP_DATA_PATH)/home`)
101+
and uses its own config `{[git].HOME_PATH}/.gitconfig`.
101102
If you have your own customized git config for Gitea, you should set these configs in system git config (aka `/etc/gitconfig`)
102-
or the Gitea internal git config `{[repository].ROOT}/.gitconfig`.
103-
Related home files for git command (like `.gnupg`) should also be put in Gitea's git home directory `[repository].ROOT`.
103+
or the Gitea internal git config `{[git].HOME_PATH}/.gitconfig`.
104+
Related home files for git command (like `.gnupg`) should also be put in Gitea's git home directory `[git].HOME_PATH`.
104105

105106

106107
### `INITIAL_COMMIT`

integrations/migrate_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
package integrations
66

77
import (
8+
"fmt"
9+
"net/http"
10+
"net/url"
811
"os"
912
"testing"
1013

14+
repo_model "code.gitea.io/gitea/models/repo"
1115
"code.gitea.io/gitea/models/unittest"
1216
user_model "code.gitea.io/gitea/models/user"
1317
"code.gitea.io/gitea/modules/setting"
18+
"code.gitea.io/gitea/modules/structs"
1419
"code.gitea.io/gitea/services/migrations"
1520

1621
"github.com/stretchr/testify/assert"
@@ -40,3 +45,54 @@ func TestMigrateLocalPath(t *testing.T) {
4045

4146
setting.ImportLocalPaths = old
4247
}
48+
49+
func TestMigrateGiteaForm(t *testing.T) {
50+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
51+
AllowLocalNetworks := setting.Migrations.AllowLocalNetworks
52+
setting.Migrations.AllowLocalNetworks = true
53+
AppVer := setting.AppVer
54+
// Gitea SDK (go-sdk) need to parse the AppVer from server response, so we must set it to a valid version string.
55+
setting.AppVer = "1.16.0"
56+
defer func() {
57+
setting.Migrations.AllowLocalNetworks = AllowLocalNetworks
58+
setting.AppVer = AppVer
59+
migrations.Init()
60+
}()
61+
assert.NoError(t, migrations.Init())
62+
63+
ownerName := "user2"
64+
repoName := "repo1"
65+
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: ownerName}).(*user_model.User)
66+
session := loginUser(t, ownerName)
67+
token := getTokenForLoggedInUser(t, session)
68+
69+
// Step 0: verify the repo is available
70+
req := NewRequestf(t, "GET", fmt.Sprintf("/%s/%s", ownerName, repoName))
71+
_ = session.MakeRequest(t, req, http.StatusOK)
72+
// Step 1: get the Gitea migration form
73+
req = NewRequestf(t, "GET", "/repo/migrate/?service_type=%d", structs.GiteaService)
74+
resp := session.MakeRequest(t, req, http.StatusOK)
75+
// Step 2: load the form
76+
htmlDoc := NewHTMLParser(t, resp.Body)
77+
link, exists := htmlDoc.doc.Find(`form.ui.form[action^="/repo/migrate"]`).Attr("action")
78+
assert.True(t, exists, "The template has changed")
79+
// Step 4: submit the migration to only migrate issues
80+
migratedRepoName := "otherrepo"
81+
req = NewRequestWithValues(t, "POST", link, map[string]string{
82+
"_csrf": htmlDoc.GetCSRF(),
83+
"service": fmt.Sprintf("%d", structs.GiteaService),
84+
"clone_addr": fmt.Sprintf("%s%s/%s", u, ownerName, repoName),
85+
"auth_token": token,
86+
"issues": "on",
87+
"repo_name": migratedRepoName,
88+
"description": "",
89+
"uid": fmt.Sprintf("%d", repoOwner.ID),
90+
})
91+
resp = session.MakeRequest(t, req, http.StatusSeeOther)
92+
// Step 5: a redirection displays the migrated repository
93+
loc := resp.Header().Get("Location")
94+
assert.EqualValues(t, fmt.Sprintf("/%s/%s", ownerName, migratedRepoName), loc)
95+
// Step 6: check the repo was created
96+
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: migratedRepoName})
97+
})
98+
}

models/issues/milestone.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ func (opts GetMilestonesOption) toCond() builder.Cond {
361361
}
362362

363363
if len(opts.Name) != 0 {
364-
cond = cond.And(builder.Like{"name", opts.Name})
364+
cond = cond.And(builder.Like{"UPPER(name)", strings.ToUpper(opts.Name)})
365365
}
366366

367367
return cond

models/unittest/testdb.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ func MainTest(m *testing.M, testOpts *TestOptions) {
107107

108108
setting.Packages.Storage.Path = filepath.Join(setting.AppDataPath, "packages")
109109

110+
setting.Git.HomePath = filepath.Join(setting.AppDataPath, "home")
111+
110112
if err = storage.Init(); err != nil {
111113
fatalTestError("storage.Init: %v\n", err)
112114
}

models/user/user.go

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,37 +316,45 @@ func (u *User) GenerateEmailActivateCode(email string) string {
316316
}
317317

318318
// GetUserFollowers returns range of user's followers.
319-
func GetUserFollowers(u *User, listOptions db.ListOptions) ([]*User, error) {
320-
sess := db.GetEngine(db.DefaultContext).
319+
func GetUserFollowers(ctx context.Context, u, viewer *User, listOptions db.ListOptions) ([]*User, int64, error) {
320+
sess := db.GetEngine(ctx).
321+
Select("`user`.*").
322+
Join("LEFT", "follow", "`user`.id=follow.user_id").
321323
Where("follow.follow_id=?", u.ID).
322-
Join("LEFT", "follow", "`user`.id=follow.user_id")
324+
And(isUserVisibleToViewerCond(viewer))
323325

324326
if listOptions.Page != 0 {
325327
sess = db.SetSessionPagination(sess, &listOptions)
326328

327329
users := make([]*User, 0, listOptions.PageSize)
328-
return users, sess.Find(&users)
330+
count, err := sess.FindAndCount(&users)
331+
return users, count, err
329332
}
330333

331334
users := make([]*User, 0, 8)
332-
return users, sess.Find(&users)
335+
count, err := sess.FindAndCount(&users)
336+
return users, count, err
333337
}
334338

335339
// GetUserFollowing returns range of user's following.
336-
func GetUserFollowing(u *User, listOptions db.ListOptions) ([]*User, error) {
340+
func GetUserFollowing(ctx context.Context, u, viewer *User, listOptions db.ListOptions) ([]*User, int64, error) {
337341
sess := db.GetEngine(db.DefaultContext).
342+
Select("`user`.*").
343+
Join("LEFT", "follow", "`user`.id=follow.follow_id").
338344
Where("follow.user_id=?", u.ID).
339-
Join("LEFT", "follow", "`user`.id=follow.follow_id")
345+
And(isUserVisibleToViewerCond(viewer))
340346

341347
if listOptions.Page != 0 {
342348
sess = db.SetSessionPagination(sess, &listOptions)
343349

344350
users := make([]*User, 0, listOptions.PageSize)
345-
return users, sess.Find(&users)
351+
count, err := sess.FindAndCount(&users)
352+
return users, count, err
346353
}
347354

348355
users := make([]*User, 0, 8)
349-
return users, sess.Find(&users)
356+
count, err := sess.FindAndCount(&users)
357+
return users, count, err
350358
}
351359

352360
// NewGitSig generates and returns the signature of given user.
@@ -485,6 +493,9 @@ func (u *User) GitName() string {
485493

486494
// ShortName ellipses username to length
487495
func (u *User) ShortName(length int) string {
496+
if setting.UI.DefaultShowFullName && len(u.FullName) > 0 {
497+
return base.EllipsisString(u.FullName, length)
498+
}
488499
return base.EllipsisString(u.Name, length)
489500
}
490501

@@ -1219,6 +1230,39 @@ func GetAdminUser() (*User, error) {
12191230
return &admin, nil
12201231
}
12211232

1233+
func isUserVisibleToViewerCond(viewer *User) builder.Cond {
1234+
if viewer != nil && viewer.IsAdmin {
1235+
return builder.NewCond()
1236+
}
1237+
1238+
if viewer == nil || viewer.IsRestricted {
1239+
return builder.Eq{
1240+
"`user`.visibility": structs.VisibleTypePublic,
1241+
}
1242+
}
1243+
1244+
return builder.Neq{
1245+
"`user`.visibility": structs.VisibleTypePrivate,
1246+
}.Or(
1247+
builder.In("`user`.id",
1248+
builder.
1249+
Select("`follow`.user_id").
1250+
From("follow").
1251+
Where(builder.Eq{"`follow`.follow_id": viewer.ID})),
1252+
builder.In("`user`.id",
1253+
builder.
1254+
Select("`team_user`.uid").
1255+
From("team_user").
1256+
Join("INNER", "`team_user` AS t2", "`team_user`.id = `t2`.id").
1257+
Where(builder.Eq{"`t2`.uid": viewer.ID})),
1258+
builder.In("`user`.id",
1259+
builder.
1260+
Select("`team_user`.uid").
1261+
From("team_user").
1262+
Join("INNER", "`team_user` AS t2", "`team_user`.org_id = `t2`.org_id").
1263+
Where(builder.Eq{"`t2`.uid": viewer.ID})))
1264+
}
1265+
12221266
// IsUserVisibleToViewer check if viewer is able to see user profile
12231267
func IsUserVisibleToViewer(ctx context.Context, u, viewer *User) bool {
12241268
if viewer != nil && viewer.IsAdmin {

0 commit comments

Comments
 (0)