Push to create repo (#8419)
* Refactor Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add push-create to SSH serv Signed-off-by: jolheiser <john.olheiser@gmail.com> * Cannot push for another user unless admin Signed-off-by: jolheiser <john.olheiser@gmail.com> * Get owner in case admin pushes for another user Signed-off-by: jolheiser <john.olheiser@gmail.com> * Set new repo ID in result Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update to service and use new org perms Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move pushCreateRepo to services Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix import order Signed-off-by: jolheiser <john.olheiser@gmail.com> * Changes for @guillep2k * Check owner (not user) in SSH * Add basic tests for created repos (private, not empty) Signed-off-by: jolheiser <john.olheiser@gmail.com>
This commit is contained in:
parent
47c24be293
commit
6715677b2b
7 changed files with 219 additions and 51 deletions
|
@ -5,6 +5,8 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
|
@ -54,3 +56,28 @@ func DeleteRepository(doer *models.User, repo *models.Repository) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// PushCreateRepo creates a repository when a new repository is pushed to an appropriate namespace
|
||||
func PushCreateRepo(authUser, owner *models.User, repoName string) (*models.Repository, error) {
|
||||
if !authUser.IsAdmin {
|
||||
if owner.IsOrganization() {
|
||||
if ok, err := owner.CanCreateOrgRepo(authUser.ID); err != nil {
|
||||
return nil, err
|
||||
} else if !ok {
|
||||
return nil, fmt.Errorf("cannot push-create repository for org")
|
||||
}
|
||||
} else if authUser.ID != owner.ID {
|
||||
return nil, fmt.Errorf("cannot push-create repository for another user")
|
||||
}
|
||||
}
|
||||
|
||||
repo, err := CreateRepository(authUser, owner, models.CreateRepoOptions{
|
||||
Name: repoName,
|
||||
IsPrivate: true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return repo, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue