mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-12-16 13:29:52 +01:00
Moving to Quill
This commit is contained in:
@@ -38,23 +38,24 @@ trait AccessTokenService {
|
||||
note = note,
|
||||
tokenHash = hash)
|
||||
|
||||
// TODO Remain Slick code
|
||||
val tokenId = (AccessTokens returning AccessTokens.map(_.accessTokenId)) += newToken
|
||||
(tokenId, token)
|
||||
}
|
||||
|
||||
def getAccountByAccessToken(token: String)(implicit s: Session): Option[Account] =
|
||||
def getAccountByAccessToken(token: String): Option[Account] =
|
||||
db.run(quote { (tokenHash: String) =>
|
||||
query[AccessToken].filter(_.tokenHash == tokenHash)
|
||||
.join(query[Account]).on { (t, a) => t.userName == a.userName && a.registeredDate == false }
|
||||
.map { case (t, a) => a }
|
||||
})(tokenToHash(token)).headOption
|
||||
|
||||
def getAccessTokens(userName: String)(implicit s: Session): List[AccessToken] =
|
||||
def getAccessTokens(userName: String): List[AccessToken] =
|
||||
db.run(quote { (userName: String) =>
|
||||
query[AccessToken].filter(_.userName == userName).sortBy(_.accessTokenId)(Ord.desc)
|
||||
})(userName)
|
||||
|
||||
def deleteAccessToken(userName: String, accessTokenId: Int)(implicit s: Session): Unit =
|
||||
def deleteAccessToken(userName: String, accessTokenId: Int): Unit =
|
||||
db.run(quote { (userName: String, accessTokenId: Int) =>
|
||||
query[AccessToken].filter { t => t.userName == userName && t.accessTokenId == accessTokenId }.delete
|
||||
})(List((userName, accessTokenId)))
|
||||
|
||||
@@ -89,7 +89,7 @@ trait AccountService {
|
||||
}
|
||||
|
||||
|
||||
def getAccountsByUserNames(userNames: Set[String], knowns:Set[Account], includeRemoved: Boolean = false)(implicit s: Session): Map[String, Account] = {
|
||||
def getAccountsByUserNames(userNames: Set[String], knowns:Set[Account], includeRemoved: Boolean = false): Map[String, Account] = {
|
||||
val map = knowns.map(a => a.userName -> a).toMap
|
||||
val needs = userNames -- map.keySet
|
||||
if(needs.isEmpty){
|
||||
|
||||
@@ -10,7 +10,7 @@ import io.getquill._
|
||||
|
||||
trait ActivityService {
|
||||
|
||||
def deleteOldActivities(limit: Int)(implicit s: Session): Int =
|
||||
def deleteOldActivities(limit: Int): Int =
|
||||
db.run (quote { (limit: Int) =>
|
||||
query[Activity].map(_.activityId).sortBy(x => x)(Ord.desc).drop(limit)
|
||||
})(limit).headOption.map { activityId =>
|
||||
@@ -19,7 +19,7 @@ trait ActivityService {
|
||||
)(activityId)
|
||||
} getOrElse 0
|
||||
|
||||
def getActivitiesByUser(activityUserName: String, isPublic: Boolean)(implicit s: Session): List[Activity] =
|
||||
def getActivitiesByUser(activityUserName: String, isPublic: Boolean): List[Activity] =
|
||||
db.run(quote { (activityUserName: String, isPublic: Boolean) =>
|
||||
query[Activity].join(query[Repository]).on((a, r) => a.userName == r.userName && a.repositoryName == r.repositoryName)
|
||||
.filter { case (a, r) =>
|
||||
@@ -34,7 +34,7 @@ trait ActivityService {
|
||||
.take(30)
|
||||
})(activityUserName, isPublic)
|
||||
|
||||
def getRecentActivities()(implicit s: Session): List[Activity] =
|
||||
def getRecentActivities(): List[Activity] =
|
||||
db.run(quote {
|
||||
query[Activity].join(query[Repository]).on((a, r) => a.userName == r.userName && a.repositoryName == r.repositoryName)
|
||||
.filter { case (a, r) => r.`private` == false}
|
||||
@@ -43,7 +43,7 @@ trait ActivityService {
|
||||
.take(30)
|
||||
})
|
||||
|
||||
def getRecentActivitiesByOwners(owners : Set[String])(implicit s: Session): List[Activity] =
|
||||
def getRecentActivitiesByOwners(owners : Set[String]): List[Activity] =
|
||||
db.run(quote { (owners: Set[String]) =>
|
||||
query[Activity].join(query[Repository]).on((a, r) => a.userName == r.userName && a.repositoryName == r.repositoryName)
|
||||
.filter { case (a, r) => r.`private` == false || owners.contains(r.userName) }
|
||||
@@ -52,126 +52,112 @@ trait ActivityService {
|
||||
.take(30)
|
||||
})(owners)
|
||||
|
||||
def recordCreateRepositoryActivity(userName: String, repositoryName: String, activityUserName: String)
|
||||
(implicit s: Session): Unit =
|
||||
def recordCreateRepositoryActivity(userName: String, repositoryName: String, activityUserName: String): Unit =
|
||||
insertActivity(userName, repositoryName, activityUserName,
|
||||
"create_repository",
|
||||
s"[user:${activityUserName}] created [repo:${userName}/${repositoryName}]",
|
||||
None)
|
||||
|
||||
def recordCreateIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String)
|
||||
(implicit s: Session): Unit =
|
||||
def recordCreateIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String): Unit =
|
||||
insertActivity(userName, repositoryName, activityUserName,
|
||||
"open_issue",
|
||||
s"[user:${activityUserName}] opened issue [issue:${userName}/${repositoryName}#${issueId}]",
|
||||
Some(title))
|
||||
|
||||
def recordCloseIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String)
|
||||
(implicit s: Session): Unit =
|
||||
def recordCloseIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String): Unit =
|
||||
insertActivity(userName, repositoryName, activityUserName,
|
||||
"close_issue",
|
||||
s"[user:${activityUserName}] closed issue [issue:${userName}/${repositoryName}#${issueId}]",
|
||||
Some(title))
|
||||
|
||||
def recordClosePullRequestActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String)
|
||||
(implicit s: Session): Unit =
|
||||
def recordClosePullRequestActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String): Unit =
|
||||
insertActivity(userName, repositoryName, activityUserName,
|
||||
"close_issue",
|
||||
s"[user:${activityUserName}] closed pull request [pullreq:${userName}/${repositoryName}#${issueId}]",
|
||||
Some(title))
|
||||
|
||||
def recordReopenIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String)
|
||||
(implicit s: Session): Unit =
|
||||
def recordReopenIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String): Unit =
|
||||
insertActivity(userName, repositoryName, activityUserName,
|
||||
"reopen_issue",
|
||||
s"[user:${activityUserName}] reopened issue [issue:${userName}/${repositoryName}#${issueId}]",
|
||||
Some(title))
|
||||
|
||||
def recordCommentIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, comment: String)
|
||||
(implicit s: Session): Unit =
|
||||
def recordCommentIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, comment: String): Unit =
|
||||
insertActivity(userName, repositoryName, activityUserName,
|
||||
"comment_issue",
|
||||
s"[user:${activityUserName}] commented on issue [issue:${userName}/${repositoryName}#${issueId}]",
|
||||
Some(cut(comment, 200)))
|
||||
|
||||
def recordCommentPullRequestActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, comment: String)
|
||||
(implicit s: Session): Unit =
|
||||
def recordCommentPullRequestActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, comment: String): Unit =
|
||||
insertActivity(userName, repositoryName, activityUserName,
|
||||
"comment_issue",
|
||||
s"[user:${activityUserName}] commented on pull request [pullreq:${userName}/${repositoryName}#${issueId}]",
|
||||
Some(cut(comment, 200)))
|
||||
|
||||
def recordCommentCommitActivity(userName: String, repositoryName: String, activityUserName: String, commitId: String, comment: String)
|
||||
(implicit s: Session): Unit =
|
||||
def recordCommentCommitActivity(userName: String, repositoryName: String, activityUserName: String, commitId: String, comment: String): Unit =
|
||||
insertActivity(userName, repositoryName, activityUserName,
|
||||
"comment_commit",
|
||||
s"[user:${activityUserName}] commented on commit [commit:${userName}/${repositoryName}@${commitId}]",
|
||||
Some(cut(comment, 200)))
|
||||
|
||||
def recordCreateWikiPageActivity(userName: String, repositoryName: String, activityUserName: String, pageName: String)
|
||||
(implicit s: Session): Unit =
|
||||
def recordCreateWikiPageActivity(userName: String, repositoryName: String, activityUserName: String, pageName: String): Unit =
|
||||
insertActivity(userName, repositoryName, activityUserName,
|
||||
"create_wiki",
|
||||
s"[user:${activityUserName}] created the [repo:${userName}/${repositoryName}] wiki",
|
||||
Some(pageName))
|
||||
|
||||
def recordEditWikiPageActivity(userName: String, repositoryName: String, activityUserName: String, pageName: String, commitId: String)
|
||||
(implicit s: Session): Unit =
|
||||
def recordEditWikiPageActivity(userName: String, repositoryName: String, activityUserName: String, pageName: String, commitId: String): Unit =
|
||||
insertActivity(userName, repositoryName, activityUserName,
|
||||
"edit_wiki",
|
||||
s"[user:${activityUserName}] edited the [repo:${userName}/${repositoryName}] wiki",
|
||||
Some(pageName + ":" + commitId))
|
||||
|
||||
def recordPushActivity(userName: String, repositoryName: String, activityUserName: String,
|
||||
branchName: String, commits: List[JGitUtil.CommitInfo])(implicit s: Session): Unit =
|
||||
branchName: String, commits: List[JGitUtil.CommitInfo]): Unit =
|
||||
insertActivity(userName, repositoryName, activityUserName,
|
||||
"push",
|
||||
s"[user:${activityUserName}] pushed to [branch:${userName}/${repositoryName}#${branchName}] at [repo:${userName}/${repositoryName}]",
|
||||
Some(commits.map { commit => commit.id + ":" + commit.shortMessage }.mkString("\n")))
|
||||
|
||||
def recordCreateTagActivity(userName: String, repositoryName: String, activityUserName: String,
|
||||
tagName: String, commits: List[JGitUtil.CommitInfo])(implicit s: Session): Unit =
|
||||
tagName: String, commits: List[JGitUtil.CommitInfo]): Unit =
|
||||
insertActivity(userName, repositoryName, activityUserName,
|
||||
"create_tag",
|
||||
s"[user:${activityUserName}] created tag [tag:${userName}/${repositoryName}#${tagName}] at [repo:${userName}/${repositoryName}]",
|
||||
None)
|
||||
|
||||
def recordDeleteTagActivity(userName: String, repositoryName: String, activityUserName: String,
|
||||
tagName: String, commits: List[JGitUtil.CommitInfo])(implicit s: Session): Unit =
|
||||
tagName: String, commits: List[JGitUtil.CommitInfo]): Unit =
|
||||
insertActivity(userName, repositoryName, activityUserName,
|
||||
"delete_tag",
|
||||
s"[user:${activityUserName}] deleted tag ${tagName} at [repo:${userName}/${repositoryName}]",
|
||||
None)
|
||||
|
||||
def recordCreateBranchActivity(userName: String, repositoryName: String, activityUserName: String, branchName: String)
|
||||
(implicit s: Session): Unit =
|
||||
def recordCreateBranchActivity(userName: String, repositoryName: String, activityUserName: String, branchName: String): Unit =
|
||||
insertActivity(userName, repositoryName, activityUserName,
|
||||
"create_branch",
|
||||
s"[user:${activityUserName}] created branch [branch:${userName}/${repositoryName}#${branchName}] at [repo:${userName}/${repositoryName}]",
|
||||
None)
|
||||
|
||||
def recordDeleteBranchActivity(userName: String, repositoryName: String, activityUserName: String, branchName: String)
|
||||
(implicit s: Session): Unit =
|
||||
def recordDeleteBranchActivity(userName: String, repositoryName: String, activityUserName: String, branchName: String): Unit =
|
||||
insertActivity(userName, repositoryName, activityUserName,
|
||||
"delete_branch",
|
||||
s"[user:${activityUserName}] deleted branch ${branchName} at [repo:${userName}/${repositoryName}]",
|
||||
None)
|
||||
|
||||
def recordForkActivity(userName: String, repositoryName: String, activityUserName: String, forkedUserName: String)(implicit s: Session): Unit =
|
||||
def recordForkActivity(userName: String, repositoryName: String, activityUserName: String, forkedUserName: String): Unit =
|
||||
insertActivity(userName, repositoryName, activityUserName,
|
||||
"fork",
|
||||
s"[user:${activityUserName}] forked [repo:${userName}/${repositoryName}] to [repo:${forkedUserName}/${repositoryName}]",
|
||||
None)
|
||||
|
||||
def recordPullRequestActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String)
|
||||
(implicit s: Session): Unit =
|
||||
def recordPullRequestActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String): Unit =
|
||||
insertActivity(userName, repositoryName, activityUserName,
|
||||
"open_pullreq",
|
||||
s"[user:${activityUserName}] opened pull request [pullreq:${userName}/${repositoryName}#${issueId}]",
|
||||
Some(title))
|
||||
|
||||
def recordMergeActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, message: String)
|
||||
(implicit s: Session): Unit =
|
||||
def recordMergeActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, message: String): Unit =
|
||||
insertActivity(userName, repositoryName, activityUserName,
|
||||
"merge_pullreq",
|
||||
s"[user:${activityUserName}] merged pull request [pullreq:${userName}/${repositoryName}#${issueId}]",
|
||||
|
||||
@@ -1,35 +1,34 @@
|
||||
package gitbucket.core.service
|
||||
|
||||
import gitbucket.core.model.CommitComment
|
||||
import gitbucket.core.util.{StringUtil, Implicits}
|
||||
|
||||
import scala.slick.jdbc.{StaticQuery => Q}
|
||||
import Q.interpolation
|
||||
import gitbucket.core.model.Profile._
|
||||
import profile.simple._
|
||||
import Implicits._
|
||||
import StringUtil._
|
||||
|
||||
import gitbucket.core.servlet.Database._
|
||||
import io.getquill._
|
||||
|
||||
|
||||
trait CommitsService {
|
||||
|
||||
def getCommitComments(owner: String, repository: String, commitId: String, includePullRequest: Boolean)(implicit s: Session) =
|
||||
CommitComments filter {
|
||||
t => t.byCommit(owner, repository, commitId) && (t.issueId.isEmpty || includePullRequest)
|
||||
} list
|
||||
def getCommitComments(owner: String, repository: String, commitId: String, includePullRequest: Boolean) =
|
||||
db.run(quote { (owner: String, repository: String, commitId: String, includePullRequest: Boolean) =>
|
||||
query[CommitComment].filter { t =>
|
||||
t.userName == owner && t.repositoryName == repository && t.commitId == commitId && (t.issueId.isEmpty || includePullRequest)
|
||||
}
|
||||
})(owner, repository, commitId, includePullRequest)
|
||||
|
||||
def getCommitComment(owner: String, repository: String, commentId: String)(implicit s: Session) =
|
||||
def getCommitComment(owner: String, repository: String, commentId: String) =
|
||||
if (commentId forall (_.isDigit))
|
||||
CommitComments filter { t =>
|
||||
t.byPrimaryKey(commentId.toInt) && t.byRepository(owner, repository)
|
||||
} firstOption
|
||||
db.run(quote { (owner: String, repository: String, commentId: Int) =>
|
||||
query[CommitComment].filter(t => t.userName == owner && t.repositoryName == repository && t.commentId == commentId)
|
||||
})(owner, repository, commentId.toInt).headOption
|
||||
else
|
||||
None
|
||||
|
||||
def createCommitComment(owner: String, repository: String, commitId: String, loginUser: String,
|
||||
content: String, fileName: Option[String], oldLine: Option[Int], newLine: Option[Int],
|
||||
issueId: Option[Int])(implicit s: Session): Int =
|
||||
CommitComments.autoInc insert CommitComment(
|
||||
CommitComments.autoInc insert CommitComment( // TODO Remain Slick code
|
||||
userName = owner,
|
||||
repositoryName = repository,
|
||||
commitId = commitId,
|
||||
@@ -42,13 +41,12 @@ trait CommitsService {
|
||||
updatedDate = currentDate,
|
||||
issueId = issueId)
|
||||
|
||||
def updateCommitComment(commentId: Int, content: String)(implicit s: Session) =
|
||||
CommitComments
|
||||
.filter (_.byPrimaryKey(commentId))
|
||||
.map { t =>
|
||||
t.content -> t.updatedDate
|
||||
}.update (content, currentDate)
|
||||
def updateCommitComment(commentId: Int, content: String) =
|
||||
db.run(quote { (commentId: Int, content: String, updatedDate: java.util.Date) =>
|
||||
query[CommitComment].filter(_.commentId == commentId).update(_.content -> content, _.updatedDate -> updatedDate)
|
||||
})(commentId, content, currentDate)
|
||||
|
||||
def deleteCommitComment(commentId: Int) =
|
||||
db.run(quote { (commentId: Int) => query[CommitComment].filter(_.commentId == commentId).delete })(commentId)
|
||||
|
||||
def deleteCommitComment(commentId: Int)(implicit s: Session) =
|
||||
CommitComments filter (_.byPrimaryKey(commentId)) delete
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user