Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
zjjhot committed Dec 13, 2022
2 parents 8cb75e3 + 87c64f6 commit 01d8f70
Show file tree
Hide file tree
Showing 31 changed files with 370 additions and 199 deletions.
2 changes: 1 addition & 1 deletion models/db/iterate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestIterate(t *testing.T) {
return nil
})
assert.NoError(t, err)
assert.EqualValues(t, 79, repoCnt)
assert.EqualValues(t, 80, repoCnt)

err = db.Iterate(db.DefaultContext, nil, func(ctx context.Context, repoUnit *repo_model.RepoUnit) error {
reopUnit2 := repo_model.RepoUnit{ID: repoUnit.ID}
Expand Down
6 changes: 6 additions & 0 deletions models/fixtures/repo_unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -544,3 +544,9 @@
repo_id: 51
type: 2
created_unix: 946684810

-
id: 80
repo_id: 53
type: 1
created_unix: 946684810
27 changes: 27 additions & 0 deletions models/fixtures/repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1558,3 +1558,30 @@
size: 0
is_fsck_enabled: true
close_issues_via_commit_in_any_branch: false

-
id: 53
owner_id: 30
owner_name: user30
lower_name: renderer
name: renderer
is_archived: false
is_empty: false
is_private: false
num_issues: 0
num_closed_issues: 0
num_pulls: 0
num_closed_pulls: 0
num_milestones: 0
num_closed_milestones: 0
num_watches: 0
num_projects: 0
num_closed_projects: 0
status: 0
is_fork: false
fork_id: 0
is_template: false
template_id: 0
size: 0
is_fsck_enabled: true
close_issues_via_commit_in_any_branch: false
2 changes: 1 addition & 1 deletion models/fixtures/user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 3
num_repos: 4
num_teams: 0
num_members: 0
visibility: 0
Expand Down
6 changes: 3 additions & 3 deletions models/repo/repo_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,12 @@ func TestSearchRepository(t *testing.T) {
{
name: "AllPublic/PublicRepositoriesOfUserIncludingCollaborative",
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, AllPublic: true, Template: util.OptionalBoolFalse},
count: 28,
count: 29,
},
{
name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true, Template: util.OptionalBoolFalse},
count: 33,
count: 34,
},
{
name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName",
Expand All @@ -255,7 +255,7 @@ func TestSearchRepository(t *testing.T) {
{
name: "AllPublic/PublicRepositoriesOfOrganization",
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, AllPublic: true, Collaborate: util.OptionalBoolFalse, Template: util.OptionalBoolFalse},
count: 28,
count: 29,
},
{
name: "AllTemplates",
Expand Down
12 changes: 2 additions & 10 deletions modules/web/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
goctx "context"
"fmt"
"net/http"
"reflect"
"strings"

"code.gitea.io/gitea/modules/context"
Expand All @@ -18,16 +17,9 @@ import (
)

// Bind binding an obj to a handler
func Bind(obj interface{}) http.HandlerFunc {
tp := reflect.TypeOf(obj)
if tp.Kind() == reflect.Ptr {
tp = tp.Elem()
}
if tp.Kind() != reflect.Struct {
panic("Only structs are allowed to bind")
}
func Bind[T any](obj T) http.HandlerFunc {
return Wrap(func(ctx *context.Context) {
theObj := reflect.New(tp).Interface() // create a new form obj for every request but not use obj directly
theObj := new(T) // create a new form obj for every request but not use obj directly
binding.Bind(ctx.Req, theObj)
SetForm(ctx, theObj)
middleware.AssignForm(theObj, ctx.Data)
Expand Down
9 changes: 2 additions & 7 deletions routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ import (
gocontext "context"
"fmt"
"net/http"
"reflect"
"strings"

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

// bind binding an obj to a func(ctx *context.APIContext)
func bind(obj interface{}) http.HandlerFunc {
tp := reflect.TypeOf(obj)
for tp.Kind() == reflect.Ptr {
tp = tp.Elem()
}
func bind[T any](obj T) http.HandlerFunc {
return web.Wrap(func(ctx *context.APIContext) {
theObj := reflect.New(tp).Interface() // create a new form obj for every request but not use obj directly
theObj := new(T) // create a new form obj for every request but not use obj directly
errs := binding.Bind(ctx.Req, theObj)
if len(errs) > 0 {
ctx.Error(http.StatusUnprocessableEntity, "validationError", fmt.Sprintf("%s: %s", errs[0].FieldNames, errs[0].Error()))
Expand Down
9 changes: 2 additions & 7 deletions routers/private/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package private

import (
"net/http"
"reflect"
"strings"

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

// bind binding an obj to a handler
func bind(obj interface{}) http.HandlerFunc {
tp := reflect.TypeOf(obj)
for tp.Kind() == reflect.Ptr {
tp = tp.Elem()
}
func bind[T any](obj T) http.HandlerFunc {
return web.Wrap(func(ctx *context.PrivateContext) {
theObj := reflect.New(tp).Interface() // create a new form obj for every request but not use obj directly
theObj := new(T) // create a new form obj for every request but not use obj directly
binding.Bind(ctx.Req, theObj)
web.SetForm(ctx, theObj)
})
Expand Down
9 changes: 9 additions & 0 deletions routers/web/repo/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,15 @@ func SettingsPost(ctx *context.Context) {
repoChanged = true
}

if form.EnableCode && !unit_model.TypeCode.UnitGlobalDisabled() {
units = append(units, repo_model.RepoUnit{
RepoID: repo.ID,
Type: unit_model.TypeCode,
})
} else if !unit_model.TypeCode.UnitGlobalDisabled() {
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeCode)
}

if form.EnableWiki && form.EnableExternalWiki && !unit_model.TypeExternalWiki.UnitGlobalDisabled() {
if !validation.IsValidExternalURL(form.ExternalWikiURL) {
ctx.Flash.Error(ctx.Tr("repo.settings.external_wiki_url_error"))
Expand Down
2 changes: 1 addition & 1 deletion routers/web/user/home_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestArchivedIssues(t *testing.T) {

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

0 comments on commit 01d8f70

Please sign in to comment.