Skip to content

Commit e56187c

Browse files
committed
Allow setting wiki writeable for all users on an instance
1 parent 4334fe7 commit e56187c

File tree

6 files changed

+37
-10
lines changed

6 files changed

+37
-10
lines changed

models/repo_permission.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ func (p *Permission) UnitAccessMode(unitType UnitType) AccessMode {
4242
return p.UnitsMode[unitType]
4343
}
4444

45+
// AllowWriteAll returns true if a all users are on the gitea instance have write access to the unit
46+
func (p *Permission) AllowWriteAll(unitType UnitType) bool {
47+
for _, u := range p.Units {
48+
if u.Type == unitType {
49+
return u.AllowWriteAll
50+
}
51+
}
52+
return false
53+
}
54+
4555
// CanAccess returns true if user has mode access to the unit of the repository
4656
func (p *Permission) CanAccess(mode AccessMode, unitType UnitType) bool {
4757
return p.UnitAccessMode(unitType) >= mode
@@ -176,6 +186,9 @@ func getUserRepoPermission(e Engine, repo *Repository, user *User) (perm Permiss
176186
if !found && !repo.IsPrivate {
177187
if _, ok := perm.UnitsMode[u.Type]; !ok {
178188
perm.UnitsMode[u.Type] = AccessModeRead
189+
if u.AllowWriteAll == true {
190+
perm.UnitsMode[u.Type] = AccessModeWrite
191+
}
179192
}
180193
}
181194
}

models/repo_unit.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ import (
1616

1717
// RepoUnit describes all units of a repository
1818
type RepoUnit struct {
19-
ID int64
20-
RepoID int64 `xorm:"INDEX(s)"`
21-
Type UnitType `xorm:"INDEX(s)"`
22-
Config core.Conversion `xorm:"TEXT"`
23-
CreatedUnix util.TimeStamp `xorm:"INDEX CREATED"`
19+
ID int64
20+
RepoID int64 `xorm:"INDEX(s)"`
21+
Type UnitType `xorm:"INDEX(s)"`
22+
AllowWriteAll bool
23+
Config core.Conversion `xorm:"TEXT"`
24+
CreatedUnix util.TimeStamp `xorm:"INDEX CREATED"`
2425
}
2526

2627
// UnitConfig describes common unit config

modules/auth/repo_form.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ type RepoSettingForm struct {
102102

103103
// Advanced settings
104104
EnableWiki bool
105+
AllowWikiEditAll bool
105106
EnableExternalWiki bool
106107
ExternalWikiURL string
107108
EnableIssues bool

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,7 @@ settings.advanced_settings = Advanced Settings
10641064
settings.wiki_desc = Enable Repository Wiki
10651065
settings.use_internal_wiki = Use Built-In Wiki
10661066
settings.use_external_wiki = Use External Wiki
1067+
settings.allow_wiki_edit_all = Allow Wiki editing by all users
10671068
settings.external_wiki_url = External Wiki URL
10681069
settings.external_wiki_url_error = The external wiki URL is not a valid URL.
10691070
settings.external_wiki_url_desc = Visitors are redirected to the external wiki URL when clicking the wiki tab.

routers/repo/setting.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,10 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
186186
})
187187
} else {
188188
units = append(units, models.RepoUnit{
189-
RepoID: repo.ID,
190-
Type: models.UnitTypeWiki,
191-
Config: new(models.UnitConfig),
189+
RepoID: repo.ID,
190+
Type: models.UnitTypeWiki,
191+
Config: new(models.UnitConfig),
192+
AllowWriteAll: form.AllowWikiEditAll,
192193
})
193194
}
194195
}

templates/repo/settings/options.tmpl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,23 @@
104104
<div class="field {{if not $isWikiEnabled}}disabled{{end}}" id="wiki_box">
105105
<div class="field">
106106
<div class="ui radio checkbox">
107-
<input class="hidden enable-system-radio" tabindex="0" name="enable_external_wiki" type="radio" value="false" data-target="#external_wiki_box" {{if not (.Repository.UnitEnabled $.UnitTypeExternalWiki)}}checked{{end}}/>
107+
<input class="hidden enable-system-radio" tabindex="0" name="enable_external_wiki" type="radio" value="false" data-target="#external_wiki_box" data-context="#internal_wiki_box" {{if not (.Repository.UnitEnabled $.UnitTypeExternalWiki)}}checked{{end}}/>
108108
<label>{{.i18n.Tr "repo.settings.use_internal_wiki"}}</label>
109109
</div>
110110
</div>
111+
{{if .Repository.Owner.IsOrganization}}
112+
<div class="field {{if (.Repository.UnitEnabled $.UnitTypeExternalWiki)}}disabled{{end}}" id="internal_wiki_box">
113+
<div class="field">
114+
<div class="ui checkbox">
115+
<input name="allow_wiki_edit_all" type="checkbox" {{if .Permission.AllowWriteAll $.UnitTypeWiki}}checked{{end}}>
116+
<label>{{.i18n.Tr "repo.settings.allow_wiki_edit_all"}}</label>
117+
</div>
118+
</div>
119+
</div>
120+
{{end}}
111121
<div class="field">
112122
<div class="ui radio checkbox">
113-
<input class="hidden enable-system-radio" tabindex="0" name="enable_external_wiki" type="radio" value="true" data-target="#external_wiki_box" {{if .Repository.UnitEnabled $.UnitTypeExternalWiki}}checked{{end}}/>
123+
<input class="hidden enable-system-radio" tabindex="0" name="enable_external_wiki" type="radio" value="true" data-target="#external_wiki_box" data-context="#internal_wiki_box" {{if .Repository.UnitEnabled $.UnitTypeExternalWiki}}checked{{end}}/>
114124
<label>{{.i18n.Tr "repo.settings.use_external_wiki"}}</label>
115125
</div>
116126
</div>

0 commit comments

Comments
 (0)