From 3cef6a47abc95fbfe3978f95eeffb94939c25354 Mon Sep 17 00:00:00 2001 From: yuyuanshifu <747342561@qq.com> Date: Thu, 28 Jan 2021 17:40:41 +0800 Subject: [PATCH] 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" .}}