Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Jan 11, 2025
1 parent 83c5adc commit 79a6bab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions services/notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,9 @@ func MigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo
}

// TransferRepository notifies create repository to notifiers
func TransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, newOwnerName string) {
func TransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldOwnerName string) {
for _, notifier := range notifiers {
notifier.TransferRepository(ctx, doer, repo, newOwnerName)
notifier.TransferRepository(ctx, doer, repo, oldOwnerName)
}
}

Expand Down
7 changes: 5 additions & 2 deletions services/repository/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func AcceptTransferOwnership(ctx context.Context, repo *repo_model.Repository, d
return err
}

oldOwnerName := repo.OwnerName

if err := db.WithTx(ctx, func(ctx context.Context) error {
if err := repoTransfer.LoadAttributes(ctx); err != nil {
return err
Expand All @@ -65,7 +67,7 @@ func AcceptTransferOwnership(ctx context.Context, repo *repo_model.Repository, d
}
releaser()

notify_service.TransferRepository(ctx, doer, repo, repoTransfer.Recipient.Name)
notify_service.TransferRepository(ctx, doer, repo, oldOwnerName)

return nil
}
Expand Down Expand Up @@ -397,6 +399,7 @@ func StartRepositoryTransfer(ctx context.Context, doer, newOwner *user_model.Use
}

var isTransfer bool
oldOwnerName := repo.OwnerName

if err := db.WithTx(ctx, func(ctx context.Context) error {
// Admin is always allowed to transfer || user transfer repo back to his account
Expand Down Expand Up @@ -440,7 +443,7 @@ func StartRepositoryTransfer(ctx context.Context, doer, newOwner *user_model.Use
}

if isTransfer {
notify_service.TransferRepository(ctx, doer, repo, newOwner.Name)
notify_service.TransferRepository(ctx, doer, repo, oldOwnerName)
} else {
// notify users who are able to accept / reject transfer
notify_service.RepoPendingTransfer(ctx, doer, newOwner, repo)
Expand Down
13 changes: 8 additions & 5 deletions services/repository/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,26 @@ func TestTransferOwnership(t *testing.T) {

assert.NoError(t, unittest.PrepareTestDatabase())

doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
repo.Owner = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
assert.NoError(t, repo.LoadOwner(db.DefaultContext))
repoTransfer := unittest.AssertExistsAndLoadBean(t, &repo_model.RepoTransfer{ID: 1})
assert.NoError(t, repoTransfer.LoadAttributes(db.DefaultContext))
assert.NoError(t, AcceptTransferOwnership(db.DefaultContext, repo, doer))

transferredRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
assert.EqualValues(t, 2, transferredRepo.OwnerID)
assert.EqualValues(t, 1, transferredRepo.OwnerID) // repo_transfer.yml id=1
unittest.AssertNotExistsBean(t, &repo_model.RepoTransfer{ID: 1})

exist, err := util.IsExist(repo_model.RepoPath("org3", "repo3"))
assert.NoError(t, err)
assert.False(t, exist)
exist, err = util.IsExist(repo_model.RepoPath("user2", "repo3"))
exist, err = util.IsExist(repo_model.RepoPath("user1", "repo3"))
assert.NoError(t, err)
assert.True(t, exist)
unittest.AssertExistsAndLoadBean(t, &activities_model.Action{
OpType: activities_model.ActionTransferRepo,
ActUserID: 2,
ActUserID: 1,
RepoID: 3,
Content: "org3/repo3",
})
Expand Down

0 comments on commit 79a6bab

Please sign in to comment.