Browse Source

新建非启智项目申请页面项目路径可选的用户和组织

2023
chenyifan01 2 years ago
parent
commit
ea59e675ea
3 changed files with 34 additions and 1 deletions
  1. +1
    -0
      routers/api/v1/api.go
  2. +27
    -0
      routers/api/v1/org/org.go
  3. +6
    -1
      services/repository/url.go

+ 1
- 0
routers/api/v1/api.go View File

@@ -1097,6 +1097,7 @@ func RegisterRoutes(m *macaron.Macaron) {


// Organizations // Organizations
m.Get("/user/orgs", reqToken(), org.ListMyOrgs) m.Get("/user/orgs", reqToken(), org.ListMyOrgs)
m.Get("/user/owners", reqToken(), org.GetMyOwners)
m.Get("/users/:username/orgs", org.ListUserOrgs) m.Get("/users/:username/orgs", org.ListUserOrgs)
m.Post("/orgs", reqToken(), bind(api.CreateOrgOption{}), org.Create) m.Post("/orgs", reqToken(), bind(api.CreateOrgOption{}), org.Create)
m.Get("/orgs", org.GetAll) m.Get("/orgs", org.GetAll)


+ 27
- 0
routers/api/v1/org/org.go View File

@@ -6,6 +6,7 @@
package org package org


import ( import (
"code.gitea.io/gitea/routers/response"
"net/http" "net/http"


"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
@@ -278,3 +279,29 @@ func Delete(ctx *context.APIContext) {
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)
} }

func GetMyOwners(ctx *context.APIContext) {
result := make([]*models.User4Front, 0)
result = append(result, ctx.User.ToFrontFormat())

orgs, err := models.GetOrgsCanCreateRepoByUserID(ctx.User.ID)
if err != nil {
ctx.JSON(http.StatusOK, response.ResponseError(err))
return
}

if !ctx.User.IsAdmin {
orgsAvailable := []*models.User{}
for i := 0; i < len(orgs); i++ {
if orgs[i].CanCreateRepo() {
orgsAvailable = append(orgsAvailable, orgs[i])
}
}
orgs = orgsAvailable
}

for _, o := range orgs {
result = append(result, o.ToFrontFormat())
}
ctx.JSON(http.StatusOK, response.SuccessWithData(result))
}

+ 6
- 1
services/repository/url.go View File

@@ -29,7 +29,12 @@ func parseOpenIUrl(u string) (string, string) {
if err != nil { if err != nil {
return "", "" return "", ""
} }
if !strings.Contains(setting.AppURL, url.Host) {

appUrl, err := url.Parse(setting.AppURL)
if err != nil {
return "", ""
}
if appUrl.Host != url.Host {
return "", "" return "", ""
} }




Loading…
Cancel
Save