func UpdateLabel(ctx *middleware.Context, form auth.CreateLabelForm) { l, err := models.GetLabelByID(form.ID) if err != nil { switch { case models.IsErrLabelNotExist(err): ctx.Error(404) default: ctx.Handle(500, "UpdateLabel", err) } return } l.Name = form.Title l.Color = form.Color if err := models.UpdateLabel(l); err != nil { ctx.Handle(500, "UpdateLabel", err) return } ctx.Redirect(ctx.Repo.RepoLink + "/labels") }
func UpdateIssueLabel(ctx *middleware.Context) { issue := getActionIssue(ctx) if ctx.Written() { return } if ctx.Query("action") == "clear" { if err := issue.ClearLabels(); err != nil { ctx.Handle(500, "ClearLabels", err) return } } else { isAttach := ctx.Query("action") == "attach" label, err := models.GetLabelByID(ctx.QueryInt64("id")) if err != nil { if models.IsErrLabelNotExist(err) { ctx.Error(404, "GetLabelByID") } else { ctx.Handle(500, "GetLabelByID", err) } return } if isAttach && !issue.HasLabel(label.ID) { if err = issue.AddLabel(label); err != nil { ctx.Handle(500, "AddLabel", err) return } } else if !isAttach && issue.HasLabel(label.ID) { if err = issue.RemoveLabel(label); err != nil { ctx.Handle(500, "RemoveLabel", err) return } } } ctx.JSON(200, map[string]interface{}{ "ok": true, }) }