From 8196430f47842fba4f227b105cd96d4b981d077d Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 24 Mar 2017 16:25:40 -0400 Subject: repo: allow private repository to have public wiki or issues Relates to #649 and #2157 --- models/repo.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'models') 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) } -- cgit v1.2.3