Skip to content

fix: Actor is required to get user repositories #20443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions models/repo/repo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package repo

import (
"context"
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -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})
Expand Down
1 change: 1 addition & 0 deletions services/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions services/user/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down