Skip to content

Commit 57e3902

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Remove unnecessary code (go-gitea#24610) Fix commits pushed with deploy keys not shown in dashboard (go-gitea#24521) fix: release page for empty or non-existing target (go-gitea#24470) Filter get single commit (go-gitea#24613) Attach a tooltip to the action status icon (go-gitea#24614) Use official Vue extension in Gitpod (go-gitea#24609) Create a branch directly from commit on the create branch API (go-gitea#22956) Make repository response support HTTP range request (go-gitea#24592)
2 parents 2090e93 + c355728 commit 57e3902

File tree

35 files changed

+691
-286
lines changed

35 files changed

+691
-286
lines changed

.gitpod.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ vscode:
3131
- golang.go
3232
- stylelint.vscode-stylelint
3333
- DavidAnson.vscode-markdownlint
34-
- johnsoncodehk.volar
34+
- Vue.volar
3535
- ms-azuretools.vscode-docker
3636
- zixuanchen.vitest-explorer
3737
- alexcvzz.vscode-sqlite

models/activities/action.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,27 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
494494
).From("`user`"),
495495
))
496496
} else if !opts.Actor.IsAdmin {
497-
cond = cond.And(builder.In("act_user_id",
498-
builder.Select("`user`.id").Where(
499-
builder.Eq{"keep_activity_private": false}.
500-
And(builder.In("visibility", structs.VisibleTypePublic, structs.VisibleTypeLimited))).
501-
Or(builder.Eq{"id": opts.Actor.ID}).From("`user`"),
502-
))
497+
uidCond := builder.Select("`user`.id").From("`user`").Where(
498+
builder.Eq{"keep_activity_private": false}.
499+
And(builder.In("visibility", structs.VisibleTypePublic, structs.VisibleTypeLimited))).
500+
Or(builder.Eq{"id": opts.Actor.ID})
501+
502+
if opts.RequestedUser != nil {
503+
if opts.RequestedUser.IsOrganization() {
504+
// An organization can always see the activities whose `act_user_id` is the same as its id.
505+
uidCond = uidCond.Or(builder.Eq{"id": opts.RequestedUser.ID})
506+
} else {
507+
// A user can always see the activities of the organizations to which the user belongs.
508+
uidCond = uidCond.Or(
509+
builder.Eq{"type": user_model.UserTypeOrganization}.
510+
And(builder.In("`user`.id", builder.Select("org_id").
511+
Where(builder.Eq{"uid": opts.RequestedUser.ID}).
512+
From("team_user"))),
513+
)
514+
}
515+
}
516+
517+
cond = cond.And(builder.In("act_user_id", uidCond))
503518
}
504519

505520
// check readable repositories by doer/actor

models/fixtures/release.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,31 @@
108108
is_prerelease: false
109109
is_tag: false
110110
created_unix: 946684803
111+
112+
- id: 9
113+
repo_id: 57
114+
publisher_id: 2
115+
tag_name: "non-existing-target-branch"
116+
lower_tag_name: "non-existing-target-branch"
117+
target: "non-existing"
118+
title: "non-existing-target-branch"
119+
sha1: "cef06e48f2642cd0dc9597b4bea09f4b3f74aad6"
120+
num_commits: 5
121+
is_draft: false
122+
is_prerelease: false
123+
is_tag: false
124+
created_unix: 946684803
125+
126+
- id: 10
127+
repo_id: 57
128+
publisher_id: 2
129+
tag_name: "empty-target-branch"
130+
lower_tag_name: "empty-target-branch"
131+
target: ""
132+
title: "empty-target-branch"
133+
sha1: "cef06e48f2642cd0dc9597b4bea09f4b3f74aad6"
134+
num_commits: 5
135+
is_draft: false
136+
is_prerelease: false
137+
is_tag: false
138+
created_unix: 946684803

models/repo/release.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type Release struct {
7272
OriginalAuthorID int64 `xorm:"index"`
7373
LowerTagName string
7474
Target string
75+
TargetBehind string `xorm:"-"` // to handle non-existing or empty target
7576
Title string
7677
Sha1 string `xorm:"VARCHAR(40)"`
7778
NumCommits int64

modules/context/context_serve.go

Lines changed: 5 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,71 +4,20 @@
44
package context
55

66
import (
7-
"fmt"
87
"io"
98
"net/http"
10-
"net/url"
11-
"strconv"
12-
"strings"
13-
"time"
149

15-
"code.gitea.io/gitea/modules/httpcache"
16-
"code.gitea.io/gitea/modules/typesniffer"
10+
"code.gitea.io/gitea/modules/httplib"
1711
)
1812

19-
type ServeHeaderOptions struct {
20-
ContentType string // defaults to "application/octet-stream"
21-
ContentTypeCharset string
22-
ContentLength *int64
23-
Disposition string // defaults to "attachment"
24-
Filename string
25-
CacheDuration time.Duration // defaults to 5 minutes
26-
LastModified time.Time
27-
}
28-
29-
// SetServeHeaders sets necessary content serve headers
30-
func (ctx *Context) SetServeHeaders(opts *ServeHeaderOptions) {
31-
header := ctx.Resp.Header()
32-
33-
contentType := typesniffer.ApplicationOctetStream
34-
if opts.ContentType != "" {
35-
if opts.ContentTypeCharset != "" {
36-
contentType = opts.ContentType + "; charset=" + strings.ToLower(opts.ContentTypeCharset)
37-
} else {
38-
contentType = opts.ContentType
39-
}
40-
}
41-
header.Set("Content-Type", contentType)
42-
header.Set("X-Content-Type-Options", "nosniff")
43-
44-
if opts.ContentLength != nil {
45-
header.Set("Content-Length", strconv.FormatInt(*opts.ContentLength, 10))
46-
}
47-
48-
if opts.Filename != "" {
49-
disposition := opts.Disposition
50-
if disposition == "" {
51-
disposition = "attachment"
52-
}
53-
54-
backslashEscapedName := strings.ReplaceAll(strings.ReplaceAll(opts.Filename, `\`, `\\`), `"`, `\"`) // \ -> \\, " -> \"
55-
header.Set("Content-Disposition", fmt.Sprintf(`%s; filename="%s"; filename*=UTF-8''%s`, disposition, backslashEscapedName, url.PathEscape(opts.Filename)))
56-
header.Set("Access-Control-Expose-Headers", "Content-Disposition")
57-
}
58-
59-
duration := opts.CacheDuration
60-
if duration == 0 {
61-
duration = 5 * time.Minute
62-
}
63-
httpcache.SetCacheControlInHeader(header, duration)
13+
type ServeHeaderOptions httplib.ServeHeaderOptions
6414

65-
if !opts.LastModified.IsZero() {
66-
header.Set("Last-Modified", opts.LastModified.UTC().Format(http.TimeFormat))
67-
}
15+
func (ctx *Context) SetServeHeaders(opt *ServeHeaderOptions) {
16+
httplib.ServeSetHeaders(ctx.Resp, (*httplib.ServeHeaderOptions)(opt))
6817
}
6918

7019
// ServeContent serves content to http request
7120
func (ctx *Context) ServeContent(r io.ReadSeeker, opts *ServeHeaderOptions) {
72-
ctx.SetServeHeaders(opts)
21+
httplib.ServeSetHeaders(ctx.Resp, (*httplib.ServeHeaderOptions)(opts))
7322
http.ServeContent(ctx.Resp, ctx.Req, opts.Filename, opts.LastModified, r)
7423
}

modules/context/context_test.go

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,16 @@ import (
77
"net/http"
88
"testing"
99

10+
"code.gitea.io/gitea/modules/httplib"
1011
"code.gitea.io/gitea/modules/setting"
1112

1213
"github.com/stretchr/testify/assert"
1314
)
1415

15-
type mockResponseWriter struct {
16-
header http.Header
17-
}
18-
19-
func (m *mockResponseWriter) Header() http.Header {
20-
return m.header
21-
}
22-
23-
func (m *mockResponseWriter) Write(bytes []byte) (int, error) {
24-
panic("implement me")
25-
}
26-
27-
func (m *mockResponseWriter) WriteHeader(statusCode int) {
28-
panic("implement me")
29-
}
30-
3116
func TestRemoveSessionCookieHeader(t *testing.T) {
32-
w := &mockResponseWriter{}
33-
w.header = http.Header{}
34-
w.header.Add("Set-Cookie", (&http.Cookie{Name: setting.SessionConfig.CookieName, Value: "foo"}).String())
35-
w.header.Add("Set-Cookie", (&http.Cookie{Name: "other", Value: "bar"}).String())
17+
w := httplib.NewMockResponseWriter()
18+
w.Header().Add("Set-Cookie", (&http.Cookie{Name: setting.SessionConfig.CookieName, Value: "foo"}).String())
19+
w.Header().Add("Set-Cookie", (&http.Cookie{Name: "other", Value: "bar"}).String())
3620
assert.Len(t, w.Header().Values("Set-Cookie"), 2)
3721
removeSessionCookieHeader(w)
3822
assert.Len(t, w.Header().Values("Set-Cookie"), 1)

modules/httplib/mock.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package httplib
5+
6+
import (
7+
"bytes"
8+
"net/http"
9+
)
10+
11+
type MockResponseWriter struct {
12+
header http.Header
13+
14+
StatusCode int
15+
BodyBuffer bytes.Buffer
16+
}
17+
18+
func (m *MockResponseWriter) Header() http.Header {
19+
return m.header
20+
}
21+
22+
func (m *MockResponseWriter) Write(bytes []byte) (int, error) {
23+
if m.StatusCode == 0 {
24+
m.StatusCode = http.StatusOK
25+
}
26+
return m.BodyBuffer.Write(bytes)
27+
}
28+
29+
func (m *MockResponseWriter) WriteHeader(statusCode int) {
30+
m.StatusCode = statusCode
31+
}
32+
33+
func NewMockResponseWriter() *MockResponseWriter {
34+
return &MockResponseWriter{header: http.Header{}}
35+
}
File renamed without changes.

0 commit comments

Comments
 (0)