Skip to content

Commit 406829f

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Fix oauth2 error handle not return immediately (go-gitea#32514) Fix incorrect project page CSS class (go-gitea#32510) Add avif image file support (go-gitea#32508) Reduce integration test overhead (go-gitea#32475) Remove jQuery import from some files (go-gitea#32512) Trim title before insert/update to database to match the size requirements of database (go-gitea#32498) Reimplement GetUserOrgsList to make it simple and clear (go-gitea#32486)
2 parents 6332a5e + 4121f95 commit 406829f

File tree

136 files changed

+429
-678
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+429
-678
lines changed

custom/conf/app.example.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,7 @@ LEVEL = Info
19121912
;ENABLED = true
19131913
;;
19141914
;; Comma-separated list of allowed file extensions (`.zip`), mime types (`text/plain`) or wildcard type (`image/*`, `audio/*`, `video/*`). Empty value or `*/*` allows all types.
1915-
;ALLOWED_TYPES = .csv,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.patch,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.xls,.xlsx,.zip
1915+
;ALLOWED_TYPES = .avif,.cpuprofile,.csv,.dmp,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.json,.jsonc,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.patch,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.webp,.xls,.xlsx,.zip
19161916
;;
19171917
;; Max size of each file. Defaults to 2048MB
19181918
;MAX_SIZE = 2048

models/actions/run.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ func CancelPreviousJobs(ctx context.Context, repoID int64, ref, workflowID strin
261261
}
262262

263263
// InsertRun inserts a run
264+
// The title will be cut off at 255 characters if it's longer than 255 characters.
264265
func InsertRun(ctx context.Context, run *ActionRun, jobs []*jobparser.SingleWorkflow) error {
265266
ctx, committer, err := db.TxContext(ctx)
266267
if err != nil {
@@ -273,6 +274,7 @@ func InsertRun(ctx context.Context, run *ActionRun, jobs []*jobparser.SingleWork
273274
return err
274275
}
275276
run.Index = index
277+
run.Title, _ = util.SplitStringAtByteN(run.Title, 255)
276278

277279
if err := db.Insert(ctx, run); err != nil {
278280
return err
@@ -399,6 +401,7 @@ func UpdateRun(ctx context.Context, run *ActionRun, cols ...string) error {
399401
if len(cols) > 0 {
400402
sess.Cols(cols...)
401403
}
404+
run.Title, _ = util.SplitStringAtByteN(run.Title, 255)
402405
affected, err := sess.Update(run)
403406
if err != nil {
404407
return err

models/actions/runner.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ func GetRunnerByID(ctx context.Context, id int64) (*ActionRunner, error) {
252252
// UpdateRunner updates runner's information.
253253
func UpdateRunner(ctx context.Context, r *ActionRunner, cols ...string) error {
254254
e := db.GetEngine(ctx)
255+
r.Name, _ = util.SplitStringAtByteN(r.Name, 255)
255256
var err error
256257
if len(cols) == 0 {
257258
_, err = e.ID(r.ID).AllCols().Update(r)
@@ -278,6 +279,7 @@ func CreateRunner(ctx context.Context, t *ActionRunner) error {
278279
// Remove OwnerID to avoid confusion; it's not worth returning an error here.
279280
t.OwnerID = 0
280281
}
282+
t.Name, _ = util.SplitStringAtByteN(t.Name, 255)
281283
return db.Insert(ctx, t)
282284
}
283285

models/actions/schedule.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
repo_model "code.gitea.io/gitea/models/repo"
1313
user_model "code.gitea.io/gitea/models/user"
1414
"code.gitea.io/gitea/modules/timeutil"
15+
"code.gitea.io/gitea/modules/util"
1516
webhook_module "code.gitea.io/gitea/modules/webhook"
1617
)
1718

@@ -67,6 +68,7 @@ func CreateScheduleTask(ctx context.Context, rows []*ActionSchedule) error {
6768

6869
// Loop through each schedule row
6970
for _, row := range rows {
71+
row.Title, _ = util.SplitStringAtByteN(row.Title, 255)
7072
// Create new schedule row
7173
if err = db.Insert(ctx, row); err != nil {
7274
return err

models/fixtures/repository.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
fork_id: 0
2727
is_template: false
2828
template_id: 0
29-
size: 8478
29+
size: 0
3030
is_fsck_enabled: true
3131
close_issues_via_commit_in_any_branch: false
3232

models/issues/issue_update.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"code.gitea.io/gitea/modules/references"
2222
api "code.gitea.io/gitea/modules/structs"
2323
"code.gitea.io/gitea/modules/timeutil"
24+
"code.gitea.io/gitea/modules/util"
2425

2526
"xorm.io/builder"
2627
)
@@ -138,6 +139,7 @@ func ChangeIssueTitle(ctx context.Context, issue *Issue, doer *user_model.User,
138139
}
139140
defer committer.Close()
140141

142+
issue.Title, _ = util.SplitStringAtByteN(issue.Title, 255)
141143
if err = UpdateIssueCols(ctx, issue, "name"); err != nil {
142144
return fmt.Errorf("updateIssueCols: %w", err)
143145
}
@@ -386,6 +388,7 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue
386388
}
387389

388390
// NewIssue creates new issue with labels for repository.
391+
// The title will be cut off at 255 characters if it's longer than 255 characters.
389392
func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) {
390393
ctx, committer, err := db.TxContext(ctx)
391394
if err != nil {
@@ -399,6 +402,7 @@ func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *Issue, la
399402
}
400403

401404
issue.Index = idx
405+
issue.Title, _ = util.SplitStringAtByteN(issue.Title, 255)
402406

403407
if err = NewIssueWithIndex(ctx, issue.Poster, NewIssueOptions{
404408
Repo: repo,

models/issues/pull.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *Iss
572572
}
573573

574574
issue.Index = idx
575+
issue.Title, _ = util.SplitStringAtByteN(issue.Title, 255)
575576

576577
if err = NewIssueWithIndex(ctx, issue.Poster, NewIssueOptions{
577578
Repo: repo,

models/migrations/base/tests.go

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"context"
99
"fmt"
1010
"os"
11-
"path"
1211
"path/filepath"
1312
"runtime"
1413
"testing"
@@ -35,27 +34,7 @@ func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (*xorm.Engine, fu
3534
ourSkip := 2
3635
ourSkip += skip
3736
deferFn := testlogger.PrintCurrentTest(t, ourSkip)
38-
assert.NoError(t, os.RemoveAll(setting.RepoRootPath))
39-
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath))
40-
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
41-
if err != nil {
42-
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)
43-
}
44-
for _, ownerDir := range ownerDirs {
45-
if !ownerDir.Type().IsDir() {
46-
continue
47-
}
48-
repoDirs, err := os.ReadDir(filepath.Join(setting.RepoRootPath, ownerDir.Name()))
49-
if err != nil {
50-
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)
51-
}
52-
for _, repoDir := range repoDirs {
53-
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "pack"), 0o755)
54-
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "info"), 0o755)
55-
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "heads"), 0o755)
56-
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "tag"), 0o755)
57-
}
58-
}
37+
assert.NoError(t, unittest.SyncDirs(filepath.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath))
5938

