diff --git a/custom/templates/repo/header.tmpl b/custom/templates/repo/header.tmpl index 2ba9b31c8..8478b1e7f 100644 --- a/custom/templates/repo/header.tmpl +++ b/custom/templates/repo/header.tmpl @@ -97,9 +97,11 @@ {{end}} - + {{if .Permission.CanRead $.UnitTypeDatasets}} + {{svg "octicon-file-submodule" 16}} {{.i18n.Tr "datasets"}} + {{end}} {{if .Permission.CanRead $.UnitTypeIssues}} diff --git a/models/repo.go b/models/repo.go index b85529ad3..365abf863 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1070,6 +1070,12 @@ func CreateRepository(ctx DBContext, doer, u *User, repo *Repository) (err error Type: tp, Config: &PullRequestsConfig{AllowMerge: true, AllowRebase: true, AllowRebaseMerge: true, AllowSquash: true}, }) + } else if tp == UnitTypeDatasets { + units = append(units, RepoUnit{ + RepoID: repo.ID, + Type: tp, + Config: &DatasetConfig{EnableDataset: true}, + }) } else { units = append(units, RepoUnit{ RepoID: repo.ID, diff --git a/models/repo_unit.go b/models/repo_unit.go index d6af3d454..ba97c5314 100644 --- a/models/repo_unit.go +++ b/models/repo_unit.go @@ -114,7 +114,7 @@ func (cfg *PullRequestsConfig) IsMergeStyleAllowed(mergeStyle MergeStyle) bool { } type DatasetConfig struct { - EnableTest bool + EnableDataset bool } // FromDB fills up a IssuesConfig from serialized format. diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go index 6c3421e4f..4f97acb1a 100644 --- a/modules/auth/repo_form.go +++ b/modules/auth/repo_form.go @@ -120,6 +120,7 @@ type RepoSettingForm struct { EnablePrune bool // Advanced settings + EnableDataset bool EnableWiki bool EnableExternalWiki bool ExternalWikiURL string diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index 6440323a3..611b23138 100644 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -60,11 +60,11 @@ func DatasetIndex(ctx *context.Context) { var dataset *models.Dataset if len(datasets) > 0 { //TODO check list is single item dataset = datasets[len(datasets)-1] - } - err = models.GetDatasetAttachments(dataset) - if err != nil { - ctx.ServerError("GetDatasetAttachments", err) - return + err = models.GetDatasetAttachments(dataset) + if err != nil { + ctx.ServerError("GetDatasetAttachments", err) + return + } } // TODO permission diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 7a2db88c1..a1a2b1fd8 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -211,6 +211,18 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { // as an error on the UI for this action ctx.Data["Err_RepoName"] = nil + if form.EnableDataset && !models.UnitTypeDatasets.UnitGlobalDisabled() { + units = append(units, models.RepoUnit{ + RepoID: repo.ID, + Type: models.UnitTypeDatasets, + Config: &models.DatasetConfig{ + EnableDataset: form.EnableDataset, + }, + }) + } else if !models.UnitTypeDatasets.UnitGlobalDisabled() { + deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeDatasets) + } + if form.EnableWiki && form.EnableExternalWiki && !models.UnitTypeExternalWiki.UnitGlobalDisabled() { if !validation.IsValidExternalURL(form.ExternalWikiURL) { ctx.Flash.Error(ctx.Tr("repo.settings.external_wiki_url_error")) diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index c674fcf7f..8859b6b2c 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -141,6 +141,15 @@ {{.CsrfTokenHtml}} + {{$isDatasetEnabled := .Repository.UnitEnabled $.UnitTypeDatasets }} +
+ +
+ + +
+
+ {{$isWikiEnabled := or (.Repository.UnitEnabled $.UnitTypeWiki) (.Repository.UnitEnabled $.UnitTypeExternalWiki)}}