mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 21:45:50 +01:00
(refs #4)Record wiki activity.
This commit is contained in:
@@ -3,6 +3,7 @@ CREATE TABLE ACTIVITY(
|
|||||||
USER_NAME VARCHAR(100) NOT NULL,
|
USER_NAME VARCHAR(100) NOT NULL,
|
||||||
REPOSITORY_NAME VARCHAR(100) NOT NULL,
|
REPOSITORY_NAME VARCHAR(100) NOT NULL,
|
||||||
ACTIVITY_USER_NAME VARCHAR(100) NOT NULL,
|
ACTIVITY_USER_NAME VARCHAR(100) NOT NULL,
|
||||||
|
ACTIVITY_TYPE VARCHAR(100) NOT NULL,
|
||||||
MESSAGE TEXT NOT NULL,
|
MESSAGE TEXT NOT NULL,
|
||||||
ADDITIONAL_INFO TEXT,
|
ADDITIONAL_INFO TEXT,
|
||||||
ACTIVITY_DATE TIMESTAMP NOT NULL
|
ACTIVITY_DATE TIMESTAMP NOT NULL
|
||||||
|
|||||||
@@ -6,10 +6,12 @@ import util.Directory._
|
|||||||
import jp.sf.amateras.scalatra.forms._
|
import jp.sf.amateras.scalatra.forms._
|
||||||
|
|
||||||
class WikiController extends WikiControllerBase
|
class WikiController extends WikiControllerBase
|
||||||
with WikiService with RepositoryService with AccountService with CollaboratorsAuthenticator with ReferrerAuthenticator
|
with WikiService with RepositoryService with AccountService with ActivityService
|
||||||
|
with CollaboratorsAuthenticator with ReferrerAuthenticator
|
||||||
|
|
||||||
trait WikiControllerBase extends ControllerBase {
|
trait WikiControllerBase extends ControllerBase {
|
||||||
self: WikiService with RepositoryService with CollaboratorsAuthenticator with ReferrerAuthenticator =>
|
self: WikiService with RepositoryService with ActivityService
|
||||||
|
with CollaboratorsAuthenticator with ReferrerAuthenticator =>
|
||||||
|
|
||||||
case class WikiPageEditForm(pageName: String, content: String, message: Option[String], currentPageName: String)
|
case class WikiPageEditForm(pageName: String, content: String, message: Option[String], currentPageName: String)
|
||||||
|
|
||||||
@@ -72,9 +74,13 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/wiki/_edit", editForm)(collaboratorsOnly { (form, repository) =>
|
post("/:owner/:repository/wiki/_edit", editForm)(collaboratorsOnly { (form, repository) =>
|
||||||
|
val loginAccount = context.loginAccount.get
|
||||||
|
|
||||||
saveWikiPage(repository.owner, repository.name, form.currentPageName, form.pageName,
|
saveWikiPage(repository.owner, repository.name, form.currentPageName, form.pageName,
|
||||||
form.content, context.loginAccount.get, form.message.getOrElse(""))
|
form.content, loginAccount, form.message.getOrElse(""))
|
||||||
|
|
||||||
updateLastActivityDate(repository.owner, repository.name)
|
updateLastActivityDate(repository.owner, repository.name)
|
||||||
|
recordEditWikiPageActivity(repository.owner, repository.name, loginAccount.userName, form.pageName)
|
||||||
|
|
||||||
redirect("/%s/%s/wiki/%s".format(repository.owner, repository.name, form.pageName))
|
redirect("/%s/%s/wiki/%s".format(repository.owner, repository.name, form.pageName))
|
||||||
})
|
})
|
||||||
@@ -84,9 +90,13 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/wiki/_new", newForm)(collaboratorsOnly { (form, repository) =>
|
post("/:owner/:repository/wiki/_new", newForm)(collaboratorsOnly { (form, repository) =>
|
||||||
|
val loginAccount = context.loginAccount.get
|
||||||
|
|
||||||
saveWikiPage(repository.owner, repository.name, form.currentPageName, form.pageName,
|
saveWikiPage(repository.owner, repository.name, form.currentPageName, form.pageName,
|
||||||
form.content, context.loginAccount.get, form.message.getOrElse(""))
|
form.content, context.loginAccount.get, form.message.getOrElse(""))
|
||||||
|
|
||||||
updateLastActivityDate(repository.owner, repository.name)
|
updateLastActivityDate(repository.owner, repository.name)
|
||||||
|
recordCreateWikiPageActivity(repository.owner, repository.name, loginAccount.userName, form.pageName)
|
||||||
|
|
||||||
redirect("/%s/%s/wiki/%s".format(repository.owner, repository.name, form.pageName))
|
redirect("/%s/%s/wiki/%s".format(repository.owner, repository.name, form.pageName))
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ import scala.slick.driver.H2Driver.simple._
|
|||||||
object Activities extends Table[Activity]("ACTIVITY") with BasicTemplate with Functions {
|
object Activities extends Table[Activity]("ACTIVITY") with BasicTemplate with Functions {
|
||||||
def activityId = column[Int]("ACTIVITY_ID", O AutoInc)
|
def activityId = column[Int]("ACTIVITY_ID", O AutoInc)
|
||||||
def activityUserName = column[String]("ACTIVITY_USER_NAME")
|
def activityUserName = column[String]("ACTIVITY_USER_NAME")
|
||||||
|
def activityType = column[String]("ACTIVITY_TYPE")
|
||||||
def message = column[String]("MESSAGE")
|
def message = column[String]("MESSAGE")
|
||||||
def additionalInfo = column[String]("ADDITIONAL_INFO")
|
def additionalInfo = column[String]("ADDITIONAL_INFO")
|
||||||
def activityDate = column[java.util.Date]("ACTIVITY_DATE")
|
def activityDate = column[java.util.Date]("ACTIVITY_DATE")
|
||||||
def * = activityId ~ userName ~ repositoryName ~ activityUserName ~ message ~ additionalInfo.? ~ activityDate <> (Activity, Activity.unapply _)
|
def * = activityId ~ userName ~ repositoryName ~ activityUserName ~ activityType ~ message ~ additionalInfo.? ~ activityDate <> (Activity, Activity.unapply _)
|
||||||
def autoInc = userName ~ repositoryName ~ activityUserName ~ message ~ additionalInfo.? ~ activityDate returning activityId
|
def autoInc = userName ~ repositoryName ~ activityUserName ~ activityType ~ message ~ additionalInfo.? ~ activityDate returning activityId
|
||||||
}
|
}
|
||||||
|
|
||||||
case class Activity(
|
case class Activity(
|
||||||
@@ -17,6 +18,7 @@ case class Activity(
|
|||||||
userName: String,
|
userName: String,
|
||||||
repositoryName: String,
|
repositoryName: String,
|
||||||
activityUserName: String,
|
activityUserName: String,
|
||||||
|
activityType: String,
|
||||||
message: String,
|
message: String,
|
||||||
additionalInfo: Option[String],
|
additionalInfo: Option[String],
|
||||||
activityDate: java.util.Date
|
activityDate: java.util.Date
|
||||||
|
|||||||
@@ -18,31 +18,57 @@ trait ActivityService {
|
|||||||
})
|
})
|
||||||
.sortBy { case (t1, t2) => t1.activityId desc }
|
.sortBy { case (t1, t2) => t1.activityId desc }
|
||||||
.map { case (t1, t2) => t1 }
|
.map { case (t1, t2) => t1 }
|
||||||
|
.take(30)
|
||||||
.list
|
.list
|
||||||
}
|
}
|
||||||
|
|
||||||
def recordCreateRepositoryActivity(userName: String, repositoryName: String, activityUserName: String): Unit =
|
def recordCreateRepositoryActivity(userName: String, repositoryName: String, activityUserName: String): Unit =
|
||||||
Activities.autoInc insert(userName, repositoryName, activityUserName,
|
Activities.autoInc insert(userName, repositoryName, activityUserName,
|
||||||
|
"create_repository",
|
||||||
"[[%s]] created [[%s/%s]]".format(activityUserName, userName, repositoryName),
|
"[[%s]] created [[%s/%s]]".format(activityUserName, userName, repositoryName),
|
||||||
None, currentDate)
|
None,
|
||||||
|
currentDate)
|
||||||
|
|
||||||
def recordCreateIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String): Unit =
|
def recordCreateIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String): Unit =
|
||||||
Activities.autoInc insert(userName, repositoryName, activityUserName,
|
Activities.autoInc insert(userName, repositoryName, activityUserName,
|
||||||
|
"open_issue",
|
||||||
"[[%s]] opened issue [[%s/%s#%d]]".format(activityUserName, userName, repositoryName, issueId),
|
"[[%s]] opened issue [[%s/%s#%d]]".format(activityUserName, userName, repositoryName, issueId),
|
||||||
Some(title), currentDate)
|
Some(title),
|
||||||
|
currentDate)
|
||||||
|
|
||||||
def recordCloseIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String): Unit =
|
def recordCloseIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String): Unit =
|
||||||
Activities.autoInc insert(userName, repositoryName, activityUserName,
|
Activities.autoInc insert(userName, repositoryName, activityUserName,
|
||||||
|
"close_issue",
|
||||||
"[[%s]] closed issue [[%s/%s#%d]]".format(activityUserName, userName, repositoryName, issueId),
|
"[[%s]] closed issue [[%s/%s#%d]]".format(activityUserName, userName, repositoryName, issueId),
|
||||||
Some(title), currentDate)
|
Some(title),
|
||||||
|
currentDate)
|
||||||
|
|
||||||
def recordReopenIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String): Unit =
|
def recordReopenIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String): Unit =
|
||||||
Activities.autoInc insert(userName, repositoryName, activityUserName,
|
Activities.autoInc insert(userName, repositoryName, activityUserName,
|
||||||
|
"reopen_issue",
|
||||||
"[[%s]] closed reopened [[%s/%s#%d]]".format(activityUserName, userName, repositoryName, issueId),
|
"[[%s]] closed reopened [[%s/%s#%d]]".format(activityUserName, userName, repositoryName, issueId),
|
||||||
Some(title), currentDate)
|
Some(title),
|
||||||
|
currentDate)
|
||||||
|
|
||||||
def recordCommentIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, comment: String): Unit =
|
def recordCommentIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, comment: String): Unit =
|
||||||
Activities.autoInc insert(userName, repositoryName, activityUserName,
|
Activities.autoInc insert(userName, repositoryName, activityUserName,
|
||||||
|
"comment_issue",
|
||||||
"[[%s]] commented on issue [[%s/%s#%d]]".format(activityUserName, userName, repositoryName, issueId),
|
"[[%s]] commented on issue [[%s/%s#%d]]".format(activityUserName, userName, repositoryName, issueId),
|
||||||
Some(comment), currentDate)
|
Some(comment),
|
||||||
|
currentDate)
|
||||||
|
|
||||||
|
def recordCreateWikiPageActivity(userName: String, repositoryName: String, activityUserName: String, pageName: String) =
|
||||||
|
Activities.autoInc insert(userName, repositoryName, activityUserName,
|
||||||
|
"create_wiki",
|
||||||
|
"[[%s]] created the [[%s/%s]] wiki".format(activityUserName, userName, repositoryName),
|
||||||
|
Some(pageName),
|
||||||
|
currentDate)
|
||||||
|
|
||||||
|
def recordEditWikiPageActivity(userName: String, repositoryName: String, activityUserName: String, pageName: String) =
|
||||||
|
Activities.autoInc insert(userName, repositoryName, activityUserName,
|
||||||
|
"edit_wiki",
|
||||||
|
"[[%s]] edited the [[%s/%s]] wiki".format(activityUserName, userName, repositoryName),
|
||||||
|
Some(pageName),
|
||||||
|
currentDate)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,17 @@
|
|||||||
<div class="muted smal">@datetime(activity.activityDate)</div>
|
<div class="muted smal">@datetime(activity.activityDate)</div>
|
||||||
<div class="strong">@activityMessage(activity.message)</div>
|
<div class="strong">@activityMessage(activity.message)</div>
|
||||||
@activity.additionalInfo.map { additionalInfo =>
|
@activity.additionalInfo.map { additionalInfo =>
|
||||||
<div>@additionalInfo</div>
|
@(activity.activityType match {
|
||||||
|
case "create_wiki" => {
|
||||||
|
<div>Created <a href={"%s/%s/%s/wiki/%s".format(path, activity.userName, activity.repositoryName, additionalInfo)}>{additionalInfo}</a>.</div>
|
||||||
|
}
|
||||||
|
case "edit_wiki" => {
|
||||||
|
<div>Edited <a href={"%s/%s/%s/wiki/%s".format(path, activity.userName, activity.repositoryName, additionalInfo)}>{additionalInfo}</a>.</div>
|
||||||
|
}
|
||||||
|
case _ => {
|
||||||
|
<div>{additionalInfo}</div>
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user