From 71d7d2b9e010fc129dfdc322c952733b7f10d4b8 Mon Sep 17 00:00:00 2001 From: chenyifan01 Date: Mon, 27 Dec 2021 15:01:16 +0800 Subject: [PATCH 1/2] #981 update --- routers/org/tag.go | 48 ++++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/routers/org/tag.go b/routers/org/tag.go index 650d4690c..e28151268 100644 --- a/routers/org/tag.go +++ b/routers/org/tag.go @@ -15,12 +15,15 @@ import ( // SubmitTags submit repos of org tag func SubmitTags(ctx *context.Context, form auth.SubmitReposOfTagForm) { - org, tag := getOrgAndTagFromContext(ctx) + if !ctx.Org.IsOwner { + ctx.ServerError("UpdateTagReposByID", errors.New("no access to submit tags")) + return + } + tag := getTagFromContext(ctx) if ctx.Written() { return } - - err := models.UpdateTagReposByID(tag.ID, org.ID, form.RepoList) + err := models.UpdateTagReposByID(tag.ID, ctx.Org.Organization.ID, form.RepoList) if err != nil { ctx.ServerError("UpdateTagReposByID", err) return @@ -34,12 +37,16 @@ func SubmitTags(ctx *context.Context, form auth.SubmitReposOfTagForm) { // GetTagRepos get repos under org tag func GetTagRepos(ctx *context.Context) { - org, tag := getOrgAndTagFromContext(ctx) + if !ctx.Org.IsOwner { + ctx.ServerError("GetTagRepos", errors.New("no access to get tags")) + return + } + tag := getTagFromContext(ctx) if ctx.Written() { return } - r, err := models.GetTagRepos(tag.ID, org.ID) + r, err := models.GetTagRepos(tag.ID, ctx.Org.Organization.ID) if err != nil { ctx.ServerError("GetTagRepos", err) return @@ -52,36 +59,15 @@ func GetTagRepos(ctx *context.Context) { }) } -// getDashboardContextUser finds out dashboard is viewing as which context user. -func getOrgAndTagFromContext(ctx *context.Context) (*models.User, *models.OfficialTag) { - - var org *models.User +// getTagFromContext finds out tag info From context. +func getTagFromContext(ctx *context.Context) *models.OfficialTag { var tag *models.OfficialTag var err error - orgName := ctx.Params(":org") - - if len(orgName) > 0 { - // Organization. - org, err = models.GetUserByName(orgName) - if err != nil { - if models.IsErrUserNotExist(err) { - ctx.NotFound("GetUserByName", err) - } else { - ctx.ServerError("GetUserByName", err) - } - return nil, nil - } - if !org.IsOrganization() { - ctx.ServerError("GetUserByName", errors.New("it is not an organization")) - return nil, nil - } - } - tagIdStr := ctx.Query("tagId") if len(tagIdStr) == 0 { ctx.ServerError("GetTagInfo", errors.New("tag is not exist")) - return nil, nil + return nil } tagId, _ := strconv.ParseInt(tagIdStr, 10, 32) tag, err = models.GetTagByID(tagId) @@ -91,8 +77,8 @@ func getOrgAndTagFromContext(ctx *context.Context) (*models.User, *models.Offici } else { ctx.ServerError("GetTagInfo", err) } - return nil, nil + return nil } - return org, tag + return tag } From fa0752c8c4e0025b9de0a129e5fb0289c9e7cc78 Mon Sep 17 00:00:00 2001 From: chenyifan01 Date: Mon, 27 Dec 2021 15:09:21 +0800 Subject: [PATCH 2/2] #981 update --- models/repo_tag.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/repo_tag.go b/models/repo_tag.go index c8e675d75..5072153ea 100644 --- a/models/repo_tag.go +++ b/models/repo_tag.go @@ -156,7 +156,7 @@ func GetOfficialTagDetail(orgID, tagId int64) ([]Repository, error) { func GetAllOfficialTags() ([]OfficialTag, error) { //todo redis? o := make([]OfficialTag, 0) - err := x.Where("status = ?", 0).Find(&o) + err := x.Where("status = ?", 0).OrderBy("updated_unix desc").Find(&o) if err != nil { log.Error("GetAllOfficialTags error,%v", err) return nil, err