@@ -1114,6 +1114,12 @@ func CreateRepository(ctx DBContext, doer, u *User, repo *Repository) (err error | |||
Type: tp, | |||
Config: &BlockChainConfig{EnableBlockChain: true}, | |||
}) | |||
} else if tp == UnitTypeModelManage { | |||
units = append(units, RepoUnit{ | |||
RepoID: repo.ID, | |||
Type: tp, | |||
Config: &ModelManageConfig{EnableModelManage: true}, | |||
}) | |||
} else { | |||
units = append(units, RepoUnit{ | |||
RepoID: repo.ID, | |||
@@ -131,6 +131,20 @@ type CloudBrainConfig struct { | |||
EnableCloudBrain bool | |||
} | |||
type ModelManageConfig struct { | |||
EnableModelManage bool | |||
} | |||
// FromDB fills up a CloudBrainConfig from serialized format. | |||
func (cfg *ModelManageConfig) FromDB(bs []byte) error { | |||
return json.Unmarshal(bs, &cfg) | |||
} | |||
// ToDB exports a CloudBrainConfig to a serialized format. | |||
func (cfg *ModelManageConfig) ToDB() ([]byte, error) { | |||
return json.Marshal(cfg) | |||
} | |||
// FromDB fills up a CloudBrainConfig from serialized format. | |||
func (cfg *CloudBrainConfig) FromDB(bs []byte) error { | |||
return json.Unmarshal(bs, &cfg) | |||
@@ -176,6 +190,8 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) { | |||
r.Config = new(CloudBrainConfig) | |||
case UnitTypeBlockChain: | |||
r.Config = new(BlockChainConfig) | |||
case UnitTypeModelManage: | |||
r.Config = new(ModelManageConfig) | |||
default: | |||
panic("unrecognized repo unit type: " + com.ToStr(*val)) | |||
} | |||
@@ -27,6 +27,7 @@ const ( | |||
UnitTypeDatasets UnitType = 10 // 10 Dataset | |||
UnitTypeCloudBrain UnitType = 11 // 11 CloudBrain | |||
UnitTypeBlockChain UnitType = 12 // 12 BlockChain | |||
UnitTypeModelManage UnitType = 13 // 13 ModelManage | |||
) | |||
// Value returns integer value for unit type | |||
@@ -56,6 +57,8 @@ func (u UnitType) String() string { | |||
return "UnitTypeCloudBrain" | |||
case UnitTypeBlockChain: | |||
return "UnitTypeBlockChain" | |||
case UnitTypeModelManage: | |||
return "UnitTypeModelManage" | |||
} | |||
return fmt.Sprintf("Unknown UnitType %d", u) | |||
} | |||
@@ -80,6 +83,7 @@ var ( | |||
UnitTypeDatasets, | |||
UnitTypeCloudBrain, | |||
UnitTypeBlockChain, | |||
UnitTypeModelManage, | |||
} | |||
// DefaultRepoUnits contains the default unit types | |||
@@ -92,6 +96,7 @@ var ( | |||
UnitTypeDatasets, | |||
UnitTypeCloudBrain, | |||
UnitTypeBlockChain, | |||
UnitTypeModelManage, | |||
} | |||
// NotAllowedDefaultRepoUnits contains units that can't be default | |||
@@ -281,6 +286,14 @@ var ( | |||
7, | |||
} | |||
UnitModelManage = Unit{ | |||
UnitTypeModelManage, | |||
"repo.modelmanage", | |||
"/modelmanage", | |||
"repo.modelmanage.desc", | |||
8, | |||
} | |||
// Units contains all the units | |||
Units = map[UnitType]Unit{ | |||
UnitTypeCode: UnitCode, | |||
@@ -293,6 +306,7 @@ var ( | |||
UnitTypeDatasets: UnitDataset, | |||
UnitTypeCloudBrain: UnitCloudBrain, | |||
UnitTypeBlockChain: UnitBlockChain, | |||
UnitTypeModelManage: UnitModelManage, | |||
} | |||
) | |||
@@ -122,6 +122,7 @@ type RepoSettingForm struct { | |||
// Advanced settings | |||
EnableDataset bool | |||
EnableCloudBrain bool | |||
EnableModelManager bool | |||
EnableWiki bool | |||
EnableExternalWiki bool | |||
ExternalWikiURL string | |||
@@ -821,5 +821,6 @@ func UnitTypes() macaron.Handler { | |||
ctx.Data["UnitTypeExternalWiki"] = models.UnitTypeExternalWiki | |||
ctx.Data["UnitTypeExternalTracker"] = models.UnitTypeExternalTracker | |||
ctx.Data["UnitTypeBlockChain"] = models.UnitTypeBlockChain | |||
ctx.Data["UnitTypeModelManage"] = models.UnitTypeModelManage | |||
} | |||
} |
@@ -118,7 +118,7 @@ func SaveModel(ctx *context.Context) { | |||
label := ctx.Query("Label") | |||
description := ctx.Query("Description") | |||
if !ctx.Repo.CanWrite(models.UnitTypeCloudBrain) { | |||
if !ctx.Repo.CanWrite(models.UnitTypeModelManage) { | |||
ctx.ServerError("No right.", errors.New(ctx.Tr("repo.model_noright"))) | |||
return | |||
} | |||
@@ -418,7 +418,7 @@ func ShowModelTemplate(ctx *context.Context) { | |||
func isQueryRight(ctx *context.Context) bool { | |||
if ctx.Repo.Repository.IsPrivate { | |||
if ctx.Repo.CanRead(models.UnitTypeCloudBrain) || ctx.User.IsAdmin || ctx.Repo.IsAdmin() || ctx.Repo.IsOwner() { | |||
if ctx.Repo.CanRead(models.UnitTypeModelManage) || ctx.User.IsAdmin || ctx.Repo.IsAdmin() || ctx.Repo.IsOwner() { | |||
return true | |||
} | |||
return false | |||
@@ -239,6 +239,18 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { | |||
deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeCloudBrain) | |||
} | |||
if form.EnableModelManager && !models.UnitTypeModelManage.UnitGlobalDisabled() { | |||
units = append(units, models.RepoUnit{ | |||
RepoID: repo.ID, | |||
Type: models.UnitTypeModelManage, | |||
Config: &models.ModelManageConfig{ | |||
EnableModelManage: form.EnableModelManager, | |||
}, | |||
}) | |||
} else if !models.UnitTypeModelManage.UnitGlobalDisabled() { | |||
deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeModelManage) | |||
} | |||
if form.EnableWiki && form.EnableExternalWiki && !models.UnitTypeExternalWiki.UnitGlobalDisabled() { | |||
if !validation.IsValidExternalURL(form.ExternalWikiURL) { | |||
ctx.Flash.Error(ctx.Tr("repo.settings.external_wiki_url_error")) | |||
@@ -616,6 +616,8 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
reqRepoDatasetWriter := context.RequireRepoWriter(models.UnitTypeDatasets) | |||
reqRepoCloudBrainReader := context.RequireRepoReader(models.UnitTypeCloudBrain) | |||
reqRepoCloudBrainWriter := context.RequireRepoWriter(models.UnitTypeCloudBrain) | |||
reqRepoModelManageReader := context.RequireRepoReader(models.UnitTypeModelManage) | |||
reqRepoModelManageWriter := context.RequireRepoWriter(models.UnitTypeModelManage) | |||
//reqRepoBlockChainReader := context.RequireRepoReader(models.UnitTypeBlockChain) | |||
//reqRepoBlockChainWriter := context.RequireRepoWriter(models.UnitTypeBlockChain) | |||
@@ -973,21 +975,21 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateCloudBrainForm{}), repo.CloudBrainCreate) | |||
}, context.RepoRef()) | |||
m.Group("/modelmanage", func() { | |||
m.Post("/create_model", repo.SaveModel) | |||
m.Post("/create_model", reqRepoModelManageWriter, repo.SaveModel) | |||
m.Delete("/delete_model", repo.DeleteModel) | |||
m.Put("/modify_model", repo.ModifyModelInfo) | |||
m.Get("/show_model", reqRepoCloudBrainReader, repo.ShowModelTemplate) | |||
m.Get("/show_model_info", reqRepoCloudBrainReader, repo.ShowModelInfo) | |||
m.Get("/show_model_info_api", reqRepoCloudBrainReader, repo.ShowSingleModel) | |||
m.Get("/show_model_api", reqRepoCloudBrainReader, repo.ShowModelPageInfo) | |||
m.Get("/show_model_child_api", reqRepoCloudBrainReader, repo.ShowOneVersionOtherModel) | |||
m.Get("/show_model", reqRepoModelManageReader, repo.ShowModelTemplate) | |||
m.Get("/show_model_info", repo.ShowModelInfo) | |||
m.Get("/show_model_info_api", repo.ShowSingleModel) | |||
m.Get("/show_model_api", repo.ShowModelPageInfo) | |||
m.Get("/show_model_child_api", repo.ShowOneVersionOtherModel) | |||
m.Get("/query_train_job", reqRepoCloudBrainReader, repo.QueryTrainJobList) | |||
m.Get("/query_train_job_version", reqRepoCloudBrainReader, repo.QueryTrainJobVersionList) | |||
m.Group("/:ID", func() { | |||
m.Get("", reqRepoCloudBrainReader, repo.ShowSingleModel) | |||
m.Get("/downloadsingle", reqRepoCloudBrainReader, repo.DownloadSingleModelFile) | |||
m.Get("", repo.ShowSingleModel) | |||
m.Get("/downloadsingle", repo.DownloadSingleModelFile) | |||
}) | |||
m.Get("/downloadall", reqRepoCloudBrainReader, repo.DownloadMultiModelFile) | |||
m.Get("/downloadall", repo.DownloadMultiModelFile) | |||
}, context.RepoRef()) | |||
m.Group("/modelarts", func() { | |||