6039
if err := deleteDB(); err != nil {
6140
t.Errorf("unable to reset database: %v", err)
@@ -123,20 +102,20 @@ func MainTest(m *testing.M) {
123102
if runtime.GOOS == "windows" {
124103
giteaBinary += ".exe"
125104
}
126-
setting.AppPath = path.Join(giteaRoot, giteaBinary)
105+
setting.AppPath = filepath.Join(giteaRoot, giteaBinary)
127106
if _, err := os.Stat(setting.AppPath); err != nil {
128107
fmt.Printf("Could not find gitea binary at %s\n", setting.AppPath)
129108
os.Exit(1)
130109
}
131110

132111
giteaConf := os.Getenv("GITEA_CONF")
133112
if giteaConf == "" {
134-
giteaConf = path.Join(filepath.Dir(setting.AppPath), "tests/sqlite.ini")
113+
giteaConf = filepath.Join(filepath.Dir(setting.AppPath), "tests/sqlite.ini")
135114
fmt.Printf("Environment variable $GITEA_CONF not set - defaulting to %s\n", giteaConf)
136115
}
137116

138-
if !path.IsAbs(giteaConf) {
139-
setting.CustomConf = path.Join(giteaRoot, giteaConf)
117+
if !filepath.IsAbs(giteaConf) {
118+
setting.CustomConf = filepath.Join(giteaRoot, giteaConf)
140119
} else {
141120
setting.CustomConf = giteaConf
142121
}

models/organization/mini_org.go

Lines changed: 0 additions & 78 deletions
This file was deleted.

models/organization/org.go

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ import (
2525
"xorm.io/xorm"
2626
)
2727

28-
// ________ .__ __ .__
29-
// \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____
30-
// / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \
31-
// / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \
32-
// \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| /
33-
// \/ /_____/ \/ \/ \/ \/ \/
34-
3528
// ErrOrgNotExist represents a "OrgNotExist" kind of error.
3629
type ErrOrgNotExist struct {
3730
ID int64
@@ -465,42 +458,6 @@ func GetUsersWhoCanCreateOrgRepo(ctx context.Context, orgID int64) (map[int64]*u
465458
And("team_user.org_id = ?", orgID).Find(&users)
466459
}
467460

468-
// SearchOrganizationsOptions options to filter organizations
469-
type SearchOrganizationsOptions struct {
470-
db.ListOptions
471-
All bool
472-
}
473-
474-
// FindOrgOptions finds orgs options
475-
type FindOrgOptions struct {
476-
db.ListOptions
477-
UserID int64
478-
IncludePrivate bool
479-
}
480-
481-
func queryUserOrgIDs(userID int64, includePrivate bool) *builder.Builder {
482-
cond := builder.Eq{"uid": userID}
483-
if !includePrivate {
484-
cond["is_public"] = true
485-
}
486-
return builder.Select("org_id").From("org_user").Where(cond)
487-
}
488-
489-
func (opts FindOrgOptions) ToConds() builder.Cond {
490-
var cond builder.Cond = builder.Eq{"`user`.`type`": user_model.UserTypeOrganization}
491-
if opts.UserID > 0 {
492-
cond = cond.And(builder.In("`user`.`id`", queryUserOrgIDs(opts.UserID, opts.IncludePrivate)))
493-
}
494-
if !opts.IncludePrivate {
495-
cond = cond.And(builder.Eq{"`user`.visibility": structs.VisibleTypePublic})
496-
}
497-
return cond
498-
}
499-
500-
func (opts FindOrgOptions) ToOrders() string {
501-
return "`user`.name ASC"
502-
}
503-
504461
// HasOrgOrUserVisible tells if the given user can see the given org or user
505462
func HasOrgOrUserVisible(ctx context.Context, orgOrUser, user *user_model.User) bool {
506463
// If user is nil, it's an anonymous user/request.
@@ -533,20 +490,6 @@ func HasOrgsVisible(ctx context.Context, orgs []*Organization, user *user_model.
533490
return false
534491
}
535492

536-
// GetOrgsCanCreateRepoByUserID returns a list of organizations where given user ID
537-
// are allowed to create repos.
538-
func GetOrgsCanCreateRepoByUserID(ctx context.Context, userID int64) ([]*Organization, error) {
539-
orgs := make([]*Organization, 0, 10)
540-
541-
return orgs, db.GetEngine(ctx).Where(builder.In("id", builder.Select("`user`.id").From("`user`").
542-
Join("INNER", "`team_user`", "`team_user`.org_id = `user`.id").
543-
Join("INNER", "`team`", "`team`.id = `team_user`.team_id").
544-
Where(builder.Eq{"`team_user`.uid": userID}).
545-
And(builder.Eq{"`team`.authorize": perm.AccessModeOwner}.Or(builder.Eq{"`team`.can_create_org_repo": true})))).
546-
Asc("`user`.name").
547-
Find(&orgs)
548-
}
549-
550493
// GetOrgUsersByOrgID returns all organization-user relations by organization ID.
551494
func GetOrgUsersByOrgID(ctx context.Context, opts *FindOrgMembersOpts) ([]*OrgUser, error) {
552495
sess := db.GetEngine(ctx).Where("org_id=?", opts.OrgID)

0 commit comments

Comments
 (0)