diff --git a/models/repo.go b/models/repo.go index 1720c0311..1add1dd58 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1076,6 +1076,12 @@ func CreateRepository(ctx DBContext, doer, u *User, repo *Repository) (err error Type: tp, Config: &DatasetConfig{EnableDataset: true}, }) + } else if tp == UnitTypeCloudBrain { + units = append(units, RepoUnit{ + RepoID: repo.ID, + Type: tp, + Config: &CloudBrainConfig{EnableCloudBrain: true}, + }) } else { units = append(units, RepoUnit{ RepoID: repo.ID, diff --git a/models/repo_unit.go b/models/repo_unit.go index ba97c5314..a0e7a2f76 100644 --- a/models/repo_unit.go +++ b/models/repo_unit.go @@ -117,16 +117,30 @@ type DatasetConfig struct { EnableDataset bool } -// FromDB fills up a IssuesConfig from serialized format. +// FromDB fills up a DatasetConfig from serialized format. func (cfg *DatasetConfig) FromDB(bs []byte) error { return json.Unmarshal(bs, &cfg) } -// ToDB exports a IssuesConfig to a serialized format. +// ToDB exports a DatasetConfig to a serialized format. func (cfg *DatasetConfig) ToDB() ([]byte, error) { return json.Marshal(cfg) } +type CloudBrainConfig struct { + EnableCloudBrain bool +} + +// FromDB fills up a CloudBrainConfig from serialized format. +func (cfg *CloudBrainConfig) FromDB(bs []byte) error { + return json.Unmarshal(bs, &cfg) +} + +// ToDB exports a CloudBrainConfig to a serialized format. +func (cfg *CloudBrainConfig) ToDB() ([]byte, error) { + return json.Marshal(cfg) +} + // BeforeSet is invoked from XORM before setting the value of a field of this object. func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) { switch colName { @@ -144,6 +158,8 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) { r.Config = new(IssuesConfig) case UnitTypeDatasets: r.Config = new(DatasetConfig) + case UnitTypeCloudBrain: + r.Config = new(CloudBrainConfig) default: panic("unrecognized repo unit type: " + com.ToStr(*val)) } diff --git a/models/unit.go b/models/unit.go index ef9daf4ba..41712f238 100644 --- a/models/unit.go +++ b/models/unit.go @@ -25,6 +25,7 @@ const ( UnitTypeExternalWiki // 6 ExternalWiki UnitTypeExternalTracker // 7 ExternalTracker UnitTypeDatasets UnitType = 10 // 10 Dataset + UnitTypeCloudBrain UnitType = 11 // 11 CloudBrain ) // Value returns integer value for unit type @@ -50,6 +51,8 @@ func (u UnitType) String() string { return "UnitTypeExternalTracker" case UnitTypeDatasets: return "UnitTypeDataset" + case UnitTypeCloudBrain: + return "UnitTypeCloudBrain" } return fmt.Sprintf("Unknown UnitType %d", u) } @@ -72,6 +75,7 @@ var ( UnitTypeExternalWiki, UnitTypeExternalTracker, UnitTypeDatasets, + UnitTypeCloudBrain, } // DefaultRepoUnits contains the default unit types @@ -82,6 +86,7 @@ var ( UnitTypeReleases, UnitTypeWiki, UnitTypeDatasets, + UnitTypeCloudBrain, } // NotAllowedDefaultRepoUnits contains units that can't be default @@ -255,6 +260,14 @@ var ( 5, } + UnitCloudBrain = Unit{ + UnitTypeCloudBrain, + "repo.cloudbrains", + "/cloudbrains", + "repo.cloudbrains.desc", + 6, + } + // Units contains all the units Units = map[UnitType]Unit{ UnitTypeCode: UnitCode, @@ -265,6 +278,7 @@ var ( UnitTypeWiki: UnitWiki, UnitTypeExternalWiki: UnitExternalWiki, UnitTypeDatasets: UnitDataset, + UnitTypeCloudBrain: UnitCloudBrain, } ) diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go index 4f97acb1a..7e867b1af 100644 --- a/modules/auth/repo_form.go +++ b/modules/auth/repo_form.go @@ -121,6 +121,7 @@ type RepoSettingForm struct { // Advanced settings EnableDataset bool + EnableCloudBrain bool EnableWiki bool EnableExternalWiki bool ExternalWikiURL string diff --git a/modules/context/repo.go b/modules/context/repo.go index 9d94030d8..bdd8cde5d 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -814,6 +814,7 @@ func UnitTypes() macaron.Handler { ctx.Data["UnitTypeCode"] = models.UnitTypeCode ctx.Data["UnitTypeIssues"] = models.UnitTypeIssues ctx.Data["UnitTypeDatasets"] = models.UnitTypeDatasets + ctx.Data["UnitTypeCloudBrain"] = models.UnitTypeCloudBrain ctx.Data["UnitTypePullRequests"] = models.UnitTypePullRequests ctx.Data["UnitTypeReleases"] = models.UnitTypeReleases ctx.Data["UnitTypeWiki"] = models.UnitTypeWiki diff --git a/routers/repo/setting.go b/routers/repo/setting.go index dd3490f12..b2ca042de 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -227,6 +227,18 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeDatasets) } + if form.EnableCloudBrain && !models.UnitTypeCloudBrain.UnitGlobalDisabled() { + units = append(units, models.RepoUnit{ + RepoID: repo.ID, + Type: models.UnitTypeCloudBrain, + Config: &models.CloudBrainConfig{ + EnableCloudBrain: form.EnableCloudBrain, + }, + }) + } else if !models.UnitTypeCloudBrain.UnitGlobalDisabled() { + deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeCloudBrain) + } + 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/routers/routes/routes.go b/routers/routes/routes.go index 27c9e0c22..9ffa50059 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -544,6 +544,8 @@ func RegisterRoutes(m *macaron.Macaron) { reqRepoIssuesOrPullsReader := context.RequireRepoReaderOr(models.UnitTypeIssues, models.UnitTypePullRequests) reqRepoDatasetReader := context.RequireRepoReader(models.UnitTypeDatasets) reqRepoDatasetWriter := context.RequireRepoWriter(models.UnitTypeDatasets) + reqRepoCloudBrainReader := context.RequireRepoReader(models.UnitTypeCloudBrain) + reqRepoCloudBrainWriter := context.RequireRepoWriter(models.UnitTypeCloudBrain) // ***** START: Organization ***** m.Group("/org", func() { @@ -870,8 +872,8 @@ func RegisterRoutes(m *macaron.Macaron) { }, context.RepoRef()) m.Group("/cloudbrain", func() { - m.Get("", repo.CloudBrainIndex) - m.Get("/new", repo.CloudBrainNew) + m.Get("", reqRepoCloudBrainReader, repo.CloudBrainIndex) + m.Get("/new", reqRepoCloudBrainWriter, repo.CloudBrainNew) }) m.Group("/wiki", func() { diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index b0e546272..7baf67809 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -139,10 +139,10 @@ {{end}} - {{if .Permission.CanRead $.UnitTypeCode}} - - {{svg "octicon-circuit-board" 16}} {{.i18n.Tr "repo.cloudbrain"}} - + {{if .Permission.CanRead $.UnitTypeCloudBrain}} + + {{svg "octicon-file-submodule" 16}} {{.i18n.Tr "cloudbrains"}} + {{end}} {{template "custom/extra_tabs" .}} diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 8859b6b2c..e63d369f5 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -150,6 +150,15 @@ + {{$isCloudBrainEnabled := .Repository.UnitEnabled $.UnitTypeCloudBrain }} +
+ +
+ + +
+
+ {{$isWikiEnabled := or (.Repository.UnitEnabled $.UnitTypeWiki) (.Repository.UnitEnabled $.UnitTypeExternalWiki)}}