mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-05-18 17:00:02 +02: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:
parent
32ca299650
commit
1ec4dc6c1d
8 changed files with 88 additions and 29 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue