finish new issue action and mentions

This commit is contained in:
Unknwon 2015-08-10 23:31:59 +08:00
parent 887bc1b594
commit cbc7b7132f
6 changed files with 123 additions and 100 deletions

View file

@ -122,6 +122,15 @@
"outputPathIsOutsideProject": 0, "outputPathIsOutsideProject": 0,
"outputPathIsSetByUser": 0 "outputPathIsSetByUser": 0
}, },
"\/public\/css\/gogs.min.css": {
"fileType": 16,
"ignore": 1,
"ignoreWasSetByUser": 0,
"inputAbbreviatedPath": "\/public\/css\/gogs.min.css",
"outputAbbreviatedPath": "No Output Path",
"outputPathIsOutsideProject": 0,
"outputPathIsSetByUser": 0
},
"\/public\/css\/jquery.datetimepicker.css": { "\/public\/css\/jquery.datetimepicker.css": {
"fileType": 16, "fileType": 16,
"ignore": 0, "ignore": 0,
@ -299,6 +308,26 @@
"outputPathIsSetByUser": 0, "outputPathIsSetByUser": 0,
"processed": 1 "processed": 1
}, },
"\/public\/less\/_base.less": {
"allowInsecureImports": 0,
"createSourceMap": 0,
"disableJavascript": 0,
"fileType": 1,
"ieCompatibility": 1,
"ignore": 1,
"ignoreWasSetByUser": 0,
"inputAbbreviatedPath": "\/public\/less\/_base.less",
"outputAbbreviatedPath": "\/public\/css\/_base.css",
"outputPathIsOutsideProject": 0,
"outputPathIsSetByUser": 0,
"outputStyle": 0,
"relativeURLS": 0,
"shouldRunAutoprefixer": 0,
"shouldRunBless": 0,
"strictImports": 0,
"strictMath": 0,
"strictUnits": 0
},
"\/public\/less\/_form.less": { "\/public\/less\/_form.less": {
"allowInsecureImports": 0, "allowInsecureImports": 0,
"createSourceMap": 0, "createSourceMap": 0,

View file

@ -188,6 +188,22 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64) (err error) {
return err return err
} }
// Notify watchers.
act := &Action{
ActUserID: issue.Poster.Id,
ActUserName: issue.Poster.Name,
ActEmail: issue.Poster.Email,
OpType: CREATE_ISSUE,
Content: fmt.Sprintf("%d|%s", issue.Index, issue.Name),
RepoID: repo.ID,
RepoUserName: repo.Owner.Name,
RepoName: repo.Name,
IsPrivate: repo.IsPrivate,
}
if err = notifyWatchers(sess, act); err != nil {
return err
}
return sess.Commit() return sess.Commit()
} }
@ -583,8 +599,8 @@ func UpdateIssueUserPairByRead(uid, iid int64) error {
return err return err
} }
// UpdateIssueUserPairsByMentions updates issue-user pairs by mentioning. // UpdateIssueUsersByMentions updates issue-user pairs by mentioning.
func UpdateIssueUserPairsByMentions(uids []int64, iid int64) error { func UpdateIssueUsersByMentions(uids []int64, iid int64) error {
for _, uid := range uids { for _, uid := range uids {
iu := &IssueUser{UID: uid, IssueID: iid} iu := &IssueUser{UID: uid, IssueID: iid}
has, err := x.Get(iu) has, err := x.Get(iu)

View file

@ -911,18 +911,19 @@ func UnFollowUser(userId int64, unFollowId int64) (err error) {
} }
func UpdateMentions(userNames []string, issueId int64) error { func UpdateMentions(userNames []string, issueId int64) error {
for i := range userNames {
userNames[i] = strings.ToLower(userNames[i])
}
users := make([]*User, 0, len(userNames)) users := make([]*User, 0, len(userNames))
if err := x.Where("name IN (?)", strings.Join(userNames, "\",\"")).OrderBy("name ASC").Find(&users); err != nil { if err := x.Where("lower_name IN (?)", strings.Join(userNames, "\",\"")).OrderBy("lower_name ASC").Find(&users); err != nil {
return err return err
} }
ids := make([]int64, 0, len(userNames)) ids := make([]int64, 0, len(userNames))
for _, user := range users { for _, user := range users {
ids = append(ids, user.Id) ids = append(ids, user.Id)
if !user.IsOrganization() {
if user.Type == INDIVIDUAL {
continue continue
} }
@ -931,9 +932,7 @@ func UpdateMentions(userNames []string, issueId int64) error {
} }
tempIds := make([]int64, 0, user.NumMembers) tempIds := make([]int64, 0, user.NumMembers)
orgUsers, err := GetOrgUsersByOrgId(user.Id) orgUsers, err := GetOrgUsersByOrgId(user.Id)
if err != nil { if err != nil {
return err return err
} }
@ -945,7 +944,7 @@ func UpdateMentions(userNames []string, issueId int64) error {
ids = append(ids, tempIds...) ids = append(ids, tempIds...)
} }
if err := UpdateIssueUserPairsByMentions(ids, issueId); err != nil { if err := UpdateIssueUsersByMentions(ids, issueId); err != nil {
return err return err
} }

File diff suppressed because one or more lines are too long

View file

@ -113,7 +113,7 @@
} }
} }
.assignee { .assignee {
margin-top: -5px; margin-top: -10px;
} }
} }
} }

View file

