mirror of https://github.com/go-gitea/gitea.git
Fix: Actor is required to get user repositories (#20443)
Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
0a97480934
commit
3df33799c1
|
@ -6,6 +6,7 @@ package repo
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
|
@ -695,6 +696,9 @@ func GetUserRepositories(opts *SearchRepoOptions) (RepositoryList, int64, error)
|
|||
}
|
||||
|
||||
cond := builder.NewCond()
|
||||
if opts.Actor == nil {
|
||||
return nil, 0, errors.New("GetUserRepositories: Actor is needed but not given")
|
||||
}
|
||||
cond = cond.And(builder.Eq{"owner_id": opts.Actor.ID})
|
||||
if !opts.Private {
|
||||
cond = cond.And(builder.Eq{"is_private": false})
|
||||
|
|
|
@ -75,6 +75,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
|
|||
},
|
||||
Private: true,
|
||||
OwnerID: u.ID,
|
||||
Actor: u,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("SearchRepositoryByName: %v", err)
|
||||
|
|
|
@ -60,6 +60,26 @@ func TestDeleteUser(t *testing.T) {
|
|||
assert.Error(t, DeleteUser(db.DefaultContext, org, false))
|
||||
}
|
||||
|
||||
func TestPurgeUser(t *testing.T) {
|
||||
test := func(userID int64) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID}).(*user_model.User)
|
||||
|
||||
err := DeleteUser(db.DefaultContext, user, true)
|
||||
assert.NoError(t, err)
|
||||
|
||||
unittest.AssertNotExistsBean(t, &user_model.User{ID: userID})
|
||||
unittest.CheckConsistencyFor(t, &user_model.User{}, &repo_model.Repository{})
|
||||
}
|
||||
test(2)
|
||||
test(4)
|
||||
test(8)
|
||||
test(11)
|
||||
|
||||
org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)
|
||||
assert.Error(t, DeleteUser(db.DefaultContext, org, false))
|
||||
}
|
||||
|
||||
func TestCreateUser(t *testing.T) {
|
||||
user := &user_model.User{
|
||||
Name: "GiteaBot",
|
||||
|
|
Loading…
Reference in New Issue