Skip to content

Commit 310604f

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Modify milestone search keywords to be case insensitive (go-gitea#20266) Fix toolip on mobile notification bell (go-gitea#20270) Allow RSA 2047 bit keys (go-gitea#20272) Refix notification bell placement (go-gitea#20251) Bump mermaid from 9.1.1 to 9.1.2 (go-gitea#20256) EscapeFilter the group dn membership (go-gitea#20200) Only show Followers that current user can access (go-gitea#20220) Init popup for new code comment (go-gitea#20234) Bypass Firefox (iOS) bug (go-gitea#20244) Adjust max-widths for the repository file table (go-gitea#20243) Display full name (go-gitea#20171) Adjust class for mobile has the problem of double small bells (go-gitea#20236) Adjust template for go-gitea#20069 smallbell (go-gitea#20108) Add integration tests for the Gitea migration form (go-gitea#20121) Allow dev i18n to be more concurrent (go-gitea#20159) Allow enable LDAP source and disable user sync via CLI (go-gitea#20206)
2 parents 4e37ea7 + 970288f commit 310604f

File tree

21 files changed

+439
-129
lines changed

21 files changed

+439
-129
lines changed

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ PATH =
12311231
;; Define allowed algorithms and their minimum key length (use -1 to disable a type)
12321232
;ED25519 = 256
12331233
;ECDSA = 256
1234-
;RSA = 2048
1234+
;RSA = 2047 ; we allow 2047 here because an otherwise valid 2048 bit RSA key can be reported as having 2047 bit length
12351235
;DSA = -1 ; set to 1024 to switch on
12361236

12371237
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

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

Lines changed: 1 addition & 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`)

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/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 {

modules/setting/setting.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ var (
170170
ServerMACs: []string{"[email protected]", "hmac-sha2-256", "hmac-sha1"},
171171
KeygenPath: "ssh-keygen",
172172
MinimumKeySizeCheck: true,
173-
MinimumKeySizes: map[string]int{"ed25519": 256, "ed25519-sk": 256, "ecdsa": 256, "ecdsa-sk": 256, "rsa": 2048},
173+
MinimumKeySizes: map[string]int{"ed25519": 256, "ed25519-sk": 256, "ecdsa": 256, "ecdsa-sk": 256, "rsa": 2047},
174174
ServerHostKeys: []string{"ssh/gitea.rsa", "ssh/gogs.rsa"},
175175
AuthorizedKeysCommandTemplate: "{{.AppPath}} --config={{.CustomConf}} serv key-{{.Key.ID}}",
176176
PerWriteTimeout: PerWriteTimeout,

0 commit comments

Comments
 (0)