Finish issue assignee

This commit is contained in:
Unknown 2014-05-11 13:46:36 -04:00
parent a196245a87
commit 68fb62347f
6 changed files with 56 additions and 23 deletions

View file

@ -177,7 +177,6 @@ func runServ(k *cli.Context) {
models.SetRepoEnvs(user.Id, user.Name, repoName, repoUserName) models.SetRepoEnvs(user.Id, user.Name, repoName, repoUserName)
gitcmd := exec.Command(verb, repoPath) gitcmd := exec.Command(verb, repoPath)
println(base.RepoRootPath)
gitcmd.Dir = base.RepoRootPath gitcmd.Dir = base.RepoRootPath
gitcmd.Stdout = os.Stdout gitcmd.Stdout = os.Stdout
gitcmd.Stdin = os.Stdin gitcmd.Stdin = os.Stdin

View file

@ -184,6 +184,7 @@ func runWeb(*cli.Context) {
r.Get("/issues/new", repo.CreateIssue) r.Get("/issues/new", repo.CreateIssue)
r.Post("/issues/new", bindIgnErr(auth.CreateIssueForm{}), repo.CreateIssuePost) r.Post("/issues/new", bindIgnErr(auth.CreateIssueForm{}), repo.CreateIssuePost)
r.Post("/issues/:index", bindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue) r.Post("/issues/:index", bindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue)
r.Post("/issues/:index/assignee", repo.UpdateAssignee)
r.Get("/issues/milestones", repo.Milestones) r.Get("/issues/milestones", repo.Milestones)
r.Get("/issues/milestones/new", repo.NewMilestones) r.Get("/issues/milestones/new", repo.NewMilestones)
r.Post("/comment/:action", repo.Comment) r.Post("/comment/:action", repo.Comment)

View file

@ -349,8 +349,12 @@ func UpdateIssueUserPairByAssignee(aid, iid int64) error {
return err return err
} }
// Assignee ID equals to 0 means clear assignee.
if aid == 0 {
return nil
}
rawSql = "UPDATE `issue_user` SET is_assigned = true WHERE uid = ? AND issue_id = ?" rawSql = "UPDATE `issue_user` SET is_assigned = true WHERE uid = ? AND issue_id = ?"
_, err := orm.Exec(rawSql, true, aid, iid) _, err := orm.Exec(rawSql, aid, iid)
return err return err
} }

View file

@ -547,7 +547,7 @@ function initIssue() {
if(uid != assignee){ if(uid != assignee){
$.post($a.data("ajax"), { $.post($a.data("ajax"), {
issue: $('#issue').data("id"), issue: $('#issue').data("id"),
assign: assignee assigneeid: uid
}, function (json) { }, function (json) {
if (json.ok) { if (json.ok) {
window.location.reload(); window.location.reload();

View file

@ -239,20 +239,12 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) {
return return
} }
// Update assignee. us, err := models.GetCollaborators(strings.TrimPrefix(ctx.Repo.RepoLink, "/"))
if ctx.Repo.IsOwner { if err != nil {
aid, _ := base.StrTo(ctx.Query("assignneid")).Int64() ctx.Handle(500, "issue.CreateIssue(GetCollaborators)", err)
if aid > 0 {
// Not check for invalid assignne id and give responsibility to owners.
issue.AssigneeId = aid
if err = models.UpdateIssueUserPairByAssignee(aid, issue.Id); err != nil {
ctx.Handle(500, "issue.ViewIssue(UpdateIssueUserPairByAssignee): %v", err)
return return
} }
ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)) ctx.Data["Collaborators"] = us
return
}
}
if ctx.IsSigned { if ctx.IsSigned {
// Update issue-user. // Update issue-user.
@ -300,18 +292,18 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) {
} }
func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) { func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) {
index, err := base.StrTo(params["index"]).Int() idx, err := base.StrTo(params["index"]).Int()
if err != nil { if err != nil {
ctx.Handle(404, "issue.UpdateIssue", err) ctx.Error(404)
return return
} }
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, int64(index)) issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, int64(idx))
if err != nil { if err != nil {
if err == models.ErrIssueNotExist { if err == models.ErrIssueNotExist {
ctx.Handle(404, "issue.UpdateIssue", err) ctx.Handle(404, "issue.UpdateIssue", err)
} else { } else {
ctx.Handle(200, "issue.UpdateIssue(get issue)", err) ctx.Handle(500, "issue.UpdateIssue(GetIssueByIndex)", err)
} }
return return
} }
@ -327,7 +319,7 @@ func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat
issue.Labels = form.Labels issue.Labels = form.Labels
issue.Content = form.Content issue.Content = form.Content
if err = models.UpdateIssue(issue); err != nil { if err = models.UpdateIssue(issue); err != nil {
ctx.Handle(200, "issue.UpdateIssue(update issue)", err) ctx.Handle(500, "issue.UpdateIssue(UpdateIssue)", err)
return return
} }
@ -338,6 +330,44 @@ func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat
}) })
} }
func UpdateAssignee(ctx *middleware.Context) {
if !ctx.Repo.IsOwner {
ctx.Error(403)
return
}
idx, err := base.StrTo(ctx.Query("issue")).Int64()
if err != nil {
ctx.Error(404)
return
}
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, idx)
if err != nil {
if err == models.ErrIssueNotExist {
ctx.Handle(404, "issue.UpdateAssignee", err)
} else {
ctx.Handle(500, "issue.UpdateAssignee(GetIssueByIndex)", err)
}
return
}
aid, _ := base.StrTo(ctx.Query("assigneeid")).Int64()
// Not check for invalid assignne id and give responsibility to owners.
issue.AssigneeId = aid
if err = models.UpdateIssueUserPairByAssignee(aid, issue.Id); err != nil {
ctx.Handle(500, "issue.UpdateAssignee(UpdateIssueUserPairByAssignee): %v", err)
return
} else if err = models.UpdateIssue(issue); err != nil {
ctx.Handle(500, "issue.UpdateAssignee(UpdateIssue)", err)
return
}
ctx.JSON(200, map[string]interface{}{
"ok": true,
})
}
func Comment(ctx *middleware.Context, params martini.Params) { func Comment(ctx *middleware.Context, params martini.Params) {
index, err := base.StrTo(ctx.Query("issueIndex")).Int64() index, err := base.StrTo(ctx.Query("issueIndex")).Int64()
if err != nil { if err != nil {

View file

@ -100,7 +100,7 @@
</div> </div>
<div class="issue-bar col-md-2"> <div class="issue-bar col-md-2">
<div class="assignee" data-assigned="{{if .Issue.Assignee}}{{.Issue.Assignee.Id}}{{else}}0{{end}}" data-ajax="{url}">{{if .IsRepositoryOwner}} <div class="assignee" data-assigned="{{if .Issue.Assignee}}{{.Issue.Assignee.Id}}{{else}}0{{end}}" data-ajax="{{.Issue.Index}}/assignee">{{if .IsRepositoryOwner}}
<div class="pull-right action"> <div class="pull-right action">
<button type="button" class="dropdown-toggle btn btn-default btn-sm" data-toggle="dropdown"> <button type="button" class="dropdown-toggle btn btn-default btn-sm" data-toggle="dropdown">
<i class="fa fa-group"></i> <i class="fa fa-group"></i>
@ -112,7 +112,6 @@
{{range .Collaborators}} {{range .Collaborators}}
<li data-uid="{{.Id}}"><img src="{{.AvatarLink}}"><strong>{{.Name}}</strong> {{.FullName}}</li> <li data-uid="{{.Id}}"><img src="{{.AvatarLink}}"><strong>{{.Name}}</strong> {{.FullName}}</li>
{{end}} {{end}}
<li data-uid="1"><img src="//1.gravatar.com/avatar/f72f7454ce9d710baa506394f68f4132"><strong>fuxiaohei</strong></li>
</ul> </ul>
</div> </div>
</div>{{end}} </div>{{end}}