diff options
author | Unknwon <u@gogs.io> | 2017-03-24 16:25:40 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2017-03-24 16:25:40 -0400 |
commit | 8196430f47842fba4f227b105cd96d4b981d077d (patch) | |
tree | a7301f793cd341564edeb75425c21249b4b39035 /models/repo.go | |
parent | 7a99e56893d00632a18d7aa030028eca28a96e3e (diff) |
repo: allow private repository to have public wiki or issues
Relates to #649 and #2157
Diffstat (limited to 'models/repo.go')
-rw-r--r-- | models/repo.go | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/models/repo.go b/models/repo.go index 16820d4e..0656f83d 100644 --- a/models/repo.go +++ b/models/repo.go @@ -173,9 +173,11 @@ type Repository struct { // Advanced settings EnableWiki bool `xorm:"NOT NULL DEFAULT true"` + AllowPublicWiki bool EnableExternalWiki bool ExternalWikiURL string EnableIssues bool `xorm:"NOT NULL DEFAULT true"` + AllowPublicIssues bool EnableExternalTracker bool ExternalTrackerURL string ExternalTrackerFormat string @@ -253,10 +255,21 @@ func (repo *Repository) LoadAttributes() error { return repo.loadAttributes(x) } -// MustOwner always returns a valid *User object to avoid -// conceptually impossible error handling. -// It creates a fake object that contains error deftail -// when error occurs. +// IsPartialPublic returns true if repository is public or allow public access to wiki or issues. +func (repo *Repository) IsPartialPublic() bool { + return !repo.IsPrivate || repo.AllowPublicWiki || repo.AllowPublicIssues +} + +func (repo *Repository) CanGuestViewWiki() bool { + return repo.IsPartialPublic() && repo.EnableWiki && !repo.EnableExternalWiki && repo.AllowPublicWiki +} + +func (repo *Repository) CanGuestViewIssues() bool { + return repo.IsPartialPublic() && repo.EnableIssues && !repo.EnableExternalTracker && repo.AllowPublicIssues +} + +// MustOwner always returns a valid *User object to avoid conceptually impossible error handling. +// It creates a fake object that contains error deftail when error occurs. func (repo *Repository) MustOwner() *User { return repo.mustOwner(x) } |