mirror of
https://github.com/go-gitea/gitea
synced 2025-07-13 22:17:20 +00:00
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:
@ -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
|
||||
|
Reference in New Issue
Block a user