aboutsummaryrefslogtreecommitdiffstats
path: root/routers/org
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-06-09 07:33:54 +0800
committerGitHub <noreply@github.com>2021-06-09 01:33:54 +0200
commit1bfb0a24d843e10d6d95c4319a84980485e584ed (patch)
treee4a736f9abee3eaad1270bf3b60ee3bb9401a9dc /routers/org
parente03a91a48ef7fb716cc7c8bfb411ca8f332dcfe5 (diff)
downloadgitea-1bfb0a24d843e10d6d95c4319a84980485e584ed.tar.gz
gitea-1bfb0a24d843e10d6d95c4319a84980485e584ed.zip
Refactor routers directory (#15800)
* refactor routers directory * move func used for web and api to common * make corsHandler a function to prohibit side efects * rm unused func Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'routers/org')
-rw-r--r--routers/org/home.go151
-rw-r--r--routers/org/members.go128
-rw-r--r--routers/org/org.go79
-rw-r--r--routers/org/org_labels.go112
-rw-r--r--routers/org/setting.go219
-rw-r--r--routers/org/teams.go357
6 files changed, 0 insertions, 1046 deletions
diff --git a/routers/org/home.go b/routers/org/home.go
deleted file mode 100644
index d84ae870ab..0000000000
--- a/routers/org/home.go
+++ /dev/null
@@ -1,151 +0,0 @@
-// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package org
-
-import (
- "net/http"
- "strings"
-
- "code.gitea.io/gitea/models"
- "code.gitea.io/gitea/modules/base"
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/markup"
- "code.gitea.io/gitea/modules/markup/markdown"
- "code.gitea.io/gitea/modules/setting"
-)
-
-const (
- tplOrgHome base.TplName = "org/home"
-)
-
-// Home show organization home page
-func Home(ctx *context.Context) {
- ctx.SetParams(":org", ctx.Params(":username"))
- context.HandleOrgAssignment(ctx)
- if ctx.Written() {
- return
- }
-
- org := ctx.Org.Organization
-
- if !models.HasOrgVisible(org, ctx.User) {
- ctx.NotFound("HasOrgVisible", nil)
- return
- }
-
- ctx.Data["PageIsUserProfile"] = true
- ctx.Data["Title"] = org.DisplayName()
- if len(org.Description) != 0 {
- desc, err := markdown.RenderString(&markup.RenderContext{
- URLPrefix: ctx.Repo.RepoLink,
- Metas: map[string]string{"mode": "document"},
- }, org.Description)
- if err != nil {
- ctx.ServerError("RenderString", err)
- return
- }
- ctx.Data["RenderedDescription"] = desc
- }
-
- var orderBy models.SearchOrderBy
- ctx.Data["SortType"] = ctx.Query("sort")
- switch ctx.Query("sort") {
- case "newest":
- orderBy = models.SearchOrderByNewest
- case "oldest":
- orderBy = models.SearchOrderByOldest
- case "recentupdate":
- orderBy = models.SearchOrderByRecentUpdated
- case "leastupdate":
- orderBy = models.SearchOrderByLeastUpdated
- case "reversealphabetically":
- orderBy = models.SearchOrderByAlphabeticallyReverse
- case "alphabetically":
- orderBy = models.SearchOrderByAlphabetically
- case "moststars":
- orderBy = models.SearchOrderByStarsReverse
- case "feweststars":
- orderBy = models.SearchOrderByStars
- case "mostforks":
- orderBy = models.SearchOrderByForksReverse
- case "fewestforks":
- orderBy = models.SearchOrderByForks
- default:
- ctx.Data["SortType"] = "recentupdate"
- orderBy = models.SearchOrderByRecentUpdated
- }
-
- keyword := strings.Trim(ctx.Query("q"), " ")
- ctx.Data["Keyword"] = keyword
-
- page := ctx.QueryInt("page")
- if page <= 0 {
- page = 1
- }
-
- var (
- repos []*models.Repository
- count int64
- err error
- )
- repos, count, err = models.SearchRepository(&models.SearchRepoOptions{
- ListOptions: models.ListOptions{
- PageSize: setting.UI.User.RepoPagingNum,
- Page: page,
- },
- Keyword: keyword,
- OwnerID: org.ID,
- OrderBy: orderBy,
- Private: ctx.IsSigned,
- Actor: ctx.User,
- IncludeDescription: setting.UI.SearchRepoDescription,
- })
- if err != nil {
- ctx.ServerError("SearchRepository", err)
- return
- }
-
- var opts = models.FindOrgMembersOpts{
- OrgID: org.ID,
- PublicOnly: true,
- ListOptions: models.ListOptions{Page: 1, PageSize: 25},
- }
-
- if ctx.User != nil {
- isMember, err := org.IsOrgMember(ctx.User.ID)
- if err != nil {
- ctx.Error(http.StatusInternalServerError, "IsOrgMember")
- return
- }
- opts.PublicOnly = !isMember && !ctx.User.IsAdmin
- }
-
- members, _, err := models.FindOrgMembers(&opts)
- if err != nil {
- ctx.ServerError("FindOrgMembers", err)
- return
- }
-
- membersCount, err := models.CountOrgMembers(opts)
- if err != nil {
- ctx.ServerError("CountOrgMembers", err)
- return
- }
-
- ctx.Data["Owner"] = org
- ctx.Data["Repos"] = repos
- ctx.Data["Total"] = count
- ctx.Data["MembersTotal"] = membersCount
- ctx.Data["Members"] = members
- ctx.Data["Teams"] = org.Teams
-
- ctx.Data["DisabledMirrors"] = setting.Repository.DisableMirrors
-
- pager := context.NewPagination(int(count), setting.UI.User.RepoPagingNum, page, 5)
- pager.SetDefaultParams(ctx)
- ctx.Data["Page"] = pager
-
- ctx.HTML(http.StatusOK, tplOrgHome)
-}
diff --git a/routers/org/members.go b/routers/org/members.go
deleted file mode 100644
index 934529d7d7..0000000000
--- a/routers/org/members.go
+++ /dev/null
@@ -1,128 +0,0 @@
-// Copyright 2014 The Gogs Authors. All rights reserved.
-// Copyright 2020 The Gitea Authors.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package org
-
-import (
- "net/http"
-
- "code.gitea.io/gitea/models"
- "code.gitea.io/gitea/modules/base"
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/setting"
-)
-
-const (
- // tplMembers template for organization members page
- tplMembers base.TplName = "org/member/members"
-)
-
-// Members render organization users page
-func Members(ctx *context.Context) {
- org := ctx.Org.Organization
- ctx.Data["Title"] = org.FullName
- ctx.Data["PageIsOrgMembers"] = true
-
- page := ctx.QueryInt("page")
- if page <= 1 {
- page = 1
- }
-
- var opts = models.FindOrgMembersOpts{
- OrgID: org.ID,
- PublicOnly: true,
- }
-
- if ctx.User != nil {
- isMember, err := ctx.Org.Organization.IsOrgMember(ctx.User.ID)
- if err != nil {
- ctx.Error(http.StatusInternalServerError, "IsOrgMember")
- return
- }
- opts.PublicOnly = !isMember && !ctx.User.IsAdmin
- }
-
- total, err := models.CountOrgMembers(opts)
- if err != nil {
- ctx.Error(http.StatusInternalServerError, "CountOrgMembers")
- return
- }
-
- pager := context.NewPagination(int(total), setting.UI.MembersPagingNum, page, 5)
- opts.ListOptions.Page = page
- opts.ListOptions.PageSize = setting.UI.MembersPagingNum
- members, membersIsPublic, err := models.FindOrgMembers(&opts)
- if err != nil {
- ctx.ServerError("GetMembers", err)
- return
- }
- ctx.Data["Page"] = pager
- ctx.Data["Members"] = members
- ctx.Data["MembersIsPublicMember"] = membersIsPublic
- ctx.Data["MembersIsUserOrgOwner"] = members.IsUserOrgOwner(org.ID)
- ctx.Data["MembersTwoFaStatus"] = members.GetTwoFaStatus()
-
- ctx.HTML(http.StatusOK, tplMembers)
-}
-
-// MembersAction response for operation to a member of organization
-func MembersAction(ctx *context.Context) {
- uid := ctx.QueryInt64("uid")
- if uid == 0 {
- ctx.Redirect(ctx.Org.OrgLink + "/members")
- return
- }
-
- org := ctx.Org.Organization
- var err error
- switch ctx.Params(":action") {
- case "private":
- if ctx.User.ID != uid && !ctx.Org.IsOwner {
- ctx.Error(http.StatusNotFound)
- return
- }
- err = models.ChangeOrgUserStatus(org.ID, uid, false)
- case "public":
- if ctx.User.ID != uid && !ctx.Org.IsOwner {
- ctx.Error(http.StatusNotFound)
- return
- }
- err = models.ChangeOrgUserStatus(org.ID, uid, true)
- case "remove":
- if !ctx.Org.IsOwner {
- ctx.Error(http.StatusNotFound)
- return
- }
- err = org.RemoveMember(uid)
- if models.IsErrLastOrgOwner(err) {
- ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
- ctx.Redirect(ctx.Org.OrgLink + "/members")
- return
- }
- case "leave":
- err = org.RemoveMember(ctx.User.ID)
- if models.IsErrLastOrgOwner(err) {
- ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
- ctx.Redirect(ctx.Org.OrgLink + "/members")
- return
- }
- }
-
- if err != nil {
- log.Error("Action(%s): %v", ctx.Params(":action"), err)
- ctx.JSON(http.StatusOK, map[string]interface{}{
- "ok": false,
- "err": err.Error(),
- })
- return
- }
-
- if ctx.Params(":action") != "leave" {
- ctx.Redirect(ctx.Org.OrgLink + "/members")
- } else {
- ctx.Redirect(setting.AppSubURL + "/")
- }
-}
diff --git a/routers/org/org.go b/routers/org/org.go
deleted file mode 100644
index beba3daca4..0000000000
--- a/routers/org/org.go
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright 2014 The Gogs Authors. All rights reserved.
-// Copyright 2018 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package org
-
-import (
- "errors"
- "net/http"
-
- "code.gitea.io/gitea/models"
- "code.gitea.io/gitea/modules/base"
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/setting"
- "code.gitea.io/gitea/modules/web"
- "code.gitea.io/gitea/services/forms"
-)
-
-const (
- // tplCreateOrg template path for create organization
- tplCreateOrg base.TplName = "org/create"
-)
-
-// Create render the page for create organization
-func Create(ctx *context.Context) {
- ctx.Data["Title"] = ctx.Tr("new_org")
- ctx.Data["DefaultOrgVisibilityMode"] = setting.Service.DefaultOrgVisibilityMode
- if !ctx.User.CanCreateOrganization() {
- ctx.ServerError("Not allowed", errors.New(ctx.Tr("org.form.create_org_not_allowed")))
- return
- }
- ctx.HTML(http.StatusOK, tplCreateOrg)
-}
-
-// CreatePost response for create organization
-func CreatePost(ctx *context.Context) {
- form := *web.GetForm(ctx).(*forms.CreateOrgForm)
- ctx.Data["Title"] = ctx.Tr("new_org")
-
- if !ctx.User.CanCreateOrganization() {
- ctx.ServerError("Not allowed", errors.New(ctx.Tr("org.form.create_org_not_allowed")))
- return
- }
-
- if ctx.HasError() {
- ctx.HTML(http.StatusOK, tplCreateOrg)
- return
- }
-
- org := &models.User{
- Name: form.OrgName,
- IsActive: true,
- Type: models.UserTypeOrganization,
- Visibility: form.Visibility,
- RepoAdminChangeTeamAccess: form.RepoAdminChangeTeamAccess,
- }
-
- if err := models.CreateOrganization(org, ctx.User); err != nil {
- ctx.Data["Err_OrgName"] = true
- switch {
- case models.IsErrUserAlreadyExist(err):
- ctx.RenderWithErr(ctx.Tr("form.org_name_been_taken"), tplCreateOrg, &form)
- case models.IsErrNameReserved(err):
- ctx.RenderWithErr(ctx.Tr("org.form.name_reserved", err.(models.ErrNameReserved).Name), tplCreateOrg, &form)
- case models.IsErrNamePatternNotAllowed(err):
- ctx.RenderWithErr(ctx.Tr("org.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplCreateOrg, &form)
- case models.IsErrUserNotAllowedCreateOrg(err):
- ctx.RenderWithErr(ctx.Tr("org.form.create_org_not_allowed"), tplCreateOrg, &form)
- default:
- ctx.ServerError("CreateOrganization", err)
- }
- return
- }
- log.Trace("Organization created: %s", org.Name)
-
- ctx.Redirect(org.DashboardLink())
-}
diff --git a/routers/org/org_labels.go b/routers/org/org_labels.go
deleted file mode 100644
index 26e232bcc9..0000000000
--- a/routers/org/org_labels.go
+++ /dev/null
@@ -1,112 +0,0 @@
-// Copyright 2020 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package org
-
-import (
- "net/http"
-
- "code.gitea.io/gitea/models"
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/web"
- "code.gitea.io/gitea/services/forms"
-)
-
-// RetrieveLabels find all the labels of an organization
-func RetrieveLabels(ctx *context.Context) {
- labels, err := models.GetLabelsByOrgID(ctx.Org.Organization.ID, ctx.Query("sort"), models.ListOptions{})
- if err != nil {
- ctx.ServerError("RetrieveLabels.GetLabels", err)
- return
- }
- for _, l := range labels {
- l.CalOpenIssues()
- }
- ctx.Data["Labels"] = labels
- ctx.Data["NumLabels"] = len(labels)
- ctx.Data["SortType"] = ctx.Query("sort")
-}
-
-// NewLabel create new label for organization
-func NewLabel(ctx *context.Context) {
- form := web.GetForm(ctx).(*forms.CreateLabelForm)
- ctx.Data["Title"] = ctx.Tr("repo.labels")
- ctx.Data["PageIsLabels"] = true
-
- if ctx.HasError() {
- ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
- ctx.Redirect(ctx.Org.OrgLink + "/settings/labels")
- return
- }
-
- l := &models.Label{
- OrgID: ctx.Org.Organization.ID,
- Name: form.Title,
- Description: form.Description,
- Color: form.Color,
- }
- if err := models.NewLabel(l); err != nil {
- ctx.ServerError("NewLabel", err)
- return
- }
- ctx.Redirect(ctx.Org.OrgLink + "/settings/labels")
-}
-
-// UpdateLabel update a label's name and color
-func UpdateLabel(ctx *context.Context) {
- form := web.GetForm(ctx).(*forms.CreateLabelForm)
- l, err := models.GetLabelInOrgByID(ctx.Org.Organization.ID, form.ID)
- if err != nil {
- switch {
- case models.IsErrOrgLabelNotExist(err):
- ctx.Error(http.StatusNotFound)
- default:
- ctx.ServerError("UpdateLabel", err)
- }
- return
- }
-
- l.Name = form.Title
- l.Description = form.Description
- l.Color = form.Color
- if err := models.UpdateLabel(l); err != nil {
- ctx.ServerError("UpdateLabel", err)
- return
- }
- ctx.Redirect(ctx.Org.OrgLink + "/settings/labels")
-}
-
-// DeleteLabel delete a label
-func DeleteLabel(ctx *context.Context) {
- if err := models.DeleteLabel(ctx.Org.Organization.ID, ctx.QueryInt64("id")); err != nil {
- ctx.Flash.Error("DeleteLabel: " + err.Error())
- } else {
- ctx.Flash.Success(ctx.Tr("repo.issues.label_deletion_success"))
- }
-
- ctx.JSON(http.StatusOK, map[string]interface{}{
- "redirect": ctx.Org.OrgLink + "/settings/labels",
- })
-}
-
-// InitializeLabels init labels for an organization
-func InitializeLabels(ctx *context.Context) {
- form := web.GetForm(ctx).(*forms.InitializeLabelsForm)
- if ctx.HasError() {
- ctx.Redirect(ctx.Repo.RepoLink + "/labels")
- return
- }
-
- if err := models.InitializeLabels(models.DefaultDBContext(), ctx.Org.Organization.ID, form.TemplateName, true); err != nil {
- if models.IsErrIssueLabelTemplateLoad(err) {
- originalErr := err.(models.ErrIssueLabelTemplateLoad).OriginalError
- ctx.Flash.Error(ctx.Tr("repo.issues.label_templates.fail_to_load_file", form.TemplateName, originalErr))
- ctx.Redirect(ctx.Org.OrgLink + "/settings/labels")
- return
- }
- ctx.ServerError("InitializeLabels", err)
- return
- }
- ctx.Redirect(ctx.Org.OrgLink + "/settings/labels")
-}
diff --git a/routers/org/setting.go b/routers/org/setting.go
deleted file mode 100644
index 0e28a93ace..0000000000
--- a/routers/org/setting.go
+++ /dev/null
@@ -1,219 +0,0 @@
-// Copyright 2014 The Gogs Authors. All rights reserved.
-// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package org
-
-import (
- "net/http"
- "strings"
-
- "code.gitea.io/gitea/models"
- "code.gitea.io/gitea/modules/base"
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/setting"
- "code.gitea.io/gitea/modules/web"
- userSetting "code.gitea.io/gitea/routers/user/setting"
- "code.gitea.io/gitea/services/forms"
-)
-
-const (
- // tplSettingsOptions template path for render settings
- tplSettingsOptions base.TplName = "org/settings/options"
- // tplSettingsDelete template path for render delete repository
- tplSettingsDelete base.TplName = "org/settings/delete"
- // tplSettingsHooks template path for render hook settings
- tplSettingsHooks base.TplName = "org/settings/hooks"
- // tplSettingsLabels template path for render labels settings
- tplSettingsLabels base.TplName = "org/settings/labels"
-)
-
-// Settings render the main settings page
-func Settings(ctx *context.Context) {
- ctx.Data["Title"] = ctx.Tr("org.settings")
- ctx.Data["PageIsSettingsOptions"] = true
- ctx.Data["CurrentVisibility"] = ctx.Org.Organization.Visibility
- ctx.Data["RepoAdminChangeTeamAccess"] = ctx.Org.Organization.RepoAdminChangeTeamAccess
- ctx.HTML(http.StatusOK, tplSettingsOptions)
-}
-
-// SettingsPost response for settings change submited
-func SettingsPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*forms.UpdateOrgSettingForm)
- ctx.Data["Title"] = ctx.Tr("org.settings")
- ctx.Data["PageIsSettingsOptions"] = true
- ctx.Data["CurrentVisibility"] = ctx.Org.Organization.Visibility
-
- if ctx.HasError() {
- ctx.HTML(http.StatusOK, tplSettingsOptions)
- return
- }
-
- org := ctx.Org.Organization
- nameChanged := org.Name != form.Name
-
- // Check if organization name has been changed.
- if org.LowerName != strings.ToLower(form.Name) {
- isExist, err := models.IsUserExist(org.ID, form.Name)
- if err != nil {
- ctx.ServerError("IsUserExist", err)
- return
- } else if isExist {
- ctx.Data["OrgName"] = true
- ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplSettingsOptions, &form)
- return
- } else if err = models.ChangeUserName(org, form.Name); err != nil {
- if err == models.ErrUserNameIllegal {
- ctx.Data["OrgName"] = true
- ctx.RenderWithErr(ctx.Tr("form.illegal_username"), tplSettingsOptions, &form)
- } else {
- ctx.ServerError("ChangeUserName", err)
- }
- return
- }
- // reset ctx.org.OrgLink with new name
- ctx.Org.OrgLink = setting.AppSubURL + "/org/" + form.Name
- log.Trace("Organization name changed: %s -> %s", org.Name, form.Name)
- nameChanged = false
- }
-
- // In case it's just a case change.
- org.Name = form.Name
- org.LowerName = strings.ToLower(form.Name)
-
- if ctx.User.IsAdmin {
- org.MaxRepoCreation = form.MaxRepoCreation
- }
-
- org.FullName = form.FullName
- org.Description = form.Description
- org.Website = form.Website
- org.Location = form.Location
- org.RepoAdminChangeTeamAccess = form.RepoAdminChangeTeamAccess
-
- visibilityChanged := form.Visibility != org.Visibility
- org.Visibility = form.Visibility
-
- if err := models.UpdateUser(org); err != nil {
- ctx.ServerError("UpdateUser", err)
- return
- }
-
- // update forks visibility
- if visibilityChanged {
- if err := org.GetRepositories(models.ListOptions{Page: 1, PageSize: org.NumRepos}); err != nil {
- ctx.ServerError("GetRepositories", err)
- return
- }
- for _, repo := range org.Repos {
- repo.OwnerName = org.Name
- if err := models.UpdateRepository(repo, true); err != nil {
- ctx.ServerError("UpdateRepository", err)
- return
- }
- }
- } else if nameChanged {
- if err := models.UpdateRepositoryOwnerNames(org.ID, org.Name); err != nil {
- ctx.ServerError("UpdateRepository", err)
- return
- }
- }
-
- log.Trace("Organization setting updated: %s", org.Name)
- ctx.Flash.Success(ctx.Tr("org.settings.update_setting_success"))
- ctx.Redirect(ctx.Org.OrgLink + "/settings")
-}
-
-// SettingsAvatar response for change avatar on settings page
-func SettingsAvatar(ctx *context.Context) {
- form := web.GetForm(ctx).(*forms.AvatarForm)
- form.Source = forms.AvatarLocal
- if err := userSetting.UpdateAvatarSetting(ctx, form, ctx.Org.Organization); err != nil {
- ctx.Flash.Error(err.Error())
- } else {
- ctx.Flash.Success(ctx.Tr("org.settings.update_avatar_success"))
- }
-
- ctx.Redirect(ctx.Org.OrgLink + "/settings")
-}
-
-// SettingsDeleteAvatar response for delete avatar on setings page
-func SettingsDeleteAvatar(ctx *context.Context) {
- if err := ctx.Org.Organization.DeleteAvatar(); err != nil {
- ctx.Flash.Error(err.Error())
- }
-
- ctx.Redirect(ctx.Org.OrgLink + "/settings")
-}
-
-// SettingsDelete response for deleting an organization
-func SettingsDelete(ctx *context.Context) {
- ctx.Data["Title"] = ctx.Tr("org.settings")
- ctx.Data["PageIsSettingsDelete"] = true
-
- org := ctx.Org.Organization
- if ctx.Req.Method == "POST" {
- if org.Name != ctx.Query("org_name") {
- ctx.Data["Err_OrgName"] = true
- ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_org_name"), tplSettingsDelete, nil)
- return
- }
-
- if err := models.DeleteOrganization(org); err != nil {
- if models.IsErrUserOwnRepos(err) {
- ctx.Flash.Error(ctx.Tr("form.org_still_own_repo"))
- ctx.Redirect(ctx.Org.OrgLink + "/settings/delete")
- } else {
- ctx.ServerError("DeleteOrganization", err)
- }
- } else {
- log.Trace("Organization deleted: %s", org.Name)
- ctx.Redirect(setting.AppSubURL + "/")
- }
- return
- }
-
- ctx.HTML(http.StatusOK, tplSettingsDelete)
-}
-
-// Webhooks render webhook list page
-func Webhooks(ctx *context.Context) {
- ctx.Data["Title"] = ctx.Tr("org.settings")
- ctx.Data["PageIsSettingsHooks"] = true
- ctx.Data["BaseLink"] = ctx.Org.OrgLink + "/settings/hooks"
- ctx.Data["BaseLinkNew"] = ctx.Org.OrgLink + "/settings/hooks"
- ctx.Data["Description"] = ctx.Tr("org.settings.hooks_desc")
-
- ws, err := models.GetWebhooksByOrgID(ctx.Org.Organization.ID, models.ListOptions{})
- if err != nil {
- ctx.ServerError("GetWebhooksByOrgId", err)
- return
- }
-
- ctx.Data["Webhooks"] = ws
- ctx.HTML(http.StatusOK, tplSettingsHooks)
-}
-
-// DeleteWebhook response for delete webhook
-func DeleteWebhook(ctx *context.Context) {
- if err := models.DeleteWebhookByOrgID(ctx.Org.Organization.ID, ctx.QueryInt64("id")); err != nil {
- ctx.Flash.Error("DeleteWebhookByOrgID: " + err.Error())
- } else {
- ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success"))
- }
-
- ctx.JSON(http.StatusOK, map[string]interface{}{
- "redirect": ctx.Org.OrgLink + "/settings/hooks",
- })
-}
-
-// Labels render organization labels page
-func Labels(ctx *context.Context) {
- ctx.Data["Title"] = ctx.Tr("repo.labels")
- ctx.Data["PageIsOrgSettingsLabels"] = true
- ctx.Data["RequireTribute"] = true
- ctx.Data["LabelTemplates"] = models.LabelTemplates
- ctx.HTML(http.StatusOK, tplSettingsLabels)
-}
diff --git a/routers/org/teams.go b/routers/org/teams.go
deleted file mode 100644
index e612cd767c..0000000000
--- a/routers/org/teams.go
+++ /dev/null
@@ -1,357 +0,0 @@
-// Copyright 2014 The Gogs Authors. All rights reserved.
-// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package org
-
-import (
- "net/http"
- "path"
- "strings"
-
- "code.gitea.io/gitea/models"
- "code.gitea.io/gitea/modules/base"
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/web"
- "code.gitea.io/gitea/routers/utils"
- "code.gitea.io/gitea/services/forms"
-)
-
-const (
- // tplTeams template path for teams list page
- tplTeams base.TplName = "org/team/teams"
- // tplTeamNew template path for create new team page
- tplTeamNew base.TplName = "org/team/new"
- // tplTeamMembers template path for showing team members page
- tplTeamMembers base.TplName = "org/team/members"
- // tplTeamRepositories template path for showing team repositories page
- tplTeamRepositories base.TplName = "org/team/repositories"
-)
-
-// Teams render teams list page
-func Teams(ctx *context.Context) {
- org := ctx.Org.Organization
- ctx.Data["Title"] = org.FullName
- ctx.Data["PageIsOrgTeams"] = true
-
- for _, t := range org.Teams {
- if err := t.GetMembers(&models.SearchMembersOptions{}); err != nil {
- ctx.ServerError("GetMembers", err)
- return
- }
- }
- ctx.Data["Teams"] = org.Teams
-
- ctx.HTML(http.StatusOK, tplTeams)
-}
-
-// TeamsAction response for join, leave, remove, add operations to team
-func TeamsAction(ctx *context.Context) {
- uid := ctx.QueryInt64("uid")
- if uid == 0 {
- ctx.Redirect(ctx.Org.OrgLink + "/teams")
- return
- }
-
- page := ctx.Query("page")
- var err error
- switch ctx.Params(":action") {
- case "join":
- if !ctx.Org.IsOwner {
- ctx.Error(http.StatusNotFound)
- return
- }
- err = ctx.Org.Team.AddMember(ctx.User.ID)
- case "leave":
- err = ctx.Org.Team.RemoveMember(ctx.User.ID)
- case "remove":
- if !ctx.Org.IsOwner {
- ctx.Error(http.StatusNotFound)
- return
- }
- err = ctx.Org.Team.RemoveMember(uid)
- page = "team"
- case "add":
- if !ctx.Org.IsOwner {
- ctx.Error(http.StatusNotFound)
- return
- }
- uname := utils.RemoveUsernameParameterSuffix(strings.ToLower(ctx.Query("uname")))
- var u *models.User
- u, err = models.GetUserByName(uname)
- if err != nil {
- if models.IsErrUserNotExist(err) {
- ctx.Flash.Error(ctx.Tr("form.user_not_exist"))
- ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName)
- } else {
- ctx.ServerError(" GetUserByName", err)
- }
- return
- }
-
- if u.IsOrganization() {
- ctx.Flash.Error(ctx.Tr("form.cannot_add_org_to_team"))
- ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName)
- return
- }
-
- if ctx.Org.Team.IsMember(u.ID) {
- ctx.Flash.Error(ctx.Tr("org.teams.add_duplicate_users"))
- } else {
- err = ctx.Org.Team.AddMember(u.ID)
- }
-
- page = "team"
- }
-
- if err != nil {
- if models.IsErrLastOrgOwner(err) {
- ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
- } else {
- log.Error("Action(%s): %v", ctx.Params(":action"), err)
- ctx.JSON(http.StatusOK, map[string]interface{}{
- "ok": false,
- "err": err.Error(),
- })
- return
- }
- }
-
- switch page {
- case "team":
- ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName)
- case "home":
- ctx.Redirect(ctx.Org.Organization.HomeLink())
- default:
- ctx.Redirect(ctx.Org.OrgLink + "/teams")
- }
-}
-
-// TeamsRepoAction operate team's repository
-func TeamsRepoAction(ctx *context.Context) {
- if !ctx.Org.IsOwner {
- ctx.Error(http.StatusNotFound)
- return
- }
-
- var err error
- action := ctx.Params(":action")
- switch action {
- case "add":
- repoName := path.Base(ctx.Query("repo_name"))
- var repo *models.Repository
- repo, err = models.GetRepositoryByName(ctx.Org.Organization.ID, repoName)
- if err != nil {
- if models.IsErrRepoNotExist(err) {
- ctx.Flash.Error(ctx.Tr("org.teams.add_nonexistent_repo"))
- ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories")
- return
- }
- ctx.ServerError("GetRepositoryByName", err)
- return
- }
- err = ctx.Org.Team.AddRepository(repo)
- case "remove":
- err = ctx.Org.Team.RemoveRepository(ctx.QueryInt64("repoid"))
- case "addall":
- err = ctx.Org.Team.AddAllRepositories()
- case "removeall":
- err = ctx.Org.Team.RemoveAllRepositories()
- }
-
- if err != nil {
- log.Error("Action(%s): '%s' %v", ctx.Params(":action"), ctx.Org.Team.Name, err)
- ctx.ServerError("TeamsRepoAction", err)
- return
- }
-
- if action == "addall" || action == "removeall" {
- ctx.JSON(http.StatusOK, map[string]interface{}{
- "redirect": ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories",
- })
- return
- }
- ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories")
-}
-
-// NewTeam render create new team page
-func NewTeam(ctx *context.Context) {
- ctx.Data["Title"] = ctx.Org.Organization.FullName
- ctx.Data["PageIsOrgTeams"] = true
- ctx.Data["PageIsOrgTeamsNew"] = true
- ctx.Data["Team"] = &models.Team{}
- ctx.Data["Units"] = models.Units
- ctx.HTML(http.StatusOK, tplTeamNew)
-}
-
-// NewTeamPost response for create new team
-func NewTeamPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*forms.CreateTeamForm)
- ctx.Data["Title"] = ctx.Org.Organization.FullName
- ctx.Data["PageIsOrgTeams"] = true
- ctx.Data["PageIsOrgTeamsNew"] = true
- ctx.Data["Units"] = models.Units
- var includesAllRepositories = form.RepoAccess == "all"
-
- t := &models.Team{
- OrgID: ctx.Org.Organization.ID,
- Name: form.TeamName,
- Description: form.Description,
- Authorize: models.ParseAccessMode(form.Permission),
- IncludesAllRepositories: includesAllRepositories,
- CanCreateOrgRepo: form.CanCreateOrgRepo,
- }
-
- if t.Authorize < models.AccessModeOwner {
- var units = make([]*models.TeamUnit, 0, len(form.Units))
- for _, tp := range form.Units {
- units = append(units, &models.TeamUnit{
- OrgID: ctx.Org.Organization.ID,
- Type: tp,
- })
- }
- t.Units = units
- }
-
- ctx.Data["Team"] = t
-
- if ctx.HasError() {
- ctx.HTML(http.StatusOK, tplTeamNew)
- return
- }
-
- if t.Authorize < models.AccessModeAdmin && len(form.Units) == 0 {
- ctx.RenderWithErr(ctx.Tr("form.team_no_units_error"), tplTeamNew, &form)
- return
- }
-
- if err := models.NewTeam(t); err != nil {
- ctx.Data["Err_TeamName"] = true
- switch {
- case models.IsErrTeamAlreadyExist(err):
- ctx.RenderWithErr(ctx.Tr("form.team_name_been_taken"), tplTeamNew, &form)
- default:
- ctx.ServerError("NewTeam", err)
- }
- return
- }
- log.Trace("Team created: %s/%s", ctx.Org.Organization.Name, t.Name)
- ctx.Redirect(ctx.Org.OrgLink + "/teams/" + t.LowerName)
-}
-
-// TeamMembers render team members page
-func TeamMembers(ctx *context.Context) {
- ctx.Data["Title"] = ctx.Org.Team.Name
- ctx.Data["PageIsOrgTeams"] = true
- ctx.Data["PageIsOrgTeamMembers"] = true
- if err := ctx.Org.Team.GetMembers(&models.SearchMembersOptions{}); err != nil {
- ctx.ServerError("GetMembers", err)
- return
- }
- ctx.HTML(http.StatusOK, tplTeamMembers)
-}
-
-// TeamRepositories show the repositories of team
-func TeamRepositories(ctx *context.Context) {
- ctx.Data["Title"] = ctx.Org.Team.Name
- ctx.Data["PageIsOrgTeams"] = true
- ctx.Data["PageIsOrgTeamRepos"] = true
- if err := ctx.Org.Team.GetRepositories(&models.SearchTeamOptions{}); err != nil {
- ctx.ServerError("GetRepositories", err)
- return
- }
- ctx.HTML(http.StatusOK, tplTeamRepositories)
-}
-
-// EditTeam render team edit page
-func EditTeam(ctx *context.Context) {
- ctx.Data["Title"] = ctx.Org.Organization.FullName
- ctx.Data["PageIsOrgTeams"] = true
- ctx.Data["team_name"] = ctx.Org.Team.Name
- ctx.Data["desc"] = ctx.Org.Team.Description
- ctx.Data["Units"] = models.Units
- ctx.HTML(http.StatusOK, tplTeamNew)
-}
-
-// EditTeamPost response for modify team information
-func EditTeamPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*forms.CreateTeamForm)
- t := ctx.Org.Team
- ctx.Data["Title"] = ctx.Org.Organization.FullName
- ctx.Data["PageIsOrgTeams"] = true
- ctx.Data["Team"] = t
- ctx.Data["Units"] = models.Units
-
- isAuthChanged := false
- isIncludeAllChanged := false
- var includesAllRepositories = form.RepoAccess == "all"
- if !t.IsOwnerTeam() {
- // Validate permission level.
- auth := models.ParseAccessMode(form.Permission)
-
- t.Name = form.TeamName
- if t.Authorize != auth {
- isAuthChanged = true
- t.Authorize = auth
- }
-
- if t.IncludesAllRepositories != includesAllRepositories {
- isIncludeAllChanged = true
- t.IncludesAllRepositories = includesAllRepositories
- }
- }
- t.Description = form.Description
- if t.Authorize < models.AccessModeOwner {
- var units = make([]models.TeamUnit, 0, len(form.Units))
- for _, tp := range form.Units {
- units = append(units, models.TeamUnit{
- OrgID: t.OrgID,
- TeamID: t.ID,
- Type: tp,
- })
- }
- err := models.UpdateTeamUnits(t, units)
- if err != nil {
- ctx.Error(http.StatusInternalServerError, "LoadIssue", err.Error())
- return
- }
- }
- t.CanCreateOrgRepo = form.CanCreateOrgRepo
-
- if ctx.HasError() {
- ctx.HTML(http.StatusOK, tplTeamNew)
- return
- }
-
- if t.Authorize < models.AccessModeAdmin && len(form.Units) == 0 {
- ctx.RenderWithErr(ctx.Tr("form.team_no_units_error"), tplTeamNew, &form)
- return
- }
-
- if err := models.UpdateTeam(t, isAuthChanged, isIncludeAllChanged); err != nil {
- ctx.Data["Err_TeamName"] = true
- switch {
- case models.IsErrTeamAlreadyExist(err):
- ctx.RenderWithErr(ctx.Tr("form.team_name_been_taken"), tplTeamNew, &form)
- default:
- ctx.ServerError("UpdateTeam", err)
- }
- return
- }
- ctx.Redirect(ctx.Org.OrgLink + "/teams/" + t.LowerName)
-}
-
-// DeleteTeam response for the delete team request
-func DeleteTeam(ctx *context.Context) {
- if err := models.DeleteTeam(ctx.Org.Team); err != nil {
- ctx.Flash.Error("DeleteTeam: " + err.Error())
- } else {
- ctx.Flash.Success(ctx.Tr("org.teams.delete_team_success"))
- }
-
- ctx.JSON(http.StatusOK, map[string]interface{}{
- "redirect": ctx.Org.OrgLink + "/teams",
- })
-}