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.

orgs.go 1.8 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2020 The Gitea Authors.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package operation
  6. import (
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/base"
  9. "code.gitea.io/gitea/modules/context"
  10. "code.gitea.io/gitea/modules/log"
  11. "code.gitea.io/gitea/modules/setting"
  12. "code.gitea.io/gitea/modules/structs"
  13. "code.gitea.io/gitea/routers"
  14. )
  15. const (
  16. tplOrgs base.TplName = "admin/org/list"
  17. )
  18. type UpdateRecommendOrgs struct {
  19. OrgInfos string `binding:"required"`
  20. }
  21. type OrgInfo struct {
  22. OrgID int64 `json:"org_id"`
  23. Order int64 `json:"order"`
  24. }
  25. type OrgInfos struct {
  26. OrgInfo []OrgInfo `json:"org_infos"`
  27. }
  28. // Organizations show all the organizations recommended
  29. func Organizations(ctx *context.Context) {
  30. ctx.Data["PageIsAdmin"] = true
  31. ctx.Data["PageIsAdminOrganizations"] = true
  32. routers.RenderUserSearch(ctx, &models.SearchUserOptions{
  33. Type: models.UserTypeOrganization,
  34. ListOptions: models.ListOptions{
  35. PageSize: setting.UI.Admin.OrgPagingNum,
  36. },
  37. Visible: []structs.VisibleType{structs.VisibleTypePublic, structs.VisibleTypeLimited, structs.VisibleTypePrivate},
  38. }, tplOrgs)
  39. }
  40. // UpdateRecommendOrganizations update the organizations recommended
  41. func UpdateRecommendOrganizations(ctx *context.Context, req OrgInfos) {
  42. orgs := make(models.RecommendOrgList, 0, 10)
  43. for _, org := range req.OrgInfo {
  44. orgs = append(orgs, &models.RecommendOrg{
  45. OrgID: org.OrgID,
  46. Order: org.Order,
  47. })
  48. }
  49. if err := models.UpdateRecommendOrgs(orgs); err != nil {
  50. log.Error("UpdateRecommendOrgs failed:%v", err.Error(), ctx.Data["MsgID"])
  51. ctx.ServerError("UpdateRecommendOrgs failed", err)
  52. return
  53. }
  54. }