mirror of
https://github.com/go-gitea/gitea
synced 2025-07-23 18:58:38 +00:00
Add units concept for modulable functions of a repository (#742)
* Add units concept for modulable functions of a repository * remove unused comment codes & fix lints and tests * remove unused comment codes * use struct config instead of map * fix lint * rm wrong files * fix tests
This commit is contained in:
@@ -205,7 +205,7 @@ func orgAssignment(args ...bool) macaron.Handler {
|
||||
}
|
||||
|
||||
func mustEnableIssues(ctx *context.APIContext) {
|
||||
if !ctx.Repo.Repository.EnableIssues || ctx.Repo.Repository.EnableExternalTracker {
|
||||
if !ctx.Repo.Repository.EnableUnit(models.UnitTypeIssues) {
|
||||
ctx.Status(404)
|
||||
return
|
||||
}
|
||||
|
@@ -59,13 +59,15 @@ var (
|
||||
|
||||
// MustEnableIssues check if repository enable internal issues
|
||||
func MustEnableIssues(ctx *context.Context) {
|
||||
if !ctx.Repo.Repository.EnableIssues {
|
||||
if !ctx.Repo.Repository.EnableUnit(models.UnitTypeIssues) &&
|
||||
!ctx.Repo.Repository.EnableUnit(models.UnitTypeExternalTracker) {
|
||||
ctx.Handle(404, "MustEnableIssues", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if ctx.Repo.Repository.EnableExternalTracker {
|
||||
ctx.Redirect(ctx.Repo.Repository.ExternalTrackerURL)
|
||||
unit, err := ctx.Repo.Repository.GetUnit(models.UnitTypeExternalTracker)
|
||||
if err == nil {
|
||||
ctx.Redirect(unit.ExternalTrackerConfig().ExternalTrackerURL)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@@ -143,18 +143,70 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
|
||||
ctx.Redirect(repo.Link() + "/settings")
|
||||
|
||||
case "advanced":
|
||||
repo.EnableWiki = form.EnableWiki
|
||||
repo.EnableExternalWiki = form.EnableExternalWiki
|
||||
repo.ExternalWikiURL = form.ExternalWikiURL
|
||||
repo.EnableIssues = form.EnableIssues
|
||||
repo.EnableExternalTracker = form.EnableExternalTracker
|
||||
repo.ExternalTrackerURL = form.ExternalTrackerURL
|
||||
repo.ExternalTrackerFormat = form.TrackerURLFormat
|
||||
repo.ExternalTrackerStyle = form.TrackerIssueStyle
|
||||
repo.EnablePulls = form.EnablePulls
|
||||
var units []models.RepoUnit
|
||||
|
||||
if err := models.UpdateRepository(repo, false); err != nil {
|
||||
ctx.Handle(500, "UpdateRepository", err)
|
||||
for _, tp := range models.MustRepoUnits {
|
||||
units = append(units, models.RepoUnit{
|
||||
RepoID: repo.ID,
|
||||
Type: tp,
|
||||
Index: int(tp),
|
||||
Config: new(models.UnitConfig),
|
||||
})
|
||||
}
|
||||
|
||||
if form.EnableWiki {
|
||||
if form.EnableExternalWiki {
|
||||
units = append(units, models.RepoUnit{
|
||||
RepoID: repo.ID,
|
||||
Type: models.UnitTypeExternalWiki,
|
||||
Index: int(models.UnitTypeExternalWiki),
|
||||
Config: &models.ExternalWikiConfig{
|
||||
ExternalWikiURL: form.ExternalWikiURL,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
units = append(units, models.RepoUnit{
|
||||
RepoID: repo.ID,
|
||||
Type: models.UnitTypeWiki,
|
||||
Index: int(models.UnitTypeWiki),
|
||||
Config: new(models.UnitConfig),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if form.EnableIssues {
|
||||
if form.EnableExternalTracker {
|
||||
units = append(units, models.RepoUnit{
|
||||
RepoID: repo.ID,
|
||||
Type: models.UnitTypeExternalWiki,
|
||||
Index: int(models.UnitTypeExternalWiki),
|
||||
Config: &models.ExternalTrackerConfig{
|
||||
ExternalTrackerURL: form.ExternalTrackerURL,
|
||||
ExternalTrackerFormat: form.TrackerURLFormat,
|
||||
ExternalTrackerStyle: form.TrackerIssueStyle,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
units = append(units, models.RepoUnit{
|
||||
RepoID: repo.ID,
|
||||
Type: models.UnitTypeIssues,
|
||||
Index: int(models.UnitTypeIssues),
|
||||
Config: new(models.UnitConfig),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if form.EnablePulls {
|
||||
units = append(units, models.RepoUnit{
|
||||
RepoID: repo.ID,
|
||||
Type: models.UnitTypePullRequests,
|
||||
Index: int(models.UnitTypePullRequests),
|
||||
Config: new(models.UnitConfig),
|
||||
})
|
||||
}
|
||||
|
||||
if err := models.UpdateRepositoryUnits(repo, units); err != nil {
|
||||
ctx.Handle(500, "UpdateRepositoryUnits", err)
|
||||
return
|
||||
}
|
||||
log.Trace("Repository advanced settings updated: %s/%s", ctx.Repo.Owner.Name, repo.Name)
|
||||
@@ -281,12 +333,6 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
|
||||
repo.DeleteWiki()
|
||||
log.Trace("Repository wiki deleted: %s/%s", ctx.Repo.Owner.Name, repo.Name)
|
||||
|
||||
repo.EnableWiki = false
|
||||
if err := models.UpdateRepository(repo, false); err != nil {
|
||||
ctx.Handle(500, "UpdateRepository", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("repo.settings.wiki_deletion_success"))
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/settings")
|
||||
|
||||
|
@@ -27,13 +27,15 @@ const (
|
||||
|
||||
// MustEnableWiki check if wiki is enabled, if external then redirect
|
||||
func MustEnableWiki(ctx *context.Context) {
|
||||
if !ctx.Repo.Repository.EnableWiki {
|
||||
if !ctx.Repo.Repository.EnableUnit(models.UnitTypeWiki) &&
|
||||
!ctx.Repo.Repository.EnableUnit(models.UnitTypeExternalWiki) {
|
||||
ctx.Handle(404, "MustEnableWiki", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if ctx.Repo.Repository.EnableExternalWiki {
|
||||
ctx.Redirect(ctx.Repo.Repository.ExternalWikiURL)
|
||||
unit, err := ctx.Repo.Repository.GetUnit(models.UnitTypeExternalWiki)
|
||||
if err == nil {
|
||||
ctx.Redirect(unit.ExternalWikiConfig().ExternalWikiURL)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@@ -236,7 +236,7 @@ func Issues(ctx *context.Context) {
|
||||
for _, repo := range repos {
|
||||
if (isPullList && repo.NumPulls == 0) ||
|
||||
(!isPullList &&
|
||||
(!repo.EnableIssues || repo.EnableExternalTracker || repo.NumIssues == 0)) {
|
||||
(!repo.EnableUnit(models.UnitTypeIssues) || repo.NumIssues == 0)) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user