本站源代码
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

98 lines
2.3KB

  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package org
  5. import (
  6. "code.gitea.io/gitea/models"
  7. "code.gitea.io/gitea/modules/base"
  8. "code.gitea.io/gitea/modules/context"
  9. "code.gitea.io/gitea/modules/log"
  10. "code.gitea.io/gitea/modules/setting"
  11. "github.com/unknwon/com"
  12. )
  13. const (
  14. // tplMembers template for organization members page
  15. tplMembers base.TplName = "org/member/members"
  16. )
  17. // Members render organization users page
  18. func Members(ctx *context.Context) {
  19. org := ctx.Org.Organization
  20. ctx.Data["Title"] = org.FullName
  21. ctx.Data["PageIsOrgMembers"] = true
  22. if err := org.GetMembers(); err != nil {
  23. ctx.ServerError("GetMembers", err)
  24. return
  25. }
  26. ctx.Data["Members"] = org.Members
  27. ctx.Data["MembersIsPublicMember"] = org.MembersIsPublic
  28. ctx.Data["MembersIsUserOrgOwner"] = org.Members.IsUserOrgOwner(org.ID)
  29. ctx.Data["MembersTwoFaStatus"] = org.Members.GetTwoFaStatus()
  30. ctx.HTML(200, tplMembers)
  31. }
  32. // MembersAction response for operation to a member of organization
  33. func MembersAction(ctx *context.Context) {
  34. uid := com.StrTo(ctx.Query("uid")).MustInt64()
  35. if uid == 0 {
  36. ctx.Redirect(ctx.Org.OrgLink + "/members")
  37. return
  38. }
  39. org := ctx.Org.Organization
  40. var err error
  41. switch ctx.Params(":action") {
  42. case "private":
  43. if ctx.User.ID != uid && !ctx.Org.IsOwner {
  44. ctx.Error(404)
  45. return
  46. }
  47. err = models.ChangeOrgUserStatus(org.ID, uid, false)
  48. case "public":
  49. if ctx.User.ID != uid && !ctx.Org.IsOwner {
  50. ctx.Error(404)
  51. return
  52. }
  53. err = models.ChangeOrgUserStatus(org.ID, uid, true)
  54. case "remove":
  55. if !ctx.Org.IsOwner {
  56. ctx.Error(404)
  57. return
  58. }
  59. err = org.RemoveMember(uid)
  60. if models.IsErrLastOrgOwner(err) {
  61. ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
  62. ctx.Redirect(ctx.Org.OrgLink + "/members")
  63. return
  64. }
  65. case "leave":
  66. err = org.RemoveMember(ctx.User.ID)
  67. if models.IsErrLastOrgOwner(err) {
  68. ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
  69. ctx.Redirect(ctx.Org.OrgLink + "/members")
  70. return
  71. }
  72. }
  73. if err != nil {
  74. log.Error("Action(%s): %v", ctx.Params(":action"), err)
  75. ctx.JSON(200, map[string]interface{}{
  76. "ok": false,
  77. "err": err.Error(),
  78. })
  79. return
  80. }
  81. if ctx.Params(":action") != "leave" {
  82. ctx.Redirect(ctx.Org.OrgLink + "/members")
  83. } else {
  84. ctx.Redirect(setting.AppSubURL + "/")
  85. }
  86. }
上海开阖软件有限公司 沪ICP备12045867号-1