From 92bf9539fccba3edb7875174edf184e04388a445 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Tue, 12 Mar 2019 15:38:14 +0100 Subject: [PATCH] Allow setting wiki writeable for all users on an instance --- models/repo_permission.go | 13 +++++++++++++ models/repo_unit.go | 11 ++++++----- options/locale/locale_en-US.ini | 1 + routers/web/repo/setting.go | 7 ++++--- services/forms/repo_form.go | 1 + templates/repo/settings/options.tmpl | 14 ++++++++++++-- 6 files changed, 37 insertions(+), 10 deletions(-) diff --git a/models/repo_permission.go b/models/repo_permission.go index f5138fc54ce49..3cf6fcaeebe33 100644 --- a/models/repo_permission.go +++ b/models/repo_permission.go @@ -48,6 +48,16 @@ func (p *Permission) UnitAccessMode(unitType UnitType) AccessMode { return p.UnitsMode[unitType] } +// AllowWriteAll returns true if a all users are on the gitea instance have write access to the unit +func (p *Permission) AllowWriteAll(unitType UnitType) bool { + for _, u := range p.Units { + if u.Type == unitType { + return u.AllowWriteAll + } + } + return false +} + // CanAccess returns true if user has mode access to the unit of the repository func (p *Permission) CanAccess(mode AccessMode, unitType UnitType) bool { return p.UnitAccessMode(unitType) >= mode @@ -254,6 +264,9 @@ func getUserRepoPermission(e Engine, repo *Repository, user *User) (perm Permiss if !found && !repo.IsPrivate && !user.IsRestricted { if _, ok := perm.UnitsMode[u.Type]; !ok { perm.UnitsMode[u.Type] = AccessModeRead + if u.AllowWriteAll == true { + perm.UnitsMode[u.Type] = AccessModeWrite + } } } } diff --git a/models/repo_unit.go b/models/repo_unit.go index 2a20205fe4962..f6c4af3e93013 100644 --- a/models/repo_unit.go +++ b/models/repo_unit.go @@ -16,11 +16,12 @@ import ( // RepoUnit describes all units of a repository type RepoUnit struct { - ID int64 - RepoID int64 `xorm:"INDEX(s)"` - Type UnitType `xorm:"INDEX(s)"` - Config convert.Conversion `xorm:"TEXT"` - CreatedUnix timeutil.TimeStamp `xorm:"INDEX CREATED"` + ID int64 + RepoID int64 `xorm:"INDEX(s)"` + Type UnitType `xorm:"INDEX(s)"` + AllowWriteAll bool + Config convert.Conversion `xorm:"TEXT"` + CreatedUnix timeutil.TimeStamp `xorm:"INDEX CREATED"` } // UnitConfig describes common unit config diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 76536f2d49752..666a0c8403a79 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1658,6 +1658,7 @@ settings.advanced_settings = Advanced Settings settings.wiki_desc = Enable Repository Wiki settings.use_internal_wiki = Use Built-In Wiki settings.use_external_wiki = Use External Wiki +settings.allow_wiki_edit_all = Allow Wiki editing by all users settings.external_wiki_url = External Wiki URL settings.external_wiki_url_error = The external wiki URL is not a valid URL. settings.external_wiki_url_desc = Visitors are redirected to the external wiki URL when clicking the wiki tab. diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index 136e08cb4702e..c1eafb46acc98 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -347,9 +347,10 @@ func SettingsPost(ctx *context.Context) { deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeWiki) } else if form.EnableWiki && !form.EnableExternalWiki && !models.UnitTypeWiki.UnitGlobalDisabled() { units = append(units, models.RepoUnit{ - RepoID: repo.ID, - Type: models.UnitTypeWiki, - Config: new(models.UnitConfig), + RepoID: repo.ID, + Type: models.UnitTypeWiki, + Config: new(models.UnitConfig), // TODO: introduce a WikiConfig + AllowWriteAll: form.AllowWikiEditAll, }) deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeExternalWiki) } else { diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index c1c146f234668..9059e04ffedfc 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -133,6 +133,7 @@ type RepoSettingForm struct { // Advanced settings EnableWiki bool + AllowWikiEditAll bool EnableExternalWiki bool ExternalWikiURL string EnableIssues bool diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 054df7c36899c..48981a5c1da32 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -259,17 +259,27 @@ {{else}}
{{end}} - +
+ {{if .Repository.Owner.IsOrganization}} +
+
+
+ + +
+
+
+ {{end}}
{{if .UnitTypeExternalWiki.UnitGlobalDisabled}}
{{else}}
{{end}} - +