mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-17 11:59:30 +00:00
fix: show membership of limited orgs (#8094)
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8094 Reviewed-by: Otto <otto@codeberg.org>
This commit is contained in:
commit
e0bfacac0b
4 changed files with 29 additions and 3 deletions
5
models/organization/TestFindOrgs/org_user.yml
Normal file
5
models/organization/TestFindOrgs/org_user.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
-
|
||||
id: 1000
|
||||
uid: 4
|
||||
org_id: 22
|
||||
is_public: true
|
|
@ -26,6 +26,7 @@ type SearchOrganizationsOptions struct {
|
|||
type FindOrgOptions struct {
|
||||
db.ListOptions
|
||||
UserID int64
|
||||
IncludeLimited bool
|
||||
IncludePrivate bool
|
||||
}
|
||||
|
||||
|
@ -43,7 +44,11 @@ func (opts FindOrgOptions) ToConds() builder.Cond {
|
|||
cond = cond.And(builder.In("`user`.`id`", queryUserOrgIDs(opts.UserID, opts.IncludePrivate)))
|
||||
}
|
||||
if !opts.IncludePrivate {
|
||||
if !opts.IncludeLimited {
|
||||
cond = cond.And(builder.Eq{"`user`.visibility": structs.VisibleTypePublic})
|
||||
} else {
|
||||
cond = cond.And(builder.In("`user`.visibility", structs.VisibleTypePublic, structs.VisibleTypeLimited))
|
||||
}
|
||||
}
|
||||
return cond
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ func TestCountOrganizations(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFindOrgs(t *testing.T) {
|
||||
defer unittest.OverrideFixtures("models/organization/TestFindOrgs")()
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
orgs, err := db.Find[organization.Organization](db.DefaultContext, organization.FindOrgOptions{
|
||||
|
@ -34,8 +35,14 @@ func TestFindOrgs(t *testing.T) {
|
|||
IncludePrivate: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
if assert.Len(t, orgs, 1) {
|
||||
if assert.Len(t, orgs, 2) {
|
||||
if orgs[0].ID == 22 {
|
||||
assert.EqualValues(t, 22, orgs[0].ID)
|
||||
assert.EqualValues(t, 3, orgs[1].ID)
|
||||
} else {
|
||||
assert.EqualValues(t, 3, orgs[0].ID)
|
||||
assert.EqualValues(t, 22, orgs[1].ID)
|
||||
}
|
||||
}
|
||||
|
||||
orgs, err = db.Find[organization.Organization](db.DefaultContext, organization.FindOrgOptions{
|
||||
|
@ -50,6 +57,14 @@ func TestFindOrgs(t *testing.T) {
|
|||
IncludePrivate: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.EqualValues(t, 2, total)
|
||||
|
||||
total, err = db.Count[organization.Organization](db.DefaultContext, organization.FindOrgOptions{
|
||||
UserID: 4,
|
||||
IncludePrivate: false,
|
||||
IncludeLimited: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.EqualValues(t, 1, total)
|
||||
}
|
||||
|
||||
|
|
|
@ -67,6 +67,7 @@ func PrepareContextForProfileBigAvatar(ctx *context.Context) {
|
|||
showPrivate := ctx.IsSigned && (ctx.Doer.IsAdmin || ctx.Doer.ID == ctx.ContextUser.ID)
|
||||
orgs, err := db.Find[organization.Organization](ctx, organization.FindOrgOptions{
|
||||
UserID: ctx.ContextUser.ID,
|
||||
IncludeLimited: ctx.IsSigned,
|
||||
IncludePrivate: showPrivate,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue