Browse Source

fix 902

tags/v1.21.12.1^2
lewis 4 years ago
parent
commit
3880714654
5 changed files with 16 additions and 11 deletions
  1. +1
    -0
      models/user.go
  2. +1
    -2
      modules/context/auth.go
  3. +1
    -0
      modules/context/context.go
  4. +12
    -8
      routers/api/v1/api.go
  5. +1
    -1
      routers/routes/routes.go

+ 1
- 0
models/user.go View File

@@ -145,6 +145,7 @@ type User struct {
AllowImportLocal bool // Allow migrate repository by local path AllowImportLocal bool // Allow migrate repository by local path
AllowCreateOrganization bool `xorm:"DEFAULT true"` AllowCreateOrganization bool `xorm:"DEFAULT true"`
ProhibitLogin bool `xorm:"NOT NULL DEFAULT false"` ProhibitLogin bool `xorm:"NOT NULL DEFAULT false"`
IsOperator bool `xorm:"NOT NULL DEFAULT false"` //运营人员


// Avatar // Avatar
Avatar string `xorm:"VARCHAR(2048) NOT NULL"` Avatar string `xorm:"VARCHAR(2048) NOT NULL"`


+ 1
- 2
modules/context/auth.go View File

@@ -145,8 +145,7 @@ func Toggle(options *ToggleOptions) macaron.Handler {
} }


if options.OperationRequired { if options.OperationRequired {
//todo: add isOperator judgement
if !ctx.User.IsAdmin {
if !ctx.User.IsOperator {
ctx.Error(403) ctx.Error(403)
return return
} }


+ 1
- 0
modules/context/context.go View File

@@ -310,6 +310,7 @@ func Contexter() macaron.Handler {
ctx.Data["SignedUserID"] = ctx.User.ID ctx.Data["SignedUserID"] = ctx.User.ID
ctx.Data["SignedUserName"] = ctx.User.Name ctx.Data["SignedUserName"] = ctx.User.Name
ctx.Data["IsAdmin"] = ctx.User.IsAdmin ctx.Data["IsAdmin"] = ctx.User.IsAdmin
ctx.Data["IsOperator"] = ctx.User.IsOperator
c.Data["SignedUserName"] = ctx.User.Name c.Data["SignedUserName"] = ctx.User.Name
} else { } else {
ctx.Data["SignedUserID"] = int64(0) ctx.Data["SignedUserID"] = int64(0)


+ 12
- 8
routers/api/v1/api.go View File

@@ -75,6 +75,7 @@ import (
"code.gitea.io/gitea/routers/api/v1/repo" "code.gitea.io/gitea/routers/api/v1/repo"
_ "code.gitea.io/gitea/routers/api/v1/swagger" // for swagger generation _ "code.gitea.io/gitea/routers/api/v1/swagger" // for swagger generation
"code.gitea.io/gitea/routers/api/v1/user" "code.gitea.io/gitea/routers/api/v1/user"
repo_ext "code.gitea.io/gitea/routers/repo"


"gitea.com/macaron/binding" "gitea.com/macaron/binding"
"gitea.com/macaron/macaron" "gitea.com/macaron/macaron"
@@ -523,23 +524,26 @@ func RegisterRoutes(m *macaron.Macaron) {
Get(notify.GetThread). Get(notify.GetThread).
Patch(notify.ReadThread) Patch(notify.ReadThread)
}, reqToken()) }, reqToken())
adminReq := context.Toggle(&context.ToggleOptions{SignInRequired: true, AdminRequired: true})
operationReq := context.Toggle(&context.ToggleOptions{SignInRequired: true, OperationRequired: true})
//Project board //Project board
m.Group("/projectboard", func() { m.Group("/projectboard", func() {


m.Get("/restoreFork", adminReq, repo.RestoreForkNumber)
m.Get("/downloadAll", adminReq, repo.ServeAllProjectsPeriodStatisticsFile)
m.Get("/downloadAllOpenI", adminReq, repo.ServeAllProjectsOpenIStatisticsFile)
m.Get("/restoreFork", repo.RestoreForkNumber)
m.Get("/downloadAll", repo.ServeAllProjectsPeriodStatisticsFile)
m.Get("/downloadAllOpenI", repo.ServeAllProjectsOpenIStatisticsFile)
m.Group("/project", func() { m.Group("/project", func() {
m.Get("", adminReq, repo.GetAllProjectsPeriodStatistics)
m.Get("", repo.GetAllProjectsPeriodStatistics)


m.Group("/:id", func() { m.Group("/:id", func() {
m.Get("", adminReq, repo.GetProjectLatestStatistics)
m.Get("/period", adminReq, repo.GetProjectPeriodStatistics)
m.Get("", repo.GetProjectLatestStatistics)
m.Get("/period", repo.GetProjectPeriodStatistics)


}) })
}) })
})
}, operationReq)

m.Get("/query_user_static_page", operationReq, repo_ext.QueryUserStaticDataPage)


// Users // Users
m.Group("/users", func() { m.Group("/users", func() {


+ 1
- 1
routers/routes/routes.go View File

@@ -792,7 +792,7 @@ func RegisterRoutes(m *macaron.Macaron) {
}, reqSignIn, context.RepoAssignment(), context.UnitTypes(), reqRepoAdmin, context.RepoRef()) }, reqSignIn, context.RepoAssignment(), context.UnitTypes(), reqRepoAdmin, context.RepoRef())


m.Post("/:username/:reponame/action/:action", reqSignIn, context.RepoAssignment(), context.UnitTypes(), repo.Action) m.Post("/:username/:reponame/action/:action", reqSignIn, context.RepoAssignment(), context.UnitTypes(), repo.Action)
m.Get("/tool/query_user_static_page", adminReq, repo.QueryUserStaticDataPage)
// Grouping for those endpoints not requiring authentication // Grouping for those endpoints not requiring authentication
m.Group("/:username/:reponame", func() { m.Group("/:username/:reponame", func() {
m.Get("/contributors", repo.Contributors) m.Get("/contributors", repo.Contributors)


Loading…
Cancel
Save