mirror of
				https://github.com/gitbucket/gitbucket.git
				synced 2025-11-03 20:15:59 +01:00 
			
		
		
		
	Fix model usage rules.
This commit is contained in:
		@@ -14,23 +14,15 @@ trait IssuesService {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  def getIssue(owner: String, repository: String, issueId: String) =
 | 
					  def getIssue(owner: String, repository: String, issueId: String) =
 | 
				
			||||||
    if (issueId forall (_.isDigit))
 | 
					    if (issueId forall (_.isDigit))
 | 
				
			||||||
      Query(Issues) filter { t =>
 | 
					      Query(Issues) filter (_.byPrimaryKey(owner, repository, issueId.toInt)) firstOption
 | 
				
			||||||
        (t.userName is owner.bind) &&
 | 
					 | 
				
			||||||
        (t.repositoryName is repository.bind) &&
 | 
					 | 
				
			||||||
        (t.issueId is issueId.toInt.bind)
 | 
					 | 
				
			||||||
      } firstOption
 | 
					 | 
				
			||||||
    else None
 | 
					    else None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def getComments(owner: String, repository: String, issueId: Int) =
 | 
					  def getComments(owner: String, repository: String, issueId: Int) =
 | 
				
			||||||
    Query(IssueComments) filter { t =>
 | 
					    Query(IssueComments) filter (_.byIssue(owner, repository, issueId)) list
 | 
				
			||||||
      (t.userName is owner.bind) &&
 | 
					 | 
				
			||||||
      (t.repositoryName is repository.bind) &&
 | 
					 | 
				
			||||||
      (t.issueId is issueId.bind)
 | 
					 | 
				
			||||||
    } list
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def getComment(commentId: String) =
 | 
					  def getComment(commentId: String) =
 | 
				
			||||||
    if (commentId forall (_.isDigit))
 | 
					    if (commentId forall (_.isDigit))
 | 
				
			||||||
      Query(IssueComments) filter (_.commentId is commentId.toInt.bind) firstOption
 | 
					      Query(IssueComments) filter (_.byPrimaryKey(commentId.toInt)) firstOption
 | 
				
			||||||
    else None
 | 
					    else None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
@@ -62,10 +54,10 @@ trait IssuesService {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    searchIssueQuery(owner, repository, condition.copy(labels = Set.empty), filter, userName)
 | 
					    searchIssueQuery(owner, repository, condition.copy(labels = Set.empty), filter, userName)
 | 
				
			||||||
      .innerJoin(IssueLabels).on { (t1, t2) =>
 | 
					      .innerJoin(IssueLabels).on { (t1, t2) =>
 | 
				
			||||||
        (t1.userName is t2.userName) && (t1.repositoryName is t2.repositoryName) && (t1.issueId is t2.issueId)
 | 
					        t1.byIssue(t2.userName, t2.repositoryName, t2.issueId)
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      .innerJoin(Labels).on { case ((t1, t2), t3) =>
 | 
					      .innerJoin(Labels).on { case ((t1, t2), t3) =>
 | 
				
			||||||
        (t2.userName is t3.userName) && (t2.repositoryName is t3.repositoryName) && (t2.labelId is t3.labelId)
 | 
					        t2.byLabel(t3.userName, t3.repositoryName, t3.labelId)
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      .groupBy { case ((t1, t2), t3) =>
 | 
					      .groupBy { case ((t1, t2), t3) =>
 | 
				
			||||||
        t3.labelName
 | 
					        t3.labelName
 | 
				
			||||||
@@ -95,7 +87,7 @@ trait IssuesService {
 | 
				
			|||||||
    // get issues and comment count
 | 
					    // get issues and comment count
 | 
				
			||||||
    val issues = searchIssueQuery(owner, repository, condition, filter, userName)
 | 
					    val issues = searchIssueQuery(owner, repository, condition, filter, userName)
 | 
				
			||||||
      .leftJoin(Query(IssueComments)
 | 
					      .leftJoin(Query(IssueComments)
 | 
				
			||||||
        .filter  { t => (t.userName is owner.bind) && (t.repositoryName is repository.bind) }
 | 
					        .filter  { _.byRepository(owner, repository) }
 | 
				
			||||||
        .groupBy { _.issueId }
 | 
					        .groupBy { _.issueId }
 | 
				
			||||||
        .map     { case (issueId, t) => issueId ~ t.length }).on((t1, t2) => t1.issueId is t2._1)
 | 
					        .map     { case (issueId, t) => issueId ~ t.length }).on((t1, t2) => t1.issueId is t2._1)
 | 
				
			||||||
      .sortBy { case (t1, t2) =>
 | 
					      .sortBy { case (t1, t2) =>
 | 
				
			||||||
@@ -117,14 +109,11 @@ trait IssuesService {
 | 
				
			|||||||
    // get labels
 | 
					    // get labels
 | 
				
			||||||
    val labels = Query(IssueLabels)
 | 
					    val labels = Query(IssueLabels)
 | 
				
			||||||
      .innerJoin(Labels).on { (t1, t2) =>
 | 
					      .innerJoin(Labels).on { (t1, t2) =>
 | 
				
			||||||
        (t1.userName       is t2.userName) &&
 | 
					        t1.byLabel(t2.userName, t2.repositoryName, t2.labelId)
 | 
				
			||||||
        (t1.repositoryName is t2.repositoryName) &&
 | 
					 | 
				
			||||||
        (t1.labelId        is t2.labelId)
 | 
					 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      .filter { case (t1, t2) =>
 | 
					      .filter { case (t1, t2) =>
 | 
				
			||||||
        (t1.userName       is owner.bind) &&
 | 
					        (t1.byRepository(owner, repository)) &&
 | 
				
			||||||
        (t1.repositoryName is repository.bind) &&
 | 
					        (t1.issueId inSetBind (issues.map(_._1.issueId)))
 | 
				
			||||||
        (t1.issueId        inSetBind (issues.map(_._1.issueId)))
 | 
					 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      .sortBy { case (t1, t2) => t1.issueId ~ t2.labelName }
 | 
					      .sortBy { case (t1, t2) => t1.issueId ~ t2.labelName }
 | 
				
			||||||
      .map    { case (t1, t2) => (t1.issueId, t2) }
 | 
					      .map    { case (t1, t2) => (t1.issueId, t2) }
 | 
				
			||||||
@@ -140,28 +129,24 @@ trait IssuesService {
 | 
				
			|||||||
   */
 | 
					   */
 | 
				
			||||||
  private def searchIssueQuery(owner: String, repository: String, condition: IssueSearchCondition, filter: String, userName: Option[String]) =
 | 
					  private def searchIssueQuery(owner: String, repository: String, condition: IssueSearchCondition, filter: String, userName: Option[String]) =
 | 
				
			||||||
    Query(Issues) filter { t1 =>
 | 
					    Query(Issues) filter { t1 =>
 | 
				
			||||||
      (t1.userName         is owner.bind) &&
 | 
					      (t1.byRepository(owner, repository)) &&
 | 
				
			||||||
      (t1.repositoryName   is repository.bind) &&
 | 
					 | 
				
			||||||
      (t1.closed           is (condition.state == "closed").bind) &&
 | 
					      (t1.closed           is (condition.state == "closed").bind) &&
 | 
				
			||||||
      (t1.milestoneId      is condition.milestoneId.get.get.bind, condition.milestoneId.flatten.isDefined) &&
 | 
					      (t1.milestoneId      is condition.milestoneId.get.get.bind, condition.milestoneId.flatten.isDefined) &&
 | 
				
			||||||
      (t1.milestoneId      isNull, condition.milestoneId == Some(None)) &&
 | 
					      (t1.milestoneId      isNull, condition.milestoneId == Some(None)) &&
 | 
				
			||||||
      (t1.assignedUserName is userName.get.bind, filter == "assigned") &&
 | 
					      (t1.assignedUserName is userName.get.bind, filter == "assigned") &&
 | 
				
			||||||
      (t1.openedUserName   is userName.get.bind, filter == "created_by") &&
 | 
					      (t1.openedUserName   is userName.get.bind, filter == "created_by") &&
 | 
				
			||||||
      (IssueLabels filter { t2 =>
 | 
					      (IssueLabels filter { t2 =>
 | 
				
			||||||
        (t2.userName       is t1.userName) &&
 | 
					        (t2.byIssue(t1.userName, t1.repositoryName, t1.issueId)) &&
 | 
				
			||||||
        (t2.repositoryName is t1.repositoryName) &&
 | 
					        (t2.labelId in
 | 
				
			||||||
        (t2.issueId        is t1.issueId) &&
 | 
					 | 
				
			||||||
        (t2.labelId        in
 | 
					 | 
				
			||||||
          (Labels filter { t3 =>
 | 
					          (Labels filter { t3 =>
 | 
				
			||||||
            (t3.userName       is t1.userName) &&
 | 
					            (t3.byRepository(t1.userName, t1.repositoryName)) &&
 | 
				
			||||||
            (t3.repositoryName is t1.repositoryName) &&
 | 
					            (t3.labelName inSetBind condition.labels)
 | 
				
			||||||
            (t3.labelName      inSetBind condition.labels)
 | 
					 | 
				
			||||||
          } map(_.labelId)))
 | 
					          } map(_.labelId)))
 | 
				
			||||||
      } exists, condition.labels.nonEmpty)
 | 
					      } exists, condition.labels.nonEmpty)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def createIssue(owner: String, repository: String, loginUser: String,
 | 
					  def createIssue(owner: String, repository: String, loginUser: String, title: String, content: Option[String],
 | 
				
			||||||
      title: String, content: Option[String]) =
 | 
					                  assignedUserName: Option[String], milestoneId: Option[Int]) =
 | 
				
			||||||
    // next id number
 | 
					    // next id number
 | 
				
			||||||
    sql"SELECT ISSUE_ID + 1 FROM ISSUE_ID WHERE USER_NAME = $owner AND REPOSITORY_NAME = $repository FOR UPDATE".as[Int]
 | 
					    sql"SELECT ISSUE_ID + 1 FROM ISSUE_ID WHERE USER_NAME = $owner AND REPOSITORY_NAME = $repository FOR UPDATE".as[Int]
 | 
				
			||||||
        .firstOption.filter { id =>
 | 
					        .firstOption.filter { id =>
 | 
				
			||||||
@@ -170,8 +155,8 @@ trait IssuesService {
 | 
				
			|||||||
          repository,
 | 
					          repository,
 | 
				
			||||||
          id,
 | 
					          id,
 | 
				
			||||||
          loginUser,
 | 
					          loginUser,
 | 
				
			||||||
          None,
 | 
					          milestoneId,
 | 
				
			||||||
          None,
 | 
					          assignedUserName,
 | 
				
			||||||
          title,
 | 
					          title,
 | 
				
			||||||
          content,
 | 
					          content,
 | 
				
			||||||
          false,
 | 
					          false,
 | 
				
			||||||
@@ -179,11 +164,15 @@ trait IssuesService {
 | 
				
			|||||||
          currentDate)
 | 
					          currentDate)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // increment issue id
 | 
					      // increment issue id
 | 
				
			||||||
      IssueId.filter { t =>
 | 
					      IssueId
 | 
				
			||||||
        (t.userName is owner.bind) && (t.repositoryName is repository.bind)
 | 
					        .filter (_.byPrimaryKey(owner, repository))
 | 
				
			||||||
      }.map(_.issueId).update(id) > 0
 | 
					        .map (_.issueId)
 | 
				
			||||||
 | 
					        .update (id) > 0
 | 
				
			||||||
    } get
 | 
					    } get
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def registerIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int): Unit =
 | 
				
			||||||
 | 
					    IssueLabels.* insert (IssueLabel(owner, repository, issueId, labelId))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def createComment(owner: String, repository: String, loginUser: String,
 | 
					  def createComment(owner: String, repository: String, loginUser: String,
 | 
				
			||||||
      issueId: Int, content: String, action: Option[String]) =
 | 
					      issueId: Int, content: String, action: Option[String]) =
 | 
				
			||||||
    IssueComments.autoInc insert (
 | 
					    IssueComments.autoInc insert (
 | 
				
			||||||
@@ -198,20 +187,20 @@ trait IssuesService {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  def updateIssue(owner: String, repository: String, issueId: Int,
 | 
					  def updateIssue(owner: String, repository: String, issueId: Int,
 | 
				
			||||||
      title: String, content: Option[String]) =
 | 
					      title: String, content: Option[String]) =
 | 
				
			||||||
    Issues filter { t =>
 | 
					    Issues
 | 
				
			||||||
      (t.userName is owner.bind) &&
 | 
					      .filter (_.byPrimaryKey(owner, repository, issueId))
 | 
				
			||||||
      (t.repositoryName is repository.bind) &&
 | 
					      .map { t =>
 | 
				
			||||||
      (t.issueId is issueId.bind)
 | 
					        t.title ~ t.content.? ~ t.updatedDate
 | 
				
			||||||
    } map { t =>
 | 
					      }
 | 
				
			||||||
      t.title ~ t.content.? ~ t.updatedDate
 | 
					      .update (title, content, currentDate)
 | 
				
			||||||
    } update (title, content, currentDate)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def updateComment(commentId: Int, content: String) =
 | 
					  def updateComment(commentId: Int, content: String) =
 | 
				
			||||||
    IssueComments filter {
 | 
					    IssueComments
 | 
				
			||||||
      _.commentId is commentId.bind
 | 
					      .filter (_.byPrimaryKey(commentId))
 | 
				
			||||||
    } map { t =>
 | 
					      .map { t =>
 | 
				
			||||||
      t.content ~ t.updatedDate
 | 
					        t.content ~ t.updatedDate
 | 
				
			||||||
    } update (content, currentDate)
 | 
					      }
 | 
				
			||||||
 | 
					      .update (content, currentDate)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def updateClosed(owner: String, repository: String, issueId: Int, closed: Boolean) =
 | 
					  def updateClosed(owner: String, repository: String, issueId: Int, closed: Boolean) =
 | 
				
			||||||
    Issues
 | 
					    Issues
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user