summaryrefslogtreecommitdiffstats
path: root/routers/org
diff options
context:
space:
mode:
Diffstat (limited to 'routers/org')
-rw-r--r--routers/org/org_labels.go106
-rw-r--r--routers/org/setting.go12
2 files changed, 118 insertions, 0 deletions
diff --git a/routers/org/org_labels.go b/routers/org/org_labels.go
new file mode 100644
index 0000000000..e5b9d9ddee
--- /dev/null
+++ b/routers/org/org_labels.go
@@ -0,0 +1,106 @@
+// 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 (
+ "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/auth"
+ "code.gitea.io/gitea/modules/context"
+)
+
+// 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 auth.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 auth.CreateLabelForm) {
+ l, err := models.GetLabelInOrgByID(ctx.Org.Organization.ID, form.ID)
+ if err != nil {
+ switch {
+ case models.IsErrOrgLabelNotExist(err):
+ ctx.Error(404)
+ 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(200, map[string]interface{}{
+ "redirect": ctx.Org.OrgLink + "/settings/labels",
+ })
+}
+
+// InitializeLabels init labels for an organization
+func InitializeLabels(ctx *context.Context, form auth.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
index 3b6e124587..348d8cc8d8 100644
--- a/routers/org/setting.go
+++ b/routers/org/setting.go
@@ -24,6 +24,8 @@ const (
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
@@ -177,3 +179,13 @@ func DeleteWebhook(ctx *context.Context) {
"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["RequireMinicolors"] = true
+ ctx.Data["RequireTribute"] = true
+ ctx.Data["LabelTemplates"] = models.LabelTemplates
+ ctx.HTML(200, tplSettingsLabels)
+}