summaryrefslogtreecommitdiffstats
path: root/models/repo.go
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2017-10-15 18:06:07 +0300
committerGitHub <noreply@github.com>2017-10-15 18:06:07 +0300
commit1ec4dc6c1dec3814d8956bcd1157a51bfe53eb0e (patch)
tree742d82bceac48af7f5088be3c70bdb6d000728ea /models/repo.go
parent32ca299650277829b93994eca1508f9d84a5b667 (diff)
downloadgitea-1ec4dc6c1dec3814d8956bcd1157a51bfe53eb0e.tar.gz
gitea-1ec4dc6c1dec3814d8956bcd1157a51bfe53eb0e.zip
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
Diffstat (limited to 'models/repo.go')
-rw-r--r--models/repo.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/models/repo.go b/models/repo.go
index a6817f6514..9819d4b77a 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -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