mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 19:06:18 +01:00 
			
		
		
		
	finish view comments on issue page
This commit is contained in:
		
							
								
								
									
										20
									
								
								cmd/web.go
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								cmd/web.go
									
									
									
									
									
								
							| @@ -228,14 +228,16 @@ func runWeb(ctx *cli.Context) { | |||||||
| 			}) | 			}) | ||||||
|  |  | ||||||
| 			// Repositories. | 			// Repositories. | ||||||
| 			m.Combo("/user/repos", middleware.ApiReqToken()).Get(v1.ListMyRepos).Post(bind(api.CreateRepoOption{}), v1.CreateRepo) | 			m.Combo("/user/repos", middleware.ApiReqToken()).Get(v1.ListMyRepos). | ||||||
|  | 				Post(bind(api.CreateRepoOption{}), v1.CreateRepo) | ||||||
| 			m.Post("/org/:org/repos", middleware.ApiReqToken(), bind(api.CreateRepoOption{}), v1.CreateOrgRepo) | 			m.Post("/org/:org/repos", middleware.ApiReqToken(), bind(api.CreateRepoOption{}), v1.CreateOrgRepo) | ||||||
| 			m.Group("/repos", func() { | 			m.Group("/repos", func() { | ||||||
| 				m.Get("/search", v1.SearchRepos) | 				m.Get("/search", v1.SearchRepos) | ||||||
| 				m.Post("/migrate", bindIgnErr(auth.MigrateRepoForm{}), v1.MigrateRepo) | 				m.Post("/migrate", bindIgnErr(auth.MigrateRepoForm{}), v1.MigrateRepo) | ||||||
|  |  | ||||||
| 				m.Group("/:username/:reponame", func() { | 				m.Group("/:username/:reponame", func() { | ||||||
| 					m.Combo("/hooks").Get(v1.ListRepoHooks).Post(bind(api.CreateHookOption{}), v1.CreateRepoHook) | 					m.Combo("/hooks").Get(v1.ListRepoHooks). | ||||||
|  | 						Post(bind(api.CreateHookOption{}), v1.CreateRepoHook) | ||||||
| 					m.Patch("/hooks/:id:int", bind(api.EditHookOption{}), v1.EditRepoHook) | 					m.Patch("/hooks/:id:int", bind(api.EditHookOption{}), v1.EditRepoHook) | ||||||
| 					m.Get("/raw/*", middleware.RepoRef(), v1.GetRepoRawFile) | 					m.Get("/raw/*", middleware.RepoRef(), v1.GetRepoRawFile) | ||||||
| 				}, middleware.ApiRepoAssignment(), middleware.ApiReqToken()) | 				}, middleware.ApiRepoAssignment(), middleware.ApiReqToken()) | ||||||
| @@ -450,10 +452,14 @@ func runWeb(ctx *cli.Context) { | |||||||
| 		m.Group("/issues", func() { | 		m.Group("/issues", func() { | ||||||
| 			m.Combo("/new").Get(repo.NewIssue). | 			m.Combo("/new").Get(repo.NewIssue). | ||||||
| 				Post(bindIgnErr(auth.CreateIssueForm{}), repo.NewIssuePost) | 				Post(bindIgnErr(auth.CreateIssueForm{}), repo.NewIssuePost) | ||||||
| 			m.Post("/:index", bindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue) |  | ||||||
| 			m.Post("/:index/label", repo.UpdateIssueLabel) | 			m.Group("/:index", func() { | ||||||
| 			m.Post("/:index/milestone", repo.UpdateIssueMilestone) | 				m.Post("", bindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue) | ||||||
| 			m.Post("/:index/assignee", repo.UpdateAssignee) | 				m.Post("/label", repo.UpdateIssueLabel) | ||||||
|  | 				m.Post("/milestone", repo.UpdateIssueMilestone) | ||||||
|  | 				m.Post("/assignee", repo.UpdateAssignee) | ||||||
|  | 				m.Combo("/comments").Post(bindIgnErr(auth.CreateCommentForm{}), repo.NewComment) | ||||||
|  | 			}) | ||||||
| 		}) | 		}) | ||||||
| 		m.Group("/labels", func() { | 		m.Group("/labels", func() { | ||||||
| 			m.Post("/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel) | 			m.Post("/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel) | ||||||
| @@ -469,8 +475,6 @@ func runWeb(ctx *cli.Context) { | |||||||
| 			m.Post("/delete", repo.DeleteMilestone) | 			m.Post("/delete", repo.DeleteMilestone) | ||||||
| 		}, reqRepoAdmin) | 		}, reqRepoAdmin) | ||||||
|  |  | ||||||
| 		m.Post("/comment/:action", repo.Comment) |  | ||||||
|  |  | ||||||
| 		m.Group("/releases", func() { | 		m.Group("/releases", func() { | ||||||
| 			m.Get("/new", repo.NewRelease) | 			m.Get("/new", repo.NewRelease) | ||||||
| 			m.Post("/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost) | 			m.Post("/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost) | ||||||
|   | |||||||
| @@ -405,8 +405,8 @@ issues.next = Next | |||||||
| issues.open_title = Open | issues.open_title = Open | ||||||
| issues.closed_title = Closed | issues.closed_title = Closed | ||||||
| issues.num_comments = %d comments | issues.num_comments = %d comments | ||||||
| issues.commented_at = commented at <a href="%s">%s</a> | issues.commented_at = `commented at <a id="%[1]s" href="#%[1]s">%[2]s</a>` | ||||||
| issues.no_content = There is no content if this issue. | issues.no_content = There is no content yet. | ||||||
| issues.close_issue = Close | issues.close_issue = Close | ||||||
| issues.close_comment_issue = Close and comment | issues.close_comment_issue = Close and comment | ||||||
| issues.create_comment = Comment | issues.create_comment = Comment | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								gogs.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								gogs.go
									
									
									
									
									
								
							| @@ -17,7 +17,7 @@ import ( | |||||||
| 	"github.com/gogits/gogs/modules/setting" | 	"github.com/gogits/gogs/modules/setting" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| const APP_VER = "0.6.4.0812 Beta" | const APP_VER = "0.6.4.0813 Beta" | ||||||
|  |  | ||||||
| func init() { | func init() { | ||||||
| 	runtime.GOMAXPROCS(runtime.NumCPU()) | 	runtime.GOMAXPROCS(runtime.NumCPU()) | ||||||
|   | |||||||
| @@ -124,7 +124,7 @@ func (a Action) GetIssueInfos() []string { | |||||||
| 	return strings.SplitN(a.Content, "|", 2) | 	return strings.SplitN(a.Content, "|", 2) | ||||||
| } | } | ||||||
|  |  | ||||||
| func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, commits []*base.PushCommit) error { | func updateIssuesCommit(u *User, repo *Repository, repoUserName, repoName string, commits []*base.PushCommit) error { | ||||||
| 	for _, c := range commits { | 	for _, c := range commits { | ||||||
| 		for _, ref := range IssueReferenceKeywordsPat.FindAllString(c.Message, -1) { | 		for _, ref := range IssueReferenceKeywordsPat.FindAllString(c.Message, -1) { | ||||||
| 			ref := ref[strings.IndexByte(ref, byte(' '))+1:] | 			ref := ref[strings.IndexByte(ref, byte(' '))+1:] | ||||||
| @@ -153,7 +153,7 @@ func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, com | |||||||
|  |  | ||||||
| 			url := fmt.Sprintf("%s/%s/%s/commit/%s", setting.AppSubUrl, repoUserName, repoName, c.Sha1) | 			url := fmt.Sprintf("%s/%s/%s/commit/%s", setting.AppSubUrl, repoUserName, repoName, c.Sha1) | ||||||
| 			message := fmt.Sprintf(`<a href="%s">%s</a>`, url, c.Message) | 			message := fmt.Sprintf(`<a href="%s">%s</a>`, url, c.Message) | ||||||
| 			if _, err = CreateComment(userId, issue.RepoID, issue.ID, 0, 0, COMMENT_TYPE_COMMIT, message, nil); err != nil { | 			if _, err = CreateComment(u, repo, issue, 0, 0, COMMENT_TYPE_COMMIT, message, nil); err != nil { | ||||||
| 				return err | 				return err | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| @@ -183,7 +183,7 @@ func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, com | |||||||
| 				return err | 				return err | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			if issue.RepoID == repoId { | 			if issue.RepoID == repo.ID { | ||||||
| 				if issue.IsClosed { | 				if issue.IsClosed { | ||||||
| 					continue | 					continue | ||||||
| 				} | 				} | ||||||
| @@ -202,7 +202,7 @@ func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, com | |||||||
|  |  | ||||||
| 				if err = UpdateIssue(issue); err != nil { | 				if err = UpdateIssue(issue); err != nil { | ||||||
| 					return err | 					return err | ||||||
| 				} else if err = UpdateIssueUserPairsByStatus(issue.ID, issue.IsClosed); err != nil { | 				} else if err = UpdateIssueUsersByStatus(issue.ID, issue.IsClosed); err != nil { | ||||||
| 					return err | 					return err | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
| @@ -211,7 +211,7 @@ func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, com | |||||||
| 				} | 				} | ||||||
|  |  | ||||||
| 				// If commit happened in the referenced repository, it means the issue can be closed. | 				// If commit happened in the referenced repository, it means the issue can be closed. | ||||||
| 				if _, err = CreateComment(userId, repoId, issue.ID, 0, 0, COMMENT_TYPE_CLOSE, "", nil); err != nil { | 				if _, err = CreateComment(u, repo, issue, 0, 0, COMMENT_TYPE_CLOSE, "", nil); err != nil { | ||||||
| 					return err | 					return err | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| @@ -242,7 +242,7 @@ func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, com | |||||||
| 				return err | 				return err | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			if issue.RepoID == repoId { | 			if issue.RepoID == repo.ID { | ||||||
| 				if !issue.IsClosed { | 				if !issue.IsClosed { | ||||||
| 					continue | 					continue | ||||||
| 				} | 				} | ||||||
| @@ -261,7 +261,7 @@ func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, com | |||||||
|  |  | ||||||
| 				if err = UpdateIssue(issue); err != nil { | 				if err = UpdateIssue(issue); err != nil { | ||||||
| 					return err | 					return err | ||||||
| 				} else if err = UpdateIssueUserPairsByStatus(issue.ID, issue.IsClosed); err != nil { | 				} else if err = UpdateIssueUsersByStatus(issue.ID, issue.IsClosed); err != nil { | ||||||
| 					return err | 					return err | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
| @@ -270,7 +270,7 @@ func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, com | |||||||
| 				} | 				} | ||||||
|  |  | ||||||
| 				// If commit happened in the referenced repository, it means the issue can be closed. | 				// If commit happened in the referenced repository, it means the issue can be closed. | ||||||
| 				if _, err = CreateComment(userId, repoId, issue.ID, 0, 0, COMMENT_TYPE_REOPEN, "", nil); err != nil { | 				if _, err = CreateComment(u, repo, issue, 0, 0, COMMENT_TYPE_REOPEN, "", nil); err != nil { | ||||||
| 					return err | 					return err | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| @@ -280,8 +280,8 @@ func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, com | |||||||
| } | } | ||||||
|  |  | ||||||
| // CommitRepoAction adds new action for committing repository. | // CommitRepoAction adds new action for committing repository. | ||||||
| func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, | func CommitRepoAction(userID, repoUserID int64, userName, actEmail string, | ||||||
| 	repoId int64, repoUserName, repoName string, refFullName string, commit *base.PushCommits, oldCommitId string, newCommitId string) error { | 	repoID int64, repoUserName, repoName string, refFullName string, commit *base.PushCommits, oldCommitID string, newCommitID string) error { | ||||||
|  |  | ||||||
| 	opType := COMMIT_REPO | 	opType := COMMIT_REPO | ||||||
| 	// Check it's tag push or branch. | 	// Check it's tag push or branch. | ||||||
| @@ -292,40 +292,44 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, | |||||||
|  |  | ||||||
| 	repoLink := fmt.Sprintf("%s%s/%s", setting.AppUrl, repoUserName, repoName) | 	repoLink := fmt.Sprintf("%s%s/%s", setting.AppUrl, repoUserName, repoName) | ||||||
| 	// if not the first commit, set the compareUrl | 	// if not the first commit, set the compareUrl | ||||||
| 	if !strings.HasPrefix(oldCommitId, "0000000") { | 	if !strings.HasPrefix(oldCommitID, "0000000") { | ||||||
| 		commit.CompareUrl = fmt.Sprintf("%s/%s/compare/%s...%s", repoUserName, repoName, oldCommitId, newCommitId) | 		commit.CompareUrl = fmt.Sprintf("%s/%s/compare/%s...%s", repoUserName, repoName, oldCommitID, newCommitID) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	bs, err := json.Marshal(commit) | 	bs, err := json.Marshal(commit) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return errors.New("json: " + err.Error()) | 		return fmt.Errorf("Marshal: %v", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	refName := git.RefEndName(refFullName) | 	refName := git.RefEndName(refFullName) | ||||||
|  |  | ||||||
| 	// Change repository bare status and update last updated time. | 	// Change repository bare status and update last updated time. | ||||||
| 	repo, err := GetRepositoryByName(repoUserId, repoName) | 	repo, err := GetRepositoryByName(repoUserID, repoName) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return errors.New("GetRepositoryByName: " + err.Error()) | 		return fmt.Errorf("GetRepositoryByName: %v", err) | ||||||
| 	} | 	} | ||||||
| 	repo.IsBare = false | 	repo.IsBare = false | ||||||
| 	if err = UpdateRepository(repo, false); err != nil { | 	if err = UpdateRepository(repo, false); err != nil { | ||||||
| 		return errors.New("UpdateRepository: " + err.Error()) | 		return fmt.Errorf("UpdateRepository: %v", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	err = updateIssuesCommit(userId, repoId, repoUserName, repoName, commit.Commits) | 	u, err := GetUserByID(userID) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return fmt.Errorf("GetUserByID: %v", err) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	err = updateIssuesCommit(u, repo, repoUserName, repoName, commit.Commits) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		log.Debug("updateIssuesCommit: ", err) | 		log.Debug("updateIssuesCommit: ", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if err = NotifyWatchers(&Action{ | 	if err = NotifyWatchers(&Action{ | ||||||
| 		ActUserID:    userId, | 		ActUserID:    u.Id, | ||||||
| 		ActUserName:  userName, | 		ActUserName:  userName, | ||||||
| 		ActEmail:     actEmail, | 		ActEmail:     actEmail, | ||||||
| 		OpType:       opType, | 		OpType:       opType, | ||||||
| 		Content:      string(bs), | 		Content:      string(bs), | ||||||
| 		RepoID:       repoId, | 		RepoID:       repo.ID, | ||||||
| 		RepoUserName: repoUserName, | 		RepoUserName: repoUserName, | ||||||
| 		RepoName:     repoName, | 		RepoName:     repoName, | ||||||
| 		RefName:      refName, | 		RefName:      refName, | ||||||
| @@ -340,7 +344,7 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, | |||||||
| 		return errors.New("GetOwner: " + err.Error()) | 		return errors.New("GetOwner: " + err.Error()) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	ws, err := GetActiveWebhooksByRepoId(repoId) | 	ws, err := GetActiveWebhooksByRepoId(repo.ID) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return errors.New("GetActiveWebhooksByRepoId: " + err.Error()) | 		return errors.New("GetActiveWebhooksByRepoId: " + err.Error()) | ||||||
| 	} | 	} | ||||||
| @@ -406,8 +410,8 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, | |||||||
| 			Email:    pusher_email, | 			Email:    pusher_email, | ||||||
| 			UserName: userName, | 			UserName: userName, | ||||||
| 		}, | 		}, | ||||||
| 		Before:     oldCommitId, | 		Before:     oldCommitID, | ||||||
| 		After:      newCommitId, | 		After:      newCommitID, | ||||||
| 		CompareUrl: setting.AppUrl + commit.CompareUrl, | 		CompareUrl: setting.AppUrl + commit.CompareUrl, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										306
									
								
								models/issue.go
									
									
									
									
									
								
							
							
						
						
									
										306
									
								
								models/issue.go
									
									
									
									
									
								
							| @@ -8,7 +8,6 @@ import ( | |||||||
| 	"bytes" | 	"bytes" | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"html/template" |  | ||||||
| 	"io" | 	"io" | ||||||
| 	"mime/multipart" | 	"mime/multipart" | ||||||
| 	"os" | 	"os" | ||||||
| @@ -58,11 +57,12 @@ type Issue struct { | |||||||
| 	Updated         time.Time `xorm:"UPDATED"` | 	Updated         time.Time `xorm:"UPDATED"` | ||||||
|  |  | ||||||
| 	Attachments []*Attachment `xorm:"-"` | 	Attachments []*Attachment `xorm:"-"` | ||||||
|  | 	Comments    []*Comment    `xorm:"-"` | ||||||
| } | } | ||||||
|  |  | ||||||
| // HashTag returns unique hash tag for issue. | // HashTag returns unique hash tag for issue. | ||||||
| func (i *Issue) HashTag() string { | func (i *Issue) HashTag() string { | ||||||
| 	return "#issue-" + com.ToStr(i.Index) | 	return "issue-" + com.ToStr(i.ID) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (i *Issue) AfterSet(colName string, _ xorm.Cell) { | func (i *Issue) AfterSet(colName string, _ xorm.Cell) { | ||||||
| @@ -74,6 +74,11 @@ func (i *Issue) AfterSet(colName string, _ xorm.Cell) { | |||||||
| 			log.Error(3, "GetAttachmentsByIssueID[%d]: %v", i.ID, err) | 			log.Error(3, "GetAttachmentsByIssueID[%d]: %v", i.ID, err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		i.Comments, err = GetCommentsByIssueID(i.ID) | ||||||
|  | 		if err != nil { | ||||||
|  | 			log.Error(3, "GetCommentsByIssueID[%d]: %v", i.ID, err) | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 	case "milestone_id": | 	case "milestone_id": | ||||||
| 		if i.MilestoneID == 0 { | 		if i.MilestoneID == 0 { | ||||||
| 			return | 			return | ||||||
| @@ -95,6 +100,11 @@ func (i *Issue) AfterSet(colName string, _ xorm.Cell) { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // IsPoster returns true if given user by ID is the poster. | ||||||
|  | func (i *Issue) IsPoster(uid int64) bool { | ||||||
|  | 	return i.PosterID == uid | ||||||
|  | } | ||||||
|  |  | ||||||
| func (i *Issue) GetPoster() (err error) { | func (i *Issue) GetPoster() (err error) { | ||||||
| 	i.Poster, err = GetUserByID(i.PosterID) | 	i.Poster, err = GetUserByID(i.PosterID) | ||||||
| 	if IsErrUserNotExist(err) { | 	if IsErrUserNotExist(err) { | ||||||
| @@ -165,6 +175,61 @@ func (i *Issue) ReadBy(uid int64) error { | |||||||
| 	return UpdateIssueUserByRead(uid, i.ID) | 	return UpdateIssueUserByRead(uid, i.ID) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (i *Issue) changeStatus(e *xorm.Session, doer *User, isClosed bool) (err error) { | ||||||
|  | 	if i.IsClosed == isClosed { | ||||||
|  | 		return nil | ||||||
|  | 	} | ||||||
|  | 	i.IsClosed = isClosed | ||||||
|  |  | ||||||
|  | 	if err = updateIssue(e, i); err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} else if err = updateIssueUsersByStatus(e, i.ID, isClosed); err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Update labels. | ||||||
|  | 	if err = i.getLabels(e); err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  | 	for idx := range i.Labels { | ||||||
|  | 		if i.IsClosed { | ||||||
|  | 			i.Labels[idx].NumClosedIssues++ | ||||||
|  | 		} else { | ||||||
|  | 			i.Labels[idx].NumClosedIssues-- | ||||||
|  | 		} | ||||||
|  | 		if err = updateLabel(e, i.Labels[idx]); err != nil { | ||||||
|  | 			return err | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Update milestone. | ||||||
|  | 	if err = changeMilestoneIssueStats(e, i); err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// New action comment. | ||||||
|  | 	if _, err = createStatusComment(e, doer, i.Repo, i); err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // ChangeStatus changes issue status to open/closed. | ||||||
|  | func (i *Issue) ChangeStatus(doer *User, isClosed bool) (err error) { | ||||||
|  | 	sess := x.NewSession() | ||||||
|  | 	defer sessionRelease(sess) | ||||||
|  | 	if err = sess.Begin(); err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if err = i.changeStatus(sess, doer, isClosed); err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	return sess.Commit() | ||||||
|  | } | ||||||
|  |  | ||||||
| // CreateIssue creates new issue with labels for repository. | // CreateIssue creates new issue with labels for repository. | ||||||
| func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) { | func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) { | ||||||
| 	// Check attachments. | 	// Check attachments. | ||||||
| @@ -587,13 +652,16 @@ func UpdateIssue(issue *Issue) error { | |||||||
| 	return updateIssue(x, issue) | 	return updateIssue(x, issue) | ||||||
| } | } | ||||||
|  |  | ||||||
| // UpdateIssueUserByStatus updates issue-user pairs by issue status. | func updateIssueUsersByStatus(e Engine, issueID int64, isClosed bool) error { | ||||||
| func UpdateIssueUserPairsByStatus(iid int64, isClosed bool) error { | 	_, err := e.Exec("UPDATE `issue_user` SET is_closed=? WHERE issue_id=?", isClosed, issueID) | ||||||
| 	rawSql := "UPDATE `issue_user` SET is_closed = ? WHERE issue_id = ?" |  | ||||||
| 	_, err := x.Exec(rawSql, isClosed, iid) |  | ||||||
| 	return err | 	return err | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // UpdateIssueUsersByStatus updates issue-user relations by issue status. | ||||||
|  | func UpdateIssueUsersByStatus(issueID int64, isClosed bool) error { | ||||||
|  | 	return updateIssueUsersByStatus(x, issueID, isClosed) | ||||||
|  | } | ||||||
|  |  | ||||||
| func updateIssueUserByAssignee(e *xorm.Session, issueID, assigneeID int64) (err error) { | func updateIssueUserByAssignee(e *xorm.Session, issueID, assigneeID int64) (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, issueID); err != nil { | ||||||
| 		return err | 		return err | ||||||
| @@ -729,12 +797,16 @@ func GetLabelsByIssueID(issueID int64) ([]*Label, error) { | |||||||
| 	return getLabelsByIssueID(x, issueID) | 	return getLabelsByIssueID(x, issueID) | ||||||
| } | } | ||||||
|  |  | ||||||
| // UpdateLabel updates label information. | func updateLabel(e Engine, l *Label) error { | ||||||
| func UpdateLabel(l *Label) error { |  | ||||||
| 	_, err := x.Id(l.ID).AllCols().Update(l) | 	_, err := x.Id(l.ID).AllCols().Update(l) | ||||||
| 	return err | 	return err | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // UpdateLabel updates label information. | ||||||
|  | func UpdateLabel(l *Label) error { | ||||||
|  | 	return updateLabel(x, l) | ||||||
|  | } | ||||||
|  |  | ||||||
| // DeleteLabel delete a label of given repository. | // DeleteLabel delete a label of given repository. | ||||||
| func DeleteLabel(repoID, labelID int64) error { | func DeleteLabel(repoID, labelID int64) error { | ||||||
| 	l, err := GetLabelByID(labelID) | 	l, err := GetLabelByID(labelID) | ||||||
| @@ -998,14 +1070,12 @@ func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) { | |||||||
| 	return sess.Commit() | 	return sess.Commit() | ||||||
| } | } | ||||||
|  |  | ||||||
| // ChangeMilestoneIssueStats updates the open/closed issues counter and progress | func changeMilestoneIssueStats(e *xorm.Session, issue *Issue) error { | ||||||
| // for the milestone associated witht the given issue. |  | ||||||
| func ChangeMilestoneIssueStats(issue *Issue) error { |  | ||||||
| 	if issue.MilestoneID == 0 { | 	if issue.MilestoneID == 0 { | ||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	m, err := GetMilestoneByID(issue.MilestoneID) | 	m, err := getMilestoneByID(e, issue.MilestoneID) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| @@ -1018,7 +1088,23 @@ func ChangeMilestoneIssueStats(issue *Issue) error { | |||||||
| 		m.NumClosedIssues-- | 		m.NumClosedIssues-- | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return UpdateMilestone(m) | 	return updateMilestone(e, m) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // ChangeMilestoneIssueStats updates the open/closed issues counter and progress | ||||||
|  | // for the milestone associated witht the given issue. | ||||||
|  | func ChangeMilestoneIssueStats(issue *Issue) (err error) { | ||||||
|  | 	sess := x.NewSession() | ||||||
|  | 	defer sessionRelease(sess) | ||||||
|  | 	if err = sess.Begin(); err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if err = changeMilestoneIssueStats(sess, issue); err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	return sess.Commit() | ||||||
| } | } | ||||||
|  |  | ||||||
| func changeMilestoneAssign(e *xorm.Session, oldMid int64, issue *Issue) error { | func changeMilestoneAssign(e *xorm.Session, oldMid int64, issue *Issue) error { | ||||||
| @@ -1145,98 +1231,165 @@ const ( | |||||||
|  |  | ||||||
| // Comment represents a comment in commit and issue page. | // Comment represents a comment in commit and issue page. | ||||||
| type Comment struct { | type Comment struct { | ||||||
| 	Id       int64 | 	ID              int64 `xorm:"pk autoincr"` | ||||||
| 	Type     CommentType | 	Type            CommentType | ||||||
| 	PosterId int64 | 	PosterID        int64 | ||||||
| 	Poster   *User `xorm:"-"` | 	Poster          *User `xorm:"-"` | ||||||
| 	IssueId  int64 | 	IssueID         int64 `xorm:"INDEX"` | ||||||
| 	CommitId int64 | 	CommitID        int64 | ||||||
| 	Line     int64 | 	Line            int64 | ||||||
| 	Content  string    `xorm:"TEXT"` | 	Content         string    `xorm:"TEXT"` | ||||||
| 	Created  time.Time `xorm:"CREATED"` | 	RenderedContent string    `xorm:"-"` | ||||||
|  | 	Created         time.Time `xorm:"CREATED"` | ||||||
|  |  | ||||||
|  | 	Attachments []*Attachment `xorm:"-"` | ||||||
| } | } | ||||||
|  |  | ||||||
| // CreateComment creates comment of issue or commit. | // HashTag returns unique hash tag for issue. | ||||||
| func CreateComment(userId, repoId, issueId, commitId, line int64, cmtType CommentType, content string, attachments []int64) (*Comment, error) { | func (c *Comment) HashTag() string { | ||||||
| 	sess := x.NewSession() | 	return "issuecomment-" + com.ToStr(c.ID) | ||||||
| 	defer sessionRelease(sess) | } | ||||||
| 	if err := sess.Begin(); err != nil { |  | ||||||
| 		return nil, err | func (c *Comment) AfterSet(colName string, _ xorm.Cell) { | ||||||
|  | 	var err error | ||||||
|  | 	switch colName { | ||||||
|  | 	case "id": | ||||||
|  | 		c.Attachments, err = GetAttachmentsByCommentID(c.ID) | ||||||
|  | 		if err != nil { | ||||||
|  | 			log.Error(3, "GetAttachmentsByCommentID[%d]: %v", c.ID, err) | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 	case "poster_id": | ||||||
|  | 		c.Poster, err = GetUserByID(c.PosterID) | ||||||
|  | 		if err != nil { | ||||||
|  | 			if IsErrUserNotExist(err) { | ||||||
|  | 				c.PosterID = -1 | ||||||
|  | 				c.Poster = &User{Name: "someone"} | ||||||
|  | 			} else { | ||||||
|  | 				log.Error(3, "GetUserByID[%d]: %v", c.ID, err) | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
| 	comment := &Comment{PosterId: userId, Type: cmtType, IssueId: issueId, | func createComment(e *xorm.Session, u *User, repo *Repository, issue *Issue, commitID, line int64, cmtType CommentType, content string, uuids []string) (_ *Comment, err error) { | ||||||
| 		CommitId: commitId, Line: line, Content: content} | 	comment := &Comment{ | ||||||
|  | 		PosterID: u.Id, | ||||||
| 	if _, err := sess.Insert(comment); err != nil { | 		Type:     cmtType, | ||||||
|  | 		IssueID:  issue.ID, | ||||||
|  | 		CommitID: commitID, | ||||||
|  | 		Line:     line, | ||||||
|  | 		Content:  content, | ||||||
|  | 	} | ||||||
|  | 	if _, err = e.Insert(comment); err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// Check comment type. | 	// Check comment type. | ||||||
| 	switch cmtType { | 	switch cmtType { | ||||||
| 	case COMMENT_TYPE_COMMENT: | 	case COMMENT_TYPE_COMMENT: | ||||||
| 		rawSql := "UPDATE `issue` SET num_comments = num_comments + 1 WHERE id = ?" | 		if _, err = e.Exec("UPDATE `issue` SET num_comments=num_comments+1 WHERE id=?", issue.ID); err != nil { | ||||||
| 		if _, err := sess.Exec(rawSql, issueId); err != nil { |  | ||||||
| 			return nil, err | 			return nil, err | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if len(attachments) > 0 { | 		// Check attachments. | ||||||
| 			rawSql = "UPDATE `attachment` SET comment_id = ? WHERE id IN (?)" | 		attachments := make([]*Attachment, 0, len(uuids)) | ||||||
|  | 		for _, uuid := range uuids { | ||||||
| 			astrs := make([]string, 0, len(attachments)) | 			attach, err := getAttachmentByUUID(e, uuid) | ||||||
|  | 			if err != nil { | ||||||
| 			for _, a := range attachments { | 				if IsErrAttachmentNotExist(err) { | ||||||
| 				astrs = append(astrs, strconv.FormatInt(a, 10)) | 					continue | ||||||
|  | 				} | ||||||
|  | 				return nil, fmt.Errorf("getAttachmentByUUID[%s]: %v", uuid, err) | ||||||
| 			} | 			} | ||||||
|  | 			attachments = append(attachments, attach) | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 			if _, err := sess.Exec(rawSql, comment.Id, strings.Join(astrs, ",")); err != nil { | 		for i := range attachments { | ||||||
| 				return nil, err | 			attachments[i].IssueID = issue.ID | ||||||
|  | 			attachments[i].CommentID = comment.ID | ||||||
|  | 			// No assign value could be 0, so ignore AllCols(). | ||||||
|  | 			if _, err = e.Id(attachments[i].ID).Update(attachments[i]); err != nil { | ||||||
|  | 				return nil, fmt.Errorf("update attachment[%d]: %v", attachments[i].ID, err) | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		// Notify watchers. | ||||||
|  | 		act := &Action{ | ||||||
|  | 			ActUserID:    u.Id, | ||||||
|  | 			ActUserName:  u.LowerName, | ||||||
|  | 			ActEmail:     u.Email, | ||||||
|  | 			OpType:       COMMENT_ISSUE, | ||||||
|  | 			Content:      fmt.Sprintf("%d|%s", issue.Index, strings.Split(content, "\n")[0]), | ||||||
|  | 			RepoID:       repo.ID, | ||||||
|  | 			RepoUserName: repo.Owner.LowerName, | ||||||
|  | 			RepoName:     repo.LowerName, | ||||||
|  | 			IsPrivate:    repo.IsPrivate, | ||||||
|  | 		} | ||||||
|  | 		if err = notifyWatchers(e, act); err != nil { | ||||||
|  | 			return nil, err | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 	case COMMENT_TYPE_REOPEN: | 	case COMMENT_TYPE_REOPEN: | ||||||
| 		rawSql := "UPDATE `repository` SET num_closed_issues = num_closed_issues - 1 WHERE id = ?" | 		if _, err = e.Exec("UPDATE `repository` SET num_closed_issues=num_closed_issues-1 WHERE id=?", repo.ID); err != nil { | ||||||
| 		if _, err := sess.Exec(rawSql, repoId); err != nil { |  | ||||||
| 			return nil, err | 			return nil, err | ||||||
| 		} | 		} | ||||||
| 	case COMMENT_TYPE_CLOSE: | 	case COMMENT_TYPE_CLOSE: | ||||||
| 		rawSql := "UPDATE `repository` SET num_closed_issues = num_closed_issues + 1 WHERE id = ?" | 		if _, err = e.Exec("UPDATE `repository` SET num_closed_issues=num_closed_issues+1 WHERE id=?", repo.ID); err != nil { | ||||||
| 		if _, err := sess.Exec(rawSql, repoId); err != nil { |  | ||||||
| 			return nil, err | 			return nil, err | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	return comment, nil | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func createStatusComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue) (*Comment, error) { | ||||||
|  | 	cmtType := COMMENT_TYPE_CLOSE | ||||||
|  | 	if !issue.IsClosed { | ||||||
|  | 		cmtType = COMMENT_TYPE_REOPEN | ||||||
|  | 	} | ||||||
|  | 	return createComment(e, doer, repo, issue, 0, 0, cmtType, "", nil) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // CreateComment creates comment of issue or commit. | ||||||
|  | func CreateComment(doer *User, repo *Repository, issue *Issue, commitID, line int64, cmtType CommentType, content string, attachments []string) (comment *Comment, err error) { | ||||||
|  | 	sess := x.NewSession() | ||||||
|  | 	defer sessionRelease(sess) | ||||||
|  | 	if err = sess.Begin(); err != nil { | ||||||
|  | 		return nil, err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	comment, err = createComment(sess, doer, repo, issue, commitID, line, cmtType, content, attachments) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return nil, err | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	return comment, sess.Commit() | 	return comment, sess.Commit() | ||||||
| } | } | ||||||
|  |  | ||||||
| // GetCommentById returns the comment with the given id | // CreateIssueComment creates a plain issue comment. | ||||||
| func GetCommentById(commentId int64) (*Comment, error) { | func CreateIssueComment(doer *User, repo *Repository, issue *Issue, content string, attachments []string) (*Comment, error) { | ||||||
| 	c := &Comment{Id: commentId} | 	return CreateComment(doer, repo, issue, 0, 0, COMMENT_TYPE_COMMENT, content, attachments) | ||||||
| 	_, err := x.Get(c) | } | ||||||
|  |  | ||||||
|  | // GetCommentById returns the comment with the given id | ||||||
|  | func GetCommentById(id int64) (*Comment, error) { | ||||||
|  | 	c := new(Comment) | ||||||
|  | 	_, err := x.Id(id).Get(c) | ||||||
| 	return c, err | 	return c, err | ||||||
| } | } | ||||||
|  |  | ||||||
| func (c *Comment) ContentHtml() template.HTML { | // GetCommentsByIssueID returns all comments of issue by given ID. | ||||||
| 	return template.HTML(c.Content) | func GetCommentsByIssueID(issueID int64) ([]*Comment, error) { | ||||||
| } | 	comments := make([]*Comment, 0, 10) | ||||||
|  | 	return comments, x.Where("issue_id=?", issueID).Asc("created").Find(&comments) | ||||||
| // GetIssueComments returns list of comment by given issue id. |  | ||||||
| func GetIssueComments(issueId int64) ([]Comment, error) { |  | ||||||
| 	comments := make([]Comment, 0, 10) |  | ||||||
| 	err := x.Asc("created").Find(&comments, &Comment{IssueId: issueId}) |  | ||||||
| 	return comments, err |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // Attachments returns the attachments for this comment. |  | ||||||
| func (c *Comment) Attachments() []*Attachment { |  | ||||||
| 	a, _ := GetAttachmentsByComment(c.Id) |  | ||||||
| 	return a |  | ||||||
| } | } | ||||||
|  |  | ||||||
| func (c *Comment) AfterDelete() { | func (c *Comment) AfterDelete() { | ||||||
| 	_, err := DeleteAttachmentsByComment(c.Id, true) | 	_, err := DeleteAttachmentsByComment(c.ID, true) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		log.Info("Could not delete files for comment %d on issue #%d: %s", c.Id, c.IssueId, err) | 		log.Info("Could not delete files for comment %d on issue #%d: %s", c.ID, c.IssueID, err) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -1297,8 +1450,7 @@ func NewAttachment(name string, buf []byte, file multipart.File) (_ *Attachment, | |||||||
| 	return attach, sess.Commit() | 	return attach, sess.Commit() | ||||||
| } | } | ||||||
|  |  | ||||||
| // GetAttachmentByUUID returns attachment by given UUID. | func getAttachmentByUUID(e Engine, uuid string) (*Attachment, error) { | ||||||
| func GetAttachmentByUUID(uuid string) (*Attachment, error) { |  | ||||||
| 	attach := &Attachment{UUID: uuid} | 	attach := &Attachment{UUID: uuid} | ||||||
| 	has, err := x.Get(attach) | 	has, err := x.Get(attach) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @@ -1309,17 +1461,21 @@ func GetAttachmentByUUID(uuid string) (*Attachment, error) { | |||||||
| 	return attach, nil | 	return attach, nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // GetAttachmentByUUID returns attachment by given UUID. | ||||||
|  | func GetAttachmentByUUID(uuid string) (*Attachment, error) { | ||||||
|  | 	return getAttachmentByUUID(x, uuid) | ||||||
|  | } | ||||||
|  |  | ||||||
| // GetAttachmentsByIssueID returns all attachments for given issue by ID. | // GetAttachmentsByIssueID returns all attachments for given issue by ID. | ||||||
| func GetAttachmentsByIssueID(issueID int64) ([]*Attachment, error) { | func GetAttachmentsByIssueID(issueID int64) ([]*Attachment, error) { | ||||||
| 	attachments := make([]*Attachment, 0, 10) | 	attachments := make([]*Attachment, 0, 10) | ||||||
| 	return attachments, x.Where("issue_id=? AND comment_id=0", issueID).Find(&attachments) | 	return attachments, x.Where("issue_id=? AND comment_id=0", issueID).Find(&attachments) | ||||||
| } | } | ||||||
|  |  | ||||||
| // GetAttachmentsByComment returns a list of attachments for the given comment | // GetAttachmentsByCommentID returns all attachments if comment by given ID. | ||||||
| func GetAttachmentsByComment(commentId int64) ([]*Attachment, error) { | func GetAttachmentsByCommentID(commentID int64) ([]*Attachment, error) { | ||||||
| 	attachments := make([]*Attachment, 0, 10) | 	attachments := make([]*Attachment, 0, 10) | ||||||
| 	err := x.Where("comment_id = ?", commentId).Find(&attachments) | 	return attachments, x.Where("comment_id=?", commentID).Find(&attachments) | ||||||
| 	return attachments, err |  | ||||||
| } | } | ||||||
|  |  | ||||||
| // DeleteAttachment deletes the given attachment and optionally the associated file. | // DeleteAttachment deletes the given attachment and optionally the associated file. | ||||||
| @@ -1358,7 +1514,7 @@ func DeleteAttachmentsByIssue(issueId int64, remove bool) (int, error) { | |||||||
|  |  | ||||||
| // DeleteAttachmentsByComment deletes all attachments associated with the given comment. | // DeleteAttachmentsByComment deletes all attachments associated with the given comment. | ||||||
| func DeleteAttachmentsByComment(commentId int64, remove bool) (int, error) { | func DeleteAttachmentsByComment(commentId int64, remove bool) (int, error) { | ||||||
| 	attachments, err := GetAttachmentsByComment(commentId) | 	attachments, err := GetAttachmentsByCommentID(commentId) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return 0, err | 		return 0, err | ||||||
|   | |||||||
| @@ -929,7 +929,7 @@ func DeleteRepository(uid, repoID int64, userName string) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	for i := range issues { | 	for i := range issues { | ||||||
| 		if _, err = sess.Delete(&Comment{IssueId: issues[i].ID}); err != nil { | 		if _, err = sess.Delete(&Comment{IssueID: issues[i].ID}); err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -110,6 +110,16 @@ func (f *CreateIssueForm) Validate(ctx *macaron.Context, errs binding.Errors) bi | |||||||
| 	return validate(errs, ctx.Data, f, ctx.Locale) | 	return validate(errs, ctx.Data, f, ctx.Locale) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | type CreateCommentForm struct { | ||||||
|  | 	Content     string | ||||||
|  | 	NewStatus   string `binding:"OmitEmpty;In(reopen,close)"` | ||||||
|  | 	Attachments []string | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func (f *CreateCommentForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { | ||||||
|  | 	return validate(errs, ctx.Data, f, ctx.Locale) | ||||||
|  | } | ||||||
|  |  | ||||||
| //    _____  .__.__                   __ | //    _____  .__.__                   __ | ||||||
| //   /     \ |__|  |   ____   _______/  |_  ____   ____   ____ | //   /     \ |__|  |   ____   _______/  |_  ____   ____   ____ | ||||||
| //  /  \ /  \|  |  | _/ __ \ /  ___/\   __\/  _ \ /    \_/ __ \ | //  /  \ /  \|  |  | _/ __ \ /  ___/\   __\/  _ \ /    \_/ __ \ | ||||||
|   | |||||||
| @@ -131,12 +131,13 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{ | |||||||
| 	"LoadTimes": func(startTime time.Time) string { | 	"LoadTimes": func(startTime time.Time) string { | ||||||
| 		return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms" | 		return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms" | ||||||
| 	}, | 	}, | ||||||
| 	"AvatarLink": AvatarLink, | 	"AvatarLink":   AvatarLink, | ||||||
| 	"Safe":       Safe, | 	"Safe":         Safe, | ||||||
| 	"Str2html":   Str2html, | 	"Str2html":     Str2html, | ||||||
| 	"TimeSince":  TimeSince, | 	"TimeSince":    TimeSince, | ||||||
| 	"FileSize":   FileSize, | 	"RawTimeSince": RawTimeSince, | ||||||
| 	"Subtract":   Subtract, | 	"FileSize":     FileSize, | ||||||
|  | 	"Subtract":     Subtract, | ||||||
| 	"Add": func(a, b int) int { | 	"Add": func(a, b int) int { | ||||||
| 		return a + b | 		return a + b | ||||||
| 	}, | 	}, | ||||||
|   | |||||||
| @@ -321,6 +321,10 @@ func timeSince(then time.Time, lang string) string { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func RawTimeSince(t time.Time, lang string) string { | ||||||
|  | 	return timeSince(t, lang) | ||||||
|  | } | ||||||
|  |  | ||||||
| // TimeSince calculates the time interval and generate user-friendly string. | // TimeSince calculates the time interval and generate user-friendly string. | ||||||
| func TimeSince(t time.Time, lang string) template.HTML { | func TimeSince(t time.Time, lang string) template.HTML { | ||||||
| 	return template.HTML(fmt.Sprintf(`<span class="time-since" title="%s">%s</span>`, t.Format(setting.TimeFormat), timeSince(t, lang))) | 	return template.HTML(fmt.Sprintf(`<span class="time-since" title="%s">%s</span>`, t.Format(setting.TimeFormat), timeSince(t, lang))) | ||||||
|   | |||||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| @@ -288,7 +288,7 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if setting.AttachmentEnabled { | 	if setting.AttachmentEnabled { | ||||||
| 		attachments = ctx.QueryStrings("attachments") | 		attachments = form.Attachments | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if ctx.HasError() { | 	if ctx.HasError() { | ||||||
| @@ -432,8 +432,6 @@ 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)) | ||||||
|  |  | ||||||
| 	// Attchments. |  | ||||||
|  |  | ||||||
| 	// Metas. | 	// Metas. | ||||||
| 	if err = issue.GetLabels(); err != nil { | 	if err = issue.GetLabels(); err != nil { | ||||||
| 		ctx.Handle(500, "GetLabels", err) | 		ctx.Handle(500, "GetLabels", err) | ||||||
| @@ -477,29 +475,14 @@ func ViewIssue(ctx *middleware.Context) { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// // Get comments. | 	// Render comments. | ||||||
| 	// comments, err := models.GetIssueComments(issue.ID) | 	for i := range issue.Comments { | ||||||
| 	// if err != nil { | 		if issue.Comments[i].Type == models.COMMENT_TYPE_COMMENT { | ||||||
| 	// 	ctx.Handle(500, "GetIssueComments: %v", err) | 			issue.Comments[i].RenderedContent = string(base.RenderMarkdown([]byte(issue.Comments[i].Content), ctx.Repo.RepoLink)) | ||||||
| 	// 	return | 		} | ||||||
| 	// } | 	} | ||||||
|  |  | ||||||
| 	// // Get posters. |  | ||||||
| 	// for i := range comments { |  | ||||||
| 	// 	u, err := models.GetUserByID(comments[i].PosterId) |  | ||||||
| 	// 	if err != nil { |  | ||||||
| 	// 		ctx.Handle(500, "GetUserById.2: %v", err) |  | ||||||
| 	// 		return |  | ||||||
| 	// 	} |  | ||||||
| 	// 	comments[i].Poster = u |  | ||||||
|  |  | ||||||
| 	// 	if comments[i].Type == models.COMMENT_TYPE_COMMENT { |  | ||||||
| 	// 		comments[i].Content = string(base.RenderMarkdown([]byte(comments[i].Content), ctx.Repo.RepoLink)) |  | ||||||
| 	// 	} |  | ||||||
| 	// } |  | ||||||
|  |  | ||||||
| 	ctx.Data["Issue"] = issue | 	ctx.Data["Issue"] = issue | ||||||
| 	// ctx.Data["Comments"] = comments |  | ||||||
| 	// ctx.Data["IsIssueOwner"] = ctx.Repo.IsOwner() || (ctx.IsSigned && issue.PosterID == ctx.User.Id) | 	// ctx.Data["IsIssueOwner"] = ctx.Repo.IsOwner() || (ctx.IsSigned && issue.PosterID == ctx.User.Id) | ||||||
| 	ctx.HTML(200, ISSUE_VIEW) | 	ctx.HTML(200, ISSUE_VIEW) | ||||||
| } | } | ||||||
| @@ -713,163 +696,76 @@ func UpdateAssignee(ctx *middleware.Context) { | |||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
|  |  | ||||||
| func Comment(ctx *middleware.Context) { | func NewComment(ctx *middleware.Context, form auth.CreateCommentForm) { | ||||||
| 	send := func(status int, data interface{}, err error) { | 	issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) | ||||||
| 		if err != nil { |  | ||||||
| 			log.Error(4, "issue.Comment(?): %s", err) |  | ||||||
|  |  | ||||||
| 			ctx.JSON(status, map[string]interface{}{ |  | ||||||
| 				"ok":     false, |  | ||||||
| 				"status": status, |  | ||||||
| 				"error":  err.Error(), |  | ||||||
| 			}) |  | ||||||
| 		} else { |  | ||||||
| 			ctx.JSON(status, map[string]interface{}{ |  | ||||||
| 				"ok":     true, |  | ||||||
| 				"status": status, |  | ||||||
| 				"data":   data, |  | ||||||
| 			}) |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	index := com.StrTo(ctx.Query("issueIndex")).MustInt64() |  | ||||||
| 	if index == 0 { |  | ||||||
| 		ctx.Error(404) |  | ||||||
| 		return |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, index) |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		if models.IsErrIssueNotExist(err) { | 		if models.IsErrIssueNotExist(err) { | ||||||
| 			send(404, nil, err) | 			ctx.Handle(404, "GetIssueByIndex", err) | ||||||
| 		} else { | 		} else { | ||||||
| 			send(200, nil, err) | 			ctx.Handle(500, "GetIssueByIndex", err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// Check if issue owner changes the status of issue. | 	var attachments []string | ||||||
| 	var newStatus string | 	if setting.AttachmentEnabled { | ||||||
| 	if ctx.Repo.IsOwner() || issue.PosterID == ctx.User.Id { | 		attachments = form.Attachments | ||||||
| 		newStatus = ctx.Query("change_status") |  | ||||||
| 	} |  | ||||||
| 	if len(newStatus) > 0 { |  | ||||||
| 		if (strings.Contains(newStatus, "Reopen") && issue.IsClosed) || |  | ||||||
| 			(strings.Contains(newStatus, "Close") && !issue.IsClosed) { |  | ||||||
| 			issue.IsClosed = !issue.IsClosed |  | ||||||
| 			if err = models.UpdateIssue(issue); err != nil { |  | ||||||
| 				send(500, nil, err) |  | ||||||
| 				return |  | ||||||
| 			} else if err = models.UpdateIssueUserPairsByStatus(issue.ID, issue.IsClosed); err != nil { |  | ||||||
| 				send(500, nil, err) |  | ||||||
| 				return |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			if err = issue.GetLabels(); err != nil { |  | ||||||
| 				send(500, nil, err) |  | ||||||
| 				return |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			for _, label := range issue.Labels { |  | ||||||
| 				if issue.IsClosed { |  | ||||||
| 					label.NumClosedIssues++ |  | ||||||
| 				} else { |  | ||||||
| 					label.NumClosedIssues-- |  | ||||||
| 				} |  | ||||||
|  |  | ||||||
| 				if err = models.UpdateLabel(label); err != nil { |  | ||||||
| 					send(500, nil, err) |  | ||||||
| 					return |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			// Change open/closed issue counter for the associated milestone |  | ||||||
| 			if issue.MilestoneID > 0 { |  | ||||||
| 				if err = models.ChangeMilestoneIssueStats(issue); err != nil { |  | ||||||
| 					send(500, nil, err) |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			cmtType := models.COMMENT_TYPE_CLOSE |  | ||||||
| 			if !issue.IsClosed { |  | ||||||
| 				cmtType = models.COMMENT_TYPE_REOPEN |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			if _, err = models.CreateComment(ctx.User.Id, ctx.Repo.Repository.ID, issue.ID, 0, 0, cmtType, "", nil); err != nil { |  | ||||||
| 				send(200, nil, err) |  | ||||||
| 				return |  | ||||||
| 			} |  | ||||||
| 			log.Trace("%s Issue(%d) status changed: %v", ctx.Req.RequestURI, issue.ID, !issue.IsClosed) |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var comment *models.Comment | 	if ctx.HasError() { | ||||||
|  | 		ctx.Flash.Error(ctx.Data["ErrorMsg"].(string)) | ||||||
|  | 		ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)) | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	var ms []string | 	// Check if issue owner/poster changes the status of issue. | ||||||
| 	content := ctx.Query("content") | 	if (ctx.Repo.IsOwner() || issue.IsPoster(ctx.User.Id)) && | ||||||
| 	// Fix #321. Allow empty comments, as long as we have attachments. | 		(form.NewStatus == "reopen" || form.NewStatus == "close") { | ||||||
| 	if len(content) > 0 || len(ctx.Req.MultipartForm.File["attachments"]) > 0 { | 		issue.Repo = ctx.Repo.Repository | ||||||
| 		switch ctx.Params(":action") { | 		if err = issue.ChangeStatus(ctx.User, form.NewStatus == "close"); err != nil { | ||||||
| 		case "new": | 			ctx.Handle(500, "ChangeStatus", err) | ||||||
| 			if comment, err = models.CreateComment(ctx.User.Id, ctx.Repo.Repository.ID, issue.ID, 0, 0, models.COMMENT_TYPE_COMMENT, content, nil); err != nil { |  | ||||||
| 				send(500, nil, err) |  | ||||||
| 				return |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			// 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 |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			log.Trace("%s Comment created: %d", ctx.Req.RequestURI, issue.ID) |  | ||||||
| 		default: |  | ||||||
| 			ctx.Handle(404, "issue.Comment", err) |  | ||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
|  | 		log.Trace("%s Issue[%d] status changed: %v", ctx.Req.RequestURI, issue.ID, !issue.IsClosed) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if comment != nil { | 	// Fix #321: Allow empty comments, as long as we have attachments. | ||||||
| 		// uploadFiles(ctx, issue.ID, comment.Id) | 	if len(form.Content) == 0 && len(attachments) == 0 { | ||||||
| 	} | 		ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)) | ||||||
|  |  | ||||||
| 	// Notify watchers. |  | ||||||
| 	act := &models.Action{ |  | ||||||
| 		ActUserID:    ctx.User.Id, |  | ||||||
| 		ActUserName:  ctx.User.LowerName, |  | ||||||
| 		ActEmail:     ctx.User.Email, |  | ||||||
| 		OpType:       models.COMMENT_ISSUE, |  | ||||||
| 		Content:      fmt.Sprintf("%d|%s", issue.Index, strings.Split(content, "\n")[0]), |  | ||||||
| 		RepoID:       ctx.Repo.Repository.ID, |  | ||||||
| 		RepoUserName: ctx.Repo.Owner.LowerName, |  | ||||||
| 		RepoName:     ctx.Repo.Repository.LowerName, |  | ||||||
| 		IsPrivate:    ctx.Repo.Repository.IsPrivate, |  | ||||||
| 	} |  | ||||||
| 	if err = models.NotifyWatchers(act); err != nil { |  | ||||||
| 		send(500, nil, err) |  | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	comment, err := models.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Content, attachments) | ||||||
|  | 	if err != nil { | ||||||
|  | 		ctx.Handle(500, "CreateIssueComment", err) | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Update mentions. | ||||||
|  | 	mentions := base.MentionPattern.FindAllString(comment.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. | 	// Mail watchers and mentions. | ||||||
| 	if setting.Service.EnableNotifyMail { | 	if setting.Service.EnableNotifyMail { | ||||||
| 		issue.Content = content | 		issue.Content = form.Content | ||||||
| 		tos, err := mailer.SendIssueNotifyMail(ctx.User, ctx.Repo.Owner, ctx.Repo.Repository, issue) | 		tos, err := mailer.SendIssueNotifyMail(ctx.User, ctx.Repo.Owner, ctx.Repo.Repository, issue) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			send(500, nil, err) | 			ctx.Handle(500, "SendIssueNotifyMail", err) | ||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		tos = append(tos, ctx.User.LowerName) | 		tos = append(tos, ctx.User.LowerName) | ||||||
| 		newTos := make([]string, 0, len(ms)) | 		newTos := make([]string, 0, len(mentions)) | ||||||
| 		for _, m := range ms { | 		for _, m := range mentions { | ||||||
| 			if com.IsSliceContainsStr(tos, m) { | 			if com.IsSliceContainsStr(tos, m) { | ||||||
| 				continue | 				continue | ||||||
| 			} | 			} | ||||||
| @@ -878,12 +774,13 @@ func Comment(ctx *middleware.Context) { | |||||||
| 		} | 		} | ||||||
| 		if err = mailer.SendIssueMentionMail(ctx.Render, ctx.User, ctx.Repo.Owner, | 		if err = mailer.SendIssueMentionMail(ctx.Render, ctx.User, ctx.Repo.Owner, | ||||||
| 			ctx.Repo.Repository, issue, models.GetUserEmailsByNames(newTos)); err != nil { | 			ctx.Repo.Repository, issue, models.GetUserEmailsByNames(newTos)); err != nil { | ||||||
| 			send(500, nil, err) | 			ctx.Handle(500, "SendIssueMentionMail", err) | ||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	send(200, fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, index), nil) | 	log.Trace("Comment created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID) | ||||||
|  | 	ctx.Redirect(fmt.Sprintf("%s/issues/%d#%s", ctx.Repo.RepoLink, issue.Index, comment.HashTag())) | ||||||
| } | } | ||||||
|  |  | ||||||
| func Labels(ctx *middleware.Context) { | func Labels(ctx *middleware.Context) { | ||||||
|   | |||||||
| @@ -1 +1 @@ | |||||||
| 0.6.4.0812 Beta | 0.6.4.0813 Beta | ||||||
| @@ -1,10 +1,7 @@ | |||||||
| {{with .Repository}} | {{with .Repository}} | ||||||
| <div class="ui container"><!-- start container --> | <div class="ui container"><!-- start container --> | ||||||
|  |  | ||||||
| 	<div id="repoheader" class="ui vertically padded grid head"><!-- start grid --> | 	<div id="repoheader" class="ui vertically padded grid head"><!-- start grid --> | ||||||
|  |  | ||||||
| 		<div class="column"><!-- start column --> | 		<div class="column"><!-- start column --> | ||||||
|  |  | ||||||
| 			<div class="ui black small compact menu floated right count labelled"> | 			<div class="ui black small compact menu floated right count labelled"> | ||||||
| 				<a class="item{{if $.IsRepositoryOwner}} poping up{{end}}"{{if not $.IsRepositoryOwner}} href="{{AppSubUrl}}/repo/fork/{{.ID}}"{{else}} data-content="{{$.i18n.Tr "repo.fork_from_self"}}" data-position="top center" data-variation="tiny"{{end}}> | 				<a class="item{{if $.IsRepositoryOwner}} poping up{{end}}"{{if not $.IsRepositoryOwner}} href="{{AppSubUrl}}/repo/fork/{{.ID}}"{{else}} data-content="{{$.i18n.Tr "repo.fork_from_self"}}" data-position="top center" data-variation="tiny"{{end}}> | ||||||
| 					<i class="icon octicon octicon-repo-forked"></i> | 					<i class="icon octicon octicon-repo-forked"></i> | ||||||
| @@ -41,9 +38,7 @@ | |||||||
| 			</div> | 			</div> | ||||||
|  |  | ||||||
| 		</div><!-- end column --> | 		</div><!-- end column --> | ||||||
|  |  | ||||||
| 	</div><!-- end grid --> | 	</div><!-- end grid --> | ||||||
| 	 |  | ||||||
| </div><!-- end container --> | </div><!-- end container --> | ||||||
|  |  | ||||||
| <div class="ui divider"></div> | <div class="ui divider"></div> | ||||||
|   | |||||||
| @@ -50,20 +50,53 @@ | |||||||
| 		    </div> | 		    </div> | ||||||
|   		</div> |   		</div> | ||||||
|  |  | ||||||
|  |   		{{range .Issue.Comments}} | ||||||
|  |   		{{ $createdStr:= TimeSince .Created $.Lang }} | ||||||
|  |   		<div class="comment"> | ||||||
|  | 		    <a class="avatar" href="{{.Poster.HomeLink}}"> | ||||||
|  | 		      <img src="{{.Poster.AvatarLink}}"> | ||||||
|  | 		    </a> | ||||||
|  | 		    <div class="content"> | ||||||
|  | 					<div class="ui top attached header"> | ||||||
|  | 						<span class="text"><a href="{{.Poster.HomeLink}}">{{.Poster.Name}}</a> {{$.i18n.Tr "repo.issues.commented_at" .HashTag $createdStr | Safe}}</span> | ||||||
|  | 					  <div class="ui right actions"> | ||||||
|  | 					  </div> | ||||||
|  | 					</div> | ||||||
|  | 			    <div class="ui attached segment markdown"> | ||||||
|  | 			    	{{if .RenderedContent}} | ||||||
|  | 						{{.RenderedContent|Str2html}} | ||||||
|  | 			    	{{else}} | ||||||
|  | 						<span class="no-content">{{$.i18n.Tr "repo.issues.no_content"}}</span> | ||||||
|  | 			    	{{end}} | ||||||
|  | 	  			</div> | ||||||
|  | 	  			{{if .Attachments}} | ||||||
|  | 					<div class="ui bottom attached segment"> | ||||||
|  | 						<div class="ui small images"> | ||||||
|  | 							{{range .Attachments}} | ||||||
|  | 						  <a target="_blank" href="/attachments/{{.UUID}}"><img class="ui image" src="/attachments/{{.UUID}}"></a> | ||||||
|  | 						  {{end}} | ||||||
|  | 						</div> | ||||||
|  | 					</div> | ||||||
|  | 	  			{{end}} | ||||||
|  | 		    </div> | ||||||
|  |   		</div> | ||||||
|  |   		{{end}} | ||||||
|  |  | ||||||
| 		  <div class="comment form"> | 		  <div class="comment form"> | ||||||
| 		    <a class="avatar" href="{{.SignedUser.HomeLink}}"> | 		    <a class="avatar" href="{{.SignedUser.HomeLink}}"> | ||||||
| 		      <img src="{{.SignedUser.AvatarLink}}"> | 		      <img src="{{.SignedUser.AvatarLink}}"> | ||||||
| 		    </a> | 		    </a> | ||||||
| 		    <div class="content"> | 		    <div class="content"> | ||||||
| 			    <form class="ui segment form" action="{{.Link}}" method="post"> | 			    <form class="ui segment form" action="{{.Link}}/comments" method="post"> | ||||||
| 						{{template "repo/issue/comment_tab" .}} | 						{{template "repo/issue/comment_tab" .}} | ||||||
|  | 						{{.CsrfTokenHtml}} | ||||||
| 			      <div class="text right"> | 			      <div class="text right"> | ||||||
| 							<div class="ui red basic button" data-close="{{.i18n.Tr "repo.issues.close_issue"}}" data-close-and-comment="{{.i18n.Tr "repo.issues.close_comment_issue"}}"> | 							<div class="ui red basic button" data-close="{{.i18n.Tr "repo.issues.close_issue"}}" data-close-and-comment="{{.i18n.Tr "repo.issues.close_comment_issue"}}"> | ||||||
| 								{{.i18n.Tr "repo.issues.close_issue"}} | 								{{.i18n.Tr "repo.issues.close_issue"}} | ||||||
| 							</div> | 							</div> | ||||||
| 							<div class="ui green button"> | 							<button class="ui green button"> | ||||||
| 								{{.i18n.Tr "repo.issues.create_comment"}} | 								{{.i18n.Tr "repo.issues.create_comment"}} | ||||||
| 							</div> | 							</button> | ||||||
| 			      </div> | 			      </div> | ||||||
| 			    </form> | 			    </form> | ||||||
| 		    </div> | 		    </div> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user