From ea59e675ea5ffb430dee033e1673355a8b6531b0 Mon Sep 17 00:00:00 2001 From: chenyifan01 Date: Tue, 31 Jan 2023 11:34:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E9=9D=9E=E5=90=AF=E6=99=BA?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=94=B3=E8=AF=B7=E9=A1=B5=E9=9D=A2=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E8=B7=AF=E5=BE=84=E5=8F=AF=E9=80=89=E7=9A=84=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=92=8C=E7=BB=84=E7=BB=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/api/v1/api.go | 1 + routers/api/v1/org/org.go | 27 +++++++++++++++++++++++++++ services/repository/url.go | 7 ++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 4d92d5ce6..303c345a2 100755 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -1097,6 +1097,7 @@ func RegisterRoutes(m *macaron.Macaron) { // Organizations m.Get("/user/orgs", reqToken(), org.ListMyOrgs) + m.Get("/user/owners", reqToken(), org.GetMyOwners) m.Get("/users/:username/orgs", org.ListUserOrgs) m.Post("/orgs", reqToken(), bind(api.CreateOrgOption{}), org.Create) m.Get("/orgs", org.GetAll) diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go index b79761c87..c22dc6113 100644 --- a/routers/api/v1/org/org.go +++ b/routers/api/v1/org/org.go @@ -6,6 +6,7 @@ package org import ( + "code.gitea.io/gitea/routers/response" "net/http" "code.gitea.io/gitea/models" @@ -278,3 +279,29 @@ func Delete(ctx *context.APIContext) { } 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)) +} diff --git a/services/repository/url.go b/services/repository/url.go index a7642e0a1..6fb364348 100644 --- a/services/repository/url.go +++ b/services/repository/url.go @@ -29,7 +29,12 @@ func parseOpenIUrl(u string) (string, string) { if err != nil { return "", "" } - if !strings.Contains(setting.AppURL, url.Host) { + + appUrl, err := url.Parse(setting.AppURL) + if err != nil { + return "", "" + } + if appUrl.Host != url.Host { return "", "" }