(refs #4)Record issue creation activity.

This commit is contained in:
takezoe
2013-07-06 20:14:49 +09:00
parent f84078c7ca
commit 342810aa3a
3 changed files with 12 additions and 5 deletions

View File

@@ -8,11 +8,11 @@ import util.{CollaboratorsAuthenticator, ReferrerAuthenticator, ReadableUsersAut
import org.scalatra.Ok import org.scalatra.Ok
class IssuesController extends IssuesControllerBase class IssuesController extends IssuesControllerBase
with IssuesService with RepositoryService with AccountService with LabelsService with MilestonesService with IssuesService with RepositoryService with AccountService with LabelsService with MilestonesService with ActivityService
with ReadableUsersAuthenticator with ReferrerAuthenticator with CollaboratorsAuthenticator with ReadableUsersAuthenticator with ReferrerAuthenticator with CollaboratorsAuthenticator
trait IssuesControllerBase extends ControllerBase { trait IssuesControllerBase extends ControllerBase {
self: IssuesService with RepositoryService with LabelsService with MilestonesService self: IssuesService with RepositoryService with LabelsService with MilestonesService with ActivityService
with ReadableUsersAuthenticator with ReferrerAuthenticator with CollaboratorsAuthenticator => with ReadableUsersAuthenticator with ReferrerAuthenticator with CollaboratorsAuthenticator =>
case class IssueCreateForm(title: String, content: Option[String], case class IssueCreateForm(title: String, content: Option[String],
@@ -86,8 +86,9 @@ trait IssuesControllerBase extends ControllerBase {
val owner = repository.owner val owner = repository.owner
val name = repository.name val name = repository.name
val writable = hasWritePermission(owner, name, context.loginAccount) val writable = hasWritePermission(owner, name, context.loginAccount)
val userName = context.loginAccount.get.userName
val issueId = createIssue(owner, name, context.loginAccount.get.userName, form.title, form.content, val issueId = createIssue(owner, name, userName, form.title, form.content,
if(writable) form.assignedUserName else None, if(writable) form.assignedUserName else None,
if(writable) form.milestoneId else None) if(writable) form.milestoneId else None)
@@ -102,6 +103,8 @@ trait IssuesControllerBase extends ControllerBase {
} }
} }
recordCreateIssue(owner, name, userName, issueId)
redirect("/%s/%s/issues/%d".format(owner, name, issueId)) redirect("/%s/%s/issues/%d".format(owner, name, issueId))
}) })

View File

@@ -21,10 +21,13 @@ trait ActivityService {
.list .list
} }
def recordCreateRepository(userName: String, repositoryName: String, activityUserName: String): Unit = { def recordCreateRepository(userName: String, repositoryName: String, activityUserName: String): Unit =
Activities.autoInc insert(userName, repositoryName, activityUserName, Activities.autoInc insert(userName, repositoryName, activityUserName,
"[[%s]] created [[%s/%s]]".format(activityUserName, userName, repositoryName), "[[%s]] created [[%s/%s]]".format(activityUserName, userName, repositoryName),
currentDate) currentDate)
}
def recordCreateIssue(userName: String, repositoryName: String, activityUserName: String, issueId: Int): Unit =
Activities.autoInc insert(userName, repositoryName, activityUserName,
"[[%s]] opened issue [[%s/%s#%d]]".format(activityUserName, userName, repositoryName, issueId),
currentDate)
} }

View File

@@ -35,6 +35,7 @@ object helpers {
def activityMessage(message: String)(implicit context: app.Context): Html = { def activityMessage(message: String)(implicit context: app.Context): Html = {
Html(message Html(message
.replaceAll("\\[\\[([^\\s]+?)/([^\\s]+?)#((\\d+))\\]\\]", "<a href=\"%s/$1/$2/issues/$3\">$1/$2#$3</a>".format(context.path))
.replaceAll("\\[\\[([^\\s]+?)/([^\\s]+?)\\]\\]", "<a href=\"%s/$1/$2\">$1/$2</a>".format(context.path)) .replaceAll("\\[\\[([^\\s]+?)/([^\\s]+?)\\]\\]", "<a href=\"%s/$1/$2\">$1/$2</a>".format(context.path))
.replaceAll("\\[\\[([^\\s]+?)\\]\\]", "<a href=\"%s/$1\">$1</a>".format(context.path)) .replaceAll("\\[\\[([^\\s]+?)\\]\\]", "<a href=\"%s/$1\">$1</a>".format(context.path))
) )