mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 13:35:50 +01:00
Improved model package. The details are as follows:
* Fix the Profiles class from package object to simple object * Fix the row case class to model package * Define the alias of JdbcBackend#Session
This commit is contained in:
@@ -21,9 +21,9 @@ trait AccountComponent { self: Profile =>
|
||||
val removed = column[Boolean]("REMOVED")
|
||||
def * = (userName, fullName, mailAddress, password, isAdmin, url.?, registeredDate, updatedDate, lastLoginDate.?, image.?, groupAccount, removed) <> (Account.tupled, Account.unapply)
|
||||
}
|
||||
}
|
||||
|
||||
case class Account(
|
||||
|
||||
userName: String,
|
||||
fullName: String,
|
||||
mailAddress: String,
|
||||
@@ -37,4 +37,3 @@ trait AccountComponent { self: Profile =>
|
||||
isGroupAccount: Boolean,
|
||||
isRemoved: Boolean
|
||||
)
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ trait ActivityComponent extends TemplateComponent { self: Profile =>
|
||||
val activityDate = column[java.util.Date]("ACTIVITY_DATE")
|
||||
def * = (userName, repositoryName, activityUserName, activityType, message, additionalInfo.?, activityDate, activityId) <> (Activity.tupled, Activity.unapply)
|
||||
}
|
||||
}
|
||||
|
||||
case class Activity(
|
||||
userName: String,
|
||||
@@ -26,4 +27,3 @@ trait ActivityComponent extends TemplateComponent { self: Profile =>
|
||||
activityDate: java.util.Date,
|
||||
activityId: Int = 0
|
||||
)
|
||||
}
|
||||
|
||||
@@ -12,10 +12,10 @@ trait CollaboratorComponent extends TemplateComponent { self: Profile =>
|
||||
def byPrimaryKey(owner: String, repository: String, collaborator: String) =
|
||||
byRepository(owner, repository) && (collaboratorName is collaborator.bind)
|
||||
}
|
||||
}
|
||||
|
||||
case class Collaborator(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
collaboratorName: String
|
||||
)
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@ trait GroupMemberComponent { self: Profile =>
|
||||
val isManager = column[Boolean]("MANAGER")
|
||||
def * = (groupName, userName, isManager) <> (GroupMember.tupled, GroupMember.unapply)
|
||||
}
|
||||
}
|
||||
|
||||
case class GroupMember(
|
||||
groupName: String,
|
||||
userName: String,
|
||||
isManager: Boolean
|
||||
)
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ trait IssueComponent extends TemplateComponent { self: Profile =>
|
||||
|
||||
def byPrimaryKey(owner: String, repository: String, issueId: Int) = byIssue(owner, repository, issueId)
|
||||
}
|
||||
}
|
||||
|
||||
case class Issue(
|
||||
userName: String,
|
||||
@@ -44,5 +45,5 @@ trait IssueComponent extends TemplateComponent { self: Profile =>
|
||||
closed: Boolean,
|
||||
registeredDate: java.util.Date,
|
||||
updatedDate: java.util.Date,
|
||||
isPullRequest: Boolean)
|
||||
}
|
||||
isPullRequest: Boolean
|
||||
)
|
||||
|
||||
@@ -19,6 +19,7 @@ trait IssueCommentComponent extends TemplateComponent { self: Profile =>
|
||||
|
||||
def byPrimaryKey(commentId: Int) = this.commentId is commentId.bind
|
||||
}
|
||||
}
|
||||
|
||||
case class IssueComment(
|
||||
userName: String,
|
||||
@@ -31,4 +32,3 @@ trait IssueCommentComponent extends TemplateComponent { self: Profile =>
|
||||
registeredDate: java.util.Date,
|
||||
updatedDate: java.util.Date
|
||||
)
|
||||
}
|
||||
|
||||
@@ -10,10 +10,11 @@ trait IssueLabelComponent extends TemplateComponent { self: Profile =>
|
||||
def byPrimaryKey(owner: String, repository: String, issueId: Int, labelId: Int) =
|
||||
byIssue(owner, repository, issueId) && (this.labelId is labelId.bind)
|
||||
}
|
||||
}
|
||||
|
||||
case class IssueLabel(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
issueId: Int,
|
||||
labelId: Int)
|
||||
}
|
||||
labelId: Int
|
||||
)
|
||||
|
||||
@@ -14,6 +14,7 @@ trait LabelComponent extends TemplateComponent { self: Profile =>
|
||||
def byPrimaryKey(owner: String, repository: String, labelId: Int) = byLabel(owner, repository, labelId)
|
||||
def byPrimaryKey(userName: Column[String], repositoryName: Column[String], labelId: Column[Int]) = byLabel(userName, repositoryName, labelId)
|
||||
}
|
||||
}
|
||||
|
||||
case class Label(
|
||||
userName: String,
|
||||
@@ -34,4 +35,3 @@ trait LabelComponent extends TemplateComponent { self: Profile =>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ trait MilestoneComponent extends TemplateComponent { self: Profile =>
|
||||
def byPrimaryKey(owner: String, repository: String, milestoneId: Int) = byMilestone(owner, repository, milestoneId)
|
||||
def byPrimaryKey(userName: Column[String], repositoryName: Column[String], milestoneId: Column[Int]) = byMilestone(userName, repositoryName, milestoneId)
|
||||
}
|
||||
}
|
||||
|
||||
case class Milestone(
|
||||
userName: String,
|
||||
@@ -25,5 +26,5 @@ trait MilestoneComponent extends TemplateComponent { self: Profile =>
|
||||
title: String,
|
||||
description: Option[String],
|
||||
dueDate: Option[java.util.Date],
|
||||
closedDate: Option[java.util.Date])
|
||||
}
|
||||
closedDate: Option[java.util.Date]
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package model
|
||||
|
||||
trait Profile {
|
||||
val profile = slick.driver.H2Driver
|
||||
val profile: slick.driver.JdbcProfile
|
||||
import profile.simple._
|
||||
|
||||
// java.util.Date Mapped Column Types
|
||||
@@ -15,3 +15,27 @@ trait Profile {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
object Profile extends {
|
||||
val profile = slick.driver.H2Driver
|
||||
|
||||
} with AccountComponent
|
||||
with ActivityComponent
|
||||
with CollaboratorComponent
|
||||
with GroupMemberComponent
|
||||
with IssueComponent
|
||||
with IssueCommentComponent
|
||||
with IssueLabelComponent
|
||||
with LabelComponent
|
||||
with MilestoneComponent
|
||||
with PullRequestComponent
|
||||
with RepositoryComponent
|
||||
with SshKeyComponent
|
||||
with WebHookComponent with Profile {
|
||||
|
||||
/**
|
||||
* Returns system date.
|
||||
*/
|
||||
def currentDate = new java.util.Date()
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ trait PullRequestComponent extends TemplateComponent { self: Profile =>
|
||||
def byPrimaryKey(userName: String, repositoryName: String, issueId: Int) = byIssue(userName, repositoryName, issueId)
|
||||
def byPrimaryKey(userName: Column[String], repositoryName: Column[String], issueId: Column[Int]) = byIssue(userName, repositoryName, issueId)
|
||||
}
|
||||
}
|
||||
|
||||
case class PullRequest(
|
||||
userName: String,
|
||||
@@ -29,4 +30,3 @@ trait PullRequestComponent extends TemplateComponent { self: Profile =>
|
||||
commitIdFrom: String,
|
||||
commitIdTo: String
|
||||
)
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ trait RepositoryComponent extends TemplateComponent { self: Profile =>
|
||||
|
||||
def byPrimaryKey(owner: String, repository: String) = byRepository(owner, repository)
|
||||
}
|
||||
}
|
||||
|
||||
case class Repository(
|
||||
userName: String,
|
||||
@@ -36,4 +37,3 @@ trait RepositoryComponent extends TemplateComponent { self: Profile =>
|
||||
parentUserName: Option[String],
|
||||
parentRepositoryName: Option[String]
|
||||
)
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ trait SshKeyComponent { self: Profile =>
|
||||
|
||||
def byPrimaryKey(userName: String, sshKeyId: Int) = (this.userName is userName.bind) && (this.sshKeyId is sshKeyId.bind)
|
||||
}
|
||||
}
|
||||
|
||||
case class SshKey(
|
||||
userName: String,
|
||||
@@ -21,4 +22,3 @@ trait SshKeyComponent { self: Profile =>
|
||||
title: String,
|
||||
publicKey: String
|
||||
)
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@ trait WebHookComponent extends TemplateComponent { self: Profile =>
|
||||
|
||||
def byPrimaryKey(owner: String, repository: String, url: String) = byRepository(owner, repository) && (this.url is url.bind)
|
||||
}
|
||||
}
|
||||
|
||||
case class WebHook(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
url: String
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,21 +1,3 @@
|
||||
package object model extends Profile
|
||||
with AccountComponent
|
||||
with ActivityComponent
|
||||
with CollaboratorComponent
|
||||
with GroupMemberComponent
|
||||
with IssueComponent
|
||||
with IssueCommentComponent
|
||||
with IssueLabelComponent
|
||||
with LabelComponent
|
||||
with MilestoneComponent
|
||||
with PullRequestComponent
|
||||
with RepositoryComponent
|
||||
with SshKeyComponent
|
||||
with WebHookComponent {
|
||||
|
||||
/**
|
||||
* Returns system date.
|
||||
*/
|
||||
def currentDate = new java.util.Date()
|
||||
|
||||
package object model {
|
||||
type Session = slick.jdbc.JdbcBackend#Session
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package service
|
||||
|
||||
import model._
|
||||
import model.Profile._
|
||||
import profile.simple._
|
||||
import model.{Account, GroupMember}
|
||||
// TODO [Slick 2.0]NOT import directly?
|
||||
import model.dateColumnType
|
||||
import model.Profile.dateColumnType
|
||||
import service.SystemSettingsService.SystemSettings
|
||||
import util.StringUtil._
|
||||
import util.LDAPUtil
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package service
|
||||
|
||||
import model._
|
||||
import model.Profile._
|
||||
import profile.simple._
|
||||
import model.Activity
|
||||
|
||||
trait ActivityService {
|
||||
|
||||
|
||||
@@ -3,8 +3,9 @@ package service
|
||||
import scala.slick.jdbc.{StaticQuery => Q}
|
||||
import Q.interpolation
|
||||
|
||||
import model._
|
||||
import model.Profile._
|
||||
import profile.simple._
|
||||
import model.{Issue, IssueComment, IssueLabel, Label}
|
||||
import util.Implicits._
|
||||
import util.StringUtil._
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package service
|
||||
|
||||
import model._
|
||||
import model.Profile._
|
||||
import profile.simple._
|
||||
import model.Label
|
||||
|
||||
trait LabelsService {
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package service
|
||||
|
||||
import model._
|
||||
import model.Profile._
|
||||
import profile.simple._
|
||||
import model.Milestone
|
||||
// TODO [Slick 2.0]NOT import directly?
|
||||
import model.dateColumnType
|
||||
import model.Profile.dateColumnType
|
||||
|
||||
trait MilestonesService {
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package service
|
||||
|
||||
import model._
|
||||
import model.Profile._
|
||||
import profile.simple._
|
||||
import model.{PullRequest, Issue}
|
||||
|
||||
trait PullRequestService { self: IssuesService =>
|
||||
import PullRequestService._
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.eclipse.jgit.revwalk.RevWalk
|
||||
import org.eclipse.jgit.treewalk.TreeWalk
|
||||
import org.eclipse.jgit.lib.FileMode
|
||||
import org.eclipse.jgit.api.Git
|
||||
import model._
|
||||
import model.Profile._
|
||||
import profile.simple._
|
||||
|
||||
trait RepositorySearchService { self: IssuesService =>
|
||||
@@ -107,7 +107,7 @@ object RepositorySearchService {
|
||||
|
||||
case class SearchResult(
|
||||
files : List[(String, String)],
|
||||
issues: List[(Issue, Int, String)])
|
||||
issues: List[(model.Issue, Int, String)])
|
||||
|
||||
case class IssueSearchResult(
|
||||
issueId: Int,
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package service
|
||||
|
||||
import model._
|
||||
import model.Profile._
|
||||
import profile.simple._
|
||||
import model.{Repository, Account, Collaborator}
|
||||
import util.JGitUtil
|
||||
|
||||
trait RepositoryService { self: AccountService =>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package service
|
||||
|
||||
import model._
|
||||
import slick.jdbc.JdbcBackend
|
||||
import model.{Account, Issue, Session}
|
||||
import util.Implicits.request2Session
|
||||
|
||||
/**
|
||||
@@ -12,7 +11,7 @@ import util.Implicits.request2Session
|
||||
*/
|
||||
trait RequestCache extends SystemSettingsService with AccountService with IssuesService {
|
||||
|
||||
private implicit def context2Session(implicit context: app.Context): JdbcBackend#Session =
|
||||
private implicit def context2Session(implicit context: app.Context): Session =
|
||||
request2Session(context.request)
|
||||
|
||||
def getIssue(userName: String, repositoryName: String, issueId: String)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package service
|
||||
|
||||
import model._
|
||||
import model.Profile._
|
||||
import profile.simple._
|
||||
import model.SshKey
|
||||
|
||||
trait SshKeyService {
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package service
|
||||
|
||||
import model._
|
||||
import model.Profile._
|
||||
import profile.simple._
|
||||
import model.{WebHook, Account}
|
||||
import org.slf4j.LoggerFactory
|
||||
import service.RepositoryService.RepositoryInfo
|
||||
import util.JGitUtil
|
||||
|
||||
@@ -5,7 +5,6 @@ import javax.servlet.http._
|
||||
import service.{SystemSettingsService, AccountService, RepositoryService}
|
||||
import model._
|
||||
import org.slf4j.LoggerFactory
|
||||
import slick.jdbc.JdbcBackend
|
||||
import util.Implicits._
|
||||
import util.ControlUtil._
|
||||
import util.Keys
|
||||
@@ -67,7 +66,7 @@ class BasicAuthenticationFilter extends Filter with RepositoryService with Accou
|
||||
}
|
||||
|
||||
private def getWritableUser(username: String, password: String, repository: RepositoryService.RepositoryInfo)
|
||||
(implicit session: JdbcBackend#Session): Option[Account] =
|
||||
(implicit session: Session): Option[Account] =
|
||||
authenticate(loadSystemSettings(), username, password) match {
|
||||
case x @ Some(account) if(hasWritePermission(repository.owner, repository.name, x)) => x
|
||||
case _ => None
|
||||
|
||||
@@ -17,7 +17,7 @@ import WebHookService._
|
||||
import org.eclipse.jgit.api.Git
|
||||
import util.JGitUtil.CommitInfo
|
||||
import service.IssuesService.IssueSearchCondition
|
||||
import slick.jdbc.JdbcBackend
|
||||
import model.Session
|
||||
|
||||
/**
|
||||
* Provides Git repository via HTTP.
|
||||
@@ -95,7 +95,7 @@ class GitBucketReceivePackFactory extends ReceivePackFactory[HttpServletRequest]
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl: String)(implicit session: JdbcBackend#Session)
|
||||
class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl: String)(implicit session: Session)
|
||||
extends PostReceiveHook with PreReceiveHook
|
||||
with RepositoryService with AccountService with IssuesService with ActivityService with PullRequestService with WebHookService {
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
|
||||
import org.apache.commons.io.IOUtils
|
||||
import twirl.api.Html
|
||||
import service.{AccountService, RepositoryService, SystemSettingsService}
|
||||
import model.Account
|
||||
import model.{Account, Session}
|
||||
import util.{JGitUtil, Keys}
|
||||
import plugin.PluginConnectionHolder
|
||||
|
||||
@@ -50,7 +50,7 @@ class PluginActionInvokeFilter extends Filter with SystemSettingsService with Re
|
||||
}
|
||||
|
||||
private def processRepositoryAction(path: String, request: HttpServletRequest, response: HttpServletResponse)
|
||||
(implicit session: model.profile.simple.Session): Boolean = {
|
||||
(implicit session: Session): Boolean = {
|
||||
val elements = path.split("/")
|
||||
if(elements.length > 3){
|
||||
val owner = elements(1)
|
||||
|
||||
@@ -12,7 +12,7 @@ import servlet.{Database, CommitLogHook}
|
||||
import service.{AccountService, RepositoryService, SystemSettingsService}
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException
|
||||
import javax.servlet.ServletContext
|
||||
import model.profile.simple.Session
|
||||
import model.Session
|
||||
|
||||
object GitCommand {
|
||||
val CommandRegex = """\Agit-(upload|receive)-pack '/([a-zA-Z0-9\-_.]+)/([a-zA-Z0-9\-_.]+).git'\Z""".r
|
||||
|
||||
@@ -6,11 +6,11 @@ import org.apache.commons.mail.{DefaultAuthenticator, HtmlEmail}
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
import app.Context
|
||||
import model.Session
|
||||
import service.{AccountService, RepositoryService, IssuesService, SystemSettingsService}
|
||||
import servlet.Database
|
||||
import SystemSettingsService.Smtp
|
||||
import _root_.util.ControlUtil.defining
|
||||
import model.profile.simple.Session
|
||||
|
||||
trait Notifier extends RepositoryService with AccountService with IssuesService {
|
||||
def toNotify(r: RepositoryService.RepositoryInfo, issueId: Int, content: String)
|
||||
|
||||
Reference in New Issue
Block a user