mirror of
https://github.com/go-gitea/gitea.git
synced 2025-02-20 11:43:57 +08:00
Merge 6a6de5c66d73123393de46160627e76270a909d2 into 40faa6dc78a5b5730a1609ba39daefddac08aa63
This commit is contained in:
commit
96ab400d68
@ -7,6 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
activities_model "code.gitea.io/gitea/models/activities"
|
activities_model "code.gitea.io/gitea/models/activities"
|
||||||
|
"code.gitea.io/gitea/models/organization"
|
||||||
"code.gitea.io/gitea/models/renderhelper"
|
"code.gitea.io/gitea/models/renderhelper"
|
||||||
"code.gitea.io/gitea/modules/markup/markdown"
|
"code.gitea.io/gitea/modules/markup/markdown"
|
||||||
"code.gitea.io/gitea/services/context"
|
"code.gitea.io/gitea/services/context"
|
||||||
@ -28,12 +29,23 @@ func ShowUserFeedAtom(ctx *context.Context) {
|
|||||||
// showUserFeed show user activity as RSS / Atom feed
|
// showUserFeed show user activity as RSS / Atom feed
|
||||||
func showUserFeed(ctx *context.Context, formatType string) {
|
func showUserFeed(ctx *context.Context, formatType string) {
|
||||||
includePrivate := ctx.IsSigned && (ctx.Doer.IsAdmin || ctx.Doer.ID == ctx.ContextUser.ID)
|
includePrivate := ctx.IsSigned && (ctx.Doer.IsAdmin || ctx.Doer.ID == ctx.ContextUser.ID)
|
||||||
|
isOrganisation := ctx.ContextUser.IsOrganization()
|
||||||
|
if ctx.IsSigned && isOrganisation && !includePrivate {
|
||||||
|
// When feed is requested by a member of the
|
||||||
|
// organization, include the private repo's the member
|
||||||
|
// has access to.
|
||||||
|
isOrgMember, err := organization.IsOrganizationMember(ctx, ctx.ContextUser.ID, ctx.Doer.ID)
|
||||||
|
if err != nil {
|
||||||
|
ctx.ServerError("IsOrganizationMember", err)
|
||||||
|
}
|
||||||
|
includePrivate = isOrgMember
|
||||||
|
}
|
||||||
|
|
||||||
actions, _, err := feed_service.GetFeeds(ctx, activities_model.GetFeedsOptions{
|
actions, _, err := feed_service.GetFeeds(ctx, activities_model.GetFeedsOptions{
|
||||||
RequestedUser: ctx.ContextUser,
|
RequestedUser: ctx.ContextUser,
|
||||||
Actor: ctx.Doer,
|
Actor: ctx.Doer,
|
||||||
IncludePrivate: includePrivate,
|
IncludePrivate: includePrivate,
|
||||||
OnlyPerformedBy: !ctx.ContextUser.IsOrganization(),
|
OnlyPerformedBy: !isOrganisation,
|
||||||
IncludeDeleted: false,
|
IncludeDeleted: false,
|
||||||
Date: ctx.FormString("date"),
|
Date: ctx.FormString("date"),
|
||||||
})
|
})
|
||||||
|
37
routers/web/feed/profile_test.go
Normal file
37
routers/web/feed/profile_test.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package feed_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/models/unittest"
|
||||||
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
"code.gitea.io/gitea/routers/web/feed"
|
||||||
|
"code.gitea.io/gitea/services/contexttest"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
unittest.MainTest(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCheckGetOrgFeedsAsOrgMember(t *testing.T) {
|
||||||
|
unittest.PrepareTestEnv(t)
|
||||||
|
ctx, resp := contexttest.MockContext(t, "org3.atom")
|
||||||
|
ctx.ContextUser = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3})
|
||||||
|
contexttest.LoadUser(t, ctx, 2)
|
||||||
|
ctx.IsSigned = true
|
||||||
|
|
||||||
|
feed.ShowUserFeedAtom(ctx)
|
||||||
|
assert.Contains(t, resp.Body.String(), "<entry>") // Should contain 1 private entry
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCheckGetOrgFeedsAsNonOrgMember(t *testing.T) {
|
||||||
|
unittest.PrepareTestEnv(t)
|
||||||
|
ctx, resp := contexttest.MockContext(t, "org3.atom")
|
||||||
|
ctx.ContextUser = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3})
|
||||||
|
contexttest.LoadUser(t, ctx, 5)
|
||||||
|
ctx.IsSigned = true
|
||||||
|
|
||||||
|
feed.ShowUserFeedAtom(ctx)
|
||||||
|
assert.NotContains(t, resp.Body.String(), "<entry>") // Should not contain any entries
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user