Skip to content

Commit 01d8f70

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Fix permission check on issue/pull lock (go-gitea#22110) Add a simple test for external renderer (go-gitea#20033) refactor bind functions based on generics (go-gitea#22055) Allow disable code tab (go-gitea#20805)
2 parents 8cb75e3 + 87c64f6 commit 01d8f70

File tree

31 files changed

+370
-199
lines changed

31 files changed

+370
-199
lines changed

models/db/iterate_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestIterate(t *testing.T) {
2525
return nil
2626
})
2727
assert.NoError(t, err)
28-
assert.EqualValues(t, 79, repoCnt)
28+
assert.EqualValues(t, 80, repoCnt)
2929

3030
err = db.Iterate(db.DefaultContext, nil, func(ctx context.Context, repoUnit *repo_model.RepoUnit) error {
3131
reopUnit2 := repo_model.RepoUnit{ID: repoUnit.ID}

models/fixtures/repo_unit.yml

+6
Original file line numberDiff line numberDiff line change
@@ -544,3 +544,9 @@
544544
repo_id: 51
545545
type: 2
546546
created_unix: 946684810
547+
548+
-
549+
id: 80
550+
repo_id: 53
551+
type: 1
552+
created_unix: 946684810

models/fixtures/repository.yml

+27
Original file line numberDiff line numberDiff line change
@@ -1558,3 +1558,30 @@
15581558
size: 0
15591559
is_fsck_enabled: true
15601560
close_issues_via_commit_in_any_branch: false
1561+
1562+
-
1563+
id: 53
1564+
owner_id: 30
1565+
owner_name: user30
1566+
lower_name: renderer
1567+
name: renderer
1568+
is_archived: false
1569+
is_empty: false
1570+
is_private: false
1571+
num_issues: 0
1572+
num_closed_issues: 0
1573+
num_pulls: 0
1574+
num_closed_pulls: 0
1575+
num_milestones: 0
1576+
num_closed_milestones: 0
1577+
num_watches: 0
1578+
num_projects: 0
1579+
num_closed_projects: 0
1580+
status: 0
1581+
is_fork: false
1582+
fork_id: 0
1583+
is_template: false
1584+
template_id: 0
1585+
size: 0
1586+
is_fsck_enabled: true
1587+
close_issues_via_commit_in_any_branch: false

models/fixtures/user.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@
11021102
num_followers: 0
11031103
num_following: 0
11041104
num_stars: 0
1105-
num_repos: 3
1105+
num_repos: 4
11061106
num_teams: 0
11071107
num_members: 0
11081108
visibility: 0

models/repo/repo_list_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,12 @@ func TestSearchRepository(t *testing.T) {
235235
{
236236
name: "AllPublic/PublicRepositoriesOfUserIncludingCollaborative",
237237
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, AllPublic: true, Template: util.OptionalBoolFalse},
238-
count: 28,
238+
count: 29,
239239
},
240240
{
241241
name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
242242
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true, Template: util.OptionalBoolFalse},
243-
count: 33,
243+
count: 34,
244244
},
245245
{
246246
name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName",
@@ -255,7 +255,7 @@ func TestSearchRepository(t *testing.T) {
255255
{
256256
name: "AllPublic/PublicRepositoriesOfOrganization",
257257
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, AllPublic: true, Collaborate: util.OptionalBoolFalse, Template: util.OptionalBoolFalse},
258-
count: 28,
258+
count: 29,
259259
},
260260
{
261261
name: "AllTemplates",

modules/web/route.go

+2-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
goctx "context"
88
"fmt"
99
"net/http"
10-
"reflect"
1110
"strings"
1211

1312
"code.gitea.io/gitea/modules/context"
@@ -18,16 +17,9 @@ import (
1817
)
1918

2019
// Bind binding an obj to a handler
21-
func Bind(obj interface{}) http.HandlerFunc {
22-
tp := reflect.TypeOf(obj)
23-
if tp.Kind() == reflect.Ptr {
24-
tp = tp.Elem()
25-
}
26-
if tp.Kind() != reflect.Struct {
27-
panic("Only structs are allowed to bind")
28-
}
20+
func Bind[T any](obj T) http.HandlerFunc {
2921
return Wrap(func(ctx *context.Context) {
30-
theObj := reflect.New(tp).Interface() // create a new form obj for every request but not use obj directly
22+
theObj := new(T) // create a new form obj for every request but not use obj directly
3123
binding.Bind(ctx.Req, theObj)
3224
SetForm(ctx, theObj)
3325
middleware.AssignForm(theObj, ctx.Data)

routers/api/v1/api.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ import (
6767
gocontext "context"
6868
"fmt"
6969
"net/http"
70-
"reflect"
7170
"strings"
7271

7372
"code.gitea.io/gitea/models/organization"
@@ -575,13 +574,9 @@ func mustEnableAttachments(ctx *context.APIContext) {
575574
}
576575

577576
// bind binding an obj to a func(ctx *context.APIContext)
578-
func bind(obj interface{}) http.HandlerFunc {
579-
tp := reflect.TypeOf(obj)
580-
for tp.Kind() == reflect.Ptr {
581-
tp = tp.Elem()
582-
}
577+
func bind[T any](obj T) http.HandlerFunc {
583578
return web.Wrap(func(ctx *context.APIContext) {
584-
theObj := reflect.New(tp).Interface() // create a new form obj for every request but not use obj directly
579+
theObj := new(T) // create a new form obj for every request but not use obj directly
585580
errs := binding.Bind(ctx.Req, theObj)
586581
if len(errs) > 0 {
587582
ctx.Error(http.StatusUnprocessableEntity, "validationError", fmt.Sprintf("%s: %s", errs[0].FieldNames, errs[0].Error()))

routers/private/internal.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package private
66

77
import (
88
"net/http"
9-
"reflect"
109
"strings"
1110

1211
"code.gitea.io/gitea/modules/context"
@@ -39,13 +38,9 @@ func CheckInternalToken(next http.Handler) http.Handler {
3938
}
4039

4140
// bind binding an obj to a handler
42-
func bind(obj interface{}) http.HandlerFunc {
43-
tp := reflect.TypeOf(obj)
44-
for tp.Kind() == reflect.Ptr {
45-
tp = tp.Elem()
46-
}
41+
func bind[T any](obj T) http.HandlerFunc {
4742
return web.Wrap(func(ctx *context.PrivateContext) {
48-
theObj := reflect.New(tp).Interface() // create a new form obj for every request but not use obj directly
43+
theObj := new(T) // create a new form obj for every request but not use obj directly
4944
binding.Bind(ctx.Req, theObj)
5045
web.SetForm(ctx, theObj)
5146
})

routers/web/repo/setting.go

+9
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,15 @@ func SettingsPost(ctx *context.Context) {
397397
repoChanged = true
398398
}
399399

400+
if form.EnableCode && !unit_model.TypeCode.UnitGlobalDisabled() {
401+
units = append(units, repo_model.RepoUnit{
402+
RepoID: repo.ID,
403+
Type: unit_model.TypeCode,
404+
})
405+
} else if !unit_model.TypeCode.UnitGlobalDisabled() {
406+
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeCode)
407+
}
408+
400409
if form.EnableWiki && form.EnableExternalWiki && !unit_model.TypeExternalWiki.UnitGlobalDisabled() {
401410
if !validation.IsValidExternalURL(form.ExternalWikiURL) {
402411
ctx.Flash.Error(ctx.Tr("repo.settings.external_wiki_url_error"))

routers/web/user/home_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestArchivedIssues(t *testing.T) {
2626

2727
// Assume: User 30 has access to two Repos with Issues, one of the Repos being archived.
2828
repos, _, _ := repo_model.GetUserRepositories(&repo_model.SearchRepoOptions{Actor: ctx.Doer})
29-
assert.Len(t, repos, 2)
29+
assert.Len(t, repos, 3)
3030
IsArchived := make(map[int64]bool)
3131
NumIssues := make(map[int64]int)
3232
for _, repo := range repos {

0 commit comments

Comments
 (0)