You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

permission_json.go 1.1 kB

2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package context
  2. import (
  3. "net/http"
  4. "code.gitea.io/gitea/models"
  5. "code.gitea.io/gitea/modules/log"
  6. "gitea.com/macaron/macaron"
  7. )
  8. func RequireRepoReaderJson(unitType models.UnitType) macaron.Handler {
  9. return func(ctx *Context) {
  10. if !ctx.Repo.CanRead(unitType) {
  11. if log.IsTrace() {
  12. if ctx.IsSigned {
  13. log.Trace("Permission Denied: User %-v cannot read %-v in Repo %-v\n"+
  14. "User in Repo has Permissions: %-+v",
  15. ctx.User,
  16. unitType,
  17. ctx.Repo.Repository,
  18. ctx.Repo.Permission)
  19. } else {
  20. log.Trace("Permission Denied: Anonymous user cannot read %-v in Repo %-v\n"+
  21. "Anonymous user in Repo has Permissions: %-+v",
  22. unitType,
  23. ctx.Repo.Repository,
  24. ctx.Repo.Permission)
  25. }
  26. }
  27. ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("error.no_right")))
  28. return
  29. }
  30. }
  31. }
  32. func RequireRepoWriterJson(unitType models.UnitType) macaron.Handler {
  33. return func(ctx *Context) {
  34. if !ctx.Repo.CanWrite(unitType) {
  35. ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("error.no_right")))
  36. return
  37. }
  38. }
  39. }