Skip to content

Allow setting wiki writeable for all users on an instance #6312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions models/repo_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions models/repo_unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a migration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought false is the default, then we would still need it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All database structure changes should have a migration. You can find many example on models/migration

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I see, I somehow thought that there was some magic invovled which inserts missing columns automagically.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some magic involved, and you've probably got your column migrated automagically.

There are two stages to Gitea migration:

  • The "manual steps" stage (from models/migration), that update the internal version and change data as needed.
  • The "startup" stage, where any remaining database structure is updated.

The problem comes when you rely on the 2nd stage to do your migration. It will work the first time, but in the future (e.g. Gitea 12.2) some manual steps can be added in the first stage of the migration that will need the structure that is not there yet (as it is created in the 2nd stage). If some user attempts to migrate from 1.10 to 12.2, all the steps on stage 1 will be executed, and that particular step will fail because of the missing column.

That's why we don't rely on the 2nd stage and make all migration steps explicit, so any upcoming step can count on the previous steps to upgrade the database to the expected state.

I hope this makes sense!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for a great explanation! Understood and I am convinced ;)

Config convert.Conversion `xorm:"TEXT"`
CreatedUnix timeutil.TimeStamp `xorm:"INDEX CREATED"`
}

// UnitConfig describes common unit config
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions routers/web/repo/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions services/forms/repo_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ type RepoSettingForm struct {

// Advanced settings
EnableWiki bool
AllowWikiEditAll bool
EnableExternalWiki bool
ExternalWikiURL string
EnableIssues bool
Expand Down
14 changes: 12 additions & 2 deletions templates/repo/settings/options.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,27 @@
{{else}}
<div class="ui radio checkbox">
{{end}}
<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}}/>
<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}}/>
<label>{{.i18n.Tr "repo.settings.use_internal_wiki"}}</label>
</div>
</div>
{{if .Repository.Owner.IsOrganization}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting should only be available for public repositories?

<div class="field {{if (.Repository.UnitEnabled $.UnitTypeExternalWiki)}}disabled{{end}}" id="internal_wiki_box">
<div class="field">
<div class="ui checkbox">
<input name="allow_wiki_edit_all" type="checkbox" {{if .Permission.AllowWriteAll $.UnitTypeWiki}}checked{{end}}>
<label>{{.i18n.Tr "repo.settings.allow_wiki_edit_all"}}</label>
</div>
</div>
</div>
{{end}}
<div class="field">
{{if .UnitTypeExternalWiki.UnitGlobalDisabled}}
<div class="ui radio checkbox poping up disabled" data-content="{{.i18n.Tr "repo.unit_disabled"}}">
{{else}}
<div class="ui radio checkbox">
{{end}}
<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}}/>
<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}}/>
<label>{{.i18n.Tr "repo.settings.use_external_wiki"}}</label>
</div>
</div>
Expand Down