summaryrefslogtreecommitdiffstats
path: root/models/repo.go
diff options
context:
space:
mode:
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