@ -246,6 +246,7 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
// Check milestone. // Check milestone.
milestoneID = form.MilestoneID milestoneID = form.MilestoneID
if milestoneID > 0 {
ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false) ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false)
if err != nil { if err != nil {
ctx.Handle(500, "GetMilestones: %v", err) ctx.Handle(500, "GetMilestones: %v", err)
@ -262,9 +263,11 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
return return
} }
ctx.Data["milestone_id"] = milestoneID ctx.Data["milestone_id"] = milestoneID
}
// Check assignee. // Check assignee.
assigneeID = form.AssigneeID assigneeID = form.AssigneeID
if assigneeID > 0 {
ctx.Data["Assignees"], err = repo.GetAssignees() ctx.Data["Assignees"], err = repo.GetAssignees()
if err != nil { if err != nil {
ctx.Handle(500, "GetAssignees: %v", err) ctx.Handle(500, "GetAssignees: %v", err)
@ -277,6 +280,7 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
} }
ctx.Data["assignee_id"] = assigneeID ctx.Data["assignee_id"] = assigneeID
} }
}
if ctx.HasError() { if ctx.HasError() {
ctx.HTML(200, ISSUE_NEW) ctx.HTML(200, ISSUE_NEW)
@ -288,6 +292,7 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
Index: int64(repo.NumIssues) + 1, Index: int64(repo.NumIssues) + 1,
Name: form.Title, Name: form.Title,
PosterID: ctx.User.Id, PosterID: ctx.User.Id,
Poster: ctx.User,
MilestoneID: milestoneID, MilestoneID: milestoneID,
AssigneeID: assigneeID, AssigneeID: assigneeID,
Content: form.Content, Content: form.Content,
@ -297,73 +302,47 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
return return
} }
// Update mentions.
mentions := base.MentionPattern.FindAllString(issue.Content, -1)
if len(mentions) > 0 {
for i := range mentions {
mentions[i] = mentions[i][1:]
}
if err := models.UpdateMentions(mentions, issue.ID); err != nil {
ctx.Handle(500, "UpdateMentions", err)
return
}
}
// Mail watchers and mentions.
if setting.Service.EnableNotifyMail {
tos, err := mailer.SendIssueNotifyMail(ctx.User, ctx.Repo.Owner, ctx.Repo.Repository, issue)
if err != nil {
ctx.Handle(500, "SendIssueNotifyMail", err)
return
}
tos = append(tos, ctx.User.LowerName)
newTos := make([]string, 0, len(mentions))
for _, m := range mentions {
if com.IsSliceContainsStr(tos, m) {
continue
}
newTos = append(newTos, m)
}
if err = mailer.SendIssueMentionMail(ctx.Render, ctx.User, ctx.Repo.Owner,
ctx.Repo.Repository, issue, models.GetUserEmailsByNames(newTos)); err != nil {
ctx.Handle(500, "SendIssueMentionMail", err)
return
}
}
log.Trace("Issue created: %d/%d", ctx.Repo.Repository.ID, issue.ID)
ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index)) ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
} }
func CreateIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
// if setting.AttachmentEnabled {
// uploadFiles(ctx, issue.ID, 0)
// }
// // Update mentions.
// ms := base.MentionPattern.FindAllString(issue.Content, -1)
// if len(ms) > 0 {
// for i := range ms {
// ms[i] = ms[i][1:]
// }
// if err := models.UpdateMentions(ms, issue.ID); err != nil {
// send(500, nil, err)
// return
// }
// }
// act := &models.Action{
// ActUserID: ctx.User.Id,
// ActUserName: ctx.User.Name,
// ActEmail: ctx.User.Email,
// OpType: models.CREATE_ISSUE,
// Content: fmt.Sprintf("%d|%s", issue.Index, issue.Name),
// RepoID: ctx.Repo.Repository.ID,
// RepoUserName: ctx.Repo.Owner.Name,
// RepoName: ctx.Repo.Repository.Name,
// RefName: ctx.Repo.BranchName,
// IsPrivate: ctx.Repo.Repository.IsPrivate,
// }
// // Notify watchers.
// if err := models.NotifyWatchers(act); err != nil {
// send(500, nil, err)
// return
// }
// // Mail watchers and mentions.
// if setting.Service.EnableNotifyMail {
// tos, err := mailer.SendIssueNotifyMail(ctx.User, ctx.Repo.Owner, ctx.Repo.Repository, issue)
// if err != nil {
// send(500, nil, err)
// return
// }
// tos = append(tos, ctx.User.LowerName)
// newTos := make([]string, 0, len(ms))
// for _, m := range ms {
// if com.IsSliceContainsStr(tos, m) {
// continue
// }
// newTos = append(newTos, m)
// }
// if err = mailer.SendIssueMentionMail(ctx.Render, ctx.User, ctx.Repo.Owner,
// ctx.Repo.Repository, issue, models.GetUserEmailsByNames(newTos)); err != nil {
// send(500, nil, err)
// return
// }
// }
// log.Trace("%d Issue created: %d", ctx.Repo.Repository.ID, issue.ID)
// send(200, fmt.Sprintf("%s/%s/%s/issues/%d", setting.AppSubUrl, ctx.Params(":username"), ctx.Params(":reponame"), issue.Index), nil)
}
func checkLabels(labels, allLabels []*models.Label) { func checkLabels(labels, allLabels []*models.Label) {
for _, l := range labels { for _, l := range labels {
for _, l2 := range allLabels { for _, l2 := range allLabels {