Browse Source

Merge pull request '#981 优化代码' (#1200) from fix-981 into V20211228

Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/1200
Reviewed-by: lewis <747342561@qq.com>
tags/v1.21.12.2^2
lewis 3 years ago
parent
commit
e8ff7ee4e9
2 changed files with 18 additions and 32 deletions
  1. +1
    -1
      models/repo_tag.go
  2. +17
    -31
      routers/org/tag.go

+ 1
- 1
models/repo_tag.go View File

@@ -156,7 +156,7 @@ func GetOfficialTagDetail(orgID, tagId int64) ([]Repository, error) {
func GetAllOfficialTags() ([]OfficialTag, error) { func GetAllOfficialTags() ([]OfficialTag, error) {
//todo redis? //todo redis?
o := make([]OfficialTag, 0) 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 { if err != nil {
log.Error("GetAllOfficialTags error,%v", err) log.Error("GetAllOfficialTags error,%v", err)
return nil, err return nil, err


+ 17
- 31
routers/org/tag.go View File

@@ -15,12 +15,15 @@ import (


// SubmitTags submit repos of org tag // SubmitTags submit repos of org tag
func SubmitTags(ctx *context.Context, form auth.SubmitReposOfTagForm) { 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() { if ctx.Written() {
return return
} }

err := models.UpdateTagReposByID(tag.ID, org.ID, form.RepoList)
err := models.UpdateTagReposByID(tag.ID, ctx.Org.Organization.ID, form.RepoList)
if err != nil { if err != nil {
ctx.ServerError("UpdateTagReposByID", err) ctx.ServerError("UpdateTagReposByID", err)
return return
@@ -34,12 +37,16 @@ func SubmitTags(ctx *context.Context, form auth.SubmitReposOfTagForm) {


// GetTagRepos get repos under org tag // GetTagRepos get repos under org tag
func GetTagRepos(ctx *context.Context) { 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() { if ctx.Written() {
return return
} }


r, err := models.GetTagRepos(tag.ID, org.ID)
r, err := models.GetTagRepos(tag.ID, ctx.Org.Organization.ID)
if err != nil { if err != nil {
ctx.ServerError("GetTagRepos", err) ctx.ServerError("GetTagRepos", err)
return 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 tag *models.OfficialTag
var err error 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") tagIdStr := ctx.Query("tagId")
if len(tagIdStr) == 0 { if len(tagIdStr) == 0 {
ctx.ServerError("GetTagInfo", errors.New("tag is not exist")) ctx.ServerError("GetTagInfo", errors.New("tag is not exist"))
return nil, nil
return nil
} }
tagId, _ := strconv.ParseInt(tagIdStr, 10, 32) tagId, _ := strconv.ParseInt(tagIdStr, 10, 32)
tag, err = models.GetTagByID(tagId) tag, err = models.GetTagByID(tagId)
@@ -91,8 +77,8 @@ func getOrgAndTagFromContext(ctx *context.Context) (*models.User, *models.Offici
} else { } else {
ctx.ServerError("GetTagInfo", err) ctx.ServerError("GetTagInfo", err)
} }
return nil, nil
return nil
} }


return org, tag
return tag
} }

Loading…
Cancel
Save