Fix so that user can still fork his own repository to owned organizations (#2699)

* Fix so that user can still fork his own repository to his organizations

* Fix to only use owned organizations

* Add integration test for forking own repository to owned organization
This commit is contained in:
Lauris BH 2017-10-15 18:06:07 +03:00 committed by GitHub
parent 32ca299650
commit 1ec4dc6c1d
8 changed files with 88 additions and 29 deletions

View file

@ -651,6 +651,25 @@ func (repo *Repository) CanBeForked() bool {
return !repo.IsBare && repo.UnitEnabled(UnitTypeCode)
}
// CanUserFork returns true if specified user can fork repository.
func (repo *Repository) CanUserFork(user *User) (bool, error) {
if user == nil {
return false, nil
}
if repo.OwnerID != user.ID && !user.HasForkedRepo(repo.ID) {
return true, nil
}
if err := user.GetOwnedOrganizations(); err != nil {
return false, err
}
for _, org := range user.OwnedOrgs {
if repo.OwnerID != org.ID && !org.HasForkedRepo(repo.ID) {
return true, nil
}
}
return false, nil
}
// CanEnablePulls returns true if repository meets the requirements of accepting pulls.
func (repo *Repository) CanEnablePulls() bool {
return !repo.IsMirror && !repo.IsBare