able edit issue labels/milestone/assignee

tokarchuk/v1.17
Unknwon 9 years ago
parent d07c081920
commit cec38f2a8c
  1. 4
      cmd/web.go
  2. 2
      gogs.go
  3. 157
      models/issue.go
  4. 9
      modules/middleware/context.go
  5. 6
      modules/middleware/repo.go
  6. 2
      public/css/gogs.min.css
  7. 43
      public/js/gogs.js
  8. 4
      public/less/_base.less
  9. 5
      public/less/_repository.less
  10. 225
      routers/repo/issue.go
  11. 2
      templates/.VERSION
  12. 23
      templates/repo/issue/view_content.tmpl

@ -457,9 +457,9 @@ func runWeb(ctx *cli.Context) {
m.Post("", bindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue) m.Post("", bindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue)
m.Post("/label", repo.UpdateIssueLabel) m.Post("/label", repo.UpdateIssueLabel)
m.Post("/milestone", repo.UpdateIssueMilestone) m.Post("/milestone", repo.UpdateIssueMilestone)
m.Post("/assignee", repo.UpdateAssignee) m.Post("/assignee", repo.UpdateIssueAssignee)
m.Combo("/comments").Post(bindIgnErr(auth.CreateCommentForm{}), repo.NewComment) m.Combo("/comments").Post(bindIgnErr(auth.CreateCommentForm{}), repo.NewComment)
}) }, reqRepoAdmin)
}) })
m.Group("/labels", func() { m.Group("/labels", func() {
m.Post("/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel) m.Post("/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel)

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.6.4.0814 Beta" const APP_VER = "0.6.5.0815 Beta"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

@ -123,13 +123,23 @@ func (i *Issue) HasLabel(labelID int64) bool {
return i.hasLabel(x, labelID) return i.hasLabel(x, labelID)
} }
func (i *Issue) addLabel(e Engine, labelID int64) error { func (i *Issue) addLabel(e *xorm.Session, label *Label) error {
return newIssueLabel(e, i.ID, labelID) return newIssueLabel(e, i, label)
} }
// AddLabel adds new label to issue by given ID. // AddLabel adds new label to issue by given ID.
func (i *Issue) AddLabel(labelID int64) error { func (i *Issue) AddLabel(label *Label) (err error) {
return i.addLabel(x, labelID) sess := x.NewSession()
defer sessionRelease(sess)
if err = sess.Begin(); err != nil {
return err
}
if err = i.addLabel(sess, label); err != nil {
return err
}
return sess.Commit()
} }
func (i *Issue) getLabels(e Engine) (err error) { func (i *Issue) getLabels(e Engine) (err error) {
@ -149,13 +159,43 @@ func (i *Issue) GetLabels() error {
return i.getLabels(x) return i.getLabels(x)
} }
func (i *Issue) removeLabel(e Engine, labelID int64) error { func (i *Issue) removeLabel(e *xorm.Session, label *Label) error {
return deleteIssueLabel(e, i.ID, labelID) return deleteIssueLabel(e, i, label)
} }
// RemoveLabel removes a label from issue by given ID. // RemoveLabel removes a label from issue by given ID.
func (i *Issue) RemoveLabel(labelID int64) error { func (i *Issue) RemoveLabel(label *Label) (err error) {
return i.removeLabel(x, labelID) sess := x.NewSession()
defer sessionRelease(sess)
if err = sess.Begin(); err != nil {
return err
}
if err = i.removeLabel(sess, label); err != nil {
return err
}
return sess.Commit()
}
func (i *Issue) ClearLabels() (err error) {
sess := x.NewSession()
defer sessionRelease(sess)
if err = sess.Begin(); err != nil {
return err
}
if err = i.getLabels(sess); err != nil {
return err
}
for idx := range i.Labels {
if err = i.removeLabel(sess, i.Labels[idx]); err != nil {
return err
}
}
return sess.Commit()
} }
func (i *Issue) GetAssignee() (err error) { func (i *Issue) GetAssignee() (err error) {
@ -257,10 +297,20 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string)
return err return err
} }
var label *Label
for _, id := range labelIDs { for _, id := range labelIDs {
if err = issue.addLabel(sess, id); err != nil { if id == 0 {
continue
}
label, err = getLabelByID(sess, id)
if err != nil {
return err
}
if err = issue.addLabel(sess, label); err != nil {
return fmt.Errorf("addLabel: %v", err) return fmt.Errorf("addLabel: %v", err)
} }
} }
if issue.MilestoneID > 0 { if issue.MilestoneID > 0 {
@ -662,28 +712,30 @@ func UpdateIssueUsersByStatus(issueID int64, isClosed bool) error {
return updateIssueUsersByStatus(x, issueID, isClosed) return updateIssueUsersByStatus(x, issueID, isClosed)
} }
func updateIssueUserByAssignee(e *xorm.Session, issueID, assigneeID int64) (err error) { func updateIssueUserByAssignee(e *xorm.Session, issue *Issue) (err error) {
if _, err = e.Exec("UPDATE `issue_user` SET is_assigned=? WHERE issue_id=?", false, issueID); err != nil { if _, err = e.Exec("UPDATE `issue_user` SET is_assigned=? WHERE issue_id=?", false, issue.ID); err != nil {
return err return err
} }
// Assignee ID equals to 0 means clear assignee. // Assignee ID equals to 0 means clear assignee.
if assigneeID == 0 { if issue.AssigneeID > 0 {
return nil if _, err = e.Exec("UPDATE `issue_user` SET is_assigned=? WHERE uid=? AND issue_id=?", true, issue.AssigneeID, issue.ID); err != nil {
}
_, err = e.Exec("UPDATE `issue_user` SET is_assigned=? WHERE uid=? AND issue_id=?", true, assigneeID, issueID)
return err return err
}
}
return updateIssue(e, issue)
} }
// UpdateIssueUserByAssignee updates issue-user relation for assignee. // UpdateIssueUserByAssignee updates issue-user relation for assignee.
func UpdateIssueUserByAssignee(issueID, assigneeID int64) (err error) { func UpdateIssueUserByAssignee(issue *Issue) (err error) {
sess := x.NewSession() sess := x.NewSession()
defer sessionRelease(sess) defer sessionRelease(sess)
if err = sess.Begin(); err != nil { if err = sess.Begin(); err != nil {
return err return err
} }
if err = updateIssueUserByAssignee(sess, issueID, assigneeID); err != nil { if err = updateIssueUserByAssignee(sess, issue); err != nil {
return err return err
} }
@ -855,21 +907,34 @@ func HasIssueLabel(issueID, labelID int64) bool {
return hasIssueLabel(x, issueID, labelID) return hasIssueLabel(x, issueID, labelID)
} }
func newIssueLabel(e Engine, issueID, labelID int64) error { func newIssueLabel(e *xorm.Session, issue *Issue, label *Label) (err error) {
if issueID == 0 || labelID == 0 { if _, err = e.Insert(&IssueLabel{
return nil IssueID: issue.ID,
LabelID: label.ID,
}); err != nil {
return err
} }
_, err := e.Insert(&IssueLabel{ label.NumIssues++
IssueID: issueID, if issue.IsClosed {
LabelID: labelID, label.NumClosedIssues++
}) }
return err return updateLabel(e, label)
} }
// NewIssueLabel creates a new issue-label relation. // NewIssueLabel creates a new issue-label relation.
func NewIssueLabel(issueID, labelID int64) error { func NewIssueLabel(issue *Issue, label *Label) (err error) {
return newIssueLabel(x, issueID, labelID) sess := x.NewSession()
defer sessionRelease(sess)
if err = sess.Begin(); err != nil {
return err
}
if err = newIssueLabel(sess, issue, label); err != nil {
return err
}
return sess.Commit()
} }
func getIssueLabels(e Engine, issueID int64) ([]*IssueLabel, error) { func getIssueLabels(e Engine, issueID int64) ([]*IssueLabel, error) {
@ -882,17 +947,34 @@ func GetIssueLabels(issueID int64) ([]*IssueLabel, error) {
return getIssueLabels(x, issueID) return getIssueLabels(x, issueID)
} }
func deleteIssueLabel(e Engine, issueID, labelID int64) error { func deleteIssueLabel(e *xorm.Session, issue *Issue, label *Label) (err error) {
_, err := e.Delete(&IssueLabel{ if _, err = e.Delete(&IssueLabel{
IssueID: issueID, IssueID: issue.ID,
LabelID: labelID, LabelID: label.ID,
}) }); err != nil {
return err return err
}
label.NumIssues--
if issue.IsClosed {
label.NumClosedIssues--
}
return updateLabel(e, label)
} }
// DeleteIssueLabel deletes issue-label relation. // DeleteIssueLabel deletes issue-label relation.
func DeleteIssueLabel(issueID, labelID int64) error { func DeleteIssueLabel(issue *Issue, label *Label) (err error) {
return deleteIssueLabel(x, issueID, labelID) sess := x.NewSession()
defer sessionRelease(sess)
if err = sess.Begin(); err != nil {
return err
}
if err = deleteIssueLabel(sess, issue, label); err != nil {
return err
}
return sess.Commit()
} }
// _____ .__.__ __ // _____ .__.__ __
@ -966,7 +1048,7 @@ func NewMilestone(m *Milestone) (err error) {
func getMilestoneByID(e Engine, id int64) (*Milestone, error) { func getMilestoneByID(e Engine, id int64) (*Milestone, error) {
m := &Milestone{ID: id} m := &Milestone{ID: id}
has, err := x.Get(m) has, err := e.Get(m)
if err != nil { if err != nil {
return nil, err return nil, err
} else if !has { } else if !has {
@ -1127,7 +1209,7 @@ func changeMilestoneAssign(e *xorm.Session, oldMid int64, issue *Issue) error {
} }
if issue.MilestoneID > 0 { if issue.MilestoneID > 0 {
m, err := GetMilestoneByID(issue.MilestoneID) m, err := getMilestoneByID(e, issue.MilestoneID)
if err != nil { if err != nil {
return err return err
} }
@ -1148,7 +1230,7 @@ func changeMilestoneAssign(e *xorm.Session, oldMid int64, issue *Issue) error {
} }
} }
return nil return updateIssue(e, issue)
} }
// ChangeMilestoneAssign changes assignment of milestone for issue. // ChangeMilestoneAssign changes assignment of milestone for issue.
@ -1162,7 +1244,6 @@ func ChangeMilestoneAssign(oldMid int64, issue *Issue) (err error) {
if err = changeMilestoneAssign(sess, oldMid, issue); err != nil { if err = changeMilestoneAssign(sess, oldMid, issue); err != nil {
return err return err
} }
return sess.Commit() return sess.Commit()
} }

@ -72,9 +72,14 @@ type RepoContext struct {
Mirror *models.Mirror Mirror *models.Mirror
} }
// Return if the current user has write access for this repository // IsOwner returns true if current user is the owner of repository.
func (r RepoContext) IsOwner() bool { func (r RepoContext) IsOwner() bool {
return r.AccessMode >= models.ACCESS_MODE_WRITE return r.AccessMode >= models.ACCESS_MODE_OWNER
}
// IsAdmin returns true if current user has admin or higher access of repository.
func (r RepoContext) IsAdmin() bool {
return r.AccessMode >= models.ACCESS_MODE_ADMIN
} }
// Return if the current user has read access for this repository // Return if the current user has read access for this repository

@ -324,8 +324,8 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
ctx.Data["Title"] = u.Name + "/" + repo.Name ctx.Data["Title"] = u.Name + "/" + repo.Name
ctx.Data["Repository"] = repo ctx.Data["Repository"] = repo
ctx.Data["Owner"] = ctx.Repo.Repository.Owner ctx.Data["Owner"] = ctx.Repo.Repository.Owner
ctx.Data["IsRepositoryOwner"] = ctx.Repo.AccessMode >= models.ACCESS_MODE_WRITE ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner()
ctx.Data["IsRepositoryAdmin"] = ctx.Repo.AccessMode >= models.ACCESS_MODE_ADMIN ctx.Data["IsRepositoryAdmin"] = ctx.Repo.IsAdmin()
ctx.Data["DisableSSH"] = setting.DisableSSH ctx.Data["DisableSSH"] = setting.DisableSSH
ctx.Repo.CloneLink, err = repo.CloneLink() ctx.Repo.CloneLink, err = repo.CloneLink()
@ -388,7 +388,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
func RequireRepoAdmin() macaron.Handler { func RequireRepoAdmin() macaron.Handler {
return func(ctx *Context) { return func(ctx *Context) {
if ctx.Repo.AccessMode < models.ACCESS_MODE_ADMIN { if !ctx.Repo.IsAdmin() {
if !ctx.IsSigned { if !ctx.IsSigned {
ctx.SetCookie("redirect_to", "/"+url.QueryEscape(setting.AppSubUrl+ctx.Req.RequestURI), 0, setting.AppSubUrl) ctx.SetCookie("redirect_to", "/"+url.QueryEscape(setting.AppSubUrl+ctx.Req.RequestURI), 0, setting.AppSubUrl)
ctx.Redirect(setting.AppSubUrl + "/user/login") ctx.Redirect(setting.AppSubUrl + "/user/login")

File diff suppressed because one or more lines are too long

@ -26,13 +26,30 @@ function initCommentForm() {
// Labels // Labels
var $list = $('.ui.labels.list'); var $list = $('.ui.labels.list');
var $no_select = $list.find('.no-select'); var $no_select = $list.find('.no-select');
$('.select-label .menu .item:not(.no-select)').click(function () { var $label_menu = $('.select-label .menu');
var has_label_update_action = $label_menu.data('action') == 'update';
function updateIssueMeta(url, action, id) {
$.post(url, {
"_csrf": csrf,
"action": action,
"id": id
});
}
$label_menu.find('.item:not(.no-select)').click(function () {
if ($(this).hasClass('checked')) { if ($(this).hasClass('checked')) {
$(this).removeClass('checked') $(this).removeClass('checked')
$(this).find('.octicon').removeClass('octicon-check') $(this).find('.octicon').removeClass('octicon-check')
if (has_label_update_action) {
updateIssueMeta($label_menu.data('update-url'), "detach", $(this).data('id'));
}
} else { } else {
$(this).addClass('checked') $(this).addClass('checked')
$(this).find('.octicon').addClass('octicon-check') $(this).find('.octicon').addClass('octicon-check')
if (has_label_update_action) {
updateIssueMeta($label_menu.data('update-url'), "attach", $(this).data('id'));
}
} }
var label_ids = ""; var label_ids = "";
@ -52,7 +69,11 @@ function initCommentForm() {
$($(this).parent().data('id')).val(label_ids); $($(this).parent().data('id')).val(label_ids);
return false; return false;
}); });
$('.select-label .menu .no-select.item').click(function () { $label_menu.find('.no-select.item').click(function () {
if (has_label_update_action) {
updateIssueMeta($label_menu.data('update-url'), "clear", '');
}
$(this).parent().find('.item').each(function () { $(this).parent().find('.item').each(function () {
$(this).removeClass('checked'); $(this).removeClass('checked');
$(this).find('.octicon').removeClass('octicon-check'); $(this).find('.octicon').removeClass('octicon-check');
@ -68,12 +89,17 @@ function initCommentForm() {
function selectItem(select_id, input_id) { function selectItem(select_id, input_id) {
var $menu = $(select_id + ' .menu'); var $menu = $(select_id + ' .menu');
var $list = $('.ui' + select_id + '.list') var $list = $('.ui' + select_id + '.list')
var has_update_action = $menu.data('action') == 'update';
$menu.find('.item:not(.no-select)').click(function () { $menu.find('.item:not(.no-select)').click(function () {
$(this).parent().find('.item').each(function () { $(this).parent().find('.item').each(function () {
$(this).removeClass('selected active') $(this).removeClass('selected active')
}); });
$(this).addClass('selected active'); $(this).addClass('selected active');
if (has_update_action) {
updateIssueMeta($menu.data('update-url'), '', $(this).data('id'));
}
switch (input_id) { switch (input_id) {
case '#milestone_id': case '#milestone_id':
$list.find('.selected').html('<a class="item" href=' + $(this).data('href') + '>' + $list.find('.selected').html('<a class="item" href=' + $(this).data('href') + '>' +
@ -92,6 +118,11 @@ function initCommentForm() {
$(this).removeClass('selected active') $(this).removeClass('selected active')
}); });
if (has_update_action) {
updateIssueMeta($menu.data('update-url'), '', '');
}
$list.find('.selected').html(''); $list.find('.selected').html('');
$list.find('.no-select').removeClass('hide'); $list.find('.no-select').removeClass('hide');
$(input_id).val(''); $(input_id).val('');
@ -235,6 +266,14 @@ function initRepository() {
$(document).ready(function () { $(document).ready(function () {
csrf = $('meta[name=_csrf]').attr("content"); csrf = $('meta[name=_csrf]').attr("content");
// Show exact time
$('.time-since').each(function () {
$(this).addClass('poping up').
attr('data-content', $(this).attr('title')).
attr('data-variation', 'inverted tiny').
attr('title', '');
});
// Semantic UI modules. // Semantic UI modules.
$('.dropdown').dropdown(); $('.dropdown').dropdown();
$('.jump.dropdown').dropdown({ $('.jump.dropdown').dropdown({

@ -99,6 +99,10 @@ img {
padding-left: 0.75rem; padding-left: 0.75rem;
vertical-align: middle; vertical-align: middle;
} }
.avatar.image {
border-radius: 3px;
}
} }
footer { footer {

@ -38,9 +38,6 @@
overflow-x: auto; overflow-x: auto;
} }
.ui.list { .ui.list {
.ui.avatar.image {
border-radius: 0;
}
.hide { .hide {
display: none!important; display: none!important;
} }
@ -116,7 +113,7 @@
} }
} }
.assignee { .assignee {
margin-top: -10px; margin-top: -5px;
margin-right: 5px; margin-right: 5px;
} }
} }

@ -184,7 +184,7 @@ func NewIssue(ctx *middleware.Context) {
ctx.Data["RequireDropzone"] = true ctx.Data["RequireDropzone"] = true
renderAttachmentSettings(ctx) renderAttachmentSettings(ctx)
if ctx.User.IsAdmin { if ctx.Repo.IsAdmin() {
var ( var (
repo = ctx.Repo.Repository repo = ctx.Repo.Repository
err error err error
@ -229,7 +229,7 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
assigneeID int64 assigneeID int64
attachments []string attachments []string
) )
if ctx.User.IsAdmin { if ctx.Repo.IsAdmin() {
// Check labels. // Check labels.
labelIDs = base.StringsToInt64s(strings.Split(form.LabelIDs, ",")) labelIDs = base.StringsToInt64s(strings.Split(form.LabelIDs, ","))
labelIDMark := base.Int64sToMap(labelIDs) labelIDMark := base.Int64sToMap(labelIDs)
@ -399,17 +399,6 @@ func UploadIssueAttachment(ctx *middleware.Context) {
}) })
} }
func checkLabels(labels, allLabels []*models.Label) {
for _, l := range labels {
for _, l2 := range allLabels {
if l.ID == l2.ID {
l2.IsChecked = true
break
}
}
}
}
func ViewIssue(ctx *middleware.Context) { func ViewIssue(ctx *middleware.Context) {
ctx.Data["PageIsIssueList"] = true ctx.Data["PageIsIssueList"] = true
ctx.Data["RequireDropzone"] = true ctx.Data["RequireDropzone"] = true
@ -432,11 +421,52 @@ func ViewIssue(ctx *middleware.Context) {
} }
issue.RenderedContent = string(base.RenderMarkdown([]byte(issue.Content), ctx.Repo.RepoLink)) issue.RenderedContent = string(base.RenderMarkdown([]byte(issue.Content), ctx.Repo.RepoLink))
repo := ctx.Repo.Repository
// Metas. // Metas.
// Check labels.
if err = issue.GetLabels(); err != nil { if err = issue.GetLabels(); err != nil {
ctx.Handle(500, "GetLabels", err) ctx.Handle(500, "GetLabels", err)
return return
} }
labelIDMark := make(map[int64]bool)
for i := range issue.Labels {
labelIDMark[issue.Labels[i].ID] = true
}
labels, err := models.GetLabelsByRepoID(repo.ID)
if err != nil {
ctx.Handle(500, "GetLabelsByRepoID: %v", err)
return
}
hasSelected := false
for i := range labels {
if labelIDMark[labels[i].ID] {
labels[i].IsChecked = true
hasSelected = true
}
}
ctx.Data["HasSelectedLabel"] = hasSelected
ctx.Data["Labels"] = labels
// Check milestone and assignee.
if ctx.Repo.IsAdmin() {
ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false)
if err != nil {
ctx.Handle(500, "GetMilestones: %v", err)
return
}
ctx.Data["ClosedMilestones"], err = models.GetMilestones(repo.ID, -1, true)
if err != nil {
ctx.Handle(500, "GetMilestones: %v", err)
return
}
ctx.Data["Assignees"], err = repo.GetAssignees()
if err != nil {
ctx.Handle(500, "GetAssignees: %v", err)
return
}
}
if ctx.IsSigned { if ctx.IsSigned {
// Update issue-user. // Update issue-user.
@ -444,39 +474,9 @@ func ViewIssue(ctx *middleware.Context) {
ctx.Handle(500, "ReadBy", err) ctx.Handle(500, "ReadBy", err)
return return
} }
if ctx.User.IsAdmin {
// labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID)
// if err != nil {
// ctx.Handle(500, "GetLabels.2", err)
// return
// }
// checkLabels(issue.Labels, labels)
// ctx.Data["Labels"] = labels
// // Get all milestones.
// ctx.Data["OpenMilestones"], err = models.GetMilestones(ctx.Repo.Repository.ID, -1, false)
// if err != nil {
// ctx.Handle(500, "GetMilestones.1: %v", err)
// return
// }
// ctx.Data["ClosedMilestones"], err = models.GetMilestones(ctx.Repo.Repository.ID, -1, true)
// if err != nil {
// ctx.Handle(500, "GetMilestones.2: %v", err)
// return
// }
// // Get all collaborators.
// ctx.Data["Collaborators"], err = ctx.Repo.Repository.GetCollaborators()
// if err != nil {
// ctx.Handle(500, "GetCollaborators", err)
// return
// }
}
} }
var ( var (
repo = ctx.Repo.Repository
tag models.CommentTag tag models.CommentTag
ok bool ok bool
marked = make(map[int64]models.CommentTag) marked = make(map[int64]models.CommentTag)
@ -555,112 +555,68 @@ func UpdateIssue(ctx *middleware.Context, form auth.CreateIssueForm) {
}) })
} }
func UpdateIssueLabel(ctx *middleware.Context) { func getActionIssue(ctx *middleware.Context) *models.Issue {
if !ctx.Repo.IsOwner() { issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
ctx.Error(403)
return
}
idx := com.StrTo(ctx.Params(":index")).MustInt64()
if idx <= 0 {
ctx.Error(404)
return
}
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, idx)
if err != nil { if err != nil {
if models.IsErrIssueNotExist(err) { if models.IsErrIssueNotExist(err) {
ctx.Handle(404, "issue.UpdateIssueLabel(GetIssueByIndex)", err) ctx.Error(404, "GetIssueByIndex")
} else { } else {
ctx.Handle(500, "issue.UpdateIssueLabel(GetIssueByIndex)", err) ctx.Handle(500, "GetIssueByIndex", err)
} }
return nil
}
return issue
}
func UpdateIssueLabel(ctx *middleware.Context) {
issue := getActionIssue(ctx)
if ctx.Written() {
return return
} }
if ctx.Query("action") == "clear" {
if err := issue.ClearLabels(); err != nil {
ctx.Handle(500, "ClearLabels", err)
return
}
} else {
isAttach := ctx.Query("action") == "attach" isAttach := ctx.Query("action") == "attach"
labelStrId := ctx.Query("id") label, err := models.GetLabelByID(ctx.QueryInt64("id"))
labelID := com.StrTo(labelStrId).MustInt64()
label, err := models.GetLabelByID(labelID)
if err != nil { if err != nil {
if models.IsErrLabelNotExist(err) { if models.IsErrLabelNotExist(err) {
ctx.Handle(404, "issue.UpdateIssueLabel(GetLabelById)", err) ctx.Error(404, "GetLabelByID")
} else { } else {
ctx.Handle(500, "issue.UpdateIssueLabel(GetLabelById)", err) ctx.Handle(500, "GetLabelByID", err)
} }
return return
} }
isNeedUpdate := false if isAttach && !issue.HasLabel(label.ID) {
if isAttach { if err = issue.AddLabel(label); err != nil {
if !issue.HasLabel(labelID) {
if err = issue.AddLabel(labelID); err != nil {
ctx.Handle(500, "AddLabel", err) ctx.Handle(500, "AddLabel", err)
return return
} }
isNeedUpdate = true } else if !isAttach && issue.HasLabel(label.ID) {
} if err = issue.RemoveLabel(label); err != nil {
} else {
if issue.HasLabel(labelID) {
if err = issue.RemoveLabel(labelID); err != nil {
ctx.Handle(500, "RemoveLabel", err) ctx.Handle(500, "RemoveLabel", err)
return return
} }
isNeedUpdate = true
} }
} }
if isNeedUpdate {
if err = models.UpdateIssue(issue); err != nil {
ctx.Handle(500, "issue.UpdateIssueLabel(UpdateIssue)", err)
return
}
if isAttach {
label.NumIssues++
if issue.IsClosed {
label.NumClosedIssues++
}
} else {
label.NumIssues--
if issue.IsClosed {
label.NumClosedIssues--
}
}
if err = models.UpdateLabel(label); err != nil {
ctx.Handle(500, "issue.UpdateIssueLabel(UpdateLabel)", err)
return
}
}
ctx.JSON(200, map[string]interface{}{ ctx.JSON(200, map[string]interface{}{
"ok": true, "ok": true,
}) })
} }
func UpdateIssueMilestone(ctx *middleware.Context) { func UpdateIssueMilestone(ctx *middleware.Context) {
if !ctx.Repo.IsOwner() { issue := getActionIssue(ctx)
ctx.Error(403) if ctx.Written() {
return
}
issueId := com.StrTo(ctx.Query("issue")).MustInt64()
if issueId == 0 {
ctx.Error(404)
return
}
issue, err := models.GetIssueByID(issueId)
if err != nil {
if models.IsErrIssueNotExist(err) {
ctx.Handle(404, "issue.UpdateIssueMilestone(GetIssueByID)", err)
} else {
ctx.Handle(500, "issue.UpdateIssueMilestone(GetIssueByID)", err)
}
return return
} }
oldMid := issue.MilestoneID oldMid := issue.MilestoneID
mid := com.StrTo(ctx.Query("milestoneid")).MustInt64() mid := ctx.QueryInt64("id")
if oldMid == mid { if oldMid == mid {
ctx.JSON(200, map[string]interface{}{ ctx.JSON(200, map[string]interface{}{
"ok": true, "ok": true,
@ -670,11 +626,8 @@ func UpdateIssueMilestone(ctx *middleware.Context) {
// Not check for invalid milestone id and give responsibility to owners. // Not check for invalid milestone id and give responsibility to owners.
issue.MilestoneID = mid issue.MilestoneID = mid
if err = models.ChangeMilestoneAssign(oldMid, issue); err != nil { if err := models.ChangeMilestoneAssign(oldMid, issue); err != nil {
ctx.Handle(500, "issue.UpdateIssueMilestone(ChangeMilestoneAssign)", err) ctx.Handle(500, "ChangeMilestoneAssign", err)
return
} else if err = models.UpdateIssue(issue); err != nil {
ctx.Handle(500, "issue.UpdateIssueMilestone(UpdateIssue)", err)
return return
} }
@ -683,36 +636,24 @@ func UpdateIssueMilestone(ctx *middleware.Context) {
}) })
} }
func UpdateAssignee(ctx *middleware.Context) { func UpdateIssueAssignee(ctx *middleware.Context) {
if !ctx.Repo.IsOwner() { issue := getActionIssue(ctx)
ctx.Error(403) if ctx.Written() {
return return
} }
issueId := com.StrTo(ctx.Query("issue")).MustInt64() aid := ctx.QueryInt64("id")
if issueId == 0 { if issue.AssigneeID == aid {
ctx.Error(404) ctx.JSON(200, map[string]interface{}{
return "ok": true,
} })
issue, err := models.GetIssueByID(issueId)
if err != nil {
if models.IsErrIssueNotExist(err) {
ctx.Handle(404, "GetIssueByID", err)
} else {
ctx.Handle(500, "GetIssueByID", err)
}
return return
} }
aid := com.StrTo(ctx.Query("assigneeid")).MustInt64()
// Not check for invalid assignee id and give responsibility to owners. // Not check for invalid assignee id and give responsibility to owners.
issue.AssigneeID = aid issue.AssigneeID = aid
if err = models.UpdateIssueUserByAssignee(issue.ID, aid); err != nil { if err := models.UpdateIssueUserByAssignee(issue); err != nil {
ctx.Handle(500, "UpdateIssueUserPairByAssignee: %v", err) ctx.Handle(500, "UpdateIssueUserByAssignee: %v", err)
return
} else if err = models.UpdateIssue(issue); err != nil {
ctx.Handle(500, "UpdateIssue", err)
return return
} }

@ -1 +1 @@
0.6.4.0814 Beta 0.6.5.0815 Beta

@ -13,7 +13,7 @@
{{end}} {{end}}
{{ $createdStr:= TimeSince .Issue.Created $.Lang }} {{ $createdStr:= TimeSince .Issue.Created $.Lang }}
<span class="time-desc"> <span class="time-desc">
{{$.i18n.Tr "repo.issues.opened_by" $createdStr .Issue.Poster.Name|Str2html}} {{$.i18n.Tr "repo.issues.opened_by" $createdStr .Issue.Poster.Name | Safe}}
· ·
{{$.i18n.Tr "repo.issues.num_comments" .Issue.NumComments}} {{$.i18n.Tr "repo.issues.num_comments" .Issue.NumComments}}
</span> </span>
@ -152,13 +152,12 @@
<div class="four wide column"> <div class="four wide column">
<div class="ui segment metas"> <div class="ui segment metas">
<input id="label_ids" name="label_ids" type="hidden" value="{{.label_ids}}"> <div class="ui {{if not .IsRepositoryAdmin}}disabled{{end}} jump select-label dropdown">
<div class="ui {{if not .Labels}}disabled{{end}} jump select-label dropdown">
<span class="text"> <span class="text">
<strong>{{.i18n.Tr "repo.issues.new.labels"}}</strong> <strong>{{.i18n.Tr "repo.issues.new.labels"}}</strong>
<span class="octicon octicon-gear"></span> <span class="octicon octicon-gear"></span>
</span> </span>
<div class="filter menu" data-id="#label_ids"> <div class="filter menu" data-action="update" data-update-url="{{$.RepoLink}}/issues/{{$.Issue.Index}}/label">
<div class="no-select item">{{.i18n.Tr "repo.issues.new.clear_labels"}}</div> <div class="no-select item">{{.i18n.Tr "repo.issues.new.clear_labels"}}</div>
{{range .Labels}} {{range .Labels}}
<a class="{{if .IsChecked}}checked{{end}} item" href="#" data-id="{{.ID}}" data-id-selector="#label_{{.ID}}"><span class="octicon {{if .IsChecked}}octicon-check{{end}}"></span><span class="label color" style="background-color: {{.Color}}"></span> {{.Name}}</a> <a class="{{if .IsChecked}}checked{{end}} item" href="#" data-id="{{.ID}}" data-id-selector="#label_{{.ID}}"><span class="octicon {{if .IsChecked}}octicon-check{{end}}"></span><span class="label color" style="background-color: {{.Color}}"></span> {{.Name}}</a>
@ -166,24 +165,20 @@
</div> </div>
</div> </div>
<div class="ui labels list"> <div class="ui labels list">
{{if not .Issue.Labels}}
<span class="no-select item {{if .HasSelectedLabel}}hide{{end}}">{{.i18n.Tr "repo.issues.new.no_label"}}</span> <span class="no-select item {{if .HasSelectedLabel}}hide{{end}}">{{.i18n.Tr "repo.issues.new.no_label"}}</span>
{{else}} {{range .Labels}}
{{range .Issue.Labels}} <a class="{{if not .IsChecked}}hide{{end}} item" id="label_{{.ID}}" href="{{$.RepoLink}}/issues?labels={{.ID}}"><span class="label color" style="background-color: {{.Color}}"></span> <span class="text">{{.Name}}</span></a>
<a class="item" id="label_{{.ID}}" href="{{$.RepoLink}}/issues?labels={{.ID}}"><span class="label color" style="background-color: {{.Color}}"></span> <span class="text">{{.Name}}</span></a>
{{end}}
{{end}} {{end}}
</div> </div>
<div class="ui divider"></div> <div class="ui divider"></div>
<input id="milestone_id" name="milestone_id" type="hidden" value="{{.milestone_id}}"> <div class="ui {{if not .IsRepositoryAdmin}}disabled{{end}} jump select-milestone dropdown">
<div class="ui {{if not (or .OpenMilestones .ClosedMilestones)}}disabled{{end}} jump select-milestone dropdown">
<span class="text"> <span class="text">
<strong>{{.i18n.Tr "repo.issues.new.milestone"}}</strong> <strong>{{.i18n.Tr "repo.issues.new.milestone"}}</strong>
<span class="octicon octicon-gear"></span> <span class="octicon octicon-gear"></span>
</span> </span>
<div class="menu"> <div class="menu" data-action="update" data-update-url="{{$.RepoLink}}/issues/{{$.Issue.Index}}/milestone">
<div class="no-select item">{{.i18n.Tr "repo.issues.new.clear_milestone"}}</div> <div class="no-select item">{{.i18n.Tr "repo.issues.new.clear_milestone"}}</div>
{{if .OpenMilestones}} {{if .OpenMilestones}}
<div class="divider"></div> <div class="divider"></div>
@ -219,12 +214,12 @@
<div class="ui divider"></div> <div class="ui divider"></div>
<input id="assignee_id" name="assignee_id" type="hidden" value="{{.assignee_id}}"> <input id="assignee_id" name="assignee_id" type="hidden" value="{{.assignee_id}}">
<div class="ui {{if not .Assignees}}disabled{{end}} jump select-assignee dropdown"> <div class="ui {{if not .IsRepositoryAdmin}}disabled{{end}} jump select-assignee dropdown">
<span class="text"> <span class="text">
<strong>{{.i18n.Tr "repo.issues.new.assignee"}}</strong> <strong>{{.i18n.Tr "repo.issues.new.assignee"}}</strong>
<span class="octicon octicon-gear"></span> <span class="octicon octicon-gear"></span>
</span> </span>
<div class="menu"> <div class="menu" data-action="update" data-update-url="{{$.RepoLink}}/issues/{{$.Issue.Index}}/assignee">
<div class="no-select item">{{.i18n.Tr "repo.issues.new.clear_assignee"}}</div> <div class="no-select item">{{.i18n.Tr "repo.issues.new.clear_assignee"}}</div>
{{range .Assignees}} {{range .Assignees}}
<div class="item" data-id="{{.Id}}" data-href="{{.HomeLink}}" data-avatar="{{.AvatarLink}}"><img src="{{.AvatarLink}}"> {{.Name}}</div> <div class="item" data-id="{{.Id}}" data-href="{{.HomeLink}}" data-avatar="{{.AvatarLink}}"><img src="{{.AvatarLink}}"> {{.Name}}</div>

Loading…
Cancel
Save