Skip to content

Commit 9a7a780

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Send 404 on `/{org}.gpg` (go-gitea#18959) Accounts with WebAuthn only (no TOTP) now exist ... fix code to handle that case (go-gitea#18897) Fix lfs management setting (go-gitea#18946) Fix admin user list pagination (go-gitea#18957)
2 parents 20bb80b + a90041d commit 9a7a780

File tree

6 files changed

+68
-21
lines changed

6 files changed

+68
-21
lines changed

models/user/list.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,19 @@ func (users UserList) GetTwoFaStatus() map[int64]bool {
3030
for _, user := range users {
3131
results[user.ID] = false // Set default to false
3232
}
33-
tokenMaps, err := users.loadTwoFactorStatus(db.GetEngine(db.DefaultContext))
34-
if err == nil {
33+
34+
if tokenMaps, err := users.loadTwoFactorStatus(db.GetEngine(db.DefaultContext)); err == nil {
3535
for _, token := range tokenMaps {
3636
results[token.UID] = true
3737
}
3838
}
3939

40+
if ids, err := users.userIDsWithWebAuthn(db.GetEngine(db.DefaultContext)); err == nil {
41+
for _, id := range ids {
42+
results[id] = true
43+
}
44+
}
45+
4046
return results
4147
}
4248

@@ -47,15 +53,23 @@ func (users UserList) loadTwoFactorStatus(e db.Engine) (map[int64]*auth.TwoFacto
4753

4854
userIDs := users.GetUserIDs()
4955
tokenMaps := make(map[int64]*auth.TwoFactor, len(userIDs))
50-
err := e.
51-
In("uid", userIDs).
52-
Find(&tokenMaps)
53-
if err != nil {
56+
if err := e.In("uid", userIDs).Find(&tokenMaps); err != nil {
5457
return nil, fmt.Errorf("find two factor: %v", err)
5558
}
5659
return tokenMaps, nil
5760
}
5861

62+
func (users UserList) userIDsWithWebAuthn(e db.Engine) ([]int64, error) {
63+
if len(users) == 0 {
64+
return nil, nil
65+
}
66+
ids := make([]int64, 0, len(users))
67+
if err := e.Table(new(auth.WebAuthnCredential)).In("user_id", users.GetUserIDs()).Select("user_id").Distinct("user_id").Find(&ids); err != nil {
68+
return nil, fmt.Errorf("find two factor: %v", err)
69+
}
70+
return ids, nil
71+
}
72+
5973
// GetUsersByIDs returns all resolved users from a list of Ids.
6074
func GetUsersByIDs(ids []int64) (UserList, error) {
6175
ous := make([]*User, 0, len(ids))

modules/context/pagination.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,12 @@ func (p *Pagination) SetDefaultParams(ctx *Context) {
5555
p.AddParam(ctx, "tab", "TabName")
5656
p.AddParam(ctx, "t", "queryType")
5757
}
58+
59+
// SetUserFilterParams sets common pagination params for user filtering, e.g. the admin userlist
60+
func (p *Pagination) SetUserFilterParams(ctx *Context) {
61+
p.AddParamString("status_filter[is_active]", ctx.FormString("status_filter[is_active]"))
62+
p.AddParamString("status_filter[is_admin]", ctx.FormString("status_filter[is_admin]"))
63+
p.AddParamString("status_filter[is_restricted]", ctx.FormString("status_filter[is_restricted]"))
64+
p.AddParamString("status_filter[is_2fa_enabled]", ctx.FormString("status_filter[is_2fa_enabled]"))
65+
p.AddParamString("status_filter[is_prohibit_login]", ctx.FormString("status_filter[is_prohibit_login]"))
66+
}

routers/web/admin/users.go

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,17 @@ func prepareUserInfo(ctx *context.Context) *user_model.User {
217217
}
218218
ctx.Data["Sources"] = sources
219219

220-
ctx.Data["TwoFactorEnabled"] = true
221-
_, err = auth.GetTwoFactorByUID(u.ID)
220+
hasTOTP, err := auth.HasTwoFactorByUID(u.ID)
222221
if err != nil {
223-
if !auth.IsErrTwoFactorNotEnrolled(err) {
224-
ctx.ServerError("IsErrTwoFactorNotEnrolled", err)
225-
return nil
226-
}
227-
ctx.Data["TwoFactorEnabled"] = false
222+
ctx.ServerError("auth.HasTwoFactorByUID", err)
223+
return nil
224+
}
225+
hasWebAuthn, err := auth.HasWebAuthnRegistrationsByUID(u.ID)
226+
if err != nil {
227+
ctx.ServerError("auth.HasWebAuthnRegistrationsByUID", err)
228+
return nil
228229
}
230+
ctx.Data["TwoFactorEnabled"] = hasTOTP || hasWebAuthn
229231

230232
return u
231233
}
@@ -327,14 +329,27 @@ func EditUserPost(ctx *context.Context) {
327329
if form.Reset2FA {
328330
tf, err := auth.GetTwoFactorByUID(u.ID)
329331
if err != nil && !auth.IsErrTwoFactorNotEnrolled(err) {
330-
ctx.ServerError("GetTwoFactorByUID", err)
332+
ctx.ServerError("auth.GetTwoFactorByUID", err)
331333
return
334+
} else if tf != nil {
335+
if err := auth.DeleteTwoFactorByID(tf.ID, u.ID); err != nil {
336+
ctx.ServerError("auth.DeleteTwoFactorByID", err)
337+
return
338+
}
332339
}
333340

334-
if err = auth.DeleteTwoFactorByID(tf.ID, u.ID); err != nil {
335-
ctx.ServerError("DeleteTwoFactorByID", err)
341+
wn, err := auth.GetWebAuthnCredentialsByUID(u.ID)
342+
if err != nil {
343+
ctx.ServerError("auth.GetTwoFactorByUID", err)
336344
return
337345
}
346+
for _, cred := range wn {
347+
if _, err := auth.DeleteCredential(cred.ID, u.ID); err != nil {
348+
ctx.ServerError("auth.DeleteCredential", err)
349+
return
350+
}
351+
}
352+
338353
}
339354

340355
u.LoginName = form.LoginName

routers/web/explore/user.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions,
8282

8383
pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5)
8484
pager.SetDefaultParams(ctx)
85+
pager.SetUserFilterParams(ctx)
8586
ctx.Data["Page"] = pager
8687

8788
ctx.HTML(http.StatusOK, tplName)

routers/web/org/home.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package org
66

77
import (
88
"net/http"
9+
"strings"
910

1011
"code.gitea.io/gitea/models"
1112
"code.gitea.io/gitea/models/db"
@@ -23,7 +24,14 @@ const (
2324

2425
// Home show organization home page
2526
func Home(ctx *context.Context) {
26-
ctx.SetParams(":org", ctx.Params(":username"))
27+
uname := ctx.Params(":username")
28+
29+
if strings.HasSuffix(uname, ".keys") || strings.HasSuffix(uname, ".gpg") {
30+
ctx.NotFound("", nil)
31+
return
32+
}
33+
34+
ctx.SetParams(":org", uname)
2735
context.HandleOrgAssignment(ctx)
2836
if ctx.Written() {
2937
return

templates/repo/settings/lfs_locks.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<td>
2525
{{if index $.Linkable $index}}
2626
{{svg "octicon-file"}}
27-
<a href="{{$.RepoLink}}/src/branch/{{PathEscapeSegments $lock.Repo.DefaultBranch}}/{{PathEscapeSegments $lock.Path}}" title="{{$lock.Path}}">{{$lock.Path}}</a>
27+
<a href="{{$.RepoLink}}/src/branch/{{PathEscapeSegments $.Repository.DefaultBranch}}/{{PathEscapeSegments $lock.Path}}" title="{{$lock.Path}}">{{$lock.Path}}</a>
2828
{{else}}
2929
{{svg "octicon-diff"}}
3030
<span class="tooltip" title="{{$.i18n.Tr "repo.settings.lfs_lock_file_no_exist"}}">{{$lock.Path}}</span>
@@ -34,9 +34,9 @@
3434
{{end}}
3535
</td>
3636
<td>
37-
<a href="{{$lock.Owner.HomeLink}}">
38-
{{avatar $lock.Owner}}
39-
{{$lock.Owner.DisplayName}}
37+
<a href="{{$.Owner.HomeLink}}">
38+
{{avatar $.Owner}}
39+
{{$.Owner.DisplayName}}
4040
</a>
4141
</td>
4242
<td>{{TimeSince .Created $.i18n.Lang}}</td>

0 commit comments

Comments
 (0)