summaryrefslogtreecommitdiffstats
path: root/services/repository
diff options
context:
space:
mode:
authorNils Dralle <nils.91@googlemail.com>2021-06-14 20:30:35 +0200
committerGitHub <noreply@github.com>2021-06-14 14:30:35 -0400
commitf374789fe22b6fdb83e727c7c0b0a344ccb98c36 (patch)
tree1c79652104e4f8a108c49cd806e21e30e7a26d29 /services/repository
parent440039c0cce18622b12da5677bf6585caed6070a (diff)
downloadgitea-f374789fe22b6fdb83e727c7c0b0a344ccb98c36.tar.gz
gitea-f374789fe22b6fdb83e727c7c0b0a344ccb98c36.zip
Fix private repo permission problem (#16142)
* Change user access permission * Add string 'transfer_notices_3' * Add 3rd transfer note to transfer dialog * Add test Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'services/repository')
-rw-r--r--services/repository/transfer.go14
-rw-r--r--services/repository/transfer_test.go21
2 files changed, 35 insertions, 0 deletions
diff --git a/services/repository/transfer.go b/services/repository/transfer.go
index ec769190bd..bb323c1c0a 100644
--- a/services/repository/transfer.go
+++ b/services/repository/transfer.go
@@ -94,6 +94,20 @@ func StartRepositoryTransfer(doer, newOwner *models.User, repo *models.Repositor
}
}
+ // In case the new owner would not have sufficient access to the repo, give access rights for read
+ hasAccess, err := models.HasAccess(newOwner.ID, repo)
+ if err != nil {
+ return err
+ }
+ if !hasAccess {
+ if err := repo.AddCollaborator(newOwner); err != nil {
+ return err
+ }
+ if err := repo.ChangeCollaborationAccessMode(newOwner.ID, models.AccessModeRead); err != nil {
+ return err
+ }
+ }
+
// Make repo as pending for transfer
repo.Status = models.RepositoryPendingTransfer
if err := models.CreatePendingRepositoryTransfer(doer, newOwner, repo.ID, teams); err != nil {
diff --git a/services/repository/transfer_test.go b/services/repository/transfer_test.go
index 052b8c9954..c92844674c 100644
--- a/services/repository/transfer_test.go
+++ b/services/repository/transfer_test.go
@@ -52,3 +52,24 @@ func TestTransferOwnership(t *testing.T) {
models.CheckConsistencyFor(t, &models.Repository{}, &models.User{}, &models.Team{})
}
+
+func TestStartRepositoryTransferSetPermission(t *testing.T) {
+ assert.NoError(t, models.PrepareTestDatabase())
+
+ doer := models.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)
+ recipient := models.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
+ repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
+ repo.Owner = models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+
+ hasAccess, err := models.HasAccess(recipient.ID, repo)
+ assert.NoError(t, err)
+ assert.False(t, hasAccess)
+
+ assert.NoError(t, StartRepositoryTransfer(doer, recipient, repo, nil))
+
+ hasAccess, err = models.HasAccess(recipient.ID, repo)
+ assert.NoError(t, err)
+ assert.True(t, hasAccess)
+
+ models.CheckConsistencyFor(t, &models.Repository{}, &models.User{}, &models.Team{})
+}