Skip to content
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

Add setting to set default and global disabled repository units. #8788

Merged
merged 16 commits into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add Default Repo Unit app.ini setting.
  • Loading branch information
davidsvantesson committed Jan 4, 2020
commit 3c0f89338c2fc3defea33f794b240a0d04bf2948
8 changes: 6 additions & 2 deletions custom/conf/app.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ DEFAULT_CLOSE_ISSUES_VIA_COMMITS_IN_ANY_BRANCH = false
; Allow users to push local repositories to Gitea and have them automatically created for a user or an org
ENABLE_PUSH_CREATE_USER = false
ENABLE_PUSH_CREATE_ORG = false
; Comma-separated list of globally disabled repo units. Allowed values: repo.issues, repo.ext_issues, repo.pulls, repo.wiki, repo.ext_wiki
; Note: Setting this will not disable units on existing repositories, use some script if you want to do that.
; Comma separated list of globally disabled repo units. Allowed values: repo.issues, repo.ext_issues, repo.pulls, repo.wiki, repo.ext_wiki
DISABLED_REPO_UNITS =
; Comma separated list of default repo units. Allowed values: repo.code, repo.releases, repo.issues, repo.pulls, repo.wiki.
; Note: Code and Releases can currently not be deactivated. If you specify default repo units you should still list them for future compatibility.
; External wiki and issue tracker can't be enabled by default as it requires additional settings.
; Disabled repo units will not be added to new repositories regardless if it is in the default list.
DEFAULT_REPO_UNITS = repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki

[repository.editor]
; List of file extensions for which lines should be wrapped in the CodeMirror editor
Expand Down
36 changes: 35 additions & 1 deletion models/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ var (
UnitTypeWiki,
}

// NotAllowedDefaultRepoUnits contains units that can't be default
NotAllowedDefaultRepoUnits = []UnitType{
UnitTypeExternalWiki,
UnitTypeExternalTracker,
}

// MustRepoUnits contains the units could not be disabled currently
MustRepoUnits = []UnitType{
UnitTypeCode,
Expand All @@ -90,6 +96,24 @@ var (
)

func loadUnitConfig() {
setDefaultRepoUnits := FindUnitTypes(setting.Repository.DefaultRepoUnits...)
// Default repo units set if setting is not empty
if len(setDefaultRepoUnits) > 0 {
// MustRepoUnits required as default
DefaultRepoUnits = make([]UnitType, len(MustRepoUnits))
copy(DefaultRepoUnits, MustRepoUnits)
for _, defaultU := range setDefaultRepoUnits {
if !defaultU.CanBeDefault() {
log.Warn("Not allowed as default unit: %s", defaultU.String())
continue
}
// MustRepoUnits already added
if defaultU.CanDisable() {
DefaultRepoUnits = append(DefaultRepoUnits, defaultU)
}
}
}

DisabledRepoUnits = FindUnitTypes(setting.Repository.DisabledRepoUnits...)
// Check that must units are not disabled
for i, disabledU := range DisabledRepoUnits {
Expand Down Expand Up @@ -123,7 +147,7 @@ func (u *UnitType) UnitGlobalDisabled() bool {
return IsUnitGlobalDisabled(*u)
}

// CanDisable returns if this unit type could be disabled.
// CanDisable checks if this unit type can be disabled.
func (u *UnitType) CanDisable() bool {
for _, mu := range MustRepoUnits {
if *u == mu {
Expand All @@ -133,6 +157,16 @@ func (u *UnitType) CanDisable() bool {
return true
}

// CanBeDefault checks if the unit type can be a default repo unit
func (u *UnitType) CanBeDefault() bool {
for _, nadU := range NotAllowedDefaultRepoUnits {
if *u == nadU {
return false
}
}
return true
}

// Unit is a section of one repository
type Unit struct {
Type UnitType
Expand Down
2 changes: 2 additions & 0 deletions modules/setting/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
EnablePushCreateUser bool
EnablePushCreateOrg bool
DisabledRepoUnits []string
DefaultRepoUnits []string

// Repository editor settings
Editor struct {
Expand Down Expand Up @@ -100,6 +101,7 @@ var (
EnablePushCreateUser: false,
EnablePushCreateOrg: false,
DisabledRepoUnits: []string{},
DefaultRepoUnits: []string{},

// Repository editor settings
Editor: struct {
Expand Down