| @@ -26,6 +26,7 @@ const ( | |||
| UnitTypeExternalTracker // 7 ExternalTracker | |||
| UnitTypeDatasets UnitType = 10 // 10 Dataset | |||
| UnitTypeCloudBrain UnitType = 11 // 11 CloudBrain | |||
| UnitTypeBlockChain UnitType = 12 // 12 BlockChain | |||
| ) | |||
| // Value returns integer value for unit type | |||
| @@ -53,6 +54,8 @@ func (u UnitType) String() string { | |||
| return "UnitTypeDataset" | |||
| case UnitTypeCloudBrain: | |||
| return "UnitTypeCloudBrain" | |||
| case UnitTypeBlockChain: | |||
| return "UnitTypeBlockChain" | |||
| } | |||
| return fmt.Sprintf("Unknown UnitType %d", u) | |||
| } | |||
| @@ -76,6 +79,7 @@ var ( | |||
| UnitTypeExternalTracker, | |||
| UnitTypeDatasets, | |||
| UnitTypeCloudBrain, | |||
| UnitTypeBlockChain, | |||
| } | |||
| // DefaultRepoUnits contains the default unit types | |||
| @@ -87,6 +91,7 @@ var ( | |||
| UnitTypeWiki, | |||
| UnitTypeDatasets, | |||
| UnitTypeCloudBrain, | |||
| UnitTypeBlockChain, | |||
| } | |||
| // NotAllowedDefaultRepoUnits contains units that can't be default | |||
| @@ -268,6 +273,14 @@ var ( | |||
| 6, | |||
| } | |||
| UnitBlockChain = Unit{ | |||
| UnitTypeBlockChain, | |||
| "repo.blockchains", | |||
| "/blockchains", | |||
| "repo.blockchains.desc", | |||
| 7, | |||
| } | |||
| // Units contains all the units | |||
| Units = map[UnitType]Unit{ | |||
| UnitTypeCode: UnitCode, | |||
| @@ -279,6 +292,7 @@ var ( | |||
| UnitTypeExternalWiki: UnitExternalWiki, | |||
| UnitTypeDatasets: UnitDataset, | |||
| UnitTypeCloudBrain: UnitCloudBrain, | |||
| UnitTypeBlockChain: UnitBlockChain, | |||
| } | |||
| ) | |||
| @@ -1,13 +1,14 @@ | |||
| package repo | |||
| import ( | |||
| "encoding/json" | |||
| "strconv" | |||
| "code.gitea.io/gitea/models" | |||
| "code.gitea.io/gitea/modules/base" | |||
| "code.gitea.io/gitea/modules/blockchain" | |||
| "code.gitea.io/gitea/modules/context" | |||
| "code.gitea.io/gitea/modules/log" | |||
| "encoding/json" | |||
| "net/http" | |||
| "strconv" | |||
| ) | |||
| type BlockChainInitNotify struct { | |||
| @@ -19,6 +20,37 @@ type BlockChainCommitNotify struct { | |||
| CommitID string `json:"commitId"` | |||
| TransactionHash string `json:"txHash"` | |||
| } | |||
| const ( | |||
| tplBlockChainIndex base.TplName = "repo/blockchain/balance" | |||
| ) | |||
| // 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) | |||
| ctx.HTML(http.StatusInternalServerError, tplBlockChainIndex) | |||
| return | |||
| } | |||
| res, err := blockchain.GetBalance(repo.ContractAddress, ctx.User.PublicKey) | |||
| if err != nil { | |||
| log.Error("GetBalance(%s) failed:%v", ctx.User.PublicKey, err) | |||
| ctx.HTML(http.StatusInternalServerError, tplBlockChainIndex) | |||
| return | |||
| } | |||
| ctx.Data["balance"] = res.Data | |||
| ctx.HTML(200, tplBlockChainIndex) | |||
| } | |||
| func HandleBlockChainInitNotify(ctx *context.Context) { | |||
| var req BlockChainInitNotify | |||
| @@ -7,7 +7,6 @@ package repo | |||
| import ( | |||
| "bytes" | |||
| "code.gitea.io/gitea/modules/blockchain" | |||
| "errors" | |||
| "fmt" | |||
| "io/ioutil" | |||
| @@ -510,7 +509,7 @@ func NewIssue(ctx *context.Context) { | |||
| ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWrite(models.UnitTypeIssues) | |||
| if ctx.Repo.Repository.ContractAddress == "" || ctx.User.PublicKey == ""{ | |||
| /*if ctx.Repo.Repository.ContractAddress == "" || ctx.User.PublicKey == ""{ | |||
| log.Error("the repo(%d) or the user(%d) has not been initialized in block_chain", ctx.Repo.Repository.ID, ctx.User.ID) | |||
| ctx.HTML(http.StatusInternalServerError, tplIssueNew) | |||
| return | |||
| @@ -523,7 +522,7 @@ func NewIssue(ctx *context.Context) { | |||
| return | |||
| } | |||
| ctx.Data["balance"] = res.Data | |||
| ctx.Data["balance"] = res.Data*/ | |||
| ctx.HTML(200, tplIssueNew) | |||
| } | |||
| @@ -653,7 +652,7 @@ func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) { | |||
| Ref: form.Ref, | |||
| } | |||
| if repo.ContractAddress == "" || ctx.User.PublicKey == ""{ | |||
| /*if repo.ContractAddress == "" || ctx.User.PublicKey == ""{ | |||
| log.Error("the repo(%d) or the user(%d) has not been initialized in block_chain", issue.RepoID, ctx.User.ID) | |||
| ctx.HTML(http.StatusInternalServerError, tplIssueNew) | |||
| return | |||
| @@ -678,7 +677,7 @@ func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) { | |||
| return | |||
| } | |||
| issue.Amount = form.Rewards | |||
| issue.Amount = form.Rewards*/ | |||
| if err := issue_service.NewIssue(repo, issue, labelIDs, attachments, assigneeIDs); err != nil { | |||
| if models.IsErrUserDoesNotHaveAccessToRepo(err) { | |||
| @@ -568,6 +568,8 @@ 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) | |||
| //reqRepoBlockChainWriter := context.RequireRepoWriter(models.UnitTypeBlockChain) | |||
| // ***** START: Organization ***** | |||
| m.Group("/org", func() { | |||
| @@ -911,6 +913,10 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
| m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateCloudBrainForm{}), repo.CloudBrainCreate) | |||
| }, context.RepoRef()) | |||
| m.Group("/blockchain", func() { | |||
| m.Get("", reqRepoBlockChainReader, repo.BlockChainIndex) | |||
| }, context.RepoRef()) | |||
| m.Group("/wiki", func() { | |||
| m.Get("/?:page", repo.Wiki) | |||
| m.Get("/_pages", repo.WikiPages) | |||