mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-06 10:24:29 +02:00
Merge branch 'main' into ssh-mirror-migrations
Signed-off-by: pomidorry <106489913+Pomidorry@users.noreply.github.com>
This commit is contained in:
@@ -436,6 +436,12 @@ type GetFeedsOptions struct {
|
||||
DontCount bool // do counting in GetFeeds
|
||||
}
|
||||
|
||||
func (opts *GetFeedsOptions) ApplyPublicOnly(publicOnly bool) {
|
||||
if publicOnly {
|
||||
opts.IncludePrivate = false
|
||||
}
|
||||
}
|
||||
|
||||
// ActivityReadable return whether doer can read activities of user
|
||||
func ActivityReadable(user, doer *user_model.User) bool {
|
||||
return !user.KeepActivityPrivate ||
|
||||
|
||||
@@ -54,6 +54,12 @@ type FindOrgOptions struct {
|
||||
IncludeVisibility structs.VisibleType
|
||||
}
|
||||
|
||||
func (opts *FindOrgOptions) ApplyPublicOnly(publicOnly bool) {
|
||||
if publicOnly {
|
||||
opts.IncludeVisibility = structs.VisibleTypePublic
|
||||
}
|
||||
}
|
||||
|
||||
func queryUserOrgIDs(userID int64, includePrivate bool) *builder.Builder {
|
||||
cond := builder.Eq{"uid": userID}
|
||||
if !includePrivate {
|
||||
|
||||
@@ -5,12 +5,19 @@ package renderhelper
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
)
|
||||
|
||||
func testRenderString(ctx *markup.RenderContext, content string) (string, error) {
|
||||
var buf strings.Builder
|
||||
err := markup.Render(ctx, strings.NewReader(content), &buf)
|
||||
return buf.String(), err
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m, &unittest.TestOptions{
|
||||
FixtureFiles: []string{"repository.yml", "user.yml"},
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
"code.gitea.io/gitea/modules/markup/markdown"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -21,7 +20,7 @@ func TestRepoComment(t *testing.T) {
|
||||
|
||||
t.Run("AutoLink", func(t *testing.T) {
|
||||
rctx := NewRenderContextRepoComment(t.Context(), repo1).WithMarkupType(markdown.MarkupName)
|
||||
rendered, err := markup.RenderString(rctx, `
|
||||
rendered, err := testRenderString(rctx, `
|
||||
65f1bf27bc3bf70f64657658635e66094edbcb4d
|
||||
#1
|
||||
@user2
|
||||
@@ -39,7 +38,7 @@ func TestRepoComment(t *testing.T) {
|
||||
|
||||
// It is Gitea's old behavior, the relative path is resolved to the repo path
|
||||
// It is different from GitHub, GitHub resolves relative links to current page's path
|
||||
rendered, err := markup.RenderString(rctx, `
|
||||
rendered, err := testRenderString(rctx, `
|
||||
[/test](/test)
|
||||
[./test](./test)
|
||||

|
||||
@@ -59,7 +58,7 @@ func TestRepoComment(t *testing.T) {
|
||||
WithMarkupType(markdown.MarkupName)
|
||||
|
||||
// the ref path is only used to render commit message: a commit message is rendered at the commit page with its commit ID path
|
||||
rendered, err := markup.RenderString(rctx, `
|
||||
rendered, err := testRenderString(rctx, `
|
||||
[/test](/test)
|
||||
[./test](./test)
|
||||

|
||||
@@ -75,7 +74,7 @@ func TestRepoComment(t *testing.T) {
|
||||
|
||||
t.Run("NoRepo", func(t *testing.T) {
|
||||
rctx := NewRenderContextRepoComment(t.Context(), nil).WithMarkupType(markdown.MarkupName)
|
||||
rendered, err := markup.RenderString(rctx, "any")
|
||||
rendered, err := testRenderString(rctx, "any")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "<p>any</p>\n", rendered)
|
||||
})
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
"code.gitea.io/gitea/modules/markup/markdown"
|
||||
|
||||
_ "code.gitea.io/gitea/modules/markup/orgmode"
|
||||
@@ -22,7 +21,7 @@ func TestRepoFile(t *testing.T) {
|
||||
|
||||
t.Run("AutoLink", func(t *testing.T) {
|
||||
rctx := NewRenderContextRepoFile(t.Context(), repo1).WithMarkupType(markdown.MarkupName)
|
||||
rendered, err := markup.RenderString(rctx, `
|
||||
rendered, err := testRenderString(rctx, `
|
||||
65f1bf27bc3bf70f64657658635e66094edbcb4d
|
||||
#1
|
||||
@user2
|
||||
@@ -38,7 +37,7 @@ func TestRepoFile(t *testing.T) {
|
||||
t.Run("AbsoluteAndRelative", func(t *testing.T) {
|
||||
rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{CurrentRefSubURL: "branch/main"}).
|
||||
WithMarkupType(markdown.MarkupName)
|
||||
rendered, err := markup.RenderString(rctx, `
|
||||
rendered, err := testRenderString(rctx, `
|
||||
[/test](/test)
|
||||
[./test](./test)
|
||||

|
||||
@@ -56,7 +55,7 @@ func TestRepoFile(t *testing.T) {
|
||||
t.Run("WithCurrentRefSubURL", func(t *testing.T) {
|
||||
rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{CurrentRefSubURL: "/commit/1234"}).
|
||||
WithMarkupType(markdown.MarkupName)
|
||||
rendered, err := markup.RenderString(rctx, `
|
||||
rendered, err := testRenderString(rctx, `
|
||||
[/test](/test)
|
||||

|
||||
`)
|
||||
@@ -72,7 +71,7 @@ func TestRepoFile(t *testing.T) {
|
||||
CurrentTreePath: "my-dir",
|
||||
}).
|
||||
WithMarkupType(markdown.MarkupName)
|
||||
rendered, err := markup.RenderString(rctx, `
|
||||
rendered, err := testRenderString(rctx, `
|
||||
<img src="LINK">
|
||||
<video src="LINK">
|
||||
`)
|
||||
@@ -93,7 +92,7 @@ func TestRepoFileOrgMode(t *testing.T) {
|
||||
CurrentTreePath: "my-dir",
|
||||
}).WithRelativePath("my-dir/a.org")
|
||||
|
||||
rendered, err := markup.RenderString(rctx, `
|
||||
rendered, err := testRenderString(rctx, `
|
||||
[[https://google.com/]]
|
||||
[[ImageLink.svg][The Image Desc]]
|
||||
`)
|
||||
@@ -107,7 +106,7 @@ func TestRepoFileOrgMode(t *testing.T) {
|
||||
t.Run("CodeHighlight", func(t *testing.T) {
|
||||
rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{}).WithRelativePath("my-dir/a.org")
|
||||
|
||||
rendered, err := markup.RenderString(rctx, `
|
||||
rendered, err := testRenderString(rctx, `
|
||||
#+begin_src c
|
||||
int a = 1;
|
||||
#+end_src
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
"code.gitea.io/gitea/modules/markup/markdown"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -20,7 +19,7 @@ func TestRepoWiki(t *testing.T) {
|
||||
|
||||
t.Run("AutoLink", func(t *testing.T) {
|
||||
rctx := NewRenderContextRepoWiki(t.Context(), repo1).WithMarkupType(markdown.MarkupName)
|
||||
rendered, err := markup.RenderString(rctx, `
|
||||
rendered, err := testRenderString(rctx, `
|
||||
65f1bf27bc3bf70f64657658635e66094edbcb4d
|
||||
#1
|
||||
@user2
|
||||
@@ -35,7 +34,7 @@ func TestRepoWiki(t *testing.T) {
|
||||
|
||||
t.Run("AbsoluteAndRelative", func(t *testing.T) {
|
||||
rctx := NewRenderContextRepoWiki(t.Context(), repo1).WithMarkupType(markdown.MarkupName)
|
||||
rendered, err := markup.RenderString(rctx, `
|
||||
rendered, err := testRenderString(rctx, `
|
||||
[/test](/test)
|
||||
[./test](./test)
|
||||

|
||||
@@ -52,7 +51,7 @@ func TestRepoWiki(t *testing.T) {
|
||||
|
||||
t.Run("PathInTag", func(t *testing.T) {
|
||||
rctx := NewRenderContextRepoWiki(t.Context(), repo1).WithMarkupType(markdown.MarkupName)
|
||||
rendered, err := markup.RenderString(rctx, `
|
||||
rendered, err := testRenderString(rctx, `
|
||||
<img src="LINK">
|
||||
<video src="LINK">
|
||||
`)
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
"code.gitea.io/gitea/modules/markup/markdown"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -16,7 +15,7 @@ import (
|
||||
func TestSimpleDocument(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
rctx := NewRenderContextSimpleDocument(t.Context(), "/base").WithMarkupType(markdown.MarkupName)
|
||||
rendered, err := markup.RenderString(rctx, `
|
||||
rendered, err := testRenderString(rctx, `
|
||||
65f1bf27bc3bf70f64657658635e66094edbcb4d
|
||||
#1
|
||||
@user2
|
||||
|
||||
@@ -212,6 +212,13 @@ type SearchRepoOptions struct {
|
||||
OnlyShowRelevant bool
|
||||
}
|
||||
|
||||
func (opts *SearchRepoOptions) ApplyPublicOnly(publicOnly bool) {
|
||||
if publicOnly {
|
||||
opts.Private = false
|
||||
opts.AllLimited = false
|
||||
}
|
||||
}
|
||||
|
||||
// UserOwnedRepoCond returns user ownered repositories
|
||||
func UserOwnedRepoCond(userID int64) builder.Cond {
|
||||
return builder.Eq{
|
||||
|
||||
@@ -24,6 +24,12 @@ type StarredReposOptions struct {
|
||||
IncludePrivate bool
|
||||
}
|
||||
|
||||
func (opts *StarredReposOptions) ApplyPublicOnly(publicOnly bool) {
|
||||
if publicOnly {
|
||||
opts.IncludePrivate = false
|
||||
}
|
||||
}
|
||||
|
||||
func (opts *StarredReposOptions) ToConds() builder.Cond {
|
||||
var cond builder.Cond = builder.Eq{
|
||||
"star.uid": opts.StarrerID,
|
||||
@@ -62,6 +68,12 @@ type WatchedReposOptions struct {
|
||||
IncludePrivate bool
|
||||
}
|
||||
|
||||
func (opts *WatchedReposOptions) ApplyPublicOnly(publicOnly bool) {
|
||||
if publicOnly {
|
||||
opts.IncludePrivate = false
|
||||
}
|
||||
}
|
||||
|
||||
func (opts *WatchedReposOptions) ToConds() builder.Cond {
|
||||
var cond builder.Cond = builder.Eq{
|
||||
"watch.user_id": opts.WatcherID,
|
||||
|
||||
@@ -58,6 +58,12 @@ type SearchUserOptions struct {
|
||||
IncludeReserved bool
|
||||
}
|
||||
|
||||
func (opts *SearchUserOptions) ApplyPublicOnly(publicOnly bool) {
|
||||
if publicOnly {
|
||||
opts.Visible = []structs.VisibleType{structs.VisibleTypePublic}
|
||||
}
|
||||
}
|
||||
|
||||
func (opts *SearchUserOptions) toSearchQueryBase(ctx context.Context) db.Session {
|
||||
var cond builder.Cond
|
||||
cond = builder.In("type", opts.Types)
|
||||
|
||||
Reference in New Issue
Block a user