From c4bd1818b3dcc657ca6ad86cee16b17cb6da8938 Mon Sep 17 00:00:00 2001 From: yuyuanshifu <747342561@qq.com> Date: Thu, 28 Jan 2021 17:40:41 +0800 Subject: [PATCH 1/3] fix --- models/repo.go | 6 ++++++ models/repo_unit.go | 16 ++++++++++++++++ routers/repo/blockchain.go | 2 +- templates/repo/header.tmpl | 2 -- 4 files changed, 23 insertions(+), 3 deletions(-) mode change 100644 => 100755 models/repo_unit.go diff --git a/models/repo.go b/models/repo.go index 1228a79ba..f99e909ae 100755 --- a/models/repo.go +++ b/models/repo.go @@ -1105,6 +1105,12 @@ func CreateRepository(ctx DBContext, doer, u *User, repo *Repository) (err error Type: tp, Config: &CloudBrainConfig{EnableCloudBrain: true}, }) + } else if tp == UnitTypeBlockChain { + units = append(units, RepoUnit{ + RepoID: repo.ID, + Type: tp, + Config: &BlockChainConfig{EnableBlockChain: true}, + }) } else { units = append(units, RepoUnit{ RepoID: repo.ID, diff --git a/models/repo_unit.go b/models/repo_unit.go old mode 100644 new mode 100755 index a0e7a2f76..518c4b979 --- a/models/repo_unit.go +++ b/models/repo_unit.go @@ -141,6 +141,20 @@ func (cfg *CloudBrainConfig) ToDB() ([]byte, error) { return json.Marshal(cfg) } +type BlockChainConfig struct { + EnableBlockChain bool +} + +// FromDB fills up a CloudBrainConfig from serialized format. +func (cfg *BlockChainConfig) FromDB(bs []byte) error { + return json.Unmarshal(bs, &cfg) +} + +// ToDB exports a CloudBrainConfig to a serialized format. +func (cfg *BlockChainConfig) 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 { @@ -160,6 +174,8 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) { r.Config = new(DatasetConfig) case UnitTypeCloudBrain: r.Config = new(CloudBrainConfig) + case UnitTypeBlockChain: + r.Config = new(BlockChainConfig) default: panic("unrecognized repo unit type: " + com.ToStr(*val)) } diff --git a/routers/repo/blockchain.go b/routers/repo/blockchain.go index 9f2e9f2d4..e487f1dcf 100755 --- a/routers/repo/blockchain.go +++ b/routers/repo/blockchain.go @@ -33,7 +33,7 @@ func MustEnableBlockChain(ctx *context.Context) { } func BlockChainIndex(ctx *context.Context) { - MustEnableBlockChain(ctx) + //MustEnableBlockChain(ctx) repo := ctx.Repo.Repository if repo.ContractAddress == "" || ctx.User.PublicKey == ""{ log.Error("the repo(%d) or the user(%d) has not been initialized in block_chain", repo.RepoID, ctx.User.ID) diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index e10e91e34..f9ce6a17a 100755 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -145,11 +145,9 @@ {{end}} - {{if .Permission.CanRead $.UnitTypeBlockChain}} {{.i18n.Tr "repo.balance"}} - {{end}} {{template "custom/extra_tabs" .}} From 19f5d10d89d8797fa4e0243814e93b24b399cd8e Mon Sep 17 00:00:00 2001 From: yuyuanshifu <747342561@qq.com> Date: Thu, 28 Jan 2021 19:16:33 +0800 Subject: [PATCH 2/3] index --- routers/repo/blockchain.go | 9 --------- routers/routes/routes.go | 4 ++-- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/routers/repo/blockchain.go b/routers/repo/blockchain.go index e487f1dcf..33129d7e4 100755 --- a/routers/repo/blockchain.go +++ b/routers/repo/blockchain.go @@ -24,16 +24,7 @@ const ( tplBlockChainIndex base.TplName = "repo/blockchain/index" ) -// MustEnableDataset check if repository enable internal cb -func MustEnableBlockChain(ctx *context.Context) { - if !ctx.Repo.CanRead(models.UnitTypeBlockChain) { - ctx.NotFound("MustEnableBlockChain", nil) - return - } -} - func BlockChainIndex(ctx *context.Context) { - //MustEnableBlockChain(ctx) repo := ctx.Repo.Repository if repo.ContractAddress == "" || ctx.User.PublicKey == ""{ log.Error("the repo(%d) or the user(%d) has not been initialized in block_chain", repo.RepoID, ctx.User.ID) diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 67186ccd2..8831e20a5 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -568,7 +568,7 @@ func RegisterRoutes(m *macaron.Macaron) { reqRepoDatasetWriter := context.RequireRepoWriter(models.UnitTypeDatasets) reqRepoCloudBrainReader := context.RequireRepoReader(models.UnitTypeCloudBrain) reqRepoCloudBrainWriter := context.RequireRepoWriter(models.UnitTypeCloudBrain) - reqRepoBlockChainReader := context.RequireRepoReader(models.UnitTypeBlockChain) + //reqRepoBlockChainReader := context.RequireRepoReader(models.UnitTypeBlockChain) //reqRepoBlockChainWriter := context.RequireRepoWriter(models.UnitTypeBlockChain) // ***** START: Organization ***** @@ -914,7 +914,7 @@ func RegisterRoutes(m *macaron.Macaron) { }, context.RepoRef()) m.Group("/blockchain", func() { - m.Get("", reqRepoBlockChainReader, repo.BlockChainIndex) + m.Get("", repo.BlockChainIndex) }, context.RepoRef()) m.Group("/wiki", func() { From 323408d409ee9afe7565a75501ad309a1f0d3182 Mon Sep 17 00:00:00 2001 From: yuyuanshifu <747342561@qq.com> Date: Thu, 28 Jan 2021 19:21:39 +0800 Subject: [PATCH 3/3] fix html --- templates/repo/blockchain/index.tmpl | 96 +----------------------------------- 1 file changed, 2 insertions(+), 94 deletions(-) diff --git a/templates/repo/blockchain/index.tmpl b/templates/repo/blockchain/index.tmpl index a68381b01..3ce0f0e8b 100755 --- a/templates/repo/blockchain/index.tmpl +++ b/templates/repo/blockchain/index.tmpl @@ -12,101 +12,9 